texinfo-commits
[Top][All Lists]
Advanced

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

[6166] parsetexi update


From: Gavin D. Smith
Subject: [6166] parsetexi update
Date: Fri, 27 Feb 2015 19:51:55 +0000

Revision: 6166
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6166
Author:   gavin
Date:     2015-02-27 19:51:53 +0000 (Fri, 27 Feb 2015)
Log Message:
-----------
parsetexi update

Modified Paths:
--------------
    trunk/parsetexi/close.c
    trunk/parsetexi/context_stack.h
    trunk/parsetexi/end_line.c
    trunk/parsetexi/handle_commands.c
    trunk/parsetexi/macro.c
    trunk/parsetexi/parser.c

Modified: trunk/parsetexi/close.c
===================================================================
--- trunk/parsetexi/close.c     2015-02-27 18:46:10 UTC (rev 6165)
+++ trunk/parsetexi/close.c     2015-02-27 19:51:53 UTC (rev 6166)
@@ -70,8 +70,8 @@
     }
   else if (current->type != ET_NONE)
     {
+      enum context c;
       debug ("CLOSING type %s", element_type_names[current->type]);
-      enum context c;
       switch (current->type)
         {
         case ET_bracketed:

Modified: trunk/parsetexi/context_stack.h
===================================================================
--- trunk/parsetexi/context_stack.h     2015-02-27 18:46:10 UTC (rev 6165)
+++ trunk/parsetexi/context_stack.h     2015-02-27 19:51:53 UTC (rev 6166)
@@ -30,8 +30,8 @@
 
 /* Contexts where an empty line doesn't start a new paragraph. */
 /* line 492 */
-#define in_no_paragraph_contexts(c) \
-  ((c) == ct_math \
+#define in_paragraph_context(c) \
+  !((c) == ct_math \
    || (c) == ct_menu \
    || (c) == ct_def \
    || (c) == ct_preformatted \

Modified: trunk/parsetexi/end_line.c
===================================================================
--- trunk/parsetexi/end_line.c  2015-02-27 18:46:10 UTC (rev 6165)
+++ trunk/parsetexi/end_line.c  2015-02-27 19:51:53 UTC (rev 6166)
@@ -335,13 +335,28 @@
       {
         char *name = 0;
         char *p = line;
-        if (!isalnum (*p))
-          goto defindex_invalid;
 
         name = read_command_name (&p);
         if (*p)
           goto defindex_invalid; /* Trailing characters. */
 
+        /* Disallow index names NAME where it is likely that for
+           a source file BASE.texi, there will be other files called
+           BASE.NAME in the same directory.  This is to prevent such
+           files being overwritten by the files produced by texindex. */
+        {
+          /* TODO: Also forbid existing index names. */
+          static char *forbidden_index_names[] = {
+            "info", "ps", "pdf", "htm", "html",
+            "log", "aux", "dvi", "texi", "txi",
+            "texinfo", "tex", "bib", 0
+          };
+          char **ptr;
+          for (ptr = forbidden_index_names; *ptr; ptr++)
+            if (!strcmp (name, *ptr))
+              goto defindex_reserved;
+        }
+
         ADD_ARG (name);
         /* TODO: Store the index. */
         break;
@@ -349,6 +364,9 @@
         line_errorf ("bad argument to @%s: %s",
                      command_data(command).cmdname, line);
         break;
+      defindex_reserved:
+        line_errorf ("reserved index name %s", name);
+        break;
       }
     case CM_synindex:
     case CM_syncodeindex:
@@ -1110,7 +1128,7 @@
           add_to_element_contents (current, e);
         }
       //else if () // in menu_entry_description
-      else if (!in_no_paragraph_contexts (current_context ()))
+      else if (in_paragraph_context (current_context ()))
         {
           current = end_paragraph (current);
         }

Modified: trunk/parsetexi/handle_commands.c
===================================================================
--- trunk/parsetexi/handle_commands.c   2015-02-27 18:46:10 UTC (rev 6165)
+++ trunk/parsetexi/handle_commands.c   2015-02-27 19:51:53 UTC (rev 6166)
@@ -21,6 +21,7 @@
 #include "parser.h"
 #include "input.h"
 #include "text.h"
+#include "errors.h"
 
 /* Return a containing @itemize or @enumerate if inside it. */
 // 1847

Modified: trunk/parsetexi/macro.c
===================================================================
--- trunk/parsetexi/macro.c     2015-02-27 18:46:10 UTC (rev 6165)
+++ trunk/parsetexi/macro.c     2015-02-27 19:51:53 UTC (rev 6166)
@@ -23,6 +23,7 @@
 #include "tree.h"
 #include "text.h"
 #include "input.h"
+#include "errors.h"
 
 typedef struct {
     char *macro_name;
@@ -213,8 +214,8 @@
           line = new_line ();
           if (!line)
             {
-              line_error ("@%s missing close brace", 
-                          command_data(cmd).cmdname);
+              line_errorf ("@%s missing close brace", 
+                           command_data(cmd).cmdname);
               line = "\n";
               goto funexit;
             }

Modified: trunk/parsetexi/parser.c
===================================================================
--- trunk/parsetexi/parser.c    2015-02-27 18:46:10 UTC (rev 6165)
+++ trunk/parsetexi/parser.c    2015-02-27 19:51:53 UTC (rev 6166)
@@ -55,32 +55,19 @@
 char *
 read_command_name (char **ptr)
 {
-  char *p = *ptr;
+  char *p = *ptr, *q;
   char *ret = 0;
 
-  /* List of single character Texinfo commands. */
-  if (strchr ("([\"'address@hidden,.!?"
-              " \f\n\r\t" /* \s in Perl */
-              "*-^`=:|/\\",
-          *p))
-    {
-      ret = malloc (2);
-      ret[0] = *p++;
-      ret[1] = '\0';
-    }
-  else
-    {
-      /* Look for a sequence of alphanumeric characters or hyphens, where the
-         first isn't a hyphen. */
-      char *q = p;
-      if (!isalnum (*q))
-        return 0; /* Invalid. */
+  /* Look for a sequence of alphanumeric characters or hyphens, where the
+     first isn't a hyphen. */
+  q = p;
+  if (!isalnum (*q))
+    return 0; /* Invalid. */
 
-      while (isalnum (*++q) || *q == '-')
-        ;
-      ret = strndup (p, q - p);
-      p = q;
-    }
+  while (isalnum (*q) || *q == '-')
+    q++;
+  ret = strndup (p, q - p);
+  p = q;
 
   *ptr = p;
   return ret;
@@ -200,7 +187,7 @@
            || current->type == ET_text_root
            || current->type == ET_document_root
            || current->type == ET_brace_command_context)
-         && !in_no_paragraph_contexts (current_context ());
+         && in_paragraph_context (current_context ());
 }
 
 /* Line 1146 */
@@ -604,8 +591,7 @@
   int retval = 1; /* Return value of function */
   enum command_id end_cmd;
 
-  char *command = 0;
-  enum command_id cmd_id = CM_NONE;
+  enum command_id cmd = CM_NONE;
 
   /* If in raw block, or ignored conditional block. */
   // 3727
@@ -772,16 +758,29 @@
 
   if (*line == '@')
     {
-      line_after_command = line;
+      line_after_command = line + 1;
 
-      line_after_command++;
-      command = read_command_name (&line_after_command);
-      cmd_id = lookup_command (command);
-      if (cmd_id == 0)
+      /* List of single character Texinfo commands. */
+      if (strchr ("([\"'address@hidden,.!?"
+                  " \f\n\r\t"
+                  "*-^`=:|/\\",
+              *line_after_command))
         {
-          /* Unknown command */
-          //abort ();
+          char single_char[2];
+          single_char[0] = *line_after_command++;
+          single_char[1] = '\0';
+          cmd = lookup_command (single_char);
         }
+      else
+        {
+          char *command = read_command_name (&line_after_command);
+
+          if (!command || !(cmd = lookup_command (command)))
+            {
+              /* Unknown command */
+              //abort ();
+            }
+        }
     }
 
   /* There are cases when we need more input, but we don't want to
@@ -810,10 +809,10 @@
 
   /* Handle user-defined macros before anything else because their expansion 
      may lead to changes in the line. */
-  if (cmd_id && (command_data(cmd_id).flags & CF_MACRO)) // 3894
+  if (cmd && (command_data(cmd).flags & CF_MACRO)) // 3894
     {
       line = line_after_command;
-      current = handle_macro (current, &line, cmd_id);
+      current = handle_macro (current, &line, cmd);
     }
 
   /* 3983 Cases that may "lead to command closing": brace commands that don't 
@@ -822,7 +821,7 @@
   /* This condition is only checked immediately after the command opening, 
      otherwise the current element is in the 'args' and not right in the 
      commmand container. */
-  else if (!cmd_id && command_flags(current) & CF_brace && *line != '{')
+  else if (!cmd && command_flags(current) & CF_brace && *line != '{')
     {
       if (command_with_command_as_argument (current->parent)) // 3988
         {
@@ -852,15 +851,15 @@
 
   /* line 4161 */
   /* Any other @-command. */
-  else if (cmd_id)
+  else if (cmd)
     {
       line = line_after_command;
-      debug ("COMMAND %s", command);
+      debug ("COMMAND %s", command_data(cmd).cmdname);
 
       /* TODO: Check if this is an alias command */
 
       /* 4172 @value */
-      if (cmd_id == CM_value)
+      if (cmd == CM_value)
         {
           char *arg_start;
           if (*line != '{')
@@ -923,7 +922,7 @@
 #endif
 
       /* 4276 check if begins or ends a paragraph */
-      if (!(command_data(cmd_id).flags & (CF_misc | CF_block)))
+      if (!(command_data(cmd).flags & (CF_misc | CF_block)))
           {
           /*
              Unless no paragraph commands (line 311):
@@ -941,15 +940,15 @@
         }
 
       // 4281
-      if (cmd_id != 0)
+      if (cmd != 0)
         {
-          if (close_paragraph_command (cmd_id))
+          if (close_paragraph_command (cmd))
             current = end_paragraph (current);
-          if (close_preformatted_command (cmd_id))
+          if (close_preformatted_command (cmd))
             current = end_preformatted (current);
         }
 
-      if (cmd_id == 0)
+      if (cmd == 0)
         {
           // Unknown command
           /* FIXME: Just add it as a new element for now to check it worked. */
@@ -965,16 +964,16 @@
       /* the 'misc-commands' - no braces and not block commands (includes
          @end).  Mostly taking a line argument, except for a small number
          of exceptions, like @tab. */
-      else if (command_data(cmd_id).flags & CF_misc)
+      else if (command_data(cmd).flags & CF_misc)
         {
-          current = handle_misc_command (current, &line, cmd_id);
+          current = handle_misc_command (current, &line, cmd);
         }
 
       /* line 4632 */
-      else if (command_data(cmd_id).flags & CF_block)
+      else if (command_data(cmd).flags & CF_block)
         {
           int new_line = 0;
-          current = handle_block_command (current, &line, cmd_id, &new_line);
+          current = handle_block_command (current, &line, cmd, &new_line);
           if (new_line)
             {
               /* For @macro, to get a new line.  This is done instead of
@@ -984,19 +983,19 @@
             }
         }
 
-      else if (command_data(cmd_id).flags & CF_brace) /* line 4835 */
+      else if (command_data(cmd).flags & CF_brace) /* line 4835 */
         /* or definfoenclose */
         {
-          current = handle_brace_command (current, &line, cmd_id);
+          current = handle_brace_command (current, &line, cmd);
         }
 
       /* No-brace command */
-      else if (command_data(cmd_id).flags & CF_nobrace) /* 4864 */
+      else if (command_data(cmd).flags & CF_nobrace) /* 4864 */
         {
           ELEMENT *nobrace;
 
           nobrace = new_element (ET_NONE);
-          nobrace->cmd = cmd_id;
+          nobrace->cmd = cmd;
           add_to_element_contents (current, nobrace);
 
           // @\




reply via email to

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