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
281a56fb
Commit
281a56fb
authored
8 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: reshuffle some things in a more linear manner
Also improve or correct some comments.
parent
592d0d6c
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/files.c
+21
-20
src/files.c
src/rcfile.c
+12
-18
src/rcfile.c
with
33 additions
and
38 deletions
+33
-38
src/files.c
View file @
281a56fb
...
...
@@ -947,13 +947,10 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
#endif
}
/* Open the file (and decide if it exists). If newfie is TRUE, display
* "New File" if the file is missing. Otherwise, say "[filename] not
* found".
*
/* Open the file with the given name. If the file does not exist, display
* "New File" if newfie is TRUE, and say "File not found" otherwise.
* Return -2 if we say "New File", -1 if the file isn't opened, and the
* fd opened otherwise. The file might still have an error while reading
* with a 0 return value. *f is set to the opened file. */
* obtained fd otherwise. *f is set to the opened file. */
int
open_file
(
const
char
*
filename
,
bool
newfie
,
bool
quiet
,
FILE
**
f
)
{
struct
stat
fileinfo
,
fileinfo2
;
...
...
@@ -972,31 +969,35 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
full_filename
=
mallocstrcpy
(
full_filename
,
filename
);
if
(
stat
(
full_filename
,
&
fileinfo
)
==
-
1
)
{
/* All cases below return. */
free
(
full_filename
);
if
(
newfie
)
{
if
(
!
quiet
)
statusbar
(
_
(
"New File"
));
free
(
full_filename
);
return
-
2
;
}
statusline
(
ALERT
,
_
(
"File
\"
%s
\"
not found"
),
filename
);
return
-
1
;
}
else
if
(
S_ISDIR
(
fileinfo
.
st_mode
)
||
S_ISCHR
(
fileinfo
.
st_mode
)
||
S_ISBLK
(
fileinfo
.
st_mode
))
{
free
(
full_filename
);
return
-
1
;
}
/* Don't open directories, character files, or block files. */
/* Don't open directories, character files, or block files. */
if
(
S_ISDIR
(
fileinfo
.
st_mode
)
||
S_ISCHR
(
fileinfo
.
st_mode
)
||
S_ISBLK
(
fileinfo
.
st_mode
))
{
statusline
(
ALERT
,
S_ISDIR
(
fileinfo
.
st_mode
)
?
_
(
"
\"
%s
\"
is a directory"
)
:
_
(
"
\"
%s
\"
is a device file"
),
filename
);
return
-
1
;
}
else
if
((
fd
=
open
(
full_filename
,
O_RDONLY
))
==
-
1
)
{
_
(
"
\"
%s
\"
is a directory"
)
:
_
(
"
\"
%s
\"
is a device file"
),
filename
);
free
(
full_filename
);
statusline
(
ALERT
,
_
(
"Error reading %s: %s"
),
filename
,
strerror
(
errno
));
return
-
1
;
}
else
{
/* The file is A-OK. Open it. */
}
/* Try opening the file. */
fd
=
open
(
full_filename
,
O_RDONLY
);
if
(
fd
==
-
1
)
statusline
(
ALERT
,
_
(
"Error reading %s: %s"
),
filename
,
strerror
(
errno
));
else
{
/* The file is A-OK. Associate a stream with it. */
*
f
=
fdopen
(
fd
,
"rb"
);
if
(
*
f
==
NULL
)
{
...
...
This diff is collapsed.
Click to expand it.
src/rcfile.c
View file @
281a56fb
...
...
@@ -533,28 +533,23 @@ static void parse_one_include(char *file)
struct
stat
rcinfo
;
FILE
*
rcstream
;
/* Can't get the specified file's full path because it may screw up
* our cwd depending on the parent directories' permissions (see
* Savannah bug #25297). */
/* Don't open directories, character files, or block files. */
if
(
stat
(
file
,
&
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"
),
file
);
}
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
);
}
/* Open the new syntax file. */
if
((
rcstream
=
fopen
(
file
,
"rb"
))
==
NULL
)
{
rcfile_error
(
_
(
"Error reading %s: %s"
),
file
,
strerror
(
errno
));
/* Open the included syntax file. */
rcstream
=
fopen
(
file
,
"rb"
);
if
(
rcstream
==
NULL
)
{
rcfile_error
(
_
(
"Error reading %s: %s"
),
file
,
strerror
(
errno
));
return
;
}
/* Use the name and line number position of the
new
syntax file
/* Use the name and line number position of the
included
syntax file
* while parsing it, so we can know where any errors in it are. */
nanorc
=
file
;
lineno
=
0
;
...
...
@@ -585,8 +580,7 @@ void parse_includes(char *ptr)
for
(
i
=
0
;
i
<
files
.
gl_pathc
;
++
i
)
parse_one_include
(
files
.
gl_pathv
[
i
]);
}
else
rcfile_error
(
_
(
"Error expanding %s: %s"
),
option
,
strerror
(
errno
));
rcfile_error
(
_
(
"Error expanding %s: %s"
),
option
,
strerror
(
errno
));
globfree
(
&
files
);
free
(
expanded
);
...
...
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