aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorEli Zaretskii2024-10-08 15:39:33 +0300
committerEli Zaretskii2024-10-08 15:39:33 +0300
commit339ffd79862c322f5b75fed1b55d61efe90bc7a1 (patch)
treecd04c286e6c0e9346cce40bce16186490c1e4fa5 /lib-src
parent9c94363894ced4ed84014cf0dc347af7882643e6 (diff)
downloademacs-339ffd79862c322f5b75fed1b55d61efe90bc7a1.tar.gz
emacs-339ffd79862c322f5b75fed1b55d61efe90bc7a1.zip
New command-line options for 'etags'
This adds '--no-fallback-lang' and '--no-empty-file-entries' options, and their opposites '--fallback-lang' and '--empty-file-entries'. * lib-src/etags.c (fallback_lang, empty_files): New toggles. (main): Initialize them to 'true'. (longopts) [!CTAGS]: Add the '--(no-)fallback-lang' and '--(no-)empty-file-entries' options. (find_entries): If 'fallback_lang' is false, don't attempt Fortran and C/C++ fallbacks. (print_help): Add help for new options. (main): If 'empty_files' is false, don't output file entries for files that have no tags. (Bug#73484) * doc/emacs/maintaining.texi (Create Tags Table): * etc/NEWS: * doc/man/etags.1: Document the new options. * test/manual/etags/Makefile (check): Add test for new options. * test/manual/etags/ETAGS.good_7: New file.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c70
1 files changed, 55 insertions, 15 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 4c9b954c9a3..a822a823a90 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -480,6 +480,8 @@ static bool ignoreindent; /* -I: ignore indentation in C */
480static int packages_only; /* --packages-only: in Ada, only tag packages*/ 480static int packages_only; /* --packages-only: in Ada, only tag packages*/
481static int class_qualify; /* -Q: produce class-qualified tags in C++/Java */ 481static int class_qualify; /* -Q: produce class-qualified tags in C++/Java */
482static int debug; /* --debug */ 482static int debug; /* --debug */
483static int fallback_lang; /* --(no-)fallback-lang: Fortran/C fallbacks */
484static int empty_files; /* --(no-)empty-file-entries */
483 485
484/* STDIN is defined in LynxOS system headers */ 486/* STDIN is defined in LynxOS system headers */
485#ifdef STDIN 487#ifdef STDIN
@@ -530,6 +532,10 @@ static struct option longopts[] =
530 { "no-defines", no_argument, NULL, 'D' }, 532 { "no-defines", no_argument, NULL, 'D' },
531 { "no-globals", no_argument, &globals, 0 }, 533 { "no-globals", no_argument, &globals, 0 },
532 { "include", required_argument, NULL, 'i' }, 534 { "include", required_argument, NULL, 'i' },
535 { "no-fallback-lang", no_argument, &fallback_lang, 0 },
536 { "fallback-lang", no_argument, &fallback_lang, 1 },
537 { "no-empty-file-entries", no_argument, &empty_files, 0 },
538 { "empty-file-entries", no_argument, &empty_files, 1 },
533#endif 539#endif
534 { NULL } 540 { NULL }
535}; 541};
@@ -1039,6 +1045,20 @@ Relative ones are stored relative to the output file's directory.\n");
1039 Do not create tag entries for members of structures\n\ 1045 Do not create tag entries for members of structures\n\
1040 in some languages."); 1046 in some languages.");
1041 1047
1048 if (!CTAGS)
1049 {
1050 puts ("--fallback-lang\n\
1051 If a file's language could not be determined, try to parse\n\
1052 it as Fortran and C/C++.");
1053 puts ("--no-fallback-lang\n\
1054 Do not fall back to Fortran and C/C++ if a file's language\n\
1055 could not be determined.");
1056 puts ("--empty-file-entries\n\
1057 Produce file entries for files with no tags.");
1058 puts ("--no-empty-file-entries\n\
1059 Do not output file entries for files with no tags.");
1060 }
1061
1042 puts ("-Q, --class-qualify\n\ 1062 puts ("-Q, --class-qualify\n\
1043 Qualify tag names with their class name in C++, ObjC, Java, and Perl.\n\ 1063 Qualify tag names with their class name in C++, ObjC, Java, and Perl.\n\
1044 This produces tag names of the form \"class::member\" for C++,\n\ 1064 This produces tag names of the form \"class::member\" for C++,\n\
@@ -1161,6 +1181,15 @@ main (int argc, char **argv)
1161 typedefs = typedefs_or_cplusplus = constantypedefs = true; 1181 typedefs = typedefs_or_cplusplus = constantypedefs = true;
1162 globals = members = true; 1182 globals = members = true;
1163 1183
1184 /* By default, fall back to Fortran/C/C++ if no language is detected by the
1185 file's name. This could be reversed in a future version, but only for
1186 ETAGS. */
1187 fallback_lang = true;
1188
1189 /* By default, output file entries for files that have no tags. This affects
1190 only ETAGS. */
1191 empty_files = true;
1192
1164 /* When the optstring begins with a '-' getopt_long does not rearrange the 1193 /* When the optstring begins with a '-' getopt_long does not rearrange the
1165 non-options arguments to be at the end, but leaves them alone. */ 1194 non-options arguments to be at the end, but leaves them alone. */
1166 optstring = concat ("-ac:Cf:Il:o:Qr:RSVhH", 1195 optstring = concat ("-ac:Cf:Il:o:Qr:RSVhH",
@@ -1388,10 +1417,13 @@ main (int argc, char **argv)
1388 { 1417 {
1389 fdesc *fdp; 1418 fdesc *fdp;
1390 1419
1391 /* Output file entries that have no tags. */ 1420 /* Output file entries that have no tags, unless disabled. */
1392 for (fdp = fdhead; fdp != NULL; fdp = fdp->next) 1421 if (empty_files)
1393 if (!fdp->written) 1422 {
1394 fprintf (tagf, "\f\n%s,0\n", fdp->taggedfname); 1423 for (fdp = fdhead; fdp != NULL; fdp = fdp->next)
1424 if (!fdp->written)
1425 fprintf (tagf, "\f\n%s,0\n", fdp->taggedfname);
1426 }
1395 1427
1396 while (nincluded_files-- > 0) 1428 while (nincluded_files-- > 0)
1397 fprintf (tagf, "\f\n%s,include\n", *included_files++); 1429 fprintf (tagf, "\f\n%s,include\n", *included_files++);
@@ -1951,22 +1983,30 @@ find_entries (FILE *inf)
1951 } 1983 }
1952 } 1984 }
1953 1985
1954 /* Else try Fortran or C. */ 1986 /* Else try Fortran or C if that fallback is not disabled. */
1955 if (parser == NULL) 1987 if (parser == NULL)
1956 { 1988 {
1957 node *old_last_node = last_node; 1989 if (fallback_lang)
1958
1959 curfdp->lang = get_language_from_langname ("fortran");
1960 find_entries (inf);
1961
1962 if (old_last_node == last_node)
1963 /* No Fortran entries found. Try C. */
1964 { 1990 {
1965 reset_input (inf); 1991 node *old_last_node = last_node;
1966 curfdp->lang = get_language_from_langname (cplusplus ? "c++" : "c"); 1992
1993 curfdp->lang = get_language_from_langname ("fortran");
1967 find_entries (inf); 1994 find_entries (inf);
1995
1996 if (old_last_node == last_node)
1997 /* No Fortran entries found. Try C. */
1998 {
1999 reset_input (inf);
2000 curfdp->lang = get_language_from_langname (cplusplus
2001 ? "c++" : "c");
2002 find_entries (inf);
2003 }
2004 return;
1968 } 2005 }
1969 return; 2006 /* If fallbacks are disabled, treat files without a language as if
2007 '--language=none' was specified for them. */
2008 curfdp->lang = get_language_from_langname ("none");
2009 parser = curfdp->lang->function;
1970 } 2010 }
1971 2011
1972 if (!no_line_directive 2012 if (!no_line_directive