summaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c102
1 files changed, 95 insertions, 7 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index 0e92b21b041..f7ece88578b 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -831,7 +831,8 @@ safe_strerror (int errnum)
char *msg;
static char buf[32];
- if ((msg = strerror (errnum)) == NULL)
+ msg = strerror (errnum);
+ if (msg == NULL)
{
sprintf (buf, "(undocumented errno %d)", errnum);
msg = buf;
@@ -1447,14 +1448,15 @@ parse_escape (char **string_ptr)
register int count = 0;
while (++count < 3)
{
- if ((c = *(*string_ptr)++) >= '0' && c <= '7')
+ c = (**string_ptr);
+ if (c >= '0' && c <= '7')
{
+ (*string_ptr)++;
i *= 8;
i += c - '0';
}
else
{
- (*string_ptr)--;
break;
}
}
@@ -1603,8 +1605,6 @@ init_page_info (void)
chars_per_line = 80;
#if !defined (_WIN32)
- /* No termcap under MPW, although might be cool to do something
- by looking at worksheet or console window sizes. */
/* Initialize the screen height and width from termcap. */
{
char *termtype = getenv ("TERM");
@@ -1640,7 +1640,7 @@ init_page_info (void)
}
}
}
-#endif /* MPW */
+#endif
#if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
@@ -2357,6 +2357,94 @@ 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
+streq (const char *lhs, const char *rhs)
+{
+ return !strcmp (lhs, rhs);
+}
/*
@@ -2676,8 +2764,8 @@ gdb_realpath (const char *filename)
if (rp == NULL)
rp = filename;
return xstrdup (rp);
- }
# endif
+ }
#endif /* HAVE_REALPATH */
/* Method 2: The host system (i.e., GNU) has the function