tweaks: elide a parameter, as it's always the inverse of another

master
Benno Schulenberg 2018-03-22 10:41:39 +01:00
parent f4d1ef1c4e
commit b9de5525c4
4 changed files with 11 additions and 15 deletions

View File

@ -476,7 +476,7 @@ bool open_buffer(const char *filename, bool new_buffer)
/* If we have a non-new file, read it in. Then, if the buffer has /* If we have a non-new file, read it in. Then, if the buffer has
* no stat, update the stat, if applicable. */ * no stat, update the stat, if applicable. */
if (rc > 0) { if (rc > 0) {
read_file(f, rc, realname, !new_buffer, new_buffer); read_file(f, rc, realname, !new_buffer);
#ifndef NANO_TINY #ifndef NANO_TINY
if (openfile->current_stat == NULL) if (openfile->current_stat == NULL)
stat_with_alloc(realname, &openfile->current_stat); stat_with_alloc(realname, &openfile->current_stat);
@ -522,7 +522,7 @@ void replace_buffer(const char *filename)
initialize_buffer_text(); initialize_buffer_text();
/* Insert the processed file into its place. */ /* Insert the processed file into its place. */
read_file(f, descriptor, filename, FALSE, TRUE); read_file(f, descriptor, filename, FALSE);
/* Put current at a place that is certain to exist. */ /* Put current at a place that is certain to exist. */
openfile->current = openfile->fileage; openfile->current = openfile->fileage;
@ -553,7 +553,7 @@ void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x,
* where the marked text was. */ * where the marked text was. */
extract_buffer(&trash_top, &trash_bot, top, top_x, bot, bot_x); extract_buffer(&trash_top, &trash_bot, top, top_x, bot, bot_x);
free_filestruct(trash_top); free_filestruct(trash_top);
read_file(f, descriptor, filename, FALSE, TRUE); read_file(f, descriptor, filename, FALSE);
/* Restore the magicline behavior now that we're done fiddling. */ /* Restore the magicline behavior now that we're done fiddling. */
if (!old_no_newlines) if (!old_no_newlines)
@ -710,13 +710,10 @@ char *encode_data(char *buf, size_t buf_len)
return mallocstrcpy(NULL, buf); return mallocstrcpy(NULL, buf);
} }
/* Read an open file into the current buffer. f should be set to the /* Read the given open file f into the current buffer. filename should be
* open file, and filename should be set to the name of the file. * set to the name of the file. undoable means that undo records should be
* undoable means do we want to create undo records to try and undo * created and that the file does not need to be checked for writability. */
* this. Will also attempt to check file writability if fd > 0 and void read_file(FILE *f, int fd, const char *filename, bool undoable)
* checkwritable == TRUE. */
void read_file(FILE *f, int fd, const char *filename, bool undoable,
bool checkwritable)
{ {
ssize_t was_lineno = openfile->current->lineno; ssize_t was_lineno = openfile->current->lineno;
/* The line number where we start the insertion. */ /* The line number where we start the insertion. */
@ -832,7 +829,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable,
if (ferror(f)) if (ferror(f))
nperror(filename); nperror(filename);
fclose(f); fclose(f);
if (fd > 0 && checkwritable) { if (fd > 0 && !undoable) {
close(fd); close(fd);
writable = is_file_writable(filename); writable = is_file_writable(filename);
} }

View File

@ -1171,7 +1171,7 @@ bool scoop_stdin(void)
/* Read the input into a new buffer. */ /* Read the input into a new buffer. */
open_buffer("", TRUE); open_buffer("", TRUE);
read_file(stream, 0, "stdin", TRUE, FALSE); read_file(stream, 0, "stdin", TRUE);
openfile->edittop = openfile->fileage; openfile->edittop = openfile->fileage;
/* Reconnect the tty as the input source. */ /* Reconnect the tty as the input source. */

View File

@ -281,8 +281,7 @@ void switch_to_prev_buffer(void);
void switch_to_next_buffer(void); void switch_to_next_buffer(void);
bool close_buffer(void); bool close_buffer(void);
#endif #endif
void read_file(FILE *f, int fd, const char *filename, bool undoable, void read_file(FILE *f, int fd, const char *filename, bool undoable);
bool checkwritable);
int open_file(const char *filename, bool newfie, bool quiet, FILE **f); int open_file(const char *filename, bool newfie, bool quiet, FILE **f);
char *get_next_filename(const char *name, const char *suffix); char *get_next_filename(const char *name, const char *suffix);
void do_insertfile_void(void); void do_insertfile_void(void);

View File

@ -1149,7 +1149,7 @@ bool execute_command(const char *command)
if (f == NULL) if (f == NULL)
nperror("fdopen"); nperror("fdopen");
read_file(f, 0, "stdin", TRUE, FALSE); read_file(f, 0, "stdin", TRUE);
if (wait(NULL) == -1) if (wait(NULL) == -1)
nperror("wait"); nperror("wait");