texinfo-commits
[Top][All Lists]
Advanced

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

[5324] Improve info -a: process manpages, filter out duplicate names.


From: Sergey Poznyakoff
Subject: [5324] Improve info -a: process manpages, filter out duplicate names.
Date: Sun, 18 Aug 2013 14:29:06 +0000

Revision: 5324
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5324
Author:   gray
Date:     2013-08-18 14:29:05 +0000 (Sun, 18 Aug 2013)
Log Message:
-----------
Improve info -a: process manpages, filter out duplicate names.

* info/info-utils.c (info_reference_free): New function.
(info_free_references): Use info_reference_free.
* info/info-utils.h (info_reference_free): New proto.
* info/info.c (info_find_matching_files): Return
REFERENCE **.
(namelist_add,namelist_free): New static functions.
(all_files): Select unique file names.
* info/session.c (info_split_window)
[SPLIT_BEFORE_ACTIVE]: Declare pagetop.
(info_menu_or_ref_item): Use info_reference_free.
(info_follow_menus): Fix processing in strict mode.

* info/filesys.c: Remove unused variable.
* info/filesys.h (forget_file_names): New proto.
* info/indices.c (apropos_in_all_indices): Use info_reference_free
to free a pointer to REFERENCE.
(info_virtual_index): Remove unused variable.
(allfiles_create_node): Second argument is REFERENCE **.
* info/indices.h (allfiles_create_node): Change signature.
* info/man.c (manpage_xrefs_in_binding): Use info_reference_free.
* info/nodes.c: Include tag.h
* info/nodes.h (TAG)<nodelen>: Change type to size_t.
* info/window.h (window_log_to_phys_line): New proto.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/filesys.c
    trunk/info/filesys.h
    trunk/info/indices.c
    trunk/info/indices.h
    trunk/info/info-utils.c
    trunk/info/info-utils.h
    trunk/info/info.c
    trunk/info/man.c
    trunk/info/nodes.c
    trunk/info/nodes.h
    trunk/info/session.c
    trunk/info/window.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/ChangeLog     2013-08-18 14:29:05 UTC (rev 5324)
@@ -1,3 +1,31 @@
+2013-08-18  Sergey Poznyakoff  <address@hidden>
+
+       Improve info -a: process manpages, filter out duplicate names.
+
+       * info/info-utils.c (info_reference_free): New function.
+       (info_free_references): Use info_reference_free.
+       * info/info-utils.h (info_reference_free): New proto.
+       * info/info.c (info_find_matching_files): Return
+       REFERENCE **.
+       (namelist_add,namelist_free): New static functions.
+       (all_files): Select unique file names.
+       * info/session.c (info_split_window)
+       [SPLIT_BEFORE_ACTIVE]: Declare pagetop.
+       (info_menu_or_ref_item): Use info_reference_free.
+       (info_follow_menus): Fix processing in strict mode.
+
+       * info/filesys.c: Remove unused variable.
+       * info/filesys.h (forget_file_names): New proto.
+       * info/indices.c (apropos_in_all_indices): Use info_reference_free
+       to free a pointer to REFERENCE.
+       (info_virtual_index): Remove unused variable.
+       (allfiles_create_node): Second argument is REFERENCE **.
+       * info/indices.h (allfiles_create_node): Change signature.
+       * info/man.c (manpage_xrefs_in_binding): Use info_reference_free.
+       * info/nodes.c: Include tag.h
+       * info/nodes.h (TAG)<nodelen>: Change type to size_t.
+       * info/window.h (window_log_to_phys_line): New proto.
+
 2013-08-17  Sergey Poznyakoff  <address@hidden>
 
        The -x option takes a numeric argument.

Modified: trunk/info/filesys.c
===================================================================
--- trunk/info/filesys.c        2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/filesys.c        2013-08-18 14:29:05 UTC (rev 5324)
@@ -163,7 +163,7 @@
 {
   struct stat finfo;
   char *temp_dirname;
-  int statable, dirname_index;
+  int statable;
 
   /* Reject ridiculous cases up front, to prevent infinite recursion
      later on.  E.g., someone might say "info '(.)foo'"...  */

Modified: trunk/info/filesys.h
===================================================================
--- trunk/info/filesys.h        2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/filesys.h        2013-08-18 14:29:05 UTC (rev 5324)
@@ -52,6 +52,9 @@
    If it can't find the file, it returns NULL. */
 extern char *info_find_fullpath (char *partial);
 
+/* Forget all cached file names */
+extern void forget_file_names (void);
+
 /* Given a chunk of text and its length, convert all CRLF pairs at the
    EOLs into a single Newline character.  Return the length of produced
    text.  */

Modified: trunk/info/indices.c
===================================================================
--- trunk/info/indices.c        2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/indices.c        2013-08-18 14:29:05 UTC (rev 5324)
@@ -648,12 +648,7 @@
                  100, REFERENCE *);
             }
           else
