texinfo-commits
[Top][All Lists]
Advanced

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

[6214] parsetexi index merging


From: Gavin D. Smith
Subject: [6214] parsetexi index merging
Date: Thu, 09 Apr 2015 17:09:31 +0000

Revision: 6214
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6214
Author:   gavin
Date:     2015-04-09 17:09:17 +0000 (Thu, 09 Apr 2015)
Log Message:
-----------
parsetexi index merging

Modified Paths:
--------------
    trunk/parsetexi/ChangeLog
    trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
    trunk/parsetexi/api.c
    trunk/parsetexi/end_line.c
    trunk/parsetexi/handle_commands.c
    trunk/parsetexi/indices.c
    trunk/parsetexi/indices.h
    trunk/parsetexi/parser.c
    trunk/parsetexi/tree_types.h

Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog   2015-04-09 14:05:56 UTC (rev 6213)
+++ trunk/parsetexi/ChangeLog   2015-04-09 17:09:17 UTC (rev 6214)
@@ -1,3 +1,10 @@
+2015-04-09  Gavin Smith  <address@hidden>
+
+       * end_line.c (parse_line_command_args) <CM_synindex>: Record
+       index synonym.
+       * api.c (build_single_index_data): Create "contained_indices" 
+       and "merged_in".
+
 2015-03-23  Gavin Smith  <address@hidden>
 
        * tree_types.h (enum extra_type): Add extra_def_args.

Modified: trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
===================================================================
--- trunk/parsetexi/Parsetexi/lib/Parsetexi.pm  2015-04-09 14:05:56 UTC (rev 
6213)
+++ trunk/parsetexi/Parsetexi/lib/Parsetexi.pm  2015-04-09 17:09:17 UTC (rev 
6214)
@@ -298,6 +298,12 @@
   $self->{'labels'} = $LABELS;
 
   $self->{'index_names'} = $INDEX_NAMES;
+  #for my $index (keys %$INDEX_NAMES) {
+  #  if ($INDEX_NAMES->{$index}->{'merged_in'}) {
+  #    $self->{'merged_indices'}-> {$index}
+  #      = $INDEX_NAMES->{$index}->{'merged_in'};
+  #  }
+  #}
 
   # Copy the errors into the error list in Texinfo::Report.
   # TODO: Could we just access the error list directly instead of going

Modified: trunk/parsetexi/api.c
===================================================================
--- trunk/parsetexi/api.c       2015-04-09 14:05:56 UTC (rev 6213)
+++ trunk/parsetexi/api.c       2015-04-09 17:09:17 UTC (rev 6214)
@@ -445,22 +445,30 @@
   return label_hash;
 }
 
-/* Return hash value for a single entry in $self->{'index_names'}, containing
-   information about a single index. */
-static HV *
+/* Ensure that I->hv is a hash value for a single entry in 
+   $self->{'index_names'}, containing information about a single index. */
+static void
 build_single_index_data (INDEX *i)
 {
 #define STORE(key, value) hv_store (hv, key, strlen (key), value, 0)
 
   HV *hv;
   AV *prefix_array;
-  HV *contained;
   AV *entries;
   int j;
 
   dTHX;
 
-  hv = newHV ();
+  if (!i->hv)
+    {
+      hv = newHV ();
+      i->hv = (void *) hv;
+    }
+  else
+    {
+      hv = (HV *) i->hv;
+    }
+
   STORE("name", newSVpv (i->name, 0));
   STORE("in_code", newSVpv ("0", 1));
 
@@ -470,10 +478,40 @@
   av_push (prefix_array, newSVpv (i->name, 0));
   STORE("prefix", newRV_inc ((SV *) prefix_array));
 
-  contained = newHV ();
-  hv_store (contained, i->name, strlen (i->name), newSViv(1), 0);
-  STORE("contained_indices", newRV_inc ((SV *) contained));
+  if (i->merged_in)
+    {
+      /* This index is merged in another one. */
+      INDEX *ultimate = ultimate_index (i);
 
+      if (!ultimate->hv)
+        {
+          ultimate->hv = (void *) newHV ();
+          ultimate->contained_hv = (void *) newHV ();
+          hv_store (ultimate->hv,
+                    "contained_indices",
+                    strlen ("contained_indices"),
+                    newRV_inc ((SV *)(HV *) ultimate->contained_hv),
+                    0);
+        }
+
+      hv_store (ultimate->contained_hv, i->name, strlen (i->name),
+                newSViv (1), 0);
+
+      STORE("merged_in", newSVpv (ultimate->name, 0));
+
+      /* See also code in end_line.c (parse_line_command_args) <CM_synindex>.
+         FIXME: Do we need to keep the original values of contained_indices?
+         I don't think so. */
+    }
+
+  if (!i->contained_hv)
+    {
+      i->contained_hv = newHV ();
+      STORE("contained_indices", newRV_inc ((SV *)(HV *) i->contained_hv));
+    }
+  /* Record that this index "contains itself". */
+  hv_store (i->contained_hv, i->name, strlen (i->name), newSViv(1), 0);
+
   entries = newAV ();
   STORE("index_entries", newRV_inc ((SV *) entries));
 #undef STORE
@@ -533,8 +571,6 @@
       }
 #undef STORE2
     }
