summaryrefslogtreecommitdiff
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-05-24 14:20:10 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-05-24 14:20:10 -0700
commit675c90a3b4c469e2e54e513b6f427ba4ec285ef5 (patch)
treeed472149040ae75932156945beaccfe3ce3795c6 /lib-src
parent379d77dfa3a03083517114e1ce32bb72137aea05 (diff)
downloademacs-675c90a3b4c469e2e54e513b6f427ba4ec285ef5.tar.gz
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.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c74
1 files changed, 29 insertions, 45 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 48d2299410a..301dd3d8c0c 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