- Change to openfilestruct for multibuffer mode by DLR. New functions nano.c:make_new_opennode(), free_openfilestruct(), delete_opennode(), unlink_opennode(), splice_opennode(), new struct openfilestruct in nano.h

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1173 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2002-04-10 02:31:20 +00:00
parent 70feb4f8e5
commit f2387fbdf7
6 changed files with 173 additions and 76 deletions

View File

@ -4,6 +4,10 @@ CVS code -
- Allow --tiny and --multibuffer to cooperate (who the heck - Allow --tiny and --multibuffer to cooperate (who the heck
would want this is beyond me but ;-). Changes to would want this is beyond me but ;-). Changes to
configure.ac, global.c, , (David Benbennick). configure.ac, global.c, , (David Benbennick).
- Change to openfilestruct for multibuffer mode by DLR.
New functions nano.c:make_new_opennode(), free_openfilestruct(),
delete_opennode(), unlink_opennode(), splice_opennode(),
new struct openfilestruct in nano.h.
- configure.ac: - configure.ac:
- Define NDEBUG to silence asserts (David Benbennick). - Define NDEBUG to silence asserts (David Benbennick).
- files.c: - files.c:

71
files.c
View File

@ -529,26 +529,20 @@ int do_insertfile_void(void)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
/* /*
* Add/update an entry to the open_files filestruct. If update is * Add/update an entry to the open_files openfilestruct. If update is
* zero, a new entry is created; otherwise, the current entry is updated. * zero, a new entry is created; otherwise, the current entry is updated.
* Return 0 on success or 1 on error. * Return 0 on success or 1 on error.
*/ */
int add_open_file(int update) int add_open_file(int update)
{ {
filestruct *tmp; openfilestruct *tmp;
if (!fileage || !current || !filename) if (!fileage || !current || !filename)
return 1; return 1;
/* if no entries, make the first one */ /* if no entries, make the first one */
if (!open_files) { if (!open_files)
open_files = make_new_node(NULL); open_files = make_new_opennode(NULL);
/* if open_files->file is NULL at the nrealloc() below, we get a
segfault
open_files->file = open_files; */
open_files->file = NULL;
}
else if (!update) { else if (!update) {
@ -556,21 +550,16 @@ int add_open_file(int update)
open_files and splice it in after the current one */ open_files and splice it in after the current one */
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("filename is %s"), open_files->data); fprintf(stderr, _("filename is %s"), open_files->filename);
#endif #endif
tmp = make_new_node(NULL); tmp = make_new_opennode(NULL);
splice_node(open_files, tmp, open_files->next); splice_opennode(open_files, tmp, open_files->next);
open_files = open_files->next; open_files = open_files->next;
/* if open_files->file is NULL at the nrealloc() below, we get a
segfault
open_files->file = open_files; */
open_files->file = NULL;
} }
/* save current filename */ /* save current filename */
open_files->data = mallocstrcpy(open_files->data, filename); open_files->filename = mallocstrcpy(open_files->filename, filename);
/* save current total number of lines */ /* save current total number of lines */
open_files->file_totlines = totlines; open_files->file_totlines = totlines;
@ -588,7 +577,7 @@ int add_open_file(int update)
open_files->file_placewewant = placewewant; open_files->file_placewewant = placewewant;
/* save current line number */ /* save current line number */
open_files->lineno = current->lineno; open_files->file_lineno = current->lineno;
/* if we're in view mode and updating, the file contents won't /* if we're in view mode and updating, the file contents won't
have changed, so we won't bother resaving the filestruct have changed, so we won't bother resaving the filestruct
@ -596,23 +585,23 @@ int add_open_file(int update)
if (!(ISSET(VIEW_MODE) && !update)) { if (!(ISSET(VIEW_MODE) && !update)) {
/* save current filestruct and restore full file position /* save current filestruct and restore full file position
afterward */ afterward */
open_files->file = fileage; open_files->fileage = fileage;
do_gotopos(open_files->lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant); do_gotopos(open_files->file_lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant);
} }
/* save current modification status */ /* save current modification status */
open_files->file_modified = ISSET(MODIFIED); open_files->file_modified = ISSET(MODIFIED);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("filename is %s"), open_files->data); fprintf(stderr, _("filename is %s"), open_files->filename);
#endif #endif
return 0; return 0;
} }
/* /*
* Update only the filename and full path stored in the current entry. * Update only the filename stored in the current entry. Return 0 on
* Return 0 on success or 1 on error. * success or 1 on error.
*/ */
int open_file_change_name(void) int open_file_change_name(void)
{ {
@ -620,7 +609,7 @@ int open_file_change_name(void)
return 1; return 1;
/* save current filename */ /* save current filename */
open_files->data = mallocstrcpy(open_files->data, filename); open_files->filename = mallocstrcpy(open_files->filename, filename);
return 0; return 0;
} }
@ -637,8 +626,8 @@ int load_open_file(void)
/* set up the filename, the file buffer, the total number of lines in /* set up the filename, the file buffer, the total number of lines in
the file, and the total file size */ the file, and the total file size */
filename = mallocstrcpy(filename, open_files->data); filename = mallocstrcpy(filename, open_files->filename);
fileage = open_files->file; fileage = open_files->fileage;
current = fileage; current = fileage;
totlines = open_files->file_totlines; totlines = open_files->file_totlines;
totsize = open_files->file_totsize; totsize = open_files->file_totsize;
@ -649,7 +638,7 @@ int load_open_file(void)
/* restore full file position: line number, x-coordinate, y- /* restore full file position: line number, x-coordinate, y-
coordinate, place we want */ coordinate, place we want */
do_gotopos(open_files->lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant); do_gotopos(open_files->file_lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant);
/* restore the bottom of the file */ /* restore the bottom of the file */
filebot = current; filebot = current;
@ -702,7 +691,7 @@ int open_prevfile(int closing_file)
open_files = open_files->prev; open_files = open_files->prev;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("filename is %s"), open_files->data); fprintf(stderr, _("filename is %s"), open_files->filename);
#endif #endif
} }
@ -714,16 +703,15 @@ int open_prevfile(int closing_file)
open_files = open_files->next; open_files = open_files->next;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("filename is %s"), open_files->data); fprintf(stderr, _("filename is %s"), open_files->filename);
#endif #endif
} }
/* free_filestruct(fileage); // delete this before reloading */
load_open_file(); load_open_file();
statusbar(_("Switched to %s"), statusbar(_("Switched to %s"),
((open_files->data[0] == '\0') ? "New Buffer" : open_files->data )); ((open_files->filename[0] == '\0') ? "New Buffer" : open_files->filename ));
#ifdef DEBUG #ifdef DEBUG
dump_buffer(current); dump_buffer(current);
@ -767,7 +755,7 @@ int open_nextfile(int closing_file)
open_files = open_files->next; open_files = open_files->next;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("filename is %s"), open_files->data); fprintf(stderr, _("filename is %s"), open_files->filename);
#endif #endif
} }
@ -778,7 +766,7 @@ int open_nextfile(int closing_file)
open_files = open_files->prev; open_files = open_files->prev;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("filename is %s"), open_files->data); fprintf(stderr, _("filename is %s"), open_files->filename);
#endif #endif
} }
@ -787,7 +775,7 @@ int open_nextfile(int closing_file)
load_open_file(); load_open_file();
statusbar(_("Switched to %s"), statusbar(_("Switched to %s"),
((open_files->data[0] == '\0') ? "New Buffer" : open_files->data )); ((open_files->filename[0] == '\0') ? "New Buffer" : open_files->filename ));
#ifdef DEBUG #ifdef DEBUG
dump_buffer(current); dump_buffer(current);
@ -810,12 +798,12 @@ int open_nextfile_void(void)
*/ */
int close_open_file(void) int close_open_file(void)
{ {
filestruct *tmp; openfilestruct *tmp;
if (!open_files) if (!open_files)
return 1; return 1;
open_files->file = fileage; open_files->fileage = fileage;
tmp = open_files; tmp = open_files;
if (open_nextfile(1)) { if (open_nextfile(1)) {
@ -823,9 +811,8 @@ int close_open_file(void)
return 1; return 1;
} }
unlink_node(tmp); unlink_opennode(tmp);
free_filestruct(tmp->file); delete_opennode(tmp);
delete_node(tmp);
shortcut_init(0); shortcut_init(0);
display_main_list(); display_main_list();
@ -1566,7 +1553,7 @@ int do_writeout(char *path, int exiting, int append)
/* first, if the filename was changed during the save, /* first, if the filename was changed during the save,
update the filename stored in the current entry, and update the filename stored in the current entry, and
then update the current entry */ then update the current entry */
if (strcmp(open_files->data, filename)) { if (strcmp(open_files->filename, filename)) {
open_file_change_name(); open_file_change_name();
add_open_file(1); add_open_file(1);
} }

View File

@ -56,7 +56,7 @@ filestruct *filebot = NULL; /* Last node in the file struct */
filestruct *cutbuffer = NULL; /* A place to store cut text */ filestruct *cutbuffer = NULL; /* A place to store cut text */
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
filestruct *open_files = NULL; /* The list of open files */ openfilestruct *open_files = NULL; /* The list of open files */
#endif #endif
#ifndef DISABLE_JUSTIFY #ifndef DISABLE_JUSTIFY
@ -759,7 +759,7 @@ void free_toggles(void)
void thanks_for_all_the_fish(void) void thanks_for_all_the_fish(void)
{ {
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
filestruct * current_open_file; openfilestruct * current_open_file;
#endif #endif
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
@ -810,26 +810,24 @@ void thanks_for_all_the_fish(void)
Do not cleanup the current one, that is fileage . . . do the Do not cleanup the current one, that is fileage . . . do the
rest of them though! (should be none if all went well) */ rest of them though! (should be none if all went well) */
current_open_file = open_files; current_open_file = open_files;
if (open_files != NULL){ if (open_files != NULL) {
while (open_files->prev != NULL) while (open_files->prev != NULL)
open_files = open_files->prev; open_files = open_files->prev;
while (open_files->next != NULL) { while (open_files->next != NULL) {
/* cleanup of a multi buf . . . */ /* cleanup of a multi buf . . . */
if (open_files != current_open_file) open_files = open_files->next;
free_filestruct(open_files->file); if (open_files->prev != current_open_file)
open_files = open_files->next; free_openfilestruct(open_files->prev);
free_filestruct(open_files->prev);
} }
/* cleanup of last multi buf . . . */ /* cleanup of last multi buf . . . */
if (open_files != current_open_file) free_openfilestruct(open_files);
free_filestruct(open_files->file);
free_filestruct(open_files);
} }
#endif #else
/* starting the cleanup of fileage now . . . */ /* starting the cleanup of fileage now . . . */
if (fileage != NULL) if (fileage != NULL)
free_filestruct(fileage); free_filestruct(fileage);
#endif
/* that is all for now */ /* that is all for now */

106
nano.c
View File

@ -131,7 +131,7 @@ void die(char *msg, ...)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
/* then save all of the other modified loaded files, if any */ /* then save all of the other modified loaded files, if any */
if (open_files) { if (open_files) {
filestruct *tmp; openfilestruct *tmp;
tmp = open_files; tmp = open_files;
@ -143,10 +143,10 @@ void die(char *msg, ...)
/* if we already saved the file above (i. e. if it was the /* if we already saved the file above (i. e. if it was the
currently loaded file), don't save it again */ currently loaded file), don't save it again */
if (tmp != open_files) { if (tmp != open_files) {
fileage = open_files->file; fileage = open_files->fileage;
/* save the file if it's been modified */ /* save the file if it's been modified */
if (open_files->file_modified) if (open_files->file_modified)
die_save_file(open_files->data); die_save_file(open_files->filename);
} }
open_files = open_files->next; open_files = open_files->next;
@ -293,7 +293,7 @@ filestruct *copy_node(filestruct * src)
return dst; return dst;
} }
/* Unlink a node from the rest of the struct */ /* Unlink a node from the rest of the filestruct. */
void unlink_node(filestruct * fileptr) void unlink_node(filestruct * fileptr)
{ {
if (fileptr->prev != NULL) if (fileptr->prev != NULL)
@ -303,8 +303,19 @@ void unlink_node(filestruct * fileptr)
fileptr->next->prev = fileptr->prev; fileptr->next->prev = fileptr->prev;
} }
/* Delete a node from the struct. This does NOT delete the data members #ifdef ENABLE_MULTIBUFFER
used only by open_files. */ /* Unlink a node from the rest of the openfilestruct. */
void unlink_opennode(openfilestruct * fileptr)
{
if (fileptr->prev != NULL)
fileptr->prev->next = fileptr->next;
if (fileptr->next != NULL)
fileptr->next->prev = fileptr->prev;
}
#endif
/* Delete a node from the filestruct. */
void delete_node(filestruct * fileptr) void delete_node(filestruct * fileptr)
{ {
if (fileptr == NULL) if (fileptr == NULL)
@ -315,8 +326,22 @@ void delete_node(filestruct * fileptr)
free(fileptr); free(fileptr);
} }
/* Okay, now let's duplicate a whole struct! This does NOT duplicate the #ifdef ENABLE_MULTIBUFFER
data members used only by open_files. */ /* Delete a node from the openfilestruct. */
void delete_opennode(openfilestruct * fileptr)
{
if (fileptr == NULL)
return;
if (fileptr->filename != NULL)
free(fileptr->filename);
if (fileptr->fileage != NULL)
free_filestruct(fileptr->fileage);
free(fileptr);
}
#endif
/* Okay, now let's duplicate a whole struct! */
filestruct *copy_filestruct(filestruct * src) filestruct *copy_filestruct(filestruct * src)
{ {
filestruct *dst, *tmp, *head, *prev; filestruct *dst, *tmp, *head, *prev;
@ -340,8 +365,7 @@ filestruct *copy_filestruct(filestruct * src)
return head; return head;
} }
/* Frees a struct. This does NOT free the data members used only by /* Frees a filestruct. */
open_files. */
int free_filestruct(filestruct * src) int free_filestruct(filestruct * src)
{ {
filestruct *fileptr = src; filestruct *fileptr = src;
@ -365,6 +389,32 @@ int free_filestruct(filestruct * src)
return 1; return 1;
} }
#ifdef ENABLE_MULTIBUFFER
/* Frees an openfilestruct. */
int free_openfilestruct(openfilestruct * src)
{
openfilestruct *fileptr = src;
if (src == NULL)
return 0;
while (fileptr->next != NULL) {
fileptr = fileptr->next;
delete_opennode(fileptr->prev);
#ifdef DEBUG
fprintf(stderr, _("delete_opennode(): free'd a node, YAY!\n"));
#endif
}
delete_opennode(fileptr);
#ifdef DEBUG
fprintf(stderr, _("delete_opennode(): free'd last node.\n"));
#endif
return 1;
}
#endif
int renumber_all(void) int renumber_all(void)
{ {
filestruct *temp; filestruct *temp;
@ -557,8 +607,7 @@ void version(void)
} }
/* Create a new node. This does NOT initialize the data members used /* Create a new filestruct node. */
only by open_files. */
filestruct *make_new_node(filestruct * prevnode) filestruct *make_new_node(filestruct * prevnode)
{ {
filestruct *newnode; filestruct *newnode;
@ -575,8 +624,24 @@ filestruct *make_new_node(filestruct * prevnode)
return newnode; return newnode;
} }
/* Splice a node into an existing filestruct. This does NOT set the data #ifdef ENABLE_MULTIBUFFER
members used only by open_files. */ /* Create a new openfilestruct node. */
openfilestruct *make_new_opennode(openfilestruct * prevnode)
{
openfilestruct *newnode;
newnode = nmalloc(sizeof(openfilestruct));
newnode->filename = NULL;
newnode->fileage = NULL;
newnode->prev = prevnode;
newnode->next = NULL;
return newnode;
}
#endif
/* Splice a node into an existing filestruct. */
void splice_node(filestruct * begin, filestruct * newnode, void splice_node(filestruct * begin, filestruct * newnode,
filestruct * end) filestruct * end)
{ {
@ -587,6 +652,19 @@ void splice_node(filestruct * begin, filestruct * newnode,
end->prev = newnode; end->prev = newnode;
} }
#ifdef ENABLE_MULTIBUFFER
/* Splice a node into an existing openfilestruct. */
void splice_opennode(openfilestruct * begin, openfilestruct * newnode,
openfilestruct * end)
{
newnode->next = end;
newnode->prev = begin;
begin->next = newnode;
if (end != NULL)
end->prev = newnode;
}
#endif
int do_mark(void) int do_mark(void)
{ {
#ifdef NANO_SMALL #ifdef NANO_SMALL

13
nano.h
View File

@ -73,20 +73,25 @@ typedef struct filestruct {
char *data; char *data;
struct filestruct *next; /* Next node */ struct filestruct *next; /* Next node */
struct filestruct *prev; /* Previous node */ struct filestruct *prev; /* Previous node */
int lineno; /* The line number */
} filestruct;
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
struct filestruct *file; /* Current file */ typedef struct openfilestruct {
char *filename;
struct openfilestruct *next; /* Next node */
struct openfilestruct *prev; /* Previous node */
struct filestruct *fileage; /* Current file */
int file_current_x; /* Current file's x-coordinate position */ int file_current_x; /* Current file's x-coordinate position */
int file_current_y; /* Current file's y-coordinate position */ int file_current_y; /* Current file's y-coordinate position */
int file_modified; /* Current file's modification status */ int file_modified; /* Current file's modification status */
int file_placewewant; /* Current file's place we want */ int file_placewewant; /* Current file's place we want */
int file_totlines; /* Current file's total number of lines */ int file_totlines; /* Current file's total number of lines */
long file_totsize; /* Current file's total size */ long file_totsize; /* Current file's total size */
int file_lineno; /* Current file's line number */
} openfilestruct;
#endif #endif
int lineno; /* The line number */
} filestruct;
typedef struct shortcut { typedef struct shortcut {
int val; /* Actual sequence that generates the keystroke */ int val; /* Actual sequence that generates the keystroke */
int altval; /* Alt key # for this function, or 0 for none */ int altval; /* Alt key # for this function, or 0 for none */

27
proto.h
View File

@ -61,7 +61,7 @@ extern filestruct *current, *fileage, *edittop, *editbot, *filebot;
extern filestruct *cutbuffer, *mark_beginbuf; extern filestruct *cutbuffer, *mark_beginbuf;
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
extern filestruct *open_files; extern openfilestruct *open_files;
#endif #endif
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
@ -104,6 +104,11 @@ char *strstrwrapper(char *haystack, char *needle, char *rev_start);
int search_init(int replacing); int search_init(int replacing);
int renumber(filestruct * fileptr); int renumber(filestruct * fileptr);
int free_filestruct(filestruct * src); int free_filestruct(filestruct * src);
#ifdef ENABLE_MULTIBUFFER
int free_openfilestruct(openfilestruct * src);
#endif
int xplustabs(void); int xplustabs(void);
int do_yesno(int all, int leavecursor, char *msg, ...); int do_yesno(int all, int leavecursor, char *msg, ...);
int actual_x(filestruct * fileptr, int xplus); int actual_x(filestruct * fileptr, int xplus);
@ -162,6 +167,11 @@ void edit_refresh(void), edit_refresh_clearok(void);
void edit_update(filestruct * fileptr, int topmidbotnone); void edit_update(filestruct * fileptr, int topmidbotnone);
void update_cursor(void); void update_cursor(void);
void delete_node(filestruct * fileptr); void delete_node(filestruct * fileptr);
#ifdef ENABLE_MULTIBUFFER
void delete_opennode(openfilestruct * fileptr);
#endif
void set_modified(void); void set_modified(void);
void dump_buffer_reverse(filestruct * inptr); void dump_buffer_reverse(filestruct * inptr);
void reset_cursor(void); void reset_cursor(void);
@ -189,6 +199,11 @@ void die_save_file(char *die_filename);
void new_file(void); void new_file(void);
void new_magicline(void); void new_magicline(void);
void splice_node(filestruct *begin, filestruct *newnode, filestruct *end); void splice_node(filestruct *begin, filestruct *newnode, filestruct *end);
#ifdef ENABLE_MULTIBUFFER
void splice_opennode(openfilestruct *begin, openfilestruct *newnode, openfilestruct *end);
#endif
void null_at(char **data, int index); void null_at(char **data, int index);
void page_up(void); void page_up(void);
void blank_edit(void); void blank_edit(void);
@ -201,6 +216,11 @@ void window_init(void);
void do_mouse(void); void do_mouse(void);
void print_view_warning(void); void print_view_warning(void);
void unlink_node(filestruct * fileptr); void unlink_node(filestruct * fileptr);
#ifdef ENABLE_MULTIBUFFER
void unlink_opennode(openfilestruct * fileptr);
#endif
void cut_marked_segment(filestruct * top, int top_x, filestruct * bot, void cut_marked_segment(filestruct * top, int top_x, filestruct * bot,
int bot_x, int destructive); int bot_x, int destructive);
void free_shortcutage(shortcut **src); void free_shortcutage(shortcut **src);
@ -265,6 +285,11 @@ RETSIGTYPE main_loop (int junk);
filestruct *copy_node(filestruct * src); filestruct *copy_node(filestruct * src);
filestruct *copy_filestruct(filestruct * src); filestruct *copy_filestruct(filestruct * src);
filestruct *make_new_node(filestruct * prevnode); filestruct *make_new_node(filestruct * prevnode);
#ifdef ENABLE_MULTIBUFFER
openfilestruct *make_new_opennode(openfilestruct * prevnode);
#endif
filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin,
int beginx, char *needle); int beginx, char *needle);