-            {
-              maybe_free (entry->label);
-              maybe_free (entry->filename);
-              maybe_free (entry->nodename);
-              free (entry);
-            }
+            info_reference_free (entry);
         }
 
       free (all_indices);
@@ -876,7 +871,6 @@
    _("List all matches of a string in the index"))
 {
   char *line;
-  size_t linelen;
   FILE_BUFFER *fb, *tfb;
   NODE *node;
   struct text_buffer text;
@@ -916,7 +910,6 @@
       free (line);
       return;
     }
-  linelen = strlen (line);
   
   text_buffer_init (&text);
   text_buffer_printf (&text, _("Index for `%s'"), line);
@@ -964,13 +957,12 @@
 static NODE *allfiles_node;
 
 NODE *
-allfiles_create_node (char *term, REFERENCE *fref)
+allfiles_create_node (char *term, REFERENCE **fref)
 {
   int i;
   struct text_buffer text;
   size_t off;
   FILE_BUFFER *fb;
-  NODE *node;
   
   text_buffer_init (&text);
   text_buffer_printf (&text, _("File names matching `%s'"), term);
@@ -989,11 +981,11 @@
   memmove (text.base, text.base + off, text.off - off);
   text.off -= off;
 
-  for (i = 0; fref[i].filename; i++)
+  for (i = 0; fref[i]; i++)
     {
-      text_buffer_printf (&text, "* %4i: (%s)", i+1, fref[i].filename);
-      if (fref[i].nodename)
-       text_buffer_printf (&text, "%s", fref[i].nodename);
+      text_buffer_printf (&text, "* %4i: (%s)", i+1, fref[i]->filename);
+      if (fref[i]->nodename)
+       text_buffer_printf (&text, "%s", fref[i]->nodename);
       text_buffer_printf (&text, ".\n");
     }
 

Modified: trunk/info/indices.h
===================================================================
--- trunk/info/indices.h        2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/indices.h        2013-08-18 14:29:05 UTC (rev 5324)
@@ -41,6 +41,6 @@
 extern void do_info_index_search (WINDOW *window, int count, char 
*search_string);
 extern int index_entry_exists (WINDOW *window, char *string);
 
-NODE *allfiles_create_node (char *term, REFERENCE *fref);
+NODE *allfiles_create_node (char *term, REFERENCE **fref);
 
 #endif /* not INFO_INDICES_H */

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/info-utils.c     2013-08-18 14:29:05 UTC (rev 5324)
@@ -435,6 +435,18 @@
 
 
 
+void
+info_reference_free (REFERENCE *ref)
+{
+  if (ref)
+    {
+      maybe_free (ref->label);
+      maybe_free (ref->filename);
+      maybe_free (ref->nodename);
+      free (ref);
+    }
+}
+
 /* Free the data associated with REFERENCES. */
 void
 info_free_references (REFERENCE **references)
@@ -445,14 +457,8 @@
   if (references)
     {
       for (i = 0; references && (entry = references[i]); i++)
-        {
-          maybe_free (entry->label);
-          maybe_free (entry->filename);
-          maybe_free (entry->nodename);
+        info_reference_free (entry);
 
-          free (entry);
-        }
-
       free (references);
     }
 }

Modified: trunk/info/info-utils.h
===================================================================
--- trunk/info/info-utils.h     2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/info-utils.h     2013-08-18 14:29:05 UTC (rev 5324)
@@ -99,6 +99,9 @@
 /* Copy an existing reference into new memory.  */
 extern REFERENCE *info_copy_reference (REFERENCE *src);
 
+/* Free the data associated with a single REF */
+void info_reference_free (REFERENCE *ref);
+
 /* Free the data associated with REFERENCES. */
 extern void info_free_references (REFERENCE **references);
 

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/info.c   2013-08-18 14:29:05 UTC (rev 5324)
@@ -344,16 +344,16 @@
   return p;
 }
 
-REFERENCE *
+REFERENCE **
 info_find_matching_files (char *filename)
 {
   size_t argc = 0;
   size_t argn = 0;
-  REFERENCE *argv = NULL;
+  REFERENCE **argv = NULL;
   int i = 0;
   char *p;
   
-  do
+  while (1)
     {
       p = info_file_find_next_in_path (filename, infopath (), &i);
       if (argc == argn)
@@ -362,22 +362,63 @@
            argn = 2;
          argv = x2nrealloc (argv, &argn, sizeof (argv[0]));
        }
-      memset (&argv[argc], 0, sizeof (argv[argc]));
-      argv[argc++].filename = p;
+      if (!p)
+       {
+         argv[argc] = NULL;
+         break;
+       }
+
+      argv[argc] = xzalloc (sizeof (*argv[0]));
+      argv[argc]->filename = p;
+      ++argc;
     }
