Allow variable length strings on statusbar

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@257 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2000-11-02 04:40:39 +00:00
parent e7a647c343
commit 31925e4517
9 changed files with 186 additions and 113 deletions

View File

@ -5,6 +5,15 @@ CVS Code -
replace with the null string without needing a special key for it. replace with the null string without needing a special key for it.
changed code in search_init(), do_replace(), nanogetstr (see below). changed code in search_init(), do_replace(), nanogetstr (see below).
- Added some missing gettext calls here and there (Jordi). - 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 - global.c
- New global replace_list_2, for 2nd half of the replace dialog - New global replace_list_2, for 2nd half of the replace dialog

View File

@ -54,7 +54,7 @@ filestruct *editbot = NULL; /* Same for the bottom */
filestruct *filebot = NULL; /* Last node in the file struct */ filestruct *filebot = NULL; /* Last node in the file struct */
filestruct *cutbuffer = NULL; /* A place to store cut text */ 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 totlines = 0; /* Total number of lines in the file */
int totsize = 0; /* Total number of bytes in the file */ int totsize = 0; /* Total number of bytes in the file */
int placewewant = 0; /* The collum we'd like the cursor int placewewant = 0; /* The collum we'd like the cursor

View File

@ -186,49 +186,52 @@ Usage: nano [option] +LINE <file>\n\
{"Cannot move edit win", 153}, {"Cannot move edit win", 153},
{"Cannot resize bottom win", 154}, {"Cannot resize bottom win", 154},
{"Cannot move bottom win", 155}, {"Cannot move bottom win", 155},
{"%s enable/disable", 156}, {"Justify Complete", 156},
{"enabled", 157}, {"%s enable/disable", 157},
{"disabled", 158}, {"enabled", 158},
{"Main: set up windows\n", 159}, {"disabled", 159},
{"Main: bottom win\n", 160}, {"Main: set up windows\n", 160},
{"Main: open file\n", 161}, {"Main: bottom win\n", 161},
{"I got Alt-O-%c! (%d)\n", 162}, {"Main: open file\n", 162},
{"I got Alt-[-1-%c! (%d)\n", 163}, {"I got Alt-O-%c! (%d)\n", 163},
{"I got Alt-[-2-%c! (%d)\n", 164}, {"I got Alt-[-1-%c! (%d)\n", 164},
{"I got Alt-[-%c! (%d)\n", 165}, {"I got Alt-[-2-%c! (%d)\n", 165},
{"I got Alt-%c! (%d)\n", 166}, {"I got Alt-[-%c! (%d)\n", 166},
{"Case Sensitive Regexp Search%s%s", 167}, {"I got Alt-%c! (%d)\n", 167},
{"Regexp Search%s%s", 168}, {"Case Sensitive Regexp Search%s%s", 168},
{"Case Sensitive Search%s%s", 169}, {"Regexp Search%s%s", 169},
{"Search%s%s", 170}, {"Case Sensitive Search%s%s", 170},
{" (to replace)", 171}, {"Search%s%s", 171},
{"Search Cancelled", 172}, {" (to replace)", 172},
{"Search Wrapped", 173}, {"Search Cancelled", 173},
{"Replaced %d occurences", 174}, {"\"%s...\" not found", 174},
{"Replaced 1 occurence", 175}, {"Search Wrapped", 175},
{"Replace Cancelled", 176}, {"Replaced %d occurences", 176},
{"Replace with", 177}, {"Replaced 1 occurence", 177},
{"Replace this instance?", 178}, {"Replace Cancelled", 178},
{"Enter line number", 179}, {"Replace with", 179},
{"Aborted", 180}, {"Replace this instance?", 180},
{"Come on, be reasonable", 181}, {"Replace failed: unknown subexpression!", 181},
{"Only %d lines available, skipping to last line", 182}, {"Enter line number", 182},
{"actual_x_from_start for xplus=%d returned %d\n", 183}, {"Aborted", 183},
{"input '%c' (%d)\n", 184}, {"Come on, be reasonable", 184},
{"New Buffer", 185}, {"Only %d lines available, skipping to last line", 185},
{" File: ...", 186}, {"actual_x_from_start for xplus=%d returned %d\n", 186},
{"Modified", 187}, {"input '%c' (%d)\n", 187},
{"Moved to (%d, %d) in edit buffer\n", 188}, {"New Buffer", 188},
{"current->data = \"%s\"\n", 189}, {" File: ...", 189},
{"I got \"%s\"\n", 190}, {"Modified", 190},
{"Yes", 191}, {"Moved to (%d, %d) in edit buffer\n", 191},
{"All", 192}, {"current->data = \"%s\"\n", 192},
{"No", 193}, {"I got \"%s\"\n", 193},
{"do_cursorpos: linepct = %f, bytepct = %f\n", 194}, {"Yes", 194},
{"line %d of %d (%.0f%%), character %d of %d (%.0f%%)", 195}, {"All", 195},
{"Dumping file buffer to stderr...\n", 196}, {"No", 196},
{"Dumping cutbuffer to stderr...\n", 197}, {"do_cursorpos: linepct = %f, bytepct = %f\n", 197},
{"Dumping a buffer to stderr...\n", 198}, {"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;

BIN
po/es.gmo

Binary file not shown.

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -32,7 +32,7 @@ msgstr ""
msgid "Read %d lines" msgid "Read %d lines"
msgstr "" msgstr ""
#: files.c:217 search.c:161 search.c:196 #: files.c:217 search.c:148
#, c-format #, c-format
msgid "\"%s\" not found" msgid "\"%s\" not found"
msgstr "" msgstr ""
@ -380,7 +380,7 @@ msgid "Case Sens"
msgstr "" msgstr ""
#: global.c:344 global.c:364 global.c:375 global.c:385 global.c:401 #: 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" msgid "Cancel"
msgstr "" msgstr ""
@ -675,6 +675,10 @@ msgstr ""
msgid "Cannot move bottom win" msgid "Cannot move bottom win"
msgstr "" msgstr ""
#: nano.c:1567
msgid "Justify Complete"
msgstr ""
#: nano.c:1635 #: nano.c:1635
#, c-format #, c-format
msgid "%s enable/disable" msgid "%s enable/disable"
@ -725,73 +729,82 @@ msgstr ""
msgid "I got Alt-%c! (%d)\n" msgid "I got Alt-%c! (%d)\n"
msgstr "" msgstr ""
#: search.c:79 #: search.c:88
#, c-format #, c-format
msgid "Case Sensitive Regexp Search%s%s" msgid "Case Sensitive Regexp Search%s%s"
msgstr "" msgstr ""
#: search.c:81 #: search.c:90
#, c-format #, c-format
msgid "Regexp Search%s%s" msgid "Regexp Search%s%s"
msgstr "" msgstr ""
#: search.c:83 #: search.c:92
#, c-format #, c-format
msgid "Case Sensitive Search%s%s" msgid "Case Sensitive Search%s%s"
msgstr "" msgstr ""
#: search.c:85 #: search.c:94
#, c-format #, c-format
msgid "Search%s%s" msgid "Search%s%s"
msgstr "" msgstr ""
#: search.c:88 #: search.c:97
msgid " (to replace)" msgid " (to replace)"
msgstr "" msgstr ""
#: search.c:96 #: search.c:105 search.c:274
msgid "Search Cancelled" msgid "Search Cancelled"
msgstr "" msgstr ""
#: search.c:177 #: search.c:152
#, c-format
msgid "\"%s...\" not found"
msgstr ""
#: search.c:199
msgid "Search Wrapped" msgid "Search Wrapped"
msgstr "" msgstr ""
#: search.c:266 #: search.c:288
#, c-format #, c-format
msgid "Replaced %d occurences" msgid "Replaced %d occurences"
msgstr "" msgstr ""
#: search.c:268 #: search.c:290
msgid "Replaced 1 occurence" msgid "Replaced 1 occurence"
msgstr "" msgstr ""
#: search.c:404 search.c:420 search.c:442 #: search.c:426 search.c:442 search.c:464
msgid "Replace Cancelled" msgid "Replace Cancelled"
msgstr "" msgstr ""
#: search.c:436 #: search.c:458
msgid "Replace with" msgid "Replace with"
msgstr "" msgstr ""
#: search.c:473 #: search.c:495
msgid "Replace this instance?" msgid "Replace this instance?"
msgstr "" msgstr ""
#: search.c:503
msgid "Replace failed: unknown subexpression!"
msgstr ""
#. Ask for it #. Ask for it
#: search.c:534 #: search.c:556
msgid "Enter line number" msgid "Enter line number"
msgstr "" msgstr ""
#: search.c:536 #: search.c:558
msgid "Aborted" msgid "Aborted"
msgstr "" msgstr ""
#: search.c:556 #: search.c:578
msgid "Come on, be reasonable" msgid "Come on, be reasonable"
msgstr "" msgstr ""
#: search.c:561 #: search.c:583
#, c-format #, c-format
msgid "Only %d lines available, skipping to last line" msgid "Only %d lines available, skipping to last line"
msgstr "" msgstr ""
@ -801,67 +814,67 @@ msgstr ""
msgid "actual_x_from_start for xplus=%d returned %d\n" msgid "actual_x_from_start for xplus=%d returned %d\n"
msgstr "" msgstr ""
#: winio.c:390 #: winio.c:398
#, c-format #, c-format
msgid "input '%c' (%d)\n" msgid "input '%c' (%d)\n"
msgstr "" msgstr ""
#: winio.c:427 #: winio.c:435
msgid "New Buffer" msgid "New Buffer"
msgstr "" msgstr ""
#: winio.c:430 #: winio.c:438
msgid " File: ..." msgid " File: ..."
msgstr "" msgstr ""
#: winio.c:438 #: winio.c:446
msgid "Modified" msgid "Modified"
msgstr "" msgstr ""
#: winio.c:890 #: winio.c:898
#, c-format #, c-format
msgid "Moved to (%d, %d) in edit buffer\n" msgid "Moved to (%d, %d) in edit buffer\n"
msgstr "" msgstr ""
#: winio.c:901 #: winio.c:909
#, c-format #, c-format
msgid "current->data = \"%s\"\n" msgid "current->data = \"%s\"\n"
msgstr "" msgstr ""
#: winio.c:944 #: winio.c:952
#, c-format #, c-format
msgid "I got \"%s\"\n" msgid "I got \"%s\"\n"
msgstr "" msgstr ""
#: winio.c:969 #: winio.c:977
msgid "Yes" msgid "Yes"
msgstr "" msgstr ""
#: winio.c:971 #: winio.c:979
msgid "All" msgid "All"
msgstr "" msgstr ""
#: winio.c:973 #: winio.c:981
msgid "No" msgid "No"
msgstr "" msgstr ""
#: winio.c:1110 #: winio.c:1118
#, c-format #, c-format
msgid "do_cursorpos: linepct = %f, bytepct = %f\n" msgid "do_cursorpos: linepct = %f, bytepct = %f\n"
msgstr "" msgstr ""
#: winio.c:1114 #: winio.c:1122
msgid "line %d of %d (%.0f%%), character %d of %d (%.0f%%)" msgid "line %d of %d (%.0f%%), character %d of %d (%.0f%%)"
msgstr "" msgstr ""
#: winio.c:1242 #: winio.c:1250
msgid "Dumping file buffer to stderr...\n" msgid "Dumping file buffer to stderr...\n"
msgstr "" msgstr ""
#: winio.c:1244 #: winio.c:1252
msgid "Dumping cutbuffer to stderr...\n" msgid "Dumping cutbuffer to stderr...\n"
msgstr "" msgstr ""
#: winio.c:1246 #: winio.c:1254
msgid "Dumping a buffer to stderr...\n" msgid "Dumping a buffer to stderr...\n"
msgstr "" msgstr ""

View File

@ -38,7 +38,7 @@ extern int fill, flags,tabsize;
extern WINDOW *edit, *topwin, *bottomwin; extern WINDOW *edit, *topwin, *bottomwin;
extern char filename[PATH_MAX]; extern char filename[PATH_MAX];
extern char answer[132]; extern char *answer;
extern char *hblank, *help_text; extern char *hblank, *help_text;
extern struct stat fileinfo; extern struct stat fileinfo;
extern filestruct *current, *fileage, *edittop, *editbot, *filebot; extern filestruct *current, *fileage, *edittop, *editbot, *filebot;
@ -107,6 +107,7 @@ void center_cursor(void);
void bottombars(shortcut s[], int slen); void bottombars(shortcut s[], int slen);
void blank_statusbar_refresh(void); void blank_statusbar_refresh(void);
void *nmalloc (size_t howmuch); void *nmalloc (size_t howmuch);
void *mallocstrcpy(void *dest, void *src);
void wrap_reset(void); void wrap_reset(void);
void display_main_list(void); void display_main_list(void);
void nano_small_msg(void); void nano_small_msg(void);

View File

@ -34,8 +34,8 @@
#define _(string) (string) #define _(string) (string)
#endif #endif
static char last_search[132] = ""; /* Last string we searched for */ static char *last_search = NULL; /* Last string we searched for */
static char last_replace[132] = ""; /* Last replacement string */ static char *last_replace = NULL; /* Last replacement string */
static int search_last_line; static int search_last_line;
@ -67,6 +67,15 @@ int search_init(int replacing)
/* char buf[BUFSIZ]; */ /* char buf[BUFSIZ]; */
char *prompt, *reprompt = ""; 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]) { if (last_search[0]) {
snprintf(buf, BUFSIZ, " [%s]", last_search); snprintf(buf, BUFSIZ, " [%s]", last_search);
@ -97,13 +106,13 @@ int search_init(int replacing)
reset_cursor(); reset_cursor();
return -1; return -1;
} else if (i == -2) { /* Same string */ } else if (i == -2) { /* Same string */
strncpy(answer, last_search, 132); answer = mallocstrcpy(answer, last_search);
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) if (ISSET(USE_REGEXP))
regexp_init(answer); regexp_init(answer);
#endif #endif
} else if (i == 0) { /* They entered something new */ } else if (i == 0) { /* They entered something new */
strncpy(last_search, answer, 132); last_search = mallocstrcpy(last_search, answer);
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) if (ISSET(USE_REGEXP))
regexp_init(answer); regexp_init(answer);
@ -131,6 +140,19 @@ int search_init(int replacing)
return 0; 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, filestruct *findnextstr(int quiet, filestruct * begin, int beginx,
char *needle) char *needle)
{ {
@ -158,7 +180,7 @@ filestruct *findnextstr(int quiet, filestruct * begin, int beginx,
/* finished processing file, get out */ /* finished processing file, get out */
if (search_last_line) { if (search_last_line) {
if (!quiet) if (!quiet)
statusbar(_("\"%s\" not found"), needle); not_found_msg(needle);
return NULL; return NULL;
} }
@ -193,7 +215,7 @@ filestruct *findnextstr(int quiet, filestruct * begin, int beginx,
/* Ensure we haven't wrap around again! */ /* Ensure we haven't wrap around again! */
if ((search_last_line) && (current_x >= beginx)) { if ((search_last_line) && (current_x >= beginx)) {
if (!quiet) if (!quiet)
statusbar(_("\"%s\" not found"), needle); not_found_msg(needle);
return NULL; return NULL;
} }
@ -396,7 +418,7 @@ int do_replace(void)
{ {
int i, replaceall = 0, numreplaced = 0, beginx; int i, replaceall = 0, numreplaced = 0, beginx;
filestruct *fileptr, *begin; filestruct *fileptr, *begin;
char *copy, prevanswer[132] = ""; char *copy, *prevanswer = NULL;
i = search_init(1); i = search_init(1);
switch (i) { switch (i) {
@ -422,7 +444,7 @@ int do_replace(void)
return 0; return 0;
} }
strncpy(prevanswer, answer, 132); prevanswer = mallocstrcpy(prevanswer, answer);
/* /*
if (strcmp(last_replace, "")) * There's a previous replace str * if (strcmp(last_replace, "")) * There's a previous replace str *
@ -438,12 +460,12 @@ int do_replace(void)
switch (i) { switch (i) {
case -1: /* Aborted enter */ case -1: /* Aborted enter */
if (strcmp(last_replace, "")) if (strcmp(last_replace, ""))
strncpy(answer, last_replace, 132); answer = mallocstrcpy(answer, last_replace);
statusbar(_("Replace Cancelled")); statusbar(_("Replace Cancelled"));
replace_abort(); replace_abort();
return 0; return 0;
case 0: /* They actually entered something */ case 0: /* They actually entered something */
strncpy(last_replace, answer, 132); last_replace = mallocstrcpy(last_replace, answer);
break; break;
default: default:
if (i != -2) { /* First page, last page, for example if (i != -2) { /* First page, last page, for example

17
utils.c
View File

@ -119,6 +119,23 @@ void *nrealloc(void *ptr, size_t howmuch)
return r; 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 */ /* Append a new magic-line to filebot */
void new_magicline(void) void new_magicline(void)
{ {

54
winio.c
View File

@ -222,32 +222,38 @@ void check_statblank(void)
void nanoget_repaint(char *buf, char *inputbuf, int x) void nanoget_repaint(char *buf, char *inputbuf, int x)
{ {
blank_statusbar(); blank_statusbar();
mvwaddstr(bottomwin, 0, 0, buf); if (x <= COLS) {
waddstr(bottomwin, inputbuf); mvwaddstr(bottomwin, 0, 0, buf);
wmove(bottomwin, 0, x); 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 */ /* 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 nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x)
{ {
int kbinput = 0, j = 0, x = 0, xend; int kbinput = 0, j = 0, x = 0, xend;
int x_left = 0; int x_left = 0, inputlen;
char inputstr[132], inputbuf[132] = ""; char *inputbuf;
blank_statusbar(); inputbuf = nmalloc(strlen(def) + 1);
mvwaddstr(bottomwin, 0, 0, buf); inputbuf[0] = 0;
if (strlen(def) > 0)
waddstr(bottomwin, def);
wrefresh(bottomwin);
x_left = strlen(buf); x_left = strlen(buf);
x = strlen(def) + x_left; x = strlen(def) + x_left;
/* Get the input! */ /* Get the input! */
if (strlen(def) > 0) { if (strlen(def) > 0)
strcpy(answer, def);
strcpy(inputbuf, def); strcpy(inputbuf, def);
}
nanoget_repaint(buf, inputbuf, x);
while ((kbinput = wgetch(bottomwin)) != 13) { while ((kbinput = wgetch(bottomwin)) != 13) {
for (j = 0; j <= slen - 1; j++) { 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; inputbuf[strlen(inputbuf) - 1] = 0;
} }
} }
blank_statusbar(); nanoget_repaint(buf, inputbuf, x);
mvwaddstr(bottomwin, 0, 0, buf);
waddstr(bottomwin, inputbuf);
case KEY_LEFT: case KEY_LEFT:
if (x > strlen(buf)) if (x > strlen(buf))
x--; x--;
@ -378,11 +382,15 @@ int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x)
default: default:
if (kbinput < 32) if (kbinput < 32)
break; break;
strcpy(inputstr, inputbuf);
inputstr[x - strlen(buf)] = kbinput; inputlen = strlen(inputbuf);
strcpy(&inputstr[x - strlen(buf) + 1], inputbuf = nrealloc(inputbuf, inputlen + 2);
&inputbuf[x - strlen(buf)]);
strcpy(inputbuf, inputstr); memmove(&inputbuf[x - x_left + 1],
&inputbuf[x - x_left],
inputlen - (x - x_left) + 1);
inputbuf[x - x_left] = kbinput;
x++; x++;
nanoget_repaint(buf, inputbuf, 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); wrefresh(bottomwin);
} }
strncpy(answer, inputbuf, 132); answer = mallocstrcpy(answer, inputbuf);
/* Now that the text is editable instead of bracketed, we have to /* Now that the text is editable instead of bracketed, we have to
check for answer == def, instead of answer == "" */ check for answer == def, instead of answer == "" */