[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev [PATCH][dev21] Remove cut-n-paste code in www_user_search
From: |
John Bley |
Subject: |
lynx-dev [PATCH][dev21] Remove cut-n-paste code in www_user_search |
Date: |
Thu, 1 Apr 1999 17:29:00 -0500 (EST) |
* Spawn a new function, www_user_search_internals, to begin cancelling
the effects of cut-n-paste coding in www_user_search. The body of
www_user_search_internals used to be duplicated at two points in
www_user_search. See comment in GridText.c for more details. (John Bley)
Doing this actually cuts the size of the binary by a KB without modifying
behaviour at all (unless I screwed up somewhere). It's kind of a
toss-up as to whether it actually makes the code "cleaner" though...
--
John Bley - address@hidden
Duke '99 - English/Computer Science
Since English is a mess, it maps well onto the problem space,
which is also a mess, which we call reality. - Larry Wall
diff -Burp lynx2-8-2/WWW/Library/Implementation/HTAssoc.c
lynx2-8-2-patched/WWW/Library/Implementation/HTAssoc.c
--- lynx2-8-2/WWW/Library/Implementation/HTAssoc.c Thu Aug 6 08:28:22 1998
+++ lynx2-8-2-patched/WWW/Library/Implementation/HTAssoc.c Wed Mar 31
23:45:02 1999
@@ -20,7 +20,6 @@
#include <HTAAUtil.h>
#include <HTAssoc.h>
-#include <HTString.h>
#include <LYLeaks.h>
diff -Burp lynx2-8-2/src/GridText.c lynx2-8-2-patched/src/GridText.c
--- lynx2-8-2/src/GridText.c Tue Mar 30 12:10:37 1999
+++ lynx2-8-2-patched/src/GridText.c Thu Apr 1 00:42:44 1999
@@ -5738,40 +5738,39 @@ PRIVATE void adjust_search_result ARGS3(
}
}
-PUBLIC void www_user_search ARGS3(
+/*
+ John Bley, April 1, 1999 (No joke)
+ www_user_search_internals was spawned from www_user_search to
+ remove a cut-n-paste coding hack: basically, this entire function
+ was duplicated at the two points that www_user_search now calls it.
+ And, because www_user_search has a return value defined as modification
+ of the screen and some global values, and since it used an awkward for(;;)
+ construct, this method has to distinguish between when it's "really"
+ returning and when it's just falling through via a break; in the
+ infinite-for-loop. So, basically, we have a large amount of arguments
+ since this loop used to be directly in www_user_search, and we return
+ 1 to say we're "really" returning and 0 to indicate we fell through.
+ Also, due to exactly one difference between the first pass of this
+ code and the second pass, we have the "firstpass" argument, which is
+ true iff it's the first pass.
+
+ I hate cut-n-paste coding.
+ */
+PRIVATE int www_user_search_internals ARGS8(
+ int, firstpass,
int, start_line,
document *, doc,
- char *, target)
+ char *, target,
+ TextAnchor *, a,
+ HTLine *, line,
+ int *, count,
+ int *, tentative_result)
{
- register HTLine * line;
- register int count;
- int tentative_result = -1;
- TextAnchor *a;
- OptionType *option;
+ OptionType * option;
char *stars = NULL, *cp;
- if (!HTMainText) {
- return;
- }
-
- /*
- * Advance to the start line.
- */
- line = HTMainText->last_line->next;
- for (count = 1; count <= start_line; line = line->next, count++) {
- if (line == HTMainText->last_line) {
- line = HTMainText->last_line->next; /* set to first line */
- count = 1;
- break;
- }
- }
- a = HTMainText->first_anchor;
- while (a && a->line_num < count - 1) {
- a = a->next;
- }
-
for (;;) {
- while ((a != NULL) && a->line_num == (count - 1)) {
+ while ((a != NULL) && a->line_num == (*count - 1)) {
if (a->show_anchor &&
(a->link_type != INPUT_ANCHOR ||
a->input_field->type != F_HIDDEN_TYPE)) {
@@ -5779,15 +5778,15 @@ PUBLIC void www_user_search ARGS3(
LYno_attr_char_strstr(a->hightext, target)) ||
((a->hightext != NULL && case_sensitive == FALSE) &&
LYno_attr_char_case_strstr(a->hightext, target))) {
- adjust_search_result(doc, count, start_line);
- return;
+ adjust_search_result(doc, *count, start_line);
+ return 1;
}
if (((a->hightext2 != NULL && case_sensitive == TRUE) &&
LYno_attr_char_strstr(a->hightext2, target)) ||
((a->hightext2 != NULL && case_sensitive == FALSE) &&
LYno_attr_char_case_strstr(a->hightext2, target))) {
- adjust_search_result(doc, count, start_line);
- return;
+ adjust_search_result(doc, *count, start_line);
+ return 1;
}
/*
@@ -5807,8 +5806,8 @@ PUBLIC void www_user_search ARGS3(
((case_sensitive == FALSE) &&
LYno_attr_char_case_strstr(a->input_field->value,
target))) {
- adjust_search_result(doc, count, start_line);
- return;
+ adjust_search_result(doc, *count, start_line);
+ return 1;
}
StrAllocCopy(stars, a->input_field->value);
for (cp = stars; *cp != '\0'; cp++)
@@ -5818,8 +5817,8 @@ PUBLIC void www_user_search ARGS3(
((case_sensitive == FALSE) &&
LYno_attr_char_case_strstr(stars, target))) {
FREE(stars);
- adjust_search_result(doc, count, start_line);
- return;
+ adjust_search_result(doc, *count, start_line);
+ return 1;
}
FREE(stars);
} else if (a->input_field->type == F_OPTION_LIST_TYPE) {
@@ -5837,8 +5836,8 @@ PUBLIC void www_user_search ARGS3(
case_sensitive == FALSE) &&
LYno_attr_char_case_strstr(option->name,
target))) {
- adjust_search_result(doc, count, start_line);
- return;
+ adjust_search_result(doc, *count, start_line);
+ return 1;
}
option = option->next;
}
@@ -5855,8 +5854,8 @@ PUBLIC void www_user_search ARGS3(
LYno_attr_char_strstr(cp, target)) ||
((case_sensitive == FALSE) &&
LYno_attr_char_case_strstr(cp, target))) {
- adjust_search_result(doc, count, start_line);
- return;
+ adjust_search_result(doc, *count, start_line);
+ return 1;
}
} else if (a->input_field->type == F_CHECKBOX_TYPE) {
/*
@@ -5872,8 +5871,8 @@ PUBLIC void www_user_search ARGS3(
LYno_attr_char_strstr(cp, target)) ||
((case_sensitive == FALSE) &&
LYno_attr_char_case_strstr(cp, target))) {
- adjust_search_result(doc, count, start_line);
- return;
+ adjust_search_result(doc, *count, start_line);
+ return 1;
}
} else {
/*
@@ -5888,191 +5887,89 @@ PUBLIC void www_user_search ARGS3(
((case_sensitive == FALSE) &&
LYno_attr_char_case_strstr(a->input_field->value,
target))) {
- adjust_search_result(doc, count, start_line);
- return;
+ adjust_search_result(doc, *count, start_line);
+ return 1;
}
}
}
}
a = a->next;
}
- if (a != NULL && a->line_num <= (count - 1)) {
+ if (a != NULL && a->line_num <= (*count - 1)) {
a = a->next;
}
if (case_sensitive && LYno_attr_char_strstr(line->data, target)) {
- tentative_result = count;
+ *tentative_result = *count;
break;
} else if (!case_sensitive &&
LYno_attr_char_case_strstr(line->data, target)) {
- tentative_result = count;
+ *tentative_result = *count;
break;
- } else if (line == HTMainText->last_line) { /* next line */
+ /* Note: this is where the two passes differ */
+ } else if (firstpass && line == HTMainText->last_line) {
+ /* next line */
break;
+ } else if (!firstpass && *count > start_line) {
+ HTUserMsg2(STRING_NOT_FOUND, target);
+ return 1; /* end */
} else { /* end */
line = line->next;
- count++;
+ (*count)++;
}
}
- if (tentative_result > 0) {
- adjust_search_result(doc, tentative_result, start_line);
+ /* No, man, we just fell through. You want to call us again. */
+ return 0;
+}
+
+PUBLIC void www_user_search ARGS3(
+ int, start_line,
+ document *, doc,
+ char *, target)
+{
+ HTLine * line;
+ int count;
+ int tentative_result = -1;
+ TextAnchor *a;
+
+ if (!HTMainText) {
return;
}
/*
- * Search from the beginning.
+ * Advance to the start line.
*/
+ line = HTMainText->last_line->next;
+ for (count = 1; count <= start_line; line = line->next, count++) {
+ if (line == HTMainText->last_line) {
+ line = HTMainText->last_line->next; /* set to first line */
+ count = 1;
+ break;
+ }
+ }
+ a = HTMainText->first_anchor;
+ while (a && a->line_num < count - 1) {
+ a = a->next;
+ }
+ if (www_user_search_internals(1, start_line, doc, target,
+ a, line, &count, &tentative_result) == 1) {
+ return; /* Return the www_user_search_internals result */
+ }
+
+ if (tentative_result > 0) {
+ adjust_search_result(doc, tentative_result, start_line);
+ return;
+ }
+ /* That didn't work, search from the beginning instead */
line = HTMainText->last_line->next; /* set to first line */
count = 1;
a = HTMainText->first_anchor;
while (a && a->line_num < count - 1) {
a = a->next;
}
-
- for (;;) {
- while ((a != NULL) && a->line_num == (count - 1)) {
- if (a->show_anchor &&
- (a->link_type != INPUT_ANCHOR ||
- a->input_field->type != F_HIDDEN_TYPE)) {
- if (((a->hightext != NULL && case_sensitive == TRUE) &&
- LYno_attr_char_strstr(a->hightext, target)) ||
- ((a->hightext != NULL && case_sensitive == FALSE) &&
- LYno_attr_char_case_strstr(a->hightext, target))) {
- adjust_search_result(doc, count, start_line);
- return;
- }
- if (((a->hightext2 != NULL && case_sensitive == TRUE) &&
- LYno_attr_char_strstr(a->hightext2, target)) ||
- ((a->hightext2 != NULL && case_sensitive == FALSE) &&
- LYno_attr_char_case_strstr(a->hightext2, target))) {
- adjust_search_result(doc, count, start_line);
- return;
- }
-
- /*
- * Search the relevant form fields, taking the
- * case_sensitive setting into account. - FM
- */
- if ((a->input_field != NULL && a->input_field->value != NULL) &&
- a->input_field->type != F_HIDDEN_TYPE) {
- if (a->input_field->type == F_PASSWORD_TYPE) {
- /*
- * Check the actual, hidden password, and then
- * the displayed string. - FM
- */
- if (((case_sensitive == TRUE) &&
- LYno_attr_char_strstr(a->input_field->value,
- target)) ||
- ((case_sensitive == FALSE) &&
- LYno_attr_char_case_strstr(a->input_field->value,
- target))) {
- adjust_search_result(doc, count, start_line);
- return;
- }
- StrAllocCopy(stars, a->input_field->value);
- for (cp = stars; *cp != '\0'; cp++)
- *cp = '*';
- if (((case_sensitive == TRUE) &&
- LYno_attr_char_strstr(stars, target)) ||
- ((case_sensitive == FALSE) &&
- LYno_attr_char_case_strstr(stars, target))) {
- FREE(stars);
- adjust_search_result(doc, count, start_line);
- return;
- }
- FREE(stars);
- } else if (a->input_field->type == F_OPTION_LIST_TYPE) {
- /*
- * Search the option strings that are displayed
- * when the popup is invoked. - FM
- */
- option = a->input_field->select_list;
- while (option != NULL) {
- if (((option->name != NULL &&
- case_sensitive == TRUE) &&
- LYno_attr_char_strstr(option->name,
- target)) ||
- ((option->name != NULL &&
- case_sensitive == FALSE) &&
- LYno_attr_char_case_strstr(option->name,
- target))) {
- adjust_search_result(doc, count, start_line);
- return;
- }
- option = option->next;
- }
- } else if (a->input_field->type == F_RADIO_TYPE) {
- /*
- * Search for checked or unchecked parens. - FM
- */
- if (a->input_field->num_value) {
- cp = checked_radio;
- } else {
- cp = unchecked_radio;
- }
- if (((case_sensitive == TRUE) &&
- LYno_attr_char_strstr(cp, target)) ||
- ((case_sensitive == FALSE) &&
- LYno_attr_char_case_strstr(cp, target))) {
- adjust_search_result(doc, count, start_line);
- return;
- }
- } else if (a->input_field->type == F_CHECKBOX_TYPE) {
- /*
- * Search for checked or unchecked
- * square brackets. - FM
- */
- if (a->input_field->num_value) {
- cp = checked_box;
- } else {
- cp = unchecked_box;
- }
- if (((case_sensitive == TRUE) &&
- LYno_attr_char_strstr(cp, target)) ||
- ((case_sensitive == FALSE) &&
- LYno_attr_char_case_strstr(cp, target))) {
- adjust_search_result(doc, count, start_line);
- return;
- }
- } 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 (((case_sensitive == TRUE) &&
- LYno_attr_char_strstr(a->input_field->value,
- target)) ||
- ((case_sensitive == FALSE) &&
- LYno_attr_char_case_strstr(a->input_field->value,
- target))) {
- adjust_search_result(doc, count, start_line);
- return;
- }
- }
- }
- }
- a = a->next;
- }
- if (a != NULL && a->line_num <= (count - 1)) {
- a = a->next;
- }
-
- if (case_sensitive && LYno_attr_char_strstr(line->data, target)) {
- tentative_result = count;
- break;
- } else if (!case_sensitive &&
- LYno_attr_char_case_strstr(line->data, target)) {
- tentative_result = count;
- break;
- } else if (count > start_line) { /* next line */
- HTUserMsg2(STRING_NOT_FOUND, target);
- return; /* end */
- } else {
- line = line->next;
- count++;
- }
+ if (www_user_search_internals(0, start_line, doc, target,
+ a, line, &count, &tentative_result) == 1) {
+ return; /* Return the www_user_search_internals result */
}
if (tentative_result > 0) {
adjust_search_result(doc, tentative_result, start_line);
- lynx-dev [PATCH][dev21] Remove cut-n-paste code in www_user_search,
John Bley <=