texinfo-commits
[Top][All Lists]
Advanced

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

[5513] minor tidy-up


From: Gavin D. Smith
Subject: [5513] minor tidy-up
Date: Sat, 03 May 2014 10:37:54 +0000

Revision: 5513
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5513
Author:   gavin
Date:     2014-05-03 10:37:53 +0000 (Sat, 03 May 2014)
Log Message:
-----------
minor tidy-up

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/info-utils.c
    trunk/info/info-utils.h
    trunk/info/info.c
    trunk/info/infodoc.c
    trunk/info/man.c
    trunk/info/nodemenu.c
    trunk/info/session.c
    trunk/info/window.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/ChangeLog     2014-05-03 10:37:53 UTC (rev 5513)
@@ -1,3 +1,15 @@
+2014-05-03  Gavin Smith  <address@hidden>
+
+       * info/window.c (string_to_node): Function deleted.  Caller in
+       create_internal_info_help_node updated.
+
+       * info/window.c, info/man.c (clean_manpage): Function moved.
+       * info/window.c, info/info-utils.c (ansi_escape): Function moved.
+
+       * info.c/info-utils.c (info_get_menu_entry_by_label): Arguments
+       changed.
+       * info.c/session.c (entry_in_menu): Arguments changed.
+
 2014-05-02  Gavin Smith  <address@hidden>
 
        * info/info.c (all_files): Get working again, having been broken

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/info/info-utils.c     2014-05-03 10:37:53 UTC (rev 5513)
@@ -184,21 +184,25 @@
 /*                                                                  */
 /* **************************************************************** */
 
-/* Get the menu entry associated with LABEL in REFERENCES.  Return a pointer
-   to the ENTRY if found, or NULL. */
+/* Get the entry associated with LABEL in the menu of NODE.  Return a
+   pointer to the ENTRY if found, or null. */
 REFERENCE *
-info_get_menu_entry_by_label (char *label, REFERENCE **references)
+info_get_menu_entry_by_label (NODE *node, char *label) 
 {
   register int i;
   REFERENCE *entry;
+  REFERENCE **references = node->references;
 
-  for (i = 0; references && (entry = references[i]); i++)
+  if (!references)
+    return 0;
+
+  for (i = 0; entry = references[i]; i++)
     {
       if (REFERENCE_MENU_ITEM != entry->type) continue;
       if (strcmp (label, entry->label) == 0)
         return entry;
     }
-  return NULL;
+  return 0;
 }
 
 /* A utility function for concatenating REFERENCE **.  Returns a new
@@ -360,6 +364,46 @@
   free (temp);
 }
 
+/* If ITER points to an ANSI escape sequence, process it, set PLEN to its
+   length in bytes, and return 1.
+   Otherwise, return 0.
+ */
+int
+ansi_escape (mbi_iterator_t iter, size_t *plen)
+{
+  if (raw_escapes_p && *mbi_cur_ptr (iter) == '\033' && mbi_avail (iter))
+    {
+      mbi_advance (iter);
+      if (*mbi_cur_ptr (iter) == '[' &&  mbi_avail (iter))
+        {
+          ITER_SETBYTES (iter, 1);
+          mbi_advance (iter);
+          if (isdigit (*mbi_cur_ptr (iter)) && mbi_avail (iter))
+            {  
+              ITER_SETBYTES (iter, 1);
+              mbi_advance (iter);
+              if (*mbi_cur_ptr (iter) == 'm')
+                {
+                  *plen = 4;
+                  return 1;
+                }
+              else if (isdigit (*mbi_cur_ptr (iter)) && mbi_avail (iter))
+                {
+                  ITER_SETBYTES (iter, 1);
+                  mbi_advance (iter);
+                  if (*mbi_cur_ptr (iter) == 'm')
+                    {
+                      *plen = 5;
+                      return 1;
+                    }
+                }
+            }
+        }
+    }
+                
+  return 0;
+}
+
 /* String representation of a char returned by printed_representation (). */
 static char *the_rep;
 static size_t the_rep_size;

Modified: trunk/info/info-utils.h
===================================================================
--- trunk/info/info-utils.h     2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/info/info-utils.h     2014-05-03 10:37:53 UTC (rev 5513)
@@ -62,10 +62,9 @@
 
 void scan_node_contents (FILE_BUFFER *fb, NODE **node_ptr);
 
-/* Get the menu entry associated with LABEL in REFERENCES.  Return a
+/* 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 (char *label,
-    REFERENCE **references);
+extern REFERENCE *info_get_menu_entry_by_label (NODE *node, char *label);
 
 /* A utility function for concatenating REFERENCE **.  Returns a new
    REFERENCE ** which is the concatenation of REF1 and REF2.  The REF1
@@ -89,6 +88,12 @@
    start and end of string. */
 void canonicalize_whitespace (char *string);
 
