texinfo-commits
[Top][All Lists]
Advanced

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

[5980] parsetexi update


From: Gavin D. Smith
Subject: [5980] parsetexi update
Date: Sat, 20 Dec 2014 18:26:44 +0000

Revision: 5980
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5980
Author:   gavin
Date:     2014-12-20 18:26:42 +0000 (Sat, 20 Dec 2014)
Log Message:
-----------
parsetexi update

Modified Paths:
--------------
    trunk/parsetexi/ChangeLog
    trunk/parsetexi/Makefile.am
    trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
    trunk/parsetexi/convert.c
    trunk/parsetexi/dump_perl.c
    trunk/parsetexi/end_line.c
    trunk/parsetexi/labels.c

Added Paths:
-----------
    trunk/parsetexi/convert.h
    trunk/parsetexi/labels.h
    trunk/parsetexi/test-files/menus.texi

Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog   2014-12-19 23:28:23 UTC (rev 5979)
+++ trunk/parsetexi/ChangeLog   2014-12-20 18:26:42 UTC (rev 5980)
@@ -1,3 +1,15 @@
+2014-12-20  Gavin Smith  <address@hidden>
+
+       * labels.c: New file.
+
+       * end_line.c (end_line) <@node>: Call register_label.
+       * dump_perl.c (dump_tree_to_perl): Dump information about 
+       labels.
+       * Parsetexi/lib/Parsetexi.pm: Set 'labels_information' from 
+       dump.
+
+       * convert.c (convert_to_normalized): Stub added.
+
 2014-12-19  Gavin Smith  <address@hidden>
 
        * element_types.txt: Add menu_entry and menu_star types.

Modified: trunk/parsetexi/Makefile.am
===================================================================
--- trunk/parsetexi/Makefile.am 2014-12-19 23:28:23 UTC (rev 5979)
+++ trunk/parsetexi/Makefile.am 2014-12-20 18:26:42 UTC (rev 5980)
@@ -14,7 +14,7 @@
                  text.c text.h \
                  context_stack.c context_stack.h \
                  debug.c \
-                 convert.c \
+                 convert.c convert.h \
                  end_line.c \
                  separator.c \
                  multitable.c \
@@ -24,7 +24,8 @@
                  def.c def.h \
                  dump_perl.c \
                  extra.c \
-                 menus.c
+                 menus.c \
+                 labels.c
 
 parsetexi_SOURCES=$(libparsetexi_a_SOURCES) main.c
 

Modified: trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
===================================================================
--- trunk/parsetexi/Parsetexi/lib/Parsetexi.pm  2014-12-19 23:28:23 UTC (rev 
5979)
+++ trunk/parsetexi/Parsetexi/lib/Parsetexi.pm  2014-12-20 18:26:42 UTC (rev 
5980)
@@ -271,22 +271,26 @@
   # to Parsetexi.pm to get the tree without doing this.
   $tree_stream = qx(./parsetexi $file_name 2>/dev/null);
 
-  my $VAR1;
+  my ($TREE, $LABELS);
   #print "Reading tree...\n";
   eval $tree_stream;
   #print "Read tree.\n";
          
   #print "Adjusting tree...\n";
-  _add_parents ($VAR1);
-  _complete_node_list ($self, $VAR1);
+  _add_parents ($TREE);
+  _complete_node_list ($self, $TREE);
   #print "Adjusted tree.\n";
 
+  $self->{'info'}->{'input_file_name'} = $file_name;
+
+  $self->{'labels'} = $LABELS;
+
   #$Data::Dumper::Purity = 1;
   #$Data::Dumper::Indent = 1;
-  #my $bar = Data::Dumper->Dump([$VAR1], ['$VAR1']);
+  #my $bar = Data::Dumper->Dump([$TREE], ['$TREE']);
   #print $bar;
 
-  return $VAR1;
+  return $TREE;
 }
 
 # Public interfaces of Texinfo::Parser (starting line 942)

Modified: trunk/parsetexi/convert.c
===================================================================
--- trunk/parsetexi/convert.c   2014-12-19 23:28:23 UTC (rev 5979)
+++ trunk/parsetexi/convert.c   2014-12-20 18:26:42 UTC (rev 5980)
@@ -18,3 +18,18 @@
     }
   return "bar";
 }
+
+/* Stub for Texinfo::Convert::NodeNameNormalization::normalize_node. */
+char *
+convert_to_normalized (ELEMENT *label)
+{
+  int i;
+
+  /* Return text of the first contents child that has text. */
+  for (i = 0; i < label->contents.number; i++)
+    {
+      if (label->contents.list[i]->text.end > 0)
+        return label->contents.list[i]->text.text;
+    }
+  return 0;
+}

Added: trunk/parsetexi/convert.h
===================================================================
--- trunk/parsetexi/convert.h                           (rev 0)
+++ trunk/parsetexi/convert.h   2014-12-20 18:26:42 UTC (rev 5980)
@@ -0,0 +1,2 @@
+char *text_convert (ELEMENT *e);
+char *convert_to_normalized (ELEMENT *label);

