Added _POSIX_VERSION check to regexp code

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@80 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2000-07-07 02:35:34 +00:00
parent cdff015d06
commit 47805612c3
4 changed files with 111 additions and 83 deletions

View File

@ -3,7 +3,9 @@ CVS code changes since last release -
- New regexp search feature by Bill Soudan. New flags USE_REGEXP
and REGEXP_COMPILED, new functions regexp_init, regexp_cleanup
replace_line, replace_regexp in search.c, changes to
search_init() and do_replace() and strstrwrapper().
search_init() and do_replace() and strstrwrapper().
- Added _POSIX_VERSION check to regexp code. Better than nothing
for non-POSIX systems...
- Made search functions & keys more like Pico. Added goto line from
search and replace function, changed wording to "No Replace" instead
of "To Search", "To Replace" to simply "Replace", and changed to

6
nano.c
View File

@ -312,8 +312,10 @@ void usage(void)
printf(_
(" -T --tabsize=[num] Set width of a tab to num\n"));
#endif
#ifdef _POSIX_VERSION
printf(_
(" -R --regexp Use regular expressions for search\n"));
#endif
printf
(_
(" -V --version Print version information and exit\n"));
@ -1531,7 +1533,9 @@ int main(int argc, char *argv[])
#ifdef HAVE_GETOPT_LONG
int option_index = 0;
struct option long_options[] = {
#ifdef _POSIX_VERSION
{"regexp", 0, 0, 'R'},
#endif
{"version", 0, 0, 'V'},
{"const", 0, 0, 'c'},
{"suspend", 0, 0, 'z'},
@ -1582,9 +1586,11 @@ int main(int argc, char *argv[])
usage(); /* Oops! You dont really have that option */
finish(1);
#endif
#ifdef _POSIX_VERSION
case 'R':
SET(USE_REGEXP);
break;
#endif
case 'V':
version();
exit(0);

View File

@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-07-06 21:41-0400\n"
"POT-Creation-Date: 2000-07-06 22:35-0400\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:215 search.c:156 search.c:174
#: files.c:215 search.c:163 search.c:181
#, c-format
msgid "\"%s\" not found"
msgstr ""
@ -55,7 +55,7 @@ msgstr ""
msgid "File to insert [from ./] "
msgstr ""
#: files.c:271 files.c:295 files.c:462 nano.c:1133
#: files.c:271 files.c:295 files.c:462 nano.c:1135
msgid "Cancelled"
msgstr ""
@ -403,323 +403,323 @@ msgstr ""
msgid " -T \t\t--tabsize=[num]\t\tSet width of a tab to num\n"
msgstr ""
#: nano.c:316
#: nano.c:317
msgid " -R\t\t--regexp\t\tUse regular expressions for search\n"
msgstr ""
#: nano.c:319
#: nano.c:321
msgid " -V \t\t--version\t\tPrint version information and exit\n"
msgstr ""
#: nano.c:321
#: nano.c:323
msgid " -c \t\t--const\t\t\tConstantly show cursor position\n"
msgstr ""
#: nano.c:323
#: nano.c:325
msgid " -h \t\t--help\t\t\tShow this message\n"
msgstr ""
#: nano.c:325
#: nano.c:327
msgid " -i \t\t--autoindent\t\tAutomatically indent new lines\n"
msgstr ""
#: nano.c:327
#: nano.c:329
msgid " -l \t\t--nofollow\t\tDon't follow symbolic links, overwrite.\n"
msgstr ""
#: nano.c:330
#: nano.c:332
msgid " -m \t\t--mouse\t\t\tEnable mouse\n"
msgstr ""
#: nano.c:335
#: nano.c:337
msgid ""
" -r [#cols] \t--fill=[#cols]\t\tSet fill cols to (wrap lines at) #cols\n"
msgstr ""
#: nano.c:337
#: nano.c:339
msgid " -p\t \t--pico\t\t\tMake bottom 2 lines more Pico-like\n"
msgstr ""
#: nano.c:339
#: nano.c:341
msgid " -s [prog] \t--speller=[prog]\tEnable alternate speller\n"
msgstr ""
#: nano.c:341
#: nano.c:343
msgid " -t \t\t--tempfile\t\tAuto save on exit, don't prompt\n"
msgstr ""
#: nano.c:343
#: nano.c:345
msgid " -v \t\t--view\t\t\tView (read only) mode\n"
msgstr ""
#: nano.c:345
#: nano.c:347
msgid " -w \t\t--nowrap\t\tDon't wrap long lines\n"
msgstr ""
#: nano.c:347
#: nano.c:349
msgid " -x \t\t--nohelp\t\tDon't show help window\n"
msgstr ""
#: nano.c:349
#: nano.c:351
msgid " -z \t\t--suspend\t\tEnable suspend\n"
msgstr ""
#: nano.c:351
#: nano.c:353
msgid " +LINE\t\t\t\t\tStart at line number LINE\n"
msgstr ""
#: nano.c:353
#: nano.c:355
msgid ""
"Usage: nano [option] +LINE <file>\n"
"\n"
msgstr ""
#: nano.c:354
#: nano.c:356
msgid "Option\t\tMeaning\n"
msgstr ""
#: nano.c:356
#: nano.c:358
msgid " -T [num]\tSet width of a tab to num\n"
msgstr ""
#: nano.c:358
#: nano.c:360
msgid " -R\t\tUse regular expressions for search\n"
msgstr ""
#: nano.c:359
#: nano.c:361
msgid " -V \t\tPrint version information and exit\n"
msgstr ""
#: nano.c:360
#: nano.c:362
msgid " -c \t\tConstantly show cursor position\n"
msgstr ""
#: nano.c:361
#: nano.c:363
msgid " -h \t\tShow this message\n"
msgstr ""
#: nano.c:362
#: nano.c:364
msgid " -i \t\tAutomatically indent new lines\n"
msgstr ""
#: nano.c:364
#: nano.c:366
msgid " -l \t\tDon't follow symbolic links, overwrite.\n"
msgstr ""
#: nano.c:367
#: nano.c:369
msgid " -m \t\tEnable mouse\n"
msgstr ""
#: nano.c:371
#: nano.c:373
msgid " -r [#cols] \tSet fill cols to (wrap lines at) #cols\n"
msgstr ""
#: nano.c:372
#: nano.c:374
msgid " -s [prog] \tEnable alternate speller\n"
msgstr ""
#: nano.c:373
#: nano.c:375
msgid " -p \t\tMake bottom 2 lines more Pico-like\n"
msgstr ""
#: nano.c:374
#: nano.c:376
msgid " -t \t\tAuto save on exit, don't prompt\n"
msgstr ""
#: nano.c:375
#: nano.c:377
msgid " -v \t\tView (read only) mode\n"
msgstr ""
#: nano.c:376
#: nano.c:378
msgid " -w \t\tDon't wrap long lines\n"
msgstr ""
#: nano.c:377
#: nano.c:379
msgid " -x \t\tDon't show help window\n"
msgstr ""
#: nano.c:378
#: nano.c:380
msgid " -z \t\tEnable suspend\n"
msgstr ""
#: nano.c:379
#: nano.c:381
msgid " +LINE\t\tStart at line number LINE\n"
msgstr ""
#: nano.c:386
#: nano.c:388
#, c-format
msgid " nano version %s by Chris Allegretta (compiled %s, %s)\n"
msgstr ""
#: nano.c:388
#: nano.c:390
msgid " Email: nano@asty.org\tWeb: http://www.asty.org/nano\n"
msgstr ""
#: nano.c:413
#: nano.c:415
msgid "Mark Set"
msgstr ""
#: nano.c:418
#: nano.c:420
msgid "Mark UNset"
msgstr ""
#: nano.c:860
#: nano.c:862
#, c-format
msgid "check_wrap called with inptr->data=\"%s\"\n"
msgstr ""
#: nano.c:920
#: nano.c:922
#, c-format
msgid "current->data now = \"%s\"\n"
msgstr ""
#: nano.c:973
#: nano.c:975
#, c-format
msgid "After, data = \"%s\"\n"
msgstr ""
#: nano.c:1043
#: nano.c:1045
msgid "Error deleting tempfile, ack!"
msgstr ""
#: nano.c:1060
#: nano.c:1062
#, c-format
msgid "Could not create a temporary filename: %s"
msgstr ""
#: nano.c:1084
#: nano.c:1086
#, c-format
msgid "Could not invoke spell program \"%s\""
msgstr ""
#. Why 32512? I dont know!
#: nano.c:1090
#: nano.c:1092
msgid "Could not invoke \"ispell\""
msgstr ""
#: nano.c:1102
#: nano.c:1104
msgid "Finished checking spelling"
msgstr ""
#: nano.c:1120
#: nano.c:1122
msgid "Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? "
msgstr ""
#: nano.c:1243
#: nano.c:1245
msgid "Cannot resize top win"
msgstr ""
#: nano.c:1245
#: nano.c:1247
msgid "Cannot move top win"
msgstr ""
#: nano.c:1247
#: nano.c:1249
msgid "Cannot resize edit win"
msgstr ""
#: nano.c:1249
#: nano.c:1251
msgid "Cannot move edit win"
msgstr ""
#: nano.c:1251
#: nano.c:1253
msgid "Cannot resize bottom win"
msgstr ""
#: nano.c:1253
#: nano.c:1255
msgid "Cannot move bottom win"
msgstr ""
#: nano.c:1712
#: nano.c:1718
msgid "Main: set up windows\n"
msgstr ""
#: nano.c:1734
#: nano.c:1740
msgid "Main: bottom win\n"
msgstr ""
#: nano.c:1740
#: nano.c:1746
msgid "Main: open file\n"
msgstr ""
#: nano.c:1813
#: nano.c:1819
#, c-format
msgid "I got Alt-[-%c! (%d)\n"
msgstr ""
#: nano.c:1829
#: nano.c:1835
#, c-format
msgid "I got Alt-%c! (%d)\n"
msgstr ""
#: search.c:68
#: search.c:71
#, c-format
msgid "Case Sensitive Regexp Search%s"
msgstr ""
#: search.c:70
#: search.c:73
#, c-format
msgid "Regexp Search%s"
msgstr ""
#: search.c:72
#: search.c:76
#, c-format
msgid "Case Sensitive Search%s"
msgstr ""
#: search.c:74
#: search.c:78
#, c-format
msgid "Search%s"
msgstr ""
#: search.c:82
#: search.c:86
msgid "Search Cancelled"
msgstr ""
#: search.c:170
#: search.c:177
msgid "Search Wrapped"
msgstr ""
#: search.c:222
#: search.c:232
#, c-format
msgid "Replaced %d occurences"
msgstr ""
#: search.c:224
#: search.c:234
msgid "Replaced 1 occurence"
msgstr ""
#: search.c:353 search.c:375 search.c:398
#: search.c:373 search.c:395 search.c:418
msgid "Replace Cancelled"
msgstr ""
#: search.c:371
#: search.c:391
#, c-format
msgid "Replace with [%s]"
msgstr ""
#. last_search is empty
#: search.c:396
#: search.c:416
msgid "Replace with"
msgstr ""
#: search.c:437
#: search.c:457
msgid "Replace this instance?"
msgstr ""
#. Ask for it
#: search.c:487
#: search.c:507
msgid "Enter line number"
msgstr ""
#: search.c:489
#: search.c:509
msgid "Aborted"
msgstr ""
#: search.c:509
#: search.c:529
msgid "Come on, be reasonable"
msgstr ""
#: search.c:514
#: search.c:534
#, c-format
msgid "Only %d lines available, skipping to last line"
msgstr ""

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include "config.h"
#include "proto.h"
@ -34,6 +35,7 @@
/* Regular expression helper functions */
#ifdef _POSIX_VERSION
void regexp_init(const char *regexp)
{
regcomp(&search_regexp, regexp, ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE);
@ -45,6 +47,7 @@ void regexp_cleanup()
UNSET(REGEXP_COMPILED);
regfree(&search_regexp);
}
#endif
/* Set up the system variables for a search or replace. Returns -1 on
abort, 0 on success, and 1 on rerun calling program
@ -68,7 +71,8 @@ int search_init(int replacing)
prompt = _("Case Sensitive Regexp Search%s");
else if (ISSET(USE_REGEXP))
prompt = _("Regexp Search%s");
else if (ISSET(CASE_SENSITIVE))
else
if (ISSET(CASE_SENSITIVE))
prompt = _("Case Sensitive Search%s");
else
prompt = _("Search%s");
@ -84,13 +88,16 @@ int search_init(int replacing)
return -1;
} else if (i == -2) { /* Same string */
strncpy(answer, last_search, 132);
#ifdef _POSIX_VERSION
if (ISSET(USE_REGEXP))
regexp_init(answer);
#endif
} else if (i == 0) { /* They entered something new */
strncpy(last_search, answer, 132);
#ifdef _POSIX_VERSION
if (ISSET(USE_REGEXP))
regexp_init(answer);
#endif
/* Blow away last_replace because they entered a new search
string....uh, right? =) */
last_replace[0] = '\0';
@ -184,8 +191,11 @@ void search_abort(void)
UNSET(KEEP_CUTBUFFER);
display_main_list();
wrefresh(bottomwin);
#ifdef _POSIX_VERSION
if (ISSET(REGEXP_COMPILED))
regexp_cleanup();
#endif
}
/* Search for a string */
@ -229,10 +239,14 @@ void replace_abort(void)
UNSET(KEEP_CUTBUFFER);
display_main_list();
reset_cursor();
#ifdef _POSIX_VERSION
if (ISSET(REGEXP_COMPILED))
regexp_cleanup();
#endif
}
#ifdef _POSIX_VERSION
int replace_regexp(char *string, int create_flag)
{
/* split personality here - if create_flag is null, just calculate
@ -293,6 +307,7 @@ int replace_regexp(char *string, int create_flag)
return new_size;
}
#endif
char *replace_line()
{
@ -301,16 +316,19 @@ char *replace_line()
int search_match_count;
/* Calculate size of new line */
#ifdef _POSIX_VERSION
if (ISSET(USE_REGEXP)) {
search_match_count = regmatches[0].rm_eo -
regmatches[0].rm_so;
new_line_size = replace_regexp(NULL, 0);
/* If they specified an invalid subexpression in the replace
* text, return NULL indicating an error */
if (new_line_size < 0)
return NULL;
} else {
#else
{
#endif
search_match_count = strlen(last_search);
new_line_size = strlen(current->data) - strlen(last_search) +
strlen(last_replace) + 1;
@ -326,8 +344,10 @@ char *replace_line()
/* Replacement Text */
if (!ISSET(USE_REGEXP))
strcat(copy, last_replace);
#ifdef _POSIX_VERSION
else
(void)replace_regexp(copy + current_x, 1);
#endif
/* The tail of the original line */
/* This may expose other bugs, because it no longer
@ -342,7 +362,7 @@ char *replace_line()
return copy;
}
/* Search for a string */
/* Replace a string */
int do_replace(void)
{
int i, replaceall = 0, numreplaced = 0, beginx;