aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c88
1 files changed, 49 insertions, 39 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 0928fada4d2..0660ce70e71 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.71"; 34char pot_etags_version[] = "@(#) pot revision number is 11.76";
35 35
36#define TRUE 1 36#define TRUE 1
37#define FALSE 0 37#define FALSE 0
@@ -268,7 +268,7 @@ logical typedefs_and_cplusplus; /* -T: create tags for typedefs, level */
268 /* 0 struct/enum/union decls, and C++ */ 268 /* 0 struct/enum/union decls, and C++ */
269 /* member functions. */ 269 /* member functions. */
270logical constantypedefs; /* -d: create tags for C #define and enum */ 270logical constantypedefs; /* -d: create tags for C #define and enum */
271 /* constants. Enum consts not implemented. */ 271 /* constants. */
272 /* -D: opposite of -d. Default under ctags. */ 272 /* -D: opposite of -d. Default under ctags. */
273logical update; /* -u: update tags */ 273logical update; /* -u: update tags */
274logical vgrind_style; /* -v: create vgrind style index output */ 274logical vgrind_style; /* -v: create vgrind style index output */
@@ -481,11 +481,11 @@ are. Relative ones are stored relative to the output file's directory.");
481 481
482 if (CTAGS) 482 if (CTAGS)
483 puts ("-d, --defines\n\ 483 puts ("-d, --defines\n\
484 Create tag entries for constant C #defines, too."); 484 Create tag entries for C #define constants and enum constants, too.");
485 else 485 else
486 puts ("-D, --no-defines\n\ 486 puts ("-D, --no-defines\n\
487 Don't create tag entries for constant C #defines. This makes\n\ 487 Don't create tag entries for C #define constants and enum constants.\n\
488 the tags file smaller."); 488 This makes the tags file smaller.");
489 489
490 if (!CTAGS) 490 if (!CTAGS)
491 { 491 {
@@ -731,7 +731,7 @@ main (argc, argv)
731 731
732 /* 732 /*
733 * If etags, always find typedefs and structure tags. Why not? 733 * If etags, always find typedefs and structure tags. Why not?
734 * Also default is to find macro constants. 734 * Also default is to find macro constants and enum constants.
735 */ 735 */
736 if (!CTAGS) 736 if (!CTAGS)
737 typedefs = typedefs_and_cplusplus = constantypedefs = TRUE; 737 typedefs = typedefs_and_cplusplus = constantypedefs = TRUE;
@@ -1784,10 +1784,10 @@ int methodlen;
1784 * consider_token () 1784 * consider_token ()
1785 * checks to see if the current token is at the start of a 1785 * checks to see if the current token is at the start of a
1786 * function, or corresponds to a typedef, or is a struct/union/enum 1786 * function, or corresponds to a typedef, or is a struct/union/enum
1787 * tag. 1787 * tag, or #define, or an enum constant.
1788 * 1788 *
1789 * *IS_FUNC gets TRUE iff the token is a function or macro with args. 1789 * *IS_FUNC gets TRUE iff the token is a function or #define macro
1790 * C_EXT is which language we are looking at. 1790 * with args. C_EXT is which language we are looking at.
1791 * 1791 *
1792 * In the future we will need some way to adjust where the end of 1792 * In the future we will need some way to adjust where the end of
1793 * the token is; for instance, implementing the C++ keyword 1793 * the token is; for instance, implementing the C++ keyword
@@ -1897,11 +1897,6 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1897 * This structdef business is NOT invoked when we are ctags and the 1897 * This structdef business is NOT invoked when we are ctags and the
1898 * file is plain C. This is because a struct tag may have the same 1898 * file is plain C. This is because a struct tag may have the same
1899 * name as another tag, and this loses with ctags. 1899 * name as another tag, and this loses with ctags.
1900 *
1901 * This if statement deals with the typdef state machine as
1902 * follows: if typdef==ttypedseen and token is struct/union/class/enum,
1903 * return FALSE. All the other code here is for the structdef
1904 * state machine.
1905 */ 1900 */
1906 switch (toktype) 1901 switch (toktype)
1907 { 1902 {
@@ -1915,6 +1910,7 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1915 } 1910 }
1916 return FALSE; 1911 return FALSE;
1917 } 1912 }
1913
1918 if (structdef == skeyseen) 1914 if (structdef == skeyseen)
1919 { 1915 {
1920 /* Save the tag for struct/union/class, for functions that may be 1916 /* Save the tag for struct/union/class, for functions that may be
@@ -1934,7 +1930,20 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1934 return FALSE; 1930 return FALSE;
1935 } 1931 }
1936 1932
1937 /* Detect GNU macros. */ 1933 /* Detect GNU macros.
1934
1935 DEFUN note for writers of emacs C code:
1936 The DEFUN macro, used in emacs C source code, has a first arg
1937 that is a string (the lisp function name), and a second arg that
1938 is a C function name. Since etags skips strings, the second arg
1939 is tagged. This is unfortunate, as it would be better to tag the
1940 first arg. The simplest way to deal with this problem would be
1941 to name the tag with a name built from the function name, by
1942 removing the initial 'F' character and substituting '-' for '_'.
1943 Anyway, this assumes that the conventions of naming lisp
1944 functions will never change. Currently, this method is not
1945 implemented, so writers of emacs code are recommended to put the
1946 first two args of a DEFUN on the same line. */
1938 if (definedef == dnone && toktype == st_C_gnumacro) 1947 if (definedef == dnone && toktype == st_C_gnumacro)
1939 { 1948 {
1940 next_token_is_func = TRUE; 1949 next_token_is_func = TRUE;
@@ -1948,9 +1957,7 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1948 return TRUE; 1957 return TRUE;
1949 } 1958 }
1950 1959
1951 /* 1960 /* Detect Objective C constructs. */
1952 * Detecting Objective C constructs.
1953 */
1954 switch (objdef) 1961 switch (objdef)
1955 { 1962 {
1956 case onone: 1963 case onone:
@@ -2020,14 +2027,16 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2020 return FALSE; 2027 return FALSE;
2021 } 2028 }
2022 2029
2023 /* A function? */ 2030 /* A function or enum constant? */
2024 switch (toktype) 2031 switch (toktype)
2025 { 2032 {
2026 case st_C_typespec: 2033 case st_C_typespec:
2027 if (funcdef != finlist && funcdef != fignore) 2034 if (funcdef != finlist && funcdef != fignore)
2028 funcdef = fnone; /* should be useless */ 2035 funcdef = fnone; /* should be useless */
2029 return FALSE; 2036 return FALSE;
2030 default: 2037 case st_none:
2038 if (constantypedefs && structdef == sinbody && structtype == st_C_enum)
2039 return TRUE;
2031 if (funcdef == fnone) 2040 if (funcdef == fnone)
2032 { 2041 {
2033 funcdef = ftagseen; 2042 funcdef = ftagseen;
@@ -2041,9 +2050,9 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2041 2050
2042/* 2051/*
2043 * C_entries () 2052 * C_entries ()
2044 * This routine finds functions, typedefs, #define's and 2053 * This routine finds functions, typedefs, #define's, enum
2045 * struct/union/enum definitions in C syntax and adds them 2054 * constants and struct/union/enum definitions in C syntax
2046 * to the list. 2055 * and adds them to the list.
2047 */ 2056 */
2048typedef struct 2057typedef struct
2049{ 2058{
@@ -2088,8 +2097,8 @@ do { \
2088 definedef = dnone; \ 2097 definedef = dnone; \
2089} while (0) 2098} while (0)
2090 2099
2091/* Ideally this macro should never be called wihen tok.valid is FALSE, 2100/* This macro should never be called when tok.valid is FALSE, but
2092 but this would mean that the state machines always guess right. */ 2101 we must protect about both invalid input and internal errors. */
2093#define make_tag(isfun) do \ 2102#define make_tag(isfun) do \
2094if (tok.valid) { \ 2103if (tok.valid) { \
2095 char *name = NULL; \ 2104 char *name = NULL; \
@@ -2097,7 +2106,7 @@ if (tok.valid) { \
2097 name = savestr (token_name.buffer); \ 2106 name = savestr (token_name.buffer); \
2098 pfnote (name, isfun, tok.buffer, tok.linelen, tok.lineno, tok.linepos); \ 2107 pfnote (name, isfun, tok.buffer, tok.linelen, tok.lineno, tok.linepos); \
2099 tok.valid = FALSE; \ 2108 tok.valid = FALSE; \
2100} while (0) 2109} /* else if (DEBUG) abort (); */ while (0)
2101 2110
2102void 2111void
2103C_entries (c_ext, inf) 2112C_entries (c_ext, inf)
@@ -2270,7 +2279,8 @@ C_entries (c_ext, inf)
2270 /* Consider token only if some complicated conditions are satisfied. */ 2279 /* Consider token only if some complicated conditions are satisfied. */
2271 if ((definedef != dnone 2280 if ((definedef != dnone
2272 || (cblev == 0 && structdef != scolonseen) 2281 || (cblev == 0 && structdef != scolonseen)
2273 || (cblev == 1 && cplpl && structdef == sinbody)) 2282 || (cblev == 1 && cplpl && structdef == sinbody)
2283 || (structdef == sinbody && structtype == st_C_enum))
2274 && typdef != tignore 2284 && typdef != tignore
2275 && definedef != dignorerest 2285 && definedef != dignorerest
2276 && funcdef != finlist) 2286 && funcdef != finlist)
@@ -2560,8 +2570,8 @@ C_entries (c_ext, inf)
2560 switch (structdef) 2570 switch (structdef)
2561 { 2571 {
2562 case skeyseen: /* unnamed struct */ 2572 case skeyseen: /* unnamed struct */
2563 structtag = "_anonymous_";
2564 structdef = sinbody; 2573 structdef = sinbody;
2574 structtag = "_anonymous_";
2565 break; 2575 break;
2566 case stagseen: 2576 case stagseen:
2567 case scolonseen: /* named struct */ 2577 case scolonseen: /* named struct */
@@ -2590,7 +2600,7 @@ C_entries (c_ext, inf)
2590 objdef = oinbody; 2600 objdef = oinbody;
2591 break; 2601 break;
2592 default: 2602 default:
2593 /* Neutralize `extern "C" {' grot and look inside structs. */ 2603 /* Neutralize `extern "C" {' grot. */
2594 if (cblev == 0 && structdef == snone && typdef == tnone) 2604 if (cblev == 0 && structdef == snone && typdef == tnone)
2595 cblev = -1; 2605 cblev = -1;
2596 } 2606 }
@@ -4337,7 +4347,6 @@ etags_getcwd ()
4337#ifdef HAVE_GETCWD 4347#ifdef HAVE_GETCWD
4338 int bufsize = 200; 4348 int bufsize = 200;
4339 char *path = xnew (bufsize, char); 4349 char *path = xnew (bufsize, char);
4340 char *p;
4341 4350
4342 while (getcwd (path, bufsize) == NULL) 4351 while (getcwd (path, bufsize) == NULL)
4343 { 4352 {
@@ -4347,11 +4356,14 @@ etags_getcwd ()
4347 path = xnew (bufsize, char); 4356 path = xnew (bufsize, char);
4348 } 4357 }
4349 4358
4350 /* Convert backslashes to slashes. */
4351#if WINDOWSNT 4359#if WINDOWSNT
4352 for (p = path; *p != '\0'; p++) 4360 {
4353 if (*p == '\\') 4361 /* Convert backslashes to slashes. */
4354 *p = '/'; 4362 char *p;
4363 for (p = path; *p != '\0'; p++)
4364 if (*p == '\\')
4365 *p = '/';
4366 }
4355#endif 4367#endif
4356 4368
4357 return path; 4369 return path;
@@ -4393,17 +4405,15 @@ relative_filename (file, dir)
4393{ 4405{
4394 char *fp, *dp, *abs, *res; 4406 char *fp, *dp, *abs, *res;
4395 4407
4396 /* Find the common root of file and dir. */ 4408 /* Find the common root of file and dir (with a trailing slash). */
4397 abs = absolute_filename (file, cwd); 4409 abs = absolute_filename (file, cwd);
4398 fp = abs; 4410 fp = abs;
4399 dp = dir; 4411 dp = dir;
4400 while (*fp++ == *dp++) 4412 while (*fp++ == *dp++)
4401 continue; 4413 continue;
4414 fp--, dp--; /* back to the first different char */
4402 do 4415 do
4403 { 4416 fp--, dp--;
4404 fp--;
4405 dp--;
4406 }
4407 while (*fp != '/'); 4417 while (*fp != '/');
4408 4418
4409 /* Build a sequence of "../" strings for the resulting relative filename. */ 4419 /* Build a sequence of "../" strings for the resulting relative filename. */