From d186f9049f93b267987bc73d5079414bda4492ac Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Tue, 22 Mar 2005 15:04:02 +0000 Subject: [PATCH] DLR's latest fixes and backports to 1.2 git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_1_2_branch/nano@2420 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 41 +++++++++++++++++++++++++ files.c | 8 ++--- global.c | 6 ++-- nano.c | 89 ++++++++++++++++++++++++++++++++++--------------------- proto.h | 1 + winio.c | 34 ++++++++++++++------- 6 files changed, 128 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9eda7e0a..5174f6d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,45 @@ CVS code - +- files.c: + open_prevfile(), open_nextfile() + - Translate the "New Buffer" string when displaying "Switched + to" messages on the statusbar. (DLR) + input_tab() + - Fix snprintf() call so that we don't segfault when trying to + complete a filename containing %'s. (Ulf Härnhammar) +- global.c: + shortcut_init() + - Move the "Cancel" shortcut up so that it's just after the "Get + Help" shortcut, for consistency with the other shortcut lists. + (DLR) +- nano.c: + do_int_spell_fix() + - Move the REVERSE_SEARCH flag toggling into the NANO_SMALL + #ifdef, since the tiny version of nano doesn't support reverse + searching. Also, turn the USE_REGEXP flag off during spell + checking in order to avoid a potential segfault. (DLR) + quote_length() + - Fix problem where quoted justify wouldn't work if HAVE_REGEX_H + wasn't set. (David Benbennick) + main() + - Interpret the escape sequences Esc O F and Esc O H as End and + Home, respectively, as nanogetstr() does. Also, don't + interpret Esc O z as a "NumLock glitch" value. (DLR) + - Call setlocale() outside the ENABLE_NLS #ifdef, since UTF-8 + support won't work properly if the locale isn't set, whether + NLS is enabled or not. (Junichi Uekawa) +- winio.c: + blocking_wgetch() + - New function used in place of blocking wgetch() calls. If we + get ERR when using blocking input, it means that the input + source that we were using is gone. In this case, call + handle_hupterm(), so that nano dies gracefully instead of + going into an infinite loop. (DLR, found by Jim Uhl) + get_page_start() + - For consistency, tweak so that scrolling always occurs when we + try to move onto the "$" at the end of the line, as opposed to + (a) when we move onto the "$" at the end of the line on the + first page and (b) when we move onto the character just before + the "$" on subsequent pages. (DLR) GNU nano 1.2.4 - 2004.06.27 - General: diff --git a/files.c b/files.c index 90716a8e..be20735d 100644 --- a/files.c +++ b/files.c @@ -911,7 +911,7 @@ int open_prevfile(int closing_file) load_open_file(); statusbar(_("Switched to %s"), - ((open_files->filename[0] == '\0') ? "New Buffer" : open_files->filename)); + ((open_files->filename[0] == '\0') ? _("New Buffer") : open_files->filename)); #ifdef DEBUG dump_buffer(current); @@ -974,7 +974,7 @@ int open_nextfile(int closing_file) load_open_file(); statusbar(_("Switched to %s"), - ((open_files->filename[0] == '\0') ? "New Buffer" : open_files->filename)); + ((open_files->filename[0] == '\0') ? _("New Buffer") : open_files->filename)); #ifdef DEBUG dump_buffer(current); @@ -2319,7 +2319,7 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list) /* make each filename shown be the same length as the longest filename, with two spaces at the end */ - snprintf(foo, longestname + 1, matches[i]); + snprintf(foo, longestname + 1, "%s", matches[i]); while (strlen(foo) < longestname) strcat(foo, " "); @@ -2822,7 +2822,7 @@ char *do_browser(const char *inpath) } } wrefresh(edit); - } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY); + } while ((kbinput = blocking_wgetch(edit)) != NANO_EXIT_KEY); curs_set(1); blank_edit(); titlebar(NULL); diff --git a/global.c b/global.c index b9914d7d..3f45c0f1 100644 --- a/global.c +++ b/global.c @@ -714,6 +714,9 @@ void shortcut_init(int unjustify) sc_init_one(&writefile_list, NANO_HELP_KEY, _("Get Help"), IFHELP(nano_help_msg, 0), 0, 0, VIEW, do_help); + sc_init_one(&writefile_list, NANO_CANCEL_KEY, _("Cancel"), + IFHELP(nano_cancel_msg, 0), 0, 0, VIEW, 0); + #ifndef DISABLE_BROWSER /* Translators: try to keep this string under 16 characters long */ sc_init_one(&writefile_list, NANO_TOFILES_KEY, _("To Files"), @@ -744,9 +747,6 @@ void shortcut_init(int unjustify) IFHELP(nano_backup_msg, 0), 0, 0, NOVIEW, 0); #endif - sc_init_one(&writefile_list, NANO_CANCEL_KEY, _("Cancel"), - IFHELP(nano_cancel_msg, 0), 0, 0, VIEW, 0); - free_shortcutage(&insertfile_list); sc_init_one(&insertfile_list, NANO_HELP_KEY, _("Get Help"), diff --git a/nano.c b/nano.c index 530500db..c41578ce 100644 --- a/nano.c +++ b/nano.c @@ -1601,17 +1601,27 @@ int do_int_spell_fix(const char *word) /* Save where we are. */ int i = 0; /* The return value. */ - int reverse_search_set = ISSET(REVERSE_SEARCH); #ifndef NANO_SMALL int case_sens_set = ISSET(CASE_SENSITIVE); + int reverse_search_set = ISSET(REVERSE_SEARCH); int mark_set = ISSET(MARK_ISSET); +#endif +#ifdef HAVE_REGEX_H + int regexp_set = ISSET(USE_REGEXP); +#endif +#ifndef NANO_SMALL + /* Make sure Spell Check is case sensitive */ SET(CASE_SENSITIVE); + /* Make sure Spell Check goes forward only */ + UNSET(REVERSE_SEARCH); /* Make sure the marking highlight is off during Spell Check */ UNSET(MARK_ISSET); #endif - /* Make sure Spell Check goes forward only */ - UNSET(REVERSE_SEARCH); +#ifdef HAVE_REGEX_H + /* Make sure Spell Check doesn't use regular expressions */ + UNSET(USE_REGEXP); +#endif /* save the current search/replace strings */ search_init_globals(); @@ -1664,18 +1674,24 @@ int do_int_spell_fix(const char *word) current_x = current_x_save; edittop = edittop_save; - /* restore Search/Replace direction */ - if (reverse_search_set) - SET(REVERSE_SEARCH); - #ifndef NANO_SMALL + /* restore case sensitivity setting */ if (!case_sens_set) UNSET(CASE_SENSITIVE); + /* restore Search/Replace direction */ + if (reverse_search_set) + SET(REVERSE_SEARCH); + /* restore marking highlight */ if (mark_set) SET(MARK_ISSET); #endif +#ifdef HAVE_REGEX_H + /* restore regular expression usage setting */ + if (regexp_set) + SET(USE_REGEXP); +#endif return i != -1; } @@ -2132,7 +2148,7 @@ size_t quote_length(const char *line) size_t qlen = strlen(quotestr); /* Compute quote depth level */ - while (!strcmp(line + qdepth, quotestr)) + while (strncmp(line + qdepth, quotestr, quotelen) == 0) qdepth += qlen; return qdepth; } @@ -2619,13 +2635,13 @@ int do_justify(void) #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION) /* 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 = wgetch(edit)) == KEY_MOUSE) + if ((i = blocking_wgetch(edit)) == KEY_MOUSE) do_mouse(); else ungetch(i); #endif - if ((i = wgetch(edit)) != NANO_UNJUSTIFY_KEY) { + if ((i = blocking_wgetch(edit)) != NANO_UNJUSTIFY_KEY) { ungetch(i); /* Did we back up anything at all? */ if (cutbuffer != cutbuffer_save) @@ -3090,8 +3106,8 @@ int main(int argc, char *argv[]) }; #endif -#ifdef ENABLE_NLS setlocale(LC_ALL, ""); +#ifdef ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif @@ -3490,26 +3506,33 @@ int main(int argc, char *argv[]) raw(); #endif - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); #ifdef DEBUG fprintf(stderr, "AHA! %c (%d)\n", kbinput, kbinput); #endif if (kbinput == 27) { /* Grab Alt-key stuff first */ - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); switch (kbinput) { /* Alt-O, suddenly very important ;) */ case 'O': - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); /* Shift or Ctrl + Arrows are Alt-O-[2,5,6]-[A,B,C,D] on some terms */ if (kbinput == '2' || kbinput == '5' || kbinput == '6') - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); if ((kbinput <= 'D' && kbinput >= 'A') || (kbinput <= 'd' && kbinput >= 'a')) kbinput = abcd(kbinput); - else if (kbinput <= 'z' && kbinput >= 'j') - print_numlock_warning(); + /* Alt-O-H and Alt-O-F are Home and End on some terms */ + else if (kbinput == 'F') + kbinput = KEY_END; + else if (kbinput == 'H') + kbinput = KEY_HOME; + /* Alt-O-P through Alt-O-S are F1 through F4 on some terms */ else if (kbinput <= 'S' && kbinput >= 'P') kbinput = KEY_F(kbinput - 79); + /* Alt-O-j through Alt-O-y are produced by the NumLock glitch */ + else if (kbinput <= 'y' && kbinput >= 'j') + print_numlock_warning(); #ifdef DEBUG else { fprintf(stderr, "I got Alt-O-%c! (%d)\n", @@ -3525,16 +3548,16 @@ int main(int argc, char *argv[]) keyhandled = 1; break; case '[': - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); switch (kbinput) { case '1': /* Alt-[-1-[0-5,7-9] = F1-F8 in X at least */ - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); if (kbinput >= '1' && kbinput <= '5') { kbinput = KEY_F(kbinput - 48); - wgetch(edit); + blocking_wgetch(edit); } else if (kbinput >= '7' && kbinput <= '9') { kbinput = KEY_F(kbinput - 49); - wgetch(edit); + blocking_wgetch(edit); } else if (kbinput == '~') kbinput = KEY_HOME; #ifdef DEBUG @@ -3546,23 +3569,23 @@ int main(int argc, char *argv[]) #endif break; case '2': /* Alt-[-2-[0,1,3,4] = F9-F12 in many terms */ - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); switch (kbinput) { case '0': kbinput = KEY_F(9); - wgetch(edit); + blocking_wgetch(edit); break; case '1': kbinput = KEY_F(10); - wgetch(edit); + blocking_wgetch(edit); break; case '3': kbinput = KEY_F(11); - wgetch(edit); + blocking_wgetch(edit); break; case '4': kbinput = KEY_F(12); - wgetch(edit); + blocking_wgetch(edit); break; case '~': kbinput = NANO_INSERTFILE_KEY; @@ -3577,15 +3600,15 @@ int main(int argc, char *argv[]) break; case '3': /* Alt-[-3 = Delete? */ kbinput = NANO_DELETE_KEY; - wgetch(edit); + blocking_wgetch(edit); break; case '4': /* Alt-[-4 = End? */ kbinput = NANO_END_KEY; - wgetch(edit); + blocking_wgetch(edit); break; case '5': /* Alt-[-5 = Page Up */ kbinput = KEY_PPAGE; - wgetch(edit); + blocking_wgetch(edit); break; case 'V': /* Alt-[-V = Page Up in Hurd Console */ case 'I': /* Alt-[-I = Page Up - FreeBSD Console */ @@ -3593,7 +3616,7 @@ int main(int argc, char *argv[]) break; case '6': /* Alt-[-6 = Page Down */ kbinput = KEY_NPAGE; - wgetch(edit); + blocking_wgetch(edit); break; case 'U': /* Alt-[-U = Page Down in Hurd Console */ case 'G': /* Alt-[-G = Page Down - FreeBSD Console */ @@ -3601,11 +3624,11 @@ int main(int argc, char *argv[]) break; case '7': kbinput = KEY_HOME; - wgetch(edit); + blocking_wgetch(edit); break; case '8': kbinput = KEY_END; - wgetch(edit); + blocking_wgetch(edit); break; case '9': /* Alt-[-9 = Delete in Hurd Console */ kbinput = KEY_DC; @@ -3615,7 +3638,7 @@ int main(int argc, char *argv[]) kbinput = NANO_INSERTFILE_KEY; break; case '[': /* Alt-[-[-[A-E], F1-F5 in Linux console */ - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); if (kbinput >= 'A' && kbinput <= 'E') kbinput = KEY_F(kbinput - 64); break; diff --git a/proto.h b/proto.h index 2bdc39f8..75b0f9e5 100644 --- a/proto.h +++ b/proto.h @@ -427,6 +427,7 @@ int check_wildcard_match(const char *text, const char *pattern); #endif /* Public functions in winio.c */ +int blocking_wgetch(WINDOW *win); int do_first_line(void); int do_last_line(void); int xpt(const filestruct *fileptr, int index); diff --git a/winio.c b/winio.c index 2c53524c..defca986 100644 --- a/winio.c +++ b/winio.c @@ -34,6 +34,18 @@ static int statblank = 0; /* Number of keystrokes left after we call statusbar(), before we actually blank the statusbar */ +int blocking_wgetch(WINDOW *win) +{ + int retval = wgetch(win); + + /* If we get ERR when using blocking input, it means that the input + * source that we were using is gone, so die gracefully. */ + if (retval == ERR) + handle_hupterm(0); + + return retval; +} + int do_first_line(void) { current = fileage; @@ -247,7 +259,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, input */ wrefresh(edit); - while ((kbinput = wgetch(bottomwin)) != 13) { + while ((kbinput = blocking_wgetch(bottomwin)) != 13) { for (t = s; t != NULL; t = t->next) { #ifdef DEBUG fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput); @@ -455,9 +467,9 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, case KEY_DC: goto do_deletekey; case 27: - switch (kbinput = wgetch(edit)) { + switch (kbinput = blocking_wgetch(edit)) { case 'O': - switch (kbinput = wgetch(edit)) { + switch (kbinput = blocking_wgetch(edit)) { case 'F': x = xend; break; @@ -467,7 +479,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, } break; case '[': - switch (kbinput = wgetch(edit)) { + switch (kbinput = blocking_wgetch(edit)) { case 'A': #ifndef NANO_SMALL goto do_upkey; @@ -715,7 +727,7 @@ int check_linenumbers(const filestruct *fileptr) int get_page_start(int column) { assert(COLS > 9); - return column < COLS - 1 ? 0 : column - 7 - (column - 8) % (COLS - 9); + return column < COLS - 1 ? 0 : column - 7 - (column - 7) % (COLS - 8); } /* Resets current_y, based on the position of current, and puts the @@ -1340,7 +1352,7 @@ int do_yesno(int all, int leavecursor, const char *msg, ...) wrefresh(bottomwin); do { - int kbinput = wgetch(edit); + int kbinput = blocking_wgetch(edit); #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION) MEVENT mevent; #endif @@ -1587,19 +1599,19 @@ int do_help(void) break; #endif case 27: - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); switch(kbinput) { case '[': - kbinput = wgetch(edit); + kbinput = blocking_wgetch(edit); switch(kbinput) { case '5': /* Alt-[-5 = Page Up */ - wgetch(edit); + blocking_wgetch(edit); goto do_pageupkey; case 'V': /* Alt-[-V = Page Up in Hurd Console */ case 'I': /* Alt-[-I = Page Up - FreeBSD Console */ goto do_pageupkey; case '6': /* Alt-[-6 = Page Down */ - wgetch(edit); + blocking_wgetch(edit); goto do_pagedownkey; case 'U': /* Alt-[-U = Page Down in Hurd Console */ case 'G': /* Alt-[-G = Page Down - FreeBSD Console */ @@ -1649,7 +1661,7 @@ int do_help(void) no_more = 1; continue; } - } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY && + } while ((kbinput = blocking_wgetch(edit)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY); currshortcut = oldshortcut; -- 2.39.5