Reducing the number of indentation steps.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5554 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2016-01-12 20:26:59 +00:00
parent 774c8ba1bf
commit 96b9249f91
2 changed files with 44 additions and 42 deletions

View File

@ -6,6 +6,7 @@
load_poshistory): Differentiate variable name from function names. load_poshistory): Differentiate variable name from function names.
* src/files.c (load_poshistory): Remove a senseless iteration. * src/files.c (load_poshistory): Remove a senseless iteration.
* src/files.c (load_poshistory): Condense the reading of a line. * src/files.c (load_poshistory): Condense the reading of a line.
* src/files.c (load_poshistory): Reduce the indentation.
GNU nano 2.5.1 - 2016.01.11 GNU nano 2.5.1 - 2016.01.11

View File

@ -3201,52 +3201,53 @@ int check_poshistory(const char *file, ssize_t *line, ssize_t *column)
void load_poshistory(void) void load_poshistory(void)
{ {
char *poshist = poshistfilename(); char *poshist = poshistfilename();
FILE *hist;
/* Assume do_rcfile() has reported a missing home directory. */ /* If the home directory is missing, do_rcfile() will have reported it. */
if (poshist != NULL) { if (poshist == NULL)
FILE *hist = fopen(poshist, "rb"); return;
if (hist == NULL) { hist = fopen(poshist, "rb");
if (errno != ENOENT) {
/* Don't save history when we quit. */
UNSET(POS_HISTORY);
history_error(N_("Error reading %s: %s"), poshist,
strerror(errno));
}
} else {
char *line = NULL, *lineptr, *xptr;
size_t buf_len = 0;
ssize_t read;
poshiststruct *record_ptr = NULL, *newrecord;
/* Read and parse each line, and store the extracted data. */ if (hist == NULL) {
while ((read = getline(&line, &buf_len, hist)) > 2) { if (errno != ENOENT) {
if (line[read - 1] == '\n') /* When reading failed, don't save history when we quit. */
line[--read] = '\0'; UNSET(POS_HISTORY);
unsunder(line, read); history_error(N_("Error reading %s: %s"), poshist, strerror(errno));
lineptr = parse_next_word(line);
xptr = parse_next_word(lineptr);
/* 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 (position_history == NULL)
position_history = newrecord;
else
record_ptr->next = newrecord;
record_ptr = newrecord;
}
fclose(hist);
free(line);
} }
free(poshist); } else {
char *line = NULL, *lineptr, *xptr;
size_t buf_len = 0;
ssize_t read;
poshiststruct *record_ptr = NULL, *newrecord;
/* Read and parse each line, and store the extracted data. */
while ((read = getline(&line, &buf_len, hist)) > 2) {
if (line[read - 1] == '\n')
line[--read] = '\0';
unsunder(line, read);
lineptr = parse_next_word(line);
xptr = parse_next_word(lineptr);
/* 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 (position_history == NULL)
position_history = newrecord;
else
record_ptr->next = newrecord;
record_ptr = newrecord;
}
fclose(hist);
free(line);
} }
free(poshist);
} }
#endif /* !DISABLE_HISTORIES */ #endif /* !DISABLE_HISTORIES */