comparison lib-src/etags.c @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents 6b37e6ddd302
children 2d532a89d707
comparison
equal deleted inserted replaced
172:a38aed19690b 173:8eaf7971accc
29 * Regexp tags by Tom Tromey. 29 * Regexp tags by Tom Tromey.
30 * 30 *
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
34 char pot_etags_version[] = "@(#) pot revision number is 12.11"; 34 char pot_etags_version[] = "@(#) pot revision number is 12.19";
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
40 # define DEBUG FALSE 40 # define DEBUG FALSE
41 #endif 41 #endif
42 42
43 #ifdef MSDOS 43 #ifdef MSDOS
44 # include <string.h>
45 # include <fcntl.h> 44 # include <fcntl.h>
46 # include <sys/param.h> 45 # include <sys/param.h>
46 # include <io.h>
47 # ifndef HAVE_CONFIG_H
48 # define DOS_NT
49 # include <sys/config.h>
50 # endif
47 #endif /* MSDOS */ 51 #endif /* MSDOS */
48 52
49 #ifdef WINDOWSNT 53 #ifdef WINDOWSNT
50 # include <stdlib.h> 54 # include <stdlib.h>
51 # include <fcntl.h> 55 # include <fcntl.h>
52 # include <string.h> 56 # include <string.h>
53 # include <io.h> 57 # include <io.h>
54 # define MAXPATHLEN _MAX_PATH 58 # define MAXPATHLEN _MAX_PATH
55 #endif 59 # ifdef HAVE_CONFIG_H
60 # undef HAVE_NTGUI
61 # else
62 # define DOS_NT
63 # define HAVE_GETCWD
64 # endif /* not HAVE_CONFIG_H */
65 #endif /* WINDOWSNT */
56 66
57 #ifdef HAVE_CONFIG_H 67 #ifdef HAVE_CONFIG_H
58 # include <config.h> 68 # include <config.h>
59 /* On some systems, Emacs defines static as nothing for the sake 69 /* On some systems, Emacs defines static as nothing for the sake
60 of unexec. We don't want that here since we don't use unexec. */ 70 of unexec. We don't want that here since we don't use unexec. */
61 # undef static 71 # undef static
62 # define ETAGS_REGEXPS 72 # define ETAGS_REGEXPS /* use the regexp features */
63 # define LONG_OPTIONS 73 # define LONG_OPTIONS /* accept long options */
64 #endif 74 #endif /* HAVE_CONFIG_H */
65 75
66 #if !defined (MSDOS) && !defined (WINDOWSNT) && defined (STDC_HEADERS) 76 #if !defined (WINDOWSNT) && defined (STDC_HEADERS)
67 #include <stdlib.h> 77 #include <stdlib.h>
68 #include <string.h> 78 #include <string.h>
69 #endif 79 #endif
80
81 #ifdef HAVE_UNISTD_H
82 # include <unistd.h>
83 #else
84 # ifdef HAVE_GETCWD
85 extern char *getcwd ();
86 # endif
87 #endif /* HAVE_UNISTD_H */
70 88
71 #include <stdio.h> 89 #include <stdio.h>
72 #include <ctype.h> 90 #include <ctype.h>
73 #include <errno.h> 91 #include <errno.h>
74 #ifndef errno 92 #ifndef errno
75 extern int errno; 93 extern int errno;
76 #endif 94 #endif
77 #include <sys/types.h> 95 #include <sys/types.h>
78 #include <sys/stat.h> 96 #include <sys/stat.h>
79 97
80 #if !defined (S_ISREG) && defined (S_IFREG) 98 #if !defined (S_ISREG) && defined (S_IFREG)
81 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 99 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
82 #endif 100 #endif
83 101
84 #ifdef HAVE_UNISTD_H
85 #include <unistd.h>
86 #endif
87
88 #ifdef LONG_OPTIONS 102 #ifdef LONG_OPTIONS
89 # include "getopt.h" 103 # include <getopt.h>
90 #else 104 #else
91 # define getopt_long(argc,argv,optstr,lopts,lind) getopt (argc, argv, optstr) 105 # define getopt_long(argc,argv,optstr,lopts,lind) getopt (argc, argv, optstr)
92 extern char *optarg; 106 extern char *optarg;
93 extern int optind, opterr; 107 extern int optind, opterr;
94 #endif /* LONG_OPTIONS */ 108 #endif /* LONG_OPTIONS */
95 109
96 #ifdef ETAGS_REGEXPS 110 #ifdef ETAGS_REGEXPS
97 # include "../src/regex.h" 111 # include <regex.h>
98 #endif /* ETAGS_REGEXPS */ 112 #endif /* ETAGS_REGEXPS */
99 113
100 /* Define CTAGS to make the program "ctags" compatible with the usual one. 114 /* Define CTAGS to make the program "ctags" compatible with the usual one.
101 Leave it undefined to make the program "etags", which makes emacs-style 115 Leave it undefined to make the program "etags", which makes emacs-style
102 tag tables and tags typedefs, #defines and struct/union/enum by default. */ 116 tag tables and tags typedefs, #defines and struct/union/enum by default. */
270 284
271 /* boolean "functions" (see init) */ 285 /* boolean "functions" (see init) */
272 bool _wht[CHARS], _nin[CHARS], _itk[CHARS], _btk[CHARS], _etk[CHARS]; 286 bool _wht[CHARS], _nin[CHARS], _itk[CHARS], _btk[CHARS], _etk[CHARS];
273 char 287 char
274 /* white chars */ 288 /* white chars */
275 *white = " \f\t\n\013", 289 *white = " \f\t\n\r",
276 /* not in a name */ 290 /* not in a name */
277 *nonam =" \f\t\n\013(=,[;", 291 *nonam =" \f\t\n\r(=,[;",
278 /* token ending chars */ 292 /* token ending chars */
279 *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?", 293 *endtk = " \t\n\r\"'#()[]{}=-+%*/&|^~!<>;,.:?",
280 /* token starting chars */ 294 /* token starting chars */
281 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@", 295 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@",
282 /* valid in-token chars */ 296 /* valid in-token chars */
283 *midtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789"; 297 *midtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789";
284 298
488 followed by the name of an interpreter. If no such sequence is found,\n\ 502 followed by the name of an interpreter. If no such sequence is found,\n\
489 Fortran is tried first; if no tags are found, C is tried next."); 503 Fortran is tried first; if no tags are found, C is tried next.");
490 } 504 }
491 505
492 #ifndef VERSION 506 #ifndef VERSION
493 # define VERSION "19" 507 # define VERSION "20"
494 #endif 508 #endif
495 void 509 void
496 print_version () 510 print_version ()
497 { 511 {
498 printf ("%s (GNU Emacs %s)\n", (CTAGS) ? "ctags" : "etags", VERSION); 512 printf ("%s (GNU Emacs %s)\n", (CTAGS) ? "ctags" : "etags", VERSION);
791 is small. */ 805 is small. */
792 argbuffer = xnew (argc, argument); 806 argbuffer = xnew (argc, argument);
793 807
794 #ifdef ETAGS_REGEXPS 808 #ifdef ETAGS_REGEXPS
795 /* Set syntax for regular expression routines. */ 809 /* Set syntax for regular expression routines. */
796 re_set_syntax (RE_SYNTAX_EMACS); 810 re_set_syntax (RE_SYNTAX_EMACS | RE_INTERVALS);
797 #endif /* ETAGS_REGEXPS */ 811 #endif /* ETAGS_REGEXPS */
798 812
799 /* 813 /*
800 * If etags, always find typedefs and structure tags. Why not? 814 * If etags, always find typedefs and structure tags. Why not?
801 * Also default is to find macro constants, enum constants and 815 * Also default is to find macro constants, enum constants and
1508 /* Output this entry */ 1522 /* Output this entry */
1509 1523
1510 if (!CTAGS) 1524 if (!CTAGS)
1511 { 1525 {
1512 if (node->name != NULL) 1526 if (node->name != NULL)
1513 fprintf (tagf, "%s\177%s\001%d,%d\n", 1527 fprintf (tagf, "%s\177%s\001%d,%ld\n",
1514 node->pat, node->name, node->lno, node->cno); 1528 node->pat, node->name, node->lno, node->cno);
1515 else 1529 else
1516 fprintf (tagf, "%s\177%d,%d\n", 1530 fprintf (tagf, "%s\177%d,%ld\n",
1517 node->pat, node->lno, node->cno); 1531 node->pat, node->lno, node->cno);
1518 } 1532 }
1519 else 1533 else
1520 { 1534 {
1521 if (node->name == NULL) 1535 if (node->name == NULL)
1629 import, C_JAVA, st_C_ignore 1643 import, C_JAVA, st_C_ignore
1630 package, C_JAVA, st_C_ignore 1644 package, C_JAVA, st_C_ignore
1631 friend, C_PLPL, st_C_ignore 1645 friend, C_PLPL, st_C_ignore
1632 extends, C_JAVA, st_C_javastruct 1646 extends, C_JAVA, st_C_javastruct
1633 implements, C_JAVA, st_C_javastruct 1647 implements, C_JAVA, st_C_javastruct
1648 interface, C_JAVA, st_C_struct
1634 class, C_PLPL, st_C_struct 1649 class, C_PLPL, st_C_struct
1635 namespace, C_PLPL, st_C_struct 1650 namespace, C_PLPL, st_C_struct
1636 domain, C_STAR, st_C_struct 1651 domain, C_STAR, st_C_struct
1637 union, 0, st_C_struct 1652 union, 0, st_C_struct
1638 struct, 0, st_C_struct 1653 struct, 0, st_C_struct
1667 #EXFUN, 0, st_C_gnumacro 1682 #EXFUN, 0, st_C_gnumacro
1668 #DEFVAR_, 0, st_C_gnumacro 1683 #DEFVAR_, 0, st_C_gnumacro
1669 %] 1684 %]
1670 and replace lines between %< and %> with its output. */ 1685 and replace lines between %< and %> with its output. */
1671 /*%<*/ 1686 /*%<*/
1672 /* starting time is 10:31:16 */ 1687 /* starting time is 10:15:51 */
1673 /* C code produced by gperf version 2.1 (K&R C version) */ 1688 /* C code produced by gperf version 2.1 (K&R C version) */
1674 /* Command-line: gperf -c -k 1,3 -o -p -r -t */ 1689 /* Command-line: gperf -c -k 1,3 -o -p -r -t */
1675 1690
1676 1691
1677 struct C_stab_entry { char *name; int c_ext; enum sym_type type; }; 1692 struct C_stab_entry { char *name; int c_ext; enum sym_type type; };
1678 1693
1679 #define MIN_WORD_LENGTH 3 1694 #define MIN_WORD_LENGTH 3
1680 #define MAX_WORD_LENGTH 15 1695 #define MAX_WORD_LENGTH 15
1681 #define MIN_HASH_VALUE 15 1696 #define MIN_HASH_VALUE 11
1682 #define MAX_HASH_VALUE 128 1697 #define MAX_HASH_VALUE 117
1683 /* 1698 /*
1684 39 keywords 1699 40 keywords
1685 114 is the maximum key range 1700 107 is the maximum key range
1686 */ 1701 */
1687 1702
1688 static int 1703 static int
1689 hash (str, len) 1704 hash (str, len)
1690 register char *str; 1705 register char *str;
1691 register unsigned int len; 1706 register unsigned int len;
1692 { 1707 {
1693 static unsigned char hash_table[] = 1708 static unsigned char hash_table[] =
1694 { 1709 {
1695 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1710 117, 117, 117, 117, 117, 117, 117, 117, 117, 117,
1696 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1711 117, 117, 117, 117, 117, 117, 117, 117, 117, 117,
1697 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1712 117, 117, 117, 117, 117, 117, 117, 117, 117, 117,
1698 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1713 117, 117, 117, 117, 117, 117, 117, 117, 117, 117,
1699 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1714 117, 117, 117, 117, 117, 117, 117, 117, 117, 117,
1700 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1715 117, 117, 117, 117, 117, 117, 117, 117, 117, 117,
1701 128, 128, 128, 128, 39, 128, 128, 128, 54, 48, 1716 117, 117, 117, 117, 1, 117, 117, 117, 2, 42,
1702 46, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1717 16, 117, 117, 117, 117, 117, 117, 117, 117, 117,
1703 28, 128, 128, 40, 32, 128, 128, 128, 128, 128, 1718 5, 117, 117, 21, 54, 117, 117, 117, 117, 117,
1704 128, 128, 128, 128, 128, 128, 128, 24, 30, 47, 1719 117, 117, 117, 117, 117, 117, 117, 24, 19, 43,
1705 62, 7, 60, 27, 128, 60, 128, 128, 59, 16, 1720 2, 35, 3, 10, 117, 26, 117, 117, 9, 20,
1706 31, 23, 45, 128, 4, 14, 2, 55, 5, 128, 1721 35, 9, 61, 117, 40, 52, 10, 57, 3, 117,
1707 128, 128, 128, 128, 128, 128, 128, 128, 1722 117, 117, 117, 117, 117, 117, 117, 117,
1708 }; 1723 };
1709 return len + hash_table[str[2]] + hash_table[str[0]]; 1724 return len + hash_table[str[2]] + hash_table[str[0]];
1710 } 1725 }
1711 1726
1712 struct C_stab_entry * 1727 struct C_stab_entry *
1716 { 1731 {
1717 1732
1718 static struct C_stab_entry wordlist[] = 1733 static struct C_stab_entry wordlist[] =
1719 { 1734 {
1720 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 1735 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1721 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 1736 {"",}, {"",},
1737 {"define", 0, st_C_define},
1738 {"",}, {"",}, {"",}, {"",}, {"",},
1739 {"float", 0, st_C_typespec},
1740 {"",}, {"",},
1741 {"volatile", 0, st_C_typespec},
1742 {"",}, {"",},
1743 {"DEFUN", 0, st_C_gnumacro},
1744 {"",}, {"",}, {"",}, {"",},
1745 {"domain", C_STAR, st_C_struct},
1746 {"",}, {"",}, {"",},
1747 {"bool", C_PLPL, st_C_typespec},
1748 {"void", 0, st_C_typespec},
1749 {"",},
1750 {"friend", C_PLPL, st_C_ignore},
1751 {"@implementation", 0, st_C_objimpl},
1752 {"mutable", C_PLPL, st_C_typespec},
1753 {"auto", 0, st_C_typespec},
1754 {"int", 0, st_C_typespec},
1755 {"@end", 0, st_C_objend},
1756 {"",}, {"",}, {"",}, {"",},
1757 {"interface", C_JAVA, st_C_struct},
1758 {"@interface", 0, st_C_objprot},
1759 {"",},
1760 {"long", 0, st_C_typespec},
1761 {"SYSCALL", 0, st_C_gnumacro},
1762 {"@protocol", 0, st_C_objprot},
1722 {"extern", 0, st_C_typespec}, 1763 {"extern", 0, st_C_typespec},
1723 {"extends", C_JAVA, st_C_javastruct}, 1764 {"extends", C_JAVA, st_C_javastruct},
1724 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 1765 {"PSEUDO", 0, st_C_gnumacro},
1725 {"struct", 0, st_C_struct},
1726 {"mutable", C_PLPL, st_C_typespec},
1727 {"",}, {"",}, {"",}, {"",},
1728 {"auto", 0, st_C_typespec},
1729 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 1766 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1730 {"",}, {"",}, 1767 {"",},
1768 {"namespace", C_PLPL, st_C_struct},
1769 {"double", 0, st_C_typespec},
1731 {"short", 0, st_C_typespec}, 1770 {"short", 0, st_C_typespec},
1732 {"",}, 1771 {"",},
1733 {"static", 0, st_C_typespec}, 1772 {"signed", 0, st_C_typespec},
1734 {"",}, {"",}, 1773 {"",}, {"",},
1735 {"signed", 0, st_C_typespec}, 1774 {"char", 0, st_C_typespec},
1736 {"",}, {"",}, {"",}, {"",}, 1775 {"class", C_PLPL, st_C_struct},
1737 {"@protocol", 0, st_C_objprot}, 1776 {"",}, {"",}, {"",}, {"",}, {"",},
1738 {"",},
1739 {"typedef", 0, st_C_typedef}, 1777 {"typedef", 0, st_C_typedef},
1740 {"typename", C_PLPL, st_C_typespec}, 1778 {"typename", C_PLPL, st_C_typespec},
1741 {"namespace", C_PLPL, st_C_struct}, 1779 {"",}, {"",},
1742 {"bool", C_PLPL, st_C_typespec}, 1780 {"static", 0, st_C_typespec},
1781 {"const", 0, st_C_typespec},
1782 {"",}, {"",}, {"",}, {"",},
1783 {"union", 0, st_C_struct},
1784 {"",}, {"",}, {"",}, {"",},
1785 {"import", C_JAVA, st_C_ignore},
1786 {"",}, {"",},
1787 {"enum", 0, st_C_enum},
1788 {"implements", C_JAVA, st_C_javastruct},
1789 {"struct", 0, st_C_struct},
1790 {"",}, {"",},
1791 {"ENTRY", 0, st_C_gnumacro},
1743 {"",}, {"",}, 1792 {"",}, {"",},
1744 {"explicit", C_PLPL, st_C_typespec}, 1793 {"explicit", C_PLPL, st_C_typespec},
1745 {"",}, {"",}, {"",}, {"",}, 1794 {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
1746 {"int", 0, st_C_typespec},
1747 {"enum", 0, st_C_enum},
1748 {"",}, {"",},
1749 {"void", 0, st_C_typespec},
1750 {"@implementation", 0, st_C_objimpl},
1751 {"",},
1752 {"volatile", 0, st_C_typespec},
1753 {"",},
1754 {"@end", 0, st_C_objend},
1755 {"char", 0, st_C_typespec},
1756 {"class", C_PLPL, st_C_struct},
1757 {"unsigned", 0, st_C_typespec},
1758 {"",}, {"",},
1759 {"@interface", 0, st_C_objprot},
1760 {"",},
1761 {"PSEUDO", 0, st_C_gnumacro},
1762 {"const", 0, st_C_typespec},
1763 {"domain", C_STAR, st_C_struct},
1764 {"ENTRY", 0, st_C_gnumacro},
1765 {"",},
1766 {"SYSCALL", 0, st_C_gnumacro},
1767 {"float", 0, st_C_typespec},
1768 {"",}, {"",}, {"",}, {"",}, {"",},
1769 {"long", 0, st_C_typespec},
1770 {"",}, {"",}, {"",}, {"",},
1771 {"package", C_JAVA, st_C_ignore}, 1795 {"package", C_JAVA, st_C_ignore},
1772 {"",}, {"",}, {"",}, {"",}, {"",}, 1796 {"",}, {"",}, {"",}, {"",}, {"",},
1773 {"DEFUN", 0, st_C_gnumacro}, 1797 {"unsigned", 0, st_C_typespec},
1774 {"",}, {"",}, {"",}, {"",}, {"",},
1775 {"import", C_JAVA, st_C_ignore},
1776 {"",}, {"",}, {"",},
1777 {"implements", C_JAVA, st_C_javastruct},
1778 {"",}, {"",}, {"",}, {"",},
1779 {"union", 0, st_C_struct},
1780 {"",}, {"",},
1781 {"double", 0, st_C_typespec},
1782 {"",}, {"",},
1783 {"friend", C_PLPL, st_C_ignore},
1784 {"",},
1785 {"define", 0, st_C_define},
1786 }; 1798 };
1787 1799
1788 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) 1800 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
1789 { 1801 {
1790 register int key = hash (str, len); 1802 register int key = hash (str, len);
1797 return &wordlist[key]; 1809 return &wordlist[key];
1798 } 1810 }
1799 } 1811 }
1800 return 0; 1812 return 0;
1801 } 1813 }
1802 /* ending time is 10:31:16 */ 1814 /* ending time is 10:15:52 */
1803 /*%>*/ 1815 /*%>*/
1804 1816
1805 enum sym_type 1817 enum sym_type
1806 C_symtype (str, len, c_ext) 1818 C_symtype (str, len, c_ext)
1807 char *str; 1819 char *str;
4278 patbuf->translate = NULL; 4290 patbuf->translate = NULL;
4279 patbuf->fastmap = NULL; 4291 patbuf->fastmap = NULL;
4280 patbuf->buffer = NULL; 4292 patbuf->buffer = NULL;
4281 patbuf->allocated = 0; 4293 patbuf->allocated = 0;
4282 4294
4283 re_syntax_options = RE_INTERVALS;
4284 err = re_compile_pattern (regexp_pattern, strlen (regexp_pattern), patbuf); 4295 err = re_compile_pattern (regexp_pattern, strlen (regexp_pattern), patbuf);
4285 if (err != NULL) 4296 if (err != NULL)
4286 { 4297 {
4287 error ("%s while compiling pattern", err); 4298 error ("%s while compiling pattern", err);
4288 return; 4299 return;
4591 } 4602 }
4592 4603
4593 void 4604 void
4594 suggest_asking_for_help () 4605 suggest_asking_for_help ()
4595 { 4606 {
4596 fprintf (stderr, "\tTry `%s --help' for a complete list of options.\n", 4607 fprintf (stderr, "\tTry `%s %s' for a complete list of options.\n",
4597 progname); 4608 progname,
4609 #ifdef LONG_OPTIONS
4610 "--help"
4611 #else
4612 "-h"
4613 #endif
4614 );
4598 exit (BAD); 4615 exit (BAD);
4599 } 4616 }
4600 4617
4601 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ 4618 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
4602 void 4619 void