Mercurial > emacs
comparison lib-src/etags.c @ 10754:cd1c0b5e8634
* etags.c (C_entries): Initialise the new members of TOKEN.
(C_entries): Do not allocate a new space for each token found by
consider_token. Let make_tag do that instead.
(make_tag): Since now TOKEN has memory of where it is taken from,
this new macro substitutes both make_tag_from_new_lb and
make_tag_from_oth_lb. All callers changed.
(TOKEN): Add linepos and buffer members.
(main): Initialise token_str.
(lang_extensions): Recognise .c++ and .h++ as C++ file suffixes.
(token_str): New global variable used by C_entries.
author | Francesco Potortì <pot@gnu.org> |
---|---|
date | Tue, 14 Feb 1995 17:31:55 +0000 |
parents | 8a73e71a55e3 |
children | 7aa80669e697 |
comparison
equal
deleted
inserted
replaced
10753:e0de204ec865 | 10754:cd1c0b5e8634 |
---|---|
28 * Regexp tags by Tom Tromey. | 28 * Regexp tags by Tom Tromey. |
29 #endif | 29 #endif |
30 * | 30 * |
31 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer. | 31 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer. |
32 */ | 32 */ |
33 | 33 char pot_etags_version[] = "@(#) pot revision number is 11.21"; |
34 | 34 |
35 char pot_etags_version[] = "@(#) pot revision number is 11.19"; | 35 |
36 #ifdef MSDOS | 36 #ifdef MSDOS |
37 #include <fcntl.h> | 37 #include <fcntl.h> |
38 #include <sys/param.h> | 38 #include <sys/param.h> |
39 #endif /* MSDOS */ | 39 #endif /* MSDOS */ |
40 | 40 |
216 long size; | 216 long size; |
217 char *buffer; | 217 char *buffer; |
218 }; | 218 }; |
219 | 219 |
220 struct linebuffer lb; /* the current line */ | 220 struct linebuffer lb; /* the current line */ |
221 struct linebuffer token_str; /* used by C_entries as temporary area */ | |
221 struct | 222 struct |
222 { | 223 { |
223 long linepos; | 224 long linepos; |
224 struct linebuffer lb; /* used by C_entries instead of lb */ | 225 struct linebuffer lb; /* used by C_entries instead of lb */ |
225 } lbs[2]; | 226 } lbs[2]; |
366 /* Note that ".c" and ".h" can be considered C++, if the --c++ | 367 /* Note that ".c" and ".h" can be considered C++, if the --c++ |
367 flag was given. That is why default_C_entries is called here. */ | 368 flag was given. That is why default_C_entries is called here. */ |
368 { "c", default_C_entries }, | 369 { "c", default_C_entries }, |
369 { "h", default_C_entries }, | 370 { "h", default_C_entries }, |
370 | 371 |
371 /* .C or .H or .cpp or .cxx or .hxx or .hh or .cc or .cpp: a C++ file */ | 372 /* .C or .H or .c++ or .cc or .cpp or .cxx or .h++ or .hh or .hxx: |
373 a C++ file */ | |
372 { "C", Cplusplus_entries }, | 374 { "C", Cplusplus_entries }, |
373 { "H", Cplusplus_entries }, | 375 { "H", Cplusplus_entries }, |
376 { "c++", Cplusplus_entries }, | |
374 { "cc", Cplusplus_entries }, | 377 { "cc", Cplusplus_entries }, |
375 { "cpp", Cplusplus_entries }, | 378 { "cpp", Cplusplus_entries }, |
376 { "cxx", Cplusplus_entries }, | 379 { "cxx", Cplusplus_entries }, |
380 { "h++", Cplusplus_entries }, | |
377 { "hh", Cplusplus_entries }, | 381 { "hh", Cplusplus_entries }, |
378 { "hxx", Cplusplus_entries }, | 382 { "hxx", Cplusplus_entries }, |
379 | 383 |
380 /* .y: a yacc file */ | 384 /* .y: a yacc file */ |
381 { "y", Yacc_entries }, | 385 { "y", Yacc_entries }, |
855 } | 859 } |
856 | 860 |
857 init (); /* set up boolean "functions" */ | 861 init (); /* set up boolean "functions" */ |
858 | 862 |
859 initbuffer (&lb); | 863 initbuffer (&lb); |
864 initbuffer (&token_str); | |
860 initbuffer (&lbs[0].lb); | 865 initbuffer (&lbs[0].lb); |
861 initbuffer (&lbs[1].lb); | 866 initbuffer (&lbs[1].lb); |
862 initbuffer (&filename_lb); | 867 initbuffer (&filename_lb); |
863 | 868 |
864 if (!CTAGS) | 869 if (!CTAGS) |
919 } | 924 } |
920 #endif | 925 #endif |
921 break; | 926 break; |
922 } | 927 } |
923 } | 928 } |
924 | |
925 if (!CTAGS) | 929 if (!CTAGS) |
926 { | 930 { |
927 while (nincluded_files-- > 0) | 931 while (nincluded_files-- > 0) |
928 fprintf (tagf, "\f\n%s,include\n", *included_files++); | 932 fprintf (tagf, "\f\n%s,include\n", *included_files++); |
929 | 933 |
1813 { | 1817 { |
1814 char *str; | 1818 char *str; |
1815 logical named; | 1819 logical named; |
1816 int linelen; | 1820 int linelen; |
1817 int lineno; | 1821 int lineno; |
1822 long linepos; | |
1823 char *buffer; | |
1818 } TOKEN; | 1824 } TOKEN; |
1819 | 1825 |
1820 #define current_lb_is_new (newndx == curndx) | 1826 #define current_lb_is_new (newndx == curndx) |
1821 #define switch_line_buffers() (curndx = 1 - curndx) | 1827 #define switch_line_buffers() (curndx = 1 - curndx) |
1822 | 1828 |
1846 token_saved = FALSE; \ | 1852 token_saved = FALSE; \ |
1847 } \ | 1853 } \ |
1848 definedef = dnone; \ | 1854 definedef = dnone; \ |
1849 } while (0) | 1855 } while (0) |
1850 | 1856 |
1851 #define make_tag_from_new_lb(isfun) pfnote (tok.str, isfun, tok.named, \ | 1857 #define make_tag(isfun) pfnote (savestr (token_str.buffer), isfun, \ |
1852 newlb.buffer, tok.linelen, tok.lineno, newlinepos) | 1858 tok.named, tok.buffer, tok.linelen, tok.lineno, tok.linepos) |
1853 #define make_tag_from_oth_lb(isfun) pfnote (tok.str, isfun, tok.named, \ | |
1854 othlb.buffer, tok.linelen, tok.lineno, othlinepos) | |
1855 | 1859 |
1856 void | 1860 void |
1857 C_entries (c_ext, inf) | 1861 C_entries (c_ext, inf) |
1858 int c_ext; /* extension of C */ | 1862 int c_ext; /* extension of C */ |
1859 FILE *inf; /* input file */ | 1863 FILE *inf; /* input file */ |
2051 if (structdef == sinbody | 2055 if (structdef == sinbody |
2052 && definedef == dnone | 2056 && definedef == dnone |
2053 && is_func) | 2057 && is_func) |
2054 /* function defined in C++ class body */ | 2058 /* function defined in C++ class body */ |
2055 { | 2059 { |
2056 char *cp = newlb.buffer + tokoff + toklen; | 2060 int strsize = strlen(structtag) + 2 + toklen + 1; |
2057 char c = *cp; | 2061 while (token_str.size < strsize) |
2058 *cp = '\0'; | 2062 { |
2059 tok.str = concat (structtag, "::", | 2063 token_str.size *= 2; |
2060 newlb.buffer + tokoff); | 2064 xrealloc (token_str.buffer, token_str.size); |
2061 *cp = c; | 2065 } |
2066 strcpy (token_str.buffer, structtag); | |
2067 strcat (token_str.buffer, "::"); | |
2068 strncat (token_str.buffer, | |
2069 newlb.buffer+tokoff, toklen); | |
2062 tok.named = TRUE; | 2070 tok.named = TRUE; |
2063 } | 2071 } |
2064 else | 2072 else |
2065 { | 2073 { |
2066 tok.str = savenstr (newlb.buffer+tokoff, toklen); | 2074 while (token_str.size < toklen + 1) |
2075 { | |
2076 token_str.size *= 2; | |
2077 xrealloc (token_str.buffer, token_str.size); | |
2078 } | |
2079 strncpy (token_str.buffer, | |
2080 newlb.buffer+tokoff, toklen); | |
2081 token_str.buffer[toklen] = '\0'; | |
2067 if (structdef == stagseen | 2082 if (structdef == stagseen |
2068 || typdef == tend | 2083 || typdef == tend |
2069 || (is_func | 2084 || (is_func |
2070 && definedef == dignorerest)) /* macro */ | 2085 && definedef == dignorerest)) /* macro */ |
2071 tok.named = TRUE; | 2086 tok.named = TRUE; |
2072 else | 2087 else |
2073 tok.named = FALSE; | 2088 tok.named = FALSE; |
2074 } | 2089 } |
2075 tok.lineno = lineno; | 2090 tok.lineno = lineno; |
2076 tok.linelen = tokoff + toklen + 1; | 2091 tok.linelen = tokoff + toklen + 1; |
2092 tok.buffer = newlb.buffer; | |
2093 tok.linepos = newlinepos; | |
2077 | 2094 |
2078 if (definedef == dnone | 2095 if (definedef == dnone |
2079 && (funcdef == ftagseen | 2096 && (funcdef == ftagseen |
2080 || structdef == stagseen | 2097 || structdef == stagseen |
2081 || typdef == tend)) | 2098 || typdef == tend)) |
2082 { | 2099 { |
2083 if (current_lb_is_new) | 2100 if (current_lb_is_new) |
2084 switch_line_buffers (); | 2101 switch_line_buffers (); |
2085 } | 2102 } |
2086 else | 2103 else |
2087 make_tag_from_new_lb (is_func); | 2104 make_tag (is_func); |
2088 } | 2105 } |
2089 midtoken = FALSE; | 2106 midtoken = FALSE; |
2090 } | 2107 } |
2091 } /* if (endtoken (c)) */ | 2108 } /* if (endtoken (c)) */ |
2092 else if (intoken (c)) | 2109 else if (intoken (c)) |
2104 { | 2121 { |
2105 case fstartlist: | 2122 case fstartlist: |
2106 funcdef = finlist; | 2123 funcdef = finlist; |
2107 continue; | 2124 continue; |
2108 case flistseen: | 2125 case flistseen: |
2109 make_tag_from_oth_lb (TRUE); | 2126 make_tag (TRUE); |
2110 funcdef = fignore; | 2127 funcdef = fignore; |
2111 break; | 2128 break; |
2112 case ftagseen: | 2129 case ftagseen: |
2113 funcdef = fnone; | 2130 funcdef = fnone; |
2114 break; | 2131 break; |
2144 switch (funcdef) | 2161 switch (funcdef) |
2145 { | 2162 { |
2146 case ftagseen: | 2163 case ftagseen: |
2147 if (yacc_rules) | 2164 if (yacc_rules) |
2148 { | 2165 { |
2149 make_tag_from_oth_lb (FALSE); | 2166 make_tag (FALSE); |
2150 funcdef = fignore; | 2167 funcdef = fignore; |
2151 } | 2168 } |
2152 break; | 2169 break; |
2153 case fstartlist: | 2170 case fstartlist: |
2154 funcdef = fnone; | 2171 funcdef = fnone; |
2160 break; | 2177 break; |
2161 if (cblev == 0) | 2178 if (cblev == 0) |
2162 switch (typdef) | 2179 switch (typdef) |
2163 { | 2180 { |
2164 case tend: | 2181 case tend: |
2165 make_tag_from_oth_lb (FALSE); | 2182 make_tag (FALSE); |
2166 /* FALLTHRU */ | 2183 /* FALLTHRU */ |
2167 default: | 2184 default: |
2168 typdef = tnone; | 2185 typdef = tnone; |
2169 } | 2186 } |
2170 if (funcdef != fignore) | 2187 if (funcdef != fignore) |
2184 if (definedef != dnone) | 2201 if (definedef != dnone) |
2185 break; | 2202 break; |
2186 if (cblev == 0 && typdef == tend) | 2203 if (cblev == 0 && typdef == tend) |
2187 { | 2204 { |
2188 typdef = tignore; | 2205 typdef = tignore; |
2189 make_tag_from_oth_lb (FALSE); | 2206 make_tag (FALSE); |
2190 break; | 2207 break; |
2191 } | 2208 } |
2192 if (funcdef != finlist && funcdef != fignore) | 2209 if (funcdef != finlist && funcdef != fignore) |
2193 funcdef = fnone; | 2210 funcdef = fnone; |
2194 if (structdef == stagseen) | 2211 if (structdef == stagseen) |
2208 This handles constructs like: | 2225 This handles constructs like: |
2209 typedef void OperatorFun (int fun); */ | 2226 typedef void OperatorFun (int fun); */ |
2210 if (*lp != '*') | 2227 if (*lp != '*') |
2211 { | 2228 { |
2212 typdef = tignore; | 2229 typdef = tignore; |
2213 make_tag_from_oth_lb (FALSE); | 2230 make_tag (FALSE); |
2214 } | 2231 } |
2215 break; | 2232 break; |
2216 } /* switch (typdef) */ | 2233 } /* switch (typdef) */ |
2217 break; | 2234 break; |
2218 case ftagseen: | 2235 case ftagseen: |
2237 break; | 2254 break; |
2238 } | 2255 } |
2239 if (cblev == 0 && typdef == tend) | 2256 if (cblev == 0 && typdef == tend) |
2240 { | 2257 { |
2241 typdef = tignore; | 2258 typdef = tignore; |
2242 make_tag_from_oth_lb (FALSE); | 2259 make_tag (FALSE); |
2243 } | 2260 } |
2244 } | 2261 } |
2245 else if (parlev < 0) /* can happen due to ill-conceived #if's. */ | 2262 else if (parlev < 0) /* can happen due to ill-conceived #if's. */ |
2246 parlev = 0; | 2263 parlev = 0; |
2247 break; | 2264 break; |
2257 structdef = sinbody; | 2274 structdef = sinbody; |
2258 break; | 2275 break; |
2259 case stagseen: | 2276 case stagseen: |
2260 case scolonseen: /* named struct */ | 2277 case scolonseen: /* named struct */ |
2261 structdef = sinbody; | 2278 structdef = sinbody; |
2262 make_tag_from_oth_lb (FALSE); | 2279 make_tag (FALSE); |
2263 break; | 2280 break; |
2264 } | 2281 } |
2265 switch (funcdef) | 2282 switch (funcdef) |
2266 { | 2283 { |
2267 case flistseen: | 2284 case flistseen: |
2268 make_tag_from_oth_lb (TRUE); | 2285 make_tag (TRUE); |
2269 /* FALLTHRU */ | 2286 /* FALLTHRU */ |
2270 case fignore: | 2287 case fignore: |
2271 funcdef = fnone; | 2288 funcdef = fnone; |
2272 break; | 2289 break; |
2273 case fnone: | 2290 case fnone: |