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
981a1d39
Commit
981a1d39
authored
8 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: factor out a small function
parent
925a0016
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/rcfile.c
+22
-24
src/rcfile.c
with
22 additions
and
24 deletions
+22
-24
src/rcfile.c
View file @
981a1d39
...
...
@@ -530,21 +530,30 @@ void parse_binding(char *ptr, bool dobind)
free
(
keycopy
);
}
/* Verify that the given file is not a folder nor a device. */
bool
is_good_file
(
char
*
file
)
{
struct
stat
rcinfo
;
/* If the thing exists, it may not be a directory nor a device. */
if
(
stat
(
file
,
&
rcinfo
)
!=
-
1
&&
(
S_ISDIR
(
rcinfo
.
st_mode
)
||
S_ISCHR
(
rcinfo
.
st_mode
)
||
S_ISBLK
(
rcinfo
.
st_mode
)))
{
rcfile_error
(
S_ISDIR
(
rcinfo
.
st_mode
)
?
_
(
"
\"
%s
\"
is a directory"
)
:
_
(
"
\"
%s
\"
is a device file"
),
file
);
return
FALSE
;
}
else
return
TRUE
;
}
#ifndef DISABLE_COLOR
/* Read and parse one included syntax file. */
static
void
parse_one_include
(
char
*
file
)
{
struct
stat
rcinfo
;
FILE
*
rcstream
;
/* Don't open directories, character files, or block files. */
if
(
stat
(
file
,
&
rcinfo
)
!=
-
1
&&
(
S_ISDIR
(
rcinfo
.
st_mode
)
||
S_ISCHR
(
rcinfo
.
st_mode
)
||
S_ISBLK
(
rcinfo
.
st_mode
)))
{
rcfile_error
(
S_ISDIR
(
rcinfo
.
st_mode
)
?
_
(
"
\"
%s
\"
is a directory"
)
:
_
(
"
\"
%s
\"
is a device file"
),
file
);
if
(
!
is_good_file
(
file
))
return
;
}
/* Open the included syntax file. */
rcstream
=
fopen
(
file
,
"rb"
);
...
...
@@ -1226,19 +1235,13 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
/* First read the system-wide rcfile, then the user's rcfile. */
void
do_rcfile
(
void
)
{
struct
stat
rcinfo
;
FILE
*
rcstream
;
nanorc
=
mallocstrcpy
(
nanorc
,
SYSCONFDIR
"/nanorc"
);
/* Don't open directories, character files, or block files. */
if
(
stat
(
nanorc
,
&
rcinfo
)
!=
-
1
)
{
if
(
S_ISDIR
(
rcinfo
.
st_mode
)
||
S_ISCHR
(
rcinfo
.
st_mode
)
||
S_ISBLK
(
rcinfo
.
st_mode
))
rcfile_error
(
S_ISDIR
(
rcinfo
.
st_mode
)
?
_
(
"
\"
%s
\"
is a directory"
)
:
_
(
"
\"
%s
\"
is a device file"
),
nanorc
);
}
/* Warn about directories, character files, or block files. */
if
(
!
is_good_file
(
nanorc
))
;
#ifdef DEBUG
fprintf
(
stderr
,
"Parsing file
\"
%s
\"\n
"
,
nanorc
);
...
...
@@ -1264,14 +1267,9 @@ void do_rcfile(void)
nanorc
=
charealloc
(
nanorc
,
strlen
(
homedir
)
+
strlen
(
RCFILE_NAME
)
+
2
);
sprintf
(
nanorc
,
"%s/%s"
,
homedir
,
RCFILE_NAME
);
/* Don't open directories, character files, or block files. */
if
(
stat
(
nanorc
,
&
rcinfo
)
!=
-
1
)
{
if
(
S_ISDIR
(
rcinfo
.
st_mode
)
||
S_ISCHR
(
rcinfo
.
st_mode
)
||
S_ISBLK
(
rcinfo
.
st_mode
))
rcfile_error
(
S_ISDIR
(
rcinfo
.
st_mode
)
?
_
(
"
\"
%s
\"
is a directory"
)
:
_
(
"
\"
%s
\"
is a device file"
),
nanorc
);
}
/* Warn about directories, character files, or block files. */
if
(
!
is_good_file
(
nanorc
))
;
/* Try to open the current user's nanorc. */
rcstream
=
fopen
(
nanorc
,
"rb"
);
...
...
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