texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[5609] sloppy menu reading; dir lookup for --all


From: Gavin D. Smith
Subject: [5609] sloppy menu reading; dir lookup for --all
Date: Tue, 27 May 2014 12:49:26 +0000

Revision: 5609
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5609
Author:   gavin
Date:     2014-05-27 12:49:23 +0000 (Tue, 27 May 2014)
Log Message:
-----------
sloppy menu reading; dir lookup for --all

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/dir.c
    trunk/info/filesys.c
    trunk/info/filesys.h
    trunk/info/info-utils.c
    trunk/info/info-utils.h
    trunk/info/info.c
    trunk/info/nodemenu.c
    trunk/info/nodes.h
    trunk/info/session.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/ChangeLog     2014-05-27 12:49:23 UTC (rev 5609)
@@ -1,5 +1,27 @@
 2014-05-25  Gavin Smith  <address@hidden>
 
+       * info/info-utils.c (info_get_menu_entry_by_label): New argument
+       for sloppy menu reading.
+
+       * info/info.c (get_initial_file): Calls to lookup_dir_entry updated.
+       Try reading dir files sloppily if no exact match was found.  Function
+       reorganized.
+       (add_initial_nodes, main): Handle case when we were invoked
+       like "--node (emacs)Buffers".
+       (info_find_matching_files): Check for dir entries as well.
+
+       * info/dir.c (lookup_dir_entry): New argument for whether to search
+       inexactly.  Callers updated.
+       (dir_entry_of_infodir): New function.
+
+       * info/session.c (entry_in_menu): Removed.  Caller in
+       info_intuit_options_node updated.
+       (info_win_find_node): Null check.
+
+       * info/filesys.c (info_add_extension): No longer static.
+
+2014-05-25  Gavin Smith  <address@hidden>
+
        * info/infodoc.c (create_internal_info_help_node): Show program
        version in help window.
        

Modified: trunk/info/dir.c
===================================================================
--- trunk/info/dir.c    2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/dir.c    2014-05-27 12:49:23 UTC (rev 5609)
@@ -41,6 +41,7 @@
 static void create_dir_buffer (void);
 static NODE *build_dir_node (void);
 
+/* Return composite directory node.  Return value should not be freed. */
 NODE *
 get_dir_node (void)
 {
@@ -276,34 +277,52 @@
 }
 
 REFERENCE *
-lookup_dir_entry (char *label)
+lookup_dir_entry (char *label, int sloppy)
 {
   NODE *node = get_dir_node ();
   REFERENCE *entry;
 
-  entry = info_get_menu_entry_by_label (node, label);
+  entry = info_get_menu_entry_by_label (node, label, sloppy);
 
-  /* If the item wasn't found, search the list sloppily, e.g. the
-     user typed "buffer" when they really meant "Buffers". */
-  /* FIXME: Should this be placed in info_get_menu_entry_by_label? */
-  if (!entry)
+  return entry;
+}
+
+/* Look up entry in "dir" and "localdir" in search directory.  Return
+   value is a pointer to a newly allocated REFERENCE. */
+REFERENCE *
+dir_entry_of_infodir (char *label, char *searchdir)
+{
+  int da_index;
+  char *dir_filename;
+  char *dir_fullpath;
+
+  struct stat dummy;
+  char *entry_fullpath;
+
+  NODE *dir_node;
+  REFERENCE *entry;
+
+  for (da_index = 0; dir_filename = dirs_to_add[da_index]; da_index++)
     {
-      int i;
-      int best_guess = -1;
+      dir_fullpath = info_add_extension (searchdir, dir_filename, &dummy);
+      if (!dir_fullpath)
+        continue;
 
-      for (i = 0; (entry = node->references[i]); i++)
+      dir_node = info_get_node (dir_fullpath, "Top", PARSE_NODE_VERBATIM);
+      free (dir_fullpath);
+      entry = info_get_menu_entry_by_label (dir_node, label, 1);
+      if (!entry)
+        continue;
+
+      entry = info_copy_reference (entry);
+      entry_fullpath = info_add_extension (searchdir, entry->filename, &dummy);
+      if (entry_fullpath)
         {
-          if (mbscasecmp (entry->label, label) == 0)
-            break;
-          else if (best_guess == -1
-                && (mbsncasecmp (entry->label, label, strlen (label)) == 0))
-              best_guess = i;
+          free (entry->filename);
+          entry->filename = entry_fullpath;
         }
-
-      if (!entry && best_guess != -1)
-        entry = node->references[best_guess];
+      return entry;
     }
-
-  return entry;
 }
 
