comparison lib-src/etags.c @ 109111:52b76722152a

Convert function definitions to standard C. * lib-src/update-game-score.c: Convert function definitions to standard C. * lib-src/sorted-doc.c: * lib-src/profile.c: * lib-src/pop.c: * lib-src/movemail.c: * lib-src/make-docfile.c: * lib-src/hexl.c: * lib-src/fakemail.c: * lib-src/etags.c: * lib-src/ebrowse.c: * lib-src/digest-doc.c: * lib-src/b2m.c: Likewise.
author Dan Nicolaescu <dann@ics.uci.edu>
date Fri, 02 Jul 2010 17:50:23 -0700
parents 1dc371b29285
children 09a43f890565
comparison
equal deleted inserted replaced
109110:25749a68f5ae 109111:52b76722152a
846 { NULL } /* end of list */ 846 { NULL } /* end of list */
847 }; 847 };
848 848
849 849
850 static void 850 static void
851 print_language_names () 851 print_language_names (void)
852 { 852 {
853 language *lang; 853 language *lang;
854 char **name, **ext; 854 char **name, **ext;
855 855
856 puts ("\nThese are the currently supported languages, along with the\n\ 856 puts ("\nThese are the currently supported languages, along with the\n\
885 #endif 885 #endif
886 #ifndef VERSION 886 #ifndef VERSION
887 # define VERSION "17.38.1.4" 887 # define VERSION "17.38.1.4"
888 #endif 888 #endif
889 static void 889 static void
890 print_version () 890 print_version (void)
891 { 891 {
892 /* Makes it easier to update automatically. */ 892 /* Makes it easier to update automatically. */
893 char emacs_copyright[] = "Copyright (C) 2010 Free Software Foundation, Inc."; 893 char emacs_copyright[] = "Copyright (C) 2010 Free Software Foundation, Inc.";
894 894
895 printf ("%s (%s %s)\n", (CTAGS) ? "ctags" : "etags", EMACS_NAME, VERSION); 895 printf ("%s (%s %s)\n", (CTAGS) ? "ctags" : "etags", EMACS_NAME, VERSION);
902 #ifndef PRINT_UNDOCUMENTED_OPTIONS_HELP 902 #ifndef PRINT_UNDOCUMENTED_OPTIONS_HELP
903 # define PRINT_UNDOCUMENTED_OPTIONS_HELP FALSE 903 # define PRINT_UNDOCUMENTED_OPTIONS_HELP FALSE
904 #endif 904 #endif
905 905
906 static void 906 static void
907 print_help (argbuffer) 907 print_help (argument *argbuffer)
908 argument *argbuffer;
909 { 908 {
910 bool help_for_lang = FALSE; 909 bool help_for_lang = FALSE;
911 910
912 for (; argbuffer->arg_type != at_end; argbuffer++) 911 for (; argbuffer->arg_type != at_end; argbuffer++)
913 if (argbuffer->arg_type == at_language) 912 if (argbuffer->arg_type == at_language)
1080 exit (EXIT_SUCCESS); 1079 exit (EXIT_SUCCESS);
1081 } 1080 }
1082 1081
1083 1082
1084 int 1083 int
1085 main (argc, argv) 1084 main (int argc, char **argv)
1086 int argc;
1087 char *argv[];
1088 { 1085 {
1089 int i; 1086 int i;
1090 unsigned int nincluded_files; 1087 unsigned int nincluded_files;
1091 char **included_files; 1088 char **included_files;
1092 argument *argbuffer; 1089 argument *argbuffer;
1407 * extension begins. If no compressor is found, NULL is returned 1404 * extension begins. If no compressor is found, NULL is returned
1408 * and EXTPTR is not significant. 1405 * and EXTPTR is not significant.
1409 * Idea by Vladimir Alexiev <vladimir@cs.ualberta.ca> (1998) 1406 * Idea by Vladimir Alexiev <vladimir@cs.ualberta.ca> (1998)
1410 */ 1407 */
1411 static compressor * 1408 static compressor *
1412 get_compressor_from_suffix (file, extptr) 1409 get_compressor_from_suffix (char *file, char **extptr)
1413 char *file;
1414 char **extptr;
1415 { 1410 {
1416 compressor *compr; 1411 compressor *compr;
1417 char *slash, *suffix; 1412 char *slash, *suffix;
1418 1413
1419 /* File has been processed by canonicalize_filename, 1414 /* File has been processed by canonicalize_filename,
1445 1440
1446 /* 1441 /*
1447 * Return a language given the name. 1442 * Return a language given the name.
1448 */ 1443 */
1449 static language * 1444 static language *
1450 get_language_from_langname (name) 1445 get_language_from_langname (const char *name)
1451 const char *name;
1452 { 1446 {
1453 language *lang; 1447 language *lang;
1454 1448
1455 if (name == NULL) 1449 if (name == NULL)
1456 error ("empty language name", (char *)NULL); 1450 error ("empty language name", (char *)NULL);
1468 1462
1469 /* 1463 /*
1470 * Return a language given the interpreter name. 1464 * Return a language given the interpreter name.
1471 */ 1465 */
1472 static language * 1466 static language *
1473 get_language_from_interpreter (interpreter) 1467 get_language_from_interpreter (char *interpreter)
1474 char *interpreter;
1475 { 1468 {
1476 language *lang; 1469 language *lang;
1477 char **iname; 1470 char **iname;
1478 1471
1479 if (interpreter == NULL) 1472 if (interpreter == NULL)
1491 1484
1492 /* 1485 /*
1493 * Return a language given the file name. 1486 * Return a language given the file name.
1494 */ 1487 */
1495 static language * 1488 static language *
1496 get_language_from_filename (file, case_sensitive) 1489 get_language_from_filename (char *file, int case_sensitive)
1497 char *file;
1498 bool case_sensitive;
1499 { 1490 {
1500 language *lang; 1491 language *lang;
1501 char **name, **ext, *suffix; 1492 char **name, **ext, *suffix;
1502 1493
1503 /* Try whole file name first. */ 1494 /* Try whole file name first. */
1527 1518
1528 /* 1519 /*
1529 * This routine is called on each file argument. 1520 * This routine is called on each file argument.
1530 */ 1521 */
1531 static void 1522 static void
1532 process_file_name (file, lang) 1523 process_file_name (char *file, language *lang)
1533 char *file;
1534 language *lang;
1535 { 1524 {
1536 struct stat stat_buf; 1525 struct stat stat_buf;
1537 FILE *inf; 1526 FILE *inf;
1538 fdesc *fdp; 1527 fdesc *fdp;
1539 compressor *compr; 1528 compressor *compr;
1651 curfdp = NULL; 1640 curfdp = NULL;
1652 return; 1641 return;
1653 } 1642 }
1654 1643
1655 static void 1644 static void
1656 process_file (fh, fn, lang) 1645 process_file (FILE *fh, char *fn, language *lang)
1657 FILE *fh;
1658 char *fn;
1659 language *lang;
1660 { 1646 {
1661 static const fdesc emptyfdesc; 1647 static const fdesc emptyfdesc;
1662 fdesc *fdp; 1648 fdesc *fdp;
1663 1649
1664 /* Create a new input file description entry. */ 1650 /* Create a new input file description entry. */
1731 * all of the array "_wht" is set to FALSE, and then the elements 1717 * all of the array "_wht" is set to FALSE, and then the elements
1732 * subscripted by the chars in "white" are set to TRUE. Thus "_wht" 1718 * subscripted by the chars in "white" are set to TRUE. Thus "_wht"
1733 * of a char is TRUE if it is the string "white", else FALSE. 1719 * of a char is TRUE if it is the string "white", else FALSE.
1734 */ 1720 */
1735 static void 1721 static void
1736 init () 1722 init (void)
1737 { 1723 {
1738 register char *sp; 1724 register char *sp;
1739 register int i; 1725 register int i;
1740 1726
1741 for (i = 0; i < CHARS; i++) 1727 for (i = 0; i < CHARS; i++)
1754 /* 1740 /*
1755 * This routine opens the specified file and calls the function 1741 * This routine opens the specified file and calls the function
1756 * which finds the function and type definitions. 1742 * which finds the function and type definitions.
1757 */ 1743 */
1758 static void 1744 static void
1759 find_entries (inf) 1745 find_entries (FILE *inf)
1760 FILE *inf;
1761 { 1746 {
1762 char *cp; 1747 char *cp;
1763 language *lang = curfdp->lang; 1748 language *lang = curfdp->lang;
1764 Lang_function *parser = NULL; 1749 Lang_function *parser = NULL;
1765 1750
1913 * The implementation uses the notinname() macro, which recognises the 1898 * The implementation uses the notinname() macro, which recognises the
1914 * characters stored in the string `nonam'. 1899 * characters stored in the string `nonam'.
1915 * etags.el needs to use the same characters that are in NONAM. 1900 * etags.el needs to use the same characters that are in NONAM.
1916 */ 1901 */
1917 static void 1902 static void
1918 make_tag (name, namelen, is_func, linestart, linelen, lno, cno) 1903 make_tag (char *name, int namelen, int is_func, char *linestart, int linelen, int lno, long int cno)
1919 char *name; /* tag name, or NULL if unnamed */ 1904 /* tag name, or NULL if unnamed */
1920 int namelen; /* tag length */ 1905 /* tag length */
1921 bool is_func; /* tag is a function */ 1906 /* tag is a function */
1922 char *linestart; /* start of the line where tag is */ 1907 /* start of the line where tag is */
1923 int linelen; /* length of the line where tag is */ 1908 /* length of the line where tag is */
1924 int lno; /* line number */ 1909 /* line number */
1925 long cno; /* character number */ 1910 /* character number */
1926 { 1911 {
1927 bool named = (name != NULL && namelen > 0); 1912 bool named = (name != NULL && namelen > 0);
1928 1913
1929 if (!CTAGS && named) /* maybe set named to false */ 1914 if (!CTAGS && named) /* maybe set named to false */
1930 /* Let's try to make an implicit tag name, that is, create an unnamed tag 1915 /* Let's try to make an implicit tag name, that is, create an unnamed tag
1956 pfnote (name, is_func, linestart, linelen, lno, cno); 1941 pfnote (name, is_func, linestart, linelen, lno, cno);
1957 } 1942 }
1958 1943
1959 /* Record a tag. */ 1944 /* Record a tag. */
1960 static void 1945 static void
1961 pfnote (name, is_func, linestart, linelen, lno, cno) 1946 pfnote (char *name, int is_func, char *linestart, int linelen, int lno, long int cno)
1962 char *name; /* tag name, or NULL if unnamed */ 1947 /* tag name, or NULL if unnamed */
1963 bool is_func; /* tag is a function */ 1948 /* tag is a function */
1964 char *linestart; /* start of the line where tag is */ 1949 /* start of the line where tag is */
1965 int linelen; /* length of the line where tag is */ 1950 /* length of the line where tag is */
1966 int lno; /* line number */ 1951 /* line number */
1967 long cno; /* character number */ 1952 /* character number */
1968 { 1953 {
1969 register node *np; 1954 register node *np;
1970 1955
1971 assert (name == NULL || name[0] != '\0'); 1956 assert (name == NULL || name[0] != '\0');
1972 if (CTAGS && name == NULL) 1957 if (CTAGS && name == NULL)
2016 /* 2001 /*
2017 * free_tree () 2002 * free_tree ()
2018 * recurse on left children, iterate on right children. 2003 * recurse on left children, iterate on right children.
2019 */ 2004 */
2020 static void 2005 static void
2021 free_tree (np) 2006 free_tree (register node *np)
2022 register node *np;
2023 { 2007 {
2024 while (np) 2008 while (np)
2025 { 2009 {
2026 register node *node_right = np->right; 2010 register node *node_right = np->right;
2027 free_tree (np->left); 2011 free_tree (np->left);
2035 /* 2019 /*
2036 * free_fdesc () 2020 * free_fdesc ()
2037 * delete a file description 2021 * delete a file description
2038 */ 2022 */
2039 static void 2023 static void
2040 free_fdesc (fdp) 2024 free_fdesc (register fdesc *fdp)
2041 register fdesc *fdp;
2042 { 2025 {
2043 free (fdp->infname); 2026 free (fdp->infname);
2044 free (fdp->infabsname); 2027 free (fdp->infabsname);
2045 free (fdp->infabsdir); 2028 free (fdp->infabsdir);
2046 free (fdp->taggedfname); 2029 free (fdp->taggedfname);
2056 * 2039 *
2057 * add_node is the only function allowed to add nodes, so it can 2040 * add_node is the only function allowed to add nodes, so it can
2058 * maintain state. 2041 * maintain state.
2059 */ 2042 */
2060 static void 2043 static void
2061 add_node (np, cur_node_p) 2044 add_node (node *np, node **cur_node_p)
2062 node *np, **cur_node_p;
2063 { 2045 {
2064 register int dif; 2046 register int dif;
2065 register node *cur_node = *cur_node_p; 2047 register node *cur_node = *cur_node_p;
2066 2048
2067 if (cur_node == NULL) 2049 if (cur_node == NULL)
2137 * invalidate_nodes () 2119 * invalidate_nodes ()
2138 * Scan the node tree and invalidate all nodes pointing to the 2120 * Scan the node tree and invalidate all nodes pointing to the
2139 * given file description (CTAGS case) or free them (ETAGS case). 2121 * given file description (CTAGS case) or free them (ETAGS case).
2140 */ 2122 */
2141 static void 2123 static void
2142 invalidate_nodes (badfdp, npp) 2124 invalidate_nodes (fdesc *badfdp, node **npp)
2143 fdesc *badfdp;
2144 node **npp;
2145 { 2125 {
2146 node *np = *npp; 2126 node *np = *npp;
2147 2127
2148 if (np == NULL) 2128 if (np == NULL)
2149 return; 2129 return;
2176 static int total_size_of_entries (node *); 2156 static int total_size_of_entries (node *);
2177 static int number_len (long); 2157 static int number_len (long);
2178 2158
2179 /* Length of a non-negative number's decimal representation. */ 2159 /* Length of a non-negative number's decimal representation. */
2180 static int 2160 static int
2181 number_len (num) 2161 number_len (long int num)
2182 long num;
2183 { 2162 {
2184 int len = 1; 2163 int len = 1;
2185 while ((num /= 10) > 0) 2164 while ((num /= 10) > 0)
2186 len += 1; 2165 len += 1;
2187 return len; 2166 return len;
2192 * the nodes in the linked list at the right of the specified node. 2171 * the nodes in the linked list at the right of the specified node.
2193 * This count is irrelevant with etags.el since emacs 19.34 at least, 2172 * This count is irrelevant with etags.el since emacs 19.34 at least,
2194 * but is still supplied for backward compatibility. 2173 * but is still supplied for backward compatibility.
2195 */ 2174 */
2196 static int 2175 static int
2197 total_size_of_entries (np) 2176 total_size_of_entries (register node *np)
2198 register node *np;
2199 { 2177 {
2200 register int total = 0; 2178 register int total = 0;
2201 2179
2202 for (; np != NULL; np = np->right) 2180 for (; np != NULL; np = np->right)
2203 if (np->valid) 2181 if (np->valid)
2213 2191
2214 return total; 2192 return total;
2215 } 2193 }
2216 2194
2217 static void 2195 static void
2218 put_entries (np) 2196 put_entries (register node *np)
2219 register node *np;
2220 { 2197 {
2221 register char *sp; 2198 register char *sp;
2222 static fdesc *fdp = NULL; 2199 static fdesc *fdp = NULL;
2223 2200
2224 if (np == NULL) 2201 if (np == NULL)
2393 #ifdef __cplusplus 2370 #ifdef __cplusplus
2394 inline 2371 inline
2395 #endif 2372 #endif
2396 #endif 2373 #endif
2397 static unsigned int 2374 static unsigned int
2398 hash (str, len) 2375 hash (register const char *str, register unsigned int len)
2399 register const char *str;
2400 register unsigned int len;
2401 { 2376 {
2402 static unsigned char asso_values[] = 2377 static unsigned char asso_values[] =
2403 { 2378 {
2404 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 2379 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2405 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 2380 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2441 } 2416 }
2442 return hval; 2417 return hval;
2443 } 2418 }
2444 2419
2445 static struct C_stab_entry * 2420 static struct C_stab_entry *
2446 in_word_set (str, len) 2421 in_word_set (register const char *str, register unsigned int len)
2447 register const char *str;
2448 register unsigned int len;
2449 { 2422 {
2450 enum 2423 enum
2451 { 2424 {
2452 TOTAL_KEYWORDS = 33, 2425 TOTAL_KEYWORDS = 33,
2453 MIN_WORD_LENGTH = 2, 2426 MIN_WORD_LENGTH = 2,
2509 return 0; 2482 return 0;
2510 } 2483 }
2511 /*%>*/ 2484 /*%>*/
2512 2485
2513 static enum sym_type 2486 static enum sym_type
2514 C_symtype (str, len, c_ext) 2487 C_symtype (char *str, int len, int c_ext)
2515 char *str;
2516 int len;
2517 int c_ext;
2518 { 2488 {
2519 register struct C_stab_entry *se = in_word_set (str, len); 2489 register struct C_stab_entry *se = in_word_set (str, len);
2520 2490
2521 if (se == NULL || (se->c_ext && !(c_ext & se->c_ext))) 2491 if (se == NULL || (se->c_ext && !(c_ext & se->c_ext)))
2522 return st_none; 2492 return st_none;
2656 /* After struct keyword or in struct body, not inside a nested function. */ 2626 /* After struct keyword or in struct body, not inside a nested function. */
2657 #define instruct (structdef == snone && nestlev > 0 \ 2627 #define instruct (structdef == snone && nestlev > 0 \
2658 && bracelev == cstack.bracelev[nestlev-1] + 1) 2628 && bracelev == cstack.bracelev[nestlev-1] + 1)
2659 2629
2660 static void 2630 static void
2661 pushclass_above (bracelev, str, len) 2631 pushclass_above (int bracelev, char *str, int len)
2662 int bracelev;
2663 char *str;
2664 int len;
2665 { 2632 {
2666 int nl; 2633 int nl;
2667 2634
2668 popclass_above (bracelev); 2635 popclass_above (bracelev);
2669 nl = cstack.nl; 2636 nl = cstack.nl;
2678 cstack.bracelev[nl] = bracelev; 2645 cstack.bracelev[nl] = bracelev;
2679 cstack.nl = nl + 1; 2646 cstack.nl = nl + 1;
2680 } 2647 }
2681 2648
2682 static void 2649 static void
2683 popclass_above (bracelev) 2650 popclass_above (int bracelev)
2684 int bracelev;
2685 { 2651 {
2686 int nl; 2652 int nl;
2687 2653
2688 for (nl = cstack.nl - 1; 2654 for (nl = cstack.nl - 1;
2689 nl >= 0 && cstack.bracelev[nl] >= bracelev; 2655 nl >= 0 && cstack.bracelev[nl] >= bracelev;
2693 cstack.nl = nl; 2659 cstack.nl = nl;
2694 } 2660 }
2695 } 2661 }
2696 2662
2697 static void 2663 static void
2698 write_classname (cn, qualifier) 2664 write_classname (linebuffer *cn, char *qualifier)
2699 linebuffer *cn;
2700 char *qualifier;
2701 { 2665 {
2702 int i, len; 2666 int i, len;
2703 int qlen = strlen (qualifier); 2667 int qlen = strlen (qualifier);
2704 2668
2705 if (cstack.nl == 0 || cstack.cname[0] == NULL) 2669 if (cstack.nl == 0 || cstack.cname[0] == NULL)
2750 * typdef IN OUT 2714 * typdef IN OUT
2751 * objdef IN OUT 2715 * objdef IN OUT
2752 */ 2716 */
2753 2717
2754 static bool 2718 static bool
2755 consider_token (str, len, c, c_extp, bracelev, parlev, is_func_or_var) 2719 consider_token (register char *str, register int len, register int c, int *c_extp, int bracelev, int parlev, int *is_func_or_var)
2756 register char *str; /* IN: token pointer */ 2720 /* IN: token pointer */
2757 register int len; /* IN: token length */ 2721 /* IN: token length */
2758 register int c; /* IN: first char after the token */ 2722 /* IN: first char after the token */
2759 int *c_extp; /* IN, OUT: C extensions mask */ 2723 /* IN, OUT: C extensions mask */
2760 int bracelev; /* IN: brace level */ 2724 /* IN: brace level */
2761 int parlev; /* IN: parenthesis level */ 2725 /* IN: parenthesis level */
2762 bool *is_func_or_var; /* OUT: function or variable found */ 2726 /* OUT: function or variable found */
2763 { 2727 {
2764 /* When structdef is stagseen, scolonseen, or snone with bracelev > 0, 2728 /* When structdef is stagseen, scolonseen, or snone with bracelev > 0,
2765 structtype is the type of the preceding struct-like keyword, and 2729 structtype is the type of the preceding struct-like keyword, and
2766 structbracelev is the brace level where it has been seen. */ 2730 structbracelev is the brace level where it has been seen. */
2767 static enum sym_type structtype; 2731 static enum sym_type structtype;
3091 definedef = dnone; \ 3055 definedef = dnone; \
3092 } while (0) 3056 } while (0)
3093 3057
3094 3058
3095 static void 3059 static void
3096 make_C_tag (isfun) 3060 make_C_tag (int isfun)
3097 bool isfun;
3098 { 3061 {
3099 /* This function is never called when token.valid is FALSE, but 3062 /* This function is never called when token.valid is FALSE, but
3100 we must protect against invalid input or internal errors. */ 3063 we must protect against invalid input or internal errors. */
3101 if (token.valid) 3064 if (token.valid)
3102 make_tag (token_name.buffer, token_name.len, isfun, token.line, 3065 make_tag (token_name.buffer, token_name.len, isfun, token.line,
3118 * This routine finds functions, variables, typedefs, 3081 * This routine finds functions, variables, typedefs,
3119 * #define's, enum constants and struct/union/enum definitions in 3082 * #define's, enum constants and struct/union/enum definitions in
3120 * C syntax and adds them to the list. 3083 * C syntax and adds them to the list.
3121 */ 3084 */
3122 static void 3085 static void
3123 C_entries (c_ext, inf) 3086 C_entries (int c_ext, FILE *inf)
3124 int c_ext; /* extension of C */ 3087 /* extension of C */
3125 FILE *inf; /* input file */ 3088 /* input file */
3126 { 3089 {
3127 register char c; /* latest char read; '\0' for end of line */ 3090 register char c; /* latest char read; '\0' for end of line */
3128 register char *lp; /* pointer one beyond the character `c' */ 3091 register char *lp; /* pointer one beyond the character `c' */
3129 int curndx, newndx; /* indices for current and new lb */ 3092 int curndx, newndx; /* indices for current and new lb */
3130 register int tokoff; /* offset in line of start of current token */ 3093 register int tokoff; /* offset in line of start of current token */
3950 /* 3913 /*
3951 * Process either a C++ file or a C file depending on the setting 3914 * Process either a C++ file or a C file depending on the setting
3952 * of a global flag. 3915 * of a global flag.
3953 */ 3916 */
3954 static void 3917 static void
3955 default_C_entries (inf) 3918 default_C_entries (FILE *inf)
3956 FILE *inf;
3957 { 3919 {
3958 C_entries (cplusplus ? C_PLPL : C_AUTO, inf); 3920 C_entries (cplusplus ? C_PLPL : C_AUTO, inf);
3959 } 3921 }
3960 3922
3961 /* Always do plain C. */ 3923 /* Always do plain C. */
3962 static void 3924 static void
3963 plain_C_entries (inf) 3925 plain_C_entries (FILE *inf)
3964 FILE *inf;
3965 { 3926 {
3966 C_entries (0, inf); 3927 C_entries (0, inf);
3967 } 3928 }
3968 3929
3969 /* Always do C++. */ 3930 /* Always do C++. */
3970 static void 3931 static void
3971 Cplusplus_entries (inf) 3932 Cplusplus_entries (FILE *inf)
3972 FILE *inf;
3973 { 3933 {
3974 C_entries (C_PLPL, inf); 3934 C_entries (C_PLPL, inf);
3975 } 3935 }
3976 3936
3977 /* Always do Java. */ 3937 /* Always do Java. */
3978 static void 3938 static void
3979 Cjava_entries (inf) 3939 Cjava_entries (FILE *inf)
3980 FILE *inf;
3981 { 3940 {
3982 C_entries (C_JAVA, inf); 3941 C_entries (C_JAVA, inf);
3983 } 3942 }
3984 3943
3985 /* Always do C*. */ 3944 /* Always do C*. */
3986 static void 3945 static void
3987 Cstar_entries (inf) 3946 Cstar_entries (FILE *inf)
3988 FILE *inf;
3989 { 3947 {
3990 C_entries (C_STAR, inf); 3948 C_entries (C_STAR, inf);
3991 } 3949 }
3992 3950
3993 /* Always do Yacc. */ 3951 /* Always do Yacc. */
3994 static void 3952 static void
3995 Yacc_entries (inf) 3953 Yacc_entries (FILE *inf)
3996 FILE *inf;
3997 { 3954 {
3998 C_entries (YACC, inf); 3955 C_entries (YACC, inf);
3999 } 3956 }
4000 3957
4001 3958
4024 /* 3981 /*
4025 * Read a file, but do no processing. This is used to do regexp 3982 * Read a file, but do no processing. This is used to do regexp
4026 * matching on files that have no language defined. 3983 * matching on files that have no language defined.
4027 */ 3984 */
4028 static void 3985 static void
4029 just_read_file (inf) 3986 just_read_file (FILE *inf)
4030 FILE *inf;
4031 { 3987 {
4032 register char *dummy; 3988 register char *dummy;
4033 3989
4034 LOOP_ON_INPUT_LINES (inf, lb, dummy) 3990 LOOP_ON_INPUT_LINES (inf, lb, dummy)
4035 continue; 3991 continue;
4040 3996
4041 static void F_takeprec (void); 3997 static void F_takeprec (void);
4042 static void F_getit (FILE *); 3998 static void F_getit (FILE *);
4043 3999
4044 static void 4000 static void
4045 F_takeprec () 4001 F_takeprec (void)
4046 { 4002 {
4047 dbp = skip_spaces (dbp); 4003 dbp = skip_spaces (dbp);
4048 if (*dbp != '*') 4004 if (*dbp != '*')
4049 return; 4005 return;
4050 dbp++; 4006 dbp++;
4063 dbp++; 4019 dbp++;
4064 while (ISDIGIT (*dbp)); 4020 while (ISDIGIT (*dbp));
4065 } 4021 }
4066 4022
4067 static void 4023 static void
4068 F_getit (inf) 4024 F_getit (FILE *inf)
4069 FILE *inf;
4070 { 4025 {
4071 register char *cp; 4026 register char *cp;
4072 4027
4073 dbp = skip_spaces (dbp); 4028 dbp = skip_spaces (dbp);
4074 if (*dbp == '\0') 4029 if (*dbp == '\0')
4088 lb.buffer, cp - lb.buffer + 1, lineno, linecharno); 4043 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4089 } 4044 }
4090 4045
4091 4046
4092 static void 4047 static void
4093 Fortran_functions (inf) 4048 Fortran_functions (FILE *inf)
4094 FILE *inf;
4095 { 4049 {
4096 LOOP_ON_INPUT_LINES (inf, lb, dbp) 4050 LOOP_ON_INPUT_LINES (inf, lb, dbp)
4097 { 4051 {
4098 if (*dbp == '%') 4052 if (*dbp == '%')
4099 dbp++; /* Ratfor escape to fortran */ 4053 dbp++; /* Ratfor escape to fortran */
4176 static void Ada_getit (FILE *, char *); 4130 static void Ada_getit (FILE *, char *);
4177 4131
4178 /* Once we are positioned after an "interesting" keyword, let's get 4132 /* Once we are positioned after an "interesting" keyword, let's get
4179 the real tag value necessary. */ 4133 the real tag value necessary. */
4180 static void 4134 static void
4181 Ada_getit (inf, name_qualifier) 4135 Ada_getit (FILE *inf, char *name_qualifier)
4182 FILE *inf;
4183 char *name_qualifier;
4184 { 4136 {
4185 register char *cp; 4137 register char *cp;
4186 char *name; 4138 char *name;
4187 char c; 4139 char c;
4188 4140
4241 return; 4193 return;
4242 } 4194 }
4243 } 4195 }
4244 4196
4245 static void 4197 static void
4246 Ada_funcs (inf) 4198 Ada_funcs (FILE *inf)
4247 FILE *inf;
4248 { 4199 {
4249 bool inquote = FALSE; 4200 bool inquote = FALSE;
4250 bool skip_till_semicolumn = FALSE; 4201 bool skip_till_semicolumn = FALSE;
4251 4202
4252 LOOP_ON_INPUT_LINES (inf, lb, dbp) 4203 LOOP_ON_INPUT_LINES (inf, lb, dbp)
4355 * Unix and microcontroller assembly tag handling 4306 * Unix and microcontroller assembly tag handling
4356 * Labels: /^[a-zA-Z_.$][a-zA_Z0-9_.$]*[: ^I^J]/ 4307 * Labels: /^[a-zA-Z_.$][a-zA_Z0-9_.$]*[: ^I^J]/
4357 * Idea by Bob Weiner, Motorola Inc. (1994) 4308 * Idea by Bob Weiner, Motorola Inc. (1994)
4358 */ 4309 */
4359 static void 4310 static void
4360 Asm_labels (inf) 4311 Asm_labels (FILE *inf)
4361 FILE *inf;
4362 { 4312 {
4363 register char *cp; 4313 register char *cp;
4364 4314
4365 LOOP_ON_INPUT_LINES (inf, lb, cp) 4315 LOOP_ON_INPUT_LINES (inf, lb, cp)
4366 { 4316 {
4388 * Original code by Bart Robinson <lomew@cs.utah.edu> (1995) 4338 * Original code by Bart Robinson <lomew@cs.utah.edu> (1995)
4389 * Additions by Michael Ernst <mernst@alum.mit.edu> (1997) 4339 * Additions by Michael Ernst <mernst@alum.mit.edu> (1997)
4390 * Ideas by Kai Großjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> (2001) 4340 * Ideas by Kai Großjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> (2001)
4391 */ 4341 */
4392 static void 4342 static void
4393 Perl_functions (inf) 4343 Perl_functions (FILE *inf)
4394 FILE *inf;
4395 { 4344 {
4396 char *package = savestr ("main"); /* current package name */ 4345 char *package = savestr ("main"); /* current package name */
4397 register char *cp; 4346 register char *cp;
4398 4347
4399 LOOP_ON_INPUT_LINES (inf, lb, cp) 4348 LOOP_ON_INPUT_LINES (inf, lb, cp)
4471 * Look for /^[\t]*def[ \t\n]+[^ \t\n(:]+/ or /^class[ \t\n]+[^ \t\n(:]+/ 4420 * Look for /^[\t]*def[ \t\n]+[^ \t\n(:]+/ or /^class[ \t\n]+[^ \t\n(:]+/
4472 * Idea by Eric S. Raymond <esr@thyrsus.com> (1997) 4421 * Idea by Eric S. Raymond <esr@thyrsus.com> (1997)
4473 * More ideas by seb bacon <seb@jamkit.com> (2002) 4422 * More ideas by seb bacon <seb@jamkit.com> (2002)
4474 */ 4423 */
4475 static void 4424 static void
4476 Python_functions (inf) 4425 Python_functions (FILE *inf)
4477 FILE *inf;
4478 { 4426 {
4479 register char *cp; 4427 register char *cp;
4480 4428
4481 LOOP_ON_INPUT_LINES (inf, lb, cp) 4429 LOOP_ON_INPUT_LINES (inf, lb, cp)
4482 { 4430 {
4502 * Only with --members: 4450 * Only with --members:
4503 * - /^[ \t]*var[ \t\n]+\$[^ \t\n=;]/ 4451 * - /^[ \t]*var[ \t\n]+\$[^ \t\n=;]/
4504 * Idea by Diez B. Roggisch (2001) 4452 * Idea by Diez B. Roggisch (2001)
4505 */ 4453 */
4506 static void 4454 static void
4507 PHP_functions (inf) 4455 PHP_functions (FILE *inf)
4508 FILE *inf;
4509 { 4456 {
4510 register char *cp, *name; 4457 register char *cp, *name;
4511 bool search_identifier = FALSE; 4458 bool search_identifier = FALSE;
4512 4459
4513 LOOP_ON_INPUT_LINES (inf, lb, cp) 4460 LOOP_ON_INPUT_LINES (inf, lb, cp)
4582 * We could look for anything that could be a paragraph name. 4529 * We could look for anything that could be a paragraph name.
4583 * i.e. anything that starts in column 8 is one word and ends in a full stop. 4530 * i.e. anything that starts in column 8 is one word and ends in a full stop.
4584 * Idea by Corny de Souza (1993) 4531 * Idea by Corny de Souza (1993)
4585 */ 4532 */
4586 static void 4533 static void
4587 Cobol_paragraphs (inf) 4534 Cobol_paragraphs (FILE *inf)
4588 FILE *inf;
4589 { 4535 {
4590 register char *bp, *ep; 4536 register char *bp, *ep;
4591 4537
4592 LOOP_ON_INPUT_LINES (inf, lb, bp) 4538 LOOP_ON_INPUT_LINES (inf, lb, bp)
4593 { 4539 {
4611 /* 4557 /*
4612 * Makefile support 4558 * Makefile support
4613 * Ideas by Assar Westerlund <assar@sics.se> (2001) 4559 * Ideas by Assar Westerlund <assar@sics.se> (2001)
4614 */ 4560 */
4615 static void 4561 static void
4616 Makefile_targets (inf) 4562 Makefile_targets (FILE *inf)
4617 FILE *inf;
4618 { 4563 {
4619 register char *bp; 4564 register char *bp;
4620 4565
4621 LOOP_ON_INPUT_LINES (inf, lb, bp) 4566 LOOP_ON_INPUT_LINES (inf, lb, bp)
4622 { 4567 {
4647 * var-definitions. It does look for the keyword "extern" or 4592 * var-definitions. It does look for the keyword "extern" or
4648 * "forward" immediately following the procedure statement; if found, 4593 * "forward" immediately following the procedure statement; if found,
4649 * the tag is skipped. 4594 * the tag is skipped.
4650 */ 4595 */
4651 static void 4596 static void
4652 Pascal_functions (inf) 4597 Pascal_functions (FILE *inf)
4653 FILE *inf;
4654 { 4598 {
4655 linebuffer tline; /* mostly copied from C_entries */ 4599 linebuffer tline; /* mostly copied from C_entries */
4656 long save_lcno; 4600 long save_lcno;
4657 int save_lineno, namelen, taglen; 4601 int save_lineno, namelen, taglen;
4658 char c, *name; 4602 char c, *name;
4828 */ 4772 */
4829 4773
4830 static void L_getit (void); 4774 static void L_getit (void);
4831 4775
4832 static void 4776 static void
4833 L_getit () 4777 L_getit (void)
4834 { 4778 {
4835 if (*dbp == '\'') /* Skip prefix quote */ 4779 if (*dbp == '\'') /* Skip prefix quote */
4836 dbp++; 4780 dbp++;
4837 else if (*dbp == '(') 4781 else if (*dbp == '(')
4838 { 4782 {
4844 } 4788 }
4845 get_tag (dbp, NULL); 4789 get_tag (dbp, NULL);
4846 } 4790 }
4847 4791
4848 static void 4792 static void
4849 Lisp_functions (inf) 4793 Lisp_functions (FILE *inf)
4850 FILE *inf;
4851 { 4794 {
4852 LOOP_ON_INPUT_LINES (inf, lb, dbp) 4795 LOOP_ON_INPUT_LINES (inf, lb, dbp)
4853 { 4796 {
4854 if (dbp[0] != '(') 4797 if (dbp[0] != '(')
4855 continue; 4798 continue;
4889 * Original code by David A. Capello <dacap@users.sourceforge.net> (2004) 4832 * Original code by David A. Capello <dacap@users.sourceforge.net> (2004)
4890 * 4833 *
4891 * "function" and "local function" are tags if they start at column 1. 4834 * "function" and "local function" are tags if they start at column 1.
4892 */ 4835 */
4893 static void 4836 static void
4894 Lua_functions (inf) 4837 Lua_functions (FILE *inf)
4895 FILE *inf;
4896 { 4838 {
4897 register char *bp; 4839 register char *bp;
4898 4840
4899 LOOP_ON_INPUT_LINES (inf, lb, bp) 4841 LOOP_ON_INPUT_LINES (inf, lb, bp)
4900 { 4842 {
4916 * Ideas by: 4858 * Ideas by:
4917 * Richard Mlynarik <mly@adoc.xerox.com> (1997) 4859 * Richard Mlynarik <mly@adoc.xerox.com> (1997)
4918 * Masatake Yamato <masata-y@is.aist-nara.ac.jp> (1999) 4860 * Masatake Yamato <masata-y@is.aist-nara.ac.jp> (1999)
4919 */ 4861 */
4920 static void 4862 static void
4921 PS_functions (inf) 4863 PS_functions (FILE *inf)
4922 FILE *inf;
4923 { 4864 {
4924 register char *bp, *ep; 4865 register char *bp, *ep;
4925 4866
4926 LOOP_ON_INPUT_LINES (inf, lb, bp) 4867 LOOP_ON_INPUT_LINES (inf, lb, bp)
4927 { 4868 {
4947 * Look for constant, code, create, defer, value, and variable 4888 * Look for constant, code, create, defer, value, and variable
4948 * OBP extensions: Look for buffer:, field, 4889 * OBP extensions: Look for buffer:, field,
4949 * Ideas by Eduardo Horvath <eeh@netbsd.org> (2004) 4890 * Ideas by Eduardo Horvath <eeh@netbsd.org> (2004)
4950 */ 4891 */
4951 static void 4892 static void
4952 Forth_words (inf) 4893 Forth_words (FILE *inf)
4953 FILE *inf;
4954 { 4894 {
4955 register char *bp; 4895 register char *bp;
4956 4896
4957 LOOP_ON_INPUT_LINES (inf, lb, bp) 4897 LOOP_ON_INPUT_LINES (inf, lb, bp)
4958 while ((bp = skip_spaces (bp))[0] != '\0') 4898 while ((bp = skip_spaces (bp))[0] != '\0')
4984 * (def ... ((...(xyzzy .... 4924 * (def ... ((...(xyzzy ....
4985 * (set! xyzzy 4925 * (set! xyzzy
4986 * Original code by Ken Haase (1985?) 4926 * Original code by Ken Haase (1985?)
4987 */ 4927 */
4988 static void 4928 static void
4989 Scheme_functions (inf) 4929 Scheme_functions (FILE *inf)
4990 FILE *inf;
4991 { 4930 {
4992 register char *bp; 4931 register char *bp;
4993 4932
4994 LOOP_ON_INPUT_LINES (inf, lb, bp) 4933 LOOP_ON_INPUT_LINES (inf, lb, bp)
4995 { 4934 {
5036 4975
5037 /* 4976 /*
5038 * TeX/LaTeX scanning loop. 4977 * TeX/LaTeX scanning loop.
5039 */ 4978 */
5040 static void 4979 static void
5041 TeX_commands (inf) 4980 TeX_commands (FILE *inf)
5042 FILE *inf;
5043 { 4981 {
5044 char *cp; 4982 char *cp;
5045 linebuffer *key; 4983 linebuffer *key;
5046 4984
5047 /* Select either \ or ! as escape character. */ 4985 /* Select either \ or ! as escape character. */
5101 #define TEX_SESC '!' 5039 #define TEX_SESC '!'
5102 5040
5103 /* Figure out whether TeX's escapechar is '\\' or '!' and set grouping 5041 /* Figure out whether TeX's escapechar is '\\' or '!' and set grouping
5104 chars accordingly. */ 5042 chars accordingly. */
5105 static void 5043 static void
5106 TEX_mode (inf) 5044 TEX_mode (FILE *inf)
5107 FILE *inf;
5108 { 5045 {
5109 int c; 5046 int c;
5110 5047
5111 while ((c = getc (inf)) != EOF) 5048 while ((c = getc (inf)) != EOF)
5112 { 5049 {
5136 } 5073 }
5137 5074
5138 /* Read environment and prepend it to the default string. 5075 /* Read environment and prepend it to the default string.
5139 Build token table. */ 5076 Build token table. */
5140 static void 5077 static void
5141 TEX_decode_env (evarname, defenv) 5078 TEX_decode_env (char *evarname, char *defenv)
5142 char *evarname;
5143 char *defenv;
5144 { 5079 {
5145 register char *env, *p; 5080 register char *env, *p;
5146 int i, len; 5081 int i, len;
5147 5082
5148 /* Append default string to environment. */ 5083 /* Append default string to environment. */
5186 } 5121 }
5187 5122
5188 5123
5189 /* Texinfo support. Dave Love, Mar. 2000. */ 5124 /* Texinfo support. Dave Love, Mar. 2000. */
5190 static void 5125 static void
5191 Texinfo_nodes (inf) 5126 Texinfo_nodes (FILE *inf)
5192 FILE * inf;
5193 { 5127 {
5194 char *cp, *start; 5128 char *cp, *start;
5195 LOOP_ON_INPUT_LINES (inf, lb, cp) 5129 LOOP_ON_INPUT_LINES (inf, lb, cp)
5196 if (LOOKING_AT (cp, "@node")) 5130 if (LOOKING_AT (cp, "@node"))
5197 { 5131 {
5210 * Contents of <a name=xxx> are tags with name xxx. 5144 * Contents of <a name=xxx> are tags with name xxx.
5211 * 5145 *
5212 * Francesco Potortì, 2002. 5146 * Francesco Potortì, 2002.
5213 */ 5147 */
5214 static void 5148 static void
5215 HTML_labels (inf) 5149 HTML_labels (FILE *inf)
5216 FILE * inf;
5217 { 5150 {
5218 bool getnext = FALSE; /* next text outside of HTML tags is a tag */ 5151 bool getnext = FALSE; /* next text outside of HTML tags is a tag */
5219 bool skiptag = FALSE; /* skip to the end of the current HTML tag */ 5152 bool skiptag = FALSE; /* skip to the end of the current HTML tag */
5220 bool intag = FALSE; /* inside an html tag, looking for ID= */ 5153 bool intag = FALSE; /* inside an html tag, looking for ID= */
5221 bool inanchor = FALSE; /* when INTAG, is an anchor, look for NAME= */ 5154 bool inanchor = FALSE; /* when INTAG, is an anchor, look for NAME= */
5336 static int prolog_pr (char *, char *); 5269 static int prolog_pr (char *, char *);
5337 static void prolog_skip_comment (linebuffer *, FILE *); 5270 static void prolog_skip_comment (linebuffer *, FILE *);
5338 static int prolog_atom (char *, int); 5271 static int prolog_atom (char *, int);
5339 5272
5340 static void 5273 static void
5341 Prolog_functions (inf) 5274 Prolog_functions (FILE *inf)
5342 FILE *inf;
5343 { 5275 {
5344 char *cp, *last; 5276 char *cp, *last;
5345 int len; 5277 int len;
5346 int allocated; 5278 int allocated;
5347 5279
5373 free (last); 5305 free (last);
5374 } 5306 }
5375 5307
5376 5308
5377 static void 5309 static void
5378 prolog_skip_comment (plb, inf) 5310 prolog_skip_comment (linebuffer *plb, FILE *inf)
5379 linebuffer *plb;
5380 FILE *inf;
5381 { 5311 {
5382 char *cp; 5312 char *cp;
5383 5313
5384 do 5314 do
5385 { 5315 {
5401 * 5331 *
5402 * Return the size of the name of the predicate or rule, or 0 if no 5332 * Return the size of the name of the predicate or rule, or 0 if no
5403 * header was found. 5333 * header was found.
5404 */ 5334 */
5405 static int 5335 static int
5406 prolog_pr (s, last) 5336 prolog_pr (char *s, char *last)
5407 char *s; 5337
5408 char *last; /* Name of last clause. */ 5338 /* Name of last clause. */
5409 { 5339 {
5410 int pos; 5340 int pos;
5411 int len; 5341 int len;
5412 5342
5413 pos = prolog_atom (s, 0); 5343 pos = prolog_atom (s, 0);
5439 * - An alphanumeric sequence, starting with a lower case letter. 5369 * - An alphanumeric sequence, starting with a lower case letter.
5440 * - A quoted arbitrary string. Single quotes can escape themselves. 5370 * - A quoted arbitrary string. Single quotes can escape themselves.
5441 * Backslash quotes everything. 5371 * Backslash quotes everything.
5442 */ 5372 */
5443 static int 5373 static int
5444 prolog_atom (s, pos) 5374 prolog_atom (char *s, int pos)
5445 char *s;
5446 int pos;
5447 { 5375 {
5448 int origpos; 5376 int origpos;
5449 5377
5450 origpos = pos; 5378 origpos = pos;
5451 5379
5501 static int erlang_func (char *, char *); 5429 static int erlang_func (char *, char *);
5502 static void erlang_attribute (char *); 5430 static void erlang_attribute (char *);
5503 static int erlang_atom (char *); 5431 static int erlang_atom (char *);
5504 5432
5505 static void 5433 static void
5506 Erlang_functions (inf) 5434 Erlang_functions (FILE *inf)
5507 FILE *inf;
5508 { 5435 {
5509 char *cp, *last; 5436 char *cp, *last;
5510 int len; 5437 int len;
5511 int allocated; 5438 int allocated;
5512 5439
5561 * 5488 *
5562 * Return the size of the name of the function, or 0 if no function 5489 * Return the size of the name of the function, or 0 if no function
5563 * was found. 5490 * was found.
5564 */ 5491 */
5565 static int 5492 static int
5566 erlang_func (s, last) 5493 erlang_func (char *s, char *last)
5567 char *s; 5494
5568 char *last; /* Name of last clause. */ 5495 /* Name of last clause. */
5569 { 5496 {
5570 int pos; 5497 int pos;
5571 int len; 5498 int len;
5572 5499
5573 pos = erlang_atom (s); 5500 pos = erlang_atom (s);
5599 * -define(foo, bar). 5526 * -define(foo, bar).
5600 * -define(Foo(M, N), M+N). 5527 * -define(Foo(M, N), M+N).
5601 * -record(graph, {vtab = notable, cyclic = true}). 5528 * -record(graph, {vtab = notable, cyclic = true}).
5602 */ 5529 */
5603 static void 5530 static void
5604 erlang_attribute (s) 5531 erlang_attribute (char *s)
5605 char *s;
5606 { 5532 {
5607 char *cp = s; 5533 char *cp = s;
5608 5534
5609 if ((LOOKING_AT (cp, "-define") || LOOKING_AT (cp, "-record")) 5535 if ((LOOKING_AT (cp, "-define") || LOOKING_AT (cp, "-record"))
5610 && *cp++ == '(') 5536 && *cp++ == '(')
5620 /* 5546 /*
5621 * Consume an Erlang atom (or variable). 5547 * Consume an Erlang atom (or variable).
5622 * Return the number of bytes consumed, or -1 if there was an error. 5548 * Return the number of bytes consumed, or -1 if there was an error.
5623 */ 5549 */
5624 static int 5550 static int
5625 erlang_atom (s) 5551 erlang_atom (char *s)
5626 char *s;
5627 { 5552 {
5628 int pos = 0; 5553 int pos = 0;
5629 5554
5630 if (ISALPHA (s[pos]) || s[pos] == '_') 5555 if (ISALPHA (s[pos]) || s[pos] == '_')
5631 { 5556 {
5659 * appropriate characters. Works in place. Null terminates name string. 5584 * appropriate characters. Works in place. Null terminates name string.
5660 * Returns pointer to terminating separator, or NULL for 5585 * Returns pointer to terminating separator, or NULL for
5661 * unterminated regexps. 5586 * unterminated regexps.
5662 */ 5587 */
5663 static char * 5588 static char *
5664 scan_separators (name) 5589 scan_separators (char *name)
5665 char *name;
5666 { 5590 {
5667 char sep = name[0]; 5591 char sep = name[0];
5668 char *copyto = name; 5592 char *copyto = name;
5669 bool quoted = FALSE; 5593 bool quoted = FALSE;
5670 5594
5712 } 5636 }
5713 5637
5714 /* Look at the argument of --regex or --no-regex and do the right 5638 /* Look at the argument of --regex or --no-regex and do the right
5715 thing. Same for each line of a regexp file. */ 5639 thing. Same for each line of a regexp file. */
5716 static void 5640 static void
5717 analyse_regex (regex_arg) 5641 analyse_regex (char *regex_arg)
5718 char *regex_arg;
5719 { 5642 {
5720 if (regex_arg == NULL) 5643 if (regex_arg == NULL)
5721 { 5644 {
5722 free_regexps (); /* --no-regex: remove existing regexps */ 5645 free_regexps (); /* --no-regex: remove existing regexps */
5723 return; 5646 return;
5784 } 5707 }
5785 5708
5786 /* Separate the regexp pattern, compile it, 5709 /* Separate the regexp pattern, compile it,
5787 and care for optional name and modifiers. */ 5710 and care for optional name and modifiers. */
5788 static void 5711 static void
5789 add_regex (regexp_pattern, lang) 5712 add_regex (char *regexp_pattern, language *lang)
5790 char *regexp_pattern;
5791 language *lang;
5792 { 5713 {
5793 static struct re_pattern_buffer zeropattern; 5714 static struct re_pattern_buffer zeropattern;
5794 char sep, *pat, *name, *modifiers; 5715 char sep, *pat, *name, *modifiers;
5795 const char *err; 5716 const char *err;
5796 struct re_pattern_buffer *patbuf; 5717 struct re_pattern_buffer *patbuf;
5903 /* 5824 /*
5904 * Do the substitutions indicated by the regular expression and 5825 * Do the substitutions indicated by the regular expression and
5905 * arguments. 5826 * arguments.
5906 */ 5827 */
5907 static char * 5828 static char *
5908 substitute (in, out, regs) 5829 substitute (char *in, char *out, struct re_registers *regs)
5909 char *in, *out;
5910 struct re_registers *regs;
5911 { 5830 {
5912 char *result, *t; 5831 char *result, *t;
5913 int size, dig, diglen; 5832 int size, dig, diglen;
5914 5833
5915 result = NULL; 5834 result = NULL;
5952 return result; 5871 return result;
5953 } 5872 }
5954 5873
5955 /* Deallocate all regexps. */ 5874 /* Deallocate all regexps. */
5956 static void 5875 static void
5957 free_regexps () 5876 free_regexps (void)
5958 { 5877 {
5959 regexp *rp; 5878 regexp *rp;
5960 while (p_head != NULL) 5879 while (p_head != NULL)
5961 { 5880 {
5962 rp = p_head->p_next; 5881 rp = p_head->p_next;
5974 * readline already dealt with normal regexps. 5893 * readline already dealt with normal regexps.
5975 * 5894 *
5976 * Idea by Ben Wing <ben@666.com> (2002). 5895 * Idea by Ben Wing <ben@666.com> (2002).
5977 */ 5896 */
5978 static void 5897 static void
5979 regex_tag_multiline () 5898 regex_tag_multiline (void)
5980 { 5899 {
5981 char *buffer = filebuf.buffer; 5900 char *buffer = filebuf.buffer;
5982 regexp *rp; 5901 regexp *rp;
5983 char *name; 5902 char *name;
5984 5903
6051 } 5970 }
6052 } 5971 }
6053 5972
6054 5973
6055 static bool 5974 static bool
6056 nocase_tail (cp) 5975 nocase_tail (char *cp)
6057 char *cp;
6058 { 5976 {
6059 register int len = 0; 5977 register int len = 0;
6060 5978
6061 while (*cp != '\0' && lowcase (*cp) == lowcase (dbp[len])) 5979 while (*cp != '\0' && lowcase (*cp) == lowcase (dbp[len]))
6062 cp++, len++; 5980 cp++, len++;
6067 } 5985 }
6068 return FALSE; 5986 return FALSE;
6069 } 5987 }
6070 5988
6071 static void 5989 static void
6072 get_tag (bp, namepp) 5990 get_tag (register char *bp, char **namepp)
6073 register char *bp;
6074 char **namepp;
6075 { 5991 {
6076 register char *cp = bp; 5992 register char *cp = bp;
6077 5993
6078 if (*bp != '\0') 5994 if (*bp != '\0')
6079 { 5995 {
6100 * 6016 *
6101 * If multi-line regular expressions are requested, each line read is 6017 * If multi-line regular expressions are requested, each line read is
6102 * appended to `filebuf'. 6018 * appended to `filebuf'.
6103 */ 6019 */
6104 static long 6020 static long
6105 readline_internal (lbp, stream) 6021 readline_internal (linebuffer *lbp, register FILE *stream)
6106 linebuffer *lbp;
6107 register FILE *stream;
6108 { 6022 {
6109 char *buffer = lbp->buffer; 6023 char *buffer = lbp->buffer;
6110 register char *p = lbp->buffer; 6024 register char *p = lbp->buffer;
6111 register char *pend; 6025 register char *pend;
6112 int chars_deleted; 6026 int chars_deleted;
6180 * Like readline_internal, above, but in addition try to match the 6094 * Like readline_internal, above, but in addition try to match the
6181 * input line against relevant regular expressions and manage #line 6095 * input line against relevant regular expressions and manage #line
6182 * directives. 6096 * directives.
6183 */ 6097 */
6184 static void 6098 static void
6185 readline (lbp, stream) 6099 readline (linebuffer *lbp, FILE *stream)
6186 linebuffer *lbp;
6187 FILE *stream;
6188 { 6100 {
6189 long result; 6101 long result;
6190 6102
6191 linecharno = charno; /* update global char number of line start */ 6103 linecharno = charno; /* update global char number of line start */
6192 result = readline_internal (lbp, stream); /* read line */ 6104 result = readline_internal (lbp, stream); /* read line */
6375 /* 6287 /*
6376 * Return a pointer to a space of size strlen(cp)+1 allocated 6288 * Return a pointer to a space of size strlen(cp)+1 allocated
6377 * with xnew where the string CP has been copied. 6289 * with xnew where the string CP has been copied.
6378 */ 6290 */
6379 static char * 6291 static char *
6380 savestr (cp) 6292 savestr (char *cp)
6381 char *cp;
6382 { 6293 {
6383 return savenstr (cp, strlen (cp)); 6294 return savenstr (cp, strlen (cp));
6384 } 6295 }
6385 6296
6386 /* 6297 /*
6387 * Return a pointer to a space of size LEN+1 allocated with xnew where 6298 * Return a pointer to a space of size LEN+1 allocated with xnew where
6388 * the string CP has been copied for at most the first LEN characters. 6299 * the string CP has been copied for at most the first LEN characters.
6389 */ 6300 */
6390 static char * 6301 static char *
6391 savenstr (cp, len) 6302 savenstr (char *cp, int len)
6392 char *cp;
6393 int len;
6394 { 6303 {
6395 register char *dp; 6304 register char *dp;
6396 6305
6397 dp = xnew (len + 1, char); 6306 dp = xnew (len + 1, char);
6398 strncpy (dp, cp, len); 6307 strncpy (dp, cp, len);
6405 * appears; NULL if not found 6314 * appears; NULL if not found
6406 * 6315 *
6407 * Identical to POSIX strrchr, included for portability. 6316 * Identical to POSIX strrchr, included for portability.
6408 */ 6317 */
6409 static char * 6318 static char *
6410 etags_strrchr (sp, c) 6319 etags_strrchr (register const char *sp, register int c)
6411 register const char *sp;
6412 register int c;
6413 { 6320 {
6414 register const char *r; 6321 register const char *r;
6415 6322
6416 r = NULL; 6323 r = NULL;
6417 do 6324 do
6427 * appears; NULL if not found 6334 * appears; NULL if not found
6428 * 6335 *
6429 * Identical to POSIX strchr, included for portability. 6336 * Identical to POSIX strchr, included for portability.
6430 */ 6337 */
6431 static char * 6338 static char *
6432 etags_strchr (sp, c) 6339 etags_strchr (register const char *sp, register int c)
6433 register const char *sp;
6434 register int c;
6435 { 6340 {
6436 do 6341 do
6437 { 6342 {
6438 if (*sp == c) 6343 if (*sp == c)
6439 return (char *)sp; 6344 return (char *)sp;
6445 * Compare two strings, ignoring case for alphabetic characters. 6350 * Compare two strings, ignoring case for alphabetic characters.
6446 * 6351 *
6447 * Same as BSD's strcasecmp, included for portability. 6352 * Same as BSD's strcasecmp, included for portability.
6448 */ 6353 */
6449 static int 6354 static int
6450 etags_strcasecmp (s1, s2) 6355 etags_strcasecmp (register const char *s1, register const char *s2)
6451 register const char *s1;
6452 register const char *s2;
6453 { 6356 {
6454 while (*s1 != '\0' 6357 while (*s1 != '\0'
6455 && (ISALPHA (*s1) && ISALPHA (*s2) 6358 && (ISALPHA (*s1) && ISALPHA (*s2)
6456 ? lowcase (*s1) == lowcase (*s2) 6359 ? lowcase (*s1) == lowcase (*s2)
6457 : *s1 == *s2)) 6360 : *s1 == *s2))
6467 * Stop after a given number of characters 6370 * Stop after a given number of characters
6468 * 6371 *
6469 * Same as BSD's strncasecmp, included for portability. 6372 * Same as BSD's strncasecmp, included for portability.
6470 */ 6373 */
6471 static int 6374 static int
6472 etags_strncasecmp (s1, s2, n) 6375 etags_strncasecmp (register const char *s1, register const char *s2, register int n)
6473 register const char *s1;
6474 register const char *s2;
6475 register int n;
6476 { 6376 {
6477 while (*s1 != '\0' && n-- > 0 6377 while (*s1 != '\0' && n-- > 0
6478 && (ISALPHA (*s1) && ISALPHA (*s2) 6378 && (ISALPHA (*s1) && ISALPHA (*s2)
6479 ? lowcase (*s1) == lowcase (*s2) 6379 ? lowcase (*s1) == lowcase (*s2)
6480 : *s1 == *s2)) 6380 : *s1 == *s2))
6488 : *s1 - *s2); 6388 : *s1 - *s2);
6489 } 6389 }
6490 6390
6491 /* Skip spaces (end of string is not space), return new pointer. */ 6391 /* Skip spaces (end of string is not space), return new pointer. */
6492 static char * 6392 static char *
6493 skip_spaces (cp) 6393 skip_spaces (char *cp)
6494 char *cp;
6495 { 6394 {
6496 while (iswhite (*cp)) 6395 while (iswhite (*cp))
6497 cp++; 6396 cp++;
6498 return cp; 6397 return cp;
6499 } 6398 }
6500 6399
6501 /* Skip non spaces, except end of string, return new pointer. */ 6400 /* Skip non spaces, except end of string, return new pointer. */
6502 static char * 6401 static char *
6503 skip_non_spaces (cp) 6402 skip_non_spaces (char *cp)
6504 char *cp;
6505 { 6403 {
6506 while (*cp != '\0' && !iswhite (*cp)) 6404 while (*cp != '\0' && !iswhite (*cp))
6507 cp++; 6405 cp++;
6508 return cp; 6406 return cp;
6509 } 6407 }
6510 6408
6511 /* Print error message and exit. */ 6409 /* Print error message and exit. */
6512 void 6410 void
6513 fatal (s1, s2) 6411 fatal (char *s1, char *s2)
6514 char *s1, *s2;
6515 { 6412 {
6516 error (s1, s2); 6413 error (s1, s2);
6517 exit (EXIT_FAILURE); 6414 exit (EXIT_FAILURE);
6518 } 6415 }
6519 6416
6520 static void 6417 static void
6521 pfatal (s1) 6418 pfatal (char *s1)
6522 char *s1;
6523 { 6419 {
6524 perror (s1); 6420 perror (s1);
6525 exit (EXIT_FAILURE); 6421 exit (EXIT_FAILURE);
6526 } 6422 }
6527 6423
6528 static void 6424 static void
6529 suggest_asking_for_help () 6425 suggest_asking_for_help (void)
6530 { 6426 {
6531 fprintf (stderr, "\tTry `%s %s' for a complete list of options.\n", 6427 fprintf (stderr, "\tTry `%s %s' for a complete list of options.\n",
6532 progname, NO_LONG_OPTIONS ? "-h" : "--help"); 6428 progname, NO_LONG_OPTIONS ? "-h" : "--help");
6533 exit (EXIT_FAILURE); 6429 exit (EXIT_FAILURE);
6534 } 6430 }
6535 6431
6536 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ 6432 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
6537 static void 6433 static void
6538 error (s1, s2) 6434 error (const char *s1, const char *s2)
6539 const char *s1, *s2;
6540 { 6435 {
6541 fprintf (stderr, "%s: ", progname); 6436 fprintf (stderr, "%s: ", progname);
6542 fprintf (stderr, s1, s2); 6437 fprintf (stderr, s1, s2);
6543 fprintf (stderr, "\n"); 6438 fprintf (stderr, "\n");
6544 } 6439 }
6545 6440
6546 /* Return a newly-allocated string whose contents 6441 /* Return a newly-allocated string whose contents
6547 concatenate those of s1, s2, s3. */ 6442 concatenate those of s1, s2, s3. */
6548 static char * 6443 static char *
6549 concat (s1, s2, s3) 6444 concat (char *s1, char *s2, char *s3)
6550 char *s1, *s2, *s3;
6551 { 6445 {
6552 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); 6446 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
6553 char *result = xnew (len1 + len2 + len3 + 1, char); 6447 char *result = xnew (len1 + len2 + len3 + 1, char);
6554 6448
6555 strcpy (result, s1); 6449 strcpy (result, s1);
6562 6456
6563 6457
6564 /* Does the same work as the system V getcwd, but does not need to 6458 /* Does the same work as the system V getcwd, but does not need to
6565 guess the buffer size in advance. */ 6459 guess the buffer size in advance. */
6566 static char * 6460 static char *
6567 etags_getcwd () 6461 etags_getcwd (void)
6568 { 6462 {
6569 #ifdef HAVE_GETCWD 6463 #ifdef HAVE_GETCWD
6570 int bufsize = 200; 6464 int bufsize = 200;
6571 char *path = xnew (bufsize, char); 6465 char *path = xnew (bufsize, char);
6572 6466
6612 } 6506 }
6613 6507
6614 /* Return a newly allocated string containing the file name of FILE 6508 /* Return a newly allocated string containing the file name of FILE
6615 relative to the absolute directory DIR (which should end with a slash). */ 6509 relative to the absolute directory DIR (which should end with a slash). */
6616 static char * 6510 static char *
6617 relative_filename (file, dir) 6511 relative_filename (char *file, char *dir)
6618 char *file, *dir;
6619 { 6512 {
6620 char *fp, *dp, *afn, *res; 6513 char *fp, *dp, *afn, *res;
6621 int i; 6514 int i;
6622 6515
6623 /* Find the common root of file and dir (with a trailing slash). */ 6516 /* Find the common root of file and dir (with a trailing slash). */
6652 } 6545 }
6653 6546
6654 /* Return a newly allocated string containing the absolute file name 6547 /* Return a newly allocated string containing the absolute file name
6655 of FILE given DIR (which should end with a slash). */ 6548 of FILE given DIR (which should end with a slash). */
6656 static char * 6549 static char *
6657 absolute_filename (file, dir) 6550 absolute_filename (char *file, char *dir)
6658 char *file, *dir;
6659 { 6551 {
6660 char *slashp, *cp, *res; 6552 char *slashp, *cp, *res;
6661 6553
6662 if (filename_is_absolute (file)) 6554 if (filename_is_absolute (file))
6663 res = savestr (file); 6555 res = savestr (file);
6726 6618
6727 /* Return a newly allocated string containing the absolute 6619 /* Return a newly allocated string containing the absolute
6728 file name of dir where FILE resides given DIR (which should 6620 file name of dir where FILE resides given DIR (which should
6729 end with a slash). */ 6621 end with a slash). */
6730 static char * 6622 static char *
6731 absolute_dirname (file, dir) 6623 absolute_dirname (char *file, char *dir)
6732 char *file, *dir;
6733 { 6624 {
6734 char *slashp, *res; 6625 char *slashp, *res;
6735 char save; 6626 char save;
6736 6627
6737 slashp = etags_strrchr (file, '/'); 6628 slashp = etags_strrchr (file, '/');
6746 } 6637 }
6747 6638
6748 /* Whether the argument string is an absolute file name. The argument 6639 /* Whether the argument string is an absolute file name. The argument
6749 string must have been canonicalized with canonicalize_filename. */ 6640 string must have been canonicalized with canonicalize_filename. */
6750 static bool 6641 static bool
6751 filename_is_absolute (fn) 6642 filename_is_absolute (char *fn)
6752 char *fn;
6753 { 6643 {
6754 return (fn[0] == '/' 6644 return (fn[0] == '/'
6755 #ifdef DOS_NT 6645 #ifdef DOS_NT
6756 || (ISALPHA(fn[0]) && fn[1] == ':' && fn[2] == '/') 6646 || (ISALPHA(fn[0]) && fn[1] == ':' && fn[2] == '/')
6757 #endif 6647 #endif
6759 } 6649 }
6760 6650
6761 /* Upcase DOS drive letter and collapse separators into single slashes. 6651 /* Upcase DOS drive letter and collapse separators into single slashes.
6762 Works in place. */ 6652 Works in place. */
6763 static void 6653 static void
6764 canonicalize_filename (fn) 6654 canonicalize_filename (register char *fn)
6765 register char *fn;
6766 { 6655 {
6767 register char* cp; 6656 register char* cp;
6768 char sep = '/'; 6657 char sep = '/';
6769 6658
6770 #ifdef DOS_NT 6659 #ifdef DOS_NT
6789 } 6678 }
6790 6679
6791 6680
6792 /* Initialize a linebuffer for use. */ 6681 /* Initialize a linebuffer for use. */
6793 static void 6682 static void
6794 linebuffer_init (lbp) 6683 linebuffer_init (linebuffer *lbp)
6795 linebuffer *lbp;
6796 { 6684 {
6797 lbp->size = (DEBUG) ? 3 : 200; 6685 lbp->size = (DEBUG) ? 3 : 200;
6798 lbp->buffer = xnew (lbp->size, char); 6686 lbp->buffer = xnew (lbp->size, char);
6799 lbp->buffer[0] = '\0'; 6687 lbp->buffer[0] = '\0';
6800 lbp->len = 0; 6688 lbp->len = 0;
6801 } 6689 }
6802 6690
6803 /* Set the minimum size of a string contained in a linebuffer. */ 6691 /* Set the minimum size of a string contained in a linebuffer. */
6804 static void 6692 static void
6805 linebuffer_setlen (lbp, toksize) 6693 linebuffer_setlen (linebuffer *lbp, int toksize)
6806 linebuffer *lbp;
6807 int toksize;
6808 { 6694 {
6809 while (lbp->size <= toksize) 6695 while (lbp->size <= toksize)
6810 { 6696 {
6811 lbp->size *= 2; 6697 lbp->size *= 2;
6812 xrnew (lbp->buffer, lbp->size, char); 6698 xrnew (lbp->buffer, lbp->size, char);
6814 lbp->len = toksize; 6700 lbp->len = toksize;
6815 } 6701 }
6816 6702
6817 /* Like malloc but get fatal error if memory is exhausted. */ 6703 /* Like malloc but get fatal error if memory is exhausted. */
6818 static PTR 6704 static PTR
6819 xmalloc (size) 6705 xmalloc (unsigned int size)
6820 unsigned int size;
6821 { 6706 {
6822 PTR result = (PTR) malloc (size); 6707 PTR result = (PTR) malloc (size);
6823 if (result == NULL) 6708 if (result == NULL)
6824 fatal ("virtual memory exhausted", (char *)NULL); 6709 fatal ("virtual memory exhausted", (char *)NULL);
6825 return result; 6710 return result;
6826 } 6711 }
6827 6712
6828 static PTR 6713 static PTR
6829 xrealloc (ptr, size) 6714 xrealloc (char *ptr, unsigned int size)
6830 char *ptr;
6831 unsigned int size;
6832 { 6715 {
6833 PTR result = (PTR) realloc (ptr, size); 6716 PTR result = (PTR) realloc (ptr, size);
6834 if (result == NULL) 6717 if (result == NULL)
6835 fatal ("virtual memory exhausted", (char *)NULL); 6718 fatal ("virtual memory exhausted", (char *)NULL);
6836 return result; 6719 return result;