[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[6133] parsetexi build index data
From: |
Gavin D. Smith |
Subject: |
[6133] parsetexi build index data |
Date: |
Wed, 18 Feb 2015 18:13:11 +0000 |
Revision: 6133
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6133
Author: gavin
Date: 2015-02-18 18:13:09 +0000 (Wed, 18 Feb 2015)
Log Message:
-----------
parsetexi build index data
Modified Paths:
--------------
trunk/parsetexi/ChangeLog
trunk/parsetexi/Parsetexi/Parsetexi.xs
trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
trunk/parsetexi/api.c
trunk/parsetexi/makeinfo
Added Paths:
-----------
trunk/parsetexi/test-files/xref.texi
Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog 2015-02-18 00:07:53 UTC (rev 6132)
+++ trunk/parsetexi/ChangeLog 2015-02-18 18:13:09 UTC (rev 6133)
@@ -1,3 +1,7 @@
+2015-02-18 Gavin Smith <address@hidden>
+
+ * api.c (build_index_data): New function.
+
2015-02-16 Gavin Smith <address@hidden>
* api.c (build_texinfo_tree, build_label_list): New functions,
Modified: trunk/parsetexi/Parsetexi/Parsetexi.xs
===================================================================
--- trunk/parsetexi/Parsetexi/Parsetexi.xs 2015-02-18 00:07:53 UTC (rev
6132)
+++ trunk/parsetexi/Parsetexi/Parsetexi.xs 2015-02-18 18:13:09 UTC (rev
6133)
@@ -12,6 +12,7 @@
HV *build_texinfo_tree (void);
HV *build_label_list (void);
+HV *build_index_data (void);
MODULE = Parsetexi PACKAGE = Parsetexi
@@ -73,3 +74,7 @@
HV *
build_label_list ()
+
+HV *
+build_index_data ()
+
Modified: trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
===================================================================
--- trunk/parsetexi/Parsetexi/lib/Parsetexi.pm 2015-02-18 00:07:53 UTC (rev
6132)
+++ trunk/parsetexi/Parsetexi/lib/Parsetexi.pm 2015-02-18 18:13:09 UTC (rev
6133)
@@ -238,7 +238,7 @@
#print "Getting tree...\n";
my ($TREE, $LABELS, $INDEX_NAMES, $ERRORS);
- if (0) {
+ if (1) {
# This is our third way of passing the data: construct it using
# Perl api directly.
print "Parsing file...\n";
@@ -247,13 +247,13 @@
$TREE = build_texinfo_tree ();
print "Got tree...\n";
#print Texinfo::Parser::_print_tree ($TREE);
- print ref($TREE->{'contents'}[1]{'extra'}{'node_content'}), "\n";
$LABELS = build_label_list ();
# TODO: Get $INDEX_NAMES as well
+ $INDEX_NAMES = build_index_data ();
- } elsif (1) {
+ } elsif (0) {
# $| = 1; # Flush after each print
print "Parsing file...\n";
parse_file ($file_name);
@@ -363,52 +363,3 @@
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
-
-=head1 NAME
-
-Parsetexi - Perl extension for blah blah blah
-
-=head1 SYNOPSIS
-
- use Parsetexi;
- blah blah blah
-
-=head1 DESCRIPTION
-
-Stub documentation for Parsetexi, created by h2xs. It looks like the
-author of the extension was negligent enough to leave the stub
-unedited.
-
-Blah blah blah.
-
-=head2 EXPORT
-
-None by default.
-
-
-
-=head1 SEE ALSO
-
-Mention other useful documentation such as the documentation of
-related modules or operating system documentation (such as man pages
-in UNIX), or any relevant external documentation such as RFCs or
-standards.
-
-If you have a mailing list set up for your module, mention it here.
-
-If you have a web site set up for your module, mention it here.
-
-=head1 AUTHOR
-
-A. U. Thor, E<lt>address@hidden<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright (C) 2014 by A. U. Thor
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself, either Perl version 5.18.1 or,
-at your option, any later version of Perl 5 you may have available.
-
-
-=cut
Modified: trunk/parsetexi/api.c
===================================================================
--- trunk/parsetexi/api.c 2015-02-18 00:07:53 UTC (rev 6132)
+++ trunk/parsetexi/api.c 2015-02-18 18:13:09 UTC (rev 6133)
@@ -30,6 +30,7 @@
#include "parser.h"
#include "input.h"
#include "labels.h"
+#include "indices.h"
ELEMENT *Root;
@@ -242,23 +243,7 @@
case extra_element_contents:
{
int j;
- fprintf (stderr, "extra element key is %s\n", key);
STORE(build_perl_array (&f->contents));
-#if 0
- AV *av;
- av = newAV ();
- STORE(newRV_inc ((SV *)av));
- for (j = 0; j < f->contents.number; j++)
- {
- /* TODO: Check if any of the elements in the array
- are not in the main tree - if so, we will have to
- create them. */
- ELEMENT *g = f->contents.list[j];
- if (!g->hv)
- g->hv = newHV ();
- av_push (av, f->hv);
- }
-#endif
break;
}
case extra_element_contents_array:
@@ -287,7 +272,7 @@
create them. */
if (!h->hv)
h->hv = newHV ();
- av_push (av2, g->hv);
+ av_push (av2, newRV_inc ((SV*)h->hv));
}
}
break;
@@ -342,6 +327,7 @@
entry. Unlike the other keys, the value is not in the
main parse tree, but in the indices_information. It would
be much nicer if we could get rid of the need for this key. */
+ /* Could we set this afterwards in build_index_data? */
break;
default:
abort ();
@@ -385,3 +371,114 @@
return label_hash;
}
+/* Return hash value for a single entry in $self->{'index_names'}, containing
+ information about a single index. */
+static HV *
+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 ();
+ STORE("name", newSVpv (i->name, 0));
+ STORE("in_code", newSVpv ("0", 1));
+
+ /* e.g. 'prefix' => ['k', 'ky'] */
+ prefix_array = newAV ();
+ av_push (prefix_array, newSVpv (i->name, 1));
+ 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));
+
+ entries = newAV ();
+ STORE("index_entries", newRV_inc ((SV *) entries));
+#undef STORE
+
+ for (j = 0; j < i->index_number; j++)
+ {
+#define STORE2(key, value) hv_store (entry, key, strlen (key), value, 0)
+ HV *entry;
+ INDEX_ENTRY *e;
+
+ e = &i->index_entries[j];
+ entry = newHV ();
+ av_push (entries, newRV_inc ((SV *)entry));
+
+ STORE2("index_name", newSVpv (i->name, 0));
+ STORE2("index_prefix", newSVpv (i->name, 1));
+ STORE2("index_at_command",
+ newSVpv (command_data(e->index_at_command).cmdname, 0));
+ STORE2("index_type_command",
+ newSVpv (command_data(e->index_type_command).cmdname, 0));
+ STORE2("command",
+ newRV_inc ((SV *)e->command->hv));
+ STORE2("number", newSViv (j));
+ if (e->content)
+ {
+ SV **contents_array;
+ contents_array = hv_fetch (e->content->hv,
+ "contents", strlen ("contents"), 0);
+
+ /* Copy the reference to the array. */
+ STORE2("content", newRV_inc ((SV *)(AV *)SvRV(*contents_array)));
+ }
+ if (e->node)
+ STORE2("node", newRV_inc ((SV *)e->node->hv));
+
+ /* We set this now because the index data structures don't
+ exist at the time that the main tree is built. */
+ {
+ SV **extra_hash;
+ extra_hash = hv_fetch (e->command->hv, "extra", strlen ("extra"), 0);
+ if (!extra_hash)
+ {
+ /* There's no guarantee that the "extra" value was set on
+ the element. */
+ extra_hash = hv_store (e->command->hv, "extra", strlen ("extra"),
+ newRV_inc ((SV *)newHV ()), 0);
+ }
+
+ hv_store ((HV *)SvRV(*extra_hash), "index_entry", strlen ("index_entry"),
+ newRV_inc ((SV *)entry), 0);
+ }
+#undef STORE2
+ }
+
+ return hv;
+}
+
+/* Return object to be used as $self->{'index_names'} in the perl code.
+ build_texinfo_tree must be called before this so all the 'hv' fields
+ are set on the elements in the tree. */
+HV *
+build_index_data (void)
+{
+ HV *hv;
+ INDEX *i;
+
+ dTHX;
+
+ hv = newHV ();
+
+ for (i = index_names; i->name; i++)
+ {
+ HV *hv2;
+ hv2 = build_single_index_data (i);
+ hv_store (hv, i->name, strlen (i->name), newRV_inc ((SV *)hv2), 0);
+ }
+
+ return hv;
+}
+
+
+
Modified: trunk/parsetexi/makeinfo
===================================================================
--- trunk/parsetexi/makeinfo 2015-02-18 00:07:53 UTC (rev 6132)
+++ trunk/parsetexi/makeinfo 2015-02-18 18:13:09 UTC (rev 6133)
@@ -4,4 +4,4 @@
#OPTIONS='-c DEBUG=1 --no-validate'
COMMAND=${COMMAND:-./texi2any-C.pl}
-PERL5LIB=../tp:../tp/maintain/lib/libintl-perl/lib:../tp/maintain/lib/Text-Unidecode/lib/:../tp/maintain/lib/Unicode-EastAsianWidth/lib:./Parsetexi/lib:./Parsetexi/blib/lib:./Parsetexi/blib/arch/auto/Parsetexi
${DEBUG} ${COMMAND} ${OPTIONS} "$@"
+PERL5LIB=../tp:../tp/maintain/lib/libintl-perl/lib:../tp/maintain/lib/Text-Unidecode/lib/:../tp/maintain/lib/Unicode-EastAsianWidth/lib:./Parsetexi/lib:./Parsetexi/blib/lib:./Parsetexi/blib/arch/auto/Parsetexi:../tp/Texinfo/Convert/XSParagraph/lib:../tp/Texinfo/Convert/XSParagraph/blib/arch/auto/XSParagraph
${DEBUG} ${COMMAND} ${OPTIONS} "$@"
Added: trunk/parsetexi/test-files/xref.texi
===================================================================
--- trunk/parsetexi/test-files/xref.texi (rev 0)
+++ trunk/parsetexi/test-files/xref.texi 2015-02-18 18:13:09 UTC (rev
6133)
@@ -0,0 +1,7 @@
address@hidden Top
+
address@hidden
+
address@hidden Second
+
+Got here.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [6133] parsetexi build index data,
Gavin D. Smith <=