- Allow --tiny and --multibuffer to cooperate (who the heck
would want this is beyond me but ;-). Changes to
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:
- Define NDEBUG to silence asserts (David Benbennick).
- files.c:
#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.
* Return 0 on success or 1 on error.
*/
int add_open_file(int update)
{
- filestruct *tmp;
+ openfilestruct *tmp;
if (!fileage || !current || !filename)
return 1;
/* if no entries, make the first one */
- if (!open_files) {
- open_files = make_new_node(NULL);
-
- /* if open_files->file is NULL at the nrealloc() below, we get a
- segfault
- open_files->file = open_files; */
- open_files->file = NULL;
- }
+ if (!open_files)
+ open_files = make_new_opennode(NULL);
else if (!update) {
open_files and splice it in after the current one */
#ifdef DEBUG
- fprintf(stderr, _("filename is %s"), open_files->data);
+ fprintf(stderr, _("filename is %s"), open_files->filename);
#endif
- tmp = make_new_node(NULL);
- splice_node(open_files, tmp, open_files->next);
+ tmp = make_new_opennode(NULL);
+ splice_opennode(open_files, tmp, 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 */
- open_files->data = mallocstrcpy(open_files->data, filename);
+ open_files->filename = mallocstrcpy(open_files->filename, filename);
/* save current total number of lines */
open_files->file_totlines = totlines;
open_files->file_placewewant = placewewant;
/* 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
have changed, so we won't bother resaving the filestruct
if (!(ISSET(VIEW_MODE) && !update)) {
/* save current filestruct and restore full file position
afterward */
- open_files->file = fileage;
- do_gotopos(open_files->lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant);
+ open_files->fileage = fileage;
+ do_gotopos(open_files->file_lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant);
}
/* save current modification status */
open_files->file_modified = ISSET(MODIFIED);
#ifdef DEBUG
- fprintf(stderr, _("filename is %s"), open_files->data);
+ fprintf(stderr, _("filename is %s"), open_files->filename);
#endif
return 0;
}
/*
- * Update only the filename and full path stored in the current entry.
- * Return 0 on success or 1 on error.
+ * Update only the filename stored in the current entry. Return 0 on
+ * success or 1 on error.
*/
int open_file_change_name(void)
{
return 1;
/* save current filename */
- open_files->data = mallocstrcpy(open_files->data, filename);
+ open_files->filename = mallocstrcpy(open_files->filename, filename);
return 0;
}
/* set up the filename, the file buffer, the total number of lines in
the file, and the total file size */
- filename = mallocstrcpy(filename, open_files->data);
- fileage = open_files->file;
+ filename = mallocstrcpy(filename, open_files->filename);
+ fileage = open_files->fileage;
current = fileage;
totlines = open_files->file_totlines;
totsize = open_files->file_totsize;
/* restore full file position: line number, x-coordinate, y-
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 */
filebot = current;
open_files = open_files->prev;
#ifdef DEBUG
- fprintf(stderr, _("filename is %s"), open_files->data);
+ fprintf(stderr, _("filename is %s"), open_files->filename);
#endif
}
open_files = open_files->next;
#ifdef DEBUG
- fprintf(stderr, _("filename is %s"), open_files->data);
+ fprintf(stderr, _("filename is %s"), open_files->filename);
#endif
}
-/* free_filestruct(fileage); // delete this before reloading */
load_open_file();
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
dump_buffer(current);
open_files = open_files->next;
#ifdef DEBUG
- fprintf(stderr, _("filename is %s"), open_files->data);
+ fprintf(stderr, _("filename is %s"), open_files->filename);
#endif
}
open_files = open_files->prev;
#ifdef DEBUG
- fprintf(stderr, _("filename is %s"), open_files->data);
+ fprintf(stderr, _("filename is %s"), open_files->filename);
#endif
}
load_open_file();
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
dump_buffer(current);
*/
int close_open_file(void)
{
- filestruct *tmp;
+ openfilestruct *tmp;
if (!open_files)
return 1;
- open_files->file = fileage;
+ open_files->fileage = fileage;
tmp = open_files;
if (open_nextfile(1)) {
return 1;
}
- unlink_node(tmp);
- free_filestruct(tmp->file);
- delete_node(tmp);
+ unlink_opennode(tmp);
+ delete_opennode(tmp);
shortcut_init(0);
display_main_list();
/* first, if the filename was changed during the save,
update the filename stored in the current entry, and
then update the current entry */
- if (strcmp(open_files->data, filename)) {
+ if (strcmp(open_files->filename, filename)) {
open_file_change_name();
add_open_file(1);
}
filestruct *cutbuffer = NULL; /* A place to store cut text */
#ifdef ENABLE_MULTIBUFFER
-filestruct *open_files = NULL; /* The list of open files */
+openfilestruct *open_files = NULL; /* The list of open files */
#endif
#ifndef DISABLE_JUSTIFY
void thanks_for_all_the_fish(void)
{
#ifdef ENABLE_MULTIBUFFER
- filestruct * current_open_file;
+ openfilestruct * current_open_file;
#endif
#ifndef DISABLE_OPERATINGDIR
Do not cleanup the current one, that is fileage . . . do the
rest of them though! (should be none if all went well) */
current_open_file = open_files;
- if (open_files != NULL){
- while (open_files->prev != NULL)
- open_files = open_files->prev;
- while (open_files->next != NULL) {
+ if (open_files != NULL) {
+ while (open_files->prev != NULL)
+ open_files = open_files->prev;
+ while (open_files->next != NULL) {
/* cleanup of a multi buf . . . */
- if (open_files != current_open_file)
- free_filestruct(open_files->file);
- open_files = open_files->next;
- free_filestruct(open_files->prev);
+ open_files = open_files->next;
+ if (open_files->prev != current_open_file)
+ free_openfilestruct(open_files->prev);
}
/* cleanup of last multi buf . . . */
- if (open_files != current_open_file)
- free_filestruct(open_files->file);
- free_filestruct(open_files);
+ free_openfilestruct(open_files);
}
-#endif
+#else
/* starting the cleanup of fileage now . . . */
if (fileage != NULL)
- free_filestruct(fileage);
+ free_filestruct(fileage);
+#endif
/* that is all for now */
#ifdef ENABLE_MULTIBUFFER
/* then save all of the other modified loaded files, if any */
if (open_files) {
- filestruct *tmp;
+ openfilestruct *tmp;
tmp = open_files;
/* if we already saved the file above (i. e. if it was the
currently loaded file), don't save it again */
if (tmp != open_files) {
- fileage = open_files->file;
+ fileage = open_files->fileage;
/* save the file if it's been modified */
if (open_files->file_modified)
- die_save_file(open_files->data);
+ die_save_file(open_files->filename);
}
open_files = open_files->next;
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)
{
if (fileptr->prev != NULL)
fileptr->next->prev = fileptr->prev;
}
-/* Delete a node from the struct. This does NOT delete the data members
- used only by open_files. */
+#ifdef ENABLE_MULTIBUFFER
+/* 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)
{
if (fileptr == NULL)
free(fileptr);
}
-/* Okay, now let's duplicate a whole struct! This does NOT duplicate the
- data members used only by open_files. */
+#ifdef ENABLE_MULTIBUFFER
+/* 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 *dst, *tmp, *head, *prev;
return head;
}
-/* Frees a struct. This does NOT free the data members used only by
- open_files. */
+/* Frees a filestruct. */
int free_filestruct(filestruct * src)
{
filestruct *fileptr = src;
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)
{
filestruct *temp;
}
-/* Create a new node. This does NOT initialize the data members used
- only by open_files. */
+/* Create a new filestruct node. */
filestruct *make_new_node(filestruct * prevnode)
{
filestruct *newnode;
return newnode;
}
-/* Splice a node into an existing filestruct. This does NOT set the data
- members used only by open_files. */
+#ifdef ENABLE_MULTIBUFFER
+/* 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,
filestruct * end)
{
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)
{
#ifdef NANO_SMALL
char *data;
struct filestruct *next; /* Next node */
struct filestruct *prev; /* Previous node */
+ int lineno; /* The line number */
+} filestruct;
#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_y; /* Current file's y-coordinate position */
int file_modified; /* Current file's modification status */
int file_placewewant; /* Current file's place we want */
int file_totlines; /* Current file's total number of lines */
long file_totsize; /* Current file's total size */
+ int file_lineno; /* Current file's line number */
+} openfilestruct;
#endif
- int lineno; /* The line number */
-} filestruct;
-
typedef struct shortcut {
int val; /* Actual sequence that generates the keystroke */
int altval; /* Alt key # for this function, or 0 for none */
extern filestruct *cutbuffer, *mark_beginbuf;
#ifdef ENABLE_MULTIBUFFER
-extern filestruct *open_files;
+extern openfilestruct *open_files;
#endif
#ifdef ENABLE_COLOR
int search_init(int replacing);
int renumber(filestruct * fileptr);
int free_filestruct(filestruct * src);
+
+#ifdef ENABLE_MULTIBUFFER
+int free_openfilestruct(openfilestruct * src);
+#endif
+
int xplustabs(void);
int do_yesno(int all, int leavecursor, char *msg, ...);
int actual_x(filestruct * fileptr, int xplus);
void edit_update(filestruct * fileptr, int topmidbotnone);
void update_cursor(void);
void delete_node(filestruct * fileptr);
+
+#ifdef ENABLE_MULTIBUFFER
+void delete_opennode(openfilestruct * fileptr);
+#endif
+
void set_modified(void);
void dump_buffer_reverse(filestruct * inptr);
void reset_cursor(void);
void new_file(void);
void new_magicline(void);
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 page_up(void);
void blank_edit(void);
void do_mouse(void);
void print_view_warning(void);
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,
int bot_x, int destructive);
void free_shortcutage(shortcut **src);
filestruct *copy_node(filestruct * src);
filestruct *copy_filestruct(filestruct * src);
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,
int beginx, char *needle);