texinfo-commits
[Top][All Lists]
Advanced

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

[5561] preprocess-nodes appearance tweaks


From: Gavin D. Smith
Subject: [5561] preprocess-nodes appearance tweaks
Date: Tue, 13 May 2014 05:47:49 +0000

Revision: 5561
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5561
Author:   gavin
Date:     2014-05-13 05:47:48 +0000 (Tue, 13 May 2014)
Log Message:
-----------
preprocess-nodes appearance tweaks

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/info-utils.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-12 14:51:49 UTC (rev 5560)
+++ trunk/ChangeLog     2014-05-13 05:47:48 UTC (rev 5561)
@@ -1,3 +1,14 @@
+2014-05-13  Gavin Smith  <address@hidden>
+
+       * info/info-utils.c (scan_reference_label) Declared static.
+       (scan_reference_target): Argument added.  Declared static.
+       [preprocess-nodes=On]: Add space before output "(" if not at
+       start of line.  Hide full stop terminating reference if it
+       looks like (*note Label:(file)node.)  Caller updated.
+       (safe_string_index): Utility function.
+       (avoid_see_see): New function.
+       (scan_node_contents): Call avoid_see_see.
+
 2014-05-11  Gavin Smith  <address@hidden>
 
        * info/info-utils.c (info_parse_node): Don't include terminating

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2014-05-12 14:51:49 UTC (rev 5560)
+++ trunk/info/info-utils.c     2014-05-13 05:47:48 UTC (rev 5561)
@@ -1077,7 +1077,7 @@
 }
 
 /* Output reference label and create REFERENCE object. */
-REFERENCE *
+static REFERENCE *
 scan_reference_label (char *label, long label_len, long start_of_reference,
                       int found_menu_entry)
 {
@@ -1162,8 +1162,9 @@
   return entry;
 }
 
-void
-scan_reference_target (REFERENCE *entry, int found_menu_entry, int in_index)
+static void
+scan_reference_target (REFERENCE *entry, int found_menu_entry,
+                       int in_index, int in_parentheses)
 {
   /* If this reference entry continues with another ':' then the reference is
      within the same file, and the nodename is the same as the label. */
@@ -1207,7 +1208,9 @@
           char saved_char;
           char *nl_off;
 
-          copy_input_to_output (skip_whitespace_and_newlines (inptr));
+          /* Skip any following spaces after the ":". */
+          skip_input (skip_whitespace (inptr));
+
           length = info_parse_node (inptr, PARSE_NODE_SKIP_NEWLINES);
 
           /* Check if there is a newline in the target. */
@@ -1218,6 +1221,8 @@
           
           if (info_parsed_filename)
             {
+              if (inptr[-1] != '\n')
+                write_extra_bytes_to_output (" ", 1);
               write_extra_bytes_to_output ("(", 1);
               write_extra_bytes_to_output (info_parsed_filename,
                 strlen (info_parsed_filename));
@@ -1225,17 +1230,19 @@
                                            strlen (" manual)"));
             }
 
-          /* A full stop terminating a reference should be output,
-             but a comma is usually? not. */
-          if (inptr[length - 1] == '.')
-            skip_input (length - 1);
+          /* Output terminating punctuation, unless we are in a reference
+             like (*note Label:(file)node.). */
+          if (!in_parentheses)
+            skip_input (length);
           else
-            skip_input (length);
+            skip_input (length + 1);
 
           /* Copy any terminating punctuation before the optional newline. */
           copy_input_to_output (strspn (inptr, ".),"));
 
-          if (nl_off)
+          /* Output a newline if one is needed.  Don't do it at the end
+             a paragraph. */
+          if (nl_off && *inptr != '\n')
             { 
               int i, j = skip_whitespace (nl_off + 1);
               write_extra_bytes_to_output ("\n", 1);
@@ -1271,6 +1278,54 @@
     }
 }
 
+/* BASE is earlier in a block of allocated memory than PTR, and the block
+   extends until at least BASE + LEN - 1.  Return PTR[INDEX], unless this
+   could be outside the allocated block, in which case return 0. */
+static char
+safe_string_index (char *ptr, long index, char *base, long len)
+{
+  long offset = ptr - base;
+
+  if (   offset + index < 0
+      || offset + index >= len)
+    return 0;
+
+  return ptr[index];
+}
+
+/* Check if preceding word is a word like "see". BASE points before PTR in
+   a block of allocated memory. */
+static int
+avoid_see_see (char *ptr, char *base)
+{
+  /* TODO: Only do this for English-language files. */
+  static char *words_like_see[] = {
+    "see", "See", "In", "in", "of"
+  };
+  int i;
+
+  if (ptr == base)
+    return 0;
+
+  /* Skip past whitespace, and then go to beginning of preceding word. */
+  ptr--;
+  while (ptr > base && (*ptr == ' ' || *ptr == '\n' || *ptr == '\t'))
+    ptr--;
+
+  while (ptr > base && !(*ptr == ' ' || *ptr == '\n' || *ptr == '\t'))
+    ptr--;
+
+  ptr++;
+
+  /* Check if it is in our list. */
+  for (i = 0; i < sizeof (words_like_see) / sizeof (char *); i++)
+    {
+      if (!strncmp (words_like_see[i], ptr, strlen (words_like_see[i])))
+        return 1;
+    }
+  return 0;
+}
+
 /* Scan (*NODE_PTR)->contents and record location and contents of
    cross-references and menu items.  Convert character encoding of
    node contents to that of the user if the two are known to be
@@ -1350,6 +1405,7 @@
     {
       long label_len;
       char *label = 0;
+      int in_parentheses = 0;
 
       /* Save offset of "*" starting link. When preprocess_nodes is Off,
          we position the cursor on the * when moving between references. */
@@ -1388,6 +1444,8 @@
         }
       else
         {
+          int previous_word_is_like_see = 0;
+
           found_menu_entry = 0;
           start_of_reference = position;
 
@@ -1404,9 +1462,18 @@
           if (match[1] == 'N')
             write_extra_bytes_to_output ("See", 3);
           else
-            write_extra_bytes_to_output ("see", 3);
+            {
+              previous_word_is_like_see = avoid_see_see (inptr, s.buffer);
 
+              if (!previous_word_is_like_see)
+                write_extra_bytes_to_output ("see", 3);
+              if (safe_string_index (inptr, -1, s.buffer, s.end) == '(')
+                in_parentheses = 1;
+            }
+
           skip_input (strlen ("*Note"));
+          if (previous_word_is_like_see)
+            skip_input (skip_whitespace (inptr));
         }
 
       /* Copy any white space before label. */
@@ -1438,7 +1505,7 @@
       free (label);
 
       /* Get target of reference and update entry. */
-      scan_reference_target (entry, found_menu_entry, in_index);
+      scan_reference_target (entry, found_menu_entry, in_index, 
in_parentheses);
 
       add_pointer_to_array (entry, refs_index, refs, refs_slots, 50);
 




reply via email to

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