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.
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

View File

@ -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

View File

@ -186,49 +186,52 @@ Usage: nano [option] +LINE <file>\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;

BIN
po/es.gmo

Binary file not shown.

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

View File

@ -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);

View File

@ -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

17
utils.c
View File

@ -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)
{

54
winio.c
View File

@ -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 == "" */