+/* Used with multibyte iterator mbi_iterator_t. */
+#define ITER_SETBYTES(iter,n) ((iter).cur.bytes = n)
+#define ITER_LIMIT(iter) ((iter).limit - (iter).cur.ptr)
+
+extern int ansi_escape (mbi_iterator_t iter, size_t *plen);
+
 /* Return a pointer to a string which is the printed representation
    of CHARACTER if it were printed at HPOS. */
 extern char *printed_representation (const char *str, size_t len,

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/info/info.c   2014-05-03 10:37:53 UTC (rev 5513)
@@ -184,8 +184,7 @@
         {
           dir_node = info_get_node (0, 0, PARSE_NODE_DFLT);
 
-          entry = info_get_menu_entry_by_label ((*argv)[0],
-                                                dir_node->references);
+          entry = info_get_menu_entry_by_label (dir_node, (*argv)[0]);
           if (entry)
             initial_file = info_find_fullpath (entry->filename, 0);
 

Modified: trunk/info/infodoc.c
===================================================================
--- trunk/info/infodoc.c        2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/info/infodoc.c        2014-05-03 10:37:53 UTC (rev 5513)
@@ -374,7 +374,9 @@
   else
     {
       /* We already had the right contents, so simply use them. */
-      node = string_to_node (contents);
+      node = info_create_node ();
+      node->contents = contents;
+      node->nodelen = strlen (contents);
     }
 
   internal_info_help_node = node;

Modified: trunk/info/man.c
===================================================================
--- trunk/info/man.c    2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/info/man.c    2014-05-03 10:37:53 UTC (rev 5513)
@@ -269,6 +269,51 @@
 }
 #endif
 
+void
+clean_manpage (char *manpage)
+{
+  mbi_iterator_t iter;
+  size_t len = strlen (manpage);
+  char *newpage = xmalloc (len + 1);
+  char *np = newpage;
+  int prev_len = 0;
+  
+  for (mbi_init (iter, manpage, len);
+       mbi_avail (iter);
+       mbi_advance (iter))
+    {
+      const char *cur_ptr = mbi_cur_ptr (iter);
+      size_t cur_len = mb_len (mbi_cur (iter));
+
+      if (cur_len == 1)
+       {
+         if (*cur_ptr == '\b' || *cur_ptr == '\f')
+           {
+             if (np >= newpage + prev_len)
+               np -= prev_len;
+           }
+         else if (ansi_escape (iter, &cur_len))
+           {
+             memcpy (np, cur_ptr, cur_len);
+             np += cur_len;
+             ITER_SETBYTES (iter, cur_len);
+           }
+         else if (show_malformed_multibyte_p || mbi_cur (iter).wc_valid)
+           *np++ = *cur_ptr;
+       }
+      else
+       {
+         memcpy (np, cur_ptr, cur_len);
+         np += cur_len;
+       }
+      prev_len = cur_len;
+    }
+  *np = 0;
+  
+  strcpy (manpage, newpage);
+  free (newpage);
+}
+
 static char *
 get_manpage_contents (char *pagename)
 {

Modified: trunk/info/nodemenu.c
===================================================================
--- trunk/info/nodemenu.c       2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/info/nodemenu.c       2014-05-03 10:37:53 UTC (rev 5513)
@@ -313,13 +313,11 @@
   REFERENCE **menu;
 
   node = get_visited_nodes (NULL);
-
-  menu = node->references;
   free (node);
 
   line =
     info_read_completing_in_echo_area (window,
-        _("Select visited node: "), menu);
+        _("Select visited node: "), node->references);
 
   window = active_window;
 
@@ -327,7 +325,6 @@
   if (!line)
     {
       info_abort_key (window, 0, 0);
-      info_free_references (menu);
       return;
     }
 
@@ -336,7 +333,7 @@
       REFERENCE *entry;
 
       /* Find the selected label in the references. */
-      entry = info_get_menu_entry_by_label (line, menu);
+      entry = info_get_menu_entry_by_label (node, line);
 
       if (!entry)
         info_error (_("The reference disappeared! (%s)."), line);
@@ -345,7 +342,6 @@
     }
 
   free (line);
-  info_free_references (menu);
 
   if (!info_error_was_printed)
     window_clear_echo_area ();

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/info/session.c        2014-05-03 10:37:53 UTC (rev 5513)
@@ -2828,7 +2828,7 @@
         }
 
       /* Find the specified menu item. */
-      entry = info_get_menu_entry_by_label (arg, initial_node->references);
+      entry = info_get_menu_entry_by_label (initial_node, arg);
 
       /* If the item wasn't found, search the list sloppily.  Perhaps this
          user typed "buffer" when they really meant "Buffers". */
@@ -2978,17 +2978,21 @@
     window_clear_echo_area ();
 }
 
-/* Search the menu MENU for a (possibly mis-spelled) entry ARG.
+/* 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, REFERENCE **menu, int exact)
+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 (arg, menu);
+  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".  */
@@ -3045,7 +3049,6 @@
     (const char *)0
   };
   NODE *node = NULL;