+

Modified: trunk/info/filesys.c
===================================================================
--- trunk/info/filesys.c        2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/filesys.c        2014-05-27 12:49:23 UTC (rev 5609)
@@ -27,7 +27,7 @@
 
 /* Local to this file. */
 static char *info_file_in_path (char *filename, struct stat *finfo);
-static char *info_add_extension (char *dirname, char *fname,
+char *info_add_extension (char *dirname, char *fname,
                                  struct stat *finfo);
 
 static char *filesys_read_compressed (char *pathname, size_t *filesize);
@@ -191,7 +191,7 @@
    extensions if necessary.  FILENAME can be an absolute path or a path
    relative to the current directory, in which case DIRNAME should be
    null.  Return it as a new string; otherwise return a NULL pointer. */
-static char *
+char *
 info_add_extension (char *dirname, char *filename, struct stat *finfo)
 {
   char *try_filename;

Modified: trunk/info/filesys.h
===================================================================
--- trunk/info/filesys.h        2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/filesys.h        2014-05-27 12:49:23 UTC (rev 5609)
@@ -46,6 +46,9 @@
 extern char *info_file_find_next_in_path (char *filename,
                                          int *diridx, struct stat *finfo);
 
+extern char *info_add_extension (char *dirname, char *filename,
+                                 struct stat *finfo);
+
 /* Read the contents of PATHNAME, returning a buffer with the contents of
    that file in it, and returning the size of that buffer in FILESIZE.
    FINFO is a stat struct which has already been filled in by the caller.

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/info-utils.c     2014-05-27 12:49:23 UTC (rev 5609)
@@ -245,7 +245,7 @@
    pointer to the ENTRY if found, or null.  Return value should not
    be freed by caller. */
 REFERENCE *
-info_get_menu_entry_by_label (NODE *node, char *label) 
+info_get_menu_entry_by_label (NODE *node, char *label, int sloppy) 
 {
   register int i;
   REFERENCE *entry;
@@ -254,12 +254,35 @@
   if (!references)
     return 0;
 
+  /* First look for an exact match. */
   for (i = 0; entry = references[i]; i++)
     {
       if (REFERENCE_MENU_ITEM != entry->type) continue;
       if (strcmp (label, entry->label) == 0)
         return entry;
     }
+
+  /* If the item wasn't found, search the list sloppily.  Perhaps this
+     user typed "buffer" when they really meant "Buffers". */
+  if (sloppy)
+    {
+      int i;
+      int best_guess = -1;
+
+      for (i = 0; entry = references[i]; i++)
+        {
+          if (REFERENCE_MENU_ITEM != entry->type) continue;
+          if (mbscasecmp (label, entry->label) == 0)
+            return entry; /* Exact, case-insensitive match. */
+          else if (best_guess == -1
+                && (mbsncasecmp (entry->label, label, strlen (label)) == 0))
+              best_guess = i;
+        }
+
+      if (!entry && best_guess != -1)
+        return references[best_guess];
+    }
+
   return 0;
 }
 

Modified: trunk/info/info-utils.h
===================================================================
--- trunk/info/info-utils.h     2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/info-utils.h     2014-05-27 12:49:23 UTC (rev 5609)
@@ -65,8 +65,10 @@
 void scan_node_contents (FILE_BUFFER *fb, NODE **node_ptr);
 
 /* Get the menu entry associated with LABEL in NODE.  Return a
-   pointer to the reference if found, or NULL. */
-extern REFERENCE *info_get_menu_entry_by_label (NODE *node, char *label);
+   pointer to the reference if found, or NULL.  If SLOPPY, accept
+   initial substrings and check insensitively to case. */
+extern REFERENCE *info_get_menu_entry_by_label (NODE *node, char *label,
+                                                int sloppy);
 
 /* A utility function for concatenating REFERENCE **.  Returns a new
    REFERENCE ** which is the concatenation of REF1 and REF2.  The REF1

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/info.c   2014-05-27 12:49:23 UTC (rev 5609)
@@ -166,72 +166,76 @@
 get_initial_file (char *filename, int *argc, char ***argv, char **error)
 {
   char *initial_file = 0;           /* First file loaded by Info. */
+  REFERENCE *entry;
 
-  if (!filename)
+  /* If there are any more arguments, the initial file is the
+     dir entry given by the first one. */
+  if (!filename && (*argv)[0])
     {
-      REFERENCE *entry = 0;
+      /* If they say info -O info, we want to show them the invocation node
+         for standalone info; there's nothing useful in info.texi.  */
+      if (goto_invocation_p && (*argv)[0]
+          && mbscasecmp ((*argv)[0], "info") == 0)
+        (*argv)[0] = "info-stnd";
 
-      /* If there are any more arguments, the initial file is the
-         dir entry given by the first one. */
-      if ((*argv)[0])
+      entry = lookup_dir_entry ((*argv)[0], 0);
+      if (entry)
         {
-          /* If they say info -O info, we want to show them the invocation node
-             for standalone info; there's nothing useful in info.texi.  */
-          if (goto_invocation_p && (*argv)[0]
-              && mbscasecmp ((*argv)[0], "info") == 0)
-            (*argv)[0] = "info-stnd";
+          initial_file = info_find_fullpath (entry->filename, 0);
+          if (initial_file)
+            {
+              (*argv)++; /* Advance past first remaining argument. */
+              (*argc)--;
 
-          entry = lookup_dir_entry ((*argv)[0]);
-
-          if (entry)
-            {
-              initial_file = info_find_fullpath (entry->filename, 0);
               /* Store full path, so that we find the already loaded file in
                  info_find_file, and show the full path if --where is used. */
               entry->filename = initial_file;
               add_pointer_to_array (info_copy_reference (entry),
                   ref_index, ref_list, ref_slots, 2);
+              return initial_file;
             }
+        }
+    }
 
-          if (!initial_file)
-            /* Try finding a file with this name, in case
-               it exists, but wasn't listed in dir. */
-            initial_file = info_find_fullpath ((*argv)[0], 0);
+  /* User used "--file". */
+  if (filename)
+    {
+      initial_file = info_find_fullpath (filename, 0);
 
-          if (initial_file)
-            {
-              (*argv)++; /* Advance past first remaining argument. */
-              (*argc)--;
-            }
-          else
-            asprintf (error, _("No menu item `%s' in node `%s'."),
-                (*argv)[0], "(dir)Top");
+      if (!initial_file)
+        {
+          if (filesys_error_number)
+            *error = filesys_error_string (filename, filesys_error_number);
         }
-      /* Otherwise, we want the dir node.  The only node to be displayed
-         or output will be "Top". */
       else
-        return 0;
+        return initial_file;
     }
-  else
+
+  /* File name lookup. */
+  if (!filename && (*argv)[0])
     {
-      initial_file = info_find_fullpath (filename, 0);
-
-      if (!initial_file && filesys_error_number)
-        *error = filesys_error_string (filename, filesys_error_number);
+      /* Try finding a file with this name, in case
+         it exists, but wasn't listed in dir. */
+      initial_file = info_find_fullpath ((*argv)[0], 0);
+      if (initial_file)
+        {
+          (*argv)++; /* Advance past first remaining argument. */
+          (*argc)--;
+          return initial_file;
+        }
+      else
+        asprintf (error, _("No menu item `%s' in node `%s'."),
+            (*argv)[0], "(dir)Top");
     }
 
   /* Fall back to loading man page. */
-  if (!initial_file)
+  if (filename || (*argv)[0])
     {
       NODE *man_node;
 
       debug (3, ("falling back to manpage node"));
 
-      if (!filename)
-        filename = (*argv)[0];
-
-      man_node = get_manpage_node (filename);
-
+      man_node = get_manpage_node (filename ? filename : (*argv)[0]);
       if (man_node)
         {
           REFERENCE *new_ref;
@@ -240,7 +244,7 @@
 
           new_ref = xzalloc (sizeof (REFERENCE));
           new_ref->filename = MANPAGE_FILE_BUFFER_NAME;
-          new_ref->nodename = filename;
+          new_ref->nodename = filename ? filename : (*argv)[0];
           add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
 
           initial_file = MANPAGE_FILE_BUFFER_NAME;
@@ -248,7 +252,25 @@
         }
     }
 
-  return initial_file;
+  /* Inexact dir lookup. */
+  if (!filename && (*argv)[0])
+    {
+      entry = lookup_dir_entry ((*argv)[0], 1);
+      if (entry)
+        {
+          initial_file = info_find_fullpath (entry->filename, 0);
+          /* Store full path, so that we find the already loaded file in
+             info_find_file, and show the full path if --where is used. */
+          entry->filename = initial_file;
+          add_pointer_to_array (info_copy_reference (entry),
+              ref_index, ref_list, ref_slots, 2);
+          return initial_file;
+        }
+    }
+
+  /* Otherwise, we want the dir node.  The only node to be displayed
+     or output will be "Top". */
+  return 0;
 }
 
 /* Expand list of nodes to be loaded. */
@@ -274,13 +296,23 @@
       for (i = 0; user_nodenames[i]; i++)
         {
           new_ref = xzalloc (sizeof (REFERENCE));
-          new_ref->filename = initial_file->fullpath;
-          new_ref->nodename = user_nodenames[i];
 
+          /* Parse node spec to support invoking
+             like info --node "(emacs)Buffers". */
+          info_parse_node (user_nodenames[i], PARSE_NODE_VERBATIM);
+          if (info_parsed_filename)
+            new_ref->filename = xstrdup (info_parsed_filename);
+          else
+            new_ref->filename = initial_file->fullpath;
+          new_ref->nodename = xstrdup (info_parsed_nodename);
+
           add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
         }
     }
 
+  if (!initial_file)
+    return;
+
   if (goto_invocation_p)
     {
       NODE *top_node;
@@ -449,22 +481,49 @@
 static void
 info_find_matching_files (char *filename)
 {
+  int i;
+  char *searchdir;
+
   REFERENCE *new_ref;
   NODE *man_node;
 
-  int i = 0;
+  /* Check for dir entries first. */
+  i = 0;
+  for (searchdir = infopath_first (&i); searchdir;
+       searchdir = infopath_next (&i))
+    {
+      new_ref = dir_entry_of_infodir (filename, searchdir);
 
+      if (new_ref)
+        add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+    }
+
+  /* Look for files with matching names. */
+  i = 0;
   while (1)
     {
       char *p;
+      int j;
 
       p = info_file_find_next_in_path (filename, &i, 0);
       if (!p)
         break;
 
-      new_ref = xzalloc (sizeof (REFERENCE));
-      new_ref->filename = p;
-      add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+      /* Add to list only if the file is not in the list already (which would
+         happen if there was a dir entry with the label and filename both
+         being this file). */
+      for (j = 0; j < ref_index; j++)
+        {
+          if (!strcmp (p, ref_list[j]->filename))
+            break;
+        }
+
+      if (j == ref_index)
+        {
+          new_ref = xzalloc (sizeof (REFERENCE));
+          new_ref->filename = p;
+          add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+        }
     }
 
   /* Check for man page. */
@@ -803,9 +862,13 @@
         }
 
       /* Add nodes to start with (unless we fell back to the man page). */
-      if (initial_file && strcmp (MANPAGE_FILE_BUFFER_NAME, initial_file))
+      if (!initial_file || strcmp (MANPAGE_FILE_BUFFER_NAME, initial_file))
         {
-          initial_fb = info_find_file (initial_file);
+          if (initial_file)
+            initial_fb = info_find_file (initial_file);
+          else
+            initial_fb = 0;
+
           add_initial_nodes (initial_fb, argc, argv, &error);
         }
     }

Modified: trunk/info/nodemenu.c
===================================================================
--- trunk/info/nodemenu.c       2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/nodemenu.c       2014-05-27 12:49:23 UTC (rev 5609)
@@ -325,9 +325,11 @@
       REFERENCE *entry;
 
       /* Find the selected label in the references. */
-      entry = info_get_menu_entry_by_label (node, line);
+      entry = info_get_menu_entry_by_label (node, line, 0);
 
       if (!entry)
+        /* This shouldn't happen, because LINE was in the completion list
+           built from the list of references. */
         info_error (_("The reference disappeared! (%s)."), line);
       else
         info_select_reference (window, entry);

Modified: trunk/info/nodes.h
===================================================================
--- trunk/info/nodes.h  2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/nodes.h  2014-05-27 12:49:23 UTC (rev 5609)
@@ -193,6 +193,7 @@
 
 /* Found in dir.c */
 extern NODE *get_dir_node (void);
-extern REFERENCE *lookup_dir_entry (char *label);
+extern REFERENCE *lookup_dir_entry (char *label, int sloppy);
+extern REFERENCE *dir_entry_of_infodir (char *label, char *searchdir);
 
 #endif /* not NODES_H */

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-05-25 23:06:38 UTC (rev 5608)
+++ trunk/info/session.c        2014-05-27 12:49:23 UTC (rev 5609)
@@ -1804,8 +1804,8 @@
     {
       NODE *p = win->nodes[i];
 
-      if (strcmp (p->filename, node->filename) == 0 &&
-         strcmp (p->nodename, node->nodename) == 0)
+      if (p->filename && !strcmp (p->filename, node->filename)
+         && p->nodename && !strcmp (p->nodename, node->nodename))
        break;
     }
   return i;
@@ -2795,30 +2795,9 @@
         }
 
       /* Find the specified menu item. */
