nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] updated nanopieces.patch


From: David Lawrence Ramsey
Subject: [Nano-devel] updated nanopieces.patch
Date: Sat, 6 Apr 2002 14:00:25 -0800 (PST)

Here's the updated nanopieces.patch (attached).

_____________________________________________________________
Sluggy.Net: The Sluggy Freelance Community!

_____________________________________________________________
Run a small business? Then you need professional email like address@hidden from 
Everyone.net  http://www.everyone.net?tag
diff -urN nano-1.1.8-cvs/files.c nano-1.1.8-cvs-fixed/files.c
--- nano-1.1.8-cvs/files.c      Fri Apr  5 18:36:45 2002
+++ nano-1.1.8-cvs-fixed/files.c        Fri Apr  5 18:39:56 2002
@@ -529,26 +529,20 @@
 
 #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) {
 
@@ -556,21 +550,16 @@
           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;
@@ -588,7 +577,7 @@
     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
@@ -596,23 +585,23 @@
     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)
 {
@@ -620,7 +609,7 @@
        return 1;
 
     /* save current filename */
-    open_files->data = mallocstrcpy(open_files->data, filename);
+    open_files->filename = mallocstrcpy(open_files->filename, filename);
 
     return 0;
 }
@@ -637,8 +626,8 @@
 
     /* 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;
@@ -649,7 +638,7 @@
 
     /* 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;
@@ -702,7 +691,7 @@
        open_files = open_files->prev;
 
 #ifdef DEBUG
-       fprintf(stderr, _("filename is %s"), open_files->data);
+       fprintf(stderr, _("filename is %s"), open_files->filename);
 #endif
 
     }
@@ -714,16 +703,15 @@
            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);
@@ -767,7 +755,7 @@
        open_files = open_files->next;
 
 #ifdef DEBUG
-       fprintf(stderr, _("filename is %s"), open_files->data);
+       fprintf(stderr, _("filename is %s"), open_files->filename);
 #endif
 
     }
@@ -778,7 +766,7 @@
            open_files = open_files->prev;
 
 #ifdef DEBUG
-           fprintf(stderr, _("filename is %s"), open_files->data);
+           fprintf(stderr, _("filename is %s"), open_files->filename);
 #endif
 
        }
@@ -787,7 +775,7 @@
     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);
@@ -810,12 +798,12 @@
  */
 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)) {
@@ -823,9 +811,8 @@
            return 1;
     }
 
-    unlink_node(tmp);
-    free_filestruct(tmp->file);
-    delete_node(tmp);
+    unlink_opennode(tmp);
+    delete_opennode(tmp);
 
     shortcut_init(0);
     display_main_list();
@@ -1566,7 +1553,7 @@
                /* 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);
                }
diff -urN nano-1.1.8-cvs/global.c nano-1.1.8-cvs-fixed/global.c
--- nano-1.1.8-cvs/global.c     Fri Apr  5 18:36:45 2002
+++ nano-1.1.8-cvs-fixed/global.c       Fri Apr  5 18:39:47 2002
@@ -56,7 +56,7 @@
 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
@@ -759,7 +759,7 @@
 void thanks_for_all_the_fish(void) 
 {
 #ifdef ENABLE_MULTIBUFFER
-    filestruct * current_open_file;
+    openfilestruct * current_open_file;
 #endif
 
 #ifndef DISABLE_OPERATINGDIR
@@ -810,26 +810,24 @@
    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 */
 
diff -urN nano-1.1.8-cvs/nano.c nano-1.1.8-cvs-fixed/nano.c
--- nano-1.1.8-cvs/nano.c       Fri Apr  5 18:36:45 2002
+++ nano-1.1.8-cvs-fixed/nano.c Fri Apr  5 18:39:47 2002
@@ -131,7 +131,7 @@
 #ifdef ENABLE_MULTIBUFFER
     /* then save all of the other modified loaded files, if any */
     if (open_files) {
-        filestruct *tmp;
+       openfilestruct *tmp;
 
        tmp = open_files;
 
@@ -143,10 +143,10 @@
            /* 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;
@@ -293,7 +293,7 @@
     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)
@@ -303,8 +303,19 @@
        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)
@@ -315,8 +326,22 @@
     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;
@@ -340,8 +365,7 @@
     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;
@@ -365,6 +389,32 @@
     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;
@@ -557,8 +607,7 @@
 
 }
 
-/* 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;
@@ -575,8 +624,24 @@
     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)
 {
@@ -586,6 +651,19 @@
     if (end != NULL)
        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)
 {
diff -urN nano-1.1.8-cvs/nano.h nano-1.1.8-cvs-fixed/nano.h
--- nano-1.1.8-cvs/nano.h       Fri Apr  5 18:36:45 2002
+++ nano-1.1.8-cvs-fixed/nano.h Fri Apr  5 18:39:47 2002
@@ -73,19 +73,24 @@
     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 */
diff -urN nano-1.1.8-cvs/proto.h nano-1.1.8-cvs-fixed/proto.h
--- nano-1.1.8-cvs/proto.h      Fri Apr  5 18:36:45 2002
+++ nano-1.1.8-cvs-fixed/proto.h        Fri Apr  5 18:39:47 2002
@@ -61,7 +61,7 @@
 extern filestruct *cutbuffer, *mark_beginbuf;
 
 #ifdef ENABLE_MULTIBUFFER
-extern filestruct *open_files;
+extern openfilestruct *open_files;
 #endif
 
 #ifdef ENABLE_COLOR
@@ -104,6 +104,11 @@
 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);
@@ -162,6 +167,11 @@
 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);
@@ -189,6 +199,11 @@
 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);
@@ -201,6 +216,11 @@
 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);
@@ -265,6 +285,11 @@
 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);
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]