tweaks: adjust comments and indentation after the previous change
parent
60f1090da0
commit
d289510724
48
src/search.c
48
src/search.c
|
@ -89,33 +89,19 @@ void search_replace_abort(void)
|
||||||
regexp_cleanup();
|
regexp_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up the system variables for a search or replace. If use_answer
|
/* Prepare the prompt and ask the user what to search for. Keep looping
|
||||||
* is TRUE, only set backupstring to answer. Return -2 to run the
|
* as long as the user presses a toggle, and only take action and exit
|
||||||
* opposite program (search -> replace, replace -> search), return -1 if
|
* when <Enter> is pressed or a non-toggle shortcut was executed. */
|
||||||
* the search should be canceled (due to Cancel, a blank search string,
|
void search_init(bool replacing, bool keep_the_answer)
|
||||||
* Go to Line, or a failed regcomp()), return 0 on success, and return 1
|
|
||||||
* on rerun calling program.
|
|
||||||
*
|
|
||||||
* replacing is TRUE if we call from do_replace(), and FALSE if called
|
|
||||||
* from do_search(). */
|
|
||||||
void search_init(bool replacing, bool use_answer)
|
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
char *buf;
|
char *buf;
|
||||||
static char *backupstring = NULL;
|
static char *backupstring = NULL;
|
||||||
/* The search string we'll be using. */
|
/* What the user has typed so far, before toggling something. */
|
||||||
functionptrtype func;
|
|
||||||
|
|
||||||
/* If use_answer is TRUE, set backupstring to answer. */
|
if (keep_the_answer)
|
||||||
if (use_answer) {
|
|
||||||
backupstring = mallocstrcpy(backupstring, answer);
|
backupstring = mallocstrcpy(backupstring, answer);
|
||||||
}
|
|
||||||
|
|
||||||
/* We display the search prompt below. If the user types a partial
|
|
||||||
* search string and then Replace or a toggle, we will return to
|
|
||||||
* do_search() or do_replace() and be called again. In that case,
|
|
||||||
* we should put the same search string back up. */
|
|
||||||
|
|
||||||
|
/* If something was searched for earlier, include it in the prompt. */
|
||||||
if (*last_search != '\0') {
|
if (*last_search != '\0') {
|
||||||
char *disp = display_string(last_search, 0, COLS / 3, FALSE);
|
char *disp = display_string(last_search, 0, COLS / 3, FALSE);
|
||||||
|
|
||||||
|
@ -128,8 +114,9 @@ void search_init(bool replacing, bool use_answer)
|
||||||
buf = mallocstrcpy(NULL, "");
|
buf = mallocstrcpy(NULL, "");
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
/* This is now one simple call. It just does a lot. */
|
functionptrtype func;
|
||||||
i = do_prompt(FALSE, FALSE,
|
/* Ask the user what to search for (or replace). */
|
||||||
|
int i = do_prompt(FALSE, FALSE,
|
||||||
inhelp ? MFINDINHELP : (replacing ? MREPLACE : MWHEREIS),
|
inhelp ? MFINDINHELP : (replacing ? MREPLACE : MWHEREIS),
|
||||||
backupstring, &search_history,
|
backupstring, &search_history,
|
||||||
/* TRANSLATORS: This is the main search prompt. */
|
/* TRANSLATORS: This is the main search prompt. */
|
||||||
|
@ -153,9 +140,9 @@ void search_init(bool replacing, bool use_answer)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If Enter was pressed, see what we got. */
|
/* If Enter was pressed, prepare to do a replace or a search. */
|
||||||
if (i == 0 || i == -2) {
|
if (i == 0 || i == -2) {
|
||||||
/* If an answer was given, remember it. */
|
/* If an actual answer was typed, remember it. */
|
||||||
if (*answer != '\0') {
|
if (*answer != '\0') {
|
||||||
last_search = mallocstrcpy(last_search, answer);
|
last_search = mallocstrcpy(last_search, answer);
|
||||||
#ifdef ENABLE_HISTORIES
|
#ifdef ENABLE_HISTORIES
|
||||||
|
@ -165,6 +152,8 @@ void search_init(bool replacing, bool use_answer)
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
/* If doing a regular-expression search, compile the
|
||||||
|
* search string, and get out when it's invalid. */
|
||||||
if (ISSET(USE_REGEXP) && !regexp_init(last_search)) {
|
if (ISSET(USE_REGEXP) && !regexp_init(last_search)) {
|
||||||
search_replace_abort();
|
search_replace_abort();
|
||||||
return;
|
return;
|
||||||
|
@ -182,6 +171,8 @@ void search_init(bool replacing, bool use_answer)
|
||||||
|
|
||||||
func = func_from_key(&i);
|
func = func_from_key(&i);
|
||||||
|
|
||||||
|
/* If we're here, one of the five toggles was pressed, or
|
||||||
|
* a shortcut was executed. */
|
||||||
if (func == case_sens_void) {
|
if (func == case_sens_void) {
|
||||||
TOGGLE(CASE_SENSITIVE);
|
TOGGLE(CASE_SENSITIVE);
|
||||||
} else if (func == backwards_void) {
|
} else if (func == backwards_void) {
|
||||||
|
@ -709,14 +700,13 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
|
||||||
/* Replace a string. */
|
/* Replace a string. */
|
||||||
void do_replace(void)
|
void do_replace(void)
|
||||||
{
|
{
|
||||||
if (ISSET(VIEW_MODE)) {
|
if (ISSET(VIEW_MODE))
|
||||||
print_view_warning();
|
print_view_warning();
|
||||||
return;
|
else
|
||||||
}
|
|
||||||
|
|
||||||
search_init(TRUE, FALSE);
|
search_init(TRUE, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ask the user what the already given search string should be replaced with. */
|
||||||
void ask_for_replacement(void)
|
void ask_for_replacement(void)
|
||||||
{
|
{
|
||||||
filestruct *edittop_save, *begin;
|
filestruct *edittop_save, *begin;
|
||||||
|
|
Loading…
Reference in New Issue