28 |
* 1992 Joseph B. Wells improved C and C++ parsing. |
* 1992 Joseph B. Wells improved C and C++ parsing. |
29 |
* 1993 Francesco Potort́ reorganised C and C++. |
* 1993 Francesco Potort́ reorganised C and C++. |
30 |
* 1994 Regexp tags by Tom Tromey. |
* 1994 Regexp tags by Tom Tromey. |
31 |
* 2001 Nested classes by Francesco Potort́ (ideas by Mykola Dzyuba). |
* 2001 Nested classes by Francesco Potort́ (concept by Mykola Dzyuba). |
32 |
|
* 2002 #line directives by Francesco Potort́. |
33 |
* |
* |
34 |
* Francesco Potort́ <pot@gnu.org> has maintained it since 1993. |
* Francesco Potort́ <pot@gnu.org> has maintained it since 1993. |
35 |
*/ |
*/ |
36 |
|
|
37 |
char pot_etags_version[] = "@(#) pot revision number is $Revision$"; |
char pot_etags_version[] = "@(#) pot revision number is 15.26"; |
38 |
|
|
39 |
#define TRUE 1 |
#define TRUE 1 |
40 |
#define FALSE 0 |
#define FALSE 0 |
3352 |
break; |
break; |
3353 |
case dsharpseen: |
case dsharpseen: |
3354 |
savetoken = token; |
savetoken = token; |
3355 |
|
break; |
3356 |
} |
} |
3357 |
if (!yacc_rules || lp == newlb.buffer + 1) |
if (!yacc_rules || lp == newlb.buffer + 1) |
3358 |
{ |
{ |
3617 |
&& typdef == tnone) |
&& typdef == tnone) |
3618 |
cblev = -1; |
cblev = -1; |
3619 |
} |
} |
3620 |
|
break; |
3621 |
} |
} |
3622 |
switch (structdef) |
switch (structdef) |
3623 |
{ |
{ |
4698 |
/* Find tags in TeX and LaTeX input files. */ |
/* Find tags in TeX and LaTeX input files. */ |
4699 |
|
|
4700 |
/* TEX_toktab is a table of TeX control sequences that define tags. |
/* TEX_toktab is a table of TeX control sequences that define tags. |
4701 |
Each TEX_tabent records one such control sequence. |
* Each entry records one such control sequence. |
4702 |
CONVERT THIS TO USE THE Stab TYPE!! */ |
* |
4703 |
struct TEX_tabent |
* Original code from who knows whom. |
4704 |
{ |
* Ideas by: |
4705 |
char *name; |
* Stefan Monnier (2002) |
4706 |
int len; |
*/ |
|
}; |
|
4707 |
|
|
4708 |
static struct TEX_tabent *TEX_toktab = NULL; /* Table with tag tokens */ |
static linebuffer *TEX_toktab = NULL; /* Table with tag tokens */ |
4709 |
|
|
4710 |
/* Default set of control sequences to put into TEX_toktab. |
/* Default set of control sequences to put into TEX_toktab. |
4711 |
The value of environment var TEXTAGS is prepended to this. */ |
The value of environment var TEXTAGS is prepended to this. */ |
|
|
|
4712 |
static char *TEX_defenv = "\ |
static char *TEX_defenv = "\ |
4713 |
:chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem\ |
:chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem\ |
4714 |
:part:appendix:entry:index"; |
:part:appendix:entry:index:def\ |
4715 |
|
:newcommand:renewcommand:newenvironment:renewenvironment"; |
4716 |
|
|
4717 |
static void TEX_mode __P((FILE *)); |
static void TEX_mode __P((FILE *)); |
4718 |
static struct TEX_tabent *TEX_decode_env __P((char *, char *)); |
static void TEX_decode_env __P((char *, char *)); |
|
static int TEX_Token __P((char *)); |
|
4719 |
|
|
4720 |
static char TEX_esc = '\\'; |
static char TEX_esc = '\\'; |
4721 |
static char TEX_opgrp = '{'; |
static char TEX_opgrp = '{'; |
4728 |
TeX_commands (inf) |
TeX_commands (inf) |
4729 |
FILE *inf; |
FILE *inf; |
4730 |
{ |
{ |
4731 |
char *cp, *lasthit; |
char *cp; |
4732 |
register int i; |
linebuffer *key; |
4733 |
|
|
4734 |
/* Select either \ or ! as escape character. */ |
/* Select either \ or ! as escape character. */ |
4735 |
TEX_mode (inf); |
TEX_mode (inf); |
4736 |
|
|
4737 |
/* Initialize token table once from environment. */ |
/* Initialize token table once from environment. */ |
4738 |
if (!TEX_toktab) |
if (TEX_toktab == NULL) |
4739 |
TEX_toktab = TEX_decode_env ("TEXTAGS", TEX_defenv); |
TEX_decode_env ("TEXTAGS", TEX_defenv); |
4740 |
|
|
4741 |
LOOP_ON_INPUT_LINES (inf, lb, cp) |
LOOP_ON_INPUT_LINES (inf, lb, cp) |
4742 |
{ |
{ |
4743 |
lasthit = cp; |
/* Look at each TEX keyword in line. */ |
4744 |
/* Look at each esc in line. */ |
for (;;) |
|
while ((cp = etags_strchr (cp, TEX_esc)) != NULL) |
|
4745 |
{ |
{ |
4746 |
if (*++cp == '\0') |
/* Look for a TEX escape. */ |
4747 |
break; |
while (*cp++ != TEX_esc) |
4748 |
linecharno += cp - lasthit; |
if (cp[-1] == '\0' || cp[-1] == '%') |
4749 |
lasthit = cp; |
goto tex_next_line; |
4750 |
i = TEX_Token (lasthit); |
|
4751 |
if (i >= 0) |
for (key = TEX_toktab; key->buffer != NULL; key++) |
4752 |
{ |
if (strneq (cp, key->buffer, key->len)) |
4753 |
register char *p; |
{ |
4754 |
for (lasthit += TEX_toktab[i].len; |
register char *p; |
4755 |
*lasthit == TEX_esc || *lasthit == TEX_opgrp; |
char *name; |
4756 |
lasthit++) |
int linelen; |
4757 |
continue; |
bool opgrp = FALSE; |
4758 |
for (p = lasthit; |
|
4759 |
!iswhite (*p) && *p != TEX_opgrp && *p != TEX_clgrp; |
cp = skip_spaces (cp + key->len); |
4760 |
p++) |
if (*cp == TEX_opgrp) |
4761 |
continue; |
{ |
4762 |
pfnote (savenstr (lasthit, p-lasthit), TRUE, |
opgrp = TRUE; |
4763 |
lb.buffer, lb.len, lineno, linecharno); |
cp++; |
4764 |
break; /* We only tag a line once */ |
} |
4765 |
} |
for (p = cp; |
4766 |
|
(!iswhite (*p) && *p != '#' && |
4767 |
|
*p != TEX_opgrp && *p != TEX_clgrp); |
4768 |
|
p++) |
4769 |
|
continue; |
4770 |
|
name = savenstr (cp, p-cp); |
4771 |
|
linelen = lb.len; |
4772 |
|
if (!opgrp || *p == TEX_clgrp) |
4773 |
|
{ |
4774 |
|
while (*p != '\0' && *p != TEX_opgrp && *p != TEX_clgrp) |
4775 |
|
*p++; |
4776 |
|
linelen = p - lb.buffer + 1; |
4777 |
|
} |
4778 |
|
pfnote (name, TRUE, lb.buffer, linelen, lineno, linecharno); |
4779 |
|
goto tex_next_line; /* We only tag a line once */ |
4780 |
|
} |
4781 |
} |
} |
4782 |
|
tex_next_line: |
4783 |
|
; |
4784 |
} |
} |
4785 |
} |
} |
4786 |
|
|
4787 |
#define TEX_LESC '\\' |
#define TEX_LESC '\\' |
4788 |
#define TEX_SESC '!' |
#define TEX_SESC '!' |
|
#define TEX_cmt '%' |
|
4789 |
|
|
4790 |
/* Figure out whether TeX's escapechar is '\\' or '!' and set grouping |
/* Figure out whether TeX's escapechar is '\\' or '!' and set grouping |
4791 |
chars accordingly. */ |
chars accordingly. */ |
4798 |
while ((c = getc (inf)) != EOF) |
while ((c = getc (inf)) != EOF) |
4799 |
{ |
{ |
4800 |
/* Skip to next line if we hit the TeX comment char. */ |
/* Skip to next line if we hit the TeX comment char. */ |
4801 |
if (c == TEX_cmt) |
if (c == '%') |
4802 |
while (c != '\n') |
while (c != '\n') |
4803 |
c = getc (inf); |
c = getc (inf); |
4804 |
else if (c == TEX_LESC || c == TEX_SESC ) |
else if (c == TEX_LESC || c == TEX_SESC ) |
4824 |
|
|
4825 |
/* Read environment and prepend it to the default string. |
/* Read environment and prepend it to the default string. |
4826 |
Build token table. */ |
Build token table. */ |
4827 |
static struct TEX_tabent * |
static void |
4828 |
TEX_decode_env (evarname, defenv) |
TEX_decode_env (evarname, defenv) |
4829 |
char *evarname; |
char *evarname; |
4830 |
char *defenv; |
char *defenv; |
4831 |
{ |
{ |
4832 |
register char *env, *p; |
register char *env, *p; |
4833 |
|
int i, len; |
|
struct TEX_tabent *tab; |
|
|
int size, i; |
|
4834 |
|
|
4835 |
/* Append default string to environment. */ |
/* Append default string to environment. */ |
4836 |
env = getenv (evarname); |
env = getenv (evarname); |
4843 |
} |
} |
4844 |
|
|
4845 |
/* Allocate a token table */ |
/* Allocate a token table */ |
4846 |
for (size = 1, p = env; p;) |
for (len = 1, p = env; p;) |
4847 |
if ((p = etags_strchr (p, ':')) && *++p != '\0') |
if ((p = etags_strchr (p, ':')) && *++p != '\0') |
4848 |
size++; |
len++; |
4849 |
/* Add 1 to leave room for null terminator. */ |
TEX_toktab = xnew (len, linebuffer); |
|
tab = xnew (size + 1, struct TEX_tabent); |
|
4850 |
|
|
4851 |
/* Unpack environment string into token table. Be careful about */ |
/* Unpack environment string into token table. Be careful about */ |
4852 |
/* zero-length strings (leading ':', "::" and trailing ':') */ |
/* zero-length strings (leading ':', "::" and trailing ':') */ |
4853 |
for (i = 0; *env;) |
for (i = 0; *env != '\0';) |
4854 |
{ |
{ |
4855 |
p = etags_strchr (env, ':'); |
p = etags_strchr (env, ':'); |
4856 |
if (!p) /* End of environment string. */ |
if (!p) /* End of environment string. */ |
4857 |
p = env + strlen (env); |
p = env + strlen (env); |
4858 |
if (p - env > 0) |
if (p - env > 0) |
4859 |
{ /* Only non-zero strings. */ |
{ /* Only non-zero strings. */ |
4860 |
tab[i].name = savenstr (env, p - env); |
TEX_toktab[i].buffer = savenstr (env, p - env); |
4861 |
tab[i].len = strlen (tab[i].name); |
TEX_toktab[i].len = p - env; |
4862 |
i++; |
i++; |
4863 |
} |
} |
4864 |
if (*p) |
if (*p) |
4865 |
env = p + 1; |
env = p + 1; |
4866 |
else |
else |
4867 |
{ |
{ |
4868 |
tab[i].name = NULL; /* Mark end of table. */ |
TEX_toktab[i].buffer = NULL; /* Mark end of table. */ |
4869 |
tab[i].len = 0; |
TEX_toktab[i].len = 0; |
4870 |
break; |
break; |
4871 |
} |
} |
4872 |
} |
} |
|
return tab; |
|
|
} |
|
|
|
|
|
/* If the text at CP matches one of the tag-defining TeX command names, |
|
|
return the pointer to the first occurrence of that command in TEX_toktab. |
|
|
Otherwise return -1. |
|
|
Keep the capital `T' in `token' for dumb truncating compilers |
|
|
(this distinguishes it from `TEX_toktab' */ |
|
|
static int |
|
|
TEX_Token (cp) |
|
|
char *cp; |
|
|
{ |
|
|
int i; |
|
|
|
|
|
for (i = 0; TEX_toktab[i].len > 0; i++) |
|
|
if (strneq (TEX_toktab[i].name, cp, TEX_toktab[i].len)) |
|
|
return i; |
|
|
return -1; |
|
4873 |
} |
} |
4874 |
|
|
4875 |
|
|