* xtensa-modules.c: Remove comment indicating that this is a
[deliverable/binutils-gdb.git] / gdb / utils.c
index 9b047bc8993be2e0850abeb206dd00422677cdc4..f8ac0fd41a82654fbf009b2edb6503cbd4b830cc 100644 (file)
 #endif
 
 #ifdef NEED_DECLARATION_MALLOC
-extern PTR malloc ();
+extern PTR malloc ();          /* OK: PTR */
 #endif
 #ifdef NEED_DECLARATION_REALLOC
-extern PTR realloc ();
+extern PTR realloc ();         /* OK: PTR */
 #endif
 #ifdef NEED_DECLARATION_FREE
 extern void free ();
@@ -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;
@@ -955,9 +956,6 @@ request_quit (int signo)
 
 #if !defined (USE_MMALLOC)
 
-/* NOTE: These must use PTR so that their definition matches the
-   declaration found in "mmalloc.h". */
-
 static void *
 mmalloc (void *md, size_t size)
 {
@@ -1150,19 +1148,19 @@ xmfree (void *md, void *ptr)
 /* NOTE: These are declared using PTR to ensure consistency with
    "libiberty.h".  xfree() is GDB local.  */
 
-PTR
+PTR                            /* OK: PTR */
 xmalloc (size_t size)
 {
   return xmmalloc (NULL, size);
 }
 
-PTR
-xrealloc (PTR ptr, size_t size)
+PTR                            /* OK: PTR */
+xrealloc (PTR ptr, size_t size)        /* OK: PTR */
 {
   return xmrealloc (NULL, ptr, size);
 }
 
-PTR
+PTR                            /* OK: PTR */
 xcalloc (size_t number, size_t size)
 {
   return xmcalloc (NULL, number, size);
@@ -1450,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;
                }
            }
@@ -1606,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");
@@ -1643,7 +1640,7 @@ init_page_info (void)
              }
          }
       }
-#endif /* MPW */
+#endif
 
 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
 
@@ -2301,22 +2298,7 @@ fprintf_symbol_filtered (struct ui_file *stream, char *name,
        }
       else
        {
-         switch (lang)
-           {
-           case language_cplus:
-             demangled = cplus_demangle (name, arg_mode);
-             break;
-           case language_java:
-             demangled = cplus_demangle (name, arg_mode | DMGL_JAVA);
-             break;
-           case language_objc:
-             /* Commented out until ObjC handling is enabled.  */
-             /*demangled = objc_demangle (name); */
-             /*break; */
-           default:
-             demangled = NULL;
-             break;
-           }
+         demangled = language_demangle (language_def (lang), name, arg_mode);
          fputs_filtered (demangled ? demangled : name, stream);
          if (demangled != NULL)
            {
@@ -2360,6 +2342,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);
+}
 \f
 
 /*
@@ -2605,25 +2675,6 @@ phex_nz (ULONGEST l, int sizeof_l)
 }
 
 
-/* Convert to / from the hosts pointer to GDB's internal CORE_ADDR
-   using the target's conversion routines. */
-CORE_ADDR
-host_pointer_to_address (void *ptr)
-{
-  gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
-  return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
-}
-
-void *
-address_to_host_pointer (CORE_ADDR addr)
-{
-  void *ptr;
-
-  gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
-  ADDRESS_TO_POINTER (builtin_type_void_data_ptr, &ptr, addr);
-  return ptr;
-}
-
 /* Convert a CORE_ADDR into a string.  */
 const char *
 core_addr_to_string (const CORE_ADDR addr)
@@ -2698,8 +2749,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
This page took 0.026145 seconds and 4 git commands to generate.