-  while (p);
+
   return argv;
 }
+
+struct namelist_ent
+{
+  struct namelist_ent *next;
+  char name[1];
+};
 
 static int
+namelist_add (struct namelist_ent **ptop, const char *name)
+{
+  struct namelist_ent *p;
+
+  for (p = *ptop; p; p = p->next)
+    if (strcmp (p->name, name) == 0)
+      return 1;
+
+  p = xmalloc (sizeof (*p) + strlen (name));
+  strcpy (p->name, name);
+  p->next = *ptop;
+  *ptop = p;
+  return 0;
+}
+
+static void
+namelist_free (struct namelist_ent *top)
+{
+  while (top)
+    {
+      struct namelist_ent *next = top->next;
+      free (top);
+      top = next;
+    }
+}
+
+
+static int
 all_files (char *filename, int argc, char **argv)
 {
-  REFERENCE *fref;
+  REFERENCE **fref;
   char *fname;
   int i, j;
   int dirok;
-  size_t count;
-  
+  struct namelist_ent *nlist = NULL;
+
   if (user_filename)
     {
       fname = user_filename;
@@ -391,30 +432,27 @@
   
   fref = info_find_matching_files (fname);
   
-  for (i = 0; fref[i].filename; )
+  for (i = 0; fref[i]; )
     {
       NODE *node;
-
+      
       forget_file_names ();
       if (!user_filename)
        {
-         char *p = dirname (fref[i].filename);
+         char *p = dirname (fref[i]->filename);
          infopath_add (p, INFOPATH_INIT);
          free (p);
        }
-      node = info_get_node (fref[i].filename,
+      node = info_get_node (fref[i]->filename,
                            user_nodenames ? user_nodenames[0] : 0,
                            PARSE_NODE_DFLT);
       
       if (node)
        {
-         NODE *errnode;
-         NODE *subnode = info_follow_menus (node, argv, &errnode, 1);
-         if (errnode)
-           show_error_node (errnode);
+         NODE *subnode = info_follow_menus (node, argv, NULL, 1);
          if (!subnode)
            {
-             forget_info_file (fref[i].filename);
+             forget_info_file (fref[i]->filename);
              node = NULL;
            }
          else
@@ -428,30 +466,40 @@
            node = NULL;
          else
            {
-             free (fref[i].filename);
-             fref[i].filename = xstrdup (name);
+             free (fref[i]->filename);
+             fref[i]->filename = xstrdup (name);
            }
        }
       
       if (!node)
        {
-         free (fref[i].filename);
-         for (j = i; (fref[j] = fref[j + 1]).filename; j++);
+         info_reference_free (fref[i]);
+         for (j = i; (fref[j] = fref[j + 1]); j++);
        }
       else
        {
-         if (print_where_p)
-           printf ("%s\n", fref[i].filename);
-         else if (user_output_filename)
-           dump_node_to_file (node, user_output_filename,
-                              dump_subnodes);
+         if (namelist_add (&nlist, fref[i]->filename) == 0)
+           {
+             if (print_where_p)
+               printf ("%s\n", fref[i]->filename);
+             else if (user_output_filename)
+               dump_node_to_file (node, user_output_filename,
+                                  dump_subnodes);
+             else
+               fref[i]->nodename = xstrdup (node->nodename);
+             forget_info_file (fref[i]->filename);
+             ++i;
+           }
          else
-           fref[i].nodename = xstrdup (node->nodename);
-
-         forget_info_file (fref[i].filename);
-         ++i;
+           {
+             forget_info_file (fref[i]->filename);
+             info_reference_free (fref[i]);
+             for (j = i; (fref[j] = fref[j + 1]); j++);
+           }
        }
     }
+  
+  namelist_free (nlist);
 
   if (print_where_p || user_output_filename)
     return EXIT_SUCCESS;
@@ -703,7 +751,7 @@
   
   if (all_matches_p)
     return all_files (user_filename, argc, argv);
-  
+
   return single_file (user_filename, argc, argv);
 }
 

Modified: trunk/info/man.c
===================================================================
--- trunk/info/man.c    2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/man.c    2013-08-18 14:29:05 UTC (rev 5324)
@@ -671,17 +671,10 @@
   for (i = 0; (entry = all_refs[i]); i++)
     {
       if ((entry->start > start) && (entry->end < end))
-        {
-          add_pointer_to_array
-            (entry, brefs_index, brefs, brefs_slots, 10, REFERENCE *);
-        }
+        add_pointer_to_array (entry, brefs_index, brefs, brefs_slots, 10, 
+                              REFERENCE *);
       else
-        {
-          maybe_free (entry->label);
-          maybe_free (entry->filename);
-          maybe_free (entry->nodename);
-          free (entry);
-        }
+        info_reference_free (entry);
     }
 
   free (all_refs);

Modified: trunk/info/nodes.c
===================================================================
--- trunk/info/nodes.c  2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/nodes.c  2013-08-18 14:29:05 UTC (rev 5324)
@@ -25,6 +25,7 @@
 #include "search.h"
 #include "filesys.h"
 #include "info-utils.h"
+#include "tag.h"
 
 #if defined (HANDLE_MAN_PAGES)
 #  include "man.h"
@@ -953,9 +954,8 @@
   int i;
 
   /* If no tags at all (possibly a misformatted info file), quit.  */
-  if (!file_buffer->tags) {
+  if (!file_buffer->tags)
     return NULL;
-  }
 
   for (i = 0; (tag = file_buffer->tags[i]); i++)
     if (strcmp (nodename, tag->nodename) == 0)

Modified: trunk/info/nodes.h
===================================================================
--- trunk/info/nodes.h  2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/nodes.h  2013-08-18 14:29:05 UTC (rev 5324)
@@ -89,7 +89,7 @@
   char *filename;               /* The file where this node can be found. */
   char *nodename;               /* The node pointed to by this tag. */
   long nodestart;               /* The offset of the start of this node. */
-  long nodelen;                 /* The length of this node. */
+  size_t nodelen;               /* The length of this node. */
   char *content_cache;          /* Cache of the node contents; used if the
                                   node contents must be preprocessed before
                                   displaying it. */

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/session.c        2013-08-18 14:29:05 UTC (rev 5324)
@@ -1778,12 +1778,14 @@
 DECLARE_INFO_COMMAND (info_split_window, _("Split the current window"))
 {
   WINDOW *split, *old_active;
+#if defined (SPLIT_BEFORE_ACTIVE)
   int pagetop;
 
   /* Remember the current pagetop of the window being split.  If it doesn't
      change, we can scroll its contents around after the split. */
   pagetop = window->pagetop;
-
+#endif
+  
   /* Make the new window. */
   old_active = active_window;
   active_window = window;
@@ -2644,13 +2646,7 @@
         }
 
       free (line);
-      if (defentry)
-        {
-          free (defentry->label);
-          maybe_free (defentry->filename);
-          maybe_free (defentry->nodename);
-          free (defentry);
-        }
+      info_reference_free (defentry);
     }
 
   info_free_references (menu);
@@ -2870,8 +2866,7 @@
             {
               if (mbscasecmp (entry->label, arg) == 0)
                 break;
-              else
-                if ((best_guess == -1)
+              else if (!strict && (best_guess == -1)
                     && (mbsncasecmp (entry->label, arg, strlen (arg)) == 0))
                   best_guess = i;
             }
@@ -2884,14 +2879,14 @@
          node anyway.  It is probably a misspelling. */
       if (!entry)
         {
-         if (strict)
-           return NULL;
           if (arg == first_arg)
             {
               /* Maybe they typed "info foo" instead of "info -f foo".  */
               node = info_get_node (first_arg, NULL, PARSE_NODE_DFLT);
               if (node)
                 add_file_directory_to_path (first_arg);
+             else if (strict)
+               return NULL;
               else
                 node = make_manpage_node (first_arg);
               if (node)
@@ -2915,7 +2910,7 @@
       /* Try to find this node.  */
       node = info_get_node (entry->filename, entry->nodename, 
                             PARSE_NODE_VERBATIM);
-      if (!node && arg == first_arg)
+      if (!strict && !node && arg == first_arg)
         {
           node = make_manpage_node (first_arg);
           if (node)

Modified: trunk/info/window.h
===================================================================
--- trunk/info/window.h 2013-08-17 19:00:28 UTC (rev 5323)
+++ trunk/info/window.h 2013-08-18 14:29:05 UTC (rev 5324)
@@ -279,14 +279,16 @@
                     size_t, size_t),
         void *closure);
 
-void clean_manpage (char *manpage);
+extern void clean_manpage (char *manpage);
 
 extern void window_compute_line_map (WINDOW *win);
 
-int window_point_to_column (WINDOW *win, long point, long *np);
+extern int window_point_to_column (WINDOW *win, long point, long *np);
 
-void window_line_map_init (WINDOW *win);
+extern void window_line_map_init (WINDOW *win);
 
-long window_end_of_line (WINDOW *win);
+extern long window_end_of_line (WINDOW *win);
 
+extern size_t window_log_to_phys_line (WINDOW *window, size_t ln);
+
 #endif /* not INFO_WINDOW_H */




reply via email to

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