comparison lib-src/etags.c @ 35297:e268b7b500f0

Changes for makefile support in etags.
author Francesco Potortì <pot@gnu.org>
date Sun, 14 Jan 2001 20:48:05 +0000
parents f8efb9150d3a
children 6a51ef53518f
comparison
equal deleted inserted replaced
35296:13441490c2f3 35297:e268b7b500f0
29 * Regexp tags by Tom Tromey. 29 * Regexp tags by Tom Tromey.
30 * 30 *
31 * Francesco Potorti` (pot@gnu.org) is the current maintainer. 31 * Francesco Potorti` (pot@gnu.org) is the current maintainer.
32 */ 32 */
33 33
34 char pot_etags_version[] = "@(#) pot revision number is 13.44"; 34 char pot_etags_version[] = "@(#) pot revision number is 13.47";
35 35
36 #define TRUE 1 36 #define TRUE 1
37 #define FALSE 0 37 #define FALSE 0
38 38
39 #ifndef DEBUG 39 #ifndef DEBUG
158 #define streq(s,t) ((DEBUG && (s) == NULL && (t) == NULL \ 158 #define streq(s,t) ((DEBUG && (s) == NULL && (t) == NULL \
159 && (abort (), 1)) || !strcmp (s, t)) 159 && (abort (), 1)) || !strcmp (s, t))
160 #define strneq(s,t,n) ((DEBUG && (s) == NULL && (t) == NULL \ 160 #define strneq(s,t,n) ((DEBUG && (s) == NULL && (t) == NULL \
161 && (abort (), 1)) || !strncmp (s, t, n)) 161 && (abort (), 1)) || !strncmp (s, t, n))
162 162
163 #define lowcase(c) tolower ((unsigned char)(c))
164 #define UPCASE(c) toupper ((unsigned char)(c))
165
166 #define CHARS 256 /* 2^sizeof(char) */ 163 #define CHARS 256 /* 2^sizeof(char) */
167 #define CHAR(x) ((unsigned int)x & (CHARS - 1)) 164 #define CHAR(x) ((unsigned int)(x) & (CHARS - 1))
168 #define iswhite(c) (_wht[CHAR(c)]) /* c is white */ 165 #define iswhite(c) (_wht[CHAR(c)]) /* c is white */
169 #define notinname(c) (_nin[CHAR(c)]) /* c is not in a name */ 166 #define notinname(c) (_nin[CHAR(c)]) /* c is not in a name */
170 #define begtoken(c) (_btk[CHAR(c)]) /* c can start token */ 167 #define begtoken(c) (_btk[CHAR(c)]) /* c can start token */
171 #define intoken(c) (_itk[CHAR(c)]) /* c can be in token */ 168 #define intoken(c) (_itk[CHAR(c)]) /* c can be in token */
172 #define endtoken(c) (_etk[CHAR(c)]) /* c ends tokens */ 169 #define endtoken(c) (_etk[CHAR(c)]) /* c ends tokens */
173 170
174 #define ISALNUM(c) isalnum ((unsigned char) (c)) 171 #define ISALNUM(c) isalnum (CHAR(c))
175 #define ISALPHA(c) isalpha ((unsigned char) (c)) 172 #define ISALPHA(c) isalpha (CHAR(c))
176 #define ISDIGIT(c) isdigit ((unsigned char) (c)) 173 #define ISDIGIT(c) isdigit (CHAR(c))
177 #define ISLOWER(c) islower ((unsigned char) (c)) 174 #define ISLOWER(c) islower (CHAR(c))
175
176 #define lowcase(c) tolower (CHAR(c))
177 #define upcase(c) toupper (CHAR(c))
178 178
179 179
180 /* 180 /*
181 * xnew, xrnew -- allocate, reallocate storage 181 * xnew, xrnew -- allocate, reallocate storage
182 * 182 *
206 206
207 typedef struct 207 typedef struct
208 { 208 {
209 char *name; 209 char *name;
210 Lang_function *function; 210 Lang_function *function;
211 char **filenames;
211 char **suffixes; 212 char **suffixes;
212 char **interpreters; 213 char **interpreters;
213 } language; 214 } language;
214 215
215 typedef struct node_st 216 typedef struct node_st
252 static void Cstar_entries P_((FILE *)); 253 static void Cstar_entries P_((FILE *));
253 static void Erlang_functions P_((FILE *)); 254 static void Erlang_functions P_((FILE *));
254 static void Fortran_functions P_((FILE *)); 255 static void Fortran_functions P_((FILE *));
255 static void Yacc_entries P_((FILE *)); 256 static void Yacc_entries P_((FILE *));
256 static void Lisp_functions P_((FILE *)); 257 static void Lisp_functions P_((FILE *));
258 static void Makefile_targets P_((FILE *));
257 static void Pascal_functions P_((FILE *)); 259 static void Pascal_functions P_((FILE *));
258 static void Perl_functions P_((FILE *)); 260 static void Perl_functions P_((FILE *));
259 static void Postscript_functions P_((FILE *)); 261 static void Postscript_functions P_((FILE *));
260 static void Prolog_functions P_((FILE *)); 262 static void Prolog_functions P_((FILE *));
261 static void Python_functions P_((FILE *)); 263 static void Python_functions P_((FILE *));
262 static void Scheme_functions P_((FILE *)); 264 static void Scheme_functions P_((FILE *));
263 static void TeX_functions P_((FILE *)); 265 static void TeX_commands P_((FILE *));
264 static void Texinfo_functions P_ ((FILE *)); 266 static void Texinfo_nodes P_((FILE *));
265 static void just_read_file P_((FILE *)); 267 static void just_read_file P_((FILE *));
266 268
267 static void print_language_names P_((void)); 269 static void print_language_names P_((void));
268 static void print_version P_((void)); 270 static void print_version P_((void));
269 static void print_help P_((void)); 271 static void print_help P_((void));
270 int main P_((int, char **)); 272 int main P_((int, char **));
271 static int number_len P_((long)); 273 static int number_len P_((long));
272 274
273 static compressor *get_compressor_from_suffix P_((char *, char **)); 275 static compressor *get_compressor_from_suffix P_((char *, char **));
274 static language *get_language_from_name P_((char *)); 276 static language *get_language_from_langname P_((char *));
275 static language *get_language_from_interpreter P_((char *)); 277 static language *get_language_from_interpreter P_((char *));
276 static language *get_language_from_suffix P_((char *)); 278 static language *get_language_from_filename P_((char *));
277 static int total_size_of_entries P_((node *)); 279 static int total_size_of_entries P_((node *));
278 static long readline P_((linebuffer *, FILE *)); 280 static long readline P_((linebuffer *, FILE *));
279 static long readline_internal P_((linebuffer *, FILE *)); 281 static long readline_internal P_((linebuffer *, FILE *));
280 static void get_tag P_((char *)); 282 static void get_tag P_((char *));
281 283
474 given. That is why default_C_entries is called here. */ 476 given. That is why default_C_entries is called here. */
475 char *default_C_suffixes [] = 477 char *default_C_suffixes [] =
476 { "c", "h", NULL }; 478 { "c", "h", NULL };
477 479
478 char *Cplusplus_suffixes [] = 480 char *Cplusplus_suffixes [] =
479 { "C", "H", "c++", "cc", "cpp", "cxx", "h++", "hh", "hpp", "hxx", 481 { "C", "c++", "cc", "cpp", "cxx", "H", "h++", "hh", "hpp", "hxx",
480 "M", /* Objective C++ */ 482 "M", /* Objective C++ */
481 "pdb", /* Postscript with C syntax */ 483 "pdb", /* Postscript with C syntax */
482 NULL }; 484 NULL };
483 485
484 char *Cjava_suffixes [] = 486 char *Cjava_suffixes [] =
495 497
496 char *Fortran_suffixes [] = 498 char *Fortran_suffixes [] =
497 { "F", "f", "f90", "for", NULL }; 499 { "F", "f", "f90", "for", NULL };
498 500
499 char *Lisp_suffixes [] = 501 char *Lisp_suffixes [] =
500 { "cl", "clisp", "el", "l", "lisp", "lsp", "ml", "LSP", NULL }; 502 { "cl", "clisp", "el", "l", "lisp", "LSP", "lsp", "ml", NULL };
503
504 char *Makefile_filenames [] =
505 { "Makefile", "makefile", "GNUMakefile", "Makefile.in", "Makefile.am", NULL};
501 506
502 char *Pascal_suffixes [] = 507 char *Pascal_suffixes [] =
503 { "p", "pas", NULL }; 508 { "p", "pas", NULL };
504 509
505 char *Perl_suffixes [] = 510 char *Perl_suffixes [] =
506 { "pl", "pm", NULL }; 511 { "pl", "pm", NULL };
507 char *Perl_interpreters [] = 512 char *Perl_interpreters [] =
508 { "perl", "@PERL@", NULL }; 513 { "perl", "@PERL@", NULL };
509 514
510 char *plain_C_suffixes [] = 515 char *plain_C_suffixes [] =
511 { "pc", /* Pro*C file */ 516 { "lm", /* Objective lex file */
512 "m", /* Objective C file */ 517 "m", /* Objective C file */
513 "lm", /* Objective lex file */ 518 "pc", /* Pro*C file */
514 NULL }; 519 NULL };
515 520
516 char *Postscript_suffixes [] = 521 char *Postscript_suffixes [] =
517 { "ps", "psw", NULL }; /* .psw is for PSWrap */ 522 { "ps", "psw", NULL }; /* .psw is for PSWrap */
518 523
522 char *Python_suffixes [] = 527 char *Python_suffixes [] =
523 { "py", NULL }; 528 { "py", NULL };
524 529
525 /* Can't do the `SCM' or `scm' prefix with a version number. */ 530 /* Can't do the `SCM' or `scm' prefix with a version number. */
526 char *Scheme_suffixes [] = 531 char *Scheme_suffixes [] =
527 { "SCM", "SM", "oak", "sch", "scheme", "scm", "sm", "ss", "t", NULL }; 532 { "oak", "sch", "scheme", "SCM", "scm", "SM", "sm", "ss", "t", NULL };
528 533
529 char *TeX_suffixes [] = 534 char *TeX_suffixes [] =
530 { "TeX", "bib", "clo", "cls", "ltx", "sty", "tex", NULL }; 535 { "bib", "clo", "cls", "ltx", "sty", "TeX", "tex", NULL };
531 536
532 char *Texinfo_suffixes [] = 537 char *Texinfo_suffixes [] =
533 { "texi", "txi", "texinfo", NULL }; 538 { "texi", "texinfo", "txi", NULL };
534 539
535 char *Yacc_suffixes [] = 540 char *Yacc_suffixes [] =
536 { "y", "ym", "yy", "yxx", "y++", NULL }; /* .ym is Objective yacc file */ 541 { "y", "y++", "ym", "yxx", "yy", NULL }; /* .ym is Objective yacc file */
537 542
538 /* 543 /*
539 * Table of languages. 544 * Table of languages.
540 * 545 *
541 * It is ok for a given function to be listed under more than one 546 * It is ok for a given function to be listed under more than one
542 * name. I just didn't. 547 * name. I just didn't.
543 */ 548 */
544 549
545 language lang_names [] = 550 language lang_names [] =
546 { 551 {
547 { "ada", Ada_funcs, Ada_suffixes, NULL }, 552 { "ada", Ada_funcs, NULL, Ada_suffixes, NULL },
548 { "asm", Asm_labels, Asm_suffixes, NULL }, 553 { "asm", Asm_labels, NULL, Asm_suffixes, NULL },
549 { "c", default_C_entries, default_C_suffixes, NULL }, 554 { "c", default_C_entries, NULL, default_C_suffixes, NULL },
550 { "c++", Cplusplus_entries, Cplusplus_suffixes, NULL }, 555 { "c++", Cplusplus_entries, NULL, Cplusplus_suffixes, NULL },
551 { "c*", Cstar_entries, Cstar_suffixes, NULL }, 556 { "c*", Cstar_entries, NULL, Cstar_suffixes, NULL },
552 { "cobol", Cobol_paragraphs, Cobol_suffixes, NULL }, 557 { "cobol", Cobol_paragraphs, NULL, Cobol_suffixes, NULL },
553 { "erlang", Erlang_functions, Erlang_suffixes, NULL }, 558 { "erlang", Erlang_functions, NULL, Erlang_suffixes, NULL },
554 { "fortran", Fortran_functions, Fortran_suffixes, NULL }, 559 { "fortran", Fortran_functions, NULL, Fortran_suffixes, NULL },
555 { "java", Cjava_entries, Cjava_suffixes, NULL }, 560 { "java", Cjava_entries, NULL, Cjava_suffixes, NULL },
556 { "lisp", Lisp_functions, Lisp_suffixes, NULL }, 561 { "lisp", Lisp_functions, NULL, Lisp_suffixes, NULL },
557 { "pascal", Pascal_functions, Pascal_suffixes, NULL }, 562 { "makefile", Makefile_targets, Makefile_filenames, NULL, NULL },
558 { "perl", Perl_functions, Perl_suffixes, Perl_interpreters }, 563 { "pascal", Pascal_functions, NULL, Pascal_suffixes, NULL },
559 { "postscript", Postscript_functions, Postscript_suffixes, NULL }, 564 { "perl", Perl_functions, NULL, Perl_suffixes, Perl_interpreters },
560 { "proc", plain_C_entries, plain_C_suffixes, NULL }, 565 { "postscript", Postscript_functions, NULL, Postscript_suffixes, NULL },
561 { "prolog", Prolog_functions, Prolog_suffixes, NULL }, 566 { "proc", plain_C_entries, NULL, plain_C_suffixes, NULL },
562 { "python", Python_functions, Python_suffixes, NULL }, 567 { "prolog", Prolog_functions, NULL, Prolog_suffixes, NULL },
563 { "scheme", Scheme_functions, Scheme_suffixes, NULL }, 568 { "python", Python_functions, NULL, Python_suffixes, NULL },
564 { "tex", TeX_functions, TeX_suffixes, NULL }, 569 { "scheme", Scheme_functions, NULL, Scheme_suffixes, NULL },
565 { "texinfo", Texinfo_functions, Texinfo_suffixes, NULL }, 570 { "tex", TeX_commands, NULL, TeX_suffixes, NULL },
566 { "yacc", Yacc_entries, Yacc_suffixes, NULL }, 571 { "texinfo", Texinfo_nodes, NULL, Texinfo_suffixes, NULL },
572 { "yacc", Yacc_entries, NULL, Yacc_suffixes, NULL },
567 { "auto", NULL }, /* default guessing scheme */ 573 { "auto", NULL }, /* default guessing scheme */
568 { "none", just_read_file }, /* regexp matching only */ 574 { "none", just_read_file }, /* regexp matching only */
569 { NULL, NULL } /* end of list */ 575 { NULL, NULL } /* end of list */
570 }; 576 };
571 577
986 case 'S': /* for backward compatibility */ 992 case 'S': /* for backward compatibility */
987 noindentypedefs = TRUE; 993 noindentypedefs = TRUE;
988 break; 994 break;
989 case 'l': 995 case 'l':
990 { 996 {
991 language *lang = get_language_from_name (optarg); 997 language *lang = get_language_from_langname (optarg);
992 if (lang != NULL) 998 if (lang != NULL)
993 { 999 {
994 argbuffer[current_arg].lang = lang; 1000 argbuffer[current_arg].lang = lang;
995 argbuffer[current_arg].arg_type = at_language; 1001 argbuffer[current_arg].arg_type = at_language;
996 ++current_arg; 1002 ++current_arg;
1249 1255
1250 /* 1256 /*
1251 * Return a language given the name. 1257 * Return a language given the name.
1252 */ 1258 */
1253 static language * 1259 static language *
1254 get_language_from_name (name) 1260 get_language_from_langname (name)
1255 char *name; 1261 char *name;
1256 { 1262 {
1257 language *lang; 1263 language *lang;
1258 1264
1259 if (name == NULL) 1265 if (name == NULL)
1295 1301
1296 /* 1302 /*
1297 * Return a language given the file name. 1303 * Return a language given the file name.
1298 */ 1304 */
1299 static language * 1305 static language *
1300 get_language_from_suffix (file) 1306 get_language_from_filename (file)
1301 char *file; 1307 char *file;
1302 { 1308 {
1303 language *lang; 1309 language *lang;
1304 char **ext, *suffix; 1310 char **name, **ext, *suffix;
1305 1311
1312 /* Try whole file name first. */
1313 for (lang = lang_names; lang->name != NULL; lang++)
1314 if (lang->filenames != NULL)
1315 for (name = lang->filenames; *name != NULL; name++)
1316 if (streq (*name, file))
1317 return lang;
1318
1319 /* If not found, try suffix after last dot. */
1306 suffix = etags_strrchr (file, '.'); 1320 suffix = etags_strrchr (file, '.');
1307 if (suffix == NULL) 1321 if (suffix == NULL)
1308 return NULL; 1322 return NULL;
1309 suffix += 1; 1323 suffix += 1;
1310 for (lang = lang_names; lang->name != NULL; lang++) 1324 for (lang = lang_names; lang->name != NULL; lang++)
1528 lang->function (inf); 1542 lang->function (inf);
1529 return; 1543 return;
1530 } 1544 }
1531 1545
1532 /* Try to guess the language given the file name. */ 1546 /* Try to guess the language given the file name. */
1533 lang = get_language_from_suffix (file); 1547 lang = get_language_from_filename (file);
1534 if (lang != NULL && lang->function != NULL) 1548 if (lang != NULL && lang->function != NULL)
1535 { 1549 {
1536 curlang = lang; 1550 curlang = lang;
1537 lang->function (inf); 1551 lang->function (inf);
1538 return; 1552 return;
1573 which is unlikely. */ 1587 which is unlikely. */
1574 rewind (inf); 1588 rewind (inf);
1575 1589
1576 /* Try Fortran. */ 1590 /* Try Fortran. */
1577 old_last_node = last_node; 1591 old_last_node = last_node;
1578 curlang = get_language_from_name ("fortran"); 1592 curlang = get_language_from_langname ("fortran");
1579 Fortran_functions (inf); 1593 Fortran_functions (inf);
1580 1594
1581 /* No Fortran entries found. Try C. */ 1595 /* No Fortran entries found. Try C. */
1582 if (old_last_node == last_node) 1596 if (old_last_node == last_node)
1583 { 1597 {
1584 /* We do not tag if rewind fails. 1598 /* We do not tag if rewind fails.
1585 Only the file name will be recorded in the tags file. */ 1599 Only the file name will be recorded in the tags file. */
1586 rewind (inf); 1600 rewind (inf);
1587 curlang = get_language_from_name (cplusplus ? "c++" : "c"); 1601 curlang = get_language_from_langname (cplusplus ? "c++" : "c");
1588 default_C_entries (inf); 1602 default_C_entries (inf);
1589 } 1603 }
1590 return; 1604 return;
1591 } 1605 }
1592 1606
3852 pfnote (savenstr (bp, ep-bp), TRUE, 3866 pfnote (savenstr (bp, ep-bp), TRUE,
3853 lb.buffer, ep - lb.buffer + 1, lineno, linecharno); 3867 lb.buffer, ep - lb.buffer + 1, lineno, linecharno);
3854 } 3868 }
3855 } 3869 }
3856 3870
3871 /*
3872 * Makefile support
3873 */
3874 static void
3875 Makefile_targets (inf)
3876 FILE *inf;
3877 {
3878 register char *bp;
3879
3880 LOOP_ON_INPUT_LINES (inf, lb, bp)
3881 {
3882 if (*bp == '\t' || *bp == '#')
3883 continue;
3884 while (*bp != '\0' && *bp != '=' && *bp != ':')
3885 bp++;
3886 if (*bp == ':')
3887 pfnote (savenstr (lb.buffer, bp - lb.buffer), TRUE,
3888 lb.buffer, bp - lb.buffer + 1, lineno, linecharno);
3889 }
3890 }
3891
3857 /* Added by Mosur Mohan, 4/22/88 */ 3892 /* Added by Mosur Mohan, 4/22/88 */
3858 /* Pascal parsing */ 3893 /* Pascal parsing */
3859 3894
3860 /* 3895 /*
3861 * Locates tags for procedures & functions. Doesn't do any type- or 3896 * Locates tags for procedures & functions. Doesn't do any type- or
4237 4272
4238 /* 4273 /*
4239 * TeX/LaTeX scanning loop. 4274 * TeX/LaTeX scanning loop.
4240 */ 4275 */
4241 static void 4276 static void
4242 TeX_functions (inf) 4277 TeX_commands (inf)
4243 FILE *inf; 4278 FILE *inf;
4244 { 4279 {
4245 char *cp, *lasthit; 4280 char *cp, *lasthit;
4246 register int i; 4281 register int i;
4247 4282
4389 return -1; 4424 return -1;
4390 } 4425 }
4391 4426
4392 /* Texinfo support. Dave Love, Mar. 2000. */ 4427 /* Texinfo support. Dave Love, Mar. 2000. */
4393 static void 4428 static void
4394 Texinfo_functions (inf) 4429 Texinfo_nodes (inf)
4395 FILE * inf; 4430 FILE * inf;
4396 { 4431 {
4397 char *cp, *start; 4432 char *cp, *start;
4398 LOOP_ON_INPUT_LINES (inf, lb, cp) 4433 LOOP_ON_INPUT_LINES (inf, lb, cp)
4399 { 4434 {
4400 if ((*cp++ == '@' && *cp++ == 'n' && *cp++ == 'o' && *cp++ == 'd' 4435 if ((*cp++ == '@'
4401 && *cp++ == 'e' && iswhite (*cp++))) 4436 && *cp++ == 'n'
4402 { 4437 && *cp++ == 'o'
4403 while (iswhite (*cp)) 4438 && *cp++ == 'd'
4404 cp++; 4439 && *cp++ == 'e' && iswhite (*cp++)))
4405 start = cp; 4440 {
4406 while (*cp != '\0' && *cp != ',') 4441 start = cp = skip_spaces(cp);
4407 cp++; 4442 while (*cp != '\0' && *cp != ',')
4408 pfnote (savenstr (start, cp - start), TRUE, 4443 cp++;
4409 lb.buffer, cp - lb.buffer + 1, lineno, linecharno); 4444 pfnote (savenstr (start, cp - start), TRUE,
4410 } 4445 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4446 }
4411 } 4447 }
4412 } 4448 }
4413 4449
4414 /* 4450 /*
4415 * Prolog support (rewritten) by Anders Lindgren, Mar. 96 4451 * Prolog support (rewritten) by Anders Lindgren, Mar. 96
4857 { 4893 {
4858 error ("unterminated language name in regex: %s", regex_arg); 4894 error ("unterminated language name in regex: %s", regex_arg);
4859 return; 4895 return;
4860 } 4896 }
4861 *cp = '\0'; 4897 *cp = '\0';
4862 lang = get_language_from_name (lang_name); 4898 lang = get_language_from_langname (lang_name);
4863 if (lang == NULL) 4899 if (lang == NULL)
4864 return; 4900 return;
4865 add_regex (cp + 1, ignore_case, lang); 4901 add_regex (cp + 1, ignore_case, lang);
4866 } 4902 }
4867 break; 4903 break;
5488 canonicalize_filename (fn) 5524 canonicalize_filename (fn)
5489 register char *fn; 5525 register char *fn;
5490 { 5526 {
5491 #ifdef DOS_NT 5527 #ifdef DOS_NT
5492 /* Canonicalize drive letter case. */ 5528 /* Canonicalize drive letter case. */
5493 if (fn[0] && fn[1] == ':' && ISLOWER (fn[0])) 5529 if (fn[0] != '\0' && fn[1] == ':' && ISLOWER (fn[0]))
5494 fn[0] = UPCASE (fn[0]); 5530 fn[0] = upcase (fn[0]);
5495 /* Convert backslashes to slashes. */ 5531 /* Convert backslashes to slashes. */
5496 for (; *fn != '\0'; fn++) 5532 for (; *fn != '\0'; fn++)
5497 if (*fn == '\\') 5533 if (*fn == '\\')
5498 *fn = '/'; 5534 *fn = '/';
5499 #else 5535 #else