diff options
| author | Francesco Potortì | 2002-06-06 22:37:28 +0000 |
|---|---|---|
| committer | Francesco Potortì | 2002-06-06 22:37:28 +0000 |
| commit | e7d3b099a25e2a895b0b9ff3e1f7100082f170a6 (patch) | |
| tree | 634e5c8c49435bfa9b5acaafddc0165805fe38a8 /lib-src | |
| parent | f0da41a610b8bd175ff0bb3a3ebe746345c570d0 (diff) | |
| download | emacs-e7d3b099a25e2a895b0b9ff3e1f7100082f170a6.tar.gz emacs-e7d3b099a25e2a895b0b9ff3e1f7100082f170a6.zip | |
(scan_separators): Support all character escape
sequences supported by gcc.
(find_entries): rewind unconditionally.
(find_entries): Do not call language functions directly, now calls
itself.
(find_entries): Do general initialisations here.
(CNL_SAVE_DEFINEDEF, C_entries, LOOP_ON_INPUT_LINES, F_getit)
(Ada_getit, Pascal_functions, Pascal_functions)
(prolog_skip_comment): Do not do them here.
(readline_internal): Increment lineno here.
(readline): Conditionally undo readline_internal increment.
(readline): Do not return a value.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/etags.c | 111 |
1 files changed, 60 insertions, 51 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c index 8b5e85c1563..6b4b379f138 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c | |||
| @@ -34,7 +34,7 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |||
| 34 | * Francesco Potortì <pot@gnu.org> has maintained it since 1993. | 34 | * Francesco Potortì <pot@gnu.org> has maintained it since 1993. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | char pot_etags_version[] = "@(#) pot revision number is 16.4"; | 37 | char pot_etags_version[] = "@(#) pot revision number is 16.10"; |
| 38 | 38 | ||
| 39 | #define TRUE 1 | 39 | #define TRUE 1 |
| 40 | #define FALSE 0 | 40 | #define FALSE 0 |
| @@ -349,7 +349,7 @@ static compressor *get_compressor_from_suffix __P((char *, char **)); | |||
| 349 | static language *get_language_from_langname __P((const char *)); | 349 | static language *get_language_from_langname __P((const char *)); |
| 350 | static language *get_language_from_interpreter __P((char *)); | 350 | static language *get_language_from_interpreter __P((char *)); |
| 351 | static language *get_language_from_filename __P((char *, bool)); | 351 | static language *get_language_from_filename __P((char *, bool)); |
| 352 | static long readline __P((linebuffer *, FILE *)); | 352 | static void readline __P((linebuffer *, FILE *)); |
| 353 | static long readline_internal __P((linebuffer *, FILE *)); | 353 | static long readline_internal __P((linebuffer *, FILE *)); |
| 354 | static bool nocase_tail __P((char *)); | 354 | static bool nocase_tail __P((char *)); |
| 355 | static char *get_tag __P((char *)); | 355 | static char *get_tag __P((char *)); |
| @@ -711,9 +711,6 @@ linked with GNU getopt."); | |||
| 711 | Absolute names are stored in the output file as they are.\n\ | 711 | Absolute names are stored in the output file as they are.\n\ |
| 712 | Relative ones are stored relative to the output file's directory.\n"); | 712 | Relative ones are stored relative to the output file's directory.\n"); |
| 713 | 713 | ||
| 714 | puts ("--parse-stdin=NAME\n\ | ||
| 715 | Read from standard input and record tags as belonging to file NAME."); | ||
| 716 | |||
| 717 | if (!CTAGS) | 714 | if (!CTAGS) |
| 718 | puts ("-a, --append\n\ | 715 | puts ("-a, --append\n\ |
| 719 | Append tag entries to existing tags file."); | 716 | Append tag entries to existing tags file."); |
| @@ -784,13 +781,15 @@ Relative ones are stored relative to the output file's directory.\n"); | |||
| 784 | puts ("-R, --no-regex\n\ | 781 | puts ("-R, --no-regex\n\ |
| 785 | Don't create tags from regexps for the following files."); | 782 | Don't create tags from regexps for the following files."); |
| 786 | #endif /* ETAGS_REGEXPS */ | 783 | #endif /* ETAGS_REGEXPS */ |
| 787 | puts ("-o FILE, --output=FILE\n\ | ||
| 788 | Write the tags to FILE."); | ||
| 789 | puts ("-I, --ignore-indentation\n\ | 784 | puts ("-I, --ignore-indentation\n\ |
| 790 | Don't rely on indentation quite as much as normal. Currently,\n\ | 785 | Don't rely on indentation quite as much as normal. Currently,\n\ |
| 791 | this means not to assume that a closing brace in the first\n\ | 786 | this means not to assume that a closing brace in the first\n\ |
| 792 | column is the final brace of a function or structure\n\ | 787 | column is the final brace of a function or structure\n\ |
| 793 | definition in C and C++."); | 788 | definition in C and C++."); |
| 789 | puts ("-o FILE, --output=FILE\n\ | ||
| 790 | Write the tags to FILE."); | ||
| 791 | puts ("--parse-stdin=NAME\n\ | ||
| 792 | Read from standard input and record tags as belonging to file NAME."); | ||
| 794 | 793 | ||
| 795 | if (CTAGS) | 794 | if (CTAGS) |
| 796 | { | 795 | { |
| @@ -1049,6 +1048,8 @@ main (argc, argv) | |||
| 1049 | argbuffer[current_arg].what = optarg; | 1048 | argbuffer[current_arg].what = optarg; |
| 1050 | ++current_arg; | 1049 | ++current_arg; |
| 1051 | ++file_count; | 1050 | ++file_count; |
| 1051 | if (parsing_stdin) | ||
| 1052 | fatal ("cannot parse standard input more than once", (char *)NULL); | ||
| 1052 | parsing_stdin = TRUE; | 1053 | parsing_stdin = TRUE; |
| 1053 | break; | 1054 | break; |
| 1054 | 1055 | ||
| @@ -1702,7 +1703,6 @@ find_entries (inf) | |||
| 1702 | /* We rewind here, even if inf may be a pipe. We fail if the | 1703 | /* We rewind here, even if inf may be a pipe. We fail if the |
| 1703 | length of the first line is longer than the pipe block size, | 1704 | length of the first line is longer than the pipe block size, |
| 1704 | which is unlikely. */ | 1705 | which is unlikely. */ |
| 1705 | if (parser == NULL) | ||
| 1706 | rewind (inf); | 1706 | rewind (inf); |
| 1707 | 1707 | ||
| 1708 | /* Else try to guess the language given the case insensitive file name. */ | 1708 | /* Else try to guess the language given the case insensitive file name. */ |
| @@ -1750,6 +1750,11 @@ find_entries (inf) | |||
| 1750 | 1750 | ||
| 1751 | if (parser != NULL) | 1751 | if (parser != NULL) |
| 1752 | { | 1752 | { |
| 1753 | /* Generic initialisations before reading from file. */ | ||
| 1754 | lineno = 0; /* reset global line number */ | ||
| 1755 | charno = 0; /* reset global char number */ | ||
| 1756 | linecharno = 0; /* reset global char number of line start */ | ||
| 1757 | |||
| 1753 | parser (inf); | 1758 | parser (inf); |
| 1754 | return; | 1759 | return; |
| 1755 | } | 1760 | } |
| @@ -1757,7 +1762,7 @@ find_entries (inf) | |||
| 1757 | /* Else try Fortran. */ | 1762 | /* Else try Fortran. */ |
| 1758 | old_last_node = last_node; | 1763 | old_last_node = last_node; |
| 1759 | curfdp->lang = get_language_from_langname ("fortran"); | 1764 | curfdp->lang = get_language_from_langname ("fortran"); |
| 1760 | Fortran_functions (inf); | 1765 | find_entries (inf); |
| 1761 | 1766 | ||
| 1762 | if (old_last_node == last_node) | 1767 | if (old_last_node == last_node) |
| 1763 | /* No Fortran entries found. Try C. */ | 1768 | /* No Fortran entries found. Try C. */ |
| @@ -1766,7 +1771,7 @@ find_entries (inf) | |||
| 1766 | Only the file name will be recorded in the tags file. */ | 1771 | Only the file name will be recorded in the tags file. */ |
| 1767 | rewind (inf); | 1772 | rewind (inf); |
| 1768 | curfdp->lang = get_language_from_langname (cplusplus ? "c++" : "c"); | 1773 | curfdp->lang = get_language_from_langname (cplusplus ? "c++" : "c"); |
| 1769 | default_C_entries (inf); | 1774 | find_entries (inf); |
| 1770 | } | 1775 | } |
| 1771 | return; | 1776 | return; |
| 1772 | } | 1777 | } |
| @@ -2951,9 +2956,7 @@ static struct | |||
| 2951 | #define CNL_SAVE_DEFINEDEF() \ | 2956 | #define CNL_SAVE_DEFINEDEF() \ |
| 2952 | do { \ | 2957 | do { \ |
| 2953 | curlinepos = charno; \ | 2958 | curlinepos = charno; \ |
| 2954 | lineno++; \ | 2959 | readline (&curlb, inf); \ |
| 2955 | linecharno = charno; \ | ||
| 2956 | charno += readline (&curlb, inf); \ | ||
| 2957 | lp = curlb.buffer; \ | 2960 | lp = curlb.buffer; \ |
| 2958 | quotednl = FALSE; \ | 2961 | quotednl = FALSE; \ |
| 2959 | newndx = curndx; \ | 2962 | newndx = curndx; \ |
| @@ -3045,8 +3048,6 @@ C_entries (c_ext, inf) | |||
| 3045 | 3048 | ||
| 3046 | tokoff = toklen = typdefcblev = 0; /* keep compiler quiet */ | 3049 | tokoff = toklen = typdefcblev = 0; /* keep compiler quiet */ |
| 3047 | curndx = newndx = 0; | 3050 | curndx = newndx = 0; |
| 3048 | lineno = 0; | ||
| 3049 | charno = 0; | ||
| 3050 | lp = curlb.buffer; | 3051 | lp = curlb.buffer; |
| 3051 | *lp = 0; | 3052 | *lp = 0; |
| 3052 | 3053 | ||
| @@ -3828,12 +3829,10 @@ Yacc_entries (inf) | |||
| 3828 | 3829 | ||
| 3829 | /* Useful macros. */ | 3830 | /* Useful macros. */ |
| 3830 | #define LOOP_ON_INPUT_LINES(file_pointer, line_buffer, char_pointer) \ | 3831 | #define LOOP_ON_INPUT_LINES(file_pointer, line_buffer, char_pointer) \ |
| 3831 | for (lineno = charno = 0; /* loop initialization */ \ | 3832 | for (; /* loop initialization */ \ |
| 3832 | !feof (file_pointer) /* loop test */ \ | 3833 | !feof (file_pointer) /* loop test */ \ |
| 3833 | && (lineno++, /* instructions at start of loop */ \ | 3834 | && (char_pointer = lb.buffer, /* instructions at start of loop */ \ |
| 3834 | linecharno = charno, \ | 3835 | readline (&line_buffer, file_pointer), \ |
| 3835 | charno += readline (&line_buffer, file_pointer), \ | ||
| 3836 | char_pointer = lb.buffer, \ | ||
| 3837 | TRUE); \ | 3836 | TRUE); \ |
| 3838 | ) | 3837 | ) |
| 3839 | #define LOOKING_AT(cp, keyword) /* keyword is a constant string */ \ | 3838 | #define LOOKING_AT(cp, keyword) /* keyword is a constant string */ \ |
| @@ -3893,9 +3892,7 @@ F_getit (inf) | |||
| 3893 | dbp = skip_spaces (dbp); | 3892 | dbp = skip_spaces (dbp); |
| 3894 | if (*dbp == '\0') | 3893 | if (*dbp == '\0') |
| 3895 | { | 3894 | { |
| 3896 | lineno++; | 3895 | readline (&lb, inf); |
| 3897 | linecharno = charno; | ||
| 3898 | charno += readline (&lb, inf); | ||
| 3899 | dbp = lb.buffer; | 3896 | dbp = lb.buffer; |
| 3900 | if (dbp[5] != '&') | 3897 | if (dbp[5] != '&') |
| 3901 | return; | 3898 | return; |
| @@ -4010,9 +4007,7 @@ Ada_getit (inf, name_qualifier) | |||
| 4010 | if (*dbp == '\0' | 4007 | if (*dbp == '\0' |
| 4011 | || (dbp[0] == '-' && dbp[1] == '-')) | 4008 | || (dbp[0] == '-' && dbp[1] == '-')) |
| 4012 | { | 4009 | { |
| 4013 | lineno++; | 4010 | readline (&lb, inf); |
| 4014 | linecharno = charno; | ||
| 4015 | charno += readline (&lb, inf); | ||
| 4016 | dbp = lb.buffer; | 4011 | dbp = lb.buffer; |
| 4017 | } | 4012 | } |
| 4018 | switch (lowcase(*dbp)) | 4013 | switch (lowcase(*dbp)) |
| @@ -4456,8 +4451,6 @@ Pascal_functions (inf) | |||
| 4456 | 4451 | ||
| 4457 | save_lcno = save_lineno = save_len = 0; /* keep compiler quiet */ | 4452 | save_lcno = save_lineno = save_len = 0; /* keep compiler quiet */ |
| 4458 | namebuf = NULL; /* keep compiler quiet */ | 4453 | namebuf = NULL; /* keep compiler quiet */ |
| 4459 | lineno = 0; | ||
| 4460 | charno = 0; | ||
| 4461 | dbp = lb.buffer; | 4454 | dbp = lb.buffer; |
| 4462 | *dbp = '\0'; | 4455 | *dbp = '\0'; |
| 4463 | initbuffer (&tline); | 4456 | initbuffer (&tline); |
| @@ -4474,9 +4467,7 @@ Pascal_functions (inf) | |||
| 4474 | c = *dbp++; | 4467 | c = *dbp++; |
| 4475 | if (c == '\0') /* if end of line */ | 4468 | if (c == '\0') /* if end of line */ |
| 4476 | { | 4469 | { |
| 4477 | lineno++; | 4470 | readline (&lb, inf); |
| 4478 | linecharno = charno; | ||
| 4479 | charno += readline (&lb, inf); | ||
| 4480 | dbp = lb.buffer; | 4471 | dbp = lb.buffer; |
| 4481 | if (*dbp == '\0') | 4472 | if (*dbp == '\0') |
| 4482 | continue; | 4473 | continue; |
| @@ -4987,8 +4978,7 @@ prolog_skip_comment (plb, inf) | |||
| 4987 | for (cp = plb->buffer; *cp != '\0'; cp++) | 4978 | for (cp = plb->buffer; *cp != '\0'; cp++) |
| 4988 | if (cp[0] == '*' && cp[1] == '/') | 4979 | if (cp[0] == '*' && cp[1] == '/') |
| 4989 | return; | 4980 | return; |
| 4990 | lineno++; | 4981 | readline (plb, inf); |
| 4991 | linecharno += readline (plb, inf); | ||
| 4992 | } | 4982 | } |
| 4993 | while (!feof(inf)); | 4983 | while (!feof(inf)); |
| 4994 | } | 4984 | } |
| @@ -5280,7 +5270,8 @@ static char *substitute __P((char *, char *, struct re_registers *)); | |||
| 5280 | /* Take a string like "/blah/" and turn it into "blah", making sure | 5270 | /* Take a string like "/blah/" and turn it into "blah", making sure |
| 5281 | that the first and last characters are the same, and handling | 5271 | that the first and last characters are the same, and handling |
| 5282 | quoted separator characters. Actually, stops on the occurrence of | 5272 | quoted separator characters. Actually, stops on the occurrence of |
| 5283 | an unquoted separator. Also turns "\t" into a Tab character. | 5273 | an unquoted separator. Also turns "\t" into a Tab character, and |
| 5274 | similarly for all character escape sequences supported by Gcc. | ||
| 5284 | Returns pointer to terminating separator. Works in place. Null | 5275 | Returns pointer to terminating separator. Works in place. Null |
| 5285 | terminates name string. */ | 5276 | terminates name string. */ |
| 5286 | static char * | 5277 | static char * |
| @@ -5295,15 +5286,27 @@ scan_separators (name) | |||
| 5295 | { | 5286 | { |
| 5296 | if (quoted) | 5287 | if (quoted) |
| 5297 | { | 5288 | { |
| 5298 | if (*name == 't') | 5289 | switch (*name) |
| 5299 | *copyto++ = '\t'; | ||
| 5300 | else if (*name == sep) | ||
| 5301 | *copyto++ = sep; | ||
| 5302 | else | ||
| 5303 | { | 5290 | { |
| 5304 | /* Something else is quoted, so preserve the quote. */ | 5291 | case 'a': *copyto++ = '\007'; break; |
| 5305 | *copyto++ = '\\'; | 5292 | case 'b': *copyto++ = '\b'; break; |
| 5306 | *copyto++ = *name; | 5293 | case 'd': *copyto++ = 0177; break; |
| 5294 | case 'e': *copyto++ = 033; break; | ||
| 5295 | case 'f': *copyto++ = '\f'; break; | ||
| 5296 | case 'n': *copyto++ = '\n'; break; | ||
| 5297 | case 'r': *copyto++ = '\r'; break; | ||
| 5298 | case 't': *copyto++ = '\t'; break; | ||
| 5299 | case 'v': *copyto++ = '\v'; break; | ||
| 5300 | default: | ||
| 5301 | if (*name == sep) | ||
| 5302 | *copyto++ = sep; | ||
| 5303 | else | ||
| 5304 | { | ||
| 5305 | /* Something else is quoted, so preserve the quote. */ | ||
| 5306 | *copyto++ = '\\'; | ||
| 5307 | *copyto++ = *name; | ||
| 5308 | } | ||
| 5309 | break; | ||
| 5307 | } | 5310 | } |
| 5308 | quoted = FALSE; | 5311 | quoted = FALSE; |
| 5309 | } | 5312 | } |
| @@ -5630,13 +5633,17 @@ readline_internal (lbp, stream) | |||
| 5630 | * Like readline_internal, above, but in addition try to match the | 5633 | * Like readline_internal, above, but in addition try to match the |
| 5631 | * input line against relevant regular expressions. | 5634 | * input line against relevant regular expressions. |
| 5632 | */ | 5635 | */ |
| 5633 | static long | 5636 | static void |
| 5634 | readline (lbp, stream) | 5637 | readline (lbp, stream) |
| 5635 | linebuffer *lbp; | 5638 | linebuffer *lbp; |
| 5636 | FILE *stream; | 5639 | FILE *stream; |
| 5637 | { | 5640 | { |
| 5638 | /* Read new line. */ | 5641 | long result; |
| 5639 | long result = readline_internal (lbp, stream); | 5642 | |
| 5643 | linecharno = charno; /* update global char number of line start */ | ||
| 5644 | result = readline_internal (lbp, stream); /* read line */ | ||
| 5645 | lineno += 1; /* increment global line number */ | ||
| 5646 | charno += result; /* increment global char number */ | ||
| 5640 | 5647 | ||
| 5641 | /* Honour #line directives. */ | 5648 | /* Honour #line directives. */ |
| 5642 | if (!no_line_directive) | 5649 | if (!no_line_directive) |
| @@ -5733,8 +5740,9 @@ readline (lbp, stream) | |||
| 5733 | } | 5740 | } |
| 5734 | } | 5741 | } |
| 5735 | free (taggedabsname); | 5742 | free (taggedabsname); |
| 5736 | lineno = lno; | 5743 | lineno = lno - 1; |
| 5737 | return readline (lbp, stream); | 5744 | readline (lbp, stream); |
| 5745 | return; | ||
| 5738 | } /* if a real #line directive */ | 5746 | } /* if a real #line directive */ |
| 5739 | } /* if #line is followed by a a number */ | 5747 | } /* if #line is followed by a a number */ |
| 5740 | } /* if line begins with "#line " */ | 5748 | } /* if line begins with "#line " */ |
| @@ -5743,12 +5751,15 @@ readline (lbp, stream) | |||
| 5743 | if (discard_until_line_directive) | 5751 | if (discard_until_line_directive) |
| 5744 | { | 5752 | { |
| 5745 | if (result > 0) | 5753 | if (result > 0) |
| 5754 | { | ||
| 5746 | /* Do a tail recursion on ourselves, thus discarding the contents | 5755 | /* Do a tail recursion on ourselves, thus discarding the contents |
| 5747 | of the line buffer. */ | 5756 | of the line buffer. */ |
| 5748 | return readline (lbp, stream); | 5757 | readline (lbp, stream); |
| 5758 | return; | ||
| 5759 | } | ||
| 5749 | /* End of file. */ | 5760 | /* End of file. */ |
| 5750 | discard_until_line_directive = FALSE; | 5761 | discard_until_line_directive = FALSE; |
| 5751 | return 0; | 5762 | return; |
| 5752 | } | 5763 | } |
| 5753 | } /* if #line directives should be considered */ | 5764 | } /* if #line directives should be considered */ |
| 5754 | 5765 | ||
| @@ -5800,8 +5811,6 @@ readline (lbp, stream) | |||
| 5800 | } | 5811 | } |
| 5801 | } | 5812 | } |
| 5802 | #endif /* ETAGS_REGEXPS */ | 5813 | #endif /* ETAGS_REGEXPS */ |
| 5803 | |||
| 5804 | return result; | ||
| 5805 | } | 5814 | } |
| 5806 | 5815 | ||
| 5807 | 5816 | ||