Commit 9c371a24 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

Converted ifs to switches, added Rocco's optmiization

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@247 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 42 additions and 30 deletions
+42 -30
...@@ -20,6 +20,11 @@ CVS Code - ...@@ -20,6 +20,11 @@ CVS Code -
do_replace() do_replace()
- Added code for Gotoline key after entering the search term. - Added code for Gotoline key after entering the search term.
Fixes bug #46. Fixes bug #46.
- Removed redundant code involving processing replacemenet string.
Converted if statements to switch statements.
- Optimizations by Rocco Corsi.
do_search()
- Converted if statements to one switch statement.
- winio.c - winio.c
nanogetstr() nanogetstr()
- Added check for 343 in while loop to get rid of getting "locked" - Added check for 343 in while loop to get rid of getting "locked"
......
...@@ -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-10-27 01:32-0400\n" "POT-Creation-Date: 2000-10-27 01:45-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"
...@@ -765,52 +765,52 @@ msgstr "" ...@@ -765,52 +765,52 @@ msgstr ""
msgid "Search Wrapped" msgid "Search Wrapped"
msgstr "" msgstr ""
#: search.c:256 #: search.c:258
#, c-format #, c-format
msgid "Replaced %d occurences" msgid "Replaced %d occurences"
msgstr "" msgstr ""
#: search.c:258 #: search.c:260
msgid "Replaced 1 occurence" msgid "Replaced 1 occurence"
msgstr "" msgstr ""
#: search.c:392 search.c:424 #: search.c:396 search.c:429
msgid "Replace Cancelled" msgid "Replace Cancelled"
msgstr "" msgstr ""
#. They used ^N in the search field, shame on them. #. They used ^N in the search field, shame on them.
#. Any Dungeon fans out there? #. Any Dungeon fans out there?
#: search.c:409 #: search.c:413
msgid "Nothing Happens" msgid "Nothing Happens"
msgstr "" msgstr ""
#: search.c:417 #: search.c:421
#, c-format #, c-format
msgid "Replace with [%s]" msgid "Replace with [%s]"
msgstr "" msgstr ""
#: search.c:419 #: search.c:423
msgid "Replace with" msgid "Replace with"
msgstr "" msgstr ""
#: search.c:467 #: search.c:474
msgid "Replace this instance?" msgid "Replace this instance?"
msgstr "" msgstr ""
#. Ask for it #. Ask for it
#: search.c:528 #: search.c:535
msgid "Enter line number" msgid "Enter line number"
msgstr "" msgstr ""
#: search.c:530 #: search.c:537
msgid "Aborted" msgid "Aborted"
msgstr "" msgstr ""
#: search.c:550 #: search.c:557
msgid "Come on, be reasonable" msgid "Come on, be reasonable"
msgstr "" msgstr ""
#: search.c:555 #: search.c:562
#, c-format #, c-format
msgid "Only %d lines available, skipping to last line" msgid "Only %d lines available, skipping to last line"
msgstr "" msgstr ""
......
...@@ -229,17 +229,19 @@ int do_search(void) ...@@ -229,17 +229,19 @@ int do_search(void)
filestruct *fileptr = current; filestruct *fileptr = current;
wrap_reset(); wrap_reset();
if ((i = search_init(0)) == -1) { i = search_init(0);
switch (i) {
case -1:
current = fileptr; current = fileptr;
search_abort(); search_abort();
return 0; return 0;
} else if (i == -3) { case -3:
search_abort(); search_abort();
return 0; return 0;
} else if (i == -2) { case -2:
do_replace(); do_replace();
return 0; return 0;
} else if (i == 1) { case 1:
do_search(); do_search();
search_abort(); search_abort();
return 1; return 1;
...@@ -388,17 +390,19 @@ int do_replace(void) ...@@ -388,17 +390,19 @@ int do_replace(void)
filestruct *fileptr, *begin; filestruct *fileptr, *begin;
char *copy, prevanswer[132] = ""; char *copy, prevanswer[132] = "";
if ((i = search_init(1)) == -1) { i = search_init(1);
switch (i) {
case -1:
statusbar(_("Replace Cancelled")); statusbar(_("Replace Cancelled"));
replace_abort(); replace_abort();
return 0; return 0;
} else if (i == 1) { case 1:
do_replace(); do_replace();
return 1; return 1;
} else if (i == -2) { case -2:
do_search(); do_search();
return 0; return 0;
} else if (i == -3) { case -3:
replace_abort(); replace_abort();
return 0; return 0;
} }
...@@ -418,17 +422,20 @@ int do_replace(void) ...@@ -418,17 +422,20 @@ int do_replace(void)
else else
i = statusq(replace_list, REPLACE_LIST_LEN, "", _("Replace with")); i = statusq(replace_list, REPLACE_LIST_LEN, "", _("Replace with"));
if (i == -1) { /* Aborted enter */ switch (i) {
case -1: /* Aborted enter */
if (strcmp(last_replace, "")) if (strcmp(last_replace, ""))
strncpy(answer, last_replace, 132); strncpy(answer, last_replace, 132);
statusbar(_("Replace Cancelled")); statusbar(_("Replace Cancelled"));
replace_abort(); replace_abort();
return 0; return 0;
} else if (i == 0) /* They actually entered something */ case 0: /* They actually entered something */
strncpy(last_replace, answer, 132); strncpy(last_replace, answer, 132);
else if (i == NANO_NULL_KEY) /* They actually entered something */ break;
case NANO_NULL_KEY: /* They want the null string */
strcpy(last_replace, ""); strcpy(last_replace, "");
else if (i == NANO_CASE_KEY) { /* They asked for case sensitivity */ break;
case NANO_CASE_KEY: /* They asked for case sensitivity */
if (ISSET(CASE_SENSITIVE)) if (ISSET(CASE_SENSITIVE))
UNSET(CASE_SENSITIVE); UNSET(CASE_SENSITIVE);
else else
...@@ -436,14 +443,16 @@ int do_replace(void) ...@@ -436,14 +443,16 @@ int do_replace(void)
do_replace(); do_replace();
return 0; return 0;
} else if (i == NANO_FROMSEARCHTOGOTO_KEY) { /* oops... */ case NANO_FROMSEARCHTOGOTO_KEY: /* Oops, they want goto line... */
do_gotoline_void(); do_gotoline_void();
return 0; return 0;
} else if (i != -2) { /* First page, last page, for example default:
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();
return 0; return 0;
}
} }
/* save where we are */ /* save where we are */
...@@ -453,10 +462,8 @@ int do_replace(void) ...@@ -453,10 +462,8 @@ int do_replace(void)
while (1) { while (1) {
if (replaceall) /* Sweet optimization by Rocco here */
fileptr = findnextstr(1, begin, beginx, prevanswer); fileptr = findnextstr(replaceall, begin, beginx, prevanswer);
else
fileptr = findnextstr(0, begin, beginx, prevanswer);
/* No more matches. Done! */ /* No more matches. Done! */
if (!fileptr) if (!fileptr)
......
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