Commit 27eb13f0 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

Rocco's spelling code

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@266 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 489 additions and 243 deletions
+489 -243
...@@ -14,6 +14,11 @@ CVS Code - ...@@ -14,6 +14,11 @@ CVS Code -
pointers. New function not_found_msg in search.c for displaying pointers. New function not_found_msg in search.c for displaying
truncated strings in satusbar when the string is not found. truncated strings in satusbar when the string is not found.
We disable this feature when using PICO_MSGS (-p). We disable this feature when using PICO_MSGS (-p).
- New spelling code by Rocco Corsi. New functions
do_int_speller, do_alt_speller, changes to do_spell in nano.c,
New functions search_init_globals and do_replace_loop, changes
to search_init(), do_replace, findnextstr, moved last_search and
last_replace back to nano.c (*shrug*).
- files.c: - files.c:
do_writeout() do_writeout()
- Change strcpy to answer to mallocstrcpy. - Change strcpy to answer to mallocstrcpy.
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h> #include <errno.h>
#include <ctype.h> #include <ctype.h>
#include <locale.h> #include <locale.h>
...@@ -66,6 +68,10 @@ static char *help_text_init = ""; ...@@ -66,6 +68,10 @@ static char *help_text_init = "";
/* Initial message, not including shortcuts */ /* Initial message, not including shortcuts */
static struct sigaction act; /* For all out fun signal handlers */ static struct sigaction act; /* For all out fun signal handlers */
char *last_search = NULL; /* Last string we searched for */
char *last_replace = NULL; /* Last replacement string */
int search_last_line; /* Is this the last search line? */
void keypad_on(int yesno) void keypad_on(int yesno)
{ {
keypad(edit, yesno); keypad(edit, yesno);
...@@ -1045,6 +1051,8 @@ void wrap_reset(void) ...@@ -1045,6 +1051,8 @@ void wrap_reset(void)
UNSET(SAMELINEWRAP); UNSET(SAMELINEWRAP);
} }
#ifndef NANO_SMALL
/* Stuff we want to do when we exit the spell program one of its many ways */ /* Stuff we want to do when we exit the spell program one of its many ways */
void exit_spell(char *tmpfilename, char *foo) void exit_spell(char *tmpfilename, char *foo)
{ {
...@@ -1054,65 +1062,259 @@ void exit_spell(char *tmpfilename, char *foo) ...@@ -1054,65 +1062,259 @@ void exit_spell(char *tmpfilename, char *foo)
statusbar(_("Error deleting tempfile, ack!")); statusbar(_("Error deleting tempfile, ack!"));
display_main_list(); display_main_list();
} }
#endif
/* #ifndef NANO_SMALL
* This is Chris' very ugly spell function. Someone please make this
* better =-) int do_int_spell_fix(char *word)
*/
int do_spell(void)
{ {
#ifdef NANO_SMALL char *prevanswer = NULL, *save_search = NULL, *save_replace = NULL;
nano_small_msg(); filestruct *begin, *begin_top;
return 1; int i = 0, beginx, beginx_top;
#else
char *temp, *foo;
int i, size;
if ((temp = tempnam(0, "nano.")) == NULL) { /* save where we are */
statusbar(_("Could not create a temporary filename: %s"), begin = current;
strerror(errno)); beginx = current_x + 1;
return 0;
/* save the current search/replace strings */
search_init_globals();
save_search = mallocstrcpy(save_search, last_search);
save_replace = mallocstrcpy(save_replace, last_replace);
/* set search/replace strings to mis-spelt word */
prevanswer = mallocstrcpy(prevanswer, word);
last_search = mallocstrcpy(last_search, word);
last_replace = mallocstrcpy(last_replace, word);
/* start from the top of file */
begin_top = current = fileage;
beginx_top = current_x = -1;
search_last_line = FALSE;
/* make sure word is still mis-spelt (i.e. when multi-errors) */
if (findnextstr(TRUE, begin_top, beginx_top, prevanswer) != NULL)
{
/* start from the start of this line again */
current = begin_top;
current_x = beginx_top;
search_last_line = FALSE;
/* allow replace word to be corrected */
i = statusq(replace_list_2, REPLACE_LIST_2_LEN, last_replace,
_("Edit a replacement"));
do_replace_loop(prevanswer, begin_top, &beginx_top, TRUE, &i);
} }
if (write_file(temp, 1) == -1)
return 0;
if (alt_speller) { /* restore the search/replace strings */
size = strlen(temp) + strlen(alt_speller) + 2; last_search = mallocstrcpy(last_search, save_search);
foo = nmalloc(size); last_replace = mallocstrcpy(last_replace, save_replace);
snprintf(foo, size, "%s %s", alt_speller, temp);
} else {
/* For now, we only try ispell because we're not capable of /* restore where we were */
handling the normal spell program (yet...) */ current = begin;
size = strlen(temp) + 8; current_x = beginx - 1;
foo = nmalloc(size);
snprintf(foo, size, "ispell %s", temp); edit_update(current, CENTER);
if (i == -1)
return FALSE;
return TRUE;
}
#endif
#ifndef NANO_SMALL
/* Integrated spell checking using 'spell' program */
int do_int_speller(void)
{
filestruct *fileptr;
char read_buff[2], *read_buff_ptr;
char curr_word[132], *curr_word_ptr;
int in_fd[2], out_fd[2];
int spell_status;
pid_t pid_spell;
ssize_t bytesread;
/* Input from spell pipe */
if (pipe(in_fd) == -1)
return FALSE;
/* Output to spell pipe */
if (pipe(out_fd) == -1) {
close(in_fd[0]);
close(in_fd[1]);
return FALSE;
} }
endwin(); if ( (pid_spell = fork()) == 0) {
if (alt_speller) {
if ((i = system(foo)) == -1 || i == 32512) { /* Child continues, (i.e. future spell process) */
statusbar(_("Could not invoke spell program \"%s\""),
alt_speller); close(in_fd[1]);
exit_spell(temp, foo); close(out_fd[0]);
return 0;
/* setup spell standard in */
if (dup2(in_fd[0], STDIN_FILENO) != STDIN_FILENO)
{
close(in_fd[0]);
close(out_fd[1]);
return FALSE;
} }
} else if ((i = system(foo)) == -1 || i == 32512) { /* Why 32512? I dont know! */ close(in_fd[0]);
statusbar(_("Could not invoke \"ispell\""));
exit_spell(temp, foo); /* setup spell standard out */
return 0; if (dup2(out_fd[1], STDOUT_FILENO) != STDOUT_FILENO)
{
close(out_fd[1]);
return FALSE;
}
close(out_fd[1]);
/* Start spell program */
execlp("spell", "spell", NULL);
/* Should not be reached, if spell is available!!! */
exit(-1);
} }
/* initscr(); */
/* Parent continues here */
close(in_fd[0]); /* close child's input pipe */
close(out_fd[1]); /* close child's output pipe */
if (pid_spell < 0) {
/* Child process was not forked successfully */
close(in_fd[1]); /* close parent's output pipe */
close(out_fd[0]); /* close parent's input pipe */
return FALSE;
}
/* Send out the file content to spell program */
fileptr = fileage;
while ( fileptr != NULL )
{
write(in_fd[1], fileptr->data, strlen(fileptr->data));
write(in_fd[1], "\n", 1);
fileptr = fileptr->next;
}
close(in_fd[1]);
/* Let spell process the file */
wait(&spell_status);
if (spell_status != 0)
return FALSE;
/* Read spelling errors from spell */
curr_word_ptr = curr_word;
while ( (bytesread = read(out_fd[0], read_buff, sizeof(read_buff) - 1)) > 0)
{
read_buff[bytesread]=(char) NULL;
read_buff_ptr = read_buff;
while (*read_buff_ptr != (char) NULL)
{
if (*read_buff_ptr == '\n') {
*curr_word_ptr = (char) NULL;
if (do_int_spell_fix(curr_word) == FALSE)
{
close(out_fd[0]);
return TRUE;
}
curr_word_ptr = curr_word;
}
else {
*curr_word_ptr = *read_buff_ptr;
curr_word_ptr++;
}
read_buff_ptr++;
}
}
close(out_fd[0]);
replace_abort();
return TRUE;
}
#endif
#ifndef NANO_SMALL
/* External spell checking */
int do_alt_speller(char *command_line, char *file_name)
{
int i;
endwin();
if ( (i = system(command_line) == -1) || (i == 32512))
return FALSE;
refresh(); refresh();
free_filestruct(fileage); free_filestruct(fileage);
global_init(); global_init();
open_file(temp, 0, 1); open_file(file_name, 0, 1);
edit_update(fileage, CENTER); edit_update(fileage, CENTER);
set_modified(); set_modified();
exit_spell(temp, foo);
statusbar(_("Finished checking spelling")); return TRUE;
return 1; }
#endif
int do_spell(void)
{
#ifdef NANO_SMALL
nano_small_msg();
return (TRUE);
#else
char *temp, *foo;
int size, spell_res;
if (alt_speller) {
if ((temp = tempnam(0, "nano.")) == NULL) {
statusbar(_("Could not create a temporary filename: %s"),
strerror(errno));
return 0;
}
if (write_file(temp, 1) == -1)
return 0;
size = strlen(temp) + strlen(alt_speller) + 2;
foo = nmalloc(size);
snprintf(foo, size, "%s %s", alt_speller, temp);
spell_res = do_alt_speller(foo, temp);
exit_spell(temp, foo);
} else
spell_res = do_int_speller();
if (spell_res)
statusbar(_("Finished checking spelling"));
else
statusbar(_("Spell checking failed"));
return spell_res;
#endif #endif
} }
......
...@@ -175,10 +175,10 @@ Usage: nano [option] +LINE <file>\n\ ...@@ -175,10 +175,10 @@ Usage: nano [option] +LINE <file>\n\
{"current->data now = \"%s\"\n", 142}, {"current->data now = \"%s\"\n", 142},
{"After, data = \"%s\"\n", 143}, {"After, data = \"%s\"\n", 143},
{"Error deleting tempfile, ack!", 144}, {"Error deleting tempfile, ack!", 144},
{"Could not create a temporary filename: %s", 145}, {"Edit a replacement", 145},
{"Could not invoke spell program \"%s\"", 146}, {"Could not create a temporary filename: %s", 146},
{"Could not invoke \"ispell\"", 147}, {"Finished checking spelling", 147},
{"Finished checking spelling", 148}, {"Spell checking failed", 148},
{"Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? ", 149}, {"Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? ", 149},
{"Cannot resize top win", 150}, {"Cannot resize top win", 150},
{"Cannot move top win", 151}, {"Cannot move top win", 151},
...@@ -209,10 +209,10 @@ Usage: nano [option] +LINE <file>\n\ ...@@ -209,10 +209,10 @@ Usage: nano [option] +LINE <file>\n\
{"Replaced %d occurences", 176}, {"Replaced %d occurences", 176},
{"Replaced 1 occurence", 177}, {"Replaced 1 occurence", 177},
{"Replace Cancelled", 178}, {"Replace Cancelled", 178},
{"Replace with [%s]", 179}, {"Replace this instance?", 179},
{"Replace with", 180}, {"Replace failed: unknown subexpression!", 180},
{"Replace this instance?", 181}, {"Replace with [%s]", 181},
{"Replace failed: unknown subexpression!", 182}, {"Replace with", 182},
{"Enter line number", 183}, {"Enter line number", 183},
{"Aborted", 184}, {"Aborted", 184},
{"Come on, be reasonable", 185}, {"Come on, be reasonable", 185},
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-11-03 09:21-0500\n" "POT-Creation-Date: 2000-11-05 11:52-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 "" ...@@ -32,7 +32,7 @@ msgstr ""
msgid "Read %d lines" msgid "Read %d lines"
msgstr "" msgstr ""
#: files.c:217 search.c:163 #: files.c:217 search.c:164
#, c-format #, c-format
msgid "\"%s\" not found" msgid "\"%s\" not found"
msgstr "" msgstr ""
...@@ -55,7 +55,7 @@ msgstr "" ...@@ -55,7 +55,7 @@ msgstr ""
msgid "File to insert [from ./] " msgid "File to insert [from ./] "
msgstr "" msgstr ""
#: files.c:274 files.c:298 files.c:486 nano.c:1145 #: files.c:274 files.c:298 files.c:486 nano.c:1347
msgid "Cancelled" msgid "Cancelled"
msgstr "" msgstr ""
...@@ -388,17 +388,17 @@ msgstr "" ...@@ -388,17 +388,17 @@ msgstr ""
msgid "No Replace" msgid "No Replace"
msgstr "" msgstr ""
#: nano.c:125 #: nano.c:131
msgid "" msgid ""
"\n" "\n"
"Buffer written to 'nano.save'\n" "Buffer written to 'nano.save'\n"
msgstr "" msgstr ""
#: nano.c:132 #: nano.c:138
msgid "Key illegal in VIEW mode" msgid "Key illegal in VIEW mode"
msgstr "" msgstr ""
#: nano.c:169 #: nano.c:175
msgid "" msgid ""
" nano help text\n" " nano help text\n"
"\n" "\n"
...@@ -419,397 +419,395 @@ msgid "" ...@@ -419,397 +419,395 @@ msgid ""
"\n" "\n"
msgstr "" msgstr ""
#: nano.c:272 #: nano.c:278
msgid "free_node(): free'd a node, YAY!\n" msgid "free_node(): free'd a node, YAY!\n"
msgstr "" msgstr ""
#: nano.c:277 #: nano.c:283
msgid "free_node(): free'd last node.\n" msgid "free_node(): free'd last node.\n"
msgstr "" msgstr ""
#: nano.c:329 #: nano.c:335
msgid "" msgid ""
"Usage: nano [GNU long option] [option] +LINE <file>\n" "Usage: nano [GNU long option] [option] +LINE <file>\n"
"\n" "\n"
msgstr "" msgstr ""
#: nano.c:330 #: nano.c:336
msgid "Option\t\tLong option\t\tMeaning\n" msgid "Option\t\tLong option\t\tMeaning\n"
msgstr "" msgstr ""
#: nano.c:332 #: nano.c:338
msgid " -T \t\t--tabsize=[num]\t\tSet width of a tab to num\n" msgid " -T \t\t--tabsize=[num]\t\tSet width of a tab to num\n"
msgstr "" msgstr ""
#: nano.c:335 #: nano.c:341
msgid " -R\t\t--regexp\t\tUse regular expressions for search\n" msgid " -R\t\t--regexp\t\tUse regular expressions for search\n"
msgstr "" msgstr ""
#: nano.c:339 #: nano.c:345
msgid " -V \t\t--version\t\tPrint version information and exit\n" msgid " -V \t\t--version\t\tPrint version information and exit\n"
msgstr "" msgstr ""
#: nano.c:341 #: nano.c:347
msgid " -c \t\t--const\t\t\tConstantly show cursor position\n" msgid " -c \t\t--const\t\t\tConstantly show cursor position\n"
msgstr "" msgstr ""
#: nano.c:343 #: nano.c:349
msgid " -h \t\t--help\t\t\tShow this message\n" msgid " -h \t\t--help\t\t\tShow this message\n"
msgstr "" msgstr ""
#: nano.c:346 #: nano.c:352
msgid " -k \t\t--cut\t\t\tLet ^K cut from cursor to end of line\n" msgid " -k \t\t--cut\t\t\tLet ^K cut from cursor to end of line\n"
msgstr "" msgstr ""
#: nano.c:349 #: nano.c:355
msgid " -i \t\t--autoindent\t\tAutomatically indent new lines\n" msgid " -i \t\t--autoindent\t\tAutomatically indent new lines\n"
msgstr "" msgstr ""
#: nano.c:351 #: nano.c:357
msgid " -l \t\t--nofollow\t\tDon't follow symbolic links, overwrite\n" msgid " -l \t\t--nofollow\t\tDon't follow symbolic links, overwrite\n"
msgstr "" msgstr ""
#: nano.c:354 #: nano.c:360
msgid " -m \t\t--mouse\t\t\tEnable mouse\n" msgid " -m \t\t--mouse\t\t\tEnable mouse\n"
msgstr "" msgstr ""
#: nano.c:359 #: nano.c:365
msgid "" msgid ""
" -r [#cols] \t--fill=[#cols]\t\tSet fill cols to (wrap lines at) #cols\n" " -r [#cols] \t--fill=[#cols]\t\tSet fill cols to (wrap lines at) #cols\n"
msgstr "" msgstr ""
#: nano.c:361 #: nano.c:367
msgid " -p\t \t--pico\t\t\tMake bottom 2 lines more Pico-like\n" msgid " -p\t \t--pico\t\t\tMake bottom 2 lines more Pico-like\n"
msgstr "" msgstr ""
#: nano.c:363 #: nano.c:369
msgid " -s [prog] \t--speller=[prog]\tEnable alternate speller\n" msgid " -s [prog] \t--speller=[prog]\tEnable alternate speller\n"
msgstr "" msgstr ""
#: nano.c:365 #: nano.c:371
msgid " -t \t\t--tempfile\t\tAuto save on exit, don't prompt\n" msgid " -t \t\t--tempfile\t\tAuto save on exit, don't prompt\n"
msgstr "" msgstr ""
#: nano.c:367 #: nano.c:373
msgid " -v \t\t--view\t\t\tView (read only) mode\n" msgid " -v \t\t--view\t\t\tView (read only) mode\n"
msgstr "" msgstr ""
#: nano.c:369 #: nano.c:375
msgid " -w \t\t--nowrap\t\tDon't wrap long lines\n" msgid " -w \t\t--nowrap\t\tDon't wrap long lines\n"
msgstr "" msgstr ""
#: nano.c:371 #: nano.c:377
msgid " -x \t\t--nohelp\t\tDon't show help window\n" msgid " -x \t\t--nohelp\t\tDon't show help window\n"
msgstr "" msgstr ""
#: nano.c:373 #: nano.c:379
msgid " -z \t\t--suspend\t\tEnable suspend\n" msgid " -z \t\t--suspend\t\tEnable suspend\n"
msgstr "" msgstr ""
#: nano.c:375 #: nano.c:381
msgid " +LINE\t\t\t\t\tStart at line number LINE\n" msgid " +LINE\t\t\t\t\tStart at line number LINE\n"
msgstr "" msgstr ""
#: nano.c:377 #: nano.c:383
msgid "" msgid ""
"Usage: nano [option] +LINE <file>\n" "Usage: nano [option] +LINE <file>\n"
"\n" "\n"
msgstr "" msgstr ""
#: nano.c:378 #: nano.c:384
msgid "Option\t\tMeaning\n" msgid "Option\t\tMeaning\n"
msgstr "" msgstr ""
#: nano.c:379 #: nano.c:385
msgid " -T [num]\tSet width of a tab to num\n" msgid " -T [num]\tSet width of a tab to num\n"
msgstr "" msgstr ""
#: nano.c:380 #: nano.c:386
msgid " -R\t\tUse regular expressions for search\n" msgid " -R\t\tUse regular expressions for search\n"
msgstr "" msgstr ""
#: nano.c:381 #: nano.c:387
msgid " -V \t\tPrint version information and exit\n" msgid " -V \t\tPrint version information and exit\n"
msgstr "" msgstr ""
#: nano.c:382 #: nano.c:388
msgid " -c \t\tConstantly show cursor position\n" msgid " -c \t\tConstantly show cursor position\n"
msgstr "" msgstr ""
#: nano.c:383 #: nano.c:389
msgid " -h \t\tShow this message\n" msgid " -h \t\tShow this message\n"
msgstr "" msgstr ""
#: nano.c:385 #: nano.c:391
msgid " -k \t\tLet ^K cut from cursor to end of line\n" msgid " -k \t\tLet ^K cut from cursor to end of line\n"
msgstr "" msgstr ""
#: nano.c:387 #: nano.c:393
msgid " -i \t\tAutomatically indent new lines\n" msgid " -i \t\tAutomatically indent new lines\n"
msgstr "" msgstr ""
#: nano.c:389 #: nano.c:395
msgid " -l \t\tDon't follow symbolic links, overwrite\n" msgid " -l \t\tDon't follow symbolic links, overwrite\n"
msgstr "" msgstr ""
#: nano.c:392 #: nano.c:398
msgid " -m \t\tEnable mouse\n" msgid " -m \t\tEnable mouse\n"
msgstr "" msgstr ""
#: nano.c:396 #: nano.c:402
msgid " -r [#cols] \tSet fill cols to (wrap lines at) #cols\n" msgid " -r [#cols] \tSet fill cols to (wrap lines at) #cols\n"
msgstr "" msgstr ""
#: nano.c:397 #: nano.c:403
msgid " -s [prog] \tEnable alternate speller\n" msgid " -s [prog] \tEnable alternate speller\n"
msgstr "" msgstr ""
#: nano.c:398 #: nano.c:404
msgid " -p \t\tMake bottom 2 lines more Pico-like\n" msgid " -p \t\tMake bottom 2 lines more Pico-like\n"
msgstr "" msgstr ""
#: nano.c:399 #: nano.c:405
msgid " -t \t\tAuto save on exit, don't prompt\n" msgid " -t \t\tAuto save on exit, don't prompt\n"
msgstr "" msgstr ""
#: nano.c:400 #: nano.c:406
msgid " -v \t\tView (read only) mode\n" msgid " -v \t\tView (read only) mode\n"
msgstr "" msgstr ""
#: nano.c:401 #: nano.c:407
msgid " -w \t\tDon't wrap long lines\n" msgid " -w \t\tDon't wrap long lines\n"
msgstr "" msgstr ""
#: nano.c:402 #: nano.c:408
msgid " -x \t\tDon't show help window\n" msgid " -x \t\tDon't show help window\n"
msgstr "" msgstr ""
#: nano.c:403 #: nano.c:409
msgid " -z \t\tEnable suspend\n" msgid " -z \t\tEnable suspend\n"
msgstr "" msgstr ""
#: nano.c:404 #: nano.c:410
msgid " +LINE\t\tStart at line number LINE\n" msgid " +LINE\t\tStart at line number LINE\n"
msgstr "" msgstr ""
#: nano.c:411 #: nano.c:417
#, c-format #, c-format
msgid " nano version %s by Chris Allegretta (compiled %s, %s)\n" msgid " nano version %s by Chris Allegretta (compiled %s, %s)\n"
msgstr "" msgstr ""
#: nano.c:414 #: nano.c:420
msgid " Email: nano@nano-editor.org\tWeb: http://www.nano-editor.org\n" msgid " Email: nano@nano-editor.org\tWeb: http://www.nano-editor.org\n"
msgstr "" msgstr ""
#: nano.c:449 #: nano.c:455
msgid "Mark Set" msgid "Mark Set"
msgstr "" msgstr ""
#: nano.c:454 #: nano.c:460
msgid "Mark UNset" msgid "Mark UNset"
msgstr "" msgstr ""
#: nano.c:881 #: nano.c:887
#, c-format #, c-format
msgid "check_wrap called with inptr->data=\"%s\"\n" msgid "check_wrap called with inptr->data=\"%s\"\n"
msgstr "" msgstr ""
#: nano.c:932 #: nano.c:938
#, c-format #, c-format
msgid "current->data now = \"%s\"\n" msgid "current->data now = \"%s\"\n"
msgstr "" msgstr ""
#: nano.c:985 #: nano.c:991
#, c-format #, c-format
msgid "After, data = \"%s\"\n" msgid "After, data = \"%s\"\n"
msgstr "" msgstr ""
#: nano.c:1054 #: nano.c:1062
msgid "Error deleting tempfile, ack!" msgid "Error deleting tempfile, ack!"
msgstr "" msgstr ""
#: nano.c:1072 #: nano.c:1106
#, c-format msgid "Edit a replacement"
msgid "Could not create a temporary filename: %s"
msgstr "" msgstr ""
#: nano.c:1095 #: nano.c:1292
#, c-format #, c-format
msgid "Could not invoke spell program \"%s\"" msgid "Could not create a temporary filename: %s"
msgstr "" msgstr ""
#. Why 32512? I dont know! #: nano.c:1312
#: nano.c:1101 msgid "Finished checking spelling"
msgid "Could not invoke \"ispell\""
msgstr "" msgstr ""
#: nano.c:1114 #: nano.c:1314
msgid "Finished checking spelling" msgid "Spell checking failed"
msgstr "" msgstr ""
#: nano.c:1132 #: nano.c:1334
msgid "Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? " msgid "Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? "
msgstr "" msgstr ""
#: nano.c:1295 #: nano.c:1497
msgid "Cannot resize top win" msgid "Cannot resize top win"
msgstr "" msgstr ""
#: nano.c:1297 #: nano.c:1499
msgid "Cannot move top win" msgid "Cannot move top win"
msgstr "" msgstr ""
#: nano.c:1299 #: nano.c:1501
msgid "Cannot resize edit win" msgid "Cannot resize edit win"
msgstr "" msgstr ""
#: nano.c:1301 #: nano.c:1503
msgid "Cannot move edit win" msgid "Cannot move edit win"
msgstr "" msgstr ""
#: nano.c:1303 #: nano.c:1505
msgid "Cannot resize bottom win" msgid "Cannot resize bottom win"
msgstr "" msgstr ""
#: nano.c:1305 #: nano.c:1507
msgid "Cannot move bottom win" msgid "Cannot move bottom win"
msgstr "" msgstr ""
#: nano.c:1576 #: nano.c:1778
msgid "Justify Complete" msgid "Justify Complete"
msgstr "" msgstr ""
#: nano.c:1644 #: nano.c:1846
#, c-format #, c-format
msgid "%s enable/disable" msgid "%s enable/disable"
msgstr "" msgstr ""
#: nano.c:1656 #: nano.c:1858
msgid "enabled" msgid "enabled"
msgstr "" msgstr ""
#: nano.c:1657 #: nano.c:1859
msgid "disabled" msgid "disabled"
msgstr "" msgstr ""
#: nano.c:1887 #: nano.c:2089
msgid "Main: set up windows\n" msgid "Main: set up windows\n"
msgstr "" msgstr ""
#: nano.c:1900 #: nano.c:2102
msgid "Main: bottom win\n" msgid "Main: bottom win\n"
msgstr "" msgstr ""
#: nano.c:1906 #: nano.c:2108
msgid "Main: open file\n" msgid "Main: open file\n"
msgstr "" msgstr ""
#: nano.c:1940 #: nano.c:2142
#, c-format #, c-format
msgid "I got Alt-O-%c! (%d)\n" msgid "I got Alt-O-%c! (%d)\n"
msgstr "" msgstr ""
#: nano.c:1962 #: nano.c:2164
#, c-format #, c-format
msgid "I got Alt-[-1-%c! (%d)\n" msgid "I got Alt-[-1-%c! (%d)\n"
msgstr "" msgstr ""
#: nano.c:1995 #: nano.c:2197
#, c-format #, c-format
msgid "I got Alt-[-2-%c! (%d)\n" msgid "I got Alt-[-2-%c! (%d)\n"
msgstr "" msgstr ""
#: nano.c:2043 #: nano.c:2245
#, c-format #, c-format
msgid "I got Alt-[-%c! (%d)\n" msgid "I got Alt-[-%c! (%d)\n"
msgstr "" msgstr ""
#: nano.c:2069 #: nano.c:2271
#, c-format #, c-format
msgid "I got Alt-%c! (%d)\n" msgid "I got Alt-%c! (%d)\n"
msgstr "" msgstr ""
#: search.c:98 #: search.c:99
#, c-format #, c-format
msgid "Case Sensitive Regexp Search%s%s" msgid "Case Sensitive Regexp Search%s%s"
msgstr "" msgstr ""
#: search.c:100 #: search.c:101
#, c-format #, c-format
msgid "Regexp Search%s%s" msgid "Regexp Search%s%s"
msgstr "" msgstr ""
#: search.c:102 #: search.c:103
#, c-format #, c-format
msgid "Case Sensitive Search%s%s" msgid "Case Sensitive Search%s%s"
msgstr "" msgstr ""
#: search.c:104 #: search.c:105
#, c-format #, c-format
msgid "Search%s%s" msgid "Search%s%s"
msgstr "" msgstr ""
#: search.c:107 #: search.c:108
msgid " (to replace)" msgid " (to replace)"
msgstr "" msgstr ""
#: search.c:120 search.c:289 #: search.c:121 search.c:290
msgid "Search Cancelled" msgid "Search Cancelled"
msgstr "" msgstr ""
#: search.c:167 #: search.c:168
#, c-format #, c-format
msgid "\"%s...\" not found" msgid "\"%s...\" not found"
msgstr "" msgstr ""
#: search.c:214 #: search.c:215
msgid "Search Wrapped" msgid "Search Wrapped"
msgstr "" msgstr ""
#: search.c:303 #: search.c:304
#, c-format #, c-format
msgid "Replaced %d occurences" msgid "Replaced %d occurences"
msgstr "" msgstr ""
#: search.c:305 #: search.c:306
msgid "Replaced 1 occurence" msgid "Replaced 1 occurence"
msgstr "" msgstr ""
#: search.c:441 search.c:457 search.c:488 #: search.c:443 search.c:536 search.c:552
msgid "Replace Cancelled" msgid "Replace Cancelled"
msgstr "" msgstr ""
#: search.c:474 #: search.c:486
#, c-format msgid "Replace this instance?"
msgid "Replace with [%s]"
msgstr "" msgstr ""
#: search.c:478 search.c:482 #: search.c:494
msgid "Replace with" msgid "Replace failed: unknown subexpression!"
msgstr "" msgstr ""
#: search.c:519 #: search.c:569
msgid "Replace this instance?" #, c-format
msgid "Replace with [%s]"
msgstr "" msgstr ""
#: search.c:527 #: search.c:573 search.c:577
msgid "Replace failed: unknown subexpression!" msgid "Replace with"
msgstr "" msgstr ""
#. Ask for it #. Ask for it
#: search.c:580 #: search.c:612
msgid "Enter line number" msgid "Enter line number"
msgstr "" msgstr ""
#: search.c:582 #: search.c:614
msgid "Aborted" msgid "Aborted"
msgstr "" msgstr ""
#: search.c:602 #: search.c:634
msgid "Come on, be reasonable" msgid "Come on, be reasonable"
msgstr "" msgstr ""
#: search.c:607 #: search.c:639
#, c-format #, c-format
msgid "Only %d lines available, skipping to last line" msgid "Only %d lines available, skipping to last line"
msgstr "" msgstr ""
......
...@@ -35,11 +35,14 @@ extern int placewewant; ...@@ -35,11 +35,14 @@ extern int placewewant;
extern int mark_beginx, samelinewrap; extern int mark_beginx, samelinewrap;
extern int totsize, temp_opt; extern int totsize, temp_opt;
extern int fill, flags,tabsize; extern int fill, flags,tabsize;
extern int search_last_line;
extern WINDOW *edit, *topwin, *bottomwin; extern WINDOW *edit, *topwin, *bottomwin;
extern char filename[PATH_MAX]; extern char filename[PATH_MAX];
extern char *answer; extern char *answer;
extern char *hblank, *help_text; extern char *hblank, *help_text;
extern char *last_search;
extern char *last_replace;
extern struct stat fileinfo; extern struct stat fileinfo;
extern filestruct *current, *fileage, *edittop, *editbot, *filebot; extern filestruct *current, *fileage, *edittop, *editbot, *filebot;
extern filestruct *cutbuffer, *mark_beginbuf; extern filestruct *cutbuffer, *mark_beginbuf;
...@@ -77,6 +80,8 @@ int renumber_all(void); ...@@ -77,6 +80,8 @@ int renumber_all(void);
int open_file(char *filename, int insert, int quiet); int open_file(char *filename, int insert, int quiet);
int do_writeout(int exiting); int do_writeout(int exiting);
int do_gotoline(long defline); int do_gotoline(long defline);
int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
int wholewords, int *i);
/* Now in move.c */ /* Now in move.c */
int do_up(void); int do_up(void);
int do_down(void); int do_down(void);
...@@ -120,6 +125,8 @@ void new_magicline(void); ...@@ -120,6 +125,8 @@ void new_magicline(void);
void splice_node(filestruct *begin, filestruct *new, filestruct *end); void splice_node(filestruct *begin, filestruct *new, filestruct *end);
void null_at(char *data, int index); void null_at(char *data, int index);
void page_up_center(void); void page_up_center(void);
void search_init_globals(void);
void replace_abort(void);
int do_writeout_void(void), do_exit(void), do_gotoline_void(void); int do_writeout_void(void), do_exit(void), do_gotoline_void(void);
int do_insertfile(void), do_search(void), page_up(void), page_down(void); int do_insertfile(void), do_search(void), page_up(void), page_down(void);
...@@ -133,3 +140,5 @@ int do_replace(void), do_help(void), do_enter_void(void); ...@@ -133,3 +140,5 @@ int do_replace(void), do_help(void), do_enter_void(void);
filestruct *copy_node(filestruct * src); filestruct *copy_node(filestruct * src);
filestruct *copy_filestruct(filestruct * src); filestruct *copy_filestruct(filestruct * src);
filestruct *make_new_node(filestruct * prevnode); filestruct *make_new_node(filestruct * prevnode);
filestruct *findnextstr(int quiet, filestruct * begin,
int beginx, char *needle);
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h>
#include "config.h" #include "config.h"
#include "proto.h" #include "proto.h"
#include "nano.h" #include "nano.h"
...@@ -34,11 +35,6 @@ ...@@ -34,11 +35,6 @@
#define _(string) (string) #define _(string) (string)
#endif #endif
static char *last_search = NULL; /* Last string we searched for */
static char *last_replace = NULL; /* Last replacement string */
static int search_last_line;
/* Regular expression helper functions */ /* Regular expression helper functions */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
...@@ -55,6 +51,18 @@ void regexp_cleanup() ...@@ -55,6 +51,18 @@ void regexp_cleanup()
} }
#endif #endif
void search_init_globals(void)
{
if (last_search == NULL) {
last_search = nmalloc(1);
last_search[0] = 0;
}
if (last_replace == NULL) {
last_replace = nmalloc(1);
last_replace[0] = 0;
}
}
/* Set up the system variables for a search or replace. Returns -1 on /* Set up the system variables for a search or replace. Returns -1 on
abort, 0 on success, and 1 on rerun calling program abort, 0 on success, and 1 on rerun calling program
Return -2 to run opposite program (searchg -> replace, replace -> search) Return -2 to run opposite program (searchg -> replace, replace -> search)
...@@ -67,20 +75,13 @@ int search_init(int replacing) ...@@ -67,20 +75,13 @@ int search_init(int replacing)
char *buf; char *buf;
char *prompt, *reprompt = ""; char *prompt, *reprompt = "";
if (last_search == NULL) { search_init_globals();
last_search = nmalloc(1);
last_search[0] = 0;
}
if (last_replace == NULL) {
last_replace = nmalloc(1);
last_replace[0] = 0;
}
buf = nmalloc(strlen(last_search) + 5); buf = nmalloc(strlen(last_search) + 5);
buf[0] = 0; buf[0] = 0;
/* If using Pico messages, we do things the old fashioned way... */ /* If using Pico messages, we do things the old fashioned way... */
if (ISSET(PICO_MSGS)) { if (ISSET(PICO_MSGS)) {
if (last_search[0]) { if (last_search[0]) {
/* We use COLS / 3 here because we need to see more on the line */ /* We use COLS / 3 here because we need to see more on the line */
...@@ -428,60 +429,14 @@ char *replace_line(void) ...@@ -428,60 +429,14 @@ char *replace_line(void)
return copy; return copy;
} }
/* Replace a string */ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
int do_replace(void) int wholewords, int *i)
{ {
int i, replaceall = 0, numreplaced = 0, beginx; int replaceall = 0, numreplaced = 0;
filestruct *fileptr, *begin; filestruct *fileptr;
char *copy, *prevanswer = NULL, *buf = NULL; char *copy;
i = search_init(1);
switch (i) {
case -1:
statusbar(_("Replace Cancelled"));
replace_abort();
return 0;
case 1:
do_replace();
return 1;
case -2:
do_search();
return 0;
case -3:
replace_abort();
return 0;
}
/* Again, there was a previous string but they deleted it and hit enter */
if (!strcmp(answer, "")) {
statusbar(_("Replace Cancelled"));
replace_abort();
return 0;
}
prevanswer = mallocstrcpy(prevanswer, answer);
if (ISSET(PICO_MSGS)) {
buf = nmalloc(strlen(last_replace) + 5);
if (strcmp(last_replace, "")) {
if (strlen(last_replace) > (COLS / 3)) {
strncpy(buf, last_replace, COLS / 3);
sprintf(&buf[COLS / 3 - 1], "...");
} else
sprintf(buf, "%s", last_replace);
i = statusq(replace_list_2, REPLACE_LIST_2_LEN, "",
_("Replace with [%s]"), buf);
}
else
i = statusq(replace_list_2, REPLACE_LIST_2_LEN, "",
_("Replace with"));
}
else
i = statusq(replace_list_2, REPLACE_LIST_2_LEN, last_replace,
_("Replace with"));
switch (i) { switch (*i) {
case -1: /* Aborted enter */ case -1: /* Aborted enter */
if (strcmp(last_replace, "")) if (strcmp(last_replace, ""))
answer = mallocstrcpy(answer, last_replace); answer = mallocstrcpy(answer, last_replace);
...@@ -492,7 +447,7 @@ int do_replace(void) ...@@ -492,7 +447,7 @@ int do_replace(void)
last_replace = mallocstrcpy(last_replace, answer); 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
could get here */ could get here */
do_early_abort(); do_early_abort();
replace_abort(); replace_abort();
...@@ -500,26 +455,38 @@ int do_replace(void) ...@@ -500,26 +455,38 @@ int do_replace(void)
} }
} }
/* save where we are */
begin = current;
beginx = current_x + 1;
search_last_line = 0;
while (1) { while (1) {
/* Sweet optimization by Rocco here */ /* Sweet optimization by Rocco here */
fileptr = findnextstr(replaceall, begin, beginx, prevanswer); fileptr = findnextstr(replaceall, begin, *beginx, prevanswer);
/* No more matches. Done! */ /* No more matches. Done! */
if (!fileptr) if (!fileptr)
break; break;
/* Make sure only wholewords are found */
if (wholewords)
{
/* start of line or previous character not a letter */
if ((current_x == 0) || (!isalpha(fileptr->data[current_x-1])))
{
/* end of line or next character not a letter */
if (((current_x + strlen(prevanswer)) == strlen(fileptr->data))
|| (!isalpha(fileptr->data[current_x + strlen(prevanswer)])))
;
else
continue;
}
else
continue;
}
/* If we're here, we've found the search string */ /* If we're here, we've found the search string */
if (!replaceall) if (!replaceall)
i = do_yesno(1, 1, _("Replace this instance?")); *i = do_yesno(1, 1, _("Replace this instance?"));
if (i > 0 || replaceall) { /* Yes, replace it!!!! */ if (*i > 0 || replaceall) { /* Yes, replace it!!!! */
if (i == 2) if (*i == 2)
replaceall = 1; replaceall = 1;
copy = replace_line(); copy = replace_line();
...@@ -538,21 +505,86 @@ int do_replace(void) ...@@ -538,21 +505,86 @@ int do_replace(void)
/* Adjust the original cursor position - COULD BE IMPROVED */ /* Adjust the original cursor position - COULD BE IMPROVED */
if (search_last_line) { if (search_last_line) {
beginx += strlen(last_replace) - strlen(last_search); *beginx += strlen(last_replace) - strlen(last_search);
/* For strings that cross the search start/end boundary */ /* For strings that cross the search start/end boundary */
/* Don't go outside of allocated memory */ /* Don't go outside of allocated memory */
if (beginx < 1) if (*beginx < 1)
beginx = 1; *beginx = 1;
} }
edit_refresh(); edit_refresh();
set_modified(); set_modified();
numreplaced++; numreplaced++;
} else if (i == -1) /* Abort, else do nothing and continue loop */ } else if (*i == -1) /* Abort, else do nothing and continue loop */
break; break;
} }
return numreplaced;
}
/* Replace a string */
int do_replace(void)
{
int i, numreplaced, beginx;
filestruct *begin;
char *prevanswer = NULL, *buf = NULL;
i = search_init(1);
switch (i) {
case -1:
statusbar(_("Replace Cancelled"));
replace_abort();
return 0;
case 1:
do_replace();
return 1;
case -2:
do_search();
return 0;
case -3:
replace_abort();
return 0;
}
/* Again, there was a previous string but they deleted it and hit enter */
if (!strcmp(answer, "")) {
statusbar(_("Replace Cancelled"));
replace_abort();
return 0;
}
prevanswer = mallocstrcpy(prevanswer, answer);
if (ISSET(PICO_MSGS)) {
buf = nmalloc(strlen(last_replace) + 5);
if (strcmp(last_replace, "")) {
if (strlen(last_replace) > (COLS / 3)) {
strncpy(buf, last_replace, COLS / 3);
sprintf(&buf[COLS / 3 - 1], "...");
} else
sprintf(buf, "%s", last_replace);
i = statusq(replace_list_2, REPLACE_LIST_2_LEN, "",
_("Replace with [%s]"), buf);
}
else
i = statusq(replace_list_2, REPLACE_LIST_2_LEN, "",
_("Replace with"));
}
else
i = statusq(replace_list_2, REPLACE_LIST_2_LEN, last_replace,
_("Replace with"));
/* save where we are */
begin = current;
beginx = current_x + 1;
search_last_line = 0;
numreplaced = do_replace_loop(prevanswer, begin, &beginx, FALSE, &i);
/* restore where we were */
current = begin; current = begin;
current_x = beginx - 1; current_x = beginx - 1;
renumber_all(); renumber_all();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment