Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
git_rec_nano
Commits
7a9d0101
Commit
7a9d0101
authored
7 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: rename two variables, to be more indicative of what they do
parent
231fe4bf
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/history.c
+36
-36
src/history.c
with
36 additions
and
36 deletions
+36
-36
src/history.c
View file @
7a9d0101
...
...
@@ -294,35 +294,35 @@ int check_dotnano(void)
/* Load the search and replace histories from ~/.nano/search_history. */
void
load_history
(
void
)
{
char
*
search
hist
=
histfilename
();
char
*
hist
name
=
histfilename
();
char
*
legacyhist
=
legacyhistfilename
();
struct
stat
hstat
;
FILE
*
hist
;
FILE
*
hist
file
;
/* If no home directory was found, we can't do anything. */
if
(
search
hist
==
NULL
||
legacyhist
==
NULL
)
if
(
hist
name
==
NULL
||
legacyhist
==
NULL
)
return
;
/* If there is an old history file, migrate it. */
/* (To be removed in 2018.) */
if
(
stat
(
legacyhist
,
&
hstat
)
!=
-
1
&&
stat
(
search
hist
,
&
hstat
)
==
-
1
)
{
if
(
rename
(
legacyhist
,
search
hist
)
==
-
1
)
if
(
stat
(
legacyhist
,
&
hstat
)
!=
-
1
&&
stat
(
hist
name
,
&
hstat
)
==
-
1
)
{
if
(
rename
(
legacyhist
,
hist
name
)
==
-
1
)
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"
),
legacyhist
,
search
hist
,
strerror
(
errno
));
legacyhist
,
hist
name
,
strerror
(
errno
));
else
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)"
),
legacyhist
,
search
hist
);
legacyhist
,
hist
name
);
}
hist
=
fopen
(
search
hist
,
"rb"
);
hist
file
=
fopen
(
hist
name
,
"rb"
);
if
(
hist
==
NULL
)
{
if
(
hist
file
==
NULL
)
{
if
(
errno
!=
ENOENT
)
{
/* When reading failed, don't save history when we quit. */
UNSET
(
HISTORYLOG
);
history_error
(
N_
(
"Error reading %s: %s"
),
search
hist
,
history_error
(
N_
(
"Error reading %s: %s"
),
hist
name
,
strerror
(
errno
));
}
}
else
{
...
...
@@ -334,7 +334,7 @@ void load_history(void)
size_t
buf_len
=
0
;
ssize_t
read
;
while
((
read
=
getline
(
&
line
,
&
buf_len
,
hist
))
>
0
)
{
while
((
read
=
getline
(
&
line
,
&
buf_len
,
hist
file
))
>
0
)
{
line
[
--
read
]
=
'\0'
;
if
(
read
>
0
)
{
/* Encode any embedded NUL as 0x0A. */
...
...
@@ -347,14 +347,14 @@ void load_history(void)
}
fclose
(
hist
);
fclose
(
hist
file
);
free
(
line
);
}
/* After reading them in, set the status of the lists to "unchanged". */
history_changed
=
FALSE
;
free
(
search
hist
);
free
(
hist
name
);
free
(
legacyhist
);
}
...
...
@@ -382,51 +382,51 @@ bool write_list(const filestruct *head, FILE *histfile)
/* Save the search and replace histories to ~/.nano/search_history. */
void
save_history
(
void
)
{
char
*
search
hist
;
FILE
*
hist
;
char
*
hist
name
;
FILE
*
hist
file
;
/* If the histories are unchanged, don't bother saving them. */
if
(
!
history_changed
)
return
;
search
hist
=
histfilename
();
hist
name
=
histfilename
();
if
(
search
hist
==
NULL
)
if
(
hist
name
==
NULL
)
return
;
hist
=
fopen
(
search
hist
,
"wb"
);
hist
file
=
fopen
(
hist
name
,
"wb"
);
if
(
hist
==
NULL
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
search
hist
,
if
(
hist
file
==
NULL
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
hist
name
,
strerror
(
errno
));
else
{
/* Don't allow others to read or write the history file. */
chmod
(
search
hist
,
S_IRUSR
|
S_IWUSR
);
chmod
(
hist
name
,
S_IRUSR
|
S_IWUSR
);
if
(
!
write_list
(
searchtop
,
hist
)
||
!
write_list
(
replacetop
,
hist
)
||
!
write_list
(
executetop
,
hist
))
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
search
hist
,
if
(
!
write_list
(
searchtop
,
hist
file
)
||
!
write_list
(
replacetop
,
hist
file
)
||
!
write_list
(
executetop
,
hist
file
))
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
hist
name
,
strerror
(
errno
));
fclose
(
hist
);
fclose
(
hist
file
);
}
free
(
search
hist
);
free
(
hist
name
);
}
/* Load the recorded file positions from ~/.nano/filepos_history. */
void
load_poshistory
(
void
)
{
char
*
poshist
=
poshistfilename
();
FILE
*
hist
;
FILE
*
hist
file
;
/* If the home directory is missing, do_rcfile() will have reported it. */
if
(
poshist
==
NULL
)
return
;
hist
=
fopen
(
poshist
,
"rb"
);
hist
file
=
fopen
(
poshist
,
"rb"
);
if
(
hist
==
NULL
)
{
if
(
hist
file
==
NULL
)
{
if
(
errno
!=
ENOENT
)
{
/* When reading failed, don't save history when we quit. */
UNSET
(
POS_HISTORY
);
...
...
@@ -439,7 +439,7 @@ void load_poshistory(void)
poshiststruct
*
record_ptr
=
NULL
,
*
newrecord
;
/* Read and parse each line, and store the extracted data. */
while
((
read
=
getline
(
&
line
,
&
buf_len
,
hist
))
>
5
)
{
while
((
read
=
getline
(
&
line
,
&
buf_len
,
hist
file
))
>
5
)
{
/* Decode nulls as embedded newlines. */
unsunder
(
line
,
read
);
...
...
@@ -480,7 +480,7 @@ void load_poshistory(void)
free
(
drop_record
);
}
}
fclose
(
hist
);
fclose
(
hist
file
);
free
(
line
);
}
free
(
poshist
);
...
...
@@ -491,14 +491,14 @@ void save_poshistory(void)
{
char
*
poshist
=
poshistfilename
();
poshiststruct
*
posptr
;
FILE
*
hist
;
FILE
*
hist
file
;
if
(
poshist
==
NULL
)
return
;
hist
=
fopen
(
poshist
,
"wb"
);
hist
file
=
fopen
(
poshist
,
"wb"
);
if
(
hist
==
NULL
)
if
(
hist
file
==
NULL
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
poshist
,
strerror
(
errno
));
else
{
/* Don't allow others to read or write the history file. */
...
...
@@ -520,12 +520,12 @@ void save_poshistory(void)
/* Restore the terminating newline. */
path_and_place
[
length
-
1
]
=
'\n'
;
if
(
fwrite
(
path_and_place
,
sizeof
(
char
),
length
,
hist
)
<
length
)
if
(
fwrite
(
path_and_place
,
sizeof
(
char
),
length
,
hist
file
)
<
length
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
poshist
,
strerror
(
errno
));
free
(
path_and_place
);
}
fclose
(
hist
);
fclose
(
hist
file
);
}
free
(
poshist
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help