From 31925e4517a85f316617d220776af2fd179ce02a Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Thu, 2 Nov 2000 04:40:39 +0000 Subject: [PATCH] Allow variable length strings on statusbar git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@257 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 9 +++++ global.c | 2 +- po/cat-id-tbl.c | 91 +++++++++++++++++++++++++----------------------- po/es.gmo | Bin 17459 -> 17372 bytes po/nano.pot | 81 ++++++++++++++++++++++++------------------ proto.h | 3 +- search.c | 42 ++++++++++++++++------ utils.c | 17 +++++++++ winio.c | 54 ++++++++++++++++------------ 9 files changed, 186 insertions(+), 113 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43ba6c16..9c8d3e67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,15 @@ CVS Code - replace with the null string without needing a special key for it. changed code in search_init(), do_replace(), nanogetstr (see below). - Added some missing gettext calls here and there (Jordi). +- Revamped nanogetsr() and calls to it to use variable length strings. + MANY changes in nanogetstr(), many chances in search.c, new function + mallocstrcpy which is sure to be a programmatic nightmare, changed + last_search, last_replace, answer to pointers. New function + not_found_msg in search.c for displaying truncated strings in satusbar + when the string is not found. + + *** Note that backspace key makes input be off by one when entring + *** a string > COLS in length. This must be fixed before a new release - global.c - New global replace_list_2, for 2nd half of the replace dialog diff --git a/global.c b/global.c index 981ec50f..115385d5 100644 --- a/global.c +++ b/global.c @@ -54,7 +54,7 @@ filestruct *editbot = NULL; /* Same for the bottom */ filestruct *filebot = NULL; /* Last node in the file struct */ filestruct *cutbuffer = NULL; /* A place to store cut text */ -char answer[132]; /* Answer str to many questions */ +char *answer = NULL; /* Answer str to many questions */ int totlines = 0; /* Total number of lines in the file */ int totsize = 0; /* Total number of bytes in the file */ int placewewant = 0; /* The collum we'd like the cursor diff --git a/po/cat-id-tbl.c b/po/cat-id-tbl.c index 97f5456a..90723160 100644 --- a/po/cat-id-tbl.c +++ b/po/cat-id-tbl.c @@ -186,49 +186,52 @@ Usage: nano [option] +LINE \n\ {"Cannot move edit win", 153}, {"Cannot resize bottom win", 154}, {"Cannot move bottom win", 155}, - {"%s enable/disable", 156}, - {"enabled", 157}, - {"disabled", 158}, - {"Main: set up windows\n", 159}, - {"Main: bottom win\n", 160}, - {"Main: open file\n", 161}, - {"I got Alt-O-%c! (%d)\n", 162}, - {"I got Alt-[-1-%c! (%d)\n", 163}, - {"I got Alt-[-2-%c! (%d)\n", 164}, - {"I got Alt-[-%c! (%d)\n", 165}, - {"I got Alt-%c! (%d)\n", 166}, - {"Case Sensitive Regexp Search%s%s", 167}, - {"Regexp Search%s%s", 168}, - {"Case Sensitive Search%s%s", 169}, - {"Search%s%s", 170}, - {" (to replace)", 171}, - {"Search Cancelled", 172}, - {"Search Wrapped", 173}, - {"Replaced %d occurences", 174}, - {"Replaced 1 occurence", 175}, - {"Replace Cancelled", 176}, - {"Replace with", 177}, - {"Replace this instance?", 178}, - {"Enter line number", 179}, - {"Aborted", 180}, - {"Come on, be reasonable", 181}, - {"Only %d lines available, skipping to last line", 182}, - {"actual_x_from_start for xplus=%d returned %d\n", 183}, - {"input '%c' (%d)\n", 184}, - {"New Buffer", 185}, - {" File: ...", 186}, - {"Modified", 187}, - {"Moved to (%d, %d) in edit buffer\n", 188}, - {"current->data = \"%s\"\n", 189}, - {"I got \"%s\"\n", 190}, - {"Yes", 191}, - {"All", 192}, - {"No", 193}, - {"do_cursorpos: linepct = %f, bytepct = %f\n", 194}, - {"line %d of %d (%.0f%%), character %d of %d (%.0f%%)", 195}, - {"Dumping file buffer to stderr...\n", 196}, - {"Dumping cutbuffer to stderr...\n", 197}, - {"Dumping a buffer to stderr...\n", 198}, + {"Justify Complete", 156}, + {"%s enable/disable", 157}, + {"enabled", 158}, + {"disabled", 159}, + {"Main: set up windows\n", 160}, + {"Main: bottom win\n", 161}, + {"Main: open file\n", 162}, + {"I got Alt-O-%c! (%d)\n", 163}, + {"I got Alt-[-1-%c! (%d)\n", 164}, + {"I got Alt-[-2-%c! (%d)\n", 165}, + {"I got Alt-[-%c! (%d)\n", 166}, + {"I got Alt-%c! (%d)\n", 167}, + {"Case Sensitive Regexp Search%s%s", 168}, + {"Regexp Search%s%s", 169}, + {"Case Sensitive Search%s%s", 170}, + {"Search%s%s", 171}, + {" (to replace)", 172}, + {"Search Cancelled", 173}, + {"\"%s...\" not found", 174}, + {"Search Wrapped", 175}, + {"Replaced %d occurences", 176}, + {"Replaced 1 occurence", 177}, + {"Replace Cancelled", 178}, + {"Replace with", 179}, + {"Replace this instance?", 180}, + {"Replace failed: unknown subexpression!", 181}, + {"Enter line number", 182}, + {"Aborted", 183}, + {"Come on, be reasonable", 184}, + {"Only %d lines available, skipping to last line", 185}, + {"actual_x_from_start for xplus=%d returned %d\n", 186}, + {"input '%c' (%d)\n", 187}, + {"New Buffer", 188}, + {" File: ...", 189}, + {"Modified", 190}, + {"Moved to (%d, %d) in edit buffer\n", 191}, + {"current->data = \"%s\"\n", 192}, + {"I got \"%s\"\n", 193}, + {"Yes", 194}, + {"All", 195}, + {"No", 196}, + {"do_cursorpos: linepct = %f, bytepct = %f\n", 197}, + {"line %d of %d (%.0f%%), character %d of %d (%.0f%%)", 198}, + {"Dumping file buffer to stderr...\n", 199}, + {"Dumping cutbuffer to stderr...\n", 200}, + {"Dumping a buffer to stderr...\n", 201}, }; -int _msg_tbl_length = 198; +int _msg_tbl_length = 201; diff --git a/po/es.gmo b/po/es.gmo index 25441f656147ff9502c12e3ebf3cb9d1eb6bbe1b..0d279a02a307dd013ac277558ac77feb00966b13 100644 GIT binary patch delta 4469 zcmYM$4OG?T0mt#@@}hzq-_bykYg_{aCY|HJQop6B6z|Ige1 z|A%n9K}&xb^YJgJr5)ppK1P#Kdsm0L*;b(junRS#Zq$HJp*nsSHRC@b zPont@b^UmjrvOKz2EG7werOQ|&8!~v+y?ClUADa&b(8g=R_Ir#6}f`i`+uVLJe`+- z&YOXnc`a%HYmrk-JF1^Ur~w>B1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v^g^FEzsU0Cjqw+HeSV)Wc502cwsA>wM{`@Nw<6HlIL6BN`Fvhq zvDa5*<>imb^N;Z5hsJuQg&y`Khqie9k@wZrgg*3SySzRB@~j&eH!;xA*cz~w1nR#D z^eh{1xk6`4?;TLv*tl>}OJG@`-KuYEwTGB6VXG^3MhBN#0#^Mke-<9&-m=1o{{yr! B*rNad diff --git a/po/nano.pot b/po/nano.pot index 01579470..16358e6b 100644 --- a/po/nano.pot +++ b/po/nano.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2000-10-31 00:32-0500\n" +"POT-Creation-Date: 2000-11-01 23:34-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -32,7 +32,7 @@ msgstr "" msgid "Read %d lines" msgstr "" -#: files.c:217 search.c:161 search.c:196 +#: files.c:217 search.c:148 #, c-format msgid "\"%s\" not found" msgstr "" @@ -380,7 +380,7 @@ msgid "Case Sens" msgstr "" #: global.c:344 global.c:364 global.c:375 global.c:385 global.c:401 -#: global.c:405 global.c:411 winio.c:974 +#: global.c:405 global.c:411 winio.c:982 msgid "Cancel" msgstr "" @@ -675,6 +675,10 @@ msgstr "" msgid "Cannot move bottom win" msgstr "" +#: nano.c:1567 +msgid "Justify Complete" +msgstr "" + #: nano.c:1635 #, c-format msgid "%s enable/disable" @@ -725,73 +729,82 @@ msgstr "" msgid "I got Alt-%c! (%d)\n" msgstr "" -#: search.c:79 +#: search.c:88 #, c-format msgid "Case Sensitive Regexp Search%s%s" msgstr "" -#: search.c:81 +#: search.c:90 #, c-format msgid "Regexp Search%s%s" msgstr "" -#: search.c:83 +#: search.c:92 #, c-format msgid "Case Sensitive Search%s%s" msgstr "" -#: search.c:85 +#: search.c:94 #, c-format msgid "Search%s%s" msgstr "" -#: search.c:88 +#: search.c:97 msgid " (to replace)" msgstr "" -#: search.c:96 +#: search.c:105 search.c:274 msgid "Search Cancelled" msgstr "" -#: search.c:177 +#: search.c:152 +#, c-format +msgid "\"%s...\" not found" +msgstr "" + +#: search.c:199 msgid "Search Wrapped" msgstr "" -#: search.c:266 +#: search.c:288 #, c-format msgid "Replaced %d occurences" msgstr "" -#: search.c:268 +#: search.c:290 msgid "Replaced 1 occurence" msgstr "" -#: search.c:404 search.c:420 search.c:442 +#: search.c:426 search.c:442 search.c:464 msgid "Replace Cancelled" msgstr "" -#: search.c:436 +#: search.c:458 msgid "Replace with" msgstr "" -#: search.c:473 +#: search.c:495 msgid "Replace this instance?" msgstr "" +#: search.c:503 +msgid "Replace failed: unknown subexpression!" +msgstr "" + #. Ask for it -#: search.c:534 +#: search.c:556 msgid "Enter line number" msgstr "" -#: search.c:536 +#: search.c:558 msgid "Aborted" msgstr "" -#: search.c:556 +#: search.c:578 msgid "Come on, be reasonable" msgstr "" -#: search.c:561 +#: search.c:583 #, c-format msgid "Only %d lines available, skipping to last line" msgstr "" @@ -801,67 +814,67 @@ msgstr "" msgid "actual_x_from_start for xplus=%d returned %d\n" msgstr "" -#: winio.c:390 +#: winio.c:398 #, c-format msgid "input '%c' (%d)\n" msgstr "" -#: winio.c:427 +#: winio.c:435 msgid "New Buffer" msgstr "" -#: winio.c:430 +#: winio.c:438 msgid " File: ..." msgstr "" -#: winio.c:438 +#: winio.c:446 msgid "Modified" msgstr "" -#: winio.c:890 +#: winio.c:898 #, c-format msgid "Moved to (%d, %d) in edit buffer\n" msgstr "" -#: winio.c:901 +#: winio.c:909 #, c-format msgid "current->data = \"%s\"\n" msgstr "" -#: winio.c:944 +#: winio.c:952 #, c-format msgid "I got \"%s\"\n" msgstr "" -#: winio.c:969 +#: winio.c:977 msgid "Yes" msgstr "" -#: winio.c:971 +#: winio.c:979 msgid "All" msgstr "" -#: winio.c:973 +#: winio.c:981 msgid "No" msgstr "" -#: winio.c:1110 +#: winio.c:1118 #, c-format msgid "do_cursorpos: linepct = %f, bytepct = %f\n" msgstr "" -#: winio.c:1114 +#: winio.c:1122 msgid "line %d of %d (%.0f%%), character %d of %d (%.0f%%)" msgstr "" -#: winio.c:1242 +#: winio.c:1250 msgid "Dumping file buffer to stderr...\n" msgstr "" -#: winio.c:1244 +#: winio.c:1252 msgid "Dumping cutbuffer to stderr...\n" msgstr "" -#: winio.c:1246 +#: winio.c:1254 msgid "Dumping a buffer to stderr...\n" msgstr "" diff --git a/proto.h b/proto.h index bc410e36..6fe76aa3 100644 --- a/proto.h +++ b/proto.h @@ -38,7 +38,7 @@ extern int fill, flags,tabsize; extern WINDOW *edit, *topwin, *bottomwin; extern char filename[PATH_MAX]; -extern char answer[132]; +extern char *answer; extern char *hblank, *help_text; extern struct stat fileinfo; extern filestruct *current, *fileage, *edittop, *editbot, *filebot; @@ -107,6 +107,7 @@ void center_cursor(void); void bottombars(shortcut s[], int slen); void blank_statusbar_refresh(void); void *nmalloc (size_t howmuch); +void *mallocstrcpy(void *dest, void *src); void wrap_reset(void); void display_main_list(void); void nano_small_msg(void); diff --git a/search.c b/search.c index bcbd48ce..4c2fdce3 100644 --- a/search.c +++ b/search.c @@ -34,8 +34,8 @@ #define _(string) (string) #endif -static char last_search[132] = ""; /* Last string we searched for */ -static char last_replace[132] = ""; /* Last replacement string */ +static char *last_search = NULL; /* Last string we searched for */ +static char *last_replace = NULL; /* Last replacement string */ static int search_last_line; @@ -67,6 +67,15 @@ int search_init(int replacing) /* char buf[BUFSIZ]; */ char *prompt, *reprompt = ""; + if (last_search == NULL) { + last_search = nmalloc(1); + last_search[0] = 0; + } + if (last_replace == NULL) { + last_replace = nmalloc(1); + last_replace[0] = 0; + } + /* if (last_search[0]) { snprintf(buf, BUFSIZ, " [%s]", last_search); @@ -97,13 +106,13 @@ int search_init(int replacing) reset_cursor(); return -1; } else if (i == -2) { /* Same string */ - strncpy(answer, last_search, 132); + answer = mallocstrcpy(answer, last_search); #ifdef HAVE_REGEX_H if (ISSET(USE_REGEXP)) regexp_init(answer); #endif } else if (i == 0) { /* They entered something new */ - strncpy(last_search, answer, 132); + last_search = mallocstrcpy(last_search, answer); #ifdef HAVE_REGEX_H if (ISSET(USE_REGEXP)) regexp_init(answer); @@ -131,6 +140,19 @@ int search_init(int replacing) return 0; } +void not_found_msg(char *str) +{ + char foo[COLS]; + + if (strlen(str) < COLS / 2) + statusbar(_("\"%s\" not found"), str); + else { + strncpy(foo, str, COLS / 2); + foo[COLS / 2] = 0; + statusbar(_("\"%s...\" not found"), foo); + } +} + filestruct *findnextstr(int quiet, filestruct * begin, int beginx, char *needle) { @@ -158,7 +180,7 @@ filestruct *findnextstr(int quiet, filestruct * begin, int beginx, /* finished processing file, get out */ if (search_last_line) { if (!quiet) - statusbar(_("\"%s\" not found"), needle); + not_found_msg(needle); return NULL; } @@ -193,7 +215,7 @@ filestruct *findnextstr(int quiet, filestruct * begin, int beginx, /* Ensure we haven't wrap around again! */ if ((search_last_line) && (current_x >= beginx)) { if (!quiet) - statusbar(_("\"%s\" not found"), needle); + not_found_msg(needle); return NULL; } @@ -396,7 +418,7 @@ int do_replace(void) { int i, replaceall = 0, numreplaced = 0, beginx; filestruct *fileptr, *begin; - char *copy, prevanswer[132] = ""; + char *copy, *prevanswer = NULL; i = search_init(1); switch (i) { @@ -422,7 +444,7 @@ int do_replace(void) return 0; } - strncpy(prevanswer, answer, 132); + prevanswer = mallocstrcpy(prevanswer, answer); /* if (strcmp(last_replace, "")) * There's a previous replace str * @@ -438,12 +460,12 @@ int do_replace(void) switch (i) { case -1: /* Aborted enter */ if (strcmp(last_replace, "")) - strncpy(answer, last_replace, 132); + answer = mallocstrcpy(answer, last_replace); statusbar(_("Replace Cancelled")); replace_abort(); return 0; case 0: /* They actually entered something */ - strncpy(last_replace, answer, 132); + last_replace = mallocstrcpy(last_replace, answer); break; default: if (i != -2) { /* First page, last page, for example diff --git a/utils.c b/utils.c index f4f51375..f538de7a 100644 --- a/utils.c +++ b/utils.c @@ -119,6 +119,23 @@ void *nrealloc(void *ptr, size_t howmuch) return r; } +/* Copy one malloced string to another pointer. + + Should be used as dest = mallocstrcpy(dest, src); +*/ +void *mallocstrcpy(void *dest, void *src) +{ + + if (dest != NULL) + free(dest); + + dest = nmalloc(strlen(src) + 1); + strcpy(dest, src); + + return dest; +} + + /* Append a new magic-line to filebot */ void new_magicline(void) { diff --git a/winio.c b/winio.c index 721f0924..3a92bad0 100644 --- a/winio.c +++ b/winio.c @@ -222,32 +222,38 @@ void check_statblank(void) void nanoget_repaint(char *buf, char *inputbuf, int x) { blank_statusbar(); - mvwaddstr(bottomwin, 0, 0, buf); - waddstr(bottomwin, inputbuf); - wmove(bottomwin, 0, x); + if (x <= COLS) { + mvwaddstr(bottomwin, 0, 0, buf); + waddnstr(bottomwin, inputbuf, COLS - strlen(buf)); + + } else if (x > COLS && x <= COLS * 2) + mvwaddnstr(bottomwin, 0, 0, &inputbuf[COLS - strlen(buf)], COLS); + else + mvwaddnstr(bottomwin, 0, 0, &inputbuf[COLS * (x / COLS) - + strlen(buf)], COLS); + + wmove(bottomwin, 0, (x % COLS)); + } /* Get the input from the kb, this should only be called from statusq */ int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x) { int kbinput = 0, j = 0, x = 0, xend; - int x_left = 0; - char inputstr[132], inputbuf[132] = ""; - - blank_statusbar(); - mvwaddstr(bottomwin, 0, 0, buf); - if (strlen(def) > 0) - waddstr(bottomwin, def); - wrefresh(bottomwin); + int x_left = 0, inputlen; + char *inputbuf; + + inputbuf = nmalloc(strlen(def) + 1); + inputbuf[0] = 0; x_left = strlen(buf); x = strlen(def) + x_left; /* Get the input! */ - if (strlen(def) > 0) { - strcpy(answer, def); + if (strlen(def) > 0) strcpy(inputbuf, def); - } + + nanoget_repaint(buf, inputbuf, x); while ((kbinput = wgetch(bottomwin)) != 13) { for (j = 0; j <= slen - 1; j++) { @@ -307,9 +313,7 @@ int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x) inputbuf[strlen(inputbuf) - 1] = 0; } } - blank_statusbar(); - mvwaddstr(bottomwin, 0, 0, buf); - waddstr(bottomwin, inputbuf); + nanoget_repaint(buf, inputbuf, x); case KEY_LEFT: if (x > strlen(buf)) x--; @@ -378,11 +382,15 @@ int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x) default: if (kbinput < 32) break; - strcpy(inputstr, inputbuf); - inputstr[x - strlen(buf)] = kbinput; - strcpy(&inputstr[x - strlen(buf) + 1], - &inputbuf[x - strlen(buf)]); - strcpy(inputbuf, inputstr); + + inputlen = strlen(inputbuf); + inputbuf = nrealloc(inputbuf, inputlen + 2); + + memmove(&inputbuf[x - x_left + 1], + &inputbuf[x - x_left], + inputlen - (x - x_left) + 1); + inputbuf[x - x_left] = kbinput; + x++; nanoget_repaint(buf, inputbuf, x); @@ -393,7 +401,7 @@ int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x) wrefresh(bottomwin); } - strncpy(answer, inputbuf, 132); + answer = mallocstrcpy(answer, inputbuf); /* Now that the text is editable instead of bracketed, we have to check for answer == def, instead of answer == "" */ -- 2.39.5