diff options
| author | Francesco Potortì | 2002-06-06 09:45:52 +0000 |
|---|---|---|
| committer | Francesco Potortì | 2002-06-06 09:45:52 +0000 |
| commit | f6566f9015fac459eaf14126e2c51052af532a4b (patch) | |
| tree | 0754808b55aa42ab5e1b44aa64fbc58ef563cbe2 /lib-src | |
| parent | 5526f1f6888a108a161460d8bb96f1be1ca00393 (diff) | |
| download | emacs-f6566f9015fac459eaf14126e2c51052af532a4b.tar.gz emacs-f6566f9015fac459eaf14126e2c51052af532a4b.zip | |
(TeX_commands): Skip comments.
(TEX_defenv): Now contains more contructs.
(TEX_cmt): Make it a static char and move it before TeX_commands.
(TeX_commands): Shorten the tag to the brace after the name.
(TeX_commands): Names now include the initial backslash.
(TeX_commands): Names do not include numeric args #n.
(TeX_commands): Correct line char number in tags.
(TEX_tabent, TEX_token): Deleted.
(TeX_commands, TEX_decode_env): Streamlined.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/etags.c | 143 |
1 files changed, 69 insertions, 74 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c index b21175e21c2..628fe3a3977 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c | |||
| @@ -28,12 +28,13 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |||
| 28 | * 1992 Joseph B. Wells improved C and C++ parsing. | 28 | * 1992 Joseph B. Wells improved C and C++ parsing. |
| 29 | * 1993 Francesco Potortì reorganised C and C++. | 29 | * 1993 Francesco Potortì reorganised C and C++. |
| 30 | * 1994 Regexp tags by Tom Tromey. | 30 | * 1994 Regexp tags by Tom Tromey. |
| 31 | * 2001 Nested classes by Francesco Potortì (ideas by Mykola Dzyuba). | 31 | * 2001 Nested classes by Francesco Potortì (concept by Mykola Dzyuba). |
| 32 | * 2002 #line directives by Francesco Potortì. | ||
| 32 | * | 33 | * |
| 33 | * Francesco Potortì <pot@gnu.org> has maintained it since 1993. | 34 | * Francesco Potortì <pot@gnu.org> has maintained it since 1993. |
| 34 | */ | 35 | */ |
| 35 | 36 | ||
| 36 | char pot_etags_version[] = "@(#) pot revision number is $Revision: 15.18 $"; | 37 | char pot_etags_version[] = "@(#) pot revision number is 15.26"; |
| 37 | 38 | ||
| 38 | #define TRUE 1 | 39 | #define TRUE 1 |
| 39 | #define FALSE 0 | 40 | #define FALSE 0 |
| @@ -3351,6 +3352,7 @@ C_entries (c_ext, inf) | |||
| 3351 | break; | 3352 | break; |
| 3352 | case dsharpseen: | 3353 | case dsharpseen: |
| 3353 | savetoken = token; | 3354 | savetoken = token; |
| 3355 | break; | ||
| 3354 | } | 3356 | } |
| 3355 | if (!yacc_rules || lp == newlb.buffer + 1) | 3357 | if (!yacc_rules || lp == newlb.buffer + 1) |
| 3356 | { | 3358 | { |
| @@ -3615,6 +3617,7 @@ C_entries (c_ext, inf) | |||
| 3615 | && typdef == tnone) | 3617 | && typdef == tnone) |
| 3616 | cblev = -1; | 3618 | cblev = -1; |
| 3617 | } | 3619 | } |
| 3620 | break; | ||
| 3618 | } | 3621 | } |
| 3619 | switch (structdef) | 3622 | switch (structdef) |
| 3620 | { | 3623 | { |
| @@ -4695,26 +4698,24 @@ Scheme_functions (inf) | |||
| 4695 | /* Find tags in TeX and LaTeX input files. */ | 4698 | /* Find tags in TeX and LaTeX input files. */ |
| 4696 | 4699 | ||
| 4697 | /* TEX_toktab is a table of TeX control sequences that define tags. | 4700 | /* TEX_toktab is a table of TeX control sequences that define tags. |
| 4698 | Each TEX_tabent records one such control sequence. | 4701 | * Each entry records one such control sequence. |
| 4699 | CONVERT THIS TO USE THE Stab TYPE!! */ | 4702 | * |
| 4700 | struct TEX_tabent | 4703 | * Original code from who knows whom. |
| 4701 | { | 4704 | * Ideas by: |
| 4702 | char *name; | 4705 | * Stefan Monnier (2002) |
| 4703 | int len; | 4706 | */ |
| 4704 | }; | ||
| 4705 | 4707 | ||
| 4706 | static struct TEX_tabent *TEX_toktab = NULL; /* Table with tag tokens */ | 4708 | static linebuffer *TEX_toktab = NULL; /* Table with tag tokens */ |
| 4707 | 4709 | ||
| 4708 | /* Default set of control sequences to put into TEX_toktab. | 4710 | /* Default set of control sequences to put into TEX_toktab. |
| 4709 | The value of environment var TEXTAGS is prepended to this. */ | 4711 | The value of environment var TEXTAGS is prepended to this. */ |
| 4710 | |||
| 4711 | static char *TEX_defenv = "\ | 4712 | static char *TEX_defenv = "\ |
| 4712 | :chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem\ | 4713 | :chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem\ |
| 4713 | :part:appendix:entry:index"; | 4714 | :part:appendix:entry:index:def\ |
| 4715 | :newcommand:renewcommand:newenvironment:renewenvironment"; | ||
| 4714 | 4716 | ||
| 4715 | static void TEX_mode __P((FILE *)); | 4717 | static void TEX_mode __P((FILE *)); |
| 4716 | static struct TEX_tabent *TEX_decode_env __P((char *, char *)); | 4718 | static void TEX_decode_env __P((char *, char *)); |
| 4717 | static int TEX_Token __P((char *)); | ||
| 4718 | 4719 | ||
| 4719 | static char TEX_esc = '\\'; | 4720 | static char TEX_esc = '\\'; |
| 4720 | static char TEX_opgrp = '{'; | 4721 | static char TEX_opgrp = '{'; |
| @@ -4727,49 +4728,64 @@ static void | |||
| 4727 | TeX_commands (inf) | 4728 | TeX_commands (inf) |
| 4728 | FILE *inf; | 4729 | FILE *inf; |
| 4729 | { | 4730 | { |
| 4730 | char *cp, *lasthit; | 4731 | char *cp; |
| 4731 | register int i; | 4732 | linebuffer *key; |
| 4732 | 4733 | ||
| 4733 | /* Select either \ or ! as escape character. */ | 4734 | /* Select either \ or ! as escape character. */ |
| 4734 | TEX_mode (inf); | 4735 | TEX_mode (inf); |
| 4735 | 4736 | ||
| 4736 | /* Initialize token table once from environment. */ | 4737 | /* Initialize token table once from environment. */ |
| 4737 | if (!TEX_toktab) | 4738 | if (TEX_toktab == NULL) |
| 4738 | TEX_toktab = TEX_decode_env ("TEXTAGS", TEX_defenv); | 4739 | TEX_decode_env ("TEXTAGS", TEX_defenv); |
| 4739 | 4740 | ||
| 4740 | LOOP_ON_INPUT_LINES (inf, lb, cp) | 4741 | LOOP_ON_INPUT_LINES (inf, lb, cp) |
| 4741 | { | 4742 | { |
| 4742 | lasthit = cp; | 4743 | /* Look at each TEX keyword in line. */ |
| 4743 | /* Look at each esc in line. */ | 4744 | for (;;) |
| 4744 | while ((cp = etags_strchr (cp, TEX_esc)) != NULL) | ||
| 4745 | { | 4745 | { |
| 4746 | if (*++cp == '\0') | 4746 | /* Look for a TEX escape. */ |
| 4747 | break; | 4747 | while (*cp++ != TEX_esc) |
| 4748 | linecharno += cp - lasthit; | 4748 | if (cp[-1] == '\0' || cp[-1] == '%') |
| 4749 | lasthit = cp; | 4749 | goto tex_next_line; |
| 4750 | i = TEX_Token (lasthit); | 4750 | |
| 4751 | if (i >= 0) | 4751 | for (key = TEX_toktab; key->buffer != NULL; key++) |
| 4752 | { | 4752 | if (strneq (cp, key->buffer, key->len)) |
| 4753 | register char *p; | 4753 | { |
| 4754 | for (lasthit += TEX_toktab[i].len; | 4754 | register char *p; |
| 4755 | *lasthit == TEX_esc || *lasthit == TEX_opgrp; | 4755 | char *name; |
| 4756 | lasthit++) | 4756 | int linelen; |
| 4757 | continue; | 4757 | bool opgrp = FALSE; |
| 4758 | for (p = lasthit; | 4758 | |
| 4759 | !iswhite (*p) && *p != TEX_opgrp && *p != TEX_clgrp; | 4759 | cp = skip_spaces (cp + key->len); |
| 4760 | p++) | 4760 | if (*cp == TEX_opgrp) |
| 4761 | continue; | 4761 | { |
| 4762 | pfnote (savenstr (lasthit, p-lasthit), TRUE, | 4762 | opgrp = TRUE; |
| 4763 | lb.buffer, lb.len, lineno, linecharno); | 4763 | cp++; |
| 4764 | break; /* We only tag a line once */ | 4764 | } |
| 4765 | } | 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 | } | ||
| 4766 | } | 4781 | } |
| 4782 | tex_next_line: | ||
| 4783 | ; | ||
| 4767 | } | 4784 | } |
| 4768 | } | 4785 | } |
| 4769 | 4786 | ||
| 4770 | #define TEX_LESC '\\' | 4787 | #define TEX_LESC '\\' |
| 4771 | #define TEX_SESC '!' | 4788 | #define TEX_SESC '!' |
| 4772 | #define TEX_cmt '%' | ||
| 4773 | 4789 | ||
| 4774 | /* Figure out whether TeX's escapechar is '\\' or '!' and set grouping | 4790 | /* Figure out whether TeX's escapechar is '\\' or '!' and set grouping |
| 4775 | chars accordingly. */ | 4791 | chars accordingly. */ |
| @@ -4782,7 +4798,7 @@ TEX_mode (inf) | |||
| 4782 | while ((c = getc (inf)) != EOF) | 4798 | while ((c = getc (inf)) != EOF) |
| 4783 | { | 4799 | { |
| 4784 | /* Skip to next line if we hit the TeX comment char. */ | 4800 | /* Skip to next line if we hit the TeX comment char. */ |
| 4785 | if (c == TEX_cmt) | 4801 | if (c == '%') |
| 4786 | while (c != '\n') | 4802 | while (c != '\n') |
| 4787 | c = getc (inf); | 4803 | c = getc (inf); |
| 4788 | else if (c == TEX_LESC || c == TEX_SESC ) | 4804 | else if (c == TEX_LESC || c == TEX_SESC ) |
| @@ -4808,15 +4824,13 @@ TEX_mode (inf) | |||
| 4808 | 4824 | ||
| 4809 | /* Read environment and prepend it to the default string. | 4825 | /* Read environment and prepend it to the default string. |
| 4810 | Build token table. */ | 4826 | Build token table. */ |
| 4811 | static struct TEX_tabent * | 4827 | static void |
| 4812 | TEX_decode_env (evarname, defenv) | 4828 | TEX_decode_env (evarname, defenv) |
| 4813 | char *evarname; | 4829 | char *evarname; |
| 4814 | char *defenv; | 4830 | char *defenv; |
| 4815 | { | 4831 | { |
| 4816 | register char *env, *p; | 4832 | register char *env, *p; |
| 4817 | 4833 | int i, len; | |
| 4818 | struct TEX_tabent *tab; | ||
| 4819 | int size, i; | ||
| 4820 | 4834 | ||
| 4821 | /* Append default string to environment. */ | 4835 | /* Append default string to environment. */ |
| 4822 | env = getenv (evarname); | 4836 | env = getenv (evarname); |
| @@ -4829,52 +4843,33 @@ TEX_decode_env (evarname, defenv) | |||
| 4829 | } | 4843 | } |
| 4830 | 4844 | ||
| 4831 | /* Allocate a token table */ | 4845 | /* Allocate a token table */ |
| 4832 | for (size = 1, p = env; p;) | 4846 | for (len = 1, p = env; p;) |
| 4833 | if ((p = etags_strchr (p, ':')) && *++p != '\0') | 4847 | if ((p = etags_strchr (p, ':')) && *++p != '\0') |
| 4834 | size++; | 4848 | len++; |
| 4835 | /* Add 1 to leave room for null terminator. */ | 4849 | TEX_toktab = xnew (len, linebuffer); |
| 4836 | tab = xnew (size + 1, struct TEX_tabent); | ||
| 4837 | 4850 | ||
| 4838 | /* Unpack environment string into token table. Be careful about */ | 4851 | /* Unpack environment string into token table. Be careful about */ |
| 4839 | /* zero-length strings (leading ':', "::" and trailing ':') */ | 4852 | /* zero-length strings (leading ':', "::" and trailing ':') */ |
| 4840 | for (i = 0; *env;) | 4853 | for (i = 0; *env != '\0';) |
| 4841 | { | 4854 | { |
| 4842 | p = etags_strchr (env, ':'); | 4855 | p = etags_strchr (env, ':'); |
| 4843 | if (!p) /* End of environment string. */ | 4856 | if (!p) /* End of environment string. */ |
| 4844 | p = env + strlen (env); | 4857 | p = env + strlen (env); |
| 4845 | if (p - env > 0) | 4858 | if (p - env > 0) |
| 4846 | { /* Only non-zero strings. */ | 4859 | { /* Only non-zero strings. */ |
| 4847 | tab[i].name = savenstr (env, p - env); | 4860 | TEX_toktab[i].buffer = savenstr (env, p - env); |
| 4848 | tab[i].len = strlen (tab[i].name); | 4861 | TEX_toktab[i].len = p - env; |
| 4849 | i++; | 4862 | i++; |
| 4850 | } | 4863 | } |
| 4851 | if (*p) | 4864 | if (*p) |
| 4852 | env = p + 1; | 4865 | env = p + 1; |
| 4853 | else | 4866 | else |
| 4854 | { | 4867 | { |
| 4855 | tab[i].name = NULL; /* Mark end of table. */ | 4868 | TEX_toktab[i].buffer = NULL; /* Mark end of table. */ |
| 4856 | tab[i].len = 0; | 4869 | TEX_toktab[i].len = 0; |
| 4857 | break; | 4870 | break; |
| 4858 | } | 4871 | } |
| 4859 | } | 4872 | } |
| 4860 | return tab; | ||
| 4861 | } | ||
| 4862 | |||
| 4863 | /* If the text at CP matches one of the tag-defining TeX command names, | ||
| 4864 | return the pointer to the first occurrence of that command in TEX_toktab. | ||
| 4865 | Otherwise return -1. | ||
| 4866 | Keep the capital `T' in `token' for dumb truncating compilers | ||
| 4867 | (this distinguishes it from `TEX_toktab' */ | ||
| 4868 | static int | ||
| 4869 | TEX_Token (cp) | ||
| 4870 | char *cp; | ||
| 4871 | { | ||
| 4872 | int i; | ||
| 4873 | |||
| 4874 | for (i = 0; TEX_toktab[i].len > 0; i++) | ||
| 4875 | if (strneq (TEX_toktab[i].name, cp, TEX_toktab[i].len)) | ||
| 4876 | return i; | ||
| 4877 | return -1; | ||
| 4878 | } | 4873 | } |
| 4879 | 4874 | ||
| 4880 | 4875 | ||