-      entry = info_get_menu_entry_by_label (initial_node, arg);
+      entry = info_get_menu_entry_by_label (initial_node, arg, !strict);
 
-      /* If the item wasn't found, search the list sloppily.  Perhaps this
-         user typed "buffer" when they really meant "Buffers". */
-      if (!strict && !entry)
-        {
-          int i;
-          int best_guess = -1;
-
-         debug (3, ("no entry found: guessing"));
-          for (i = 0; (entry = initial_node->references[i]); i++)
-            {
-              if (mbscasecmp (entry->label, arg) == 0)
-                break;
-              else if (best_guess == -1
-                    && (mbsncasecmp (entry->label, arg, strlen (arg)) == 0))
-                  best_guess = i;
-            }
-
-          if (!entry && best_guess != -1)
-            entry = initial_node->references[best_guess];
-        }
-
-      /* If we still failed to find the reference: */
+      /* If we failed to find the reference: */
       if (!entry)
         {
           if (error)
@@ -2949,47 +2928,6 @@
     window_clear_echo_area ();
 }
 
-/* Search the menu in NODE for a (possibly mis-spelled) entry ARG.
-   Return the menu entry, or the best guess for what they meant by ARG,
-   or NULL if there's nothing in this menu seems to fit the bill.
-   If EXACT is non-zero, allow only exact matches.  */
-static REFERENCE *
-entry_in_menu (char *arg, NODE *node, int exact)
-{
-  REFERENCE **menu = node->references;
-  REFERENCE *entry;
-
-  if (!menu)
-    return 0;
-
-  /* First, try to find the specified menu item verbatim.  */
-  entry = info_get_menu_entry_by_label (node, arg);
-
-  /* If the item wasn't found, search the list sloppily.  Perhaps we
-     have "Option Summary", but ARG is "option".  */
-  if (!entry && !exact)
-    {
-      int i;
-      int best_guess = -1;
-
-      for (i = 0; (entry = menu[i]); i++)
-        {
-          if (REFERENCE_MENU_ITEM != entry->type) continue;
-
-          if (mbscasecmp (entry->label, arg) == 0)
-            break;
-          else
-            if (mbsncasecmp (entry->label, arg, strlen (arg)) == 0)
-              best_guess = i;
-        }
-
-      if (!entry && best_guess != -1)
-        entry = menu[best_guess];
-    }
-
-  return entry;
-}
-
 /* Find the node that is the best candidate to list the PROGRAM's
    invocation info and its command-line options, by looking for menu
    items and chains of menu items with characteristic names.  Return
@@ -3047,8 +2985,8 @@
           sprintf (nodename, *try_node, program);
           /* The last resort "%s" is dangerous, so we restrict it
              to exact matches here.  */
-          new_entry = entry_in_menu (nodename, initial_node,
-                                 strcmp (*try_node, "%s") == 0);
+          new_entry = info_get_menu_entry_by_label
+            (initial_node, nodename, strcmp (*try_node, "%s"));
           free (nodename);
           if (new_entry)
             break;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]