[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[7848] parsetexi CPP_LINE_DIRECTIVES
From: |
gavinsmith0123 |
Subject: |
[7848] parsetexi CPP_LINE_DIRECTIVES |
Date: |
Sun, 25 Jun 2017 09:48:29 -0400 (EDT) |
Revision: 7848
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7848
Author: gavin
Date: 2017-06-25 09:48:28 -0400 (Sun, 25 Jun 2017)
Log Message:
-----------
parsetexi CPP_LINE_DIRECTIVES
Modified Paths:
--------------
trunk/tp/parsetexi/Parsetexi.pm
trunk/tp/parsetexi/Parsetexi.xs
trunk/tp/parsetexi/api.c
trunk/tp/parsetexi/api.h
trunk/tp/parsetexi/handle_commands.c
trunk/tp/parsetexi/input.c
trunk/tp/parsetexi/input.h
trunk/tp/parsetexi/macro.c
trunk/tp/parsetexi/parser.c
trunk/tp/parsetexi/separator.c
trunk/tp/parsetexi/tree_types.h
Modified: trunk/tp/parsetexi/Parsetexi.pm
===================================================================
--- trunk/tp/parsetexi/Parsetexi.pm 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/Parsetexi.pm 2017-06-25 13:48:28 UTC (rev 7848)
@@ -172,6 +172,8 @@
}
} elsif ($key eq 'SHOW_MENU') {
conf_set_show_menu ($conf->{$key});
+ } elsif ($key eq 'CPP_LINE_DIRECTIVES') {
+ conf_set_CPP_LINE_DIRECTIVES($conf->{$key});
} else {
#warn "ignoring parser configuration value \"$key\"\n";
}
Modified: trunk/tp/parsetexi/Parsetexi.xs
===================================================================
--- trunk/tp/parsetexi/Parsetexi.xs 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/Parsetexi.xs 2017-06-25 13:48:28 UTC (rev 7848)
@@ -132,3 +132,6 @@
void
conf_set_show_menu (int i)
+
+void
+conf_set_CPP_LINE_DIRECTIVES (int i)
Modified: trunk/tp/parsetexi/api.c
===================================================================
--- trunk/tp/parsetexi/api.c 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/api.c 2017-06-25 13:48:28 UTC (rev 7848)
@@ -976,8 +976,15 @@
}
void
+conf_set_CPP_LINE_DIRECTIVES (int i)
+{
+ conf.cpp_line_directives = i;
+}
+
+void
reset_conf (void)
{
memset (&conf, 0, sizeof (conf));
conf.show_menu = 1;
+ conf.cpp_line_directives = 1;
}
Modified: trunk/tp/parsetexi/api.h
===================================================================
--- trunk/tp/parsetexi/api.h 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/api.h 2017-06-25 13:48:28 UTC (rev 7848)
@@ -1,5 +1,6 @@
/* In api.c */
extern ELEMENT *Root;
+extern CONF conf;
void parse_file (char *filename);
ELEMENT *get_root (void);
Modified: trunk/tp/parsetexi/handle_commands.c
===================================================================
--- trunk/tp/parsetexi/handle_commands.c 2017-06-24 20:07:38 UTC (rev
7847)
+++ trunk/tp/parsetexi/handle_commands.c 2017-06-25 13:48:28 UTC (rev
7848)
@@ -304,7 +304,7 @@
input_push_text (strdup (line), 0);
save_ln = line_nr;
- line2 = new_line ();
+ line2 = new_line (current);
if (line2)
{
line = line2;
@@ -761,7 +761,7 @@
{
char *line2;
input_push_text (strdup (line), 0);
- line2 = new_line ();
+ line2 = new_line (current);
if (line2)
line = line2;
}
@@ -1096,7 +1096,7 @@
while (!is_end_current_command (current,
&line_dummy, &dummy))
{
- line = new_line ();
+ line = new_line (current);
if (!line)
abort (); // TODO
line_dummy = line;
Modified: trunk/tp/parsetexi/input.c
===================================================================
--- trunk/tp/parsetexi/input.c 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/input.c 2017-06-25 13:48:28 UTC (rev 7848)
@@ -1,4 +1,4 @@
-/* Copyright 2010, 2011, 2012, 2013, 2014, 2015
+/* Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
@@ -27,6 +27,7 @@
#include "input.h"
#include "text.h"
#include "api.h"
+#include "commands.h"
enum input_type { IN_file, IN_text };
@@ -65,7 +66,7 @@
Return value should not be freed by caller, and becomes invalid after
a subsequent call. */
char *
-new_line (void)
+new_line (ELEMENT *current)
{
static TEXT t;
char *new = 0;
@@ -74,7 +75,7 @@
while (1)
{
- new = next_text ();
+ new = next_text (current);
if (!new)
break;
text_append (&t, new);
@@ -250,9 +251,69 @@
return 0;
}
+static int
+check_line_directive (char *line, ELEMENT *current, LINE_NR *line_nr)
+{
+ char *p = line, *q;
+ int line_no = 0;
+ char *filename;
+
+ if (current && current->parent && current->parent->cmd == CM_verb)
+ return 0;
+ if (current && (command_flags(current) & CF_block)
+ && (command_data(current->cmd).data == BLOCK_raw
+ || command_data(current->cmd).data == BLOCK_conditional))
+ return 0;
+
+ p += strspn (p, " \t");
+ if (*p != '#')
+ return 0;
+ p++;
+
+ q = p + strspn (p, " \t");
+ if (!memcmp (q, "line", strlen ("line")))
+ p = q + strlen ("line");
+
+ if (!strchr (" \t", *p))
+ return 0;
+ p += strspn (p, " \t");
+
+ /* p should now be at the line number */
+ if (!strchr ("0123456789", *p))
+ return 0;
+ line_no = strtoul (p, &p, 10);
+
+ p += strspn (p, " \t");
+ if (*p == '"')
+ {
+ p++;
+ q = strchr (p, '"');
+ if (!q)
+ return 0;
+ filename = malloc (q - p + 1);
+ memcpy (filename, p, q - p);
+ filename[q - p] = '\0';
+ p = q + 1;
+ p += strspn (p, " \t");
+
+ p += strspn (p, "0123456789");
+ p += strspn (p, " \t");
+ }
+ if (*p && *p != '\n')
+ return 0; /* trailing text on line */
+
+ line_nr->line_nr = line_no;
+ if (filename)
+ {
+ // free (line_nr->file_name); // FIXME: could still be referenced
+ line_nr->file_name = filename;
+ }
+ return 1;
+}
+
/* Return value to be freed by caller. Return null if we are out of input. */
char *
-next_text (void)
+next_text (ELEMENT *current)
{
ssize_t status;
char *line = 0;
@@ -293,7 +354,7 @@
case IN_file: // 1911
input_file = input_stack[input_number - 1].file;
status = getline (&line, &n, input_file);
- while (status != -1)
+ if (status != -1)
{
char *comment;
if (feof (input_file))
@@ -310,7 +371,11 @@
if (comment)
*comment = '\0';
- // 1920 CPP_LINE_DIRECTIVES
+ if (conf.cpp_line_directives)
+ {
+ if (check_line_directive (line, current, &i->line_nr))
+ continue;
+ }
i->line_nr.line_nr++;
line_nr = i->line_nr;
@@ -360,7 +425,8 @@
if (!macro)
line_number--;
input_stack[input_number].line_nr.line_nr = line_number;
- input_stack[input_number].line_nr.file_name = filename;
+ input_stack[input_number].line_nr.file_name
+ = filename ? strdup (filename) : 0;
input_stack[input_number].line_nr.macro = macro;
input_number++;
}
@@ -498,7 +564,8 @@
input_stack[input_number].type = IN_file;
input_stack[input_number].file = stream;
- input_stack[input_number].line_nr.file_name = filename;
+ input_stack[input_number].line_nr.file_name
+ = filename ? strdup (filename) : 0;
input_stack[input_number].line_nr.line_nr = 0;
input_stack[input_number].line_nr.macro = 0;
input_stack[input_number].text = 0;
Modified: trunk/tp/parsetexi/input.h
===================================================================
--- trunk/tp/parsetexi/input.h 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/input.h 2017-06-25 13:48:28 UTC (rev 7848)
@@ -1,7 +1,7 @@
#include <stdio.h>
-char *new_line (void);
-char *next_text (void);
+char *new_line (ELEMENT *current);
+char *next_text (ELEMENT *current);
void input_push (char *text, char *macro, char *filename, int line_number);
void input_push_text (char *line, char *macro);
Modified: trunk/tp/parsetexi/macro.c
===================================================================
--- trunk/tp/parsetexi/macro.c 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/macro.c 2017-06-25 13:48:28 UTC (rev 7848)
@@ -269,7 +269,7 @@
{
debug ("MACRO ARG end of line");
text_append (&arg, pline);
- line = new_line ();
+ line = new_line (macro);
if (!line)
{
line_error ("@%s missing closing brace", command_name(cmd));
@@ -476,7 +476,7 @@
}
// 3898
-/* CMD is the macro command. */
+/* Handle macro expandsion. CMD is the macro command. */
ELEMENT *
handle_macro (ELEMENT *current, char **line_inout, enum command_id cmd)
{
@@ -524,7 +524,7 @@
input already, call new_line. */
if (!strchr (line, '\n'))
{
- line = new_line ();
+ line = new_line (current);
if (!line)
line = "";
}
Modified: trunk/tp/parsetexi/parser.c
===================================================================
--- trunk/tp/parsetexi/parser.c 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/parser.c 2017-06-25 13:48:28 UTC (rev 7848)
@@ -172,7 +172,7 @@
/* FIXME: _next_text isn't used in Perl. */
free (line);
- line = next_text ();
+ line = next_text (0);
if (!line)
abort (); /* Empty file? */
@@ -899,14 +899,15 @@
popped = pop_element_from_contents (current);
if (popped->cmd != end_cmd)
abort(); //error
- destroy_element_and_children (popped);
/* Ignore until end of line */
if (!strchr (line, '\n'))
{
+ line = new_line (popped);
debug ("IGNORE CLOSE LINE");
- line = new_line ();
}
+ destroy_element_and_children (popped);
+
debug ("CLOSED conditional %s", command_name(end_cmd));
retval = GET_A_NEW_LINE;
goto funexit;
@@ -1021,7 +1022,7 @@
input in a static variable like allocated_text, to prevent
memory leaks. */
free (allocated_text);
- line = allocated_text = next_text ();
+ line = allocated_text = next_text (current);
if (!line)
{
@@ -1087,7 +1088,7 @@
line = line_after_command;
current = handle_macro (current, &line, cmd);
free (allocated_line);
- allocated_line = next_text ();
+ allocated_line = next_text (current);
line = allocated_line;
}
@@ -1717,7 +1718,7 @@
while (1)
{
free (allocated_line);
- line = allocated_line = next_text ();
+ line = allocated_line = next_text (current);
if (!allocated_line)
break; /* Out of input. */
Modified: trunk/tp/parsetexi/separator.c
===================================================================
--- trunk/tp/parsetexi/separator.c 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/separator.c 2017-06-25 13:48:28 UTC (rev 7848)
@@ -748,7 +748,7 @@
brace_count--;
break;
default:
- line = next_text ();
+ line = next_text (current);
if (!line)
{
/* ERROR - unbalanced brace */
@@ -795,7 +795,7 @@
brace_count--;
break;
default:
- line = next_text ();
+ line = next_text (current);
if (!line)
{
/* ERROR - unbalanced brace */
Modified: trunk/tp/parsetexi/tree_types.h
===================================================================
--- trunk/tp/parsetexi/tree_types.h 2017-06-24 20:07:38 UTC (rev 7847)
+++ trunk/tp/parsetexi/tree_types.h 2017-06-25 13:48:28 UTC (rev 7848)
@@ -174,6 +174,7 @@
typedef struct CONF {
int show_menu;
+ int cpp_line_directives;
} CONF;
typedef struct {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [7848] parsetexi CPP_LINE_DIRECTIVES,
gavinsmith0123 <=