[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[7562] parsetexi update
From: |
gavinsmith0123 |
Subject: |
[7562] parsetexi update |
Date: |
Fri, 23 Dec 2016 21:06:39 +0000 (UTC) |
Revision: 7562
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7562
Author: gavin
Date: 2016-12-23 21:06:38 +0000 (Fri, 23 Dec 2016)
Log Message:
-----------
parsetexi update
Modified Paths:
--------------
trunk/tp/parsetexi/end_line.c
trunk/tp/parsetexi/input.c
trunk/tp/parsetexi/input.h
trunk/tp/parsetexi/parser.c
trunk/tp/parsetexi/parser.h
Modified: trunk/tp/parsetexi/end_line.c
===================================================================
--- trunk/tp/parsetexi/end_line.c 2016-12-23 18:37:43 UTC (rev 7561)
+++ trunk/tp/parsetexi/end_line.c 2016-12-23 21:06:38 UTC (rev 7562)
@@ -1531,15 +1531,28 @@
else if (current->cmd == CM_include) // 3166
{
int status;
+ char *fullpath;
debug ("Include %s", text);
- status = input_push_file (text);
- if (!status)
+
+ fullpath = locate_include_file (text);
+ if (!fullpath)
{
command_error (current,
"@include: could not find %s", text);
}
else
- included_file = 1;
+ {
+ status = input_push_file (fullpath);
+ if (status)
+ {
+ command_error (current,
+ "@include: could not open %s:",
+ text,
+ strerror (status));
+ }
+ else
+ included_file = 1;
+ }
}
else if (current->cmd == CM_documentencoding) // 3190
{
Modified: trunk/tp/parsetexi/input.c
===================================================================
--- trunk/tp/parsetexi/input.c 2016-12-23 18:37:43 UTC (rev 7561)
+++ trunk/tp/parsetexi/input.c 2016-12-23 21:06:38 UTC (rev 7562)
@@ -21,6 +21,7 @@
#include <string.h>
#include <iconv.h>
#include <errno.h>
+#include <sys/stat.h>
#include "tree_types.h"
#include "input.h"
@@ -418,47 +419,63 @@
void
add_include_directory (char *filename)
{
+ int len;
if (include_dirs_number == include_dirs_space)
{
include_dirs = realloc (include_dirs,
sizeof (char *) * (include_dirs_space += 5));
}
- include_dirs[include_dirs_number++] = strdup (filename);
+ filename = strdup (filename);
+ include_dirs[include_dirs_number++] = filename;
+ len = strlen (filename);
+ if (len > 0 && filename[len - 1] == '/')
+ filename[len - 1] = '\0';
}
-/* Try to open a file called FILENAME, looking for it in the list of include
- directories. */
-int
-input_push_file (char *filename)
+char *
+locate_include_file (char *filename)
{
- FILE *stream;
- int i;
+ char *fullpath;
+ struct stat dummy;
+ int i, status;
- for (i = 0; i < include_dirs_number; i++)
+ /* Checks if filename is absolute or relative to current directory.
+ TODO: Could use macros in top-level config.h for this. */
+ /* TODO: The Perl code (in Common.pm, 'locate_include_file') handles
+ a volume in a path (like "A:"), possibly more general treatment
+ with File::Spec module. */
+ if (!memcmp (filename, "/", 1)
+ || !memcmp (filename, "../", 3)
+ || !memcmp (filename, "./", 2))
{
- /* TODO: The Perl code (in Common.pm, 'locate_include_file') handles a
- volume in a path (like "A:"), possibly more general treatment with
- File::Spec module. */
-
- /* Checks if filename is absolute or relative to current directory.
- TODO: Could use macros in top-level config.h for this. */
- if (!memcmp (filename, "/", 1)
- || !memcmp (filename, "../", 3)
- || !memcmp (filename, "./", 2))
- stream = fopen (filename, "r");
- else
+ status = stat (filename, &dummy);
+ if (status == 0)
+ return filename;
+ }
+ else
+ {
+ for (i = 0; i < include_dirs_number; i++)
{
- char *fullpath;
asprintf (&fullpath, "%s/%s", include_dirs[i], filename);
- stream = fopen (fullpath, "r");
+ status = stat (fullpath, &dummy);
+ if (status == 0)
+ return fullpath;
free (fullpath);
}
- if (stream)
- break;
}
+ return 0;
+}
+/* Try to open a file called FILENAME, looking for it in the list of include
+ directories. */
+int
+input_push_file (char *filename)
+{
+ FILE *stream;
+
+ stream = fopen (filename, "r");
if (!stream)
- return 0;
+ return errno;
if (input_number == input_space)
{
@@ -467,6 +484,18 @@
abort ();
}
+ /* Strip off a leading directory path. */
+ char *p, *q;
+ p = 0;
+ q = strchr (filename, '/');
+ while (q)
+ {
+ p = q;
+ q = strchr (q + 1, '/');
+ }
+ if (p)
+ filename = strdup (p+1);
+
input_stack[input_number].type = IN_file;
input_stack[input_number].file = stream;
input_stack[input_number].line_nr.file_name = filename;
@@ -477,6 +506,6 @@
input_stack[input_number].input_encoding = 0;
input_number++;
- return 1;
+ return 0;
}
Modified: trunk/tp/parsetexi/input.h
===================================================================
--- trunk/tp/parsetexi/input.h 2016-12-23 18:37:43 UTC (rev 7561)
+++ trunk/tp/parsetexi/input.h 2016-12-23 21:06:38 UTC (rev 7562)
@@ -10,6 +10,7 @@
void input_reset_input_stack (void);
int expanding_macro (char *macro);
int top_file_index (void);
+char *locate_include_file (char *filename);
extern LINE_NR line_nr;
Modified: trunk/tp/parsetexi/parser.c
===================================================================
--- trunk/tp/parsetexi/parser.c 2016-12-23 18:37:43 UTC (rev 7561)
+++ trunk/tp/parsetexi/parser.c 2016-12-23 21:06:38 UTC (rev 7562)
@@ -128,14 +128,25 @@
/* 835 */
void
-parse_texi_file (const char *filename_in)
+parse_texi_file (char *filename)
{
char *p, *q;
char *linep, *line = 0;
ELEMENT *root = new_element (ET_text_root);
ELEMENT *preamble = 0;
- char *filename = strdup (filename_in);
+ char c;
+ int status;
+
+ status = input_push_file (filename);
+ if (status)
+ {
+ /* TODO document_error */
+ abort ();
+ }
+
+ //filename = strdup (filename);
+
/* Strip off a leading directory path, by looking for the last
'/' in filename. */
p = 0;
@@ -148,15 +159,14 @@
if (p)
{
+ c = *p;
*p = '\0';
add_include_directory (filename);
- filename = p + 1;
+ *p = c;
}
- input_push_file (filename);
-
/* Check for preamble. */
- do
+ while (1)
{
ELEMENT *l;
@@ -183,7 +193,6 @@
text_append (&l->text, line);
add_to_element_contents (preamble, l);
}
- while (1);
if (preamble)
add_to_element_contents (root, preamble);
Modified: trunk/tp/parsetexi/parser.h
===================================================================
--- trunk/tp/parsetexi/parser.h 2016-12-23 18:37:43 UTC (rev 7561)
+++ trunk/tp/parsetexi/parser.h 2016-12-23 21:06:38 UTC (rev 7562)
@@ -53,7 +53,7 @@
void push_conditional_stack (enum command_id cond);
enum command_id pop_conditional_stack (void);
extern size_t conditional_number;
-void parse_texi_file (const char *filename);
+void parse_texi_file (char *filename);
int abort_empty_line (ELEMENT **current_inout, char *additional);
ELEMENT *end_paragraph (ELEMENT *current,
enum command_id closed_command,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [7562] parsetexi update,
gavinsmith0123 <=