diff options
Diffstat (limited to 'src/LYSearch.c')
-rw-r--r-- | src/LYSearch.c | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/src/LYSearch.c b/src/LYSearch.c index 7c6d1d28..f989bf31 100644 --- a/src/LYSearch.c +++ b/src/LYSearch.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYSearch.c,v 1.31 2012/02/09 19:02:53 tom Exp $ + * $LynxId: LYSearch.c,v 1.37 2013/10/03 12:27:55 tom Exp $ */ #include <HTUtils.h> #include <HTAlert.h> @@ -11,97 +11,97 @@ #include <LYLeaks.h> -static BOOL link_has_target(int cur, - char *target) +#define MATCH(a,b) (BOOL)(LYno_attr_strstr(a, b) != 0) + +/* + * Handle special field-related comparisons for anchor_has_target() and + * link_has_target(). + */ +BOOL field_has_target(FormInfo * field, const char *target) { - LinkInfo *a = &links[cur]; + BOOL result = FALSE; OptionType *option; char *stars = NULL; const char *cp; - int count; - - /* - * Search the hightext strings, if present, taking the LYcase_sensitive - * setting into account. - */ - for (count = 0;; ++count) { - const char *text = LYGetHiliteStr(cur, count); - - if (text == NULL) - break; - if (LYno_attr_strstr(text, target)) - return TRUE; - } - /* - * Search the relevant form fields, taking the LYcase_sensitive setting into - * account. - FM - */ - if ((a->l_form != NULL && a->l_form->value != NULL) && - a->l_form->type != F_HIDDEN_TYPE) { - if (a->l_form->type == F_PASSWORD_TYPE) { + if ((field != NULL && field->value != NULL) && + field->type != F_HIDDEN_TYPE) { + if (field->type == F_PASSWORD_TYPE) { /* - * Check the actual, hidden password, and then the displayed - * string. - FM + * Check the actual (hidden password), and then the displayed + * string - FM */ - if (LYno_attr_strstr(a->l_form->value, target)) { - return TRUE; - } - StrAllocCopy(stars, a->l_form->value); - memset(stars, '*', strlen(stars)); - if (LYno_attr_strstr(stars, target)) { + if (MATCH(field->value, target)) { + result = TRUE; + } else { + StrAllocCopy(stars, field->value); + memset(stars, '*', strlen(stars)); + result = MATCH(stars, target); FREE(stars); - return TRUE; } - FREE(stars); - } else if (a->l_form->type == F_OPTION_LIST_TYPE) { + } else if (field->type == F_OPTION_LIST_TYPE) { /* * Search the option strings that are displayed when the popup is - * invoked. - FM + * invoked - FM */ - option = a->l_form->select_list; - while (option != NULL) { - if (LYno_attr_strstr(option->name, target)) { - return TRUE; + for (option = field->select_list; option != NULL; option = option->next) { + if (MATCH(option->name, target)) { + result = TRUE; + break; } - option = option->next; } - } else if (a->l_form->type == F_RADIO_TYPE) { + } else if (field->type == F_RADIO_TYPE) { /* - * Search for checked or unchecked parens. - FM + * Search for checked or unchecked parens - FM */ - if (a->l_form->num_value) { - cp = checked_radio; - } else { - cp = unchecked_radio; - } - if (LYno_attr_strstr(cp, target)) { - return TRUE; - } - } else if (a->l_form->type == F_CHECKBOX_TYPE) { + cp = ((field->num_value) + ? checked_radio + : unchecked_radio); + result = MATCH(cp, target); + } else if (field->type == F_CHECKBOX_TYPE) { /* - * Search for checked or unchecked square brackets. - FM + * Search for checked or unchecked square brackets - FM */ - if (a->l_form->num_value) { - cp = checked_box; - } else { - cp = unchecked_box; - } - if (LYno_attr_strstr(cp, target)) { - return TRUE; - } + cp = ((field->num_value) + ? checked_box + : unchecked_box); + result = MATCH(cp, target); } else { - /* - * Check the values intended for display. May have been found - * already via the hightext search, but make sure here that the - * entire value is searched. - FM - */ - if (LYno_attr_strstr(a->l_form->value, target)) { + result = MATCH(field->value, target); + } + } + return result; +} + +/* + * see also anchor_has_target + */ +static BOOL link_has_target(int cur, + char *target) +{ + LinkInfo *a = &links[cur]; + char *text = NULL; + const char *last = "?"; + int count; + + /* + * Combine the parts of the link's text using the highlighting information, + * and compare the target against that. + */ + for (count = 0; count < 10; ++count) { + const char *part = LYGetHiliteStr(cur, count); + + if (part == NULL || part == last) { + if (MATCH(text, target)) { return TRUE; } + break; } + StrAllocCat(text, part); + last = part; } - return FALSE; + + return field_has_target(a->l_form, target); } /* |