-
-  return hv;
 }
 
 /* Return object to be used as $self->{'index_names'} in the perl code.
@@ -553,7 +589,8 @@
   for (i = index_names; (idx = *i); i++)
     {
       HV *hv2;
-      hv2 = build_single_index_data (idx);
+      build_single_index_data (idx);
+      hv2 = idx->hv;
       hv_store (hv, idx->name, strlen (idx->name), newRV_inc ((SV *)hv2), 0);
     }
 

Modified: trunk/parsetexi/end_line.c
===================================================================
--- trunk/parsetexi/end_line.c  2015-04-09 14:05:56 UTC (rev 6213)
+++ trunk/parsetexi/end_line.c  2015-04-09 17:09:17 UTC (rev 6214)
@@ -371,10 +371,11 @@
         break;
       }
     case CM_synindex:
-    case CM_syncodeindex:
+    case CM_syncodeindex: // 5595
       {
         /* synindex FROM TO */
         char *from = 0, *to = 0;
+        INDEX *from_index, *to_index;
         char *p = line;
 
         if (!isalnum (*p))
@@ -391,12 +392,39 @@
         if (!to)
           goto synindex_invalid;
 
-        ADD_ARG(from); free (from);
-        ADD_ARG(to); free (to);
+        ADD_ARG(from);
+        ADD_ARG(to);
 
-        /* TODO: Rememer the synonym. */
+        from_index = index_by_name (from);
+        to_index = index_by_name (to);
+        if (!from_index)
+          line_errorf ("unknown source index in @%s: %s", command_name(cmd),
+                       from);
+        if (!to_index)
+          line_errorf ("unknown source index in @%s: %s", command_name(cmd),
+                       to);
+
+        if (from_index && to_index) // 5606
+          {
+            INDEX *current_to = to_index;
+            /* Find ultimate index this merges to. */
+            current_to = ultimate_index (current_to);
+
+            if (current_to != from_index)
+              {
+                /* TODO: unless "ignore_global_commands" */
+                from_index->merged_in = current_to;
+              }
+            else
+              line_warnf ("@%s leads to a merging of %s in itself, ignoring",
+                          command_name(cmd), from);
+          }
+
+        free (from);
+        free (to);
+
         break;
-      synindex_invalid:
+      synindex_invalid: // 5638
         line_errorf ("bad argument to @%s: %s",
                      command_name(cmd), line);
         free (from); free (to);

Modified: trunk/parsetexi/handle_commands.c
===================================================================
--- trunk/parsetexi/handle_commands.c   2015-04-09 14:05:56 UTC (rev 6213)
+++ trunk/parsetexi/handle_commands.c   2015-04-09 17:09:17 UTC (rev 6214)
@@ -446,7 +446,7 @@
       // open a new element (which we shall later remove).
 
       debug ("CONDITIONAL %s", command_name(cmd));
-      if (cmd != CM_ifnotinfo) // TODO
+      if (cmd != CM_ifnotinfo) // && cmd != CM_iftex) // TODO
         push_conditional_stack (cmd); // Not ignored
       else
         {

Modified: trunk/parsetexi/indices.c
===================================================================
--- trunk/parsetexi/indices.c   2015-04-09 14:05:56 UTC (rev 6213)
+++ trunk/parsetexi/indices.c   2015-04-09 17:09:17 UTC (rev 6214)
@@ -96,7 +96,7 @@
 }
 
 /* NAME is the name of an index, e.g. "cp" */
-static INDEX *
+INDEX *
 index_by_name (char *name)
 {
   int i;
@@ -262,3 +262,12 @@
   add_extra_key_index_entry (current, "index_entry", ier);
 
 }
+
+
+INDEX *
+ultimate_index (INDEX *index)
+{
+  while (index->merged_in)
+    index = index->merged_in;
+  return index;
+}

Modified: trunk/parsetexi/indices.h
===================================================================
--- trunk/parsetexi/indices.h   2015-04-09 14:05:56 UTC (rev 6213)
+++ trunk/parsetexi/indices.h   2015-04-09 17:09:17 UTC (rev 6214)
@@ -1,7 +1,9 @@
 extern INDEX **index_names;
 
+INDEX *index_by_name (char *name);
 void add_index (char *name, int in_code);
 INDEX *index_of_command (enum command_id cmd);
 void enter_index_entry (enum command_id index_type_command,
                    enum command_id index_at_command, ELEMENT *current,
                    ELEMENT *content);
+INDEX *ultimate_index (INDEX *index);

Modified: trunk/parsetexi/parser.c
===================================================================
--- trunk/parsetexi/parser.c    2015-04-09 14:05:56 UTC (rev 6213)
+++ trunk/parsetexi/parser.c    2015-04-09 17:09:17 UTC (rev 6214)
@@ -781,7 +781,7 @@
             {
               cmd = lookup_command (command);
               if (!cmd)
-                line_errorf ("unknown command `%s'", command); // 4877
+                ;//line_errorf ("unknown command `%s'", command); // 4877
             }
           free (command);
         }

Modified: trunk/parsetexi/tree_types.h
===================================================================
--- trunk/parsetexi/tree_types.h        2015-04-09 14:05:56 UTC (rev 6213)
+++ trunk/parsetexi/tree_types.h        2015-04-09 17:09:17 UTC (rev 6214)
@@ -120,14 +120,20 @@
     enum command_id region;
 } INDEX_ENTRY;
 
-typedef struct {
+typedef struct INDEX {
     char *name;
     char *prefix;
     // int in_code;
 
+    struct INDEX *merged_in; /* Index this index is merged into, if any. */
+
     INDEX_ENTRY *index_entries;
     size_t index_number;
     size_t index_space;
+
+    /********* Used when building Perl hash value ********************/
+    void *hv;
+    void *contained_hv;
 } INDEX;
 
 /* Used when dumping to a text stream only.  A reference to an




reply via email to

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