miscellaneous enum cleanups, including making the file-writing

functions' append parameter an enum instead of an int


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2966 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-08-01 18:27:10 +00:00
parent 5d552195ea
commit bf0e47dc37
5 changed files with 44 additions and 35 deletions

View File

@ -148,6 +148,8 @@ CVS code -
- Assert that filename isn't NULL, and don't do anything special
if it's blank, as the the former case shouldn't occur, and the
latter case is now handled elsewhere. (DLR)
write_file(), write_marked_file(), do_writeout()
- Make append an append_type enum instead of an int. (DLR)
input_tab()
- Make columns an int instead of a size_t, since it's limited by
COLS. (DLR)
@ -222,6 +224,8 @@ CVS code -
(DLR)
- Move stdlib.h, dirent.h, regex.h, and assert.h includes here,
as every source file needs them. (DLR)
- Rename the updown enum scroll_dir and the centernone enum
update_type for clarity, and add an append_type enum. (DLR)
- rcfile.c:
nregcomp()
- Return TRUE when the compilation succeeds and FALSE otherwise,

View File

@ -1130,15 +1130,15 @@ int copy_file(FILE *inn, FILE *out)
* 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.
*
* append == 1 means we are appending instead of overwriting.
* append == 2 means we are prepending instead of overwriting.
* append == APPEND means we are appending instead of overwriting.
* append == PREPEND means we are prepending instead of overwriting.
*
* nonamechange means don't change the current filename. It is ignored
* if tmp is FALSE or if we're appending/prepending.
*
* Return 0 on success or -1 on error. */
int write_file(const char *name, FILE *f_open, bool tmp, int append,
bool nonamechange)
int write_file(const char *name, FILE *f_open, bool tmp, append_type
append, bool nonamechange)
{
int retval = -1;
/* Instead of returning in this function, you should always
@ -1213,9 +1213,9 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
* aren't appending, prepending, or writing a selection, we backup
* only if the file has not been modified by someone else since nano
* opened it. */
if (ISSET(BACKUP_FILE) && !tmp && realexists && ((append != 0 ||
openfile->mark_set) || openfile->current_stat->st_mtime ==
st.st_mtime)) {
if (ISSET(BACKUP_FILE) && !tmp && realexists && ((append !=
OVERWRITE || openfile->mark_set) ||
openfile->current_stat->st_mtime == st.st_mtime)) {
FILE *backup_file;
char *backupname;
struct utimbuf filetime;
@ -1345,7 +1345,7 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
}
/* If we're prepending, copy the file to a temp file. */
if (append == 2) {
if (append == PREPEND) {
int fd_source;
FILE *f_source = NULL;
@ -1385,9 +1385,9 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
/* Now open the file in place. Use O_EXCL if tmp is TRUE. This
* is copied from joe, because wiggy says so *shrug*. */
fd = open(realname, O_WRONLY | O_CREAT |
((append == 1) ? O_APPEND : (tmp ? O_EXCL : O_TRUNC)),
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH |
S_IWOTH);
((append == APPEND) ? O_APPEND : (tmp ? O_EXCL :
O_TRUNC)), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH);
/* Set the umask back to the user's original value. */
umask(original_umask);
@ -1403,7 +1403,7 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
goto cleanup_and_exit;
}
f = fdopen(fd, (append == 1) ? "ab" : "wb");
f = fdopen(fd, (append == APPEND) ? "ab" : "wb");
if (f == NULL) {
statusbar(_("Error writing %s: %s"), realname,
@ -1462,7 +1462,7 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
}
/* If we're prepending, open the temp file, and append it to f. */
if (append == 2) {
if (append == PREPEND) {
int fd_source;
FILE *f_source = NULL;
@ -1492,7 +1492,7 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
goto cleanup_and_exit;
}
if (!tmp && append == 0) {
if (!tmp && append == OVERWRITE) {
if (!nonamechange) {
openfile->filename = mallocstrcpy(openfile->filename,
realname);
@ -1537,8 +1537,8 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
#ifndef NANO_SMALL
/* Write a marked selection from a file out. */
int write_marked_file(const char *name, FILE *f_open, bool tmp, int
append)
int write_marked_file(const char *name, FILE *f_open, bool tmp,
append_type append)
{
int retval = -1;
bool old_modified = openfile->modified;
@ -1582,8 +1582,8 @@ int write_marked_file(const char *name, FILE *f_open, bool tmp, int
int do_writeout(bool exiting)
{
int i;
int retval = 0, append = 0;
int i, retval = 0;
append_type append = OVERWRITE;
char *ans;
/* The last answer the user typed on the statusbar. */
#ifdef NANO_EXTRA
@ -1619,13 +1619,14 @@ int do_writeout(bool exiting)
backupstr = ISSET(BACKUP_FILE) ? N_(" [Backup]") : "";
if (openfile->mark_set && !exiting)
msg = (append == 2) ? N_("Prepend Selection to File") :
(append == 1) ? N_("Append Selection to File") :
msg = (append == PREPEND) ?
N_("Prepend Selection to File") : (append == APPEND) ?
N_("Append Selection to File") :
N_("Write Selection to File");
else
#endif /* !NANO_SMALL */
msg = (append == 2) ? N_("File Name to Prepend to") :
(append == 1) ? N_("File Name to Append to") :
msg = (append == PREPEND) ? N_("File Name to Prepend to") :
(append == APPEND) ? N_("File Name to Append to") :
N_("File Name to Write");
/* If we're using restricted mode, the filename isn't blank,
@ -1679,10 +1680,10 @@ int do_writeout(bool exiting)
} else
#endif /* !NANO_SMALL */
if (i == NANO_PREPEND_KEY) {
append = (append == 2) ? 0 : 2;
append = (append == PREPEND) ? OVERWRITE : PREPEND;
continue;
} else if (i == NANO_APPEND_KEY) {
append = (append == 1) ? 0 : 1;
append = (append == APPEND) ? OVERWRITE : APPEND;
continue;
}
@ -1699,7 +1700,7 @@ int do_writeout(bool exiting)
break;
}
#endif
if (append == 0 && strcmp(answer,
if (append == OVERWRITE && strcmp(answer,
openfile->filename) != 0) {
struct stat st;

View File

@ -150,13 +150,17 @@ typedef enum {
NIX_FILE, DOS_FILE, MAC_FILE
} file_format;
typedef enum {
OVERWRITE, APPEND, PREPEND
} append_type;
typedef enum {
UP, DOWN
} updown;
} scroll_dir;
typedef enum {
CENTER, NONE
} centernone;
} update_type;
/* Structure types. */
typedef struct filestruct {

View File

@ -257,11 +257,11 @@ bool check_operating_dir(const char *currpath, bool allow_tabcomp);
void init_backup_dir(void);
#endif
int copy_file(FILE *inn, FILE *out);
int write_file(const char *name, FILE *f_open, bool tmp, int append,
bool nonamechange);
int write_file(const char *name, FILE *f_open, bool tmp, append_type
append, bool nonamechange);
#ifndef NANO_SMALL
int write_marked_file(const char *name, FILE *f_open, bool tmp, int
append);
int write_marked_file(const char *name, FILE *f_open, bool tmp,
append_type append);
#endif
int do_writeout(bool exiting);
void do_writeout_void(void);
@ -666,10 +666,10 @@ void edit_add(const filestruct *fileptr, const char *converted, int
void update_line(const filestruct *fileptr, size_t index);
int need_horizontal_update(size_t old_pww);
int need_vertical_update(size_t old_pww);
void edit_scroll(updown direction, int nlines);
void edit_scroll(scroll_dir direction, int nlines);
void edit_redraw(const filestruct *old_current, size_t old_pww);
void edit_refresh(void);
void edit_update(centernone location);
void edit_update(update_type location);
int do_yesno(bool all, const char *msg);
void total_redraw(void);
void total_refresh(void);

View File

@ -3477,7 +3477,7 @@ int need_vertical_update(size_t old_pww)
* and nlines is the number of lines to scroll. We change edittop, and
* assume that current and current_x are up to date. We also assume
* that scrollok(edit) is FALSE. */
void edit_scroll(updown direction, int nlines)
void edit_scroll(scroll_dir direction, int nlines)
{
bool do_redraw = need_vertical_update(0);
const filestruct *foo;
@ -3649,7 +3649,7 @@ void edit_refresh(void)
* same place. location determines how we move it: if it's CENTER, we
* center current, and if it's NONE, we put current current_y lines
* below edittop. */
void edit_update(centernone location)
void edit_update(update_type location)
{
filestruct *foo = openfile->current;
int goal;