texinfo-commits
[Top][All Lists]
Advanced

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

[7561] parsetexi update


From: gavinsmith0123
Subject: [7561] parsetexi update
Date: Fri, 23 Dec 2016 18:37:44 +0000 (UTC)

Revision: 7561
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7561
Author:   gavin
Date:     2016-12-23 18:37:43 +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

Modified: trunk/tp/parsetexi/end_line.c
===================================================================
--- trunk/tp/parsetexi/end_line.c       2016-12-23 07:34:08 UTC (rev 7560)
+++ trunk/tp/parsetexi/end_line.c       2016-12-23 18:37:43 UTC (rev 7561)
@@ -1394,6 +1394,7 @@
   ELEMENT *misc_cmd;
   char *end_command = 0;
   enum command_id end_id;
+  int included_file = 0;
 
   isolate_last_space (current, 0);
 
@@ -1529,8 +1530,16 @@
             }
           else if (current->cmd == CM_include) // 3166
             {
+              int status;
               debug ("Include %s", text);
-              input_push_file (text);
+              status = input_push_file (text);
+              if (!status)
+                {
+                  command_error (current,
+                                 "@include: could not find %s", text);
+                }
+              else
+                included_file = 1;
             }
           else if (current->cmd == CM_documentencoding) // 3190
             {
@@ -1878,10 +1887,14 @@
         current = begin_preformatted (current);
     }
 
-  /* 3346 included file */
+  /* 3346 */
+  /* If a file was included, remove the include command completely.
+     Also ignore @setfilename in included file, as said in the manual. */
+  if (included_file || (cmd == CM_setfilename && top_file_index () > 0))
+    destroy_element (pop_element_from_contents (current));
 
   /* 3350 */
-  if (cmd == CM_setfilename && (current_node || current_section))
+  else if (cmd == CM_setfilename && (current_node || current_section))
     {
       command_warn (misc_cmd, "@setfilename after the first element");
     }

Modified: trunk/tp/parsetexi/input.c
===================================================================
--- trunk/tp/parsetexi/input.c  2016-12-23 07:34:08 UTC (rev 7560)
+++ trunk/tp/parsetexi/input.c  2016-12-23 18:37:43 UTC (rev 7561)
@@ -390,15 +390,22 @@
   /* TODO: free the memory */
 }
 
+int
+top_file_index (void)
+{
+  int i = input_number - 1;
+  while (i >= 0 && input_stack[i].type != IN_file)
+    i--;
+  return i;
+}
+
 void
 set_input_encoding (char *encoding)
 {
   int i;
 
   /* Set encoding of top file in stack. */
-  i = input_number - 1;
-  while (i >= 0 && input_stack[i].type != IN_file)
-    i--;
+  i = top_file_index ();
   if (i >= 0)
     input_stack[i].input_encoding = encoding;
 }
@@ -416,12 +423,12 @@
       include_dirs = realloc (include_dirs,
                               sizeof (char *) * (include_dirs_space += 5));
     }
-  include_dirs[include_dirs_number++] = filename;
+  include_dirs[include_dirs_number++] = strdup (filename);
 }
 
 /* Try to open a file called FILENAME, looking for it in the list of include
    directories. */
-void
+int
 input_push_file (char *filename)
 {
   FILE *stream;
@@ -432,21 +439,26 @@
       /* 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. */
-      /* Also checks if filename is absolute. */
 
-      char *fullpath;
-      asprintf (&fullpath, "%s/%s", include_dirs[i], filename);
-      stream = fopen (fullpath, "r");
-      free (fullpath);
+      /* 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
+        {
+          char *fullpath;
+          asprintf (&fullpath, "%s/%s", include_dirs[i], filename);
+          stream = fopen (fullpath, "r");
+          free (fullpath);
+        }
       if (stream)
         break;
     }
 
   if (!stream)
-    {
-      fprintf (stderr, "Could not open %s\n", filename);
-      exit (1);
-    }
+    return 0;
 
   if (input_number == input_space)
     {
@@ -465,6 +477,6 @@
   input_stack[input_number].input_encoding = 0;
   input_number++;
 
-  return;
+  return 1;
 }
 

Modified: trunk/tp/parsetexi/input.h
===================================================================
--- trunk/tp/parsetexi/input.h  2016-12-23 07:34:08 UTC (rev 7560)
+++ trunk/tp/parsetexi/input.h  2016-12-23 18:37:43 UTC (rev 7561)
@@ -6,9 +6,10 @@
 void input_push (char *text, char *macro, char *filename, int line_number);
 void input_push_text (char *line, char *macro);
 void input_push_text_with_line_nos (char *text, int starting);
-void input_push_file (char *filename);
+int input_push_file (char *filename);
 void input_reset_input_stack (void);
 int expanding_macro (char *macro);
+int top_file_index (void);
 
 extern LINE_NR line_nr;
 




reply via email to

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