This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Allow to find parameters in completion for case insensitive settings


  While trying to fix case completion for
pascal, I stumbled or this problem.

  Currently, even if you explicitly set 'set case off'
and try to complete a struct (or a pascal record)
the completer code will not find the field if the first letter
do not match the casing of the recorded name for the field.

  This patch adds a new parameter to add_struct_fields
function called ignore_case.
  This function is called a first time was ignore_case set to zero.
This generates the former behavior.
  But if current settings is case insensitive (either due to
automatic and current language being case insensitive or by explicitly
set case sensitivity to off) and no case matching completion
was found, then a second call to add_struct_fields is performed,
this time with case_ignore set to 1, thus using strncasecmp function.

Any comments,

Pierre Muller


2013-11-27  Pierre Muller  <muller@sourceware.org>

        * completer.c (add_struct_fields): Add new parameter ignore_case.
        Use strncmp or strncasecmp depending on IGNORE_CASE.
        (expression_completer): Call add_struct_fields first with
        IGNORE_CASE=0, and a second time with IGNORE_CASE=1,
        if no match was found and current case sensitivity is off.

diff --git a/gdb/completer.c b/gdb/completer.c
index 91bf812..de18a4f 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -336,24 +336,29 @@ location_completer (struct cmd_list_element *ignore,
    OUTPUT.  */
 static void
 add_struct_fields (struct type *type, VEC (char_ptr) **output,
-                  char *fieldname, int namelen)
+                  char *fieldname, int namelen, int ignore_case)
 {
   int i;
   int computed_type_name = 0;
   const char *type_name = NULL;
+  int (*ncmp) (const char *, const char *, size_t);
+
+  ncmp = (ignore_case == 0 ? strncmp : strncasecmp);
+

   CHECK_TYPEDEF (type);
   for (i = 0; i < TYPE_NFIELDS (type); ++i)
     {
       if (i < TYPE_N_BASECLASSES (type))
        add_struct_fields (TYPE_BASECLASS (type, i),
-                          output, fieldname, namelen);
+                          output, fieldname, namelen, ignore_case);
       else if (TYPE_FIELD_NAME (type, i))
        {
          if (TYPE_FIELD_NAME (type, i)[0] != '\0')
            {
-             if (! strncmp (TYPE_FIELD_NAME (type, i),
-                            fieldname, namelen))
+             int res = ncmp (TYPE_FIELD_NAME (type, i),
+                               fieldname, namelen);
+             if (! res)
                VEC_safe_push (char_ptr, *output,
                               xstrdup (TYPE_FIELD_NAME (type, i)));
            }
@@ -361,7 +366,7 @@ add_struct_fields (struct type *type, VEC (char_ptr)
**output,
            {
              /* Recurse into anonymous unions.  */
              add_struct_fields (TYPE_FIELD_TYPE (type, i),
-                                output, fieldname, namelen);
+                                output, fieldname, namelen, ignore_case);
            }
        }
     }
@@ -369,8 +374,12 @@ add_struct_fields (struct type *type, VEC (char_ptr)
**output,
   for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
     {
       const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
-
-      if (name && ! strncmp (name, fieldname, namelen))
+      int res;
+      if (name == NULL)
+       res = 1;
+      else
+       res = ncmp (name, fieldname, namelen);
+      if (res == 0)
        {
          if (!computed_type_name)
            {
@@ -378,7 +387,7 @@ add_struct_fields (struct type *type, VEC (char_ptr)
**output,
              computed_type_name = 1;
            }
          /* Omit constructors from the completion list.  */
-         if (!type_name || strcmp (type_name, name))
+         if (!type_name || ncmp (type_name, name, namelen))
            VEC_safe_push (char_ptr, *output, xstrdup (name));
        }
     }
@@ -423,7 +432,17 @@ expression_completer (struct cmd_list_element *ignore,
          int flen = strlen (fieldname);
          VEC (char_ptr) *result = NULL;

-         add_struct_fields (type, &result, fieldname, flen);
+         /* First try with ignore_case set to zero.  */
+         add_struct_fields (type, &result, fieldname, flen, 0);
+         /* Second try, if case_sensitivity set to off,
+            with ignore_case set to one.  */
+         if (result == NULL
+             && ((case_mode == case_mode_manual
+                  && case_sensitivity == case_sensitive_off)
+                 || (case_mode == case_mode_auto
+                     && current_language->la_case_sensitivity
+                        == case_sensitive_off)))
+           add_struct_fields (type, &result, fieldname, flen, 1);
          xfree (fieldname);
          return result;
        }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]