tweaks: rename a variable and a type, to be less confusing
This commit is contained in:
44
src/files.c
44
src/files.c
@@ -1695,15 +1695,15 @@ int copy_file(FILE *inn, FILE *out)
|
|||||||
*
|
*
|
||||||
* tmp means we are writing a temporary file in a secure fashion. We
|
* tmp means we are writing a temporary file in a secure fashion. We
|
||||||
* use it when spell checking or dumping the file on an error. If
|
* use it when spell checking or dumping the file on an error. If
|
||||||
* append is APPEND, it means we are appending instead of overwriting.
|
* method is APPEND, it means we are appending instead of overwriting.
|
||||||
* If append is PREPEND, it means we are prepending instead of
|
* If method is PREPEND, it means we are prepending instead of
|
||||||
* overwriting. If nonamechange is TRUE, we don't change the current
|
* overwriting. If nonamechange is TRUE, we don't change the current
|
||||||
* filename. nonamechange is ignored if tmp is FALSE, we're appending,
|
* filename. nonamechange is ignored if tmp is FALSE, we're appending,
|
||||||
* or we're prepending.
|
* or we're prepending.
|
||||||
*
|
*
|
||||||
* Return TRUE on success or FALSE on error. */
|
* Return TRUE on success or FALSE on error. */
|
||||||
bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
bool write_file(const char *name, FILE *f_open, bool tmp,
|
||||||
append, bool nonamechange)
|
kind_of_writing_type method, bool nonamechange)
|
||||||
{
|
{
|
||||||
bool retval = FALSE;
|
bool retval = FALSE;
|
||||||
/* Instead of returning in this function, you should always
|
/* Instead of returning in this function, you should always
|
||||||
@@ -1769,7 +1769,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||||||
* only if the file has not been modified by someone else since nano
|
* only if the file has not been modified by someone else since nano
|
||||||
* opened it. */
|
* opened it. */
|
||||||
if (ISSET(BACKUP_FILE) && !tmp && realexists && openfile->current_stat &&
|
if (ISSET(BACKUP_FILE) && !tmp && realexists && openfile->current_stat &&
|
||||||
(append != OVERWRITE || openfile->mark_set ||
|
(method != OVERWRITE || openfile->mark_set ||
|
||||||
openfile->current_stat->st_mtime == st.st_mtime)) {
|
openfile->current_stat->st_mtime == st.st_mtime)) {
|
||||||
int backup_fd;
|
int backup_fd;
|
||||||
FILE *backup_file;
|
FILE *backup_file;
|
||||||
@@ -1948,7 +1948,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If we're prepending, copy the file to a temp file. */
|
/* If we're prepending, copy the file to a temp file. */
|
||||||
if (append == PREPEND) {
|
if (method == PREPEND) {
|
||||||
int fd_source;
|
int fd_source;
|
||||||
FILE *f_source = NULL;
|
FILE *f_source = NULL;
|
||||||
|
|
||||||
@@ -1997,7 +1997,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||||||
if (f_open == NULL) {
|
if (f_open == NULL) {
|
||||||
/* Now open the file in place. Use O_EXCL if tmp is TRUE. This
|
/* Now open the file in place. Use O_EXCL if tmp is TRUE. This
|
||||||
* is copied from joe, because wiggy says so *shrug*. */
|
* is copied from joe, because wiggy says so *shrug*. */
|
||||||
fd = open(realname, O_WRONLY | O_CREAT | ((append == APPEND) ?
|
fd = open(realname, O_WRONLY | O_CREAT | ((method == APPEND) ?
|
||||||
O_APPEND : (tmp ? O_EXCL : O_TRUNC)), S_IRUSR |
|
O_APPEND : (tmp ? O_EXCL : O_TRUNC)), S_IRUSR |
|
||||||
S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||||
|
|
||||||
@@ -2013,7 +2013,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
f = fdopen(fd, (append == APPEND) ? "ab" : "wb");
|
f = fdopen(fd, (method == APPEND) ? "ab" : "wb");
|
||||||
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
statusline(ALERT, _("Error writing %s: %s"), realname,
|
statusline(ALERT, _("Error writing %s: %s"), realname,
|
||||||
@@ -2079,7 +2079,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If we're prepending, open the temp file, and append it to f. */
|
/* If we're prepending, open the temp file, and append it to f. */
|
||||||
if (append == PREPEND) {
|
if (method == PREPEND) {
|
||||||
int fd_source;
|
int fd_source;
|
||||||
FILE *f_source = NULL;
|
FILE *f_source = NULL;
|
||||||
|
|
||||||
@@ -2111,7 +2111,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tmp && append == OVERWRITE) {
|
if (!tmp && method == OVERWRITE) {
|
||||||
/* If we must set the filename, and it changed, adjust things. */
|
/* If we must set the filename, and it changed, adjust things. */
|
||||||
if (!nonamechange && strcmp(openfile->filename, realname) != 0) {
|
if (!nonamechange && strcmp(openfile->filename, realname) != 0) {
|
||||||
#ifndef DISABLE_COLOR
|
#ifndef DISABLE_COLOR
|
||||||
@@ -2164,7 +2164,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||||||
/* Write a marked selection from a file out to disk. Return TRUE on
|
/* Write a marked selection from a file out to disk. Return TRUE on
|
||||||
* success or FALSE on error. */
|
* success or FALSE on error. */
|
||||||
bool write_marked_file(const char *name, FILE *f_open, bool tmp,
|
bool write_marked_file(const char *name, FILE *f_open, bool tmp,
|
||||||
append_type append)
|
kind_of_writing_type method)
|
||||||
{
|
{
|
||||||
bool retval;
|
bool retval;
|
||||||
bool old_modified = openfile->modified;
|
bool old_modified = openfile->modified;
|
||||||
@@ -2188,7 +2188,7 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp,
|
|||||||
added_magicline = TRUE;
|
added_magicline = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = write_file(name, f_open, tmp, append, TRUE);
|
retval = write_file(name, f_open, tmp, method, TRUE);
|
||||||
|
|
||||||
/* If we added a magicline, remove it now. */
|
/* If we added a magicline, remove it now. */
|
||||||
if (added_magicline)
|
if (added_magicline)
|
||||||
@@ -2214,7 +2214,7 @@ int do_writeout(bool exiting)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
bool result = FALSE;
|
bool result = FALSE;
|
||||||
append_type append = 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. */
|
||||||
bool maychange = (openfile->filename[0] == '\0');
|
bool maychange = (openfile->filename[0] == '\0');
|
||||||
@@ -2250,13 +2250,13 @@ int do_writeout(bool exiting)
|
|||||||
* it allows reading from or writing to files not specified on
|
* it allows reading from or writing to files not specified on
|
||||||
* the command line. */
|
* the command line. */
|
||||||
if (openfile->mark_set && !exiting && !ISSET(RESTRICTED))
|
if (openfile->mark_set && !exiting && !ISSET(RESTRICTED))
|
||||||
msg = (append == PREPEND) ? _("Prepend Selection to File") :
|
msg = (method == PREPEND) ? _("Prepend Selection to File") :
|
||||||
(append == APPEND) ? _("Append Selection to File") :
|
(method == APPEND) ? _("Append Selection to File") :
|
||||||
_("Write Selection to File");
|
_("Write Selection to File");
|
||||||
else
|
else
|
||||||
#endif /* !NANO_TINY */
|
#endif /* !NANO_TINY */
|
||||||
msg = (append == PREPEND) ? _("File Name to Prepend to") :
|
msg = (method == PREPEND) ? _("File Name to Prepend to") :
|
||||||
(append == APPEND) ? _("File Name to Append to") :
|
(method == APPEND) ? _("File Name to Append to") :
|
||||||
_("File Name to Write");
|
_("File Name to Write");
|
||||||
|
|
||||||
present_path = mallocstrcpy(present_path, "./");
|
present_path = mallocstrcpy(present_path, "./");
|
||||||
@@ -2332,10 +2332,10 @@ int do_writeout(bool exiting)
|
|||||||
} else
|
} else
|
||||||
#endif /* !NANO_TINY */
|
#endif /* !NANO_TINY */
|
||||||
if (func == prepend_void) {
|
if (func == prepend_void) {
|
||||||
append = (append == PREPEND) ? OVERWRITE : PREPEND;
|
method = (method == PREPEND) ? OVERWRITE : PREPEND;
|
||||||
continue;
|
continue;
|
||||||
} else if (func == append_void) {
|
} else if (func == append_void) {
|
||||||
append = (append == APPEND) ? OVERWRITE : APPEND;
|
method = (method == APPEND) ? OVERWRITE : APPEND;
|
||||||
continue;
|
continue;
|
||||||
} else if (func == do_help_void) {
|
} else if (func == do_help_void) {
|
||||||
continue;
|
continue;
|
||||||
@@ -2360,7 +2360,7 @@ int do_writeout(bool exiting)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (append == OVERWRITE) {
|
if (method == OVERWRITE) {
|
||||||
size_t answer_len = strlen(answer);
|
size_t answer_len = strlen(answer);
|
||||||
bool name_exists, do_warning;
|
bool name_exists, do_warning;
|
||||||
char *full_answer, *full_filename;
|
char *full_answer, *full_filename;
|
||||||
@@ -2449,10 +2449,10 @@ int do_writeout(bool exiting)
|
|||||||
* 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_set && !exiting && !ISSET(RESTRICTED))
|
if (openfile->mark_set && !exiting && !ISSET(RESTRICTED))
|
||||||
result = write_marked_file(answer, NULL, FALSE, append);
|
result = write_marked_file(answer, NULL, FALSE, method);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
result = write_file(answer, NULL, FALSE, append, FALSE);
|
result = write_file(answer, NULL, FALSE, method, FALSE);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
OVERWRITE, APPEND, PREPEND
|
OVERWRITE, APPEND, PREPEND
|
||||||
} append_type;
|
} kind_of_writing_type;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
UPWARD, DOWNWARD
|
UPWARD, DOWNWARD
|
||||||
|
|||||||
@@ -317,11 +317,11 @@ int delete_lockfile(const char *lockfilename);
|
|||||||
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified);
|
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified);
|
||||||
#endif
|
#endif
|
||||||
int copy_file(FILE *inn, FILE *out);
|
int copy_file(FILE *inn, FILE *out);
|
||||||
bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
bool write_file(const char *name, FILE *f_open, bool tmp,
|
||||||
append, bool nonamechange);
|
kind_of_writing_type method, bool nonamechange);
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
bool write_marked_file(const char *name, FILE *f_open, bool tmp,
|
bool write_marked_file(const char *name, FILE *f_open, bool tmp,
|
||||||
append_type append);
|
kind_of_writing_type method);
|
||||||
#endif
|
#endif
|
||||||
int do_writeout(bool exiting);
|
int do_writeout(bool exiting);
|
||||||
void do_writeout_void(void);
|
void do_writeout_void(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user