Modified: trunk/parsetexi/dump_perl.c
===================================================================
--- trunk/parsetexi/dump_perl.c 2014-12-19 23:28:23 UTC (rev 5979)
+++ trunk/parsetexi/dump_perl.c 2014-12-20 18:26:42 UTC (rev 5980)
@@ -4,10 +4,12 @@
 #include "parser.h"
 #include "input.h"
 #include "text.h"
+#include "labels.h"
 
 #define element_type_name(e) element_type_names[(e)->type]
 
-#define TREE_ROOT_VAR "$VAR1"
+#define TREE_ROOT_VAR "$TREE"
+#define LABELS_VAR "$LABELS"
 
 int indent = 0;
 
@@ -307,12 +309,34 @@
 }
 
 void
+dump_labels_information (void)
+{
+  int i;
+
+  text_append (&fixup_dump, "\n" LABELS_VAR " = {\n");
+
+  for (i = 0; i < labels_number; i++)
+    {
+      text_printf (&fixup_dump, "'%s' => ", labels_list[i].label);
+      dump_route_to_element (labels_list[i].target);
+      text_append (&fixup_dump, ",\n");
+    }
+
+  text_append (&fixup_dump, "};\n");
+}
+
+void
 dump_tree_to_perl (ELEMENT *root)
 {
   text_init (&fixup_dump);
   printf (TREE_ROOT_VAR " = ");
   dump_element (root);
   printf (";\n");
+
+  /* All the elements in the tree have routing information now. */
+
+  dump_labels_information ();
+
   if (fixup_dump.end > 0)
     printf ("%s", fixup_dump.text);
 }

Modified: trunk/parsetexi/end_line.c
===================================================================
--- trunk/parsetexi/end_line.c  2014-12-19 23:28:23 UTC (rev 5979)
+++ trunk/parsetexi/end_line.c  2014-12-20 18:26:42 UTC (rev 5980)
@@ -5,10 +5,9 @@
 #include "tree.h"
 #include "text.h"
 #include "input.h"
+#include "convert.h"
+#include "labels.h"
 
-/* In convert.c */
-char *text_convert (ELEMENT *e);
-
 /* 2610 */
 /* Actions to be taken when a whole line of input has been processed */
 ELEMENT *
@@ -360,7 +359,7 @@
 
           /* This sets 'node_content' and 'normalized' on the node, among
              other things (which were already set in parse_node_manual). */
-          //register_label (current, current->args.list[0]);
+          register_label (current, arg);
 
           current_node = current;
         }

Modified: trunk/parsetexi/labels.c
===================================================================
--- trunk/parsetexi/labels.c    2014-12-19 23:28:23 UTC (rev 5979)
+++ trunk/parsetexi/labels.c    2014-12-20 18:26:42 UTC (rev 5980)
@@ -1,5 +1,25 @@
-void
-register_label (ELEMENT *current, ELEMENT *label)
+#include "parser.h"
+#include "convert.h"
+#include "labels.h"
+
+/* Array of recorded labels. */
+/* If looking through this array turns out to be slow, we might have to replace
+   it with some kind of hash table implementation. */
+LABEL *labels_list = 0;
+size_t labels_number = 0;
+size_t labels_space = 0;
+
+void register_label (ELEMENT *current, ELEMENT *label)
 {
-  /* Texinfo::Convert::Texinfo::convert is used here. */
+  if (labels_number == labels_space)
+    {
+      labels_space += 1;
+      labels_space *= 1.5;
+      labels_list = realloc (labels_list, labels_space * sizeof (LABEL));
+      if (!labels_list)
+        abort ();
+    }
+
+  labels_list[labels_number].label = convert_to_normalized (label);
+  labels_list[labels_number++].target = current;
 }

Added: trunk/parsetexi/labels.h
===================================================================
--- trunk/parsetexi/labels.h                            (rev 0)
+++ trunk/parsetexi/labels.h    2014-12-20 18:26:42 UTC (rev 5980)
@@ -0,0 +1,17 @@
+/* Information about a possible target of a cross-reference, often a node. */
+typedef struct {
+    /* The normalized node name for HTML output of the target, used as a key.  
+       Using the normalized node name as a key is a way to avoid clashes if 
+       different node names containing @-commands end up as the same. */
+    char *label;
+
+    /* Pointer to the element for the command defining this label, usually a
+       node element.  FIXME: I'm not sure if we actualy need to get to the
+       target - much of the use of the labels_information is to check that 
+       references are to real places. */
+    ELEMENT *target;
+} LABEL;
+
+extern LABEL *labels_list;
+extern size_t labels_number;
+void register_label (ELEMENT *current, ELEMENT *label);

Added: trunk/parsetexi/test-files/menus.texi
===================================================================
--- trunk/parsetexi/test-files/menus.texi                               (rev 0)
+++ trunk/parsetexi/test-files/menus.texi       2014-12-20 18:26:42 UTC (rev 
5980)
@@ -0,0 +1,27 @@
address@hidden Top
address@hidden GNU Sample
+
+This manual is for GNU Sample
+
address@hidden
+* First Chapter::    The first chapter is the
+                      only chapter in this sample.
+* Index::            Complete index.
address@hidden menu
+
+
address@hidden First Chapter
address@hidden First Chapter
+
+This is the first chapter.
+
+Here is a numbered list.
+
address@hidden Index
address@hidden Index
+
+
+printindex
+
address@hidden
+




reply via email to

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