Magic Line Code Added

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@68 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Robert Siemborski 2000-07-04 22:15:39 +00:00
parent 66b0fc5b6c
commit 63b3d7e0c0
4 changed files with 28 additions and 3 deletions

View File

@ -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"),

8
nano.c
View File

@ -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(&current->data[current_x + 1],

View File

@ -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);

12
utils.c
View File

@ -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++;
}