Saving with F5 now saves to the file name.
This commit is contained in:
parent
fe910b6e31
commit
1025c25eb9
3
page.c
3
page.c
@ -1,6 +1,6 @@
|
||||
#include "page.h"
|
||||
|
||||
void init_page(PAGE *p, int size)
|
||||
void init_page(PAGE *p, char *filename, int size)
|
||||
{
|
||||
p->text = (LINE *)malloc(size * sizeof(LINE));
|
||||
|
||||
@ -9,6 +9,7 @@ void init_page(PAGE *p, int size)
|
||||
{
|
||||
init_line(p->text + i);
|
||||
}
|
||||
strcpy(p->filename, filename);
|
||||
p->numlines = 0;
|
||||
p->size = size;
|
||||
} // init_page
|
||||
|
4
page.h
4
page.h
@ -7,15 +7,17 @@
|
||||
|
||||
#define PAGE_SIZE 500 /* Max number of lines. Currently not expandable. */
|
||||
#define WIN_SIZE (LINES - 2) /* Size of window, making room for bottom prompt */
|
||||
#define NAME_LIMIT 256 /* Max size of a unix filename + 1 */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char filename[NAME_LIMIT];
|
||||
LINE *text; // lines of text
|
||||
int numlines;
|
||||
int size; // size of array
|
||||
} PAGE;
|
||||
|
||||
void init_page(PAGE *p, int size);
|
||||
void init_page(PAGE *p, char *filename, int size);
|
||||
void dest_page(PAGE *p);
|
||||
void insert_line(PAGE *p, int index);
|
||||
void remove_line(PAGE *p, int index);
|
||||
|
10
text.c
10
text.c
@ -33,7 +33,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else // initialize
|
||||
{
|
||||
init_page(&page, PAGE_SIZE);
|
||||
init_page(&page, "untitled.txt", PAGE_SIZE);
|
||||
page.text[0].line[0] = '\0';
|
||||
page.numlines = 1;
|
||||
}
|
||||
@ -66,7 +66,9 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case KEY_F(5):
|
||||
save_file(argc, argv, &page);
|
||||
update_status("Saved as \'save.txt\'");
|
||||
char status[NAME_LIMIT + 10];
|
||||
sprintf(status, "Saved as \'%s\'", page.filename);
|
||||
update_status(status);
|
||||
break;
|
||||
case KEY_UP:
|
||||
move_up(&page, &x, &y);
|
||||
@ -207,7 +209,7 @@ void load_file(int argc, char **argv, PAGE *p)
|
||||
int size = count_lines(argc, argv) * 2;
|
||||
char ch = '\0';
|
||||
int line, col;
|
||||
init_page(p, size);
|
||||
init_page(p, argv[1], size);
|
||||
|
||||
for(line = 0; line < PAGE_SIZE && ch != EOF; line++)
|
||||
{
|
||||
@ -225,7 +227,7 @@ void load_file(int argc, char **argv, PAGE *p)
|
||||
|
||||
void save_file(int argc, char **argv, PAGE *p)
|
||||
{
|
||||
FILE *fp = fopen("save.txt", "w");
|
||||
FILE *fp = fopen(p->filename, "w");
|
||||
int line, col;
|
||||
|
||||
for(line = 0; line < p->numlines; line++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user