- 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)
(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,
* 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
* 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;
}
/* If we're prepending, copy the file to a temp file. */
- if (append == 2) {
+ if (append == PREPEND) {
int fd_source;
FILE *f_source = NULL;
/* 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);
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,
}
/* 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;
goto cleanup_and_exit;
}
- if (!tmp && append == 0) {
+ if (!tmp && append == OVERWRITE) {
if (!nonamechange) {
openfile->filename = mallocstrcpy(openfile->filename,
realname);
#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;
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
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,
} 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;
}
break;
}
#endif
- if (append == 0 && strcmp(answer,
+ if (append == OVERWRITE && strcmp(answer,
openfile->filename) != 0) {
struct stat st;
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);
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);