-  REFERENCE **menu;
   const char **try_node;
 
   /* We keep looking deeper and deeper in the menu structure until
@@ -3056,11 +3059,9 @@
     {
       REFERENCE *entry = NULL;
 
-      menu = initial_node->references;
-
-      /* If no menu item in this node, stop here.  Perhaps this node
+      /* If no menu in this node, stop here.  Perhaps this node
          is the one they need.  */
-      if (!menu)
+      if (!initial_node->references)
         break;
 
       /* Look for node names typical for usage nodes in this menu.  */
@@ -3072,7 +3073,7 @@
           sprintf (nodename, *try_node, program);
           /* The last resort "%s" is dangerous, so we restrict it
              to exact matches here.  */
-          entry = entry_in_menu (nodename, menu,
+          entry = entry_in_menu (nodename, initial_node,
                                  strcmp (*try_node, "%s") == 0);
           free (nodename);
           if (entry)

Modified: trunk/info/window.c
===================================================================
--- trunk/info/window.c 2014-05-02 16:43:26 UTC (rev 5512)
+++ trunk/info/window.c 2014-05-03 10:37:53 UTC (rev 5513)
@@ -1321,19 +1321,6 @@
   return node;
 }
 
-NODE *
-string_to_node (char *contents)
-{
-  NODE *node;
-
-  node = info_create_node ();
-
-  /* Make sure that this buffer ends with a newline. */
-  node->nodelen = 1 + strlen (contents);
-  node->contents = contents;
-  return node;
-}
-
 /* Convert the contents of the message buffer to a node. */
 NODE *
 message_buffer_to_node (void)
@@ -1410,49 +1397,6 @@
 }
 
 
-#define ITER_SETBYTES(iter,n) ((iter).cur.bytes = n)
-#define ITER_LIMIT(iter) ((iter).limit - (iter).cur.ptr)
-
-/* If ITER points to an ANSI escape sequence, process it, set PLEN to its
-   length in bytes, and return 1.
-   Otherwise, return 0.
- */
-static int
-ansi_escape (mbi_iterator_t iter, size_t *plen)
-{
-  if (raw_escapes_p && *mbi_cur_ptr (iter) == '\033' && mbi_avail (iter))
-    {
-      mbi_advance (iter);
-      if (*mbi_cur_ptr (iter) == '[' &&  mbi_avail (iter))
-       {
-         ITER_SETBYTES (iter, 1);
-         mbi_advance (iter);
-         if (isdigit (*mbi_cur_ptr (iter)) && mbi_avail (iter))
-           {   
-             ITER_SETBYTES (iter, 1);
-             mbi_advance (iter);
-             if (*mbi_cur_ptr (iter) == 'm')
-               {
-                 *plen = 4;
-                 return 1;
-               }
-             else if (isdigit (*mbi_cur_ptr (iter)) && mbi_avail (iter))
-               {
-                 ITER_SETBYTES (iter, 1);
-                 mbi_advance (iter);
-                 if (*mbi_cur_ptr (iter) == 'm')
-                   {
-                     *plen = 5;
-                     return 1;
-                   }
-               }
-           }
-       }
-    }
-               
-  return 0;
-}
-
 /* If ITER points to an info tag, process it, set PLEN to its
    length in bytes, and return 1.
    Otherwise, return 0.
@@ -1716,51 +1660,6 @@
   return line_index;
 }
 
-void
-clean_manpage (char *manpage)
-{
-  mbi_iterator_t iter;
-  size_t len = strlen (manpage);
-  char *newpage = xmalloc (len + 1);
-  char *np = newpage;
-  int prev_len = 0;
-  
-  for (mbi_init (iter, manpage, len);
-       mbi_avail (iter);
-       mbi_advance (iter))
-    {
-      const char *cur_ptr = mbi_cur_ptr (iter);
-      size_t cur_len = mb_len (mbi_cur (iter));
-
-      if (cur_len == 1)
-       {
-         if (*cur_ptr == '\b' || *cur_ptr == '\f')
-           {
-             if (np >= newpage + prev_len)
-               np -= prev_len;
-           }
-         else if (ansi_escape (iter, &cur_len))
-           {
-             memcpy (np, cur_ptr, cur_len);
-             np += cur_len;
-             ITER_SETBYTES (iter, cur_len);
-           }
-         else if (show_malformed_multibyte_p || mbi_cur (iter).wc_valid)
-           *np++ = *cur_ptr;
-       }
-      else
-       {
-         memcpy (np, cur_ptr, cur_len);
-         np += cur_len;
-       }
-      prev_len = cur_len;
-    }
-  *np = 0;
-  
-  strcpy (manpage, newpage);
-  free (newpage);
-}
-
 static void
 line_map_init (LINE_MAP *map, NODE *node, int line)
 {




reply via email to

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