From 63b3d7e0c094da507ddd31174d3be43ad44c332a Mon Sep 17 00:00:00 2001 From: Robert Siemborski Date: Tue, 4 Jul 2000 22:15:39 +0000 Subject: [PATCH] Magic Line Code Added git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@68 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- files.c | 7 +++++++ nano.c | 8 ++++++++ proto.h | 4 +--- utils.c | 12 ++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/files.c b/files.c index cc1fd4d5..bd24dd3e 100644 --- a/files.c +++ b/files.c @@ -180,6 +180,7 @@ int read_file(int fd, char *filename) statusbar(_("Read %d lines"), lines); return 1; } + if (current != NULL) { fileptr->next = current; current->prev = fileptr; @@ -188,6 +189,9 @@ int read_file(int fd, char *filename) placewewant = 0; } else if (fileptr->next == NULL) { filebot = fileptr; + new_magicline(); + + /* Update the edit buffer */ load_file(); } statusbar(_("Read %d lines"), lines); @@ -326,6 +330,9 @@ int write_file(char *name, int tmp) dump_buffer(fileage); while (fileptr != NULL && fileptr->next != NULL) { + /* Next line is so we discount the "magic line" */ + if(filebot == fileptr && fileptr->data[0] == '\0') break; + size = write(fd, fileptr->data, strlen(fileptr->data)); if (size == -1) { statusbar(_("Could not open file for writing: %s"), diff --git a/nano.c b/nano.c index 435648bd..a391a43b 100644 --- a/nano.c +++ b/nano.c @@ -440,6 +440,14 @@ void nano_small_msg(void) /* The user typed a printable character; add it to the edit buffer */ void do_char(char ch) { + /* magic-line: when a character is inserted on the current magic line, + * it means we need a new one! */ + if(filebot == current && current->data[0] == '\0') { + new_magicline(); + if(current == editbot) + fix_editbot(); + } + /* More dangerousness fun =) */ current->data = nrealloc(current->data, strlen(current->data) + 2); memmove(¤t->data[current_x + 1], diff --git a/proto.h b/proto.h index 10da7ce5..54e1b9aa 100644 --- a/proto.h +++ b/proto.h @@ -102,7 +102,7 @@ void *nmalloc(size_t howmuch); void *nrealloc(void *ptr, size_t howmuch); void die(char *msg, ...); void new_file(void); - +void new_magicline(void); int do_writeout_void(void), do_exit(void), do_gotoline_void(void); int do_insertfile(void), do_search(void), page_up(void), page_down(void); @@ -116,5 +116,3 @@ int do_replace(void), do_help(void), do_enter_void(void); filestruct *copy_node(filestruct * src); filestruct *copy_filestruct(filestruct * src); filestruct *make_new_node(filestruct * prevnode); - - diff --git a/utils.c b/utils.c index e9af3a16..c10dda55 100644 --- a/utils.c +++ b/utils.c @@ -109,3 +109,15 @@ void *nrealloc(void *ptr, size_t howmuch) return r; } + +/* Append a new magic-line to filebot */ +void new_magicline(void) { + filebot->next = nmalloc(sizeof(filestruct)); + filebot->next->data = nmalloc(1); + filebot->next->data[0] = '\0'; + filebot->next->prev = filebot; + filebot->next->next = NULL; + filebot->next->lineno = filebot->lineno + 1; + filebot = filebot->next; + totlines++; +}