tweaks: rename two variables, to be more indicative of what they do
parent
231fe4bf01
commit
7a9d010186
|
@ -294,35 +294,35 @@ int check_dotnano(void)
|
||||||
/* Load the search and replace histories from ~/.nano/search_history. */
|
/* Load the search and replace histories from ~/.nano/search_history. */
|
||||||
void load_history(void)
|
void load_history(void)
|
||||||
{
|
{
|
||||||
char *searchhist = histfilename();
|
char *histname = histfilename();
|
||||||
char *legacyhist = legacyhistfilename();
|
char *legacyhist = legacyhistfilename();
|
||||||
struct stat hstat;
|
struct stat hstat;
|
||||||
FILE *hist;
|
FILE *histfile;
|
||||||
|
|
||||||
/* If no home directory was found, we can't do anything. */
|
/* If no home directory was found, we can't do anything. */
|
||||||
if (searchhist == NULL || legacyhist == NULL)
|
if (histname == NULL || legacyhist == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* If there is an old history file, migrate it. */
|
/* If there is an old history file, migrate it. */
|
||||||
/* (To be removed in 2018.) */
|
/* (To be removed in 2018.) */
|
||||||
if (stat(legacyhist, &hstat) != -1 && stat(searchhist, &hstat) == -1) {
|
if (stat(legacyhist, &hstat) != -1 && stat(histname, &hstat) == -1) {
|
||||||
if (rename(legacyhist, searchhist) == -1)
|
if (rename(legacyhist, histname) == -1)
|
||||||
history_error(N_("Detected a legacy nano history file (%s) which I tried to move\n"
|
history_error(N_("Detected a legacy nano history file (%s) which I tried to move\n"
|
||||||
"to the preferred location (%s) but encountered an error: %s"),
|
"to the preferred location (%s) but encountered an error: %s"),
|
||||||
legacyhist, searchhist, strerror(errno));
|
legacyhist, histname, strerror(errno));
|
||||||
else
|
else
|
||||||
history_error(N_("Detected a legacy nano history file (%s) which I moved\n"
|
history_error(N_("Detected a legacy nano history file (%s) which I moved\n"
|
||||||
"to the preferred location (%s)\n(see the nano FAQ about this change)"),
|
"to the preferred location (%s)\n(see the nano FAQ about this change)"),
|
||||||
legacyhist, searchhist);
|
legacyhist, histname);
|
||||||
}
|
}
|
||||||
|
|
||||||
hist = fopen(searchhist, "rb");
|
histfile = fopen(histname, "rb");
|
||||||
|
|
||||||
if (hist == NULL) {
|
if (histfile == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
/* When reading failed, don't save history when we quit. */
|
/* When reading failed, don't save history when we quit. */
|
||||||
UNSET(HISTORYLOG);
|
UNSET(HISTORYLOG);
|
||||||
history_error(N_("Error reading %s: %s"), searchhist,
|
history_error(N_("Error reading %s: %s"), histname,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -334,7 +334,7 @@ void load_history(void)
|
||||||
size_t buf_len = 0;
|
size_t buf_len = 0;
|
||||||
ssize_t read;
|
ssize_t read;
|
||||||
|
|
||||||
while ((read = getline(&line, &buf_len, hist)) > 0) {
|
while ((read = getline(&line, &buf_len, histfile)) > 0) {
|
||||||
line[--read] = '\0';
|
line[--read] = '\0';
|
||||||
if (read > 0) {
|
if (read > 0) {
|
||||||
/* Encode any embedded NUL as 0x0A. */
|
/* Encode any embedded NUL as 0x0A. */
|
||||||
|
@ -347,14 +347,14 @@ void load_history(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(hist);
|
fclose(histfile);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* After reading them in, set the status of the lists to "unchanged". */
|
/* After reading them in, set the status of the lists to "unchanged". */
|
||||||
history_changed = FALSE;
|
history_changed = FALSE;
|
||||||
|
|
||||||
free(searchhist);
|
free(histname);
|
||||||
free(legacyhist);
|
free(legacyhist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,51 +382,51 @@ bool write_list(const filestruct *head, FILE *histfile)
|
||||||
/* 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 *searchhist;
|
char *histname;
|
||||||
FILE *hist;
|
FILE *histfile;
|
||||||
|
|
||||||
/* If the histories are unchanged, don't bother saving them. */
|
/* If the histories are unchanged, don't bother saving them. */
|
||||||
if (!history_changed)
|
if (!history_changed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
searchhist = histfilename();
|
histname = histfilename();
|
||||||
|
|
||||||
if (searchhist == NULL)
|
if (histname == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hist = fopen(searchhist, "wb");
|
histfile = fopen(histname, "wb");
|
||||||
|
|
||||||
if (hist == NULL)
|
if (histfile == NULL)
|
||||||
fprintf(stderr, _("Error writing %s: %s\n"), searchhist,
|
fprintf(stderr, _("Error writing %s: %s\n"), histname,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
else {
|
else {
|
||||||
/* Don't allow others to read or write the history file. */
|
/* Don't allow others to read or write the history file. */
|
||||||
chmod(searchhist, S_IRUSR | S_IWUSR);
|
chmod(histname, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
if (!write_list(searchtop, hist) || !write_list(replacetop, hist) ||
|
if (!write_list(searchtop, histfile) || !write_list(replacetop, histfile) ||
|
||||||
!write_list(executetop, hist))
|
!write_list(executetop, histfile))
|
||||||
fprintf(stderr, _("Error writing %s: %s\n"), searchhist,
|
fprintf(stderr, _("Error writing %s: %s\n"), histname,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
fclose(hist);
|
fclose(histfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(searchhist);
|
free(histname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load the recorded file positions from ~/.nano/filepos_history. */
|
/* Load the recorded file positions from ~/.nano/filepos_history. */
|
||||||
void load_poshistory(void)
|
void load_poshistory(void)
|
||||||
{
|
{
|
||||||
char *poshist = poshistfilename();
|
char *poshist = poshistfilename();
|
||||||
FILE *hist;
|
FILE *histfile;
|
||||||
|
|
||||||
/* If the home directory is missing, do_rcfile() will have reported it. */
|
/* If the home directory is missing, do_rcfile() will have reported it. */
|
||||||
if (poshist == NULL)
|
if (poshist == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hist = fopen(poshist, "rb");
|
histfile = fopen(poshist, "rb");
|
||||||
|
|
||||||
if (hist == NULL) {
|
if (histfile == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
/* When reading failed, don't save history when we quit. */
|
/* When reading failed, don't save history when we quit. */
|
||||||
UNSET(POS_HISTORY);
|
UNSET(POS_HISTORY);
|
||||||
|
@ -439,7 +439,7 @@ void load_poshistory(void)
|
||||||
poshiststruct *record_ptr = NULL, *newrecord;
|
poshiststruct *record_ptr = NULL, *newrecord;
|
||||||
|
|
||||||
/* Read and parse each line, and store the extracted data. */
|
/* Read and parse each line, and store the extracted data. */
|
||||||
while ((read = getline(&line, &buf_len, hist)) > 5) {
|
while ((read = getline(&line, &buf_len, histfile)) > 5) {
|
||||||
/* Decode nulls as embedded newlines. */
|
/* Decode nulls as embedded newlines. */
|
||||||
unsunder(line, read);
|
unsunder(line, read);
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ void load_poshistory(void)
|
||||||
free(drop_record);
|
free(drop_record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(hist);
|
fclose(histfile);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
free(poshist);
|
free(poshist);
|
||||||
|
@ -491,14 +491,14 @@ void save_poshistory(void)
|
||||||
{
|
{
|
||||||
char *poshist = poshistfilename();
|
char *poshist = poshistfilename();
|
||||||
poshiststruct *posptr;
|
poshiststruct *posptr;
|
||||||
FILE *hist;
|
FILE *histfile;
|
||||||
|
|
||||||
if (poshist == NULL)
|
if (poshist == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hist = fopen(poshist, "wb");
|
histfile = fopen(poshist, "wb");
|
||||||
|
|
||||||
if (hist == NULL)
|
if (histfile == NULL)
|
||||||
fprintf(stderr, _("Error writing %s: %s\n"), poshist, strerror(errno));
|
fprintf(stderr, _("Error writing %s: %s\n"), poshist, strerror(errno));
|
||||||
else {
|
else {
|
||||||
/* Don't allow others to read or write the history file. */
|
/* Don't allow others to read or write the history file. */
|
||||||
|
@ -520,12 +520,12 @@ void save_poshistory(void)
|
||||||
/* Restore the terminating newline. */
|
/* Restore the terminating newline. */
|
||||||
path_and_place[length - 1] = '\n';
|
path_and_place[length - 1] = '\n';
|
||||||
|
|
||||||
if (fwrite(path_and_place, sizeof(char), length, hist) < length)
|
if (fwrite(path_and_place, sizeof(char), length, histfile) < length)
|
||||||
fprintf(stderr, _("Error writing %s: %s\n"),
|
fprintf(stderr, _("Error writing %s: %s\n"),
|
||||||
poshist, strerror(errno));
|
poshist, strerror(errno));
|
||||||
free(path_and_place);
|
free(path_and_place);
|
||||||
}
|
}
|
||||||
fclose(hist);
|
fclose(histfile);
|
||||||
}
|
}
|
||||||
free(poshist);
|
free(poshist);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue