Removing some code duplication.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5550 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2016-01-12 19:07:01 +00:00
parent 583b67bad2
commit cb832bef1b
2 changed files with 19 additions and 21 deletions

View File

@ -1,6 +1,7 @@
2016-01-12 Benno Schulenberg <bensberg@justemail.net> 2016-01-12 Benno Schulenberg <bensberg@justemail.net>
* NEWS: Fix some typos and whitespace, and normalize the dates. * NEWS: Fix some typos and whitespace, and normalize the dates.
* src/files.c (load_poshistory): Rename a variable. * 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 GNU nano 2.5.1 - 2016.01.11

View File

@ -3216,11 +3216,10 @@ void load_poshistory(void)
} else { } else {
char *line = NULL, *lineptr, *xptr; char *line = NULL, *lineptr, *xptr;
size_t buf_len = 0; size_t buf_len = 0;
ssize_t read, lineno, xno; ssize_t read;
poshiststruct *posptr; poshiststruct *posptr, *newrecord;
/* Read and parse each line, and put the data into the /* Read and parse each line, and store the extracted data. */
* positions history structure. */
while ((read = getline(&line, &buf_len, hist)) >= 0) { while ((read = getline(&line, &buf_len, hist)) >= 0) {
if (read > 0 && line[read - 1] == '\n') { if (read > 0 && line[read - 1] == '\n') {
read--; read--;
@ -3230,25 +3229,23 @@ void load_poshistory(void)
unsunder(line, read); unsunder(line, read);
lineptr = parse_next_word(line); lineptr = parse_next_word(line);
xptr = parse_next_word(lineptr); xptr = parse_next_word(lineptr);
lineno = atoi(lineptr);
xno = atoi(xptr); /* Create a new position record. */
if (poshistory == NULL) { newrecord = (poshiststruct *)nmalloc(sizeof(poshiststruct));
poshistory = (poshiststruct *)nmalloc(sizeof(poshiststruct)); newrecord->filename = mallocstrcpy(NULL, line);
poshistory->filename = mallocstrcpy(NULL, line); newrecord->lineno = atoi(lineptr);
poshistory->lineno = lineno; newrecord->xno = atoi(xptr);
poshistory->xno = xno; newrecord->next = NULL;
poshistory->next = NULL;
} else { /* Add the record to the list. */
for (posptr = poshistory; posptr->next != NULL; posptr = posptr->next) if (poshistory == NULL)
; poshistory = newrecord;
posptr->next = (poshiststruct *)nmalloc(sizeof(poshiststruct)); else {
posptr->next->filename = mallocstrcpy(NULL, line); for (posptr = poshistory; posptr->next != NULL;)
posptr->next->lineno = lineno; posptr = posptr->next;
posptr->next->xno = xno; posptr->next = newrecord;
posptr->next->next = NULL;
} }
} }
fclose(hist); fclose(hist);
free(line); free(line);
} }