From 00d7798756b8f619c39a9e253e8b660fb71476ee Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 7 Aug 2004 21:27:37 +0000 Subject: [PATCH] per DB's patch, convert a few parts of files.c to use bool so that open_pipe()'s failure is handled properly again, and add various #ifdefs to fix a few warnings and compilation problems that occur when everything is enabled manually including NANO_SMALL git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1886 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/files.c | 38 ++++++++++++++++++-------------------- src/global.c | 8 +++++++- src/nano.c | 6 +++++- src/proto.h | 4 +--- 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 736747cf..c7da8e00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -76,8 +76,13 @@ CVS code - Changes to src/Marefile.am. (DLR) - Move the static int pid to the beginning of nano.c with all the other static variables. (DLR) + - Consolidate some if blocks to remove some redundant code. + (David Benbennick) - Fix warnings when compiling with ENABLE_NLS undefined and with -the fwritable-strings option. (David Benbennick) + - Add various #ifdefs to fix warnings and compilation problems + when compiling with every option manually turned on, including + NANO_SMALL. (David Benbennick) - files.c: close_open_file() - Tweak to no longer rely on the return values of diff --git a/src/files.c b/src/files.c index dcbcbf8c..a4246f02 100644 --- a/src/files.c +++ b/src/files.c @@ -338,8 +338,9 @@ void read_file(FILE *f, const char *filename, int quiet) return; } -/* Open the file (and decide if it exists). */ -int open_file(const char *filename, int insert, int quiet) +/* Open the file (and decide if it exists). Return TRUE on success, + * FALSE on failure. */ +bool open_file(const char *filename, int insert, int quiet) { int fd; FILE *f; @@ -348,7 +349,7 @@ int open_file(const char *filename, int insert, int quiet) if (filename[0] == '\0' || stat(filename, &fileinfo) == -1) { if (insert && !quiet) { statusbar(_("\"%s\" not found"), filename); - return -1; + return FALSE; } else { /* We have a new file */ statusbar(_("New File")); @@ -361,7 +362,7 @@ int open_file(const char *filename, int insert, int quiet) _("File \"%s\" is a device file"), filename); if (!insert) new_file(); - return -1; + return FALSE; } else if ((fd = open(filename, O_RDONLY)) == -1) { /* If we're in multibuffer mode, don't be quiet when an error occurs while opening a file */ @@ -373,7 +374,7 @@ int open_file(const char *filename, int insert, int quiet) statusbar("%s: %s", strerror(errno), filename); if (!insert) new_file(); - return -1; + return FALSE; } else { /* File is A-OK */ if (!quiet) statusbar(_("Reading File")); @@ -381,7 +382,7 @@ int open_file(const char *filename, int insert, int quiet) if (f == NULL) { nperror("fdopen"); close(fd); - return -1; + return FALSE; } read_file(f, filename, quiet); #ifndef NANO_SMALL @@ -389,7 +390,7 @@ int open_file(const char *filename, int insert, int quiet) #endif } - return 1; + return TRUE; } /* This function will return the name of the first available extension @@ -426,6 +427,8 @@ char *get_next_filename(const char *name) void do_insertfile(int loading_file) { int i, old_current_x = current_x; + bool opened; + /* TRUE if the file opened successfully. */ char *realname = NULL; static char *inspath = NULL; @@ -550,11 +553,11 @@ void do_insertfile(int loading_file) #ifndef NANO_SMALL if (i == NANO_EXTCMD_KEY) { realname = mallocstrcpy(realname, ""); - i = open_pipe(answer); + opened = open_pipe(answer); } else { #endif realname = real_dir_from_tilde(answer); - i = open_file(realname, TRUE, loading_file); + opened = open_file(realname, TRUE, loading_file); #ifndef NANO_SMALL } #endif @@ -566,7 +569,7 @@ void do_insertfile(int loading_file) created to hold the file), reload the buffer we had open before, and skip the insertion; otherwise, save realname in filename and continue the insertion */ - if (i == -1) { + if (!opened) { free(realname); free(fileage); load_open_file(); @@ -597,20 +600,11 @@ void do_insertfile(int loading_file) /* And re-init the shortcut list */ shortcut_init(FALSE); - } -#endif - -#ifdef ENABLE_MULTIBUFFER - if (!loading_file) { + } else #endif - /* Restore the old x-coordinate position */ current_x = old_current_x; -#ifdef ENABLE_MULTIBUFFER - } -#endif - /* If we've gone off the bottom, recenter; otherwise, just redraw */ edit_refresh(); @@ -2675,8 +2669,12 @@ char *do_browser(const char *inpath) case NANO_HELP_KEY: case NANO_HELP_FKEY: case '?': /* Pico compatibility */ +#ifndef DISABLE_HELP do_help(); curs_set(0); +#else + nano_disabled_msg(); +#endif break; case NANO_ENTER_KEY: case 'S': /* Pico compatibility */ diff --git a/src/global.c b/src/global.c index 69455f5a..c5dd9423 100644 --- a/src/global.c +++ b/src/global.c @@ -282,25 +282,31 @@ void shortcut_init(int unjustify) const char *nano_tab_msg = N_("Insert a tab character"); const char *nano_enter_msg = N_("Insert a carriage return at the cursor position"); +#ifndef NANO_SMALL const char *nano_nextword_msg = N_("Move forward one word"); const char *nano_prevword_msg = N_("Move backward one word"); +#endif const char *nano_verbatim_msg = N_("Insert character(s) verbatim"); #ifdef ENABLE_MULTIBUFFER const char *nano_openprev_msg = N_("Switch to previous file buffer"); const char *nano_opennext_msg = N_("Switch to next file buffer"); #endif -#if !defined(NANO_SMALL) && defined(HAVE_REGEX_H) +#ifndef NANO_SMALL +#ifdef HAVE_REGEX_H const char *nano_bracket_msg = N_("Find other bracket"); #endif const char *nano_whereis_next_msg = N_("Repeat last search"); +#endif const char *nano_cancel_msg = N_("Cancel the current function"); const char *nano_firstline_msg = N_("Go to the first line of the file"); const char *nano_lastline_msg = N_("Go to the last line of the file"); +#ifndef DISABLE_JUSTIFY const char *nano_parabegin_msg = N_("Go to the beginning of the current paragraph"); const char *nano_paraend_msg = N_("Go to the end of the current paragraph"); const char *nano_fulljustify_msg = N_("Justify the entire file"); +#endif #ifndef NANO_SMALL const char *nano_case_msg = N_("Make the current search/replace case (in)sensitive"); diff --git a/src/nano.c b/src/nano.c index 9ea0307e..b35cbe88 100644 --- a/src/nano.c +++ b/src/nano.c @@ -861,7 +861,7 @@ bool open_pipe(const char *command) f = fdopen(fd[0], "rb"); if (f == NULL) nperror("fdopen"); - + read_file(f, "stdin", FALSE); /* If multibuffer mode is on, we could be here in view mode. If so, * don't set the modification flag. */ @@ -912,6 +912,7 @@ void do_mouse(void) xcur = actual_x(current->data, get_page_start(xplustabs()) + mouse_x); +#ifndef NANO_SMALL /* Selecting where the cursor is toggles the mark, as does selecting beyond the line length with the cursor at the end of the line. */ @@ -922,6 +923,7 @@ void do_mouse(void) } do_mark(); } +#endif current_x = xcur; placewewant = xplustabs(); @@ -1078,7 +1080,9 @@ void do_delete(void) delete_node(foo); renumber(current); totlines--; +#ifndef DISABLE_WRAPPING wrap_reset(); +#endif } else return; diff --git a/src/proto.h b/src/proto.h index 1afcdbe2..e7ec77a5 100644 --- a/src/proto.h +++ b/src/proto.h @@ -165,7 +165,7 @@ void new_file(void); filestruct *read_line(char *buf, filestruct *prev, int *line1ins, size_t len); void read_file(FILE *f, const char *filename, int quiet); -int open_file(const char *filename, int insert, int quiet); +bool open_file(const char *filename, int insert, int quiet); char *get_next_filename(const char *name); void do_insertfile(int loading_file); void do_insertfile_void(void); @@ -352,9 +352,7 @@ void allow_pending_sigwinch(bool allow); #ifndef NANO_SMALL void do_toggle(const toggle *which); #endif -#if !defined(NANO_SMALL) || defined(USE_SLANG) void disable_signals(void); -#endif #ifndef NANO_SMALL void enable_signals(void); #endif -- 2.39.5