tweaks: slightly shorten a loop, to place the actual action outside of it
And in the bargain elide a variable, and make it clearer what the return value is at two early exit points. [This change makes use of the fact that TRUE (successful write) == 1 and FALSE (failed write) == 0. But this is already used twenty lines earlier, for the other call of write_file().]
Этот коммит содержится в:
родитель
300f67d78f
Коммит
f660f22623
23
src/files.c
23
src/files.c
@ -2043,7 +2043,6 @@ bool write_marked_file(const char *name, FILE *stream, bool tmp,
|
|||||||
* the buffer is to be discarded. */
|
* the buffer is to be discarded. */
|
||||||
int do_writeout(bool exiting, bool withprompt)
|
int do_writeout(bool exiting, bool withprompt)
|
||||||
{
|
{
|
||||||
bool result = FALSE;
|
|
||||||
kind_of_writing_type method = OVERWRITE;
|
kind_of_writing_type method = OVERWRITE;
|
||||||
char *given;
|
char *given;
|
||||||
/* The filename we offer, or what the user typed so far. */
|
/* The filename we offer, or what the user typed so far. */
|
||||||
@ -2105,7 +2104,8 @@ int do_writeout(bool exiting, bool withprompt)
|
|||||||
|
|
||||||
if (response < 0) {
|
if (response < 0) {
|
||||||
statusbar(_("Cancelled"));
|
statusbar(_("Cancelled"));
|
||||||
break;
|
free(given);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
func = func_from_key(&response);
|
func = func_from_key(&response);
|
||||||
@ -2163,7 +2163,9 @@ int do_writeout(bool exiting, bool withprompt)
|
|||||||
} else
|
} else
|
||||||
/* TRANSLATORS: Concisely say the screen is too small. */
|
/* TRANSLATORS: Concisely say the screen is too small. */
|
||||||
statusbar(_("Too tiny"));
|
statusbar(_("Too tiny"));
|
||||||
break;
|
|
||||||
|
free(given);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2262,23 +2264,20 @@ int do_writeout(bool exiting, bool withprompt)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(given);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Here's where we allow the selected text to be written to
|
/* Here's where we allow the selected text to be written to
|
||||||
* a separate file. If we're using restricted mode, this
|
* a separate file. If we're using restricted mode, this
|
||||||
* function is disabled, since it allows reading from or
|
* function is disabled, since it allows reading from or
|
||||||
* writing to files not specified on the command line. */
|
* writing to files not specified on the command line. */
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (openfile->mark && !exiting && withprompt && !ISSET(RESTRICTED))
|
if (openfile->mark && !exiting && withprompt && !ISSET(RESTRICTED))
|
||||||
result = write_marked_file(answer, NULL, FALSE, method);
|
return write_marked_file(answer, NULL, FALSE, method);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
result = write_file(answer, NULL, FALSE, method, TRUE);
|
return write_file(answer, NULL, FALSE, method, TRUE);
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(given);
|
|
||||||
|
|
||||||
return result ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the current buffer to disk, or discard it. */
|
/* Write the current buffer to disk, or discard it. */
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user