tweaks: reshuffle some code to harmonize two related functions
parent
b4fd08fa5e
commit
21a5978027
23
src/files.c
23
src/files.c
|
@ -2860,35 +2860,36 @@ bool writehist(FILE *hist, const filestruct *head)
|
||||||
/* Save the search and replace histories to ~/.nano/search_history. */
|
/* Save the search and replace histories to ~/.nano/search_history. */
|
||||||
void save_history(void)
|
void save_history(void)
|
||||||
{
|
{
|
||||||
char *nanohist;
|
char *searchhist;
|
||||||
|
FILE *hist;
|
||||||
|
|
||||||
/* Don't save unchanged or empty histories. */
|
/* Don't save unchanged or empty histories. */
|
||||||
if (!history_has_changed() || (searchbot->lineno == 1 &&
|
if (!history_has_changed() || (searchbot->lineno == 1 &&
|
||||||
replacebot->lineno == 1))
|
replacebot->lineno == 1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nanohist = histfilename();
|
searchhist = histfilename();
|
||||||
|
|
||||||
if (nanohist != NULL) {
|
if (searchhist == NULL)
|
||||||
FILE *hist = fopen(nanohist, "wb");
|
return;
|
||||||
|
|
||||||
|
hist = fopen(searchhist, "wb");
|
||||||
|
|
||||||
if (hist == NULL)
|
if (hist == NULL)
|
||||||
fprintf(stderr, _("Error writing %s: %s\n"), nanohist,
|
fprintf(stderr, _("Error writing %s: %s\n"), searchhist,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
else {
|
else {
|
||||||
/* Make sure no one else can read from or write to the
|
/* Don't allow others to read or write the history file. */
|
||||||
* history file. */
|
chmod(searchhist, S_IRUSR | S_IWUSR);
|
||||||
chmod(nanohist, S_IRUSR | S_IWUSR);
|
|
||||||
|
|
||||||
if (!writehist(hist, searchage) || !writehist(hist, replaceage))
|
if (!writehist(hist, searchage) || !writehist(hist, replaceage))
|
||||||
fprintf(stderr, _("Error writing %s: %s\n"), nanohist,
|
fprintf(stderr, _("Error writing %s: %s\n"), searchhist,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
fclose(hist);
|
fclose(hist);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(nanohist);
|
free(searchhist);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the recorded last file positions to ~/.nano/filepos_history. */
|
/* Save the recorded last file positions to ~/.nano/filepos_history. */
|
||||||
|
|
Loading…
Reference in New Issue