Added _POSIX_VERSION check to regexp code

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@80 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
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

@ -4,6 +4,8 @@ CVS code changes since last release -
and REGEXP_COMPILED, new functions regexp_init, regexp_cleanup and REGEXP_COMPILED, new functions regexp_init, regexp_cleanup
replace_line, replace_regexp in search.c, changes to 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 - Made search functions & keys more like Pico. Added goto line from
search and replace function, changed wording to "No Replace" instead search and replace function, changed wording to "No Replace" instead
of "To Search", "To Replace" to simply "Replace", and changed to of "To Search", "To Replace" to simply "Replace", and changed to

6
nano.c
View File

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

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

View File

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