]> git.wh0rd.org Git - nano.git/commitdiff
Removing some code duplication.
authorBenno Schulenberg <bensberg@justemail.net>
Tue, 12 Jan 2016 19:07:01 +0000 (19:07 +0000)
committerBenno Schulenberg <bensberg@justemail.net>
Tue, 12 Jan 2016 19:07:01 +0000 (19:07 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5550 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/files.c

index a0f256a31225ecc073a3bd8370631967bcc2d583..76f10fdfe9e56ed148a8f6f64f103f5f2f3872f4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2016-01-12  Benno Schulenberg  <bensberg@justemail.net>
        * NEWS: Fix some typos and whitespace, and normalize the dates.
        * src/files.c (load_poshistory): Rename a variable.
+       * src/files.c (load_poshistory): Remove some code duplication.
 
 GNU nano 2.5.1 - 2016.01.11
 
index b43fbea22b22c0e7eb947bc42e096a354d952f7c..cd6d6facc9b7f43737e50e8f401aca8c92c531da 100644 (file)
@@ -3216,11 +3216,10 @@ void load_poshistory(void)
        } else {
            char *line = NULL, *lineptr, *xptr;
            size_t buf_len = 0;
-           ssize_t read, lineno, xno;
-           poshiststruct *posptr;
+           ssize_t read;
+           poshiststruct *posptr, *newrecord;
 
-           /* Read and parse each line, and put the data into the
-            * positions history structure. */
+           /* Read and parse each line, and store the extracted data. */
            while ((read = getline(&line, &buf_len, hist)) >= 0) {
                if (read > 0 && line[read - 1] == '\n') {
                    read--;
@@ -3230,25 +3229,23 @@ void load_poshistory(void)
                    unsunder(line, read);
                lineptr = parse_next_word(line);
                xptr = parse_next_word(lineptr);
-               lineno = atoi(lineptr);
-               xno = atoi(xptr);
-               if (poshistory == NULL) {
-                   poshistory = (poshiststruct *)nmalloc(sizeof(poshiststruct));
-                   poshistory->filename = mallocstrcpy(NULL, line);
-                   poshistory->lineno = lineno;
-                   poshistory->xno = xno;
-                   poshistory->next = NULL;
-               } else {
-                   for (posptr = poshistory; posptr->next != NULL; posptr = posptr->next)
-                       ;
-                   posptr->next = (poshiststruct *)nmalloc(sizeof(poshiststruct));
-                   posptr->next->filename = mallocstrcpy(NULL, line);
-                   posptr->next->lineno = lineno;
-                   posptr->next->xno = xno;
-                   posptr->next->next = NULL;
+
+               /* Create a new position record. */
+               newrecord = (poshiststruct *)nmalloc(sizeof(poshiststruct));
+               newrecord->filename = mallocstrcpy(NULL, line);
+               newrecord->lineno = atoi(lineptr);
+               newrecord->xno = atoi(xptr);
+               newrecord->next = NULL;
+
+               /* Add the record to the list. */
+               if (poshistory == NULL)
+                   poshistory = newrecord;
+               else {
+                   for (posptr = poshistory; posptr->next != NULL;)
+                       posptr = posptr->next;
+                   posptr->next = newrecord;
                }
            }
-
            fclose(hist);
            free(line);
        }