aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c96
1 files changed, 55 insertions, 41 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 0660ce70e71..d44494f931f 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.76"; 34char pot_etags_version[] = "@(#) pot revision number is 11.77";
35 35
36#define TRUE 1 36#define TRUE 1
37#define FALSE 0 37#define FALSE 0
@@ -54,6 +54,11 @@ char pot_etags_version[] = "@(#) pot revision number is 11.76";
54# define MAXPATHLEN _MAX_PATH 54# define MAXPATHLEN _MAX_PATH
55#endif 55#endif
56 56
57#if !defined (MSDOS) && !defined (WINDOWSNT) && defined (STDC_HEADERS)
58#include <stdlib.h>
59#include <string.h>
60#endif
61
57#ifdef HAVE_CONFIG_H 62#ifdef HAVE_CONFIG_H
58# include <config.h> 63# include <config.h>
59 /* On some systems, Emacs defines static as nothing for the sake 64 /* On some systems, Emacs defines static as nothing for the sake
@@ -107,7 +112,7 @@ extern int errno;
107#define streq(s,t) ((DEBUG &&!(s)&&!(t)&&(abort(),1)) || !strcmp(s,t)) 112#define streq(s,t) ((DEBUG &&!(s)&&!(t)&&(abort(),1)) || !strcmp(s,t))
108#define strneq(s,t,n) ((DEBUG &&!(s)&&!(t)&&(abort(),1)) || !strncmp(s,t,n)) 113#define strneq(s,t,n) ((DEBUG &&!(s)&&!(t)&&(abort(),1)) || !strncmp(s,t,n))
109 114
110#define lowcase(c) tolower ((unsigned char)c) 115#define lowcase(c) tolower ((char)c)
111 116
112#define iswhite(arg) (_wht[arg]) /* T if char is white */ 117#define iswhite(arg) (_wht[arg]) /* T if char is white */
113#define begtoken(arg) (_btk[arg]) /* T if char can start token */ 118#define begtoken(arg) (_btk[arg]) /* T if char can start token */
@@ -150,6 +155,7 @@ char *savenstr (), *savestr ();
150char *etags_strchr (), *etags_strrchr (); 155char *etags_strchr (), *etags_strrchr ();
151char *etags_getcwd (); 156char *etags_getcwd ();
152char *relative_filename (), *absolute_filename (), *absolute_dirname (); 157char *relative_filename (), *absolute_filename (), *absolute_dirname ();
158void grow_linebuffer ();
153long *xmalloc (), *xrealloc (); 159long *xmalloc (), *xrealloc ();
154 160
155typedef void Lang_function (); 161typedef void Lang_function ();
@@ -232,9 +238,6 @@ NODE *head; /* the head of the binary tree of tags */
232 * `readline' reads a line from a stream into a linebuffer and works 238 * `readline' reads a line from a stream into a linebuffer and works
233 * regardless of the length of the line. 239 * regardless of the length of the line.
234 */ 240 */
235#define GROW_LINEBUFFER(buf,toksize) \
236while (buf.size < toksize) \
237 buf.buffer = (char *) xrealloc (buf.buffer, buf.size *= 2)
238struct linebuffer 241struct linebuffer
239{ 242{
240 long size; 243 long size;
@@ -967,7 +970,7 @@ main (argc, argv)
967 "mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS", 970 "mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS",
968 tagfile, argbuffer[i].what, tagfile); 971 tagfile, argbuffer[i].what, tagfile);
969 if (system (cmd) != GOOD) 972 if (system (cmd) != GOOD)
970 fatal ("failed to execute shell command"); 973 fatal ("failed to execute shell command", NULL);
971 } 974 }
972 append_to_tagfile = TRUE; 975 append_to_tagfile = TRUE;
973 } 976 }
@@ -1339,7 +1342,7 @@ add_node (node, cur_node_p)
1339 { 1342 {
1340 /* Etags Mode */ 1343 /* Etags Mode */
1341 if (last_node == NULL) 1344 if (last_node == NULL)
1342 fatal ("internal error in add_node", 0); 1345 fatal ("internal error in add_node", NULL);
1343 last_node->right = node; 1346 last_node->right = node;
1344 last_node = node; 1347 last_node = node;
1345 } 1348 }
@@ -1405,7 +1408,7 @@ put_entries (node)
1405 else 1408 else
1406 { 1409 {
1407 if (node->name == NULL) 1410 if (node->name == NULL)
1408 error ("internal error: NULL name in ctags mode.", 0); 1411 error ("internal error: NULL name in ctags mode.", NULL);
1409 1412
1410 if (cxref_style) 1413 if (cxref_style)
1411 { 1414 {
@@ -1666,12 +1669,12 @@ in_word_set (str, len)
1666/*%>*/ 1669/*%>*/
1667 1670
1668enum sym_type 1671enum sym_type
1669C_symtype(str, len, c_ext) 1672C_symtype (str, len, c_ext)
1670 char *str; 1673 char *str;
1671 int len; 1674 int len;
1672 int c_ext; 1675 int c_ext;
1673{ 1676{
1674 register struct C_stab_entry *se = in_word_set(str, len); 1677 register struct C_stab_entry *se = in_word_set (str, len);
1675 1678
1676 if (se == NULL || (se->c_ext && !(c_ext & se->c_ext))) 1679 if (se == NULL || (se->c_ext && !(c_ext & se->c_ext)))
1677 return st_none; 1680 return st_none;
@@ -1847,7 +1850,7 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1847 case dignorerest: 1850 case dignorerest:
1848 return FALSE; 1851 return FALSE;
1849 default: 1852 default:
1850 error ("internal error: definedef value.", 0); 1853 error ("internal error: definedef value.", NULL);
1851 } 1854 }
1852 1855
1853 /* 1856 /*
@@ -1993,7 +1996,7 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
1993 { 1996 {
1994 objdef = omethodtag; 1997 objdef = omethodtag;
1995 methodlen = len; 1998 methodlen = len;
1996 GROW_LINEBUFFER (token_name, methodlen+1); 1999 grow_linebuffer (&token_name, methodlen+1);
1997 strncpy (token_name.buffer, str, len); 2000 strncpy (token_name.buffer, str, len);
1998 token_name.buffer[methodlen] = '\0'; 2001 token_name.buffer[methodlen] = '\0';
1999 return TRUE; 2002 return TRUE;
@@ -2008,7 +2011,7 @@ consider_token (str, len, c, c_ext, cblev, parlev, is_func)
2008 { 2011 {
2009 objdef = omethodtag; 2012 objdef = omethodtag;
2010 methodlen += len; 2013 methodlen += len;
2011 GROW_LINEBUFFER (token_name, methodlen+1); 2014 grow_linebuffer (&token_name, methodlen+1);
2012 strncat (token_name.buffer, str, len); 2015 strncat (token_name.buffer, str, len);
2013 return TRUE; 2016 return TRUE;
2014 } 2017 }
@@ -2099,7 +2102,7 @@ do { \
2099 2102
2100/* This macro should never be called when tok.valid is FALSE, but 2103/* This macro should never be called when tok.valid is FALSE, but
2101 we must protect about both invalid input and internal errors. */ 2104 we must protect about both invalid input and internal errors. */
2102#define make_tag(isfun) do \ 2105#define make_C_tag(isfun) do \
2103if (tok.valid) { \ 2106if (tok.valid) { \
2104 char *name = NULL; \ 2107 char *name = NULL; \
2105 if (CTAGS || tok.named) \ 2108 if (CTAGS || tok.named) \
@@ -2311,7 +2314,7 @@ C_entries (c_ext, inf)
2311 && is_func) 2314 && is_func)
2312 /* function defined in C++ class body */ 2315 /* function defined in C++ class body */
2313 { 2316 {
2314 GROW_LINEBUFFER (token_name, 2317 grow_linebuffer (&token_name,
2315 strlen(structtag)+2+toklen+1); 2318 strlen(structtag)+2+toklen+1);
2316 strcpy (token_name.buffer, structtag); 2319 strcpy (token_name.buffer, structtag);
2317 strcat (token_name.buffer, "::"); 2320 strcat (token_name.buffer, "::");
@@ -2322,7 +2325,7 @@ C_entries (c_ext, inf)
2322 else if (objdef == ocatseen) 2325 else if (objdef == ocatseen)
2323 /* Objective C category */ 2326 /* Objective C category */
2324 { 2327 {
2325 GROW_LINEBUFFER (token_name, 2328 grow_linebuffer (&token_name,
2326 strlen(objtag)+2+toklen+1); 2329 strlen(objtag)+2+toklen+1);
2327 strcpy (token_name.buffer, objtag); 2330 strcpy (token_name.buffer, objtag);
2328 strcat (token_name.buffer, "("); 2331 strcat (token_name.buffer, "(");
@@ -2339,7 +2342,7 @@ C_entries (c_ext, inf)
2339 } 2342 }
2340 else 2343 else
2341 { 2344 {
2342 GROW_LINEBUFFER (token_name, toklen+1); 2345 grow_linebuffer (&token_name, toklen+1);
2343 strncpy (token_name.buffer, 2346 strncpy (token_name.buffer,
2344 newlb.buffer+tokoff, toklen); 2347 newlb.buffer+tokoff, toklen);
2345 token_name.buffer[toklen] = '\0'; 2348 token_name.buffer[toklen] = '\0';
@@ -2367,7 +2370,7 @@ C_entries (c_ext, inf)
2367 switch_line_buffers (); 2370 switch_line_buffers ();
2368 } 2371 }
2369 else 2372 else
2370 make_tag (is_func); 2373 make_C_tag (is_func);
2371 } 2374 }
2372 midtoken = FALSE; 2375 midtoken = FALSE;
2373 } 2376 }
@@ -2389,7 +2392,7 @@ C_entries (c_ext, inf)
2389 funcdef = finlist; 2392 funcdef = finlist;
2390 continue; 2393 continue;
2391 case flistseen: 2394 case flistseen:
2392 make_tag (TRUE); 2395 make_C_tag (TRUE);
2393 funcdef = fignore; 2396 funcdef = fignore;
2394 break; 2397 break;
2395 case ftagseen: 2398 case ftagseen:
@@ -2424,13 +2427,13 @@ C_entries (c_ext, inf)
2424 { 2427 {
2425 case otagseen: 2428 case otagseen:
2426 objdef = oignore; 2429 objdef = oignore;
2427 make_tag (TRUE); 2430 make_C_tag (TRUE);
2428 break; 2431 break;
2429 case omethodtag: 2432 case omethodtag:
2430 case omethodparm: 2433 case omethodparm:
2431 objdef = omethodcolon; 2434 objdef = omethodcolon;
2432 methodlen += 1; 2435 methodlen += 1;
2433 GROW_LINEBUFFER (token_name, methodlen+1); 2436 grow_linebuffer (&token_name, methodlen+1);
2434 strcat (token_name.buffer, ":"); 2437 strcat (token_name.buffer, ":");
2435 break; 2438 break;
2436 } 2439 }
@@ -2442,7 +2445,7 @@ C_entries (c_ext, inf)
2442 case ftagseen: 2445 case ftagseen:
2443 if (yacc_rules) 2446 if (yacc_rules)
2444 { 2447 {
2445 make_tag (FALSE); 2448 make_C_tag (FALSE);
2446 funcdef = fignore; 2449 funcdef = fignore;
2447 } 2450 }
2448 break; 2451 break;
@@ -2458,7 +2461,7 @@ C_entries (c_ext, inf)
2458 switch (typdef) 2461 switch (typdef)
2459 { 2462 {
2460 case tend: 2463 case tend:
2461 make_tag (FALSE); 2464 make_C_tag (FALSE);
2462 /* FALLTHRU */ 2465 /* FALLTHRU */
2463 default: 2466 default:
2464 typdef = tnone; 2467 typdef = tnone;
@@ -2481,7 +2484,7 @@ C_entries (c_ext, inf)
2481 { 2484 {
2482 case omethodtag: 2485 case omethodtag:
2483 case omethodparm: 2486 case omethodparm:
2484 make_tag (TRUE); 2487 make_C_tag (TRUE);
2485 objdef = oinbody; 2488 objdef = oinbody;
2486 break; 2489 break;
2487 } 2490 }
@@ -2496,7 +2499,7 @@ C_entries (c_ext, inf)
2496 if (cblev == 0 && typdef == tend) 2499 if (cblev == 0 && typdef == tend)
2497 { 2500 {
2498 typdef = tignore; 2501 typdef = tignore;
2499 make_tag (FALSE); 2502 make_C_tag (FALSE);
2500 break; 2503 break;
2501 } 2504 }
2502 if (funcdef != finlist && funcdef != fignore) 2505 if (funcdef != finlist && funcdef != fignore)
@@ -2522,7 +2525,7 @@ C_entries (c_ext, inf)
2522 if (*lp != '*') 2525 if (*lp != '*')
2523 { 2526 {
2524 typdef = tignore; 2527 typdef = tignore;
2525 make_tag (FALSE); 2528 make_C_tag (FALSE);
2526 } 2529 }
2527 break; 2530 break;
2528 } /* switch (typdef) */ 2531 } /* switch (typdef) */
@@ -2541,7 +2544,7 @@ C_entries (c_ext, inf)
2541 break; 2544 break;
2542 if (objdef == ocatseen && parlev == 1) 2545 if (objdef == ocatseen && parlev == 1)
2543 { 2546 {
2544 make_tag (TRUE); 2547 make_C_tag (TRUE);
2545 objdef = oignore; 2548 objdef = oignore;
2546 } 2549 }
2547 if (--parlev == 0) 2550 if (--parlev == 0)
@@ -2556,7 +2559,7 @@ C_entries (c_ext, inf)
2556 if (cblev == 0 && typdef == tend) 2559 if (cblev == 0 && typdef == tend)
2557 { 2560 {
2558 typdef = tignore; 2561 typdef = tignore;
2559 make_tag (FALSE); 2562 make_C_tag (FALSE);
2560 } 2563 }
2561 } 2564 }
2562 else if (parlev < 0) /* can happen due to ill-conceived #if's. */ 2565 else if (parlev < 0) /* can happen due to ill-conceived #if's. */
@@ -2576,13 +2579,13 @@ C_entries (c_ext, inf)
2576 case stagseen: 2579 case stagseen:
2577 case scolonseen: /* named struct */ 2580 case scolonseen: /* named struct */
2578 structdef = sinbody; 2581 structdef = sinbody;
2579 make_tag (FALSE); 2582 make_C_tag (FALSE);
2580 break; 2583 break;
2581 } 2584 }
2582 switch (funcdef) 2585 switch (funcdef)
2583 { 2586 {
2584 case flistseen: 2587 case flistseen:
2585 make_tag (TRUE); 2588 make_C_tag (TRUE);
2586 /* FALLTHRU */ 2589 /* FALLTHRU */
2587 case fignore: 2590 case fignore:
2588 funcdef = fnone; 2591 funcdef = fnone;
@@ -2591,12 +2594,12 @@ C_entries (c_ext, inf)
2591 switch (objdef) 2594 switch (objdef)
2592 { 2595 {
2593 case otagseen: 2596 case otagseen:
2594 make_tag (TRUE); 2597 make_C_tag (TRUE);
2595 objdef = oignore; 2598 objdef = oignore;
2596 break; 2599 break;
2597 case omethodtag: 2600 case omethodtag:
2598 case omethodparm: 2601 case omethodparm:
2599 make_tag (TRUE); 2602 make_C_tag (TRUE);
2600 objdef = oinbody; 2603 objdef = oinbody;
2601 break; 2604 break;
2602 default: 2605 default:
@@ -2658,7 +2661,7 @@ C_entries (c_ext, inf)
2658 case '\0': 2661 case '\0':
2659 if (objdef == otagseen) 2662 if (objdef == otagseen)
2660 { 2663 {
2661 make_tag (TRUE); 2664 make_C_tag (TRUE);
2662 objdef = oignore; 2665 objdef = oignore;
2663 } 2666 }
2664 /* If a macro spans multiple lines don't reset its state. */ 2667 /* If a macro spans multiple lines don't reset its state. */
@@ -3089,7 +3092,7 @@ Pascal_functions (inf)
3089 continue; 3092 continue;
3090 3093
3091 /* save all values for later tagging */ 3094 /* save all values for later tagging */
3092 GROW_LINEBUFFER (tline, strlen (lb.buffer) + 1); 3095 grow_linebuffer (&tline, strlen (lb.buffer) + 1);
3093 strcpy (tline.buffer, lb.buffer); 3096 strcpy (tline.buffer, lb.buffer);
3094 save_lineno = lineno; 3097 save_lineno = lineno;
3095 save_lcno = linecharno; 3098 save_lcno = linecharno;
@@ -3535,7 +3538,7 @@ Prolog_functions (inf)
3535 else if (isspace (dbp[0])) /* Not a predicate */ 3538 else if (isspace (dbp[0])) /* Not a predicate */
3536 continue; 3539 continue;
3537 else if (dbp[0] == '/' && dbp[1] == '*') /* comment. */ 3540 else if (dbp[0] == '/' && dbp[1] == '*') /* comment. */
3538 prolog_skip_comment (&lb, inf, &lineno, &linecharno); 3541 prolog_skip_comment (&lb, inf);
3539 else if (len = prolog_pred (dbp, last)) 3542 else if (len = prolog_pred (dbp, last))
3540 { 3543 {
3541 /* Predicate. Store the function name so that we only 3544 /* Predicate. Store the function name so that we only
@@ -3968,7 +3971,7 @@ add_regex (regexp_pattern)
3968 3971
3969 if (regexp_pattern[0] == '\0') 3972 if (regexp_pattern[0] == '\0')
3970 { 3973 {
3971 error ("missing regexp", 0); 3974 error ("missing regexp", NULL);
3972 return; 3975 return;
3973 } 3976 }
3974 if (regexp_pattern[strlen(regexp_pattern)-1] != regexp_pattern[0]) 3977 if (regexp_pattern[strlen(regexp_pattern)-1] != regexp_pattern[0])
@@ -3979,7 +3982,7 @@ add_regex (regexp_pattern)
3979 name = scan_separators (regexp_pattern); 3982 name = scan_separators (regexp_pattern);
3980 if (regexp_pattern[0] == '\0') 3983 if (regexp_pattern[0] == '\0')
3981 { 3984 {
3982 error ("null regexp", 0); 3985 error ("null regexp", NULL);
3983 return; 3986 return;
3984 } 3987 }
3985 (void) scan_separators (name); 3988 (void) scan_separators (name);
@@ -4411,8 +4414,8 @@ relative_filename (file, dir)
4411 dp = dir; 4414 dp = dir;
4412 while (*fp++ == *dp++) 4415 while (*fp++ == *dp++)
4413 continue; 4416 continue;
4414 fp--, dp--; /* back to the first different char */ 4417 fp--, dp--; /* back to the first differing char */
4415 do 4418 do /* look at the equal chars until / */
4416 fp--, dp--; 4419 fp--, dp--;
4417 while (*fp != '/'); 4420 while (*fp != '/');
4418 4421
@@ -4526,6 +4529,17 @@ absolute_dirname (file, cwd)
4526 return res; 4529 return res;
4527} 4530}
4528 4531
4532/* Increase the size of a linebuffer. */
4533void
4534grow_linebuffer (bufp, toksize)
4535 struct linebuffer *bufp;
4536 int toksize;
4537{
4538 while (bufp->size < toksize)
4539 bufp->size *= 2;
4540 bufp->buffer = (char *) xrealloc (bufp->buffer, bufp->size);
4541}
4542
4529/* Like malloc but get fatal error if memory is exhausted. */ 4543/* Like malloc but get fatal error if memory is exhausted. */
4530long * 4544long *
4531xmalloc (size) 4545xmalloc (size)
@@ -4533,7 +4547,7 @@ xmalloc (size)
4533{ 4547{
4534 long *result = (long *) malloc (size); 4548 long *result = (long *) malloc (size);
4535 if (result == NULL) 4549 if (result == NULL)
4536 fatal ("virtual memory exhausted", 0); 4550 fatal ("virtual memory exhausted", NULL);
4537 return result; 4551 return result;
4538} 4552}
4539 4553
@@ -4544,6 +4558,6 @@ xrealloc (ptr, size)
4544{ 4558{
4545 long *result = (long *) realloc (ptr, size); 4559 long *result = (long *) realloc (ptr, size);
4546 if (result == NULL) 4560 if (result == NULL)
4547 fatal ("virtual memory exhausted"); 4561 fatal ("virtual memory exhausted", NULL);
4548 return result; 4562 return result;
4549} 4563}