[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[6179] parsetexi update
From: |
Gavin D. Smith |
Subject: |
[6179] parsetexi update |
Date: |
Fri, 06 Mar 2015 18:27:05 +0000 |
Revision: 6179
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6179
Author: gavin
Date: 2015-03-06 18:27:03 +0000 (Fri, 06 Mar 2015)
Log Message:
-----------
parsetexi update
Modified Paths:
--------------
trunk/parsetexi/ChangeLog
trunk/parsetexi/Makefile.am
trunk/parsetexi/close.c
trunk/parsetexi/debug.c
trunk/parsetexi/end_line.c
trunk/parsetexi/handle_commands.c
trunk/parsetexi/parser.c
trunk/parsetexi/parser.h
trunk/parsetexi/separator.c
Added Paths:
-----------
trunk/parsetexi/counter.c
trunk/parsetexi/counter.h
Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/ChangeLog 2015-03-06 18:27:03 UTC (rev 6179)
@@ -1,3 +1,7 @@
+2015-03-06 Gavin Smith <address@hidden>
+
+ * counter.c: New file.
+
2015-03-01 Gavin Smith <address@hidden>
* end_line.c (parse_line_commanad_args) <CM_defindex>: Call
Modified: trunk/parsetexi/Makefile.am
===================================================================
--- trunk/parsetexi/Makefile.am 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/Makefile.am 2015-03-06 18:27:03 UTC (rev 6179)
@@ -36,7 +36,8 @@
extra.c \
menus.c \
labels.c \
- errors.c errors.h
+ errors.c errors.h \
+ counter.c counter.h
parsetexi_SOURCES=$(libparsetexi_a_SOURCES) main.c
Modified: trunk/parsetexi/close.c
===================================================================
--- trunk/parsetexi/close.c 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/close.c 2015-03-06 18:27:03 UTC (rev 6179)
@@ -31,6 +31,10 @@
if (current->cmd == CM_multitable)
{
}
+ else if (current->cmd == CM_itemize || current->cmd == CM_enumerate)
+ {
+ counter_pop (&count_items);
+ }
/* Put everything after the last @def*x command in a def_item type
container. */
Added: trunk/parsetexi/counter.c
===================================================================
--- trunk/parsetexi/counter.c (rev 0)
+++ trunk/parsetexi/counter.c 2015-03-06 18:27:03 UTC (rev 6179)
@@ -0,0 +1,55 @@
+#include "tree_types.h"
+#include "counter.h"
+
+void
+counter_push (COUNTER *c, ELEMENT *elt, int num)
+{
+ if (c->nvalues >= c->space - 1)
+ {
+ c->space += 5;
+ c->values = realloc (c->values, c->space * sizeof (int));
+ c->elts = realloc (c->elts, c->space * sizeof (ELEMENT *));
+ if (!c->values)
+ abort ();
+ }
+ c->values[c->nvalues] = num;
+ c->elts[c->nvalues] = elt;
+
+ c->nvalues++;
+ c->values[c->nvalues] = 0;
+ c->elts[c->nvalues] = 0;
+}
+
+void
+counter_pop (COUNTER *c)
+{
+ if (!c->nvalues)
+ abort ();
+
+ c->nvalues--;
+ c->values[c->nvalues] = 0;
+ c->elts[c->nvalues] = 0;
+}
+
+void
+counter_inc (COUNTER *c)
+{
+ c->values[c->nvalues - 1]++;
+}
+
+void
+counter_dec (COUNTER *c)
+{
+ c->values[c->nvalues - 1]--;
+}
+
+/* Return value of counter if the top counter is for element ELT, otherwise
+ return -1. */
+int
+counter_value (COUNTER *c, ELEMENT *elt)
+{
+ if (c->nvalues > 0 && c->elts[c->nvalues - 1] == elt)
+ return c->values[c->nvalues - 1];
+ else
+ return -1;
+}
Added: trunk/parsetexi/counter.h
===================================================================
--- trunk/parsetexi/counter.h (rev 0)
+++ trunk/parsetexi/counter.h 2015-03-06 18:27:03 UTC (rev 6179)
@@ -0,0 +1,12 @@
+typedef struct {
+ int *values; /* Array of values. */
+ ELEMENT **elts; /* Elements corresponding to each value. */
+ int nvalues;
+ int space;
+} COUNTER;
+
+void counter_push (COUNTER *c, ELEMENT *e, int n);
+void counter_pop (COUNTER *c);
+void counter_inc (COUNTER *c);
+void counter_dec (COUNTER *c);
+int counter_value (COUNTER *c, ELEMENT *e);
Modified: trunk/parsetexi/debug.c
===================================================================
--- trunk/parsetexi/debug.c 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/debug.c 2015-03-06 18:27:03 UTC (rev 6179)
@@ -16,7 +16,7 @@
#include <stdio.h>
/* Whether to dump debugging output on stderr. */
-int debug_output = 1;
+int debug_output = 0;
void
debug (char *s, ...)
Modified: trunk/parsetexi/end_line.c
===================================================================
--- trunk/parsetexi/end_line.c 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/end_line.c 2015-03-06 18:27:03 UTC (rev 6179)
@@ -755,6 +755,7 @@
{
}
current = current->parent; //2965
+ //counter_pop (&count_remaining_args);
/* Don't consider empty argument of block @-command as argument,
reparent them as contents. */
@@ -1008,7 +1009,7 @@
current = current->parent; /* 3285 */
if (end_command) /* Set above */
{
- /* more processing of @end */
+ /* More processing of @end */
ELEMENT *end_elt;
debug ("END COMMAND %s", end_command);
@@ -1079,6 +1080,8 @@
else if (command_data(cmd_id).flags & CF_root) /* 3380 */
{
current = last_contents_child (current);
+ if (cmd_id == CM_node)
+ counter_pop (&count_remaining_args);
/* 3383 Destroy all contents (why do we do this?) */
while (last_contents_child (current))
Modified: trunk/parsetexi/handle_commands.c
===================================================================
--- trunk/parsetexi/handle_commands.c 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/handle_commands.c 2015-03-06 18:27:03 UTC (rev 6179)
@@ -177,13 +177,14 @@
{
if (cmd == CM_item)
{
- ELEMENT *misc;
+ ELEMENT *misc; char *s;
debug ("ITEM CONTAINER");
+ counter_inc (&count_items);
misc = new_element (ET_NONE);
misc->cmd = CM_item;
- add_extra_string (misc, "item_number", "1");
- /* TODO: Keep count. */
+ asprintf (&s, "%d", counter_value (&count_items, parent));
+ add_extra_string (misc, "item_number", s);
add_to_element_contents (parent, misc);
current = misc;
@@ -260,6 +261,7 @@
add_to_element_contents (row, misc);
current = misc;
+ /* TODO: Keep count. */
add_extra_string (current, "cell_number", "1");
}
}
@@ -344,7 +346,7 @@
is the only (non-block) line command taking comma-separated
arguments. Its arguments will be gathered the same as
those of some block line commands and brace commands. */
- current->remaining_args = 3;
+ counter_push (&count_remaining_args, current, 3);
}
/* 4586 - author */
/* 4612 - dircategory */
@@ -375,18 +377,21 @@
}
/* line 4632 */
+/* A command name has been read that starts a multiline block, which should
+ end in @end <command name>. The block will be processed until
+ "end_line_misc_line" in end_line.c processes the @end command. */
ELEMENT *
handle_block_command (ELEMENT *current, char **line_inout,
- enum command_id cmd_id, int *get_new_line)
+ enum command_id cmd, int *get_new_line)
{
char *line = *line_inout;
- unsigned long flags = command_data(cmd_id).flags;
+ unsigned long flags = command_data(cmd).flags;
/* New macro being defined. */
- if (cmd_id == CM_macro || cmd_id == CM_rmacro)
+ if (cmd == CM_macro || cmd == CM_rmacro)
{
ELEMENT *macro;
- macro = parse_macro_command_line (cmd_id, &line, current);
+ macro = parse_macro_command_line (cmd, &line, current);
add_to_element_contents (current, macro);
// mark_and_warn_invalid ();
current = macro;
@@ -399,20 +404,20 @@
*get_new_line = 1;
goto funexit;
}
- else if (command_data(cmd_id).data == BLOCK_conditional)
+ else if (command_data(cmd).data == BLOCK_conditional)
{
// 4699 - If conditional true, push onto conditional stack. Otherwise
// open a new element (which we shall later remove).
- debug ("CONDITIONAL %s", command_data(cmd_id).cmdname);
- if (cmd_id != CM_ifnotinfo) // TODO
- push_conditional_stack (cmd_id); // Not ignored
+ debug ("CONDITIONAL %s", command_data(cmd).cmdname);
+ if (cmd != CM_ifnotinfo) // TODO
+ push_conditional_stack (cmd); // Not ignored
else
{
// Ignored.
ELEMENT *e;
e = new_element (ET_NONE);
- e->cmd = cmd_id;
+ e->cmd = cmd;
add_to_element_contents (current, e);
current = e;
}
@@ -446,7 +451,7 @@
ELEMENT *block, *def_line;
push_context (ct_def);
block = new_element (ET_NONE);
- block->cmd = cmd_id;
+ block->cmd = cmd;
add_to_element_contents (current, block);
current = block;
def_line = new_element (ET_def_line);
@@ -458,17 +463,17 @@
/* line 4756 */
ELEMENT *block = new_element (ET_NONE);
- block->cmd = cmd_id;
+ block->cmd = cmd;
add_to_element_contents (current, block);
current = block;
}
/* 4763 Check if 'block args command' */
- if (command_data(cmd_id).data != BLOCK_raw)
+ if (command_data(cmd).data != BLOCK_raw)
{
- if (command_data(cmd_id).flags & CF_preformatted)
+ if (command_data(cmd).flags & CF_preformatted)
push_context (ct_preformatted);
- else if (command_data(cmd_id).flags & CF_format_raw)
+ else if (command_data(cmd).flags & CF_format_raw)
{
push_context (ct_rawpreformatted);
}
@@ -476,7 +481,7 @@
// regionsstack
// 4784 menu commands
- if (command_data(cmd_id).flags & CF_menu)
+ if (command_data(cmd).flags & CF_menu)
{
if (current_context () == ct_preformatted)
push_context (ct_preformatted);
@@ -489,11 +494,11 @@
if (current_node)
{
- if (cmd_id == CM_direntry)
+ if (cmd == CM_direntry)
{
// warning
}
- else if (cmd_id == CM_menu)
+ else if (cmd == CM_menu)
{
// add to array of menus for current node
}
@@ -503,12 +508,17 @@
}
}
+ if (cmd == CM_itemize || cmd == CM_enumerate)
+ counter_push (&count_items, current, 0);
+ /* Note that no equivalent thing is done in the Perl code, because
+ 'item_count' is assumed to start at 0. */
+
// 4816
{
ELEMENT *bla = new_element (ET_block_line_arg);
add_to_element_args (current, bla);
current = bla;
- if (!(command_data(cmd_id).flags & CF_def))
+ if (!(command_data(cmd).flags & CF_def))
push_context (ct_line);
/* Note that an ET_empty_line_after_command gets reparented in the
@@ -529,13 +539,13 @@
/* 4835 */
ELEMENT *
handle_brace_command (ELEMENT *current, char **line_inout,
- enum command_id cmd_id)
+ enum command_id cmd)
{
char *line = *line_inout;
ELEMENT *e;
e = new_element (ET_NONE);
- e->cmd = cmd_id;
+ e->cmd = cmd;
add_to_element_contents (current, e);
current = e;
Modified: trunk/parsetexi/parser.c
===================================================================
--- trunk/parsetexi/parser.c 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/parser.c 2015-03-06 18:27:03 UTC (rev 6179)
@@ -109,6 +109,11 @@
}
+/* Counters */
+COUNTER count_remaining_args;
+COUNTER count_items;
+
+
/* lines 1-751 - comments, variable declarations, package imports,
initializations, utilities */
Modified: trunk/parsetexi/parser.h
===================================================================
--- trunk/parsetexi/parser.h 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/parser.h 2015-03-06 18:27:03 UTC (rev 6179)
@@ -81,3 +81,7 @@
/* In menus.c */
int handle_menu (ELEMENT **current_inout, char **line_inout);
ELEMENT *enter_menu_entry_node (ELEMENT *current);
+
+#include "counter.h"
+/* Defined in parser.c */
+extern COUNTER count_remaining_args, count_items;
Modified: trunk/parsetexi/separator.c
===================================================================
--- trunk/parsetexi/separator.c 2015-03-06 08:44:46 UTC (rev 6178)
+++ trunk/parsetexi/separator.c 2015-03-06 18:27:03 UTC (rev 6179)
@@ -69,8 +69,9 @@
command = current->cmd;
/* 4896 */
- current->remaining_args = command_data(current->cmd).data;
- current->remaining_args--;
+ counter_push (&count_remaining_args, current,
+ command_data(current->cmd).data);
+ counter_dec (&count_remaining_args);
arg = new_element (ET_NONE);
add_to_element_args (current, arg);
@@ -217,6 +218,7 @@
closed_command = current->parent->cmd;
debug ("CLOSING(brace) %s", command_data(closed_command).cmdname);
+ counter_pop (&count_remaining_args);
// 5044 check for brace command that doesn't take arguments has in
// fact been given arguments.
@@ -335,7 +337,7 @@
}
#endif
- current->remaining_args--;
+ counter_dec (&count_remaining_args);
new_arg = new_element (type);
add_to_element_args (current, new_arg);
current = new_arg;
@@ -362,7 +364,8 @@
}
/* If a comma is seen after all the arguments for the command have been
read, it is included in the last argument. */
- else if (separator == ',' && current->parent->remaining_args > 0) // 5228
+ else if (separator == ',' // 5228
+ && counter_value (&count_remaining_args, current->parent) > 0)
{
current = handle_comma (current, &line);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [6179] parsetexi update,
Gavin D. Smith <=