aboutsummaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorDavid Carlton <carlton@bactrian.org>2003-02-24 23:37:02 +0000
committerDavid Carlton <carlton@bactrian.org>2003-02-24 23:37:02 +0000
commit0fe19209f9dde2fd4450b13a9e772203cf313eff (patch)
tree5c56927bc27c7bdb16a65cbc6664f872ddbbe207 /gdb/utils.c
parentc8d6825d9aa09b432701bb990fe9610442fcbaa1 (diff)
downloadgdb-0fe19209f9dde2fd4450b13a9e772203cf313eff.zip
gdb-0fe19209f9dde2fd4450b13a9e772203cf313eff.tar.gz
gdb-0fe19209f9dde2fd4450b13a9e772203cf313eff.tar.bz2
2003-02-24 David Carlton <carlton@math.stanford.edu>
* symtab.c (lookup_partial_symbol): Use strcmp_iw_ordered to do the comparison, not strcmp. * symfile.c (compare_psymbols): Ditto. * defs.h: Declare strcmp_iw_ordered. * utils.c (strcmp_iw_ordered): New function.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index 0d9fb31..df196ec 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2358,6 +2358,86 @@ strcmp_iw (const char *string1, const char *string2)
return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
}
+/* This is like strcmp except that it ignores whitespace and treats
+ '(' as the first non-NULL character in terms of ordering. Like
+ strcmp (and unlike strcmp_iw), it returns negative if STRING1 <
+ STRING2, 0 if STRING2 = STRING2, and positive if STRING1 > STRING2
+ according to that ordering.
+
+ If a list is sorted according to this function and if you want to
+ find names in the list that match some fixed NAME according to
+ strcmp_iw(LIST_ELT, NAME), then the place to start looking is right
+ where this function would put NAME.
+
+ Here are some examples of why using strcmp to sort is a bad idea:
+
+ Whitespace example:
+
+ Say your partial symtab contains: "foo<char *>", "goo". Then, if
+ we try to do a search for "foo<char*>", strcmp will locate this
+ after "foo<char *>" and before "goo". Then lookup_partial_symbol
+ will start looking at strings beginning with "goo", and will never
+ see the correct match of "foo<char *>".
+
+ Parenthesis example:
+
+ In practice, this is less like to be an issue, but I'll give it a
+ shot. Let's assume that '$' is a legitimate character to occur in
+ symbols. (Which may well even be the case on some systems.) Then
+ say that the partial symbol table contains "foo$" and "foo(int)".
+ strcmp will put them in this order, since '$' < '('. Now, if the
+ user searches for "foo", then strcmp will sort "foo" before "foo$".
+ Then lookup_partial_symbol will notice that strcmp_iw("foo$",
+ "foo") is false, so it won't proceed to the actual match of
+ "foo(int)" with "foo". */
+
+int
+strcmp_iw_ordered (const char *string1, const char *string2)
+{
+ while ((*string1 != '\0') && (*string2 != '\0'))
+ {
+ while (isspace (*string1))
+ {
+ string1++;
+ }
+ while (isspace (*string2))
+ {
+ string2++;
+ }
+ if (*string1 != *string2)
+ {
+ break;
+ }
+ if (*string1 != '\0')
+ {
+ string1++;
+ string2++;
+ }
+ }
+
+ switch (*string1)
+ {
+ /* Characters are non-equal unless they're both '\0'; we want to
+ make sure we get the comparison right according to our
+ comparison in the cases where one of them is '\0' or '('. */
+ case '\0':
+ if (*string2 == '\0')
+ return 0;
+ else
+ return -1;
+ case '(':
+ if (*string2 == '\0')
+ return 1;
+ else
+ return -1;
+ default:
+ if (*string2 == '(')
+ return 1;
+ else
+ return *string1 - *string2;
+ }
+}
+
/* A simple comparison function with opposite semantics to strcmp. */
int