aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorFrancesco Potortì1997-05-30 14:53:42 +0000
committerFrancesco Potortì1997-05-30 14:53:42 +0000
commit309032468c14b17ac48763377be5dc1dbb3867d3 (patch)
tree85bb07442400ee13b845b83cec7a3db621887b02 /lib-src
parent9d3d895d11ee6d4be5c3fb300aef74a4554dc5be (diff)
downloademacs-309032468c14b17ac48763377be5dc1dbb3867d3.tar.gz
emacs-309032468c14b17ac48763377be5dc1dbb3867d3.zip
Various cleanups on TeX, Erlang, Prolog, C.
New function new_pfnote will be used for "optimised tags", but it depends on a constant that disables it for now. New possibility of tagging global variables in C/C++/ObjC/Java is enabled by default. Tags of member variables is disabled by default. Options --(no-)members and --(no-)globals control them. New symbol table entries for "import", "package" and "friend".
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c1007
1 files changed, 577 insertions, 430 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 5ef118c6870..a9e35d34139 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -31,7 +31,7 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 * Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer. 31 * Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer.
32 */ 32 */
33 33
34char pot_etags_version[] = "@(#) pot revision number is 11.91"; 34char pot_etags_version[] = "@(#) pot revision number is 12.11";
35 35
36#define TRUE 1 36#define TRUE 1
37#define FALSE 0 37#define FALSE 0
@@ -40,10 +40,6 @@ char pot_etags_version[] = "@(#) pot revision number is 11.91";
40# define DEBUG FALSE 40# define DEBUG FALSE
41#endif 41#endif
42 42
43#ifndef TeX_named_tokens
44# define TeX_named_tokens FALSE
45#endif
46
47#ifdef MSDOS 43#ifdef MSDOS
48# include <string.h> 44# include <string.h>
49# include <fcntl.h> 45# include <fcntl.h>
@@ -63,6 +59,8 @@ char pot_etags_version[] = "@(#) pot revision number is 11.91";
63 /* On some systems, Emacs defines static as nothing for the sake 59 /* On some systems, Emacs defines static as nothing for the sake
64 of unexec. We don't want that here since we don't use unexec. */ 60 of unexec. We don't want that here since we don't use unexec. */
65# undef static 61# undef static
62# define ETAGS_REGEXPS
63# define LONG_OPTIONS
66#endif 64#endif
67 65
68#if !defined (MSDOS) && !defined (WINDOWSNT) && defined (STDC_HEADERS) 66#if !defined (MSDOS) && !defined (WINDOWSNT) && defined (STDC_HEADERS)
@@ -83,7 +81,13 @@ extern int errno;
83# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 81# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
84#endif 82#endif
85 83
86#include <getopt.h> 84#ifdef LONG_OPTIONS
85# include <getopt.h>
86#else
87# define getopt_long(argc,argv,optstr,lopts,lind) getopt (argc, argv, optstr)
88 extern char *optarg;
89 extern int optind, opterr;
90#endif /* LONG_OPTIONS */
87 91
88#ifdef ETAGS_REGEXPS 92#ifdef ETAGS_REGEXPS
89# include <regex.h> 93# include <regex.h>
@@ -121,10 +125,13 @@ extern int errno;
121 125
122#define lowcase(c) tolower ((char)c) 126#define lowcase(c) tolower ((char)c)
123 127
124#define iswhite(arg) (_wht[arg]) /* T if char is white */ 128#define CHARS 256 /* 2^sizeof(char) */
125#define begtoken(arg) (_btk[arg]) /* T if char can start token */ 129#define CHAR(x) ((int)x & (CHARS - 1))
126#define intoken(arg) (_itk[arg]) /* T if char can be in token */ 130#define iswhite(c) (_wht[CHAR(c)]) /* c is white */
127#define endtoken(arg) (_etk[arg]) /* T if char ends tokens */ 131#define notinname(c) (_nin[CHAR(c)]) /* c is not in a name */
132#define begtoken(c) (_btk[CHAR(c)]) /* c can start token */
133#define intoken(c) (_itk[CHAR(c)]) /* c can be in token */
134#define endtoken(c) (_etk[CHAR(c)]) /* c ends tokens */
128 135
129#ifdef DOS_NT 136#ifdef DOS_NT
130# define absolutefn(fn) (fn[0] == '/' \ 137# define absolutefn(fn) (fn[0] == '/' \
@@ -147,14 +154,14 @@ extern int errno;
147# define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type))) 154# define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
148#endif 155#endif
149 156
150typedef int logical; 157typedef int bool;
151 158
152typedef struct nd_st 159typedef struct nd_st
153{ /* sorting structure */ 160{ /* sorting structure */
154 char *name; /* function or type name */ 161 char *name; /* function or type name */
155 char *file; /* file name */ 162 char *file; /* file name */
156 logical is_func; /* use pattern or line no */ 163 bool is_func; /* use pattern or line no */
157 logical been_warned; /* set if noticed dup */ 164 bool been_warned; /* set if noticed dup */
158 int lno; /* line number tag is on */ 165 int lno; /* line number tag is on */
159 long cno; /* character number line starts on */ 166 long cno; /* character number line starts on */
160 char *pat; /* search pattern */ 167 char *pat; /* search pattern */
@@ -172,30 +179,15 @@ void grow_linebuffer ();
172long *xmalloc (), *xrealloc (); 179long *xmalloc (), *xrealloc ();
173 180
174typedef void Lang_function (); 181typedef void Lang_function ();
175#if FALSE /* many compilers barf on this */ 182/* Many compilers barf on this:
176Lang_function Asm_labels; 183 Lang_function Asm_labels;
177Lang_function default_C_entries; 184 so let's write it this way */
178Lang_function C_entries;
179Lang_function Cplusplus_entries;
180Lang_function Cjava_entries;
181Lang_function Cstar_entries;
182Lang_function Erlang_functions;
183Lang_function Fortran_functions;
184Lang_function Yacc_entries;
185Lang_function Lisp_functions;
186Lang_function Pascal_functions;
187Lang_function Perl_functions;
188Lang_function Postscript_functions;
189Lang_function Prolog_functions;
190Lang_function Scheme_functions;
191Lang_function TeX_functions;
192Lang_function just_read_file;
193#else /* so let's write it this way */
194void Asm_labels (); 185void Asm_labels ();
195void C_entries (); 186void C_entries ();
196void default_C_entries (); 187void default_C_entries ();
197void plain_C_entries (); 188void plain_C_entries ();
198void Cjava_entries (); 189void Cjava_entries ();
190void Cobol_paragraphs ();
199void Cplusplus_entries (); 191void Cplusplus_entries ();
200void Cstar_entries (); 192void Cstar_entries ();
201void Erlang_functions (); 193void Erlang_functions ();
@@ -209,7 +201,6 @@ void Prolog_functions ();
209void Scheme_functions (); 201void Scheme_functions ();
210void TeX_functions (); 202void TeX_functions ();
211void just_read_file (); 203void just_read_file ();
212#endif
213 204
214Lang_function *get_language_from_name (); 205Lang_function *get_language_from_name ();
215Lang_function *get_language_from_interpreter (); 206Lang_function *get_language_from_interpreter ();
@@ -220,7 +211,7 @@ long readline_internal ();
220#ifdef ETAGS_REGEXPS 211#ifdef ETAGS_REGEXPS
221void analyse_regex (); 212void analyse_regex ();
222void add_regex (); 213void add_regex ();
223#endif 214#endif /* ETAGS_REGEXPS */
224void add_node (); 215void add_node ();
225void error (); 216void error ();
226void suggest_asking_for_help (); 217void suggest_asking_for_help ();
@@ -230,7 +221,7 @@ void free_tree ();
230void getit (); 221void getit ();
231void init (); 222void init ();
232void initbuffer (); 223void initbuffer ();
233void pfnote (); 224void pfnote (), new_pfnote ();
234void process_file (); 225void process_file ();
235void put_entries (); 226void put_entries ();
236void takeprec (); 227void takeprec ();
@@ -274,57 +265,69 @@ struct
274} lbs[2]; 265} lbs[2];
275 266
276/* boolean "functions" (see init) */ 267/* boolean "functions" (see init) */
277logical _wht[0177], _etk[0177], _itk[0177], _btk[0177]; 268bool _wht[CHARS], _nin[CHARS], _itk[CHARS], _btk[CHARS], _etk[CHARS];
278char 269char
279 /* white chars */ 270 /* white chars */
280 *white = " \f\t\n\013", 271 *white = " \f\t\n\013",
272 /* not in a name */
273 *nonam =" \f\t\n\013(=,[;",
281 /* token ending chars */ 274 /* token ending chars */
282 *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?", 275 *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?",
283 /* token starting chars */ 276 /* token starting chars */
284 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@", 277 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@",
285 /* valid in-token chars */ 278 /* valid in-token chars */
286 *intk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789"; 279 *midtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789";
287 280
288logical append_to_tagfile; /* -a: append to tags */ 281bool append_to_tagfile; /* -a: append to tags */
289/* The following three default to TRUE for etags, but to FALSE for ctags. */ 282/* The following four default to TRUE for etags, but to FALSE for ctags. */
290logical typedefs; /* -t: create tags for typedefs */ 283bool typedefs; /* -t: create tags for C typedefs */
291logical typedefs_and_cplusplus; /* -T: create tags for typedefs, level */ 284bool typedefs_and_cplusplus; /* -T: create tags for C typedefs, level */
292 /* 0 struct/enum/union decls, and C++ */ 285 /* 0 struct/enum/union decls, and C++ */
293 /* member functions. */ 286 /* member functions. */
294logical constantypedefs; /* -d: create tags for C #define and enum */ 287bool constantypedefs; /* -d: create tags for C #define, enum */
295 /* constants. */ 288 /* constants and variables. */
296 /* -D: opposite of -d. Default under ctags. */ 289 /* -D: opposite of -d. Default under ctags. */
297logical update; /* -u: update tags */ 290bool globals; /* create tags for C global variables */
298logical vgrind_style; /* -v: create vgrind style index output */ 291bool members; /* create tags for C member variables */
299logical no_warnings; /* -w: suppress warnings */ 292bool update; /* -u: update tags */
300logical cxref_style; /* -x: create cxref style output */ 293bool vgrind_style; /* -v: create vgrind style index output */
301logical cplusplus; /* .[hc] means C++, not C */ 294bool no_warnings; /* -w: suppress warnings */
302logical noindentypedefs; /* -I: ignore indentation in C */ 295bool cxref_style; /* -x: create cxref style output */
303 296bool cplusplus; /* .[hc] means C++, not C */
297bool noindentypedefs; /* -I: ignore indentation in C */
298
299#ifdef LONG_OPTIONS
304struct option longopts[] = 300struct option longopts[] =
305{ 301{
306 { "append", no_argument, NULL, 'a' }, 302 { "append", no_argument, NULL, 'a' },
307 { "backward-search", no_argument, NULL, 'B' }, 303 { "backward-search", no_argument, NULL, 'B' },
308 { "c++", no_argument, NULL, 'C' }, 304 { "c++", no_argument, NULL, 'C' },
309 { "cxref", no_argument, NULL, 'x' }, 305 { "cxref", no_argument, NULL, 'x' },
310 { "defines", no_argument, NULL, 'd' }, 306 { "defines", no_argument, NULL, 'd' },
311 { "help", no_argument, NULL, 'h' }, 307 { "no-defines", no_argument, NULL, 'D' },
312 { "help", no_argument, NULL, 'H' }, 308 { "globals", no_argument, &globals, TRUE },
313 { "ignore-indentation", no_argument, NULL, 'I' }, 309 { "no-globals", no_argument, &globals, FALSE },
314 { "include", required_argument, NULL, 'i' }, 310 { "help", no_argument, NULL, 'h' },
315 { "language", required_argument, NULL, 'l' }, 311 { "help", no_argument, NULL, 'H' },
316 { "no-defines", no_argument, NULL, 'D' }, 312 { "ignore-indentation", no_argument, NULL, 'I' },
317 { "no-regex", no_argument, NULL, 'R' }, 313 { "include", required_argument, NULL, 'i' },
318 { "no-warn", no_argument, NULL, 'w' }, 314 { "language", required_argument, NULL, 'l' },
319 { "output", required_argument, NULL, 'o' }, 315 { "members", no_argument, &members, TRUE },
320 { "regex", required_argument, NULL, 'r' }, 316 { "no-members", no_argument, &members, FALSE },
321 { "typedefs", no_argument, NULL, 't' }, 317 { "no-warn", no_argument, NULL, 'w' },
322 { "typedefs-and-c++", no_argument, NULL, 'T' }, 318 { "output", required_argument, NULL, 'o' },
323 { "update", no_argument, NULL, 'u' }, 319#ifdef ETAGS_REGEXPS
324 { "version", no_argument, NULL, 'V' }, 320 { "regex", required_argument, NULL, 'r' },
325 { "vgrind", no_argument, NULL, 'v' }, 321 { "no-regex", no_argument, NULL, 'R' },
322#endif /* ETAGS_REGEXPS */
323 { "typedefs", no_argument, NULL, 't' },
324 { "typedefs-and-c++", no_argument, NULL, 'T' },
325 { "update", no_argument, NULL, 'u' },
326 { "version", no_argument, NULL, 'V' },
327 { "vgrind", no_argument, NULL, 'v' },
326 { 0 } 328 { 0 }
327}; 329};
330#endif /* LONG_OPTIONS */
328 331
329#ifdef ETAGS_REGEXPS 332#ifdef ETAGS_REGEXPS
330/* Structure defining a regular expression. Elements are 333/* Structure defining a regular expression. Elements are
@@ -334,7 +337,7 @@ struct pattern
334 struct re_pattern_buffer *pattern; 337 struct re_pattern_buffer *pattern;
335 struct re_registers regs; 338 struct re_registers regs;
336 char *name_pattern; 339 char *name_pattern;
337 logical error_signaled; 340 bool error_signaled;
338}; 341};
339 342
340/* Number of regexps found. */ 343/* Number of regexps found. */
@@ -376,6 +379,9 @@ char *Cplusplus_suffixes [] =
376char *Cjava_suffixes [] = 379char *Cjava_suffixes [] =
377 { "java", NULL }; 380 { "java", NULL };
378 381
382char *Cobol_suffixes [] =
383 { "COB", "cob", NULL };
384
379char *Cstar_suffixes [] = 385char *Cstar_suffixes [] =
380 { "cs", "hs", NULL }; 386 { "cs", "hs", NULL };
381 387
@@ -436,6 +442,7 @@ struct lang_entry lang_names [] =
436 { "c", default_C_entries, default_C_suffixes, NULL }, 442 { "c", default_C_entries, default_C_suffixes, NULL },
437 { "c++", Cplusplus_entries, Cplusplus_suffixes, NULL }, 443 { "c++", Cplusplus_entries, Cplusplus_suffixes, NULL },
438 { "c*", Cstar_entries, Cstar_suffixes, NULL }, 444 { "c*", Cstar_entries, Cstar_suffixes, NULL },
445 { "cobol", Cobol_paragraphs, Cobol_suffixes, NULL },
439 { "erlang", Erlang_functions, Erlang_suffixes, NULL }, 446 { "erlang", Erlang_functions, Erlang_suffixes, NULL },
440 { "fortran", Fortran_functions, Fortran_suffixes, NULL }, 447 { "fortran", Fortran_functions, Fortran_suffixes, NULL },
441 { "java", Cjava_entries, Cjava_suffixes, NULL }, 448 { "java", Cjava_entries, Cjava_suffixes, NULL },
@@ -494,9 +501,16 @@ print_version ()
494void 501void
495print_help () 502print_help ()
496{ 503{
497 printf ("These are the options accepted by %s. You may use unambiguous\n\ 504 printf ("Usage: %s [options] [[regex-option ...] file-name] ...\n\
498abbreviations for the long option names. A - as file name means read\n\ 505\n\
499names from stdin.", progname); 506These are the options accepted by %s.\n", progname, progname);
507#ifdef LONG_OPTIONS
508 puts ("You may use unambiguous abbreviations for the long option names.");
509#else
510 puts ("Long option names do not work with this executable, as it is not\n\
511linked with GNU getopt.");
512#endif /* LONG_OPTIONS */
513 puts ("A - as file name means read names from stdin.");
500 if (!CTAGS) 514 if (!CTAGS)
501 printf (" Absolute names are stored in the output file as they\n\ 515 printf (" Absolute names are stored in the output file as they\n\
502are. Relative ones are stored relative to the output file's directory."); 516are. Relative ones are stored relative to the output file's directory.");
@@ -532,6 +546,16 @@ are. Relative ones are stored relative to the output file's directory.");
532 named language up to the next --language=LANG option."); 546 named language up to the next --language=LANG option.");
533 } 547 }
534 548
549 if (CTAGS)
550 puts ("--globals\n\
551 Create tag entries for global variables in C and derived languages.");
552 else
553 puts ("--no-globals\n\
554 Do not create tag entries for global variables in C and\n\
555 derived languages. This makes the tags file smaller.");
556 puts ("--members\n\
557 Create tag entries for member variables in C and derived languages.");
558
535#ifdef ETAGS_REGEXPS 559#ifdef ETAGS_REGEXPS
536 puts ("-r /REGEXP/, --regex=/REGEXP/ or --regex=@regexfile\n\ 560 puts ("-r /REGEXP/, --regex=/REGEXP/ or --regex=@regexfile\n\
537 Make a tag for each line matching pattern REGEXP in the\n\ 561 Make a tag for each line matching pattern REGEXP in the\n\
@@ -648,7 +672,7 @@ fn_exp (out, in)
648 static long context = 0; 672 static long context = 0;
649 static struct dsc$descriptor_s o; 673 static struct dsc$descriptor_s o;
650 static struct dsc$descriptor_s i; 674 static struct dsc$descriptor_s i;
651 static logical pass1 = TRUE; 675 static bool pass1 = TRUE;
652 long status; 676 long status;
653 short retval; 677 short retval;
654 678
@@ -688,7 +712,7 @@ fn_exp (out, in)
688char * 712char *
689gfnames (arg, p_error) 713gfnames (arg, p_error)
690 char *arg; 714 char *arg;
691 logical *p_error; 715 bool *p_error;
692{ 716{
693 static vspec filename = {MAX_FILE_SPEC_LEN, "\0"}; 717 static vspec filename = {MAX_FILE_SPEC_LEN, "\0"};
694 718
@@ -746,7 +770,7 @@ main (argc, argv)
746 int current_arg, file_count; 770 int current_arg, file_count;
747 struct linebuffer filename_lb; 771 struct linebuffer filename_lb;
748#ifdef VMS 772#ifdef VMS
749 logical got_err; 773 bool got_err;
750#endif 774#endif
751 775
752#ifdef DOS_NT 776#ifdef DOS_NT
@@ -770,16 +794,32 @@ main (argc, argv)
770 794
771 /* 795 /*
772 * If etags, always find typedefs and structure tags. Why not? 796 * If etags, always find typedefs and structure tags. Why not?
773 * Also default is to find macro constants and enum constants. 797 * Also default is to find macro constants, enum constants and
798 * global variables.
774 */ 799 */
775 if (!CTAGS) 800 if (!CTAGS)
776 typedefs = typedefs_and_cplusplus = constantypedefs = TRUE; 801 {
802 typedefs = typedefs_and_cplusplus = constantypedefs = TRUE;
803 globals = TRUE;
804 members = FALSE;
805 }
777 806
778 while (1) 807 while (1)
779 { 808 {
780 int opt = getopt_long (argc, argv, 809 int opt;
781 "-aCdDf:Il:o:r:RStTi:BuvxwVhH", longopts, 0); 810 char *optstring;
811
812#ifdef ETAGS_REGEXPS
813 optstring = "-aCdDf:Il:o:r:RStTi:BuvxwVhH";
814#else
815 optstring = "-aCdDf:Il:o:StTi:BuvxwVhH";
816#endif /* ETAGS_REGEXPS */
817
818#ifndef LONG_OPTIONS
819 optstring = optstring + 1;
820#endif /* LONG_OPTIONS */
782 821
822 opt = getopt_long (argc, argv, optstring, longopts, 0);
783 if (opt == EOF) 823 if (opt == EOF)
784 break; 824 break;
785 825
@@ -799,18 +839,10 @@ main (argc, argv)
799 break; 839 break;
800 840
801 /* Common options. */ 841 /* Common options. */
802 case 'a': 842 case 'a': append_to_tagfile = TRUE; break;
803 append_to_tagfile = TRUE; 843 case 'C': cplusplus = TRUE; break;
804 break; 844 case 'd': constantypedefs = TRUE; break;
805 case 'C': 845 case 'D': constantypedefs = FALSE; break;
806 cplusplus = TRUE;
807 break;
808 case 'd':
809 constantypedefs = TRUE;
810 break;
811 case 'D':
812 constantypedefs = FALSE;
813 break;
814 case 'f': /* for compatibility with old makefiles */ 846 case 'f': /* for compatibility with old makefiles */
815 case 'o': 847 case 'o':
816 if (tagfile) 848 if (tagfile)
@@ -861,21 +893,11 @@ main (argc, argv)
861 break; 893 break;
862#else /* CTAGS */ 894#else /* CTAGS */
863 /* Ctags options. */ 895 /* Ctags options. */
864 case 'B': 896 case 'B': searchar = '?'; break;
865 searchar = '?'; 897 case 'u': update = TRUE; break;
866 break; 898 case 'v': vgrind_style = TRUE; /*FALLTHRU*/
867 case 'u': 899 case 'x': cxref_style = TRUE; break;
868 update = TRUE; 900 case 'w': no_warnings = TRUE; break;
869 break;
870 case 'v':
871 vgrind_style = TRUE;
872 /*FALLTHRU*/
873 case 'x':
874 cxref_style = TRUE;
875 break;
876 case 'w':
877 no_warnings = TRUE;
878 break;
879#endif /* CTAGS */ 901#endif /* CTAGS */
880 default: 902 default:
881 suggest_asking_for_help (); 903 suggest_asking_for_help ();
@@ -892,7 +914,7 @@ main (argc, argv)
892 914
893 if (nincluded_files == 0 && file_count == 0) 915 if (nincluded_files == 0 && file_count == 0)
894 { 916 {
895 error ("%s", "No input files specified."); 917 error ("no input files specified.", 0);
896 suggest_asking_for_help (); 918 suggest_asking_for_help ();
897 } 919 }
898 920
@@ -957,7 +979,7 @@ main (argc, argv)
957 { 979 {
958 if (got_err) 980 if (got_err)
959 { 981 {
960 error ("Can't find file %s\n", this_file); 982 error ("can't find file %s\n", this_file);
961 argc--, argv++; 983 argc--, argv++;
962 } 984 }
963 else 985 else
@@ -1121,12 +1143,12 @@ process_file (file)
1121 1143
1122 if (stat (file, &stat_buf) == 0 && !S_ISREG (stat_buf.st_mode)) 1144 if (stat (file, &stat_buf) == 0 && !S_ISREG (stat_buf.st_mode))
1123 { 1145 {
1124 error ("Skipping %s: it is not a regular file.", file); 1146 error ("skipping %s: it is not a regular file.", file);
1125 return; 1147 return;
1126 } 1148 }
1127 if (streq (file, tagfile) && !streq (tagfile, "-")) 1149 if (streq (file, tagfile) && !streq (tagfile, "-"))
1128 { 1150 {
1129 error ("Skipping inclusion of %s in self.", file); 1151 error ("skipping inclusion of %s in self.", file);
1130 return; 1152 return;
1131 } 1153 }
1132 inf = fopen (file, "r"); 1154 inf = fopen (file, "r");
@@ -1175,20 +1197,13 @@ init ()
1175 register char *sp; 1197 register char *sp;
1176 register int i; 1198 register int i;
1177 1199
1178 for (i = 0; i < 0177; i++) 1200 for (i = 0; i < CHARS; i++)
1179 _wht[i] = _etk[i] = _itk[i] = _btk[i] = FALSE; 1201 _wht[i] = _nin[i] = _etk[i] = _itk[i] = _btk[i] = FALSE;
1180 for (sp = white; *sp; sp++) 1202 for (sp = white; *sp; sp++) _wht[*sp] = TRUE; _wht[0] = _wht['\n'];
1181 _wht[*sp] = TRUE; 1203 for (sp = nonam; *sp; sp++) _nin[*sp] = TRUE; _nin[0] = _nin['\n'];
1182 for (sp = endtk; *sp; sp++) 1204 for (sp = endtk; *sp; sp++) _etk[*sp] = TRUE; _etk[0] = _etk['\n'];
1183 _etk[*sp] = TRUE; 1205 for (sp = midtk; *sp; sp++) _itk[*sp] = TRUE; _btk[0] = _btk['\n'];
1184 for (sp = intk; *sp; sp++) 1206 for (sp = begtk; *sp; sp++) _btk[*sp] = TRUE; _itk[0] = _itk['\n'];
1185 _itk[*sp] = TRUE;
1186 for (sp = begtk; *sp; sp++)
1187 _btk[*sp] = TRUE;
1188 _wht[0] = _wht['\n'];
1189 _etk[0] = _etk['\n'];
1190 _btk[0] = _btk['\n'];
1191 _itk[0] = _itk['\n'];
1192} 1207}
1193 1208
1194/* 1209/*
@@ -1285,7 +1300,7 @@ find_entries (file, inf)
1285void 1300void
1286pfnote (name, is_func, linestart, linelen, lno, cno) 1301pfnote (name, is_func, linestart, linelen, lno, cno)
1287 char *name; /* tag name, or NULL if unnamed */ 1302 char *name; /* tag name, or NULL if unnamed */
1288 logical is_func; /* tag is a function */ 1303 bool is_func; /* tag is a function */
1289 char *linestart; /* start of the line where tag is */ 1304 char *linestart; /* start of the line where tag is */
1290 int linelen; /* length of the line where tag is */ 1305 int linelen; /* length of the line where tag is */
1291 int lno; /* line number */ 1306 int lno; /* line number */
@@ -1333,6 +1348,59 @@ pfnote (name, is_func, linestart, linelen, lno, cno)
1333 add_node (np, &head); 1348 add_node (np, &head);
1334} 1349}
1335 1350
1351/* Date: Wed, 22 Jan 1997 02:56:31 -0500
1352 * From: Sam Kendall <kendall@cybercom.net>
1353 * Subject: Proposal for firming up the TAGS format specification
1354 * To: F.Potorti@cnuce.cnr.it
1355 *
1356 * pfnote should emit the optimized form [unnamed tag] only if:
1357 * 1. name does not contain any of the characters " \t\r\n()";
1358 * 2. linestart contains name as either a rightmost, or rightmost but
1359 * one character, substring;
1360 * 3. the character, if any, immediately before name in linestart must
1361 * be one of the characters " \t()";
1362 * 4. the character, if any, immediately after name in linestart must
1363 * also be one of the characters " \t()".
1364 */
1365#define traditional_tag_style TRUE
1366void
1367new_pfnote (name, namelen, is_func, linestart, linelen, lno, cno)
1368 char *name; /* tag name, or NULL if unnamed */
1369 int namelen; /* tag length */
1370 bool is_func; /* tag is a function */
1371 char *linestart; /* start of the line where tag is */
1372 int linelen; /* length of the line where tag is */
1373 int lno; /* line number */
1374 long cno; /* character number */
1375{
1376 register char *cp;
1377 bool named;
1378
1379 named = TRUE;
1380 if (!CTAGS)
1381 {
1382 for (cp = name; !notinname (*cp); cp++)
1383 continue;
1384 if (*cp == '\0') /* rule #1 */
1385 {
1386 cp = linestart + linelen - namelen;
1387 if (notinname (linestart[linelen-1]))
1388 cp -= 1; /* rule #4 */
1389 if (cp >= linestart /* rule #2 */
1390 && (cp == linestart
1391 || notinname (cp[-1])) /* rule #3 */
1392 && strneq (name, cp, namelen)) /* rule #2 */
1393 named = FALSE; /* use unnamed tag */
1394 }
1395 }
1396
1397 if (named)
1398 name = savenstr (name, namelen);
1399 else
1400 name = NULL;
1401 pfnote (name, is_func, linestart, linelen, lno, cno);
1402}
1403
1336/* 1404/*
1337 * free_tree () 1405 * free_tree ()
1338 * recurse on left children, iterate on right children. 1406 * recurse on left children, iterate on right children.
@@ -1537,9 +1605,12 @@ total_size_of_entries (node)
1537 */ 1605 */
1538enum sym_type 1606enum sym_type
1539{ 1607{
1540 st_none, st_C_objprot, st_C_objimpl, st_C_objend, st_C_gnumacro, 1608 st_none,
1541 st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec, 1609 st_C_objprot, st_C_objimpl, st_C_objend,
1542 st_C_javastruct 1610 st_C_gnumacro,
1611 st_C_ignore,
1612 st_C_javastruct,
1613 st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec
1543}; 1614};
1544 1615
1545/* Feed stuff between (but not including) %[ and %] lines to: 1616/* Feed stuff between (but not including) %[ and %] lines to:
@@ -1551,6 +1622,9 @@ struct C_stab_entry { char *name; int c_ext; enum sym_type type; }
1551@protocol, 0, st_C_objprot 1622@protocol, 0, st_C_objprot
1552@implementation,0, st_C_objimpl 1623@implementation,0, st_C_objimpl
1553@end, 0, st_C_objend 1624@end, 0, st_C_objend
1625import, C_JAVA, st_C_ignore
1626package, C_JAVA, st_C_ignore
1627friend, C_PLPL, st_C_ignore
1554extends, C_JAVA, st_C_javastruct 1628extends, C_JAVA, st_C_javastruct
1555implements, C_JAVA, st_C_javastruct 1629implements, C_JAVA, st_C_javastruct
1556class, C_PLPL, st_C_struct 1630class, C_PLPL, st_C_struct
@@ -1591,6 +1665,7 @@ PSEUDO, 0, st_C_gnumacro
1591%] 1665%]
1592and replace lines between %< and %> with its output. */ 1666and replace lines between %< and %> with its output. */
1593/*%<*/ 1667/*%<*/
1668/* starting time is 10:31:16 */
1594/* C code produced by gperf version 2.1 (K&R C version) */ 1669/* C code produced by gperf version 2.1 (K&R C version) */
1595/* Command-line: gperf -c -k 1,3 -o -p -r -t */ 1670/* Command-line: gperf -c -k 1,3 -o -p -r -t */
1596 1671
@@ -1599,33 +1674,33 @@ struct C_stab_entry { char *name; int c_ext; enum sym_type type; };
1599 1674
1600#define MIN_WORD_LENGTH 3 1675#define MIN_WORD_LENGTH 3
1601#define MAX_WORD_LENGTH 15 1676#define MAX_WORD_LENGTH 15
1602#define MIN_HASH_VALUE 33 1677#define MIN_HASH_VALUE 15
1603#define MAX_HASH_VALUE 126 1678#define MAX_HASH_VALUE 128
1604/* 1679/*
1605 36 keywords 1680 39 keywords
1606 94 is the maximum key range 1681 114 is the maximum key range
1607*/ 1682*/
1608 1683
1609int 1684static int
1610hash (str, len) 1685hash (str, len)
1611 register char *str; 1686 register char *str;
1612 register unsigned int len; 1687 register unsigned int len;
1613{ 1688{
1614 static unsigned char hash_table[] = 1689 static unsigned char hash_table[] =
1615 { 1690 {
1616 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 1691 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
1617 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 1692 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
1618 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 1693 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
1619 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 1694 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
1620 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 1695 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
1621 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 1696 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
1622 126, 126, 126, 126, 15, 126, 126, 126, 53, 24, 1697 128, 128, 128, 128, 39, 128, 128, 128, 54, 48,
1623 41, 126, 126, 126, 126, 126, 126, 126, 126, 126, 1698 46, 128, 128, 128, 128, 128, 128, 128, 128, 128,
1624 51, 126, 126, 26, 47, 126, 126, 126, 126, 126, 1699 28, 128, 128, 40, 32, 128, 128, 128, 128, 128,
1625 126, 126, 126, 126, 126, 126, 126, 11, 36, 26, 1700 128, 128, 128, 128, 128, 128, 128, 24, 30, 47,
1626 35, 13, 22, 39, 126, 34, 126, 126, 43, 21, 1701 62, 7, 60, 27, 128, 60, 128, 128, 59, 16,
1627 36, 6, 49, 126, 47, 61, 28, 57, 35, 126, 1702 31, 23, 45, 128, 4, 14, 2, 55, 5, 128,
1628 126, 126, 126, 126, 126, 126, 126, 126, 1703 128, 128, 128, 128, 128, 128, 128, 128,
1629 }; 1704 };
1630 return len + hash_table[str[2]] + hash_table[str[0]]; 1705 return len + hash_table[str[2]] + hash_table[str[0]];
1631} 1706}
@@ -1639,64 +1714,71 @@ in_word_set (str, len)
1639 static struct C_stab_entry wordlist[] = 1714 static struct C_stab_entry wordlist[] =
1640 { 1715 {
1641 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 1716 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1642 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1643 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1644 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 1717 {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1645 {"float", 0, st_C_typespec},
1646 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1647 {"char", 0, st_C_typespec},
1648 {"class", C_PLPL, st_C_struct},
1649 {"auto", 0, st_C_typespec},
1650 {"",}, {"",},
1651 {"bool", C_PLPL, st_C_typespec},
1652 {"extern", 0, st_C_typespec}, 1718 {"extern", 0, st_C_typespec},
1653 {"extends", C_JAVA, st_C_javastruct}, 1719 {"extends", C_JAVA, st_C_javastruct},
1654 {"",}, {"",}, 1720 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1655 {"@implementation", 0, st_C_objimpl}, 1721 {"struct", 0, st_C_struct},
1656 {"",}, {"",}, {"",},
1657 {"@end", 0, st_C_objend},
1658 {"mutable", C_PLPL, st_C_typespec}, 1722 {"mutable", C_PLPL, st_C_typespec},
1723 {"",}, {"",}, {"",}, {"",},
1724 {"auto", 0, st_C_typespec},
1725 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1659 {"",}, {"",}, 1726 {"",}, {"",},
1660 {"SYSCALL", 0, st_C_gnumacro}, 1727 {"short", 0, st_C_typespec},
1661 {"",}, 1728 {"",},
1662 {"@interface", 0, st_C_objprot}, 1729 {"static", 0, st_C_typespec},
1663 {"domain", C_STAR, st_C_struct}, 1730 {"",}, {"",},
1664 {"define", 0, st_C_define}, 1731 {"signed", 0, st_C_typespec},
1732 {"",}, {"",}, {"",}, {"",},
1733 {"@protocol", 0, st_C_objprot},
1665 {"",}, 1734 {"",},
1666 {"int", 0, st_C_typespec}, 1735 {"typedef", 0, st_C_typedef},
1736 {"typename", C_PLPL, st_C_typespec},
1667 {"namespace", C_PLPL, st_C_struct}, 1737 {"namespace", C_PLPL, st_C_struct},
1668 {"const", 0, st_C_typespec}, 1738 {"bool", C_PLPL, st_C_typespec},
1669 {"",}, {"",}, 1739 {"",}, {"",},
1670 {"explicit", C_PLPL, st_C_typespec}, 1740 {"explicit", C_PLPL, st_C_typespec},
1671 {"@protocol", 0, st_C_objprot}, 1741 {"",}, {"",}, {"",}, {"",},
1672 {"short", 0, st_C_typespec}, 1742 {"int", 0, st_C_typespec},
1673 {"void", 0, st_C_typespec},
1674 {"enum", 0, st_C_enum}, 1743 {"enum", 0, st_C_enum},
1744 {"",}, {"",},
1745 {"void", 0, st_C_typespec},
1746 {"@implementation", 0, st_C_objimpl},
1675 {"",}, 1747 {"",},
1676 {"ENTRY", 0, st_C_gnumacro}, 1748 {"volatile", 0, st_C_typespec},
1677 {"",}, 1749 {"",},
1678 {"static", 0, st_C_typespec}, 1750 {"@end", 0, st_C_objend},
1751 {"char", 0, st_C_typespec},
1752 {"class", C_PLPL, st_C_struct},
1753 {"unsigned", 0, st_C_typespec},
1679 {"",}, {"",}, 1754 {"",}, {"",},
1755 {"@interface", 0, st_C_objprot},
1756 {"",},
1680 {"PSEUDO", 0, st_C_gnumacro}, 1757 {"PSEUDO", 0, st_C_gnumacro},
1758 {"const", 0, st_C_typespec},
1759 {"domain", C_STAR, st_C_struct},
1760 {"ENTRY", 0, st_C_gnumacro},
1681 {"",}, 1761 {"",},
1762 {"SYSCALL", 0, st_C_gnumacro},
1763 {"float", 0, st_C_typespec},
1764 {"",}, {"",}, {"",}, {"",}, {"",},
1682 {"long", 0, st_C_typespec}, 1765 {"long", 0, st_C_typespec},
1683 {"typedef", 0, st_C_typedef}, 1766 {"",}, {"",}, {"",}, {"",},
1684 {"typename", C_PLPL, st_C_typespec}, 1767 {"package", C_JAVA, st_C_ignore},
1685 {"volatile", 0, st_C_typespec}, 1768 {"",}, {"",}, {"",}, {"",}, {"",},
1686 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 1769 {"DEFUN", 0, st_C_gnumacro},
1770 {"",}, {"",}, {"",}, {"",}, {"",},
1771 {"import", C_JAVA, st_C_ignore},
1772 {"",}, {"",}, {"",},
1687 {"implements", C_JAVA, st_C_javastruct}, 1773 {"implements", C_JAVA, st_C_javastruct},
1688 {"",}, {"",}, 1774 {"",}, {"",}, {"",}, {"",},
1689 {"union", 0, st_C_struct}, 1775 {"union", 0, st_C_struct},
1690 {"",}, 1776 {"",}, {"",},
1691 {"double", 0, st_C_typespec}, 1777 {"double", 0, st_C_typespec},
1692 {"DEFUN", 0, st_C_gnumacro},
1693 {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1694 {"signed", 0, st_C_typespec},
1695 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1696 {"struct", 0, st_C_struct},
1697 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1698 {"",}, {"",}, 1778 {"",}, {"",},
1699 {"unsigned", 0, st_C_typespec}, 1779 {"friend", C_PLPL, st_C_ignore},
1780 {"",},
1781 {"define", 0, st_C_define},
1700 }; 1782 };
1701 1783
1702 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) 1784 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
@@ -1713,6 +1795,7 @@ in_word_set (str, len)
1713 } 1795 }
1714 return 0; 1796 return 0;
1715} 1797}
1798/* ending time is 10:31:16 */
1716/*%>*/ 1799/*%>*/
1717 1800
1718enum sym_type 1801enum sym_type
@@ -1729,18 +1812,19 @@ C_symtype (str, len, c_ext)
1729} 1812}
1730 1813
1731 /* 1814 /*
1732 * C functions are recognized using a simple finite automaton. 1815 * C functions and variables are recognized using a simple
1733 * funcdef is its state variable. 1816 * finite automaton. fvdef is its state variable.
1734 */ 1817 */
1735enum 1818enum
1736{ 1819{
1737 fnone, /* nothing seen */ 1820 fvnone, /* nothing seen */
1738 ftagseen, /* function-like tag seen */ 1821 fvnameseen, /* function or variable name seen */
1739 fstartlist, /* just after open parenthesis */ 1822 fstartlist, /* func: just after open parenthesis */
1740 finlist, /* in parameter list */ 1823 finlist, /* func: in parameter list */
1741 flistseen, /* after parameter list */ 1824 flistseen, /* func: after parameter list */
1742 fignore /* before open brace */ 1825 fignore, /* func: before open brace */
1743} funcdef; 1826 vignore /* var-like: ignore until ';' */
1827} fvdef;
1744 1828
1745 1829
1746 /* 1830 /*
@@ -1815,16 +1899,34 @@ enum
1815 oignore /* wait for @end */ 1899 oignore /* wait for @end */
1816} objdef; 1900} objdef;
1817 1901
1902
1903/*
1904 * Use this structure to keep info about the token read, and how it
1905 * should be tagged. Used by the make_C_tag function to build a tag.
1906 */
1907typedef struct
1908{
1909 bool valid;
1910 char *str;
1911 bool named;
1912 int linelen;
1913 int lineno;
1914 long linepos;
1915 char *buffer;
1916} TOKEN;
1917TOKEN tok; /* latest token read */
1918
1919
1818/* 1920/*
1819 * Set this to TRUE, and the next token considered is called a function. 1921 * Set this to TRUE, and the next token considered is called a function.
1820 * Used only for GNU emacs's function-defining macros. 1922 * Used only for GNU emacs's function-defining macros.
1821 */ 1923 */
1822logical next_token_is_func; 1924bool next_token_is_func;
1823 1925
1824/* 1926/*
1825 * TRUE in the rules part of a yacc file, FALSE outside (parse as C). 1927 * TRUE in the rules part of a yacc file, FALSE outside (parse as C).
1826 */ 1928 */
1827logical yacc_rules; 1929bool yacc_rules;
1828 1930
1829/* 1931/*
1830 * methodlen is the length of the method name stored in token_name. 1932 * methodlen is the length of the method name stored in token_name.
@@ -1834,8 +1936,8 @@ int methodlen;
1834/* 1936/*
1835 * consider_token () 1937 * consider_token ()
1836 * checks to see if the current token is at the start of a 1938 * checks to see if the current token is at the start of a
1837 * function, or corresponds to a typedef, or is a struct/union/enum 1939 * function or variable, or corresponds to a typedef, or
1838 * tag, or #define, or an enum constant. 1940 * is a struct/union/enum tag, or #define, or an enum constant.
1839 * 1941 *
1840 * *IS_FUNC gets TRUE iff the token is a function or #define macro 1942 * *IS_FUNC gets TRUE iff the token is a function or #define macro
1841 * with args. C_EXT is which language we are looking at. 1943 * with args. C_EXT is which language we are looking at.
@@ -1846,7 +1948,7 @@ int methodlen;
1846 * whatever follows `operator'. 1948 * whatever follows `operator'.
1847 * 1949 *
1848 * Globals 1950 * Globals
1849 * funcdef IN OUT 1951 * fvdef IN OUT
1850 * structdef IN OUT 1952 * structdef IN OUT
1851 * definedef IN OUT 1953 * definedef IN OUT
1852 * typdef IN OUT 1954 * typdef IN OUT
@@ -1854,15 +1956,15 @@ int methodlen;
1854 * next_token_is_func IN OUT 1956 * next_token_is_func IN OUT
1855 */ 1957 */
1856 1958
1857logical 1959bool
1858consider_token (str, len, c, c_ext, cblev, parlev, is_func) 1960consider_token (str, len, c, c_ext, cblev, parlev, is_func_or_var)
1859 register char *str; /* IN: token pointer */ 1961 register char *str; /* IN: token pointer */
1860 register int len; /* IN: token length */ 1962 register int len; /* IN: token length */
1861 register char c; /* IN: first char after the token */ 1963 register char c; /* IN: first char after the token */
1862 int c_ext; /* IN: C extensions mask */ 1964 int c_ext; /* IN: C extensions mask */
1863 int cblev; /* IN: curly brace level */ 1965 int cblev; /* IN: curly brace level */
1864 int parlev; /* IN: parenthesis level */ 1966 int parlev; /* IN: parenthesis level */
1865 logical *is_func; /* OUT: function found */ 1967 bool *is_func_or_var; /* OUT: function or variable found */
1866{ 1968{
1867 enum sym_type toktype = C_symtype (str, len, c_ext); 1969 enum sym_type toktype = C_symtype (str, len, c_ext);
1868 1970
@@ -1890,8 +1992,8 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1890 * and constantypedefs is FALSE. 1992 * and constantypedefs is FALSE.
1891 */ 1993 */
1892 definedef = dignorerest; 1994 definedef = dignorerest;
1893 *is_func = (c == '('); 1995 *is_func_or_var = (c == '(');
1894 if (!*is_func && !constantypedefs) 1996 if (!*is_func_or_var && !constantypedefs)
1895 return FALSE; 1997 return FALSE;
1896 else 1998 else
1897 return TRUE; 1999 return TRUE;
@@ -1911,7 +2013,7 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1911 { 2013 {
1912 if (typedefs) 2014 if (typedefs)
1913 typdef = ttypedseen; 2015 typdef = ttypedseen;
1914 funcdef = fnone; 2016 fvdef = fvnone;
1915 return FALSE; 2017 return FALSE;
1916 } 2018 }
1917 break; 2019 break;
@@ -1969,8 +2071,8 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1969 2071
1970 if (structdef == skeyseen) 2072 if (structdef == skeyseen)
1971 { 2073 {
1972 /* Save the tag for struct/union/class, for functions that may be 2074 /* Save the tag for struct/union/class, for functions and variables
1973 defined inside. */ 2075 that may be defined inside. */
1974 if (structtype == st_C_struct) 2076 if (structtype == st_C_struct)
1975 structtag = savenstr (str, len); 2077 structtag = savenstr (str, len);
1976 else 2078 else
@@ -1979,7 +2081,7 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1979 return TRUE; 2081 return TRUE;
1980 } 2082 }
1981 2083
1982 /* Avoid entering funcdef stuff if typdef is going on. */ 2084 /* Avoid entering fvdef stuff if typdef is going on. */
1983 if (typdef != tnone) 2085 if (typdef != tnone)
1984 { 2086 {
1985 definedef = dnone; 2087 definedef = dnone;
@@ -2008,8 +2110,8 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2008 if (next_token_is_func) 2110 if (next_token_is_func)
2009 { 2111 {
2010 next_token_is_func = FALSE; 2112 next_token_is_func = FALSE;
2011 funcdef = fignore; 2113 fvdef = fignore;
2012 *is_func = TRUE; 2114 *is_func_or_var = TRUE;
2013 return TRUE; 2115 return TRUE;
2014 } 2116 }
2015 2117
@@ -2028,7 +2130,7 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2028 } 2130 }
2029 break; 2131 break;
2030 case oimplementation: 2132 case oimplementation:
2031 /* Save the class tag for functions that may be defined inside. */ 2133 /* Save the class tag for functions or variables defined inside. */
2032 objtag = savenstr (str, len); 2134 objtag = savenstr (str, len);
2033 objdef = oinbody; 2135 objdef = oinbody;
2034 return FALSE; 2136 return FALSE;
@@ -2036,11 +2138,11 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2036 /* Save the class tag for categories. */ 2138 /* Save the class tag for categories. */
2037 objtag = savenstr (str, len); 2139 objtag = savenstr (str, len);
2038 objdef = otagseen; 2140 objdef = otagseen;
2039 *is_func = TRUE; 2141 *is_func_or_var = TRUE;
2040 return TRUE; 2142 return TRUE;
2041 case oparenseen: 2143 case oparenseen:
2042 objdef = ocatseen; 2144 objdef = ocatseen;
2043 *is_func = TRUE; 2145 *is_func_or_var = TRUE;
2044 return TRUE; 2146 return TRUE;
2045 case oinbody: 2147 case oinbody:
2046 break; 2148 break;
@@ -2049,9 +2151,10 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2049 { 2151 {
2050 objdef = omethodtag; 2152 objdef = omethodtag;
2051 methodlen = len; 2153 methodlen = len;
2052 grow_linebuffer (&token_name, methodlen+1); 2154 grow_linebuffer (&token_name, methodlen + 1);
2053 strncpy (token_name.buffer, str, len); 2155 strncpy (token_name.buffer, str, len);
2054 token_name.buffer[methodlen] = '\0'; 2156 token_name.buffer[methodlen] = '\0';
2157 token_name.len = methodlen;
2055 return TRUE; 2158 return TRUE;
2056 } 2159 }
2057 return FALSE; 2160 return FALSE;
@@ -2064,8 +2167,9 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2064 { 2167 {
2065 objdef = omethodtag; 2168 objdef = omethodtag;
2066 methodlen += len; 2169 methodlen += len;
2067 grow_linebuffer (&token_name, methodlen+1); 2170 grow_linebuffer (&token_name, methodlen + 1);
2068 strncat (token_name.buffer, str, len); 2171 strncat (token_name.buffer, str, len);
2172 token_name.len = methodlen;
2069 return TRUE; 2173 return TRUE;
2070 } 2174 }
2071 return FALSE; 2175 return FALSE;
@@ -2083,20 +2187,23 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2083 return FALSE; 2187 return FALSE;
2084 } 2188 }
2085 2189
2086 /* A function or enum constant? */ 2190 /* A function, variable or enum constant? */
2087 switch (toktype) 2191 switch (toktype)
2088 { 2192 {
2089 case st_C_typespec: 2193 case st_C_typespec:
2090 if (funcdef != finlist && funcdef != fignore) 2194 if (fvdef != finlist && fvdef != fignore && fvdef != vignore)
2091 funcdef = fnone; /* should be useless */ 2195 fvdef = fvnone; /* should be useless */
2196 return FALSE;
2197 case st_C_ignore:
2198 fvdef = vignore;
2092 return FALSE; 2199 return FALSE;
2093 case st_none: 2200 case st_none:
2094 if (constantypedefs && structdef == sinbody && structtype == st_C_enum) 2201 if (constantypedefs && structdef == sinbody && structtype == st_C_enum)
2095 return TRUE; 2202 return TRUE;
2096 if (funcdef == fnone) 2203 if (fvdef == fvnone)
2097 { 2204 {
2098 funcdef = ftagseen; 2205 fvdef = fvnameseen; /* function or variable */
2099 *is_func = TRUE; 2206 *is_func_or_var = TRUE;
2100 return TRUE; 2207 return TRUE;
2101 } 2208 }
2102 } 2209 }
@@ -2106,21 +2213,10 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2106 2213
2107/* 2214/*
2108 * C_entries () 2215 * C_entries ()
2109 * This routine finds functions, typedefs, #define's, enum 2216 * This routine finds functions, variables, typedefs,
2110 * constants and struct/union/enum definitions in C syntax 2217 * #define's, enum constants and struct/union/enum definitions in
2111 * and adds them to the list. 2218 * #C syntax and adds them to the list.
2112 */ 2219 */
2113typedef struct
2114{
2115 logical valid;
2116 char *str;
2117 logical named;
2118 int linelen;
2119 int lineno;
2120 long linepos;
2121 char *buffer;
2122} TOKEN;
2123
2124#define current_lb_is_new (newndx == curndx) 2220#define current_lb_is_new (newndx == curndx)
2125#define switch_line_buffers() (curndx = 1 - curndx) 2221#define switch_line_buffers() (curndx = 1 - curndx)
2126 2222
@@ -2155,21 +2251,28 @@ do { \
2155 2251
2156 2252
2157void 2253void
2158make_C_tag (isfun, tokp) 2254make_C_tag (isfun)
2159 logical isfun; 2255 bool isfun;
2160 TOKEN *tokp;
2161{ 2256{
2162 char *name = NULL;
2163
2164 /* This function should never be called when tok.valid is FALSE, but 2257 /* This function should never be called when tok.valid is FALSE, but
2165 we must protect against invalid input or internal errors. */ 2258 we must protect against invalid input or internal errors. */
2166 if (tokp->valid) 2259 if (tok.valid)
2167 { 2260 {
2168 if (CTAGS || tokp->named) 2261 if (traditional_tag_style)
2169 name = savestr (token_name.buffer); 2262 {
2170 pfnote (name, isfun, 2263 /* This was the original code. Now we call new_pfnote instead,
2171 tokp->buffer, tokp->linelen, tokp->lineno, tokp->linepos); 2264 which uses the new method for naming tags (see new_pfnote). */
2172 tokp->valid = FALSE; 2265 char *name = NULL;
2266
2267 if (CTAGS || tok.named)
2268 name = savestr (token_name.buffer);
2269 pfnote (name, isfun,
2270 tok.buffer, tok.linelen, tok.lineno, tok.linepos);
2271 }
2272 else
2273 new_pfnote (token_name.buffer, token_name.len, isfun,
2274 tok.buffer, tok.linelen, tok.lineno, tok.linepos);
2275 tok.valid = FALSE;
2173 } 2276 }
2174 else if (DEBUG) 2277 else if (DEBUG)
2175 abort (); 2278 abort ();
@@ -2184,13 +2287,14 @@ C_entries (c_ext, inf)
2184 register char c; /* latest char read; '\0' for end of line */ 2287 register char c; /* latest char read; '\0' for end of line */
2185 register char *lp; /* pointer one beyond the character `c' */ 2288 register char *lp; /* pointer one beyond the character `c' */
2186 int curndx, newndx; /* indices for current and new lb */ 2289 int curndx, newndx; /* indices for current and new lb */
2187 TOKEN tok; /* latest token read */
2188 register int tokoff; /* offset in line of start of current token */ 2290 register int tokoff; /* offset in line of start of current token */
2189 register int toklen; /* length of current token */ 2291 register int toklen; /* length of current token */
2292 char *qualifier; /* string used to qualify names */
2293 int qlen; /* length of qualifier */
2190 int cblev; /* current curly brace level */ 2294 int cblev; /* current curly brace level */
2191 int parlev; /* current parenthesis level */ 2295 int parlev; /* current parenthesis level */
2192 logical incomm, inquote, inchar, quotednl, midtoken; 2296 bool incomm, inquote, inchar, quotednl, midtoken;
2193 logical cplpl, cjava; 2297 bool cplpl, cjava;
2194 TOKEN savetok; /* token saved during preprocessor handling */ 2298 TOKEN savetok; /* token saved during preprocessor handling */
2195 2299
2196 2300
@@ -2200,15 +2304,19 @@ C_entries (c_ext, inf)
2200 lp = curlb.buffer; 2304 lp = curlb.buffer;
2201 *lp = 0; 2305 *lp = 0;
2202 2306
2203 funcdef = fnone; typdef = tnone; structdef = snone; 2307 fvdef = fvnone; typdef = tnone; structdef = snone;
2204 definedef = dnone; objdef = onone; 2308 definedef = dnone; objdef = onone;
2205 next_token_is_func = yacc_rules = FALSE; 2309 next_token_is_func = yacc_rules = FALSE;
2206 midtoken = inquote = inchar = incomm = quotednl = FALSE; 2310 midtoken = inquote = inchar = incomm = quotednl = FALSE;
2207 tok.valid = savetok.valid = FALSE; 2311 tok.valid = savetok.valid = FALSE;
2208 cblev = 0; 2312 cblev = 0;
2209 parlev = 0; 2313 parlev = 0;
2210 cplpl = c_ext & C_PLPL; 2314 cplpl = (c_ext & C_PLPL) == C_PLPL;
2211 cjava = c_ext & C_JAVA; 2315 cjava = (c_ext & C_JAVA) == C_JAVA;
2316 if (cjava)
2317 { qualifier = "."; qlen = 1; }
2318 else
2319 { qualifier = "::"; qlen = 2; }
2212 2320
2213 while (!feof (inf)) 2321 while (!feof (inf))
2214 { 2322 {
@@ -2280,13 +2388,13 @@ C_entries (c_ext, inf)
2280 { 2388 {
2281 case '"': 2389 case '"':
2282 inquote = TRUE; 2390 inquote = TRUE;
2283 if (funcdef != finlist && funcdef != fignore) 2391 if (fvdef != finlist && fvdef != fignore && fvdef !=vignore)
2284 funcdef = fnone; 2392 fvdef = fvnone;
2285 continue; 2393 continue;
2286 case '\'': 2394 case '\'':
2287 inchar = TRUE; 2395 inchar = TRUE;
2288 if (funcdef != finlist && funcdef != fignore) 2396 if (fvdef != finlist && fvdef != fignore && fvdef !=vignore)
2289 funcdef = fnone; 2397 fvdef = fvnone;
2290 continue; 2398 continue;
2291 case '/': 2399 case '/':
2292 if (*lp == '*') 2400 if (*lp == '*')
@@ -2307,7 +2415,7 @@ C_entries (c_ext, inf)
2307 { 2415 {
2308 /* entering or exiting rules section in yacc file */ 2416 /* entering or exiting rules section in yacc file */
2309 lp++; 2417 lp++;
2310 definedef = dnone; funcdef = fnone; 2418 definedef = dnone; fvdef = fvnone;
2311 typdef = tnone; structdef = snone; 2419 typdef = tnone; structdef = snone;
2312 next_token_is_func = FALSE; 2420 next_token_is_func = FALSE;
2313 midtoken = inquote = inchar = incomm = quotednl = FALSE; 2421 midtoken = inquote = inchar = incomm = quotednl = FALSE;
@@ -2321,7 +2429,7 @@ C_entries (c_ext, inf)
2321 if (definedef == dnone) 2429 if (definedef == dnone)
2322 { 2430 {
2323 char *cp; 2431 char *cp;
2324 logical cpptoken = TRUE; 2432 bool cpptoken = TRUE;
2325 2433
2326 /* Look back on this line. If all blanks, or nonblanks 2434 /* Look back on this line. If all blanks, or nonblanks
2327 followed by an end of comment, this is a preprocessor 2435 followed by an end of comment, this is a preprocessor
@@ -2352,7 +2460,7 @@ C_entries (c_ext, inf)
2352 || (structdef == sinbody && structtype == st_C_enum)) 2460 || (structdef == sinbody && structtype == st_C_enum))
2353 && typdef != tignore 2461 && typdef != tignore
2354 && definedef != dignorerest 2462 && definedef != dignorerest
2355 && funcdef != finlist) 2463 && fvdef != finlist)
2356 { 2464 {
2357 if (midtoken) 2465 if (midtoken)
2358 { 2466 {
@@ -2369,35 +2477,38 @@ C_entries (c_ext, inf)
2369 } 2477 }
2370 else 2478 else
2371 { 2479 {
2372 logical is_func = FALSE; 2480 bool funorvar = FALSE;
2373 2481
2374 if (yacc_rules 2482 if (yacc_rules
2375 || consider_token (newlb.buffer + tokoff, toklen, c, 2483 || consider_token (newlb.buffer + tokoff, toklen, c,
2376 c_ext, cblev, parlev, &is_func)) 2484 c_ext, cblev, parlev, &funorvar))
2377 { 2485 {
2486 tok.named = FALSE;
2378 if (structdef == sinbody 2487 if (structdef == sinbody
2379 && definedef == dnone 2488 && definedef == dnone
2380 && is_func) 2489 && funorvar)
2381 /* function defined in C++ class body */ 2490 /* function or var defined in C++ class body */
2382 { 2491 {
2383 grow_linebuffer (&token_name, 2492 int len = strlen (structtag) + qlen + toklen;
2384 strlen(structtag)+2+toklen+1); 2493 grow_linebuffer (&token_name, len + 1);
2385 strcpy (token_name.buffer, structtag); 2494 strcpy (token_name.buffer, structtag);
2386 strcat (token_name.buffer, "::"); 2495 strcat (token_name.buffer, qualifier);
2387 strncat (token_name.buffer, 2496 strncat (token_name.buffer,
2388 newlb.buffer+tokoff, toklen); 2497 newlb.buffer + tokoff, toklen);
2498 token_name.len = len;
2389 tok.named = TRUE; 2499 tok.named = TRUE;
2390 } 2500 }
2391 else if (objdef == ocatseen) 2501 else if (objdef == ocatseen)
2392 /* Objective C category */ 2502 /* Objective C category */
2393 { 2503 {
2394 grow_linebuffer (&token_name, 2504 int len = strlen (objtag) + 2 + toklen;
2395 strlen(objtag)+2+toklen+1); 2505 grow_linebuffer (&token_name, len + 1);
2396 strcpy (token_name.buffer, objtag); 2506 strcpy (token_name.buffer, objtag);
2397 strcat (token_name.buffer, "("); 2507 strcat (token_name.buffer, "(");
2398 strncat (token_name.buffer, 2508 strncat (token_name.buffer,
2399 newlb.buffer+tokoff, toklen); 2509 newlb.buffer + tokoff, toklen);
2400 strcat (token_name.buffer, ")"); 2510 strcat (token_name.buffer, ")");
2511 token_name.len = len;
2401 tok.named = TRUE; 2512 tok.named = TRUE;
2402 } 2513 }
2403 else if (objdef == omethodtag 2514 else if (objdef == omethodtag
@@ -2408,17 +2519,16 @@ C_entries (c_ext, inf)
2408 } 2519 }
2409 else 2520 else
2410 { 2521 {
2411 grow_linebuffer (&token_name, toklen+1); 2522 grow_linebuffer (&token_name, toklen + 1);
2412 strncpy (token_name.buffer, 2523 strncpy (token_name.buffer,
2413 newlb.buffer+tokoff, toklen); 2524 newlb.buffer + tokoff, toklen);
2414 token_name.buffer[toklen] = '\0'; 2525 token_name.buffer[toklen] = '\0';
2415 if (structdef == stagseen 2526 token_name.len = toklen;
2416 || typdef == tend 2527 /* Name macros. */
2417 || (is_func 2528 tok.named = (structdef == stagseen
2418 && definedef == dignorerest)) /* macro */ 2529 || typdef == tend
2419 tok.named = TRUE; 2530 || (funorvar
2420 else 2531 && definedef == dignorerest));
2421 tok.named = FALSE;
2422 } 2532 }
2423 tok.lineno = lineno; 2533 tok.lineno = lineno;
2424 tok.linelen = tokoff + toklen + 1; 2534 tok.linelen = tokoff + toklen + 1;
@@ -2427,7 +2537,7 @@ C_entries (c_ext, inf)
2427 tok.valid = TRUE; 2537 tok.valid = TRUE;
2428 2538
2429 if (definedef == dnone 2539 if (definedef == dnone
2430 && (funcdef == ftagseen 2540 && (fvdef == fvnameseen
2431 || structdef == stagseen 2541 || structdef == stagseen
2432 || typdef == tend 2542 || typdef == tend
2433 || objdef != onone)) 2543 || objdef != onone))
@@ -2436,7 +2546,7 @@ C_entries (c_ext, inf)
2436 switch_line_buffers (); 2546 switch_line_buffers ();
2437 } 2547 }
2438 else 2548 else
2439 make_C_tag (is_func, &tok); 2549 make_C_tag (funorvar);
2440 } 2550 }
2441 midtoken = FALSE; 2551 midtoken = FALSE;
2442 } 2552 }
@@ -2452,17 +2562,17 @@ C_entries (c_ext, inf)
2452 switch (definedef) 2562 switch (definedef)
2453 { 2563 {
2454 case dnone: 2564 case dnone:
2455 switch (funcdef) 2565 switch (fvdef)
2456 { 2566 {
2457 case fstartlist: 2567 case fstartlist:
2458 funcdef = finlist; 2568 fvdef = finlist;
2459 continue; 2569 continue;
2460 case flistseen: 2570 case flistseen:
2461 make_C_tag (TRUE, &tok); 2571 make_C_tag (TRUE); /* a function */
2462 funcdef = fignore; 2572 fvdef = fignore;
2463 break; 2573 break;
2464 case ftagseen: 2574 case fvnameseen:
2465 funcdef = fnone; 2575 fvdef = fvnone;
2466 break; 2576 break;
2467 } 2577 }
2468 if (structdef == stagseen && !cjava) 2578 if (structdef == stagseen && !cjava)
@@ -2493,30 +2603,31 @@ C_entries (c_ext, inf)
2493 { 2603 {
2494 case otagseen: 2604 case otagseen:
2495 objdef = oignore; 2605 objdef = oignore;
2496 make_C_tag (TRUE, &tok); 2606 make_C_tag (TRUE); /* an Objective C class */
2497 break; 2607 break;
2498 case omethodtag: 2608 case omethodtag:
2499 case omethodparm: 2609 case omethodparm:
2500 objdef = omethodcolon; 2610 objdef = omethodcolon;
2501 methodlen += 1; 2611 methodlen += 1;
2502 grow_linebuffer (&token_name, methodlen+1); 2612 grow_linebuffer (&token_name, methodlen + 1);
2503 strcat (token_name.buffer, ":"); 2613 strcat (token_name.buffer, ":");
2614 token_name.len = methodlen;
2504 break; 2615 break;
2505 } 2616 }
2506 if (structdef == stagseen) 2617 if (structdef == stagseen)
2507 structdef = scolonseen; 2618 structdef = scolonseen;
2508 else 2619 else
2509 switch (funcdef) 2620 switch (fvdef)
2510 { 2621 {
2511 case ftagseen: 2622 case fvnameseen:
2512 if (yacc_rules) 2623 if (yacc_rules)
2513 { 2624 {
2514 make_C_tag (FALSE, &tok); 2625 make_C_tag (FALSE); /* a yacc function */
2515 funcdef = fignore; 2626 fvdef = fignore;
2516 } 2627 }
2517 break; 2628 break;
2518 case fstartlist: 2629 case fstartlist:
2519 funcdef = fnone; 2630 fvdef = fvnone;
2520 break; 2631 break;
2521 } 2632 }
2522 break; 2633 break;
@@ -2527,14 +2638,21 @@ C_entries (c_ext, inf)
2527 switch (typdef) 2638 switch (typdef)
2528 { 2639 {
2529 case tend: 2640 case tend:
2530 make_C_tag (FALSE, &tok); 2641 make_C_tag (FALSE); /* a typedef */
2531 /* FALLTHRU */ 2642 /* FALLTHRU */
2532 default: 2643 default:
2533 typdef = tnone; 2644 typdef = tnone;
2534 } 2645 }
2535 if (funcdef != fignore) 2646 switch (fvdef)
2536 { 2647 {
2537 funcdef = fnone; 2648 case fignore:
2649 break;
2650 case fvnameseen:
2651 if ((globals && cblev == 0) || (members && cblev == 1))
2652 make_C_tag (FALSE); /* a variable */
2653 /* FALLTHRU */
2654 default:
2655 fvdef = fvnone;
2538 /* The following instruction invalidates the token. 2656 /* The following instruction invalidates the token.
2539 Probably the token should be invalidated in all 2657 Probably the token should be invalidated in all
2540 other cases where some state machine is reset. */ 2658 other cases where some state machine is reset. */
@@ -2550,12 +2668,23 @@ C_entries (c_ext, inf)
2550 { 2668 {
2551 case omethodtag: 2669 case omethodtag:
2552 case omethodparm: 2670 case omethodparm:
2553 make_C_tag (TRUE, &tok); 2671 make_C_tag (TRUE); /* an Objective C method */
2554 objdef = oinbody; 2672 objdef = oinbody;
2555 break; 2673 break;
2556 } 2674 }
2557 if (funcdef != finlist && funcdef != fignore) 2675 switch (fvdef)
2558 funcdef = fnone; 2676 {
2677 case finlist:
2678 case fignore:
2679 case vignore:
2680 break;
2681 case fvnameseen:
2682 if ((globals && cblev == 0) || (members && cblev == 1))
2683 make_C_tag (FALSE); /* a variable */
2684 break;
2685 default:
2686 fvdef = fvnone;
2687 }
2559 if (structdef == stagseen) 2688 if (structdef == stagseen)
2560 structdef = snone; 2689 structdef = snone;
2561 break; 2690 break;
@@ -2565,11 +2694,22 @@ C_entries (c_ext, inf)
2565 if (cblev == 0 && typdef == tend) 2694 if (cblev == 0 && typdef == tend)
2566 { 2695 {
2567 typdef = tignore; 2696 typdef = tignore;
2568 make_C_tag (FALSE, &tok); 2697 make_C_tag (FALSE); /* a typedef */
2569 break; 2698 break;
2570 } 2699 }
2571 if (funcdef != finlist && funcdef != fignore) 2700 switch (fvdef)
2572 funcdef = fnone; 2701 {
2702 case finlist:
2703 case fignore:
2704 case vignore:
2705 break;
2706 case fvnameseen:
2707 if ((globals && cblev == 0) || (members && cblev == 1))
2708 make_C_tag (FALSE); /* a variable */
2709 /* FALLTHRU */
2710 default:
2711 fvdef = fvnone;
2712 }
2573 if (structdef == stagseen) 2713 if (structdef == stagseen)
2574 structdef = snone; 2714 structdef = snone;
2575 break; 2715 break;
@@ -2578,29 +2718,28 @@ C_entries (c_ext, inf)
2578 break; 2718 break;
2579 if (objdef == otagseen && parlev == 0) 2719 if (objdef == otagseen && parlev == 0)
2580 objdef = oparenseen; 2720 objdef = oparenseen;
2581 switch (funcdef) 2721 switch (fvdef)
2582 { 2722 {
2583 case fnone: 2723 case fvnone:
2584 switch (typdef) 2724 switch (typdef)
2585 { 2725 {
2586 case ttypedseen: 2726 case ttypedseen:
2587 case tend: 2727 case tend:
2588 /* Make sure that the next char is not a '*'.
2589 This handles constructs like:
2590 typedef void OperatorFun (int fun); */
2591 if (tok.valid && *lp != '*') 2728 if (tok.valid && *lp != '*')
2592 { 2729 {
2730 /* This handles constructs like:
2731 typedef void OperatorFun (int fun); */
2732 make_C_tag (FALSE);
2593 typdef = tignore; 2733 typdef = tignore;
2594 make_C_tag (FALSE, &tok);
2595 } 2734 }
2596 break; 2735 break;
2597 } /* switch (typdef) */ 2736 } /* switch (typdef) */
2598 break; 2737 break;
2599 case ftagseen: 2738 case fvnameseen:
2600 funcdef = fstartlist; 2739 fvdef = fstartlist;
2601 break; 2740 break;
2602 case flistseen: 2741 case flistseen:
2603 funcdef = finlist; 2742 fvdef = finlist;
2604 break; 2743 break;
2605 } 2744 }
2606 parlev++; 2745 parlev++;
@@ -2610,22 +2749,22 @@ C_entries (c_ext, inf)
2610 break; 2749 break;
2611 if (objdef == ocatseen && parlev == 1) 2750 if (objdef == ocatseen && parlev == 1)
2612 { 2751 {
2613 make_C_tag (TRUE, &tok); 2752 make_C_tag (TRUE); /* an Objective C category */
2614 objdef = oignore; 2753 objdef = oignore;
2615 } 2754 }
2616 if (--parlev == 0) 2755 if (--parlev == 0)
2617 { 2756 {
2618 switch (funcdef) 2757 switch (fvdef)
2619 { 2758 {
2620 case fstartlist: 2759 case fstartlist:
2621 case finlist: 2760 case finlist:
2622 funcdef = flistseen; 2761 fvdef = flistseen;
2623 break; 2762 break;
2624 } 2763 }
2625 if (cblev == 0 && typdef == tend) 2764 if (cblev == 0 && typdef == tend)
2626 { 2765 {
2627 typdef = tignore; 2766 typdef = tignore;
2628 make_C_tag (FALSE, &tok); 2767 make_C_tag (FALSE); /* a typedef */
2629 } 2768 }
2630 } 2769 }
2631 else if (parlev < 0) /* can happen due to ill-conceived #if's. */ 2770 else if (parlev < 0) /* can happen due to ill-conceived #if's. */
@@ -2645,27 +2784,27 @@ C_entries (c_ext, inf)
2645 case stagseen: 2784 case stagseen:
2646 case scolonseen: /* named struct */ 2785 case scolonseen: /* named struct */
2647 structdef = sinbody; 2786 structdef = sinbody;
2648 make_C_tag (FALSE, &tok); 2787 make_C_tag (FALSE); /* a struct */
2649 break; 2788 break;
2650 } 2789 }
2651 switch (funcdef) 2790 switch (fvdef)
2652 { 2791 {
2653 case flistseen: 2792 case flistseen:
2654 make_C_tag (TRUE, &tok); 2793 make_C_tag (TRUE); /* a function */
2655 /* FALLTHRU */ 2794 /* FALLTHRU */
2656 case fignore: 2795 case fignore:
2657 funcdef = fnone; 2796 fvdef = fvnone;
2658 break; 2797 break;
2659 case fnone: 2798 case fvnone:
2660 switch (objdef) 2799 switch (objdef)
2661 { 2800 {
2662 case otagseen: 2801 case otagseen:
2663 make_C_tag (TRUE, &tok); 2802 make_C_tag (TRUE); /* an Objective C class */
2664 objdef = oignore; 2803 objdef = oignore;
2665 break; 2804 break;
2666 case omethodtag: 2805 case omethodtag:
2667 case omethodparm: 2806 case omethodparm:
2668 make_C_tag (TRUE, &tok); 2807 make_C_tag (TRUE); /* an Objective C method */
2669 objdef = oinbody; 2808 objdef = oinbody;
2670 break; 2809 break;
2671 default: 2810 default:
@@ -2679,8 +2818,8 @@ C_entries (c_ext, inf)
2679 case '*': 2818 case '*':
2680 if (definedef != dnone) 2819 if (definedef != dnone)
2681 break; 2820 break;
2682 if (funcdef == fstartlist) 2821 if (fvdef == fstartlist)
2683 funcdef = fnone; /* avoid tagging `foo' in `foo (*bar()) ()' */ 2822 fvdef = fvnone; /* avoid tagging `foo' in `foo (*bar()) ()' */
2684 break; 2823 break;
2685 case '}': 2824 case '}':
2686 if (definedef != dnone) 2825 if (definedef != dnone)
@@ -2708,6 +2847,23 @@ C_entries (c_ext, inf)
2708 structtag = "<error>"; 2847 structtag = "<error>";
2709 } 2848 }
2710 break; 2849 break;
2850 case '=':
2851 if (definedef != dnone)
2852 break;
2853 switch (fvdef)
2854 {
2855 case finlist:
2856 case fignore:
2857 case vignore:
2858 break;
2859 case fvnameseen:
2860 if ((globals && cblev == 0) || (members && cblev == 1))
2861 make_C_tag (FALSE); /* a variable */
2862 /* FALLTHRU */
2863 default:
2864 fvdef = vignore;
2865 }
2866 break;
2711 case '+': 2867 case '+':
2712 case '-': 2868 case '-':
2713 if (objdef == oinbody && cblev == 0) 2869 if (objdef == oinbody && cblev == 0)
@@ -2716,18 +2872,18 @@ C_entries (c_ext, inf)
2716 break; 2872 break;
2717 } 2873 }
2718 /* FALLTHRU */ 2874 /* FALLTHRU */
2719 case '=': case '#': case '~': case '&': case '%': case '/': 2875 case '#': case '~': case '&': case '%': case '/': case '|':
2720 case '|': case '^': case '!': case '<': case '>': case '.': case '?': 2876 case '^': case '!': case '<': case '>': case '.': case '?': case ']':
2721 if (definedef != dnone) 2877 if (definedef != dnone)
2722 break; 2878 break;
2723 /* These surely cannot follow a function tag. */ 2879 /* These surely cannot follow a function tag. */
2724 if (funcdef != finlist && funcdef != fignore) 2880 if (fvdef != finlist && fvdef != fignore && fvdef != vignore)
2725 funcdef = fnone; 2881 fvdef = fvnone;
2726 break; 2882 break;
2727 case '\0': 2883 case '\0':
2728 if (objdef == otagseen) 2884 if (objdef == otagseen)
2729 { 2885 {
2730 make_C_tag (TRUE, &tok); 2886 make_C_tag (TRUE); /* an Objective C class */
2731 objdef = oignore; 2887 objdef = oignore;
2732 } 2888 }
2733 /* If a macro spans multiple lines don't reset its state. */ 2889 /* If a macro spans multiple lines don't reset its state. */
@@ -2770,7 +2926,8 @@ Cplusplus_entries (inf)
2770 2926
2771/* Always do Java. */ 2927/* Always do Java. */
2772void 2928void
2773Cjava_entries (FILE *inf) 2929Cjava_entries (inf)
2930 FILE *inf;
2774{ 2931{
2775 C_entries (C_JAVA, inf); 2932 C_entries (C_JAVA, inf);
2776} 2933}
@@ -2795,7 +2952,7 @@ Yacc_entries (inf)
2795 2952
2796char *dbp; 2953char *dbp;
2797 2954
2798logical 2955bool
2799tail (cp) 2956tail (cp)
2800 char *cp; 2957 char *cp;
2801{ 2958{
@@ -3009,11 +3166,11 @@ Perl_functions (inf)
3009 charno += readline (&lb, inf); 3166 charno += readline (&lb, inf);
3010 cp = lb.buffer; 3167 cp = lb.buffer;
3011 3168
3012 if (*cp++ == 's' && *cp++ == 'u' && *cp++ == 'b' && isspace(*cp++)) 3169 if (*cp++ == 's' && *cp++ == 'u' && *cp++ == 'b' && isspace (*cp++))
3013 { 3170 {
3014 while (*cp && isspace(*cp)) 3171 while (*cp && isspace (*cp))
3015 cp++; 3172 cp++;
3016 while (*cp && ! isspace(*cp) && *cp != '{') 3173 while (*cp && ! isspace (*cp) && *cp != '{')
3017 cp++; 3174 cp++;
3018 pfnote ((CTAGS) ? savenstr (lb.buffer, cp-lb.buffer) : NULL, TRUE, 3175 pfnote ((CTAGS) ? savenstr (lb.buffer, cp-lb.buffer) : NULL, TRUE,
3019 lb.buffer, cp - lb.buffer + 1, lineno, linecharno); 3176 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
@@ -3021,6 +3178,42 @@ Perl_functions (inf)
3021 } 3178 }
3022} 3179}
3023 3180
3181/* Idea by Corny de Souza
3182 * Cobol tag functions
3183 * We could look for anything that could be a paragraph name.
3184 * i.e. anything that starts in column 8 is one word and ends in a full stop.
3185 */
3186void
3187Cobol_paragraphs (inf)
3188 FILE *inf;
3189{
3190 register char *cp;
3191
3192 lineno = 0;
3193 charno = 0;
3194
3195 while (!feof (inf))
3196 {
3197 lineno++;
3198 linecharno = charno;
3199 charno += readline (&lb, inf);
3200
3201 if (lb.len < 9)
3202 continue;
3203 dbp = lb.buffer + 8;
3204
3205 /* If eoln, compiler option or comment ignore whole line. */
3206 if (dbp[-1] != ' ' || !isalnum (dbp[0]))
3207 continue;
3208
3209 for (cp = dbp; isalnum (*cp) || *cp == '-'; cp++)
3210 continue;
3211 if (*cp++ == '.')
3212 pfnote ((CTAGS) ? savenstr (dbp, cp-dbp) : NULL, TRUE,
3213 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3214 }
3215}
3216
3024/* Added by Mosur Mohan, 4/22/88 */ 3217/* Added by Mosur Mohan, 4/22/88 */
3025/* Pascal parsing */ 3218/* Pascal parsing */
3026 3219
@@ -3039,7 +3232,7 @@ Pascal_functions (inf)
3039 int save_lineno, save_len; 3232 int save_lineno, save_len;
3040 char c, *cp, *namebuf; 3233 char c, *cp, *namebuf;
3041 3234
3042 logical /* each of these flags is TRUE iff: */ 3235 bool /* each of these flags is TRUE iff: */
3043 incomment, /* point is inside a comment */ 3236 incomment, /* point is inside a comment */
3044 inquote, /* point is inside '..' string */ 3237 inquote, /* point is inside '..' string */
3045 get_tagname, /* point is after PROCEDURE/FUNCTION 3238 get_tagname, /* point is after PROCEDURE/FUNCTION
@@ -3171,7 +3364,7 @@ Pascal_functions (inf)
3171 save_lcno = linecharno; 3364 save_lcno = linecharno;
3172 3365
3173 /* grab block name */ 3366 /* grab block name */
3174 for (cp = dbp + 1; *cp && (!endtoken (*cp)); cp++) 3367 for (cp = dbp + 1; *cp != '\0' && !endtoken (*cp); cp++)
3175 continue; 3368 continue;
3176 namebuf = (CTAGS) ? savenstr (dbp, cp-dbp) : NULL; 3369 namebuf = (CTAGS) ? savenstr (dbp, cp-dbp) : NULL;
3177 dbp = cp; /* set dbp to e-o-token */ 3370 dbp = cp; /* set dbp to e-o-token */
@@ -3224,7 +3417,7 @@ L_isquote (strp)
3224 && (*(++strp) == 'o' || *strp == 'O') 3417 && (*(++strp) == 'o' || *strp == 'O')
3225 && (*(++strp) == 't' || *strp == 'T') 3418 && (*(++strp) == 't' || *strp == 'T')
3226 && (*(++strp) == 'e' || *strp == 'E') 3419 && (*(++strp) == 'e' || *strp == 'E')
3227 && isspace(*(++strp))); 3420 && isspace (*(++strp)));
3228} 3421}
3229 3422
3230void 3423void
@@ -3237,11 +3430,11 @@ L_getit ()
3237 else if (*dbp == '(' && L_isquote (dbp)) /* Skip "(quote " */ 3430 else if (*dbp == '(' && L_isquote (dbp)) /* Skip "(quote " */
3238 { 3431 {
3239 dbp += 7; 3432 dbp += 7;
3240 while (isspace(*dbp)) 3433 while (isspace (*dbp))
3241 dbp++; 3434 dbp++;
3242 } 3435 }
3243 for (cp = dbp /*+1*/; 3436 for (cp = dbp /*+1*/;
3244 *cp && *cp != '(' && *cp != ' ' && *cp != ')'; 3437 *cp != '\0' && *cp != '(' && *cp != ' ' && *cp != ')';
3245 cp++) 3438 cp++)
3246 continue; 3439 continue;
3247 if (cp == dbp) 3440 if (cp == dbp)
@@ -3312,6 +3505,7 @@ Postscript_functions (inf)
3312{ 3505{
3313 lineno = 0; 3506 lineno = 0;
3314 charno = 0; 3507 charno = 0;
3508
3315 while (!feof (inf)) 3509 while (!feof (inf))
3316 { 3510 {
3317 lineno++; 3511 lineno++;
@@ -3423,7 +3617,6 @@ char *TEX_defenv = "\
3423void TEX_mode (); 3617void TEX_mode ();
3424struct TEX_tabent *TEX_decode_env (); 3618struct TEX_tabent *TEX_decode_env ();
3425int TEX_Token (); 3619int TEX_Token ();
3426static void TEX_getit ();
3427 3620
3428char TEX_esc = '\\'; 3621char TEX_esc = '\\';
3429char TEX_opgrp = '{'; 3622char TEX_opgrp = '{';
@@ -3437,6 +3630,7 @@ TeX_functions (inf)
3437 FILE *inf; 3630 FILE *inf;
3438{ 3631{
3439 char *lasthit; 3632 char *lasthit;
3633 register int i;
3440 3634
3441 lineno = 0; 3635 lineno = 0;
3442 charno = 0; 3636 charno = 0;
@@ -3457,20 +3651,22 @@ TeX_functions (inf)
3457 lasthit = dbp; 3651 lasthit = dbp;
3458 while (dbp = etags_strchr (dbp, TEX_esc)) /* Look at each esc in line */ 3652 while (dbp = etags_strchr (dbp, TEX_esc)) /* Look at each esc in line */
3459 { 3653 {
3460 register int i;
3461
3462 if (!*(++dbp)) 3654 if (!*(++dbp))
3463 break; 3655 break;
3464 linecharno += dbp - lasthit; 3656 linecharno += dbp - lasthit;
3465 lasthit = dbp; 3657 lasthit = dbp;
3466 i = TEX_Token (lasthit); 3658 i = TEX_Token (lasthit);
3467 if (0 <= i) 3659 if (i >= 0)
3468 { 3660 {
3469 pfnote ((char *)NULL, TRUE, 3661 /* We seem to include the TeX command in the tag name.
3662 register char *p;
3663 for (p = lasthit + TEX_toktab[i].len;
3664 *p != '\0' && *p != TEX_clgrp;
3665 p++)
3666 continue; */
3667 pfnote (/*savenstr (lasthit, p-lasthit)*/ (char *)NULL, TRUE,
3470 lb.buffer, lb.len, lineno, linecharno); 3668 lb.buffer, lb.len, lineno, linecharno);
3471 if (TeX_named_tokens) 3669 break; /* We only tag a line once */
3472 TEX_getit (lasthit, TEX_toktab[i].len);
3473 break; /* We only save a line once */
3474 } 3670 }
3475 } 3671 }
3476 } 3672 }
@@ -3568,26 +3764,6 @@ TEX_decode_env (evarname, defenv)
3568 return tab; 3764 return tab;
3569} 3765}
3570 3766
3571/* Record a tag defined by a TeX command of length LEN and starting at NAME.
3572 The name being defined actually starts at (NAME + LEN + 1).
3573 But we seem to include the TeX command in the tag name. */
3574static void
3575TEX_getit (name, len)
3576 char *name;
3577 int len;
3578{
3579 char *p = name + len;
3580
3581 if (*name == '\0')
3582 return;
3583
3584 /* Let tag name extend to next group close (or end of line) */
3585 while (*p && *p != TEX_clgrp)
3586 p++;
3587 pfnote (savenstr (name, p-name), TRUE,
3588 lb.buffer, lb.len, lineno, linecharno);
3589}
3590
3591/* If the text at CP matches one of the tag-defining TeX command names, 3767/* If the text at CP matches one of the tag-defining TeX command names,
3592 return the pointer to the first occurrence of that command in TEX_toktab. 3768 return the pointer to the first occurrence of that command in TEX_toktab.
3593 Otherwise return -1. 3769 Otherwise return -1.
@@ -3611,13 +3787,15 @@ TEX_Token (cp)
3611 * Assumes that the predicate starts at column 0. 3787 * Assumes that the predicate starts at column 0.
3612 * Only the first clause of a predicate is added. 3788 * Only the first clause of a predicate is added.
3613 */ 3789 */
3790int prolog_pred ();
3791void prolog_skip_comment ();
3792int prolog_atom ();
3793int eat_white ();
3794
3614void 3795void
3615Prolog_functions (inf) 3796Prolog_functions (inf)
3616 FILE *inf; 3797 FILE *inf;
3617{ 3798{
3618 int prolog_pred ();
3619 void prolog_skip_comment ();
3620
3621 char * last; 3799 char * last;
3622 int len; 3800 int len;
3623 int allocated; 3801 int allocated;
@@ -3691,18 +3869,15 @@ prolog_pred (s, last)
3691 char *s; 3869 char *s;
3692 char *last; /* Name of last clause. */ 3870 char *last; /* Name of last clause. */
3693{ 3871{
3694 int prolog_atom();
3695 int prolog_white();
3696
3697 int pos; 3872 int pos;
3698 int len; 3873 int len;
3699 3874
3700 pos = prolog_atom(s, 0); 3875 pos = prolog_atom (s, 0);
3701 if (pos < 1) 3876 if (pos < 1)
3702 return 0; 3877 return 0;
3703 3878
3704 len = pos; 3879 len = pos;
3705 pos += prolog_white(s, pos); 3880 pos += eat_white (s, pos);
3706 3881
3707 if ((s[pos] == '(') || (s[pos] == '.')) 3882 if ((s[pos] == '(') || (s[pos] == '.'))
3708 { 3883 {
@@ -3710,9 +3885,9 @@ prolog_pred (s, last)
3710 pos++; 3885 pos++;
3711 3886
3712 /* Save only the first clause. */ 3887 /* Save only the first clause. */
3713 if ((last == NULL) || 3888 if (last == NULL
3714 (len != strlen(last)) || 3889 || len != strlen (last)
3715 (strncmp(s, last, len) != 0)) 3890 || !strneq (s, last, len))
3716 { 3891 {
3717 pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE, 3892 pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE,
3718 s, pos, lineno, linecharno); 3893 s, pos, lineno, linecharno);
@@ -3783,15 +3958,15 @@ prolog_atom (s, pos)
3783 3958
3784/* Consume whitespace. Return the number of bytes eaten. */ 3959/* Consume whitespace. Return the number of bytes eaten. */
3785int 3960int
3786prolog_white (s, pos) 3961eat_white (s, pos)
3787 char *s; 3962 char *s;
3788 int pos; 3963 int pos;
3789{ 3964{
3790 int origpos; 3965 int origpos = pos;
3791 3966
3792 origpos = pos; 3967 origpos = pos;
3793 3968
3794 while (isspace(s[pos])) 3969 while (isspace (s[pos]))
3795 pos++; 3970 pos++;
3796 3971
3797 return pos - origpos; 3972 return pos - origpos;
@@ -3804,13 +3979,14 @@ prolog_white (s, pos)
3804 * 3979 *
3805 * Assumes that Erlang functions start at column 0. 3980 * Assumes that Erlang functions start at column 0.
3806 */ 3981 */
3982int erlang_func ();
3983void erlang_attribute ();
3984int erlang_atom ();
3985
3807void 3986void
3808Erlang_functions (inf) 3987Erlang_functions (inf)
3809 FILE *inf; 3988 FILE *inf;
3810{ 3989{
3811 int erlang_func ();
3812 void erlang_attribute ();
3813
3814 char * last; 3990 char * last;
3815 int len; 3991 int len;
3816 int allocated; 3992 int allocated;
@@ -3839,7 +4015,7 @@ Erlang_functions (inf)
3839 continue; 4015 continue;
3840 else if (dbp[0] == '-') /* attribute, e.g. "-define" */ 4016 else if (dbp[0] == '-') /* attribute, e.g. "-define" */
3841 { 4017 {
3842 erlang_attribute(dbp); 4018 erlang_attribute (dbp);
3843 last = NULL; 4019 last = NULL;
3844 } 4020 }
3845 else if (len = erlang_func (dbp, last)) 4021 else if (len = erlang_func (dbp, last))
@@ -3849,9 +4025,9 @@ Erlang_functions (inf)
3849 * generates a tag for the first clause. 4025 * generates a tag for the first clause.
3850 */ 4026 */
3851 if (last == NULL) 4027 if (last == NULL)
3852 last = xnew(len + 1, char); 4028 last = xnew (len + 1, char);
3853 else if (len + 1 > allocated) 4029 else if (len + 1 > allocated)
3854 last = (char *) xrealloc(last, len + 1); 4030 last = (char *) xrealloc (last, len + 1);
3855 allocated = len + 1; 4031 allocated = len + 1;
3856 strncpy (last, dbp, len); 4032 strncpy (last, dbp, len);
3857 last[len] = '\0'; 4033 last[len] = '\0';
@@ -3875,31 +4051,27 @@ erlang_func (s, last)
3875 char *s; 4051 char *s;
3876 char *last; /* Name of last clause. */ 4052 char *last; /* Name of last clause. */
3877{ 4053{
3878 int erlang_atom ();
3879 int erlang_white ();
3880
3881 int pos; 4054 int pos;
3882 int len; 4055 int len;
3883 4056
3884 pos = erlang_atom(s, 0); 4057 pos = erlang_atom (s, 0);
3885 if (pos < 1) 4058 if (pos < 1)
3886 return 0; 4059 return 0;
3887 4060
3888 len = pos; 4061 len = pos;
3889 pos += erlang_white(s, pos); 4062 pos += eat_white (s, pos);
3890 4063
3891 if (s[pos++] == '(') 4064 /* Save only the first clause. */
3892 { 4065 if (s[pos++] == '('
3893 /* Save only the first clause. */ 4066 && (last == NULL
3894 if ((last == NULL) || 4067 || len != strlen (last)
3895 (len != strlen(last)) || 4068 || !strneq (s, last, len)))
3896 (strncmp(s, last, len) != 0))
3897 { 4069 {
3898 pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE, 4070 pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE,
3899 s, pos, lineno, linecharno); 4071 s, pos, lineno, linecharno);
3900 return len; 4072 return len;
3901 } 4073 }
3902 } 4074
3903 return 0; 4075 return 0;
3904} 4076}
3905 4077
@@ -3917,27 +4089,18 @@ void
3917erlang_attribute (s) 4089erlang_attribute (s)
3918 char *s; 4090 char *s;
3919{ 4091{
3920 int erlang_atom ();
3921 int erlang_white ();
3922
3923 int pos; 4092 int pos;
3924 int len; 4093 int len;
3925 4094
3926 if ((strncmp(s, "-define", 7) == 0) || 4095 if (strneq (s, "-define", 7) || strneq (s, "-record", 7))
3927 (strncmp(s, "-record", 7) == 0))
3928 { 4096 {
3929 pos = 7; 4097 pos = 7 + eat_white (s, pos);
3930 pos += erlang_white(s, pos);
3931
3932 if (s[pos++] == '(') 4098 if (s[pos++] == '(')
3933 { 4099 {
3934 pos += erlang_white(s, pos); 4100 pos += eat_white (s, pos);
3935 4101 if (len = erlang_atom (s, pos))
3936 if (len = erlang_atom(s, pos))
3937 {
3938 pfnote ((CTAGS) ? savenstr (& s[pos], len) : NULL, TRUE, 4102 pfnote ((CTAGS) ? savenstr (& s[pos], len) : NULL, TRUE,
3939 s, pos + len, lineno, linecharno); 4103 s, pos + len, lineno, linecharno);
3940 }
3941 } 4104 }
3942 } 4105 }
3943 return; 4106 return;
@@ -3993,22 +4156,6 @@ erlang_atom (s, pos)
3993 else 4156 else
3994 return -1; 4157 return -1;
3995} 4158}
3996
3997/* Consume whitespace. Return the number of bytes eaten */
3998int
3999erlang_white (s, pos)
4000 char *s;
4001 int pos;
4002{
4003 int origpos;
4004
4005 origpos = pos;
4006
4007 while (isspace (s[pos]))
4008 pos++;
4009
4010 return pos - origpos;
4011}
4012 4159
4013#ifdef ETAGS_REGEXPS 4160#ifdef ETAGS_REGEXPS
4014/* Take a string like "/blah/" and turn it into "blah", making sure 4161/* Take a string like "/blah/" and turn it into "blah", making sure
@@ -4023,7 +4170,7 @@ scan_separators (name)
4023{ 4170{
4024 char sep = name[0]; 4171 char sep = name[0];
4025 char *copyto = name; 4172 char *copyto = name;
4026 logical quoted = FALSE; 4173 bool quoted = FALSE;
4027 4174
4028 for (++name; *name != '\0'; ++name) 4175 for (++name; *name != '\0'; ++name)
4029 { 4176 {