From ebd0d7c8595412f0f3f28ce8db0bdcfadda87ea8 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Thu, 1 Jul 2004 18:59:52 +0000 Subject: [PATCH] more minor cosmetic fixes git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1834 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 9 ++++++++ src/files.c | 9 +++----- src/global.c | 4 ++-- src/nano.c | 59 ++++++++++++++++++++++++++-------------------------- src/nano.h | 6 ++++-- src/proto.h | 4 ++-- src/winio.c | 26 +++++++++++------------ 7 files changed, 62 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0fb0bd88..c11419cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,17 @@ CVS code - +- General: + - More minor comment cleanups. (DLR) + - Convert more ints used as boolean values to use TRUE and + FALSE. (David Benbennick and DLR) + - Change more instances of ints that can never be negative to + size_t's. (DLR) - global.c: shortcut_init() - Fix erroneous #ifdef so that nano compiles with --disable-justify again. (DLR; found by Mike Frysinger) +- proto.h: + - Change the last variable in the prototype for get_mouseinput() + to match the one used in the actual function. (DLR) - rcfile.c: parse_rcfile() - Have whitespace display default to off instead of on. (Mike diff --git a/src/files.c b/src/files.c index defdd209..12955b31 100644 --- a/src/files.c +++ b/src/files.c @@ -439,10 +439,7 @@ int do_insertfile(int loading_file) wrap_reset(); #endif -#if !defined(DISABLE_BROWSER) || !defined(NANO_SMALL) && defined(ENABLE_MULTIBUFFER) - start_again: /* Goto here when the user cancels the file browser. */ -#endif - + start_again: #if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) currshortcut = insertfile_list; #endif @@ -599,7 +596,7 @@ int do_insertfile(int loading_file) titlebar(NULL); /* And re-init the shortcut list */ - shortcut_init(0); + shortcut_init(FALSE); } #endif @@ -1019,7 +1016,7 @@ int close_open_file(void) unlink_opennode(tmp); delete_opennode(tmp); - shortcut_init(0); + shortcut_init(FALSE); display_main_list(); return 0; } diff --git a/src/global.c b/src/global.c index 3f7c2a5c..dd9098b2 100644 --- a/src/global.c +++ b/src/global.c @@ -172,9 +172,9 @@ int curses_ended = FALSE; /* Indicates to statusbar() to simply * ended curses mode. */ -int length_of_list(const shortcut *s) +size_t length_of_list(const shortcut *s) { - int i = 0; + size_t i = 0; for (; s != NULL; s = s->next) i++; diff --git a/src/nano.c b/src/nano.c index 3814351c..049acf29 100644 --- a/src/nano.c +++ b/src/nano.c @@ -413,7 +413,7 @@ void help_init(void) /* Now add our shortcut info */ for (s = currshortcut; s != NULL; s = s->next) { /* true if the character in s->metaval is shown in first column */ - int meta_shortcut = 0; + int meta_shortcut = FALSE; if (s->ctrlval != NANO_NO_KEY) { #ifndef NANO_SMALL @@ -430,7 +430,7 @@ void help_init(void) } #ifndef NANO_SMALL else if (s->metaval != NANO_NO_KEY) { - meta_shortcut = 1; + meta_shortcut = TRUE; if (s->metaval == NANO_ALT_SPACE) ptr += snprintf(ptr, 8, "M-%.5s", _("Space")); else @@ -880,8 +880,7 @@ void do_mouse(void) { int mouse_x, mouse_y; - if (get_mouseinput(&mouse_x, &mouse_y, 1) == 0) { - + if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == FALSE) { /* Click in the edit window to move the cursor, but only when we're not in a subfunction. */ if (wenclose(edit, mouse_y, mouse_x) && currshortcut == main_list) { @@ -906,7 +905,7 @@ void do_mouse(void) xcur = actual_x(current->data, get_page_start(xplustabs()) + mouse_x); - /* Selecting where the cursor is toggles the mark. As does + /* Selecting where the cursor is toggles the mark, as does selecting beyond the line length with the cursor at the end of the line. */ if (sameline && xcur == current_x) { @@ -1810,7 +1809,7 @@ const char *do_alt_speller(char *tempfile_name) /* Only reload the temp file if it isn't a marked selection. */ #endif free_filestruct(fileage); - global_init(1); + global_init(TRUE); open_file(tempfile_name, 0, 1); #ifndef NANO_SMALL } @@ -2412,9 +2411,10 @@ int do_justify(int full_justify) filestruct *mark_beginbuf_save = mark_beginbuf; int mark_beginx_save = mark_beginx; #endif + int kbinput; + int meta_key; size_t indent_len; /* Generic indentation length. */ - size_t i; /* Generic loop variable. */ /* If we're justifying the entire file, start at the beginning. */ if (full_justify) @@ -2645,28 +2645,29 @@ int do_justify(int full_justify) statusbar(_("Can now UnJustify!")); /* Display the shortcut list with UnJustify. */ - shortcut_init(1); + shortcut_init(TRUE); display_main_list(); reset_cursor(); /* Now get a keystroke and see if it's unjustify; if not, unget the * keystroke and return. */ - { - int meta_key; - i = get_kbinput(edit, &meta_key); + kbinput = get_kbinput(edit, &meta_key); + #ifndef DISABLE_MOUSE - /* If it was a mouse click, parse it with do_mouse() and it - * might become the unjustify key. Else give it back to the - * input stream. */ - if (i == KEY_MOUSE) { - do_mouse(); - i = get_kbinput(edit, &meta_key); - } -#endif + /* If it was a mouse click, parse it with do_mouse() and it + * might become the unjustify key. Else give it back to the + * input stream. */ + if (kbinput == KEY_MOUSE) { + do_mouse(); + kbinput = get_kbinput(edit, &meta_key); } +#endif - if (i != NANO_UNJUSTIFY_KEY && i != NANO_UNJUSTIFY_FKEY) { - ungetch(i); + if (meta_key || (kbinput != NANO_UNJUSTIFY_KEY && + kbinput != NANO_UNJUSTIFY_FKEY)) { + ungetch(kbinput); + if (meta_key) + ungetch(NANO_CONTROL_3); placewewant = 0; } else { /* Else restore the justify we just did (ungrateful user!). */ @@ -2704,11 +2705,12 @@ int do_justify(int full_justify) titlebar(NULL); edit_refresh(); } + cutbuffer = cutbuffer_save; /* Note that now cutbottom is invalid, but that's okay. */ blank_statusbar(); /* Display the shortcut list with UnCut. */ - shortcut_init(0); + shortcut_init(FALSE); display_main_list(); return 0; @@ -3501,8 +3503,8 @@ int main(int argc, char *argv[]) #endif /* Set up the global variables and the shortcuts. */ - global_init(0); - shortcut_init(0); + global_init(FALSE); + shortcut_init(FALSE); /* Set up the signal handlers. */ signal_init(); @@ -3642,14 +3644,11 @@ int main(int argc, char *argv[]) cutbuffer_reset(); /* Don't even think about changing this string */ - if (kbinput == NANO_CONTROL_Q) + if (kbinput == NANO_XON_KEY) statusbar(_("XON ignored, mumble mumble.")); - if (kbinput == NANO_CONTROL_S) + if (kbinput == NANO_XOFF_KEY) statusbar(_("XOFF ignored, mumble mumble.")); - - /* If we're in raw mode or using Alt-Alt-x, we have to catch - Control-S and Control-Q */ - if (kbinput == NANO_CONTROL_Q || kbinput == NANO_CONTROL_S) + if (kbinput == NANO_XON_KEY || kbinput == NANO_XOFF_KEY) keyhandled = TRUE; /* Catch ^Z by hand when triggered also */ diff --git a/src/nano.h b/src/nano.h index 1a724aa8..314e0956 100644 --- a/src/nano.h +++ b/src/nano.h @@ -362,6 +362,8 @@ typedef struct historyheadtype { #define NANO_HISTORY_KEY -3 /* Normal keys. */ +#define NANO_XON_KEY NANO_CONTROL_Q +#define NANO_XOFF_KEY NANO_CONTROL_S #define NANO_INSERTFILE_KEY NANO_CONTROL_R #define NANO_INSERTFILE_FKEY KEY_F(5) #define NANO_EXIT_KEY NANO_CONTROL_X @@ -457,8 +459,8 @@ typedef struct historyheadtype { #define MAIN_VISIBLE 12 -#define VIEW 1 -#define NOVIEW 0 +#define VIEW TRUE +#define NOVIEW FALSE typedef enum { JUSTIFY, BEGIN, END diff --git a/src/proto.h b/src/proto.h index 5f77dcb8..0067c31f 100644 --- a/src/proto.h +++ b/src/proto.h @@ -218,7 +218,7 @@ char *do_browse_from(const char *inpath); #endif /* Public functions in global.c */ -int length_of_list(const shortcut *s); +size_t length_of_list(const shortcut *s); void sc_init_one(shortcut **shortcutage, int key, const char *desc, #ifndef DISABLE_HELP const char *help, @@ -503,7 +503,7 @@ int get_untranslated_kbinput(int kbinput, size_t position, int #endif ); #ifndef DISABLE_MOUSE -int get_mouseinput(int *mouse_x, int *mouse_y, int shortcut); +int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts); #endif size_t xplustabs(void); size_t actual_x(const char *str, size_t xplus); diff --git a/src/winio.c b/src/winio.c index c46627e1..f1ec8d10 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1239,12 +1239,12 @@ int get_untranslated_kbinput(int kbinput, size_t position, int #ifndef DISABLE_MOUSE /* Check for a mouse event, and if one's taken place, save the * coordinates where it took place in mouse_x and mouse_y. After that, - * if allow_shortcuts is zero, return 0. Otherwise, if the mouse event - * took place on the shortcut list on the bottom two lines of the screen - * (assuming that the shortcut list is visible), figure out which - * shortcut was clicked and ungetch() the equivalent keystroke(s). - * Return 0 if no keystrokes were ungetch()ed, or 1 if at least one was. - * Assume that KEY_MOUSE has already been read in. */ + * assuming allow_shortcuts is FALSE, if the shortcut list on the + * bottom two lines of the screen is visible and the mouse event took + * place on it, figure out which shortcut was clicked and ungetch() the + * equivalent keystroke(s). Return FALSE if no keystrokes were + * ungetch()ed, or TRUE if at least one was. Assume that KEY_MOUSE has + * already been read in. */ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts) { MEVENT mevent; @@ -1254,7 +1254,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts) /* First, get the actual mouse event. */ if (getmouse(&mevent) == ERR) - return 0; + return FALSE; /* Save the screen coordinates where the mouse event took place. */ *mouse_x = mevent.x; @@ -1262,7 +1262,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts) /* If we're not allowing shortcuts' we're done now. */ if (!allow_shortcuts) - return 0; + return FALSE; /* Otherwise, if the current shortcut list is being displayed on the * last two lines of the screen and the mouse event took place @@ -1270,7 +1270,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts) * ungetch() the equivalent keystroke(s) for it. */ if (!ISSET(NO_HELP) && wenclose(bottomwin, *mouse_y, *mouse_x)) { int i, j; - int currslen; + size_t currslen; /* The number of shortcuts in the current shortcut list. */ const shortcut *s = currshortcut; /* The actual shortcut we clicked on, starting at the first @@ -1318,9 +1318,9 @@ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts) ungetch(NANO_CONTROL_3); } - return 1; + return TRUE; } - return 0; + return FALSE; } #endif @@ -2888,7 +2888,7 @@ int do_yesno(int all, const char *msg) /* Look ma! We get to duplicate lots of code from * do_mouse()!! */ else if (kbinput == KEY_MOUSE) { - kbinput = get_mouseinput(&mouse_x, &mouse_y, 0); + kbinput = get_mouseinput(&mouse_x, &mouse_y, FALSE); if (mouse_x != -1 && mouse_y != -1 && !ISSET(NO_HELP) && wenclose(bottomwin, mouse_y, mouse_x) && mouse_x < @@ -3005,7 +3005,7 @@ int do_cursorpos(int constant) int do_cursorpos_void(void) { - return do_cursorpos(0); + return do_cursorpos(FALSE); } /* Calculate the next line of help_text, starting at ptr. */ -- 2.39.5