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
5f4fb8e5
Commit
5f4fb8e5
authored
7 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: frob some comments and rename a few variables and a function
parent
7a9d0101
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/history.c
+37
-37
src/history.c
src/nano.c
+9
-5
src/nano.c
src/proto.h
+1
-1
src/proto.h
with
47 additions
and
43 deletions
+47
-43
src/history.c
View file @
5f4fb8e5
...
...
@@ -26,9 +26,10 @@
#ifndef DISABLE_HISTORIES
static
bool
history_changed
=
FALSE
;
/*
Have
any of the history lists changed
?
*/
/*
Whether
any of the history lists
has
changed
.
*/
/* Initialize the search and replace history lists. */
/* Initialize the lists of historical search and replace strings
* and the list of historical executed commands. */
void
history_init
(
void
)
{
search_history
=
make_new_node
(
NULL
);
...
...
@@ -47,52 +48,52 @@ void history_init(void)
executebot
=
execute_history
;
}
/* Set the current position in the history list
h
to the bottom. */
void
history_reset
(
const
filestruct
*
h
)
/* Set the current position in the
given
history list to the bottom. */
void
history_reset
(
const
filestruct
*
list
)
{
if
(
h
==
search_history
)
if
(
list
==
search_history
)
search_history
=
searchbot
;
else
if
(
h
==
replace_history
)
else
if
(
list
==
replace_history
)
replace_history
=
replacebot
;
else
if
(
h
==
execute_history
)
else
if
(
list
==
execute_history
)
execute_history
=
executebot
;
}
/* Return
the first node containing the first len characters of the
*
string s
in the
history list, starting at h_start and ending at
*
h_end
, or NULL if there is
n't on
e. */
filestruct
*
find_history
(
const
filestruct
*
h_
start
,
const
filestruct
*
h_end
,
const
char
*
s
,
size_t
len
)
/* Return
from the history list that starts at start and ends at end
*
the first node that conta
in
s
the
first len characters of the given
*
text
, or NULL if there is
no such nod
e. */
filestruct
*
find_history
(
const
filestruct
*
start
,
const
filestruct
*
end
,
const
char
*
text
,
size_t
len
)
{
const
filestruct
*
p
;
const
filestruct
*
item
;
for
(
p
=
h_
start
;
p
!=
h_
end
->
prev
&&
p
!=
NULL
;
p
=
p
->
prev
)
{
if
(
strncmp
(
s
,
p
->
data
,
len
)
==
0
)
return
(
filestruct
*
)
p
;
for
(
item
=
start
;
item
!=
end
->
prev
&&
item
!=
NULL
;
item
=
item
->
prev
)
{
if
(
strncmp
(
item
->
data
,
text
,
len
)
==
0
)
return
(
filestruct
*
)
item
;
}
return
NULL
;
}
/* Update a history list (the one in which
h
is the current position)
* with a fresh string
s
. That is: add
s
, or move it to the end. */
void
update_history
(
filestruct
**
h
,
const
char
*
s
)
/* Update a history list (the one in which
item
is the current position)
* with a fresh string
text
. That is: add
text
, or move it to the end. */
void
update_history
(
filestruct
**
item
,
const
char
*
text
)
{
filestruct
**
htop
=
NULL
,
**
hbot
=
NULL
,
*
thesame
;
if
(
*
h
==
search_history
)
{
if
(
*
item
==
search_history
)
{
htop
=
&
searchtop
;
hbot
=
&
searchbot
;
}
else
if
(
*
h
==
replace_history
)
{
}
else
if
(
*
item
==
replace_history
)
{
htop
=
&
replacetop
;
hbot
=
&
replacebot
;
}
else
if
(
*
h
==
execute_history
)
{
}
else
if
(
*
item
==
execute_history
)
{
htop
=
&
executetop
;
hbot
=
&
executebot
;
}
/* See if the string is already in the history. */
thesame
=
find_history
(
*
hbot
,
*
htop
,
s
,
HIGHEST_POSITIVE
);
thesame
=
find_history
(
*
hbot
,
*
htop
,
text
,
HIGHEST_POSITIVE
);
/* If an identical string was found, delete that item. */
if
(
thesame
!=
NULL
)
{
...
...
@@ -117,7 +118,7 @@ void update_history(filestruct **h, const char *s)
}
/* Store the fresh string in the last item, then create a new item. */
(
*
hbot
)
->
data
=
mallocstrcpy
((
*
hbot
)
->
data
,
s
);
(
*
hbot
)
->
data
=
mallocstrcpy
((
*
hbot
)
->
data
,
text
);
splice_node
(
*
hbot
,
make_new_node
(
*
hbot
));
*
hbot
=
(
*
hbot
)
->
next
;
(
*
hbot
)
->
data
=
mallocstrcpy
(
NULL
,
""
);
...
...
@@ -126,7 +127,7 @@ void update_history(filestruct **h, const char *s)
history_changed
=
TRUE
;
/* Set the current position in the list to the bottom. */
*
h
=
*
hbot
;
*
item
=
*
hbot
;
}
/* Move h to the string in the history list just before it, and return
...
...
@@ -262,12 +263,11 @@ void history_error(const char *msg, ...)
;
}
/* Now that we have more than one history file, let's just rely on a
* .nano dir for this stuff. Return 1 if the dir exists or was
* successfully created, and return 0 otherwise. */
int
check_dotnano
(
void
)
/* Check whether the ~/.nano subdirectory for history files exists. Return
* TRUE if it exists or was successfully created, and FALSE otherwise. */
bool
have_dotnano
(
void
)
{
int
ret
=
1
;
bool
retval
=
TRUE
;
struct
stat
dirstat
;
char
*
nanodir
=
construct_filename
(
"/.nano"
);
...
...
@@ -277,21 +277,21 @@ int check_dotnano(void)
"It is required for saving/loading "
"search history or cursor positions.
\n
"
),
nanodir
,
strerror
(
errno
));
ret
=
0
;
ret
val
=
FALSE
;
}
}
else
if
(
!
S_ISDIR
(
dirstat
.
st_mode
))
{
history_error
(
N_
(
"Path %s is not a directory and needs to be.
\n
"
"Nano will be unable to load or save "
"search history or cursor positions.
\n
"
),
nanodir
);
ret
=
0
;
ret
val
=
FALSE
;
}
free
(
nanodir
);
return
ret
;
return
ret
val
;
}
/* Load the
s
earch and
r
eplace
histories from ~/.nano/search_history
. */
/* Load the
histories for S
earch and
R
eplace
and Execute Command
. */
void
load_history
(
void
)
{
char
*
histname
=
histfilename
();
...
...
@@ -379,7 +379,7 @@ bool write_list(const filestruct *head, FILE *histfile)
return
TRUE
;
}
/* Save the
s
earch and
r
eplace
histories to ~/.nano/search_history
. */
/* Save the
histories for S
earch and
R
eplace
and Execute Command
. */
void
save_history
(
void
)
{
char
*
histname
;
...
...
@@ -414,7 +414,7 @@ void save_history(void)
free
(
histname
);
}
/* Load the recorded
file
positions f
rom ~/.nano/filepos_history
. */
/* Load the recorded
cursor
positions f
or files that were edited
. */
void
load_poshistory
(
void
)
{
char
*
poshist
=
poshistfilename
();
...
...
@@ -486,7 +486,7 @@ void load_poshistory(void)
free
(
poshist
);
}
/* Save the recorded
last file
positions
to ~/.nano/filepos_history
. */
/* Save the recorded
cursor
positions
for files that were edited
. */
void
save_poshistory
(
void
)
{
char
*
poshist
=
poshistfilename
();
...
...
This diff is collapsed.
Click to expand it.
src/nano.c
View file @
5f4fb8e5
...
...
@@ -565,6 +565,7 @@ void finish(void)
tcsetattr
(
0
,
TCSANOW
,
&
oldterm
);
#ifndef DISABLE_HISTORIES
/* If the user wants history persistence, write the relevant files. */
if
(
ISSET
(
HISTORYLOG
))
save_history
();
if
(
ISSET
(
POS_HISTORY
))
{
...
...
@@ -2364,22 +2365,25 @@ int main(int argc, char **argv)
UNSET
(
NO_WRAP
);
#endif
/* If we're using bold text instead of reverse video text, set it up
* now. */
/* If the user wants bold instead of reverse video for hilited text... */
if
(
ISSET
(
BOLD_TEXT
))
hilite_attribute
=
A_BOLD
;
#ifndef DISABLE_HISTORIES
/*
Set up
the
s
earch/
r
eplace histor
y
. */
/*
Initialize the pointers for
the
S
earch/
R
eplace
/Execute
histor
ies
. */
history_init
();
/* Verify that the home directory and ~/.nano subdir exist. */
/* If we need any of the history files, verify that the user's home
* directory and its .nano subdirctory exist. */
if
(
ISSET
(
HISTORYLOG
)
||
ISSET
(
POS_HISTORY
))
{
get_homedir
();
if
(
homedir
==
NULL
||
check
_dotnano
()
==
0
)
{
if
(
homedir
==
NULL
||
!
have
_dotnano
())
{
UNSET
(
HISTORYLOG
);
UNSET
(
POS_HISTORY
);
}
}
/* If the user wants history persistence, read the relevant files. */
if
(
ISSET
(
HISTORYLOG
))
load_history
();
if
(
ISSET
(
POS_HISTORY
))
...
...
This diff is collapsed.
Click to expand it.
src/proto.h
View file @
5f4fb8e5
...
...
@@ -366,7 +366,7 @@ void get_history_newer_void(void);
#ifdef ENABLE_TABCOMP
char
*
get_history_completion
(
filestruct
**
h
,
char
*
s
,
size_t
len
);
#endif
int
check
_dotnano
(
void
);
bool
have
_dotnano
(
void
);
void
load_history
(
void
);
void
save_history
(
void
);
void
load_poshistory
(
void
);
...
...
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