emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 675c90a 3/3: Simpilify etags TEX mode scanning


From: Paul Eggert
Subject: [Emacs-diffs] master 675c90a 3/3: Simpilify etags TEX mode scanning
Date: Sun, 24 May 2015 21:20:16 +0000

branch: master
commit 675c90a3b4c469e2e54e513b6f427ba4ec285ef5
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Simpilify etags TEX mode scanning
    
    * lib-src/etags.c (TEX_mode, TEX_esc, TEX_opgrp, TEX_clgrp):
    Remove static vars.
    (TeX_commands): Deduce escapes here instead.
    (TEX_LESC, TEX_SESC, TEX_mode): Remove; all uses removed.
    This removes the need for a reset_input call.
---
 lib-src/etags.c |   74 +++++++++++++++++++++---------------------------------
 1 files changed, 29 insertions(+), 45 deletions(-)

diff --git a/lib-src/etags.c b/lib-src/etags.c
index 48d2299..301dd3d 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -4951,13 +4951,8 @@ static const char *TEX_defenv = "\
 :part:appendix:entry:index:def\
 :newcommand:renewcommand:newenvironment:renewenvironment";
 
-static void TEX_mode (FILE *);
 static void TEX_decode_env (const char *, const char *);
 
-static char TEX_esc = '\\';
-static char TEX_opgrp = '{';
-static char TEX_clgrp = '}';
-
 /*
  * TeX/LaTeX scanning loop.
  */
@@ -4967,8 +4962,8 @@ TeX_commands (FILE *inf)
   char *cp;
   linebuffer *key;
 
-  /* Select either \ or ! as escape character.  */
-  TEX_mode (inf);
+  char TEX_esc = '\0';
+  char TEX_opgrp, TEX_clgrp;
 
   /* Initialize token table once from environment. */
   if (TEX_toktab == NULL)
@@ -4980,9 +4975,33 @@ TeX_commands (FILE *inf)
       for (;;)
        {
          /* Look for a TEX escape. */
-         while (*cp++ != TEX_esc)
-           if (cp[-1] == '\0' || cp[-1] == '%')
-             goto tex_next_line;
+         while (true)
+           {
+             char c = *cp++;
+             if (c == '\0' || c == '%')
+               goto tex_next_line;
+
+             /* Select either \ or ! as escape character, whichever comes
+                first outside a comment.  */
+             if (!TEX_esc)
+               switch (c)
+                 {
+                 case '\\':
+                   TEX_esc = c;
+                   TEX_opgrp = '{';
+                   TEX_clgrp = '}';
+                   break;
+
+                 case '!':
+                   TEX_esc = c;
+                   TEX_opgrp = '<';
+                   TEX_clgrp = '>';
+                   break;
+                 }
+
+             if (c == TEX_esc)
+               break;
+           }
 
          for (key = TEX_toktab; key->buffer != NULL; key++)
            if (strneq (cp, key->buffer, key->len))
@@ -5020,41 +5039,6 @@ TeX_commands (FILE *inf)
     }
 }
 
-#define TEX_LESC '\\'
-#define TEX_SESC '!'
-
-/* Figure out whether TeX's escapechar is '\\' or '!' and set grouping
-   chars accordingly. */
-static void
-TEX_mode (FILE *inf)
-{
-  int c;
-
-  while ((c = getc (inf)) != EOF)
-    {
-      /* Skip to next line if we hit the TeX comment char. */
-      if (c == '%')
-       while (c != '\n' && c != EOF)
-         c = getc (inf);
-      else if (c == TEX_LESC || c == TEX_SESC )
-       break;
-    }
-
-  if (c == TEX_LESC)
-    {
-      TEX_esc = TEX_LESC;
-      TEX_opgrp = '{';
-      TEX_clgrp = '}';
-    }
-  else
-    {
-      TEX_esc = TEX_SESC;
-      TEX_opgrp = '<';
-      TEX_clgrp = '>';
-    }
-  reset_input (inf);
-}
-
 /* Read environment and prepend it to the default string.
    Build token table. */
 static void



reply via email to

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