annotate lib-src/etags.c @ 428:3ecd8885ac67 r21-2-22

Import from CVS: tag r21-2-22
author cvs
date Mon, 13 Aug 2007 11:28:15 +0200
parents
children 3a7e78e1142d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Tags file maker to go with GNU Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1984, 87, 88, 89, 93, 94, 95, 98, 99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Free Software Foundation, Inc. and Ken Arnold
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is not considered part of GNU Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 This program is free software; you can redistribute it and/or modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 the Free Software Foundation; either version 2 of the License, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 This program is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with this program; if not, write to the Free Software Foundation,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 * Authors:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 * Ctags originally by Ken Arnold.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 * Fortran added by Jim Kleckner.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 * Ed Pelegri-Llopart added C typedefs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 * Gnu Emacs TAGS format and modifications by RMS?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 * Sam Kendall added C++.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 * Francesco Potorti` reorganised C and C++ based on work by Joe Wells.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 * Regexp tags by Tom Tromey.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 * Francesco Potorti` (pot@gnu.org) is the current maintainer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 * Ansified by Martin Buchholz, 19991105.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 char pot_etags_version[] = "@(#) pot revision number is 13.33";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #define TRUE 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #define FALSE 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #ifndef _GNU_SOURCE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 # define _GNU_SOURCE /* enables some compiler checks on GNU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #ifndef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 # define DEBUG FALSE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 # include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 /* On some systems, Emacs defines static as nothing for the sake
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 of unexec. We don't want that here since we don't use unexec. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 # undef static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 # define ETAGS_REGEXPS /* use the regexp features */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 # define LONG_OPTIONS /* accept long options */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #endif /* HAVE_CONFIG_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #ifdef MSDOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 # include <fcntl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 # include <sys/param.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 # include <io.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 # ifndef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 # define DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 # include <sys/config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 # endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #endif /* MSDOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #ifdef WINDOWSNT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 # include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 # include <fcntl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 # include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 # include <io.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 # define MAXPATHLEN _MAX_PATH
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 # ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 # undef HAVE_NTGUI
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 # else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 # define DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 # endif /* not HAVE_CONFIG_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 # ifndef HAVE_GETCWD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 # define HAVE_GETCWD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 # endif /* undef HAVE_GETCWD */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #endif /* WINDOWSNT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 #if !defined (WINDOWSNT) && defined (STDC_HEADERS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #ifdef HAVE_UNISTD_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 # include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 # ifdef HAVE_GETCWD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 extern char *getcwd ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 # endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #endif /* HAVE_UNISTD_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 #ifndef errno
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 extern int errno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 #include <sys/stat.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 #if !defined (S_ISREG) && defined (S_IFREG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 #ifdef LONG_OPTIONS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 # include <getopt.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 # define getopt_long(argc,argv,optstr,lopts,lind) getopt (argc, argv, optstr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 extern char *optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 extern int optind, opterr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 #endif /* LONG_OPTIONS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 # include <regex.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 /* Define CTAGS to make the program "ctags" compatible with the usual one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 Leave it undefined to make the program "etags", which makes emacs-style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 tag tables and tags typedefs, #defines and struct/union/enum by default. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 #ifdef CTAGS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 # undef CTAGS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 # define CTAGS TRUE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 # define CTAGS FALSE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 /* Exit codes for success and failure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 #ifdef VMS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 # define GOOD 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 # define BAD 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 # define GOOD 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 # define BAD 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 /* C extensions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 #define C_PLPL 0x00001 /* C++ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 #define C_STAR 0x00003 /* C* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 #define C_JAVA 0x00005 /* JAVA */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 #define YACC 0x10000 /* yacc file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 #define streq(s,t) ((DEBUG && (s) == NULL && (t) == NULL \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 && (abort (), 1)) || !strcmp (s, t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 #define strneq(s,t,n) ((DEBUG && (s) == NULL && (t) == NULL \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 && (abort (), 1)) || !strncmp (s, t, n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 #define lowcase(c) tolower ((char)c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 #define CHARS 256 /* 2^sizeof(char) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 #define CHAR(x) ((unsigned int)x & (CHARS - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 #define iswhite(c) (_wht[CHAR(c)]) /* c is white */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 #define notinname(c) (_nin[CHAR(c)]) /* c is not in a name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 #define begtoken(c) (_btk[CHAR(c)]) /* c can start token */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 #define intoken(c) (_itk[CHAR(c)]) /* c can be in token */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 #define endtoken(c) (_etk[CHAR(c)]) /* c ends tokens */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 * xnew, xrnew -- allocate, reallocate storage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 * SYNOPSIS: Type *xnew (int n, Type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 * Type *xrnew (OldPointer, int n, Type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 #ifdef chkmalloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 # include "chkmalloc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 # define xnew(n,Type) ((Type *) trace_malloc (__FILE__, __LINE__, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 # define xrnew(op,n,Type) ((Type *) trace_realloc (__FILE__, __LINE__, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (op), (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 typedef int bool;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 typedef void Lang_function ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 char *suffix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 char *command; /* Takes one arg and decompresses to stdout */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 } compressor;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 char *name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 Lang_function *function;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 char **suffixes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 char **interpreters;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 } language;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 extern char *getenv ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 typedef struct node_st
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 { /* sorting structure */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 char *name; /* function or type name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 char *file; /* file name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 bool is_func; /* use pattern or line no */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 bool been_warned; /* set if noticed dup */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 int lno; /* line number tag is on */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 long cno; /* character number line starts on */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 char *pat; /* search pattern */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 struct node_st *left, *right; /* left and right sons */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 } node;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 * A `linebuffer' is a structure which holds a line of text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 * `readline_internal' reads a line from a stream into a linebuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 * and works regardless of the length of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 * SIZE is the size of BUFFER, LEN is the length of the string in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 * BUFFER after readline reads it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 long size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 char *buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 } linebuffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 /* Many compilers barf on this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 Lang_function Ada_funcs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 so let's write it this way */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 void Ada_funcs (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 void Asm_labels (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 void C_entries (int c_ext, FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 void default_C_entries (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 void plain_C_entries (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 void Cjava_entries (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 void Cobol_paragraphs (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 void Cplusplus_entries (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 void Cstar_entries (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 void Erlang_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 void Fortran_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 void Yacc_entries (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 void Lisp_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 void Pascal_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 void Perl_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 void Postscript_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 void Prolog_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 void Python_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 void Scheme_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 void TeX_functions (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 void just_read_file (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 compressor *get_compressor_from_suffix (char *file, char **extptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 language *get_language_from_name (char *name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 language *get_language_from_interpreter (char *interpreter);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 language *get_language_from_suffix (char *file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 int total_size_of_entries (register node *np);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 long readline (linebuffer *lbp, FILE *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 long readline_internal (linebuffer *lbp, register FILE *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 void get_tag (register char *bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 void analyse_regex (char *regex_arg, bool ignore_case);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 void add_regex (char *regexp_pattern, bool ignore_case, language *lan);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 void free_patterns (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 void error (const char *s1, const char *s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 void suggest_asking_for_help (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 void fatal (char *s1, char *s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 void pfatal (char *s1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 void add_node (node *np, node **cur_node_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 void init (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 void initbuffer (linebuffer *lbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 void find_entries (char *file, FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 void free_tree (register node *np);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 void pfnote (char *name, bool is_func, char *linestart, int linelen, int lno, long int cno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 void new_pfnote (char *name, int namelen, bool is_func, char *linestart, int linelen, int lno, long int cno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 void process_file (char *file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 void put_entries (register node *np);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 void takeprec (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 char *concat (char *s1, char *s2, char *s3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 char *skip_spaces (char *cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 char *skip_non_spaces (char *cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 char *savenstr (char *cp, int len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 char *savestr (char *cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 char *etags_strchr (char *sp, char c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 char *etags_strrchr (char *sp, char c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 char *etags_getcwd (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 char *relative_filename (char *file, char *dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 char *absolute_filename (char *file, char *dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 char *absolute_dirname (char *file, char *dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 bool filename_is_absolute (char *fn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 void canonicalize_filename (register char *fn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 void grow_linebuffer (linebuffer *lbp, int toksize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 long *xmalloc (unsigned int size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 long *xrealloc (char *ptr, unsigned int size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 char searchar = '/'; /* use /.../ searches */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 char *tagfile; /* output file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 char *progname; /* name this program was invoked with */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 char *cwd; /* current working directory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 char *tagfiledir; /* directory of tagfile */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 FILE *tagf; /* ioptr for tags file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 char *curfile; /* current input file name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 language *curlang; /* current language */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 int lineno; /* line number of current line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 long charno; /* current character number */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 long linecharno; /* charno of start of current line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 char *dbp; /* pointer to start of current tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 node *head; /* the head of the binary tree of tags */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 linebuffer lb; /* the current line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 linebuffer token_name; /* used by C_entries as a temporary area */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 long linepos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 linebuffer lb; /* used by C_entries instead of lb */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 } lbs[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 /* boolean "functions" (see init) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 bool _wht[CHARS], _nin[CHARS], _itk[CHARS], _btk[CHARS], _etk[CHARS];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 /* white chars */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 *white = " \f\t\n\r",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 /* not in a name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 *nonam = " \f\t\n\r(=,[;",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 /* token ending chars */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 *endtk = " \t\n\r\"'#()[]{}=-+%*/&|^~!<>;,.:?",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 /* token starting chars */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 /* valid in-token chars */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 *midtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 bool append_to_tagfile; /* -a: append to tags */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 /* The following four default to TRUE for etags, but to FALSE for ctags. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 bool typedefs; /* -t: create tags for C and Ada typedefs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 bool typedefs_and_cplusplus; /* -T: create tags for C typedefs, level */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 /* 0 struct/enum/union decls, and C++ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 /* member functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 bool constantypedefs; /* -d: create tags for C #define, enum */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 /* constants and variables. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 /* -D: opposite of -d. Default under ctags. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 bool declarations; /* --declarations: tag them and extern in C&Co*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 bool globals; /* create tags for global variables */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 bool members; /* create tags for C member variables */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 bool update; /* -u: update tags */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 bool vgrind_style; /* -v: create vgrind style index output */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 bool no_warnings; /* -w: suppress warnings */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 bool cxref_style; /* -x: create cxref style output */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 bool cplusplus; /* .[hc] means C++, not C */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 bool noindentypedefs; /* -I: ignore indentation in C */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 bool packages_only; /* --packages-only: in Ada, only tag packages*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 #ifdef LONG_OPTIONS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 struct option longopts[] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 { "packages-only", no_argument, &packages_only, TRUE },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 { "append", no_argument, NULL, 'a' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 { "backward-search", no_argument, NULL, 'B' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 { "c++", no_argument, NULL, 'C' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 { "cxref", no_argument, NULL, 'x' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 { "defines", no_argument, NULL, 'd' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 { "declarations", no_argument, &declarations, TRUE },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 { "no-defines", no_argument, NULL, 'D' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 { "globals", no_argument, &globals, TRUE },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 { "no-globals", no_argument, &globals, FALSE },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 { "help", no_argument, NULL, 'h' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 { "help", no_argument, NULL, 'H' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 { "ignore-indentation", no_argument, NULL, 'I' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 { "include", required_argument, NULL, 'i' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 { "language", required_argument, NULL, 'l' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 { "members", no_argument, &members, TRUE },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 { "no-members", no_argument, &members, FALSE },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 { "no-warn", no_argument, NULL, 'w' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 { "output", required_argument, NULL, 'o' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 { "regex", required_argument, NULL, 'r' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 { "no-regex", no_argument, NULL, 'R' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 { "ignore-case-regex", required_argument, NULL, 'c' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 { "typedefs", no_argument, NULL, 't' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 { "typedefs-and-c++", no_argument, NULL, 'T' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 { "update", no_argument, NULL, 'u' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 { "version", no_argument, NULL, 'V' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 { "vgrind", no_argument, NULL, 'v' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 { NULL }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 #endif /* LONG_OPTIONS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 /* Structure defining a regular expression. Elements are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 the compiled pattern, and the name string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 typedef struct pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 struct pattern *p_next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 language *language;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 char *regex;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 struct re_pattern_buffer *pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 struct re_registers regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 char *name_pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 bool error_signaled;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 } pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 /* List of all regexps. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 pattern *p_head = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 /* How many characters in the character set. (From regex.c.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 #define CHAR_SET_SIZE 256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 /* Translation table for case-insensitive matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 char lc_trans[CHAR_SET_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 compressor compressors[] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 { "z", "gzip -d -c"},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 { "Z", "gzip -d -c"},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 { "gz", "gzip -d -c"},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 { "GZ", "gzip -d -c"},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 { "bz2", "bzip2 -d -c" },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 { NULL }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 * Language stuff.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 /* Non-NULL if language fixed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 language *forced_lang = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 /* Ada code */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 char *Ada_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 { "ads", "adb", "ada", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 /* Assembly code */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 char *Asm_suffixes [] = { "a", /* Unix assembler */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 "asm", /* Microcontroller assembly */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 "def", /* BSO/Tasking definition includes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 "inc", /* Microcontroller include files */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 "ins", /* Microcontroller include files */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 "s", "sa", /* Unix assembler */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 "S", /* cpp-processed Unix assembler */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 "src", /* BSO/Tasking C compiler output */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 /* Note that .c and .h can be considered C++, if the --c++ flag was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 given. That is why default_C_entries is called here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 char *default_C_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 { "c", "h", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 char *Cplusplus_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 { "C", "H", "c++", "cc", "cpp", "cxx", "h++", "hh", "hpp", "hxx",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 "M", /* Objective C++ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 "pdb", /* Postscript with C syntax */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 char *Cjava_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 { "java", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 char *Cobol_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 { "COB", "cob", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 char *Cstar_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 { "cs", "hs", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 char *Erlang_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 { "erl", "hrl", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 char *Fortran_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 { "F", "f", "f90", "for", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 char *Lisp_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 { "cl", "clisp", "el", "l", "lisp", "lsp", "ml", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 char *Pascal_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 { "p", "pas", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 char *Perl_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 { "pl", "pm", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 char *Perl_interpreters [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 { "perl", "@PERL@", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 char *plain_C_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 { "pc", /* Pro*C file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 "m", /* Objective C file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 "lm", /* Objective lex file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 char *Postscript_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 { "ps", "psw", NULL }; /* .psw is for PSWrap */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 char *Prolog_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 { "prolog", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 char *Python_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 { "py", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 /* Can't do the `SCM' or `scm' prefix with a version number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 char *Scheme_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 { "SCM", "SM", "oak", "sch", "scheme", "scm", "sm", "ss", "t", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 char *TeX_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 { "TeX", "bib", "clo", "cls", "ltx", "sty", "tex", NULL };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 char *Yacc_suffixes [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 { "y", "ym", "yy", "yxx", "y++", NULL }; /* .ym is Objective yacc file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 * Table of languages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 * It is ok for a given function to be listed under more than one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 * name. I just didn't.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 language lang_names [] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 { "ada", Ada_funcs, Ada_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 { "asm", Asm_labels, Asm_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 { "c", default_C_entries, default_C_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 { "c++", Cplusplus_entries, Cplusplus_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 { "c*", Cstar_entries, Cstar_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 { "cobol", Cobol_paragraphs, Cobol_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 { "erlang", Erlang_functions, Erlang_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 { "fortran", Fortran_functions, Fortran_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 { "java", Cjava_entries, Cjava_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 { "lisp", Lisp_functions, Lisp_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 { "pascal", Pascal_functions, Pascal_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 { "perl", Perl_functions, Perl_suffixes, Perl_interpreters },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 { "postscript", Postscript_functions, Postscript_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 { "proc", plain_C_entries, plain_C_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 { "prolog", Prolog_functions, Prolog_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 { "python", Python_functions, Python_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 { "scheme", Scheme_functions, Scheme_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 { "tex", TeX_functions, TeX_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 { "yacc", Yacc_entries, Yacc_suffixes, NULL },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 { "auto", NULL }, /* default guessing scheme */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 { "none", just_read_file }, /* regexp matching only */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 { NULL, NULL } /* end of list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 print_language_names ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 language *lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 char **ext;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 puts ("\nThese are the currently supported languages, along with the\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 default file name suffixes:");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 for (lang = lang_names; lang->name != NULL; lang++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 printf ("\t%s\t", lang->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 if (lang->suffixes != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 for (ext = lang->suffixes; *ext != NULL; ext++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 printf (" .%s", *ext);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 puts ("");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 puts ("Where `auto' means use default language for files based on file\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 name suffix, and `none' means only do regexp processing on files.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 If no language is specified and no matching suffix is found,\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 the first line of the file is read for a sharp-bang (#!) sequence\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 followed by the name of an interpreter. If no such sequence is found,\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 Fortran is tried first; if no tags are found, C is tried next.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 Compressed files are supported using gzip and bzip2.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 #ifdef XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 # define EMACS_NAME "XEmacs"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 # define EMACS_NAME "GNU Emacs"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 #ifndef VERSION
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 # define VERSION "20"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 print_version ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 printf ("%s (" EMACS_NAME " %s)\n", (CTAGS) ? "ctags" : "etags", VERSION);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 puts ("Copyright (C) 1999 Free Software Foundation, Inc. and Ken Arnold");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 puts ("This program is distributed under the same terms as Emacs");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 exit (GOOD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 print_help ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 printf ("Usage: %s [options] [[regex-option ...] file-name] ...\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 \n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 These are the options accepted by %s.\n", progname, progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 #ifdef LONG_OPTIONS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 puts ("You may use unambiguous abbreviations for the long option names.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 puts ("Long option names do not work with this executable, as it is not\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 linked with GNU getopt.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 #endif /* LONG_OPTIONS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 puts ("A - as file name means read names from stdin (one per line).");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 printf (" Absolute names are stored in the output file as they are.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 Relative ones are stored relative to the output file's directory.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 puts ("\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 puts ("-a, --append\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 Append tag entries to existing tags file.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 puts ("--packages-only\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 For Ada files, only generate tags for packages .");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 if (CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 puts ("-B, --backward-search\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 Write the search commands for the tag entries using '?', the\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 backward-search command instead of '/', the forward-search command.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 puts ("-C, --c++\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 Treat files whose name suffix defaults to C language as C++ files.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 puts ("--declarations\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 In C and derived languages, create tags for function declarations,");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 if (CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 puts ("\tand create tags for extern variables if --globals is used.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 puts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 ("\tand create tags for extern variables unless --no-globals is used.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 if (CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 puts ("-d, --defines\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 Create tag entries for C #define constants and enum constants, too.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 puts ("-D, --no-defines\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 Don't create tag entries for C #define constants and enum constants.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 This makes the tags file smaller.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 puts ("-i FILE, --include=FILE\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 Include a note in tag file indicating that, when searching for\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 a tag, one should also consult the tags file FILE after\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 checking the current file.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 puts ("-l LANG, --language=LANG\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 Force the following files to be considered as written in the\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 named language up to the next --language=LANG option.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 if (CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 puts ("--globals\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 Create tag entries for global variables in some languages.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 puts ("--no-globals\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 Do not create tag entries for global variables in some\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 languages. This makes the tags file smaller.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 puts ("--members\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 Create tag entries for member variables in C and derived languages.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 puts ("-r /REGEXP/, --regex=/REGEXP/ or --regex=@regexfile\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 Make a tag for each line matching pattern REGEXP in the following\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 files. {LANGUAGE}/REGEXP/ uses REGEXP for LANGUAGE files only.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 regexfile is a file containing one REGEXP per line.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 REGEXP is anchored (as if preceded by ^).\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 The form /REGEXP/NAME/ creates a named tag.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 For example Tcl named tags can be created with:\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 --regex=/proc[ \\t]+\\([^ \\t]+\\)/\\1/.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 puts ("-c /REGEXP/, --ignore-case-regex=/REGEXP/ or --ignore-case-regex=@regexfile\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 Like -r, --regex but ignore case when matching expressions.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 puts ("-R, --no-regex\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 Don't create tags from regexps for the following files.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 puts ("-o FILE, --output=FILE\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 Write the tags to FILE.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 puts ("-I, --ignore-indentation\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 Don't rely on indentation quite as much as normal. Currently,\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 this means not to assume that a closing brace in the first\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 column is the final brace of a function or structure\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 definition in C and C++.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 if (CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 puts ("-t, --typedefs\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 Generate tag entries for C and Ada typedefs.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 puts ("-T, --typedefs-and-c++\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 Generate tag entries for C typedefs, C struct/enum/union tags,\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 and C++ member functions.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 puts ("-u, --update\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 Update the tag entries for the given files, leaving tag\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 entries for other files in place. Currently, this is\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 implemented by deleting the existing entries for the given\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 files and then rewriting the new entries at the end of the\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 tags file. It is often faster to simply rebuild the entire\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 tag file than to use this.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 puts ("-v, --vgrind\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 Generates an index of items intended for human consumption,\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 similar to the output of vgrind. The index is sorted, and\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 gives the page number of each item.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 puts ("-w, --no-warn\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 Suppress warning messages about entries defined in multiple\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 files.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 puts ("-x, --cxref\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 Like --vgrind, but in the style of cxref, rather than vgrind.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 The output uses line numbers instead of page numbers, but\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 beyond that the differences are cosmetic; try both to see\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 which you like.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 puts ("-V, --version\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 Print the version of the program.\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 -h, --help\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 Print this help message.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 print_language_names ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 puts ("");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 puts ("Report bugs to bug-gnu-emacs@gnu.org");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 exit (GOOD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 enum argument_type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 at_language,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 at_regexp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 at_filename,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 at_icregexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 /* This structure helps us allow mixing of --lang and file names. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 enum argument_type arg_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 char *what;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 language *lang; /* language of the regexp */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 } argument;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 #ifdef VMS /* VMS specific functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 #define EOS '\0'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 /* This is a BUG! ANY arbitrary limit is a BUG!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 Won't someone please fix this? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 #define MAX_FILE_SPEC_LEN 255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 typedef struct {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 short curlen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 char body[MAX_FILE_SPEC_LEN + 1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 } vspec;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 v1.05 nmm 26-Jun-86 fn_exp - expand specification of list of file names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 returning in each successive call the next file name matching the input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 spec. The function expects that each in_spec passed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 to it will be processed to completion; in particular, up to and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 including the call following that in which the last matching name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 is returned, the function ignores the value of in_spec, and will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 only start processing a new spec with the following call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 If an error occurs, on return out_spec contains the value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 of in_spec when the error occurred.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 With each successive file name returned in out_spec, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 function's return value is one. When there are no more matching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 names the function returns zero. If on the first call no file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 matches in_spec, or there is any other error, -1 is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 #include <rmsdef.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 #include <descrip.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 #define OUTSIZE MAX_FILE_SPEC_LEN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 short
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 fn_exp (out, in)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 vspec *out;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 char *in;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 static long context = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 static struct dsc$descriptor_s o;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 static struct dsc$descriptor_s i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 static bool pass1 = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 long status;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 short retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 if (pass1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 pass1 = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 o.dsc$a_pointer = (char *) out;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 o.dsc$w_length = (short)OUTSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 i.dsc$a_pointer = in;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 i.dsc$w_length = (short)strlen(in);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 i.dsc$b_dtype = DSC$K_DTYPE_T;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 i.dsc$b_class = DSC$K_CLASS_S;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 o.dsc$b_dtype = DSC$K_DTYPE_VT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 o.dsc$b_class = DSC$K_CLASS_VS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 if ((status = lib$find_file(&i, &o, &context, 0, 0)) == RMS$_NORMAL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 out->body[out->curlen] = EOS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 else if (status == RMS$_NMF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 retval = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 strcpy(out->body, in);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 retval = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 lib$find_file_end(&context);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 pass1 = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 return retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 v1.01 nmm 19-Aug-85 gfnames - return in successive calls the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 name of each file specified by the provided arg expanding wildcards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 gfnames (arg, p_error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 char *arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 bool *p_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 static vspec filename = {MAX_FILE_SPEC_LEN, "\0"};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 switch (fn_exp (&filename, arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 case 1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 *p_error = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 return filename.body;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 *p_error = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 *p_error = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 return filename.body;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 #ifndef OLD /* Newer versions of VMS do provide `system'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 system (cmd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 char *cmd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 error ("%s", "system() function not implemented under VMS");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 #define VERSION_DELIM ';'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 char *massage_name (s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 char *s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 char *start = s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 for ( ; *s; s++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 if (*s == VERSION_DELIM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 *s = EOS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 *s = lowcase (*s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 return start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 #endif /* VMS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 main (argc, argv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 int argc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 char *argv[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 unsigned int nincluded_files;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 char **included_files;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 char *this_file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 argument *argbuffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 int current_arg, file_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 linebuffer filename_lb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 #ifdef VMS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 bool got_err;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 #ifdef DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 _fmode = O_BINARY; /* all of files are treated as binary files */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 #endif /* DOS_NT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 progname = argv[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 nincluded_files = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 included_files = xnew (argc, char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 current_arg = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 file_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 /* Allocate enough no matter what happens. Overkill, but each one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 is small. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 argbuffer = xnew (argc, argument);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 /* Set syntax for regular expression routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 re_set_syntax (RE_SYNTAX_EMACS | RE_INTERVALS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 /* Translation table for case-insensitive search. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 for (i = 0; i < CHAR_SET_SIZE; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 lc_trans[i] = lowcase (i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 * If etags, always find typedefs and structure tags. Why not?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 * Also default is to find macro constants, enum constants and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 * global variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 typedefs = typedefs_and_cplusplus = constantypedefs = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 globals = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 members = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 int opt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 char *optstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 optstring = "-aCdDf:Il:o:r:c:RStTi:BuvxwVhH";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 optstring = "-aCdDf:Il:o:StTi:BuvxwVhH";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 #ifndef LONG_OPTIONS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 optstring = optstring + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 #endif /* LONG_OPTIONS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 opt = getopt_long (argc, argv, optstring, longopts, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 if (opt == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 switch (opt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 /* If getopt returns 0, then it has already processed a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 long-named option. We should do nothing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 case 1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 /* This means that a file name has been seen. Record it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 argbuffer[current_arg].arg_type = at_filename;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 argbuffer[current_arg].what = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 ++current_arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 ++file_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 /* Common options. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 case 'a': append_to_tagfile = TRUE; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 case 'C': cplusplus = TRUE; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 case 'd': constantypedefs = TRUE; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 case 'D': constantypedefs = FALSE; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 case 'f': /* for compatibility with old makefiles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 case 'o':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 if (tagfile)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 error ("-o option may only be given once.", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 suggest_asking_for_help ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 tagfile = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 case 'I':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 case 'S': /* for backward compatibility */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 noindentypedefs = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 case 'l':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 language *lang = get_language_from_name (optarg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 if (lang != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 argbuffer[current_arg].lang = lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 argbuffer[current_arg].arg_type = at_language;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 ++current_arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 case 'r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 argbuffer[current_arg].arg_type = at_regexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 argbuffer[current_arg].what = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 ++current_arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 case 'R':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 argbuffer[current_arg].arg_type = at_regexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 argbuffer[current_arg].what = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 ++current_arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 case 'c':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 argbuffer[current_arg].arg_type = at_icregexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 argbuffer[current_arg].what = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 ++current_arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 case 'V':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 print_version ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 case 'h':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 case 'H':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 print_help ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 case 't':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 typedefs = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 case 'T':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 typedefs = typedefs_and_cplusplus = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 #if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 /* Etags options */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 case 'i':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 included_files[nincluded_files++] = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 #else /* CTAGS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 /* Ctags options. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 case 'B': searchar = '?'; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 case 'u': update = TRUE; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 case 'v': vgrind_style = TRUE; /*FALLTHRU*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 case 'x': cxref_style = TRUE; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 case 'w': no_warnings = TRUE; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 #endif /* CTAGS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 suggest_asking_for_help ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 for (; optind < argc; ++optind)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 argbuffer[current_arg].arg_type = at_filename;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 argbuffer[current_arg].what = argv[optind];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 ++current_arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 ++file_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 if (nincluded_files == 0 && file_count == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 error ("no input files specified.", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 suggest_asking_for_help ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 if (tagfile == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 tagfile = CTAGS ? "tags" : "TAGS";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 cwd = etags_getcwd (); /* the current working directory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 if (cwd[strlen (cwd) - 1] != '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 char *oldcwd = cwd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 cwd = concat (oldcwd, "/", "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 free (oldcwd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 if (streq (tagfile, "-"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 tagfiledir = cwd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 tagfiledir = absolute_dirname (tagfile, cwd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 init (); /* set up boolean "functions" */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 initbuffer (&lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 initbuffer (&token_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 initbuffer (&lbs[0].lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 initbuffer (&lbs[1].lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 initbuffer (&filename_lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 if (streq (tagfile, "-"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 tagf = stdout;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 #ifdef DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 /* Switch redirected `stdout' to binary mode (setting `_fmode'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 doesn't take effect until after `stdout' is already open). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 if (!isatty (fileno (stdout)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 setmode (fileno (stdout), O_BINARY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 #endif /* DOS_NT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 if (tagf == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 pfatal (tagfile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 * Loop through files finding functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 for (i = 0; i < current_arg; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 switch (argbuffer[i].arg_type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 case at_language:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 forced_lang = argbuffer[i].lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 case at_regexp:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 analyse_regex (argbuffer[i].what, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 case at_icregexp:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 analyse_regex (argbuffer[i].what, TRUE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 case at_filename:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 #ifdef VMS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 while ((this_file = gfnames (argbuffer[i].what, &got_err)) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 if (got_err)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 error ("can't find file %s\n", this_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 argc--, argv++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 this_file = massage_name (this_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 this_file = argbuffer[i].what;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 /* Input file named "-" means read file names from stdin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 (one per line) and use them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 if (streq (this_file, "-"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 while (readline_internal (&filename_lb, stdin) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 process_file (filename_lb.buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 process_file (this_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 #ifdef VMS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 free_patterns ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 while (nincluded_files-- > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 fprintf (tagf, "\f\n%s,include\n", *included_files++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 fclose (tagf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 exit (GOOD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 /* If CTAGS, we are here. process_file did not write the tags yet,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 because we want them ordered. Let's do it now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 if (cxref_style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 put_entries (head);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 free_tree (head);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 head = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 exit (GOOD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 if (update)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 char cmd[BUFSIZ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 for (i = 0; i < current_arg; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 if (argbuffer[i].arg_type != at_filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 sprintf (cmd,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 "mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 tagfile, argbuffer[i].what, tagfile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 if (system (cmd) != GOOD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 fatal ("failed to execute shell command", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 append_to_tagfile = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 if (tagf == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 pfatal (tagfile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 put_entries (head);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 free_tree (head);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 head = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 fclose (tagf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 if (update)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 char cmd[BUFSIZ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 sprintf (cmd, "sort %s -o %s", tagfile, tagfile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 exit (system (cmd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 return GOOD;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 * Return a compressor given the file name. If EXTPTR is non-zero,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 * return a pointer into FILE where the compressor-specific
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 * extension begins. If no compressor is found, NULL is returned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 * and EXTPTR is not significant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 * Idea by Vladimir Alexiev <vladimir@cs.ualberta.ca>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 compressor *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 get_compressor_from_suffix (file, extptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 char *file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 char **extptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 compressor *compr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 char *slash, *suffix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 /* This relies on FN to be after canonicalize_filename,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 so we don't need to consider backslashes on DOS_NT. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 slash = etags_strrchr (file, '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 suffix = etags_strrchr (file, '.');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 if (suffix == NULL || suffix < slash)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 if (extptr != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 *extptr = suffix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 suffix += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 /* Let those poor souls who live with DOS 8+3 file name limits get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 some solace by treating foo.cgz as if it were foo.c.gz, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 Only the first do loop is run if not MSDOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 for (compr = compressors; compr->suffix != NULL; compr++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 if (streq (compr->suffix, suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 return compr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 #ifndef MSDOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 if (extptr != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 *extptr = ++suffix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 } while (*suffix != '\0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 * Return a language given the name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 language *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 get_language_from_name (name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 char *name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 language *lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 if (name == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 error ("empty language name", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 for (lang = lang_names; lang->name != NULL; lang++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 if (streq (name, lang->name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 return lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 error ("unknown language \"%s\"", name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 * Return a language given the interpreter name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 language *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 get_language_from_interpreter (interpreter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 char *interpreter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 language *lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 char **iname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 if (interpreter == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 for (lang = lang_names; lang->name != NULL; lang++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 if (lang->interpreters != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 for (iname = lang->interpreters; *iname != NULL; iname++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 if (streq (*iname, interpreter))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 return lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 * Return a language given the file name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 language *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 get_language_from_suffix (file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 char *file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 language *lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 char **ext, *suffix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 suffix = etags_strrchr (file, '.');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 if (suffix == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 suffix += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 for (lang = lang_names; lang->name != NULL; lang++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 if (lang->suffixes != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 for (ext = lang->suffixes; *ext != NULL; ext++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 if (streq (*ext, suffix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 return lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 * This routine is called on each file argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 process_file (file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 char *file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 struct stat stat_buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 compressor *compr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 char *compressed_name, *uncompressed_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 char *ext, *real_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 canonicalize_filename (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 if (streq (file, tagfile) && !streq (tagfile, "-"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 error ("skipping inclusion of %s in self.", file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 if ((compr = get_compressor_from_suffix (file, &ext)) == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 compressed_name = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 real_name = uncompressed_name = savestr (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 real_name = compressed_name = savestr (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 uncompressed_name = savenstr (file, ext - file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 /* If the canonicalised uncompressed name has already be dealt with,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 skip it silently, else add it to the list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 typedef struct processed_file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 char *filename;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 struct processed_file *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 } processed_file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 static processed_file *pf_head = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 register processed_file *fnp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 for (fnp = pf_head; fnp != NULL; fnp = fnp->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 if (streq (uncompressed_name, fnp->filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 goto exit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 fnp = pf_head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 pf_head = xnew (1, struct processed_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 pf_head->filename = savestr (uncompressed_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 pf_head->next = fnp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 if (stat (real_name, &stat_buf) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 /* Reset real_name and try with a different name. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 real_name = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 if (compressed_name != NULL) /* try with the given suffix */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 if (stat (uncompressed_name, &stat_buf) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 real_name = uncompressed_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 else /* try all possible suffixes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 for (compr = compressors; compr->suffix != NULL; compr++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 compressed_name = concat (file, ".", compr->suffix);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 if (stat (compressed_name, &stat_buf) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 #ifdef MSDOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 char *suf = compressed_name + strlen (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 size_t suflen = strlen (compr->suffix) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 for ( ; suf[1]; suf++, suflen--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 memmove (suf, suf + 1, suflen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 if (stat (compressed_name, &stat_buf) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 real_name = compressed_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 if (real_name != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 free (compressed_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 compressed_name = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 real_name = compressed_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 if (real_name == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 perror (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 goto exit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 } /* try with a different name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 if (!S_ISREG (stat_buf.st_mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 error ("skipping %s: it is not a regular file.", real_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 goto exit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 if (real_name == compressed_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 char *cmd = concat (compr->command, " ", real_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 inf = popen (cmd, "r");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 free (cmd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 inf = fopen (real_name, "r");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 if (inf == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 perror (real_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 goto exit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 find_entries (uncompressed_name, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 if (real_name == compressed_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 pclose (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 fclose (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 char *filename;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 if (filename_is_absolute (uncompressed_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 /* file is an absolute file name. Canonicalise it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 filename = absolute_filename (uncompressed_name, cwd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 /* file is a file name relative to cwd. Make it relative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 to the directory of the tags file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 filename = relative_filename (uncompressed_name, tagfiledir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 fprintf (tagf, "\f\n%s,%d\n", filename, total_size_of_entries (head));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 free (filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 put_entries (head);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 free_tree (head);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 head = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 exit:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 if (compressed_name) free(compressed_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 if (uncompressed_name) free(uncompressed_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 * This routine sets up the boolean pseudo-functions which work
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 * by setting boolean flags dependent upon the corresponding character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 * Every char which is NOT in that string is not a white char. Therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 * all of the array "_wht" is set to FALSE, and then the elements
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 * subscripted by the chars in "white" are set to TRUE. Thus "_wht"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 * of a char is TRUE if it is the string "white", else FALSE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 init ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 register char *sp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 register int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 for (i = 0; i < CHARS; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 iswhite(i) = notinname(i) = begtoken(i) = intoken(i) = endtoken(i) = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 for (sp = white; *sp != '\0'; sp++) iswhite (*sp) = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 for (sp = nonam; *sp != '\0'; sp++) notinname (*sp) = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 for (sp = begtk; *sp != '\0'; sp++) begtoken (*sp) = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 for (sp = midtk; *sp != '\0'; sp++) intoken (*sp) = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 for (sp = endtk; *sp != '\0'; sp++) endtoken (*sp) = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 iswhite('\0') = iswhite('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 notinname('\0') = notinname('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 begtoken('\0') = begtoken('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 intoken('\0') = intoken('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 endtoken('\0') = endtoken('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 * This routine opens the specified file and calls the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 * which finds the function and type definitions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 node *last_node = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 find_entries (file, inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 char *file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 language *lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 node *old_last_node;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 /* Memory leakage here: the string pointed by curfile is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 never released, because curfile is copied into np->file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 for each node, to be used in CTAGS mode. The amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 memory leaked here is the sum of the lengths of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 file names. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 curfile = savestr (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 /* If user specified a language, use it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 lang = forced_lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 if (lang != NULL && lang->function != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 curlang = lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 lang->function (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 /* Try to guess the language given the file name. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 lang = get_language_from_suffix (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 if (lang != NULL && lang->function != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 curlang = lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 lang->function (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 /* Look for sharp-bang as the first two characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 if (readline_internal (&lb, inf) > 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 && lb.len >= 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 && lb.buffer[0] == '#'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 && lb.buffer[1] == '!')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 char *lp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 /* Set lp to point at the first char after the last slash in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 line or, if no slashes, at the first nonblank. Then set cp to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 the first successive blank and terminate the string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 lp = etags_strrchr (lb.buffer+2, '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 if (lp != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 lp += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 lp = skip_spaces (lb.buffer + 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 cp = skip_non_spaces (lp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 *cp = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 if (strlen (lp) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 lang = get_language_from_interpreter (lp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 if (lang != NULL && lang->function != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 curlang = lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 lang->function (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 /* We rewind here, even if inf may be a pipe. We fail if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 length of the first line is longer than the pipe block size,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 which is unlikely. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 rewind (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 /* Try Fortran. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 old_last_node = last_node;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 curlang = get_language_from_name ("fortran");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 Fortran_functions (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 /* No Fortran entries found. Try C. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 if (old_last_node == last_node)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 /* We do not tag if rewind fails.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 Only the file name will be recorded in the tags file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 rewind (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 curlang = get_language_from_name (cplusplus ? "c++" : "c");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 default_C_entries (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 /* Record a tag. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 pfnote (name, is_func, linestart, linelen, lno, cno)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 char *name; /* tag name, or NULL if unnamed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 bool is_func; /* tag is a function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 char *linestart; /* start of the line where tag is */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 int linelen; /* length of the line where tag is */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 int lno; /* line number */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 long cno; /* character number */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 register node *np;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 if (CTAGS && name == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 np = xnew (1, node);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 /* If ctags mode, change name "main" to M<thisfilename>. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 if (CTAGS && !cxref_style && streq (name, "main"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 register char *fp = etags_strrchr (curfile, '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 np->name = concat ("M", fp == NULL ? curfile : fp + 1, "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 fp = etags_strrchr (np->name, '.');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 if (fp != NULL && fp[1] != '\0' && fp[2] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 fp[0] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 np->name = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 np->been_warned = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 np->file = curfile;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 np->is_func = is_func;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 np->lno = lno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 /* Our char numbers are 0-base, because of C language tradition?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 ctags compatibility? old versions compatibility? I don't know.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 Anyway, since emacs's are 1-base we expect etags.el to take care
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 of the difference. If we wanted to have 1-based numbers, we would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 uncomment the +1 below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 np->cno = cno /* + 1 */ ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 np->left = np->right = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 if (CTAGS && !cxref_style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 if (strlen (linestart) < 50)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 np->pat = concat (linestart, "$", "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 np->pat = savenstr (linestart, 50);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 np->pat = savenstr (linestart, linelen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 add_node (np, &head);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 /* Date: Wed, 22 Jan 1997 02:56:31 -0500 [last amended 18 Sep 1997]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 * From: Sam Kendall <kendall@mv.mv.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 * Subject: Proposal for firming up the TAGS format specification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 * To: F.Potorti@cnuce.cnr.it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 * pfnote should emit the optimized form [unnamed tag] only if:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 * 1. name does not contain any of the characters " \t\r\n(),;";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 * 2. linestart contains name as either a rightmost, or rightmost but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 * one character, substring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 * 3. the character, if any, immediately before name in linestart must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 * be one of the characters " \t(),;";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 * 4. the character, if any, immediately after name in linestart must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 * also be one of the characters " \t(),;".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 * The real implementation uses the notinname() macro, which recognises
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 * characters slightly different form " \t\r\n(),;". See the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 * `nonam'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 #define traditional_tag_style TRUE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 new_pfnote (name, namelen, is_func, linestart, linelen, lno, cno)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 char *name; /* tag name, or NULL if unnamed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 int namelen; /* tag length */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 bool is_func; /* tag is a function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 char *linestart; /* start of the line where tag is */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 int linelen; /* length of the line where tag is */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 int lno; /* line number */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 long cno; /* character number */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 bool named;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 named = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 for (cp = name; !notinname (*cp); cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 if (*cp == '\0') /* rule #1 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 cp = linestart + linelen - namelen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 if (notinname (linestart[linelen-1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 cp -= 1; /* rule #4 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 if (cp >= linestart /* rule #2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 && (cp == linestart
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 || notinname (cp[-1])) /* rule #3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 && strneq (name, cp, namelen)) /* rule #2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 named = FALSE; /* use unnamed tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 if (named)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 name = savenstr (name, namelen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 name = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 pfnote (name, is_func, linestart, linelen, lno, cno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 * free_tree ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 * recurse on left children, iterate on right children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 free_tree (np)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 register node *np;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 while (np)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 register node *node_right = np->right;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 free_tree (np->left);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 if (np->name != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 free (np->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 free (np->pat);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 free (np);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 np = node_right;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 * add_node ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 * Adds a node to the tree of nodes. In etags mode, we don't keep
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 * it sorted; we just keep a linear list. In ctags mode, maintain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 * an ordered tree, with no attempt at balancing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 * add_node is the only function allowed to add nodes, so it can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 * maintain state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 add_node (np, cur_node_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 node *np, **cur_node_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 register int dif;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 register node *cur_node = *cur_node_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 if (cur_node == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 *cur_node_p = np;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 last_node = np;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 /* Etags Mode */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 if (last_node == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 fatal ("internal error in add_node", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 last_node->right = np;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 last_node = np;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 /* Ctags Mode */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 dif = strcmp (np->name, cur_node->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 * If this tag name matches an existing one, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 * do not add the node, but maybe print a warning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 if (!dif)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 if (streq (np->file, cur_node->file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 if (!no_warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 fprintf (stderr, "Duplicate entry in file %s, line %d: %s\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 np->file, lineno, np->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 fprintf (stderr, "Second entry ignored\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 else if (!cur_node->been_warned && !no_warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 fprintf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 (stderr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 "Duplicate entry in files %s and %s: %s (Warning only)\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 np->file, cur_node->file, np->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 cur_node->been_warned = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 /* Actually add the node */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 add_node (np, dif < 0 ? &cur_node->left : &cur_node->right);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 put_entries (np)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 register node *np;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 register char *sp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 if (np == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 /* Output subentries that precede this one */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 put_entries (np->left);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 /* Output this entry */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 if (!CTAGS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 if (np->name != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 fprintf (tagf, "%s\177%s\001%d,%ld\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 np->pat, np->name, np->lno, np->cno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 fprintf (tagf, "%s\177%d,%ld\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 np->pat, np->lno, np->cno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 if (np->name == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 error ("internal error: NULL name in ctags mode.", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 if (cxref_style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 if (vgrind_style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 fprintf (stdout, "%s %s %d\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 np->name, np->file, (np->lno + 63) / 64);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 fprintf (stdout, "%-16s %3d %-16s %s\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 np->name, np->lno, np->file, np->pat);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 fprintf (tagf, "%s\t%s\t", np->name, np->file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 if (np->is_func)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 { /* a function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 putc (searchar, tagf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 putc ('^', tagf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 for (sp = np->pat; *sp; sp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 if (*sp == '\\' || *sp == searchar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 putc ('\\', tagf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 putc (*sp, tagf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 putc (searchar, tagf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 { /* a typedef; text pattern inadequate */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 fprintf (tagf, "%d", np->lno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 putc ('\n', tagf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 /* Output subentries that follow this one */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 put_entries (np->right);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 /* Length of a number's decimal representation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 number_len (num)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 long num;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 int len = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 while ((num /= 10) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 len += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 return len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 * Return total number of characters that put_entries will output for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 * the nodes in the subtree of the specified node. Works only if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 * we are not ctags, but called only in that case. This count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 * is irrelevant with the new tags.el, but is still supplied for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 * backward compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 total_size_of_entries (np)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 register node *np;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 register int total;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 if (np == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 for (total = 0; np != NULL; np = np->right)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 /* Count left subentries. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 total += total_size_of_entries (np->left);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 /* Count this entry */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 total += strlen (np->pat) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 total += number_len ((long) np->lno) + 1 + number_len (np->cno) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 if (np->name != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 total += 1 + strlen (np->name); /* \001name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 return total;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 * The C symbol tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 enum sym_type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 st_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 st_C_objprot, st_C_objimpl, st_C_objend,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 st_C_gnumacro,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 st_C_ignore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 st_C_javastruct,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 st_C_operator,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 st_C_struct, st_C_extern, st_C_enum, st_C_define, st_C_typedef, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 /* Feed stuff between (but not including) %[ and %] lines to:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 gperf -c -k 1,3 -o -p -r -t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 %[
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 struct C_stab_entry { char *name; int c_ext; enum sym_type type; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 %%
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 if, 0, st_C_ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 for, 0, st_C_ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 while, 0, st_C_ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 switch, 0, st_C_ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 return, 0, st_C_ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 @interface, 0, st_C_objprot
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 @protocol, 0, st_C_objprot
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 @implementation,0, st_C_objimpl
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 @end, 0, st_C_objend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 import, C_JAVA, st_C_ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 package, C_JAVA, st_C_ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 friend, C_PLPL, st_C_ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 extends, C_JAVA, st_C_javastruct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 implements, C_JAVA, st_C_javastruct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 interface, C_JAVA, st_C_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 class, C_PLPL, st_C_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 namespace, C_PLPL, st_C_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 domain, C_STAR, st_C_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 union, 0, st_C_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 struct, 0, st_C_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 extern, 0, st_C_extern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 enum, 0, st_C_enum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 typedef, 0, st_C_typedef
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 define, 0, st_C_define
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 operator, C_PLPL, st_C_operator
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 bool, C_PLPL, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 long, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 short, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 int, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 char, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 float, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 double, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 signed, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 unsigned, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 auto, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 void, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 static, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 const, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 volatile, 0, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 explicit, C_PLPL, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 mutable, C_PLPL, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 typename, C_PLPL, st_C_typespec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 # DEFUN used in emacs, the next three used in glibc (SYSCALL only for mach).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 DEFUN, 0, st_C_gnumacro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 SYSCALL, 0, st_C_gnumacro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 ENTRY, 0, st_C_gnumacro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 PSEUDO, 0, st_C_gnumacro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 # These are defined inside C functions, so currently they are not met.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 # EXFUN used in glibc, DEFVAR_* in emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 #EXFUN, 0, st_C_gnumacro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 #DEFVAR_, 0, st_C_gnumacro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 %]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 and replace lines between %< and %> with its output. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 /*%<*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 /* C code produced by gperf version 2.7.1 (19981006 egcs) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 /* Command-line: gperf -c -k 1,3 -o -p -r -t */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 struct C_stab_entry { char *name; int c_ext; enum sym_type type; };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 #define TOTAL_KEYWORDS 46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 #define MIN_WORD_LENGTH 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 #define MAX_WORD_LENGTH 15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 #define MIN_HASH_VALUE 13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 #define MAX_HASH_VALUE 123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 /* maximum key range = 111, duplicates = 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 #ifdef __GNUC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 __inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 static unsigned int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 hash (str, len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 register const char *str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 register unsigned int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 static unsigned char asso_values[] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 124, 124, 124, 124, 3, 124, 124, 124, 43, 6,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 11, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 11, 124, 124, 58, 7, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 124, 124, 124, 124, 124, 124, 124, 57, 7, 42,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 4, 14, 52, 0, 124, 53, 124, 124, 29, 11,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 6, 35, 32, 124, 29, 34, 59, 58, 51, 24,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 124, 124, 124, 124, 124, 124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 register int hval = len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 switch (hval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 case 3:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 hval += asso_values[(unsigned char)str[2]];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 case 2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 case 1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 hval += asso_values[(unsigned char)str[0]];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 return hval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 #ifdef __GNUC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 __inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 static struct C_stab_entry *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 in_word_set (str, len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 register const char *str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 register unsigned int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 static struct C_stab_entry wordlist[] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 {""}, {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 {"@end", 0, st_C_objend},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 {""}, {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 {"ENTRY", 0, st_C_gnumacro},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 {"@interface", 0, st_C_objprot},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 {"domain", C_STAR, st_C_struct},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 {"PSEUDO", 0, st_C_gnumacro},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 {"namespace", C_PLPL, st_C_struct},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 {"@implementation",0, st_C_objimpl},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 {"long", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 {"signed", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 {"@protocol", 0, st_C_objprot},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 {""}, {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 {"bool", C_PLPL, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 {""}, {""}, {""}, {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 {"const", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 {"explicit", C_PLPL, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 {"if", 0, st_C_ignore},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 {"operator", C_PLPL, st_C_operator},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 {"DEFUN", 0, st_C_gnumacro},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 {"define", 0, st_C_define},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 {""}, {""}, {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 {"double", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 {"struct", 0, st_C_struct},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 {""}, {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 {"short", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 {"enum", 0, st_C_enum},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 {"mutable", C_PLPL, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 {"extern", 0, st_C_extern},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 {"extends", C_JAVA, st_C_javastruct},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 {"package", C_JAVA, st_C_ignore},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 {"while", 0, st_C_ignore},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 {"for", 0, st_C_ignore},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 {"volatile", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 {"import", C_JAVA, st_C_ignore},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 {"float", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 {"switch", 0, st_C_ignore},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 {"return", 0, st_C_ignore},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 {"implements", C_JAVA, st_C_javastruct},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 {"static", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 {"typedef", 0, st_C_typedef},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 {"typename", C_PLPL, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 {"unsigned", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 {"char", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 {"class", C_PLPL, st_C_struct},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 {"void", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 {"friend", C_PLPL, st_C_ignore},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 {"int", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 {"union", 0, st_C_struct},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 {""}, {""}, {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 {"auto", 0, st_C_typespec},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 {"interface", C_JAVA, st_C_struct},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 {""},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 {"SYSCALL", 0, st_C_gnumacro}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 register int key = hash (str, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 if (key <= MAX_HASH_VALUE && key >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 register const char *s = wordlist[key].name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 if (*str == *s && !strncmp (str + 1, s + 1, len - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 return &wordlist[key];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 /*%>*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 static enum sym_type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 C_symtype (str, len, c_ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 char *str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 int c_ext;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 register struct C_stab_entry *se = in_word_set (str, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118 if (se == NULL || (se->c_ext && !(c_ext & se->c_ext)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 return st_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 return se->type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 * C functions and variables are recognized using a simple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 * finite automaton. fvdef is its state variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 enum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 fvnone, /* nothing seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130 foperator, /* func: operator keyword seen (cplpl) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 fvnameseen, /* function or variable name seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 fstartlist, /* func: just after open parenthesis */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 finlist, /* func: in parameter list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 flistseen, /* func: after parameter list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 fignore, /* func: before open brace */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 vignore /* var-like: ignore until ';' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137 } fvdef;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 bool fvextern; /* func or var: extern keyword seen; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 * typedefs are recognized using a simple finite automaton.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 * typdef is its state variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 enum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 tnone, /* nothing seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 tkeyseen, /* typedef keyword seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 ttypeseen, /* defined type seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 tinbody, /* inside typedef body */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 tend, /* just before typedef tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 tignore /* junk after typedef tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 } typdef;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 * struct-like structures (enum, struct and union) are recognized
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 * using another simple finite automaton. `structdef' is its state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 * variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 enum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 snone, /* nothing seen yet */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 skeyseen, /* struct-like keyword seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 stagseen, /* struct-like tag seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 scolonseen, /* colon seen after struct-like tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 sinbody /* in struct body: recognize member func defs*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 } structdef;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 * When structdef is stagseen, scolonseen, or sinbody, structtag is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 * struct tag, and structtype is the type of the preceding struct-like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 * keyword.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 char *structtag = "<uninited>";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 enum sym_type structtype;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 * When objdef is different from onone, objtag is the name of the class.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 char *objtag = "<uninited>";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 * Yet another little state machine to deal with preprocessor lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 enum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 dnone, /* nothing seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 dsharpseen, /* '#' seen as first char on line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 ddefineseen, /* '#' and 'define' seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 dignorerest /* ignore rest of line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 } definedef;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 * State machine for Objective C protocols and implementations.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 * Tom R.Hageman <tom@basil.icce.rug.nl>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 enum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 onone, /* nothing seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 oprotocol, /* @interface or @protocol seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 oimplementation, /* @implementations seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 otagseen, /* class name seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 oparenseen, /* parenthesis before category seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 ocatseen, /* category name seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 oinbody, /* in @implementation body */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 omethodsign, /* in @implementation body, after +/- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 omethodtag, /* after method name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 omethodcolon, /* after method colon */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 omethodparm, /* after method parameter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 oignore /* wait for @end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 } objdef;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 * Use this structure to keep info about the token read, and how it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 * should be tagged. Used by the make_C_tag function to build a tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 bool valid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 char *str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 bool named;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 int linelen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 int lineno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 long linepos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 char *buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 } token;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 token tok; /* latest token read */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 * Set this to TRUE, and the next token considered is called a function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 * Used only for GNU emacs's function-defining macros.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 bool next_token_is_func;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 * TRUE in the rules part of a yacc file, FALSE outside (parse as C).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 bool yacc_rules;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 * methodlen is the length of the method name stored in token_name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 int methodlen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 * consider_token ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 * checks to see if the current token is at the start of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 * function or variable, or corresponds to a typedef, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 * is a struct/union/enum tag, or #define, or an enum constant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 * *IS_FUNC gets TRUE iff the token is a function or #define macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 * with args. C_EXT is which language we are looking at.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 * Globals
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 * fvdef IN OUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 * structdef IN OUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 * definedef IN OUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 * typdef IN OUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 * objdef IN OUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 * next_token_is_func IN OUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 static bool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 consider_token (str, len, c, c_ext, cblev, parlev, is_func_or_var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 register char *str; /* IN: token pointer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 register int len; /* IN: token length */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 register char c; /* IN: first char after the token */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 int c_ext; /* IN: C extensions mask */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 int cblev; /* IN: curly brace level */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 int parlev; /* IN: parenthesis level */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 bool *is_func_or_var; /* OUT: function or variable found */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 enum sym_type toktype = C_symtype (str, len, c_ext);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 * Advance the definedef state machine.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 switch (definedef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 case dnone:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 /* We're not on a preprocessor line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 case dsharpseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 if (toktype == st_C_define)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 definedef = ddefineseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 definedef = dignorerest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 case ddefineseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 * Make a tag for any macro, unless it is a constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 * and constantypedefs is FALSE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 definedef = dignorerest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 *is_func_or_var = (c == '(');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 if (!*is_func_or_var && !constantypedefs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 case dignorerest:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 error ("internal error: definedef value.", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 * Now typedefs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 switch (typdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 case tnone:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 if (toktype == st_C_typedef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 if (typedefs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 typdef = tkeyseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 fvextern = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 case tkeyseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 switch (toktype)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 case st_none:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 case st_C_typespec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 case st_C_struct:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 case st_C_enum:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 typdef = ttypeseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 /* Do not return here, so the structdef stuff has a chance. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 case tend:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 switch (toktype)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 case st_C_typespec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 case st_C_struct:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 case st_C_enum:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 * This structdef business is currently only invoked when cblev==0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 * It should be recursively invoked whatever the curly brace level,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 * and a stack of states kept, to allow for definitions of structs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 * within structs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 * This structdef business is NOT invoked when we are ctags and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 * file is plain C. This is because a struct tag may have the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 * name as another tag, and this loses with ctags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 switch (toktype)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 case st_C_javastruct:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 if (structdef == stagseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 structdef = scolonseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 case st_C_struct:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 case st_C_enum:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 if (typdef == tkeyseen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 || (typedefs_and_cplusplus && cblev == 0 && structdef == snone))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 structdef = skeyseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 structtype = toktype;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 if (structdef == skeyseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 /* Save the tag for struct/union/class, for functions and variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 that may be defined inside. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 if (structtype == st_C_struct)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 structtag = savenstr (str, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 structtag = "<enum>";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 structdef = stagseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 if (typdef != tnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 definedef = dnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 /* Detect GNU macros.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 Writers of emacs code are recommended to put the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 first two args of a DEFUN on the same line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 The DEFUN macro, used in emacs C source code, has a first arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 that is a string (the lisp function name), and a second arg that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 is a C function name. Since etags skips strings, the second arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 is tagged. This is unfortunate, as it would be better to tag the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 first arg. The simplest way to deal with this problem would be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 to name the tag with a name built from the function name, by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 removing the initial 'F' character and substituting '-' for '_'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 Anyway, this assumes that the conventions of naming lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 functions will never change. Currently, this method is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 implemented. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 if (definedef == dnone && toktype == st_C_gnumacro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 next_token_is_func = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 if (next_token_is_func)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 next_token_is_func = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 fvdef = fignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 *is_func_or_var = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 /* Detect Objective C constructs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 switch (objdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 case onone:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 switch (toktype)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 case st_C_objprot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 objdef = oprotocol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 case st_C_objimpl:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 objdef = oimplementation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 case oimplementation:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 /* Save the class tag for functions or variables defined inside. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 objtag = savenstr (str, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 objdef = oinbody;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 case oprotocol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 /* Save the class tag for categories. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 objtag = savenstr (str, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 objdef = otagseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 *is_func_or_var = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 case oparenseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 objdef = ocatseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 *is_func_or_var = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 case oinbody:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 case omethodsign:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 if (parlev == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 objdef = omethodtag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 methodlen = len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 grow_linebuffer (&token_name, methodlen + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 strncpy (token_name.buffer, str, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 token_name.buffer[methodlen] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 token_name.len = methodlen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 case omethodcolon:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 if (parlev == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 objdef = omethodparm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 case omethodparm:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 if (parlev == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 objdef = omethodtag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 methodlen += len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 grow_linebuffer (&token_name, methodlen + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 strncat (token_name.buffer, str, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 token_name.len = methodlen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 case oignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 if (toktype == st_C_objend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 /* Memory leakage here: the string pointed by objtag is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 never released, because many tests would be needed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 avoid breaking on incorrect input code. The amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 memory leaked here is the sum of the lengths of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 class tags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 free (objtag); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 objdef = onone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 /* A function, variable or enum constant? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 switch (toktype)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 case st_C_extern:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 fvextern = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 case st_C_typespec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 if (fvdef != finlist && fvdef != fignore && fvdef != vignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 fvdef = fvnone; /* should be useless */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 case st_C_ignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 fvextern = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 fvdef = vignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 case st_C_operator:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 fvdef = foperator;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 *is_func_or_var = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 case st_none:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 if ((c_ext & C_PLPL) && strneq (str+len-10, "::operator", 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 fvdef = foperator;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 *is_func_or_var = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 if (constantypedefs && structdef == sinbody && structtype == st_C_enum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 if (fvdef == fvnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 fvdef = fvnameseen; /* function or variable */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 *is_func_or_var = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 * C_entries ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 * This routine finds functions, variables, typedefs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 * #define's, enum constants and struct/union/enum definitions in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 * C syntax and adds them to the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 #define current_lb_is_new (newndx == curndx)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 #define switch_line_buffers() (curndx = 1 - curndx)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 #define curlb (lbs[curndx].lb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 #define othlb (lbs[1-curndx].lb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 #define newlb (lbs[newndx].lb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 #define curlinepos (lbs[curndx].linepos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 #define othlinepos (lbs[1-curndx].linepos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 #define newlinepos (lbs[newndx].linepos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 #define CNL_SAVE_DEFINEDEF() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 curlinepos = charno; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 lineno++; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 linecharno = charno; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 charno += readline (&curlb, inf); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 lp = curlb.buffer; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 quotednl = FALSE; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 newndx = curndx; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 #define CNL() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 CNL_SAVE_DEFINEDEF(); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 if (savetok.valid) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 tok = savetok; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 savetok.valid = FALSE; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 definedef = dnone; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 make_C_tag (isfun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 bool isfun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 /* This function should never be called when tok.valid is FALSE, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 we must protect against invalid input or internal errors. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 if (tok.valid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 if (traditional_tag_style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 /* This was the original code. Now we call new_pfnote instead,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 which uses the new method for naming tags (see new_pfnote). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 char *name = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 if (CTAGS || tok.named)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 name = savestr (token_name.buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 pfnote (name, isfun,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 tok.buffer, tok.linelen, tok.lineno, tok.linepos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 new_pfnote (token_name.buffer, token_name.len, isfun,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 tok.buffer, tok.linelen, tok.lineno, tok.linepos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 tok.valid = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 else if (DEBUG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 C_entries (c_ext, inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 int c_ext; /* extension of C */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 FILE *inf; /* input file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 register char c; /* latest char read; '\0' for end of line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 register char *lp; /* pointer one beyond the character `c' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 int curndx, newndx; /* indices for current and new lb */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 register int tokoff; /* offset in line of start of current token */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 register int toklen; /* length of current token */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 char *qualifier; /* string used to qualify names */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 int qlen; /* length of qualifier */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 int cblev; /* current curly brace level */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 int parlev; /* current parenthesis level */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 bool incomm, inquote, inchar, quotednl, midtoken;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 bool purec, cplpl, cjava;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 token savetok; /* token saved during preprocessor handling */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 tokoff = toklen = 0; /* keep compiler quiet */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 curndx = newndx = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 lineno = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 charno = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 lp = curlb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 *lp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 fvdef = fvnone; fvextern = FALSE; typdef = tnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 structdef = snone; definedef = dnone; objdef = onone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 next_token_is_func = yacc_rules = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 midtoken = inquote = inchar = incomm = quotednl = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 tok.valid = savetok.valid = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 cblev = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 parlev = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 purec = !(c_ext & ~YACC); /* no extensions (apart from possibly yacc) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 cplpl = (c_ext & C_PLPL) == C_PLPL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 cjava = (c_ext & C_JAVA) == C_JAVA;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 if (cjava)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 { qualifier = "."; qlen = 1; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 { qualifier = "::"; qlen = 2; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 while (!feof (inf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 c = *lp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 if (c == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 /* If we're at the end of the line, the next character is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 '\0'; don't skip it, because it's the thing that tells us
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 to read the next line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 if (*lp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 quotednl = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 lp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 c = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 else if (incomm)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 case '*':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 if (*lp == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 c = *lp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 incomm = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 case '\0':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 /* Newlines inside comments do not end macro definitions in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 traditional cpp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 CNL_SAVE_DEFINEDEF ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 else if (inquote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 case '"':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 inquote = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 case '\0':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 /* Newlines inside strings do not end macro definitions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 in traditional cpp, even though compilers don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 usually accept them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 CNL_SAVE_DEFINEDEF ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 else if (inchar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 case '\0':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 /* Hmmm, something went wrong. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 CNL ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 case '\'':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 inchar = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 case '"':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 inquote = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 if (fvdef != finlist && fvdef != fignore && fvdef !=vignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 fvextern = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 case '\'':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 inchar = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 if (fvdef != finlist && fvdef != fignore && fvdef !=vignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 fvextern = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 case '/':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 if (*lp == '*')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 lp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 incomm = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 else if (/* cplpl && */ *lp == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 c = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 case '%':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 if ((c_ext & YACC) && *lp == '%')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 /* entering or exiting rules section in yacc file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 lp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 definedef = dnone; fvdef = fvnone; fvextern = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 typdef = tnone; structdef = snone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 next_token_is_func = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 midtoken = inquote = inchar = incomm = quotednl = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 cblev = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 yacc_rules = !yacc_rules;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 case '#':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 if (definedef == dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 bool cpptoken = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 /* Look back on this line. If all blanks, or nonblanks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 followed by an end of comment, this is a preprocessor
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 token. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 for (cp = newlb.buffer; cp < lp-1; cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 if (!iswhite (*cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 if (*cp == '*' && *(cp+1) == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 cpptoken = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 cpptoken = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 if (cpptoken)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 definedef = dsharpseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 } /* if (definedef == dnone) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 } /* switch (c) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 /* Consider token only if some complicated conditions are satisfied. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 if ((definedef != dnone
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 || (cblev == 0 && structdef != scolonseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 || (cblev == 1 && cplpl && structdef == sinbody)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 || (structdef == sinbody && purec))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 && typdef != tignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 && definedef != dignorerest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 && fvdef != finlist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 if (midtoken)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 if (endtoken (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 bool funorvar = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 if (c == ':' && cplpl && *lp == ':' && begtoken (lp[1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 * This handles :: in the middle, but not at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 * beginning of an identifier. Also, space-separated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 * :: is not recognised.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 lp += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 toklen += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 c = lp[-1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 goto intok;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 if (yacc_rules
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 || consider_token (newlb.buffer + tokoff, toklen, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 c_ext, cblev, parlev, &funorvar))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 if (fvdef == foperator)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 char *oldlp = lp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 lp = skip_spaces (lp-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 if (*lp != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 lp += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 while (*lp != '\0'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 && !isspace (*lp) && *lp != '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 lp += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 c = *lp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 toklen += lp - oldlp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 tok.named = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 if (!purec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 && funorvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 && definedef == dnone
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 && structdef == sinbody)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 /* function or var defined in C++ class body */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 int len = strlen (structtag) + qlen + toklen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 grow_linebuffer (&token_name, len + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 strcpy (token_name.buffer, structtag);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 strcat (token_name.buffer, qualifier);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 strncat (token_name.buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 newlb.buffer + tokoff, toklen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 token_name.len = len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 tok.named = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 else if (objdef == ocatseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 /* Objective C category */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 int len = strlen (objtag) + 2 + toklen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 grow_linebuffer (&token_name, len + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 strcpy (token_name.buffer, objtag);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 strcat (token_name.buffer, "(");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 strncat (token_name.buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 newlb.buffer + tokoff, toklen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 strcat (token_name.buffer, ")");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 token_name.len = len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 tok.named = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 else if (objdef == omethodtag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 || objdef == omethodparm)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 /* Objective C method */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 tok.named = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 grow_linebuffer (&token_name, toklen + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 strncpy (token_name.buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 newlb.buffer + tokoff, toklen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 token_name.buffer[toklen] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 token_name.len = toklen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 /* Name macros and members. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 tok.named = (structdef == stagseen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 || typdef == ttypeseen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 || typdef == tend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 || (funorvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 && definedef == dignorerest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 || (funorvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 && definedef == dnone
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 && structdef == sinbody));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 tok.lineno = lineno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 tok.linelen = tokoff + toklen + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 tok.buffer = newlb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 tok.linepos = newlinepos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 tok.valid = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 if (definedef == dnone
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 && (fvdef == fvnameseen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 || fvdef == foperator
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 || structdef == stagseen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 || typdef == tend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 || objdef != onone))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 if (current_lb_is_new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 switch_line_buffers ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 make_C_tag (funorvar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 midtoken = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 } /* if (endtoken (c)) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 else if (intoken (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 intok:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 toklen++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 } /* if (midtoken) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 else if (begtoken (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 switch (definedef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 case dnone:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 case fstartlist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 fvdef = finlist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 case flistseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 make_C_tag (TRUE); /* a function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 fvdef = fignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 case fvnameseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 if (structdef == stagseen && !cjava)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 structdef = snone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 case dsharpseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 savetok = tok;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 if (!yacc_rules || lp == newlb.buffer + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 tokoff = lp - 1 - newlb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 toklen = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 midtoken = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 } /* if (begtoken) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 } /* if must look at token */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 /* Detect end of line, colon, comma, semicolon and various braces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 after having handled a token.*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 case ':':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 switch (objdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 case otagseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 objdef = oignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 make_C_tag (TRUE); /* an Objective C class */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 case omethodtag:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 case omethodparm:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 objdef = omethodcolon;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 methodlen += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 grow_linebuffer (&token_name, methodlen + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 strcat (token_name.buffer, ":");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 token_name.len = methodlen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 if (structdef == stagseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 structdef = scolonseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 case fvnameseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 if (yacc_rules)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 make_C_tag (FALSE); /* a yacc function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 fvdef = fignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 case fstartlist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 fvextern = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 case ';':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 if (cblev == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 switch (typdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 case tend:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 make_C_tag (FALSE); /* a typedef */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 typdef = tnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 case fignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 case fvnameseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 if ((members && cblev == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 || (globals && cblev == 0 && (!fvextern || declarations)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 make_C_tag (FALSE); /* a variable */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 fvextern = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 tok.valid = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 case flistseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 if (declarations && (cblev == 0 || cblev == 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 make_C_tag (TRUE); /* a function declaration */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 fvextern = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 /* The following instruction invalidates the token.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 Probably the token should be invalidated in all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 other cases where some state machine is reset. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 tok.valid = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 if (structdef == stagseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 structdef = snone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 case ',':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 switch (objdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 case omethodtag:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 case omethodparm:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 make_C_tag (TRUE); /* an Objective C method */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 objdef = oinbody;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 case foperator:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 case finlist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 case fignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 case vignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040 case fvnameseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 if ((members && cblev == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 || (globals && cblev == 0 && (!fvextern || declarations)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 make_C_tag (FALSE); /* a variable */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 if (structdef == stagseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 structdef = snone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 case '[':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 if (cblev == 0 && typdef == tend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 typdef = tignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 make_C_tag (FALSE); /* a typedef */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 case foperator:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 case finlist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 case fignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 case vignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 case fvnameseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 if ((members && cblev == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 || (globals && cblev == 0 && (!fvextern || declarations)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 make_C_tag (FALSE); /* a variable */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 if (structdef == stagseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 structdef = snone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 case '(':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 if (objdef == otagseen && parlev == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 objdef = oparenseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 case fvnameseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 if (typdef == ttypeseen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087 && tok.valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 && *lp != '*'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 && structdef != sinbody)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 /* This handles constructs like:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 typedef void OperatorFun (int fun); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 make_C_tag (FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 typdef = tignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 case foperator:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 fvdef = fstartlist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 case flistseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 fvdef = finlist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104 parlev++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 case ')':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 if (objdef == ocatseen && parlev == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 make_C_tag (TRUE); /* an Objective C category */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 objdef = oignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 if (--parlev == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 case fstartlist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 case finlist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 fvdef = flistseen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 if (cblev == 0 && (typdef == tend))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 typdef = tignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 make_C_tag (FALSE); /* a typedef */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 else if (parlev < 0) /* can happen due to ill-conceived #if's. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 parlev = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 case '{':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 if (typdef == ttypeseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 typdef = tinbody;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 switch (structdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 case skeyseen: /* unnamed struct */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 structdef = sinbody;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 structtag = "_anonymous_";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 case stagseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 case scolonseen: /* named struct */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 structdef = sinbody;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 make_C_tag (FALSE); /* a struct */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 case flistseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 make_C_tag (TRUE); /* a function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 case fignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 case fvnone:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158 switch (objdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160 case otagseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 make_C_tag (TRUE); /* an Objective C class */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 objdef = oignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 case omethodtag:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165 case omethodparm:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 make_C_tag (TRUE); /* an Objective C method */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 objdef = oinbody;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 /* Neutralize `extern "C" {' grot. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171 if (cblev == 0 && structdef == snone && typdef == tnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 cblev = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 cblev++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 case '*':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180 if (fvdef == fstartlist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 fvdef = fvnone; /* avoid tagging `foo' in `foo (*bar()) ()' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 case '}':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 if (!noindentypedefs && lp == newlb.buffer + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 cblev = 0; /* reset curly brace level if first column */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 parlev = 0; /* also reset paren level, just in case... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 else if (cblev > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 cblev--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 if (cblev == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 if (typdef == tinbody)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 typdef = tend;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 /* Memory leakage here: the string pointed by structtag is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 never released, because I fear to miss something and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 break things while freeing the area. The amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 memory leaked here is the sum of the lengths of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 struct tags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 if (structdef == sinbody)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 free (structtag); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 structdef = snone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206 structtag = "<error>";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 case '=':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 case foperator:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 case finlist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 case fignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 case vignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 case fvnameseen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 if ((members && cblev == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 || (globals && cblev == 0 && (!fvextern || declarations)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 make_C_tag (FALSE); /* a variable */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 fvdef = vignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 case '+':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 case '-':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 if (objdef == oinbody && cblev == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 objdef = omethodsign;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 case '#': case '~': case '&': case '%': case '/': case '|':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 case '^': case '!': case '<': case '>': case '.': case '?': case ']':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 if (definedef != dnone)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 /* These surely cannot follow a function tag in C. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 switch (fvdef)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 case foperator:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 case finlist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 case fignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 case vignore:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 fvdef = fvnone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 case '\0':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 if (objdef == otagseen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 make_C_tag (TRUE); /* an Objective C class */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 objdef = oignore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 /* If a macro spans multiple lines don't reset its state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 if (quotednl)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 CNL_SAVE_DEFINEDEF ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 CNL ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 } /* switch (c) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 } /* while not eof */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 * Process either a C++ file or a C file depending on the setting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 * of a global flag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 default_C_entries (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 C_entries (cplusplus ? C_PLPL : 0, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 /* Always do plain ANSI C. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 plain_C_entries (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 C_entries (0, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 /* Always do C++. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 Cplusplus_entries (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 C_entries (C_PLPL, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 /* Always do Java. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 Cjava_entries (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 C_entries (C_JAVA, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304 /* Always do C*. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 Cstar_entries (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 C_entries (C_STAR, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 /* Always do Yacc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 Yacc_entries (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 C_entries (YACC, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 /* A useful macro. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 #define LOOP_ON_INPUT_LINES(file_pointer, line_buffer, char_pointer) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 for (lineno = charno = 0; /* loop initialization */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 !feof (file_pointer) /* loop test */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 && (lineno++, /* instructions at start of loop */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 linecharno = charno, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 charno += readline (&line_buffer, file_pointer), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 char_pointer = lb.buffer, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 TRUE); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 * Read a file, but do no processing. This is used to do regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 * matching on files that have no language defined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 just_read_file (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 register char *dummy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 LOOP_ON_INPUT_LINES (inf, lb, dummy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 /* Fortran parsing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 static bool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 tail (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 register int len = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 while (*cp != '\0' && lowcase (*cp) == lowcase (dbp[len]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 cp++, len++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 if (*cp == '\0' && !intoken (dbp[len]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 dbp += len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 takeprec ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 if (*dbp != '*')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 if (strneq (dbp, "(*)", 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 dbp += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 if (!isdigit (*dbp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 --dbp; /* force failure */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 while (isdigit (*dbp));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 getit (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 if (*dbp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 lineno++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 linecharno = charno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 charno += readline (&lb, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 dbp = lb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 if (dbp[5] != '&')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 dbp += 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 if (!isalpha (*dbp) && *dbp != '_' && *dbp != '$')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 for (cp = dbp + 1; *cp != '\0' && intoken (*cp); cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 pfnote (savenstr (dbp, cp-dbp), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 Fortran_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 LOOP_ON_INPUT_LINES (inf, lb, dbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 if (*dbp == '%')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 dbp++; /* Ratfor escape to fortran */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 if (*dbp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 switch (lowcase (*dbp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 case 'i':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 if (tail ("integer"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 takeprec ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 case 'r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 if (tail ("real"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 takeprec ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 case 'l':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 if (tail ("logical"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 takeprec ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 case 'c':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 if (tail ("complex") || tail ("character"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 takeprec ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 case 'd':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 if (tail ("double"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 if (*dbp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449 if (tail ("precision"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 if (*dbp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 switch (lowcase (*dbp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 case 'f':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 if (tail ("function"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 getit (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 case 's':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465 if (tail ("subroutine"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 getit (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 case 'e':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 if (tail ("entry"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 getit (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 case 'b':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 if (tail ("blockdata") || tail ("block data"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 if (*dbp == '\0') /* assume un-named */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 pfnote (savestr ("blockdata"), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 lb.buffer, dbp - lb.buffer, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 getit (inf); /* look for name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 * Philippe Waroquiers <philippe.waroquiers@eurocontrol.be>, 1998-04-24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489 * Ada parsing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 /* Once we are positioned after an "interesting" keyword, let's get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 the real tag value necessary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 adagetit (inf, name_qualifier)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 char *name_qualifier;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 char *name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 while (!feof (inf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 if (*dbp == '\0'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 || (dbp[0] == '-' && dbp[1] == '-'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 lineno++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 linecharno = charno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 charno += readline (&lb, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 dbp = lb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 switch (*dbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 case 'b':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 case 'B':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 if (tail ("body"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 /* Skipping body of procedure body or package body or ....
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 resetting qualifier to body instead of spec. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 name_qualifier = "/b";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 case 't':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 case 'T':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 /* Skipping type of task type or protected type ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 if (tail ("type"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 if (*dbp == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 dbp += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 for (cp = dbp; *cp != '\0' && *cp != '"'; cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 for (cp = dbp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 (*cp != '\0'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 && (isalpha (*cp) || isdigit (*cp) || *cp == '_' || *cp == '.'));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 if (cp == dbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 c = *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 *cp = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 name = concat (dbp, name_qualifier, "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552 *cp = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 pfnote (name, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 if (c == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 dbp = cp + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 Ada_funcs (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 bool inquote = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566 LOOP_ON_INPUT_LINES (inf, lb, dbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 while (*dbp != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 /* Skip a string i.e. "abcd". */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 if (inquote || (*dbp == '"'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 dbp = etags_strchr ((inquote) ? dbp : dbp+1, '"');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 if (dbp != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 inquote = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 dbp += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 continue; /* advance char */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 inquote = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 break; /* advance line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 /* Skip comments. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 if (dbp[0] == '-' && dbp[1] == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 break; /* advance line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 /* Skip character enclosed in single quote i.e. 'a'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 and skip single quote starting an attribute i.e. 'Image. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 if (*dbp == '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 dbp++ ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 if (*dbp != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 /* Search for beginning of a token. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 if (!begtoken (*dbp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 continue; /* advance char */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 /* We are at the beginning of a token. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 switch (*dbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 case 'f':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 case 'F':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 if (!packages_only && tail ("function"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 adagetit (inf, "/f");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 break; /* from switch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 continue; /* advance char */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 case 'p':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 case 'P':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 if (!packages_only && tail ("procedure"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 adagetit (inf, "/p");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 else if (tail ("package"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 adagetit (inf, "/s");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 else if (tail ("protected")) /* protected type */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 adagetit (inf, "/t");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 break; /* from switch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 continue; /* advance char */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 case 't':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 case 'T':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 if (!packages_only && tail ("task"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 adagetit (inf, "/k");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633 else if (typedefs && !packages_only && tail ("type"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 adagetit (inf, "/t");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636 while (*dbp != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637 dbp += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3638 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 break; /* from switch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 continue; /* advance char */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 /* Look for the end of the token. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 while (!endtoken (*dbp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648 } /* advance char */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 } /* advance line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 * Bob Weiner, Motorola Inc., 4/3/94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654 * Unix and microcontroller assembly tag handling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 * look for '^[a-zA-Z_.$][a-zA_Z0-9_.$]*[: ^I^J]'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3657 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658 Asm_labels (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3660 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663 LOOP_ON_INPUT_LINES (inf, lb, cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3664 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 /* If first char is alphabetic or one of [_.$], test for colon
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 following identifier. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667 if (isalpha (*cp) || *cp == '_' || *cp == '.' || *cp == '$')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669 /* Read past label. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 while (isalnum (*cp) || *cp == '_' || *cp == '.' || *cp == '$')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673 if (*cp == ':' || isspace (*cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 /* Found end of label, so copy it and add it to the table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3676 pfnote (savenstr(lb.buffer, cp-lb.buffer), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 * Perl support by Bart Robinson <lomew@cs.utah.edu>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685 * enhanced by Michael Ernst <mernst@alum.mit.edu>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 * Perl sub names: look for /^sub[ \t\n]+[^ \t\n{]+/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 * Perl variable names: /^(my|local).../
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 Perl_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3695 LOOP_ON_INPUT_LINES (inf, lb, cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 if (*cp++ == 's'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 && *cp++ == 'u'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699 && *cp++ == 'b' && isspace (*cp++))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 cp = skip_spaces (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3702 if (*cp != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704 char *sp = cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705 while (*cp != '\0'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 && !isspace (*cp) && *cp != '{' && *cp != '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3707 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708 pfnote (savenstr (sp, cp-sp), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3709 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712 else if (globals /* only if tagging global vars is enabled */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 && ((cp = lb.buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 *cp++ == 'm'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715 && *cp++ == 'y')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 || (cp = lb.buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717 *cp++ == 'l'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 && *cp++ == 'o'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 && *cp++ == 'c'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 && *cp++ == 'a'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 && *cp++ == 'l'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 && (*cp == '(' || isspace (*cp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724 /* After "my" or "local", but before any following paren or space. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 char *varname = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 cp = skip_spaces (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 if (*cp == '$' || *cp == '@' || *cp == '%')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730 char* varstart = ++cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 while (isalnum (*cp) || *cp == '_')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733 varname = savenstr (varstart, cp-varstart);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 /* Should be examining a variable list at this point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738 could insist on seeing an open parenthesis. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 while (*cp != '\0' && *cp != ';' && *cp != '=' && *cp != ')')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743 /* Perhaps I should back cp up one character, so the TAGS table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3744 doesn't mention (and so depend upon) the following char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745 pfnote ((CTAGS) ? savenstr (lb.buffer, cp-lb.buffer) : varname,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746 FALSE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3747 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3749 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3751 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3752 * Python support by Eric S. Raymond <esr@thyrsus.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3753 * Look for /^def[ \t\n]+[^ \t\n(:]+/ or /^class[ \t\n]+[^ \t\n(:]+/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3754 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3755 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3756 Python_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3757 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3758 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3759 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3761 LOOP_ON_INPUT_LINES (inf, lb, cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3763 if (*cp++ == 'd'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3764 && *cp++ == 'e'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3765 && *cp++ == 'f' && isspace (*cp++))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3766 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3767 cp = skip_spaces (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3768 while (*cp != '\0' && !isspace (*cp) && *cp != '(' && *cp != ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3769 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3770 pfnote (NULL, TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3771 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3772 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3774 cp = lb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3775 if (*cp++ == 'c'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3776 && *cp++ == 'l'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3777 && *cp++ == 'a'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3778 && *cp++ == 's'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779 && *cp++ == 's' && isspace (*cp++))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3780 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3781 cp = skip_spaces (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3782 while (*cp != '\0' && !isspace (*cp) && *cp != '(' && *cp != ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 pfnote (NULL, TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3785 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 /* Idea by Corny de Souza
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 * Cobol tag functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 * We could look for anything that could be a paragraph name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 * i.e. anything that starts in column 8 is one word and ends in a full stop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 Cobol_paragraphs (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 register char *bp, *ep;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801 LOOP_ON_INPUT_LINES (inf, lb, bp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3803 if (lb.len < 9)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3805 bp += 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807 /* If eoln, compiler option or comment ignore whole line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808 if (bp[-1] != ' ' || !isalnum (bp[0]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3809 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811 for (ep = bp; isalnum (*ep) || *ep == '-'; ep++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813 if (*ep++ == '.')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814 pfnote (savenstr (bp, ep-bp), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 lb.buffer, ep - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3816 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3817 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3819 /* Added by Mosur Mohan, 4/22/88 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3820 /* Pascal parsing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3822 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3823 * Locates tags for procedures & functions. Doesn't do any type- or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3824 * var-definitions. It does look for the keyword "extern" or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3825 * "forward" immediately following the procedure statement; if found,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3826 * the tag is skipped.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3827 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3828 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3829 Pascal_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3830 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3831 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3832 linebuffer tline; /* mostly copied from C_entries */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3833 long save_lcno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3834 int save_lineno, save_len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3835 char c, *cp, *namebuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 bool /* each of these flags is TRUE iff: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3838 incomment, /* point is inside a comment */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3839 inquote, /* point is inside '..' string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3840 get_tagname, /* point is after PROCEDURE/FUNCTION
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3841 keyword, so next item = potential tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3842 found_tag, /* point is after a potential tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3843 inparms, /* point is within parameter-list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3844 verify_tag; /* point has passed the parm-list, so the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3845 next token will determine whether this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3846 is a FORWARD/EXTERN to be ignored, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3847 whether it is a real tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3849 save_lcno = save_lineno = save_len = 0; /* keep compiler quiet */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3850 namebuf = NULL; /* keep compiler quiet */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3851 lineno = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3852 charno = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3853 dbp = lb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3854 *dbp = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3855 initbuffer (&tline);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3857 incomment = inquote = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858 found_tag = FALSE; /* have a proc name; check if extern */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859 get_tagname = FALSE; /* have found "procedure" keyword */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860 inparms = FALSE; /* found '(' after "proc" */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3861 verify_tag = FALSE; /* check if "extern" is ahead */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3864 while (!feof (inf)) /* long main loop to get next char */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3865 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3866 c = *dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3867 if (c == '\0') /* if end of line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3868 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3869 lineno++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3870 linecharno = charno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3871 charno += readline (&lb, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3872 dbp = lb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3873 if (*dbp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3874 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3875 if (!((found_tag && verify_tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3876 || get_tagname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3877 c = *dbp++; /* only if don't need *dbp pointing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3878 to the beginning of the name of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3879 the procedure or function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3880 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3881 if (incomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3882 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3883 if (c == '}') /* within { } comments */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3884 incomment = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3885 else if (c == '*' && *dbp == ')') /* within (* *) comments */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3886 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3887 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3888 incomment = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3889 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3890 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3891 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3892 else if (inquote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3893 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3894 if (c == '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3895 inquote = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3896 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3897 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3898 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3899 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3900 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3901 case '\'':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902 inquote = TRUE; /* found first quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3904 case '{': /* found open { comment */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3905 incomment = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3906 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3907 case '(':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 if (*dbp == '*') /* found open (* comment */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3909 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3910 incomment = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913 else if (found_tag) /* found '(' after tag, i.e., parm-list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3914 inparms = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3915 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3916 case ')': /* end of parms list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3917 if (inparms)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3918 inparms = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3919 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3920 case ';':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3921 if (found_tag && !inparms) /* end of proc or fn stmt */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3922 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3923 verify_tag = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3924 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3925 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3926 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3927 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3928 if (found_tag && verify_tag && (*dbp != ' '))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3929 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3930 /* check if this is an "extern" declaration */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 if (*dbp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3933 if (lowcase (*dbp == 'e'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3935 if (tail ("extern")) /* superfluous, really! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937 found_tag = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3938 verify_tag = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3939 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3940 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3941 else if (lowcase (*dbp) == 'f')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3942 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3943 if (tail ("forward")) /* check for forward reference */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3944 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3945 found_tag = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3946 verify_tag = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3947 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3948 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3949 if (found_tag && verify_tag) /* not external proc, so make tag */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3950 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3951 found_tag = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3952 verify_tag = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3953 pfnote (namebuf, TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3954 tline.buffer, save_len, save_lineno, save_lcno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3955 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3956 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3957 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3958 if (get_tagname) /* grab name of proc or fn */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3959 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3960 if (*dbp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3961 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3963 /* save all values for later tagging */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3964 grow_linebuffer (&tline, lb.len + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3965 strcpy (tline.buffer, lb.buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3966 save_lineno = lineno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3967 save_lcno = linecharno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3969 /* grab block name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 for (cp = dbp + 1; *cp != '\0' && !endtoken (*cp); cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972 namebuf = savenstr (dbp, cp-dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 dbp = cp; /* set dbp to e-o-token */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974 save_len = dbp - lb.buffer + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 get_tagname = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976 found_tag = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3977 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979 /* and proceed to check for "extern" */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3980 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3981 else if (!incomment && !inquote && !found_tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3982 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3983 /* check for proc/fn keywords */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3984 switch (lowcase (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3985 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986 case 'p':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987 if (tail ("rocedure")) /* c = 'p', dbp has advanced */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3988 get_tagname = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3989 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3990 case 'f':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3991 if (tail ("unction"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3992 get_tagname = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3995 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3996 } /* while not eof */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3998 free (tline.buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3999 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4001 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4002 * lisp tag functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4003 * look for (def or (DEF, quote or QUOTE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4004 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4005 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006 L_isdef (strp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 register char *strp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4008 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4009 return ((strp[1] == 'd' || strp[1] == 'D')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4010 && (strp[2] == 'e' || strp[2] == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4011 && (strp[3] == 'f' || strp[3] == 'F'));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4014 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 L_isquote (strp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4016 register char *strp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4018 return ((*++strp == 'q' || *strp == 'Q')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 && (*++strp == 'u' || *strp == 'U')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4020 && (*++strp == 'o' || *strp == 'O')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021 && (*++strp == 't' || *strp == 'T')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4022 && (*++strp == 'e' || *strp == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023 && isspace (*++strp));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4024 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4026 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027 L_getit ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4029 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4031 if (*dbp == '\'') /* Skip prefix quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4032 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033 else if (*dbp == '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035 if (L_isquote (dbp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4036 dbp += 7; /* Skip "(quote " */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 dbp += 1; /* Skip "(" before name in (defstruct (foo)) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4040 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042 for (cp = dbp /*+1*/;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4043 *cp != '\0' && *cp != '(' && !isspace(*cp) && *cp != ')';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4044 cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4045 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4046 if (cp == dbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4047 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4049 pfnote (savenstr (dbp, cp-dbp), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4050 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4051 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4053 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4054 Lisp_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4055 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4056 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4057 LOOP_ON_INPUT_LINES (inf, lb, dbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4059 if (dbp[0] == '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4060 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4061 if (L_isdef (dbp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4062 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4063 dbp = skip_non_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4064 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4065 L_getit ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4066 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4067 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4068 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4069 /* Check for (foo::defmumble name-defined ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4070 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4071 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4072 while (*dbp != '\0' && !isspace (*dbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4073 && *dbp != ':' && *dbp != '(' && *dbp != ')');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4074 if (*dbp == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4075 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4077 dbp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4078 while (*dbp == ':');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4080 if (L_isdef (dbp - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4081 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4082 dbp = skip_non_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4083 dbp = skip_spaces (dbp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4084 L_getit ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4085 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4086 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4087 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4088 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4089 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4090 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4092 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4093 * Postscript tag functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4094 * Just look for lines where the first character is '/'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4095 * Richard Mlynarik <mly@adoc.xerox.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4096 * Also look at "defineps" for PSWrap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4097 * suggested by Masatake YAMATO <masata-y@is.aist-nara.ac.jp>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4098 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4099 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4100 Postscript_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4102 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4103 register char *bp, *ep;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4105 LOOP_ON_INPUT_LINES (inf, lb, bp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4106 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107 if (bp[0] == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109 for (ep = bp+1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 *ep != '\0' && *ep != ' ' && *ep != '{';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4111 ep++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4112 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4113 pfnote (savenstr (bp, ep-bp), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4114 lb.buffer, ep - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4115 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4116 else if (strneq (bp, "defineps", 8))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4118 bp = skip_non_spaces (bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4119 bp = skip_spaces (bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4120 get_tag (bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4121 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4122 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4126 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4127 * Scheme tag functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4128 * look for (def... xyzzy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4129 * look for (def... (xyzzy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4130 * look for (def ... ((...(xyzzy ....
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4131 * look for (set! xyzzy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4132 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4134 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4135 Scheme_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4136 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4137 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4138 register char *bp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4140 LOOP_ON_INPUT_LINES (inf, lb, bp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4141 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4142 if (bp[0] == '('
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4143 && (bp[1] == 'D' || bp[1] == 'd')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4144 && (bp[2] == 'E' || bp[2] == 'e')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4145 && (bp[3] == 'F' || bp[3] == 'f'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4146 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4147 bp = skip_non_spaces (bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 /* Skip over open parens and white space */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 while (isspace (*bp) || *bp == '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150 bp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4151 get_tag (bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4152 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153 if (bp[0] == '('
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4154 && (bp[1] == 'S' || bp[1] == 's')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4155 && (bp[2] == 'E' || bp[2] == 'e')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4156 && (bp[3] == 'T' || bp[3] == 't')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4157 && (bp[4] == '!' || bp[4] == '!')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4158 && (isspace (bp[5])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4159 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4160 bp = skip_non_spaces (bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4161 bp = skip_spaces (bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4162 get_tag (bp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4163 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4164 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4165 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4167 /* Find tags in TeX and LaTeX input files. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4169 /* TEX_toktab is a table of TeX control sequences that define tags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4170 Each TEX_tabent records one such control sequence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4171 CONVERT THIS TO USE THE Stab TYPE!! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4172 struct TEX_tabent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4173 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4174 char *name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4175 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4176 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4178 struct TEX_tabent *TEX_toktab = NULL; /* Table with tag tokens */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4180 /* Default set of control sequences to put into TEX_toktab.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4181 The value of environment var TEXTAGS is prepended to this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4183 char *TEX_defenv = "\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4184 :chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4185 :part:appendix:entry:index";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4187 void TEX_mode (FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4188 struct TEX_tabent *TEX_decode_env (char *evarname, char *defenv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4189 int TEX_Token (char *cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4191 char TEX_esc = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4192 char TEX_opgrp = '{';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4193 char TEX_clgrp = '}';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4195 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4196 * TeX/LaTeX scanning loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4197 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4198 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4199 TeX_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4200 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4201 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4202 char *cp, *lasthit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4203 register int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4205 /* Select either \ or ! as escape character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4206 TEX_mode (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4208 /* Initialize token table once from environment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4209 if (!TEX_toktab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4210 TEX_toktab = TEX_decode_env ("TEXTAGS", TEX_defenv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4212 LOOP_ON_INPUT_LINES (inf, lb, cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4213 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4214 lasthit = cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4215 /* Look at each esc in line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4216 while ((cp = etags_strchr (cp, TEX_esc)) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4217 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4218 if (*++cp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4219 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4220 linecharno += cp - lasthit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4221 lasthit = cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4222 i = TEX_Token (lasthit);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4223 if (i >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4224 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4225 /* We seem to include the TeX command in the tag name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4226 register char *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4227 for (p = lasthit + TEX_toktab[i].len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4228 *p != '\0' && *p != TEX_clgrp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4229 p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4230 continue; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4231 pfnote (/*savenstr (lasthit, p-lasthit)*/ (char *)NULL, TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4232 lb.buffer, lb.len, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4233 break; /* We only tag a line once */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4234 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4235 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4236 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4239 #define TEX_LESC '\\'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4240 #define TEX_SESC '!'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4241 #define TEX_cmt '%'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4243 /* Figure out whether TeX's escapechar is '\\' or '!' and set grouping
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4244 chars accordingly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4245 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4246 TEX_mode (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4247 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4249 int c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4251 while ((c = getc (inf)) != EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4253 /* Skip to next line if we hit the TeX comment char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4254 if (c == TEX_cmt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4255 while (c != '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4256 c = getc (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4257 else if (c == TEX_LESC || c == TEX_SESC )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4258 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4259 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4261 if (c == TEX_LESC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4262 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4263 TEX_esc = TEX_LESC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4264 TEX_opgrp = '{';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4265 TEX_clgrp = '}';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4266 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4267 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4268 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4269 TEX_esc = TEX_SESC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4270 TEX_opgrp = '<';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4271 TEX_clgrp = '>';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4272 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4273 /* If the input file is compressed, inf is a pipe, and rewind may fail.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4274 No attempt is made to correct the situation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4275 rewind (inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4278 /* Read environment and prepend it to the default string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4279 Build token table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4280 struct TEX_tabent *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4281 TEX_decode_env (evarname, defenv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4282 char *evarname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4283 char *defenv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4285 register char *env, *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4287 struct TEX_tabent *tab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4288 int size, i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4290 /* Append default string to environment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4291 env = getenv (evarname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4292 if (!env)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4293 env = defenv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4294 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4295 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4296 char *oldenv = env;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4297 env = concat (oldenv, defenv, "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4298 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4300 /* Allocate a token table */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4301 for (size = 1, p = env; p;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4302 if ((p = etags_strchr (p, ':')) && *++p != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4303 size++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4304 /* Add 1 to leave room for null terminator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4305 tab = xnew (size + 1, struct TEX_tabent);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4307 /* Unpack environment string into token table. Be careful about */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4308 /* zero-length strings (leading ':', "::" and trailing ':') */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4309 for (i = 0; *env;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4310 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4311 p = etags_strchr (env, ':');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4312 if (!p) /* End of environment string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4313 p = env + strlen (env);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4314 if (p - env > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4315 { /* Only non-zero strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4316 tab[i].name = savenstr (env, p - env);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4317 tab[i].len = strlen (tab[i].name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4318 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4319 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4320 if (*p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4321 env = p + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4322 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4323 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4324 tab[i].name = NULL; /* Mark end of table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4325 tab[i].len = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4326 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4328 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4329 return tab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4330 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4332 /* If the text at CP matches one of the tag-defining TeX command names,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4333 return the pointer to the first occurrence of that command in TEX_toktab.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4334 Otherwise return -1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4335 Keep the capital `T' in `token' for dumb truncating compilers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4336 (this distinguishes it from `TEX_toktab' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4337 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4338 TEX_Token (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4339 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4340 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4341 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4343 for (i = 0; TEX_toktab[i].len > 0; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4344 if (strneq (TEX_toktab[i].name, cp, TEX_toktab[i].len))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4345 return i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4346 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4347 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4349 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4350 * Prolog support (rewritten) by Anders Lindgren, Mar. 96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4351 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4352 * Assumes that the predicate starts at column 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4353 * Only the first clause of a predicate is added.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4354 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4355 int prolog_pred (char *s, char *last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4356 void prolog_skip_comment (linebuffer *plb, FILE *inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4357 int prolog_atom (char *s, int pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4359 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4360 Prolog_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4361 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4362 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4363 char *cp, *last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4364 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4365 int allocated;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4367 allocated = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4368 len = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4369 last = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4371 LOOP_ON_INPUT_LINES (inf, lb, cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4372 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4373 if (cp[0] == '\0') /* Empty line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4374 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4375 else if (isspace (cp[0])) /* Not a predicate */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4376 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4377 else if (cp[0] == '/' && cp[1] == '*') /* comment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4378 prolog_skip_comment (&lb, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4379 else if ((len = prolog_pred (cp, last)) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4380 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4381 /* Predicate. Store the function name so that we only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4382 generate a tag for the first clause. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4383 if (last == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4384 last = xnew(len + 1, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4385 else if (len + 1 > allocated)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4386 last = xrnew (last, len + 1, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4387 allocated = len + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4388 strncpy (last, cp, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4389 last[len] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4390 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4391 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4395 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4396 prolog_skip_comment (plb, inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4397 linebuffer *plb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4398 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4399 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4400 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4402 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4403 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4404 for (cp = plb->buffer; *cp != '\0'; cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4405 if (cp[0] == '*' && cp[1] == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4406 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4407 lineno++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4408 linecharno += readline (plb, inf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4409 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4410 while (!feof(inf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4411 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4413 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4414 * A predicate definition is added if it matches:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4415 * <beginning of line><Prolog Atom><whitespace>(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4416 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4417 * It is added to the tags database if it doesn't match the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4418 * name of the previous clause header.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4419 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4420 * Return the size of the name of the predicate, or 0 if no header
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4421 * was found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4422 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4423 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4424 prolog_pred (s, last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4425 char *s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4426 char *last; /* Name of last clause. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4427 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4428 int pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4429 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4431 pos = prolog_atom (s, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4432 if (pos < 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4433 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4435 len = pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4436 pos = skip_spaces (s + pos) - s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4438 if ((s[pos] == '(') || (s[pos] == '.'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4439 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4440 if (s[pos] == '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4441 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4443 /* Save only the first clause. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4444 if (last == NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4445 || len != (int)strlen (last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4446 || !strneq (s, last, len))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4447 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4448 pfnote (savenstr (s, len), TRUE, s, pos, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4449 return len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4450 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4451 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4452 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4453 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4455 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4456 * Consume a Prolog atom.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4457 * Return the number of bytes consumed, or -1 if there was an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4458 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4459 * A prolog atom, in this context, could be one of:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4460 * - An alphanumeric sequence, starting with a lower case letter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4461 * - A quoted arbitrary string. Single quotes can escape themselves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4462 * Backslash quotes everything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4463 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4464 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4465 prolog_atom (s, pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4466 char *s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4467 int pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4468 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4469 int origpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4471 origpos = pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4473 if (islower(s[pos]) || (s[pos] == '_'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4474 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4475 /* The atom is unquoted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4476 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4477 while (isalnum(s[pos]) || (s[pos] == '_'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4478 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4479 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4480 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4481 return pos - origpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4482 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4483 else if (s[pos] == '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4484 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4485 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4487 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4488 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4489 if (s[pos] == '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4490 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4491 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4492 if (s[pos] != '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4493 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4494 pos++; /* A double quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4495 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4496 else if (s[pos] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4497 /* Multiline quoted atoms are ignored. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4498 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4499 else if (s[pos] == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4500 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4501 if (s[pos+1] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4502 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4503 pos += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4504 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4505 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4506 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4507 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4508 return pos - origpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4509 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4510 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4511 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4512 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4514 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4515 * Support for Erlang -- Anders Lindgren, Feb 1996.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4516 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4517 * Generates tags for functions, defines, and records.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4518 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4519 * Assumes that Erlang functions start at column 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4520 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4521 int erlang_func (char *s, char *last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4522 void erlang_attribute (char *s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4523 int erlang_atom (char *s, int pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4525 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4526 Erlang_functions (inf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4527 FILE *inf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4528 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4529 char *cp, *last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4530 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4531 int allocated;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4533 allocated = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4534 len = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4535 last = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4537 LOOP_ON_INPUT_LINES (inf, lb, cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4538 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4539 if (cp[0] == '\0') /* Empty line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4540 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4541 else if (isspace (cp[0])) /* Not function nor attribute */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4542 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4543 else if (cp[0] == '%') /* comment */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4544 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4545 else if (cp[0] == '"') /* Sometimes, strings start in column one */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4546 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4547 else if (cp[0] == '-') /* attribute, e.g. "-define" */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4548 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4549 erlang_attribute (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4550 last = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4552 else if ((len = erlang_func (cp, last)) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4553 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4554 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4555 * Function. Store the function name so that we only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4556 * generates a tag for the first clause.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4557 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4558 if (last == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4559 last = xnew (len + 1, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4560 else if (len + 1 > allocated)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4561 last = xrnew (last, len + 1, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4562 allocated = len + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4563 strncpy (last, cp, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4564 last[len] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4565 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4566 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4567 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4570 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4571 * A function definition is added if it matches:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4572 * <beginning of line><Erlang Atom><whitespace>(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4573 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4574 * It is added to the tags database if it doesn't match the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4575 * name of the previous clause header.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4576 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4577 * Return the size of the name of the function, or 0 if no function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4578 * was found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4579 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4580 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4581 erlang_func (s, last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4582 char *s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4583 char *last; /* Name of last clause. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4584 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4585 int pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4586 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4588 pos = erlang_atom (s, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4589 if (pos < 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4590 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4592 len = pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4593 pos = skip_spaces (s + pos) - s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4595 /* Save only the first clause. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4596 if (s[pos++] == '('
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4597 && (last == NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4598 || len != (int)strlen (last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4599 || !strneq (s, last, len)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4600 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4601 pfnote (savenstr (s, len), TRUE, s, pos, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4602 return len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4603 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4605 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4606 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4609 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4610 * Handle attributes. Currently, tags are generated for defines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4611 * and records.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4612 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4613 * They are on the form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4614 * -define(foo, bar).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4615 * -define(Foo(M, N), M+N).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4616 * -record(graph, {vtab = notable, cyclic = true}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4617 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4618 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4619 erlang_attribute (s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4620 char *s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4621 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4622 int pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4623 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4625 if (strneq (s, "-define", 7) || strneq (s, "-record", 7))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4626 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4627 pos = skip_spaces (s + 7) - s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4628 if (s[pos++] == '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4629 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4630 pos = skip_spaces (s + pos) - s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4631 len = erlang_atom (s, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4632 if (len != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4633 pfnote (savenstr (& s[pos], len), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4634 s, pos + len, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4635 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4636 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4637 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4638 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4639
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4641 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4642 * Consume an Erlang atom (or variable).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4643 * Return the number of bytes consumed, or -1 if there was an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4644 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4645 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4646 erlang_atom (s, pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4647 char *s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4648 int pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4649 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4650 int origpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4652 origpos = pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4654 if (isalpha (s[pos]) || s[pos] == '_')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4655 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4656 /* The atom is unquoted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4657 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4658 while (isalnum (s[pos]) || s[pos] == '_')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4659 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4660 return pos - origpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4661 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4662 else if (s[pos] == '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4663 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4664 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4666 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4667 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4668 if (s[pos] == '\'')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4669 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4670 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4671 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4672 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4673 else if (s[pos] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4674 /* Multiline quoted atoms are ignored. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4675 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4676 else if (s[pos] == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4677 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4678 if (s[pos+1] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4679 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4680 pos += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4681 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4682 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4683 pos++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4684 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4685 return pos - origpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4686 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4687 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4688 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4689 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4691 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4693 /* Take a string like "/blah/" and turn it into "blah", making sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4694 that the first and last characters are the same, and handling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4695 quoted separator characters. Actually, stops on the occurrence of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4696 an unquoted separator. Also turns "\t" into a Tab character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4697 Returns pointer to terminating separator. Works in place. Null
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4698 terminates name string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4699 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4700 scan_separators (name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4701 char *name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4702 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4703 char sep = name[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4704 char *copyto = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4705 bool quoted = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4707 for (++name; *name != '\0'; ++name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4708 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4709 if (quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4710 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4711 if (*name == 't')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4712 *copyto++ = '\t';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4713 else if (*name == sep)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4714 *copyto++ = sep;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4715 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4716 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4717 /* Something else is quoted, so preserve the quote. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4718 *copyto++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4719 *copyto++ = *name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4720 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4721 quoted = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4722 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4723 else if (*name == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4724 quoted = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4725 else if (*name == sep)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4726 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4727 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4728 *copyto++ = *name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4729 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4731 /* Terminate copied string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4732 *copyto = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4733 return name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4734 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4736 /* Look at the argument of --regex or --no-regex and do the right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4737 thing. Same for each line of a regexp file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4738 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4739 analyse_regex (regex_arg, ignore_case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4740 char *regex_arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4741 bool ignore_case;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4742 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4743 if (regex_arg == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4744 free_patterns (); /* --no-regex: remove existing regexps */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4746 /* A real --regexp option or a line in a regexp file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4747 switch (regex_arg[0])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4748 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4749 /* Comments in regexp file or null arg to --regex. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4750 case '\0':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4751 case ' ':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4752 case '\t':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4753 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4755 /* Read a regex file. This is recursive and may result in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4756 loop, which will stop when the file descriptors are exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4757 case '@':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4758 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4759 FILE *regexfp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4760 linebuffer regexbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4761 char *regexfile = regex_arg + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4763 /* regexfile is a file containing regexps, one per line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4764 regexfp = fopen (regexfile, "r");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4765 if (regexfp == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4766 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4767 pfatal (regexfile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4768 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4769 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4770 initbuffer (&regexbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4771 while (readline_internal (&regexbuf, regexfp) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4772 analyse_regex (regexbuf.buffer, ignore_case);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4773 free (regexbuf.buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4774 fclose (regexfp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4775 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4776 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4778 /* Regexp to be used for a specific language only. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4779 case '{':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4780 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4781 language *lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4782 char *lang_name = regex_arg + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4783 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4785 for (cp = lang_name; *cp != '}'; cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4786 if (*cp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4787 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4788 error ("unterminated language name in regex: %s", regex_arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4789 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4790 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4791 *cp = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4792 lang = get_language_from_name (lang_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4793 if (lang == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4794 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4795 add_regex (cp + 1, ignore_case, lang);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4796 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4797 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4799 /* Regexp to be used for any language. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4800 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4801 add_regex (regex_arg, ignore_case, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4802 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4803 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4804 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4806 /* Turn a name, which is an ed-style (but Emacs syntax) regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4807 expression, into a real regular expression by compiling it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4808 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4809 add_regex (regexp_pattern, ignore_case, lang)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4810 char *regexp_pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4811 bool ignore_case;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4812 language *lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4813 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4814 char *name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4815 const char *err;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4816 struct re_pattern_buffer *patbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4817 pattern *pp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4820 if (regexp_pattern[strlen(regexp_pattern)-1] != regexp_pattern[0])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4821 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4822 error ("%s: unterminated regexp", regexp_pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4823 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4825 name = scan_separators (regexp_pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4826 if (regexp_pattern[0] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4827 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4828 error ("null regexp", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4829 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4830 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4831 (void) scan_separators (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4833 patbuf = xnew (1, struct re_pattern_buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4834 /* Translation table to fold case if appropriate. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4835 patbuf->translate = (ignore_case) ? lc_trans : NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4836 patbuf->fastmap = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4837 patbuf->buffer = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4838 patbuf->allocated = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4840 err = re_compile_pattern (regexp_pattern, strlen (regexp_pattern), patbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4841 if (err != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4842 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4843 error ("%s while compiling pattern", err);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4844 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4845 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4847 pp = p_head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4848 p_head = xnew (1, pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4849 p_head->regex = savestr (regexp_pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4850 p_head->p_next = pp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4851 p_head->language = lang;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4852 p_head->pattern = patbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4853 p_head->name_pattern = savestr (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4854 p_head->error_signaled = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4855 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4857 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4858 * Do the substitutions indicated by the regular expression and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4859 * arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4860 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4861 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4862 substitute (in, out, regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4863 char *in, *out;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4864 struct re_registers *regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4865 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4866 char *result, *t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4867 int size, dig, diglen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4869 result = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4870 size = strlen (out);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4872 /* Pass 1: figure out how much to allocate by finding all \N strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4873 if (out[size - 1] == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4874 fatal ("pattern error in \"%s\"", out);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4875 for (t = etags_strchr (out, '\\');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4876 t != NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4877 t = etags_strchr (t + 2, '\\'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4878 if (isdigit (t[1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4879 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4880 dig = t[1] - '0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4881 diglen = regs->end[dig] - regs->start[dig];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4882 size += diglen - 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4883 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4884 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4885 size -= 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4887 /* Allocate space and do the substitutions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4888 result = xnew (size + 1, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4890 for (t = result; *out != '\0'; out++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4891 if (*out == '\\' && isdigit (*++out))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4892 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4893 /* Using "dig2" satisfies my debugger. Bleah. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4894 dig = *out - '0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4895 diglen = regs->end[dig] - regs->start[dig];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4896 strncpy (t, in + regs->start[dig], diglen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4897 t += diglen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4898 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4899 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4900 *t++ = *out;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4901 *t = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4903 if (DEBUG && (t > result + size || t - result != (int)strlen (result)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4904 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4906 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4907 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4909 /* Deallocate all patterns. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4910 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4911 free_patterns ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4912 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4913 pattern *pp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4914 while (p_head != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4915 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4916 pp = p_head->p_next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4917 free (p_head->regex);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4918 free (p_head->name_pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4919 free (p_head);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4920 p_head = pp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4921 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4922 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4923 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4925 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4926 get_tag (bp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4927 register char *bp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4928 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4929 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4931 if (*bp == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4932 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4933 /* Go till you get to white space or a syntactic break */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4934 for (cp = bp + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4935 *cp != '\0' && *cp != '(' && *cp != ')' && !isspace (*cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4936 cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4937 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4938 pfnote (savenstr (bp, cp-bp), TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4939 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4940 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4942 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4943 /* Initialize a linebuffer for use */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4944 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4945 initbuffer (lbp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4946 linebuffer *lbp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4947 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4948 lbp->size = 200;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4949 lbp->buffer = xnew (200, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4950 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4951
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4952 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4953 * Read a line of text from `stream' into `lbp', excluding the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4954 * newline or CR-NL, if any. Return the number of characters read from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4955 * `stream', which is the length of the line including the newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4956 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4957 * On DOS or Windows we do not count the CR character, if any, before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4958 * NL, in the returned length; this mirrors the behavior of emacs on those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4959 * platforms (for text files, it translates CR-NL to NL as it reads in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4960 * file).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4961 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4962 long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4963 readline_internal (lbp, stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4964 linebuffer *lbp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4965 register FILE *stream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4966 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4967 char *buffer = lbp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4968 register char *p = lbp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4969 register char *pend;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4970 int chars_deleted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4972 pend = p + lbp->size; /* Separate to avoid 386/IX compiler bug. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4973
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4974 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4975 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4976 register int c = getc (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4977 if (p == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4978 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4979 /* We're at the end of linebuffer: expand it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4980 lbp->size *= 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4981 buffer = xrnew (buffer, lbp->size, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4982 p += buffer - lbp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4983 pend = buffer + lbp->size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4984 lbp->buffer = buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4985 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4986 if (c == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4987 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4988 *p = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4989 chars_deleted = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4990 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4991 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4992 if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4993 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4994 if (p > buffer && p[-1] == '\r')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4995 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4996 p -= 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4997 #ifdef DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4998 /* Assume CRLF->LF translation will be performed by Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4999 when loading this file, so CRs won't appear in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5000 It would be cleaner to compensate within Emacs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5001 however, Emacs does not know how many CRs were deleted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5002 before any given point in the file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5003 chars_deleted = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5004 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5005 chars_deleted = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5006 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5007 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5008 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5009 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5010 chars_deleted = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5011 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5012 *p = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5013 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5014 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5015 *p++ = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5016 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5017 lbp->len = p - buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5018
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5019 return lbp->len + chars_deleted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5020 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5022 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5023 * Like readline_internal, above, but in addition try to match the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5024 * input line against relevant regular expressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5025 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5026 long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5027 readline (lbp, stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5028 linebuffer *lbp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5029 FILE *stream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5030 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5031 /* Read new line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5032 long result = readline_internal (lbp, stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5033 #ifdef ETAGS_REGEXPS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5034 int match;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5035 pattern *pp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5037 /* Match against relevant patterns. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5038 if (lbp->len > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5039 for (pp = p_head; pp != NULL; pp = pp->p_next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5040 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5041 /* Only use generic regexps or those for the current language. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5042 if (pp->language != NULL && pp->language != curlang)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5043 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5045 match = re_match (pp->pattern, lbp->buffer, lbp->len, 0, &pp->regs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5046 switch (match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5047 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5048 case -2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5049 /* Some error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5050 if (!pp->error_signaled)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5051 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5052 error ("error while matching \"%s\"", pp->regex);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5053 pp->error_signaled = TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5054 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5055 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5056 case -1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5057 /* No match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5058 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5059 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5060 /* Match occurred. Construct a tag. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5061 if (pp->name_pattern[0] != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5062 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5063 /* Make a named tag. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5064 char *name = substitute (lbp->buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5065 pp->name_pattern, &pp->regs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5066 if (name != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5067 pfnote (name, TRUE, lbp->buffer, match, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5068 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5069 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5070 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5071 /* Make an unnamed tag. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5072 pfnote ((char *)NULL, TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5073 lbp->buffer, match, lineno, linecharno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5074 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5075 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5076 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5077 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5078 #endif /* ETAGS_REGEXPS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5080 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5081 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5083 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5084 * Return a pointer to a space of size strlen(cp)+1 allocated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5085 * with xnew where the string CP has been copied.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5086 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5087 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5088 savestr (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5089 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5090 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5091 return savenstr (cp, strlen (cp));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5092 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5094 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5095 * Return a pointer to a space of size LEN+1 allocated with xnew where
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5096 * the string CP has been copied for at most the first LEN characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5097 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5098 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5099 savenstr (cp, len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5100 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5101 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5102 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5103 register char *dp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5105 dp = xnew (len + 1, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5106 strncpy (dp, cp, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5107 dp[len] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5108 return dp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5109 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5111 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5112 * Return the ptr in sp at which the character c last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5113 * appears; NULL if not found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5114 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5115 * Identical to System V strrchr, included for portability.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5116 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5117 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5118 etags_strrchr (sp, c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5119 register char *sp, c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5120 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5121 register char *r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5123 r = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5124 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5125 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5126 if (*sp == c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5127 r = sp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5128 } while (*sp++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5129 return r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5130 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5133 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5134 * Return the ptr in sp at which the character c first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5135 * appears; NULL if not found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5136 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5137 * Identical to System V strchr, included for portability.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5138 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5139 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5140 etags_strchr (sp, c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5141 register char *sp, c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5142 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5143 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5144 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5145 if (*sp == c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5146 return sp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5147 } while (*sp++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5148 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5149 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5151 /* Skip spaces, return new pointer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5152 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5153 skip_spaces (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5154 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5155 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5156 while (isspace (*cp)) /* isspace('\0')==FALSE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5157 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5158 return cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5159 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5161 /* Skip non spaces, return new pointer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5162 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5163 skip_non_spaces (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5164 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5165 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5166 while (!iswhite (*cp)) /* iswhite('\0')==TRUE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5167 cp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5168 return cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5169 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5171 /* Print error message and exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5172 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5173 fatal (s1, s2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5174 char *s1, *s2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5175 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5176 error (s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5177 exit (BAD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5180 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5181 pfatal (s1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5182 char *s1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5183 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5184 perror (s1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5185 exit (BAD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5188 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5189 suggest_asking_for_help ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5190 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5191 fprintf (stderr, "\tTry `%s %s' for a complete list of options.\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5192 progname,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5193 #ifdef LONG_OPTIONS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5194 "--help"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5195 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5196 "-h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5197 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5198 );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5199 exit (BAD);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5200 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5202 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5203 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5204 error (s1, s2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5205 const char *s1, *s2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5206 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5207 fprintf (stderr, "%s: ", progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5208 fprintf (stderr, s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5209 fprintf (stderr, "\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5210 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5212 /* Return a newly-allocated string whose contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5213 concatenate those of s1, s2, s3. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5214 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5215 concat (s1, s2, s3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5216 char *s1, *s2, *s3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5217 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5218 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5219 char *result = xnew (len1 + len2 + len3 + 1, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5221 strcpy (result, s1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5222 strcpy (result + len1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5223 strcpy (result + len1 + len2, s3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5224 result[len1 + len2 + len3] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5226 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5229 /* Does the same work as the system V getcwd, but does not need to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5230 guess the buffer size in advance. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5231 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5232 etags_getcwd ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5233 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5234 #ifdef HAVE_GETCWD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5235 int bufsize = 200;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5236 char *path = xnew (bufsize, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5238 while (getcwd (path, bufsize) == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5239 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5240 if (errno != ERANGE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5241 pfatal ("getcwd");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5242 bufsize *= 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5243 free (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5244 path = xnew (bufsize, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5245 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5247 canonicalize_filename (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5248 return path;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5250 #else /* not HAVE_GETCWD */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5251 #ifdef MSDOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5252 char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5254 getwd (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5256 for (p = path; *p != '\0'; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5257 if (*p == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5258 *p = '/';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5259 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5260 *p = lowcase (*p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5262 return strdup (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5263 #else /* not MSDOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5264 linebuffer path;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5265 FILE *pipe;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5267 initbuffer (&path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5268 pipe = (FILE *) popen ("pwd 2>/dev/null", "r");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5269 if (pipe == NULL || readline_internal (&path, pipe) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5270 pfatal ("pwd");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5271 pclose (pipe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5273 return path.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5274 #endif /* not MSDOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5275 #endif /* not HAVE_GETCWD */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5278 /* Return a newly allocated string containing the file name of FILE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5279 relative to the absolute directory DIR (which should end with a slash). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5280 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5281 relative_filename (file, dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5282 char *file, *dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5283 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5284 char *fp, *dp, *afn, *res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5285 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5287 /* Find the common root of file and dir (with a trailing slash). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5288 afn = absolute_filename (file, cwd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5289 fp = afn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5290 dp = dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5291 while (*fp++ == *dp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5292 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5293 fp--, dp--; /* back to the first differing char */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5294 #ifdef DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5295 if (fp == afn && afn[0] != '/') /* cannot build a relative name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5296 return afn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5297 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5298 do /* look at the equal chars until '/' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5299 fp--, dp--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5300 while (*fp != '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5302 /* Build a sequence of "../" strings for the resulting relative file name. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5303 i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5304 while ((dp = etags_strchr (dp + 1, '/')) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5305 i += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5306 res = xnew (3*i + strlen (fp + 1) + 1, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5307 res[0] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5308 while (i-- > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5309 strcat (res, "../");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5311 /* Add the file name relative to the common root of file and dir. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5312 strcat (res, fp + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5313 free (afn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5315 return res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5316 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5318 /* Return a newly allocated string containing the absolute file name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5319 of FILE given DIR (which should end with a slash). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5320 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5321 absolute_filename (file, dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5322 char *file, *dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5323 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5324 char *slashp, *cp, *res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5326 if (filename_is_absolute (file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5327 res = savestr (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5328 #ifdef DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5329 /* We don't support non-absolute file names with a drive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5330 letter, like `d:NAME' (it's too much hassle). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5331 else if (file[1] == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5332 fatal ("%s: relative file names with drive letters not supported", file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5333 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5334 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5335 res = concat (dir, file, "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5337 /* Delete the "/dirname/.." and "/." substrings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5338 slashp = etags_strchr (res, '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5339 while (slashp != NULL && slashp[0] != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5340 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5341 if (slashp[1] == '.')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5342 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5343 if (slashp[2] == '.'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5344 && (slashp[3] == '/' || slashp[3] == '\0'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5345 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5346 cp = slashp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5347 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5348 cp--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5349 while (cp >= res && !filename_is_absolute (cp));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5350 if (cp < res)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5351 cp = slashp; /* the absolute name begins with "/.." */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5352 #ifdef DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5353 /* Under MSDOS and NT we get `d:/NAME' as absolute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5354 file name, so the luser could say `d:/../NAME'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5355 We silently treat this as `d:/NAME'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5356 else if (cp[0] != '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5357 cp = slashp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5358 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5359 strcpy (cp, slashp + 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5360 slashp = cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5361 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5362 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5363 else if (slashp[2] == '/' || slashp[2] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5364 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5365 strcpy (slashp, slashp + 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5366 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5367 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5368 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5370 slashp = etags_strchr (slashp + 1, '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5371 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5373 if (res[0] == '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5374 return savestr ("/");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5375 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5376 return res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5377 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5379 /* Return a newly allocated string containing the absolute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5380 file name of dir where FILE resides given DIR (which should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5381 end with a slash). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5382 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5383 absolute_dirname (file, dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5384 char *file, *dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5385 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5386 char *slashp, *res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5387 char save;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5389 canonicalize_filename (file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5390 slashp = etags_strrchr (file, '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5391 if (slashp == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5392 return savestr (dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5393 save = slashp[1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5394 slashp[1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5395 res = absolute_filename (file, dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5396 slashp[1] = save;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5398 return res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5399 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5401 /* Whether the argument string is an absolute file name. The argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5402 string must have been canonicalized with canonicalize_filename. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5403 bool
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5404 filename_is_absolute (fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5405 char *fn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5406 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5407 return (fn[0] == '/'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5408 #ifdef DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5409 || (isalpha(fn[0]) && fn[1] == ':' && fn[2] == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5410 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5411 );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5412 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5414 /* Translate backslashes into slashes. Works in place. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5415 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5416 canonicalize_filename (fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5417 register char *fn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5418 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5419 #ifdef DOS_NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5420 /* Canonicalize drive letter case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5421 if (islower (fn[0]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5422 fn[0] = toupper (fn[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5423 /* Convert backslashes to slashes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5424 for (; *fn != '\0'; fn++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5425 if (*fn == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5426 *fn = '/';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5427 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5428 /* No action. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5429 fn = NULL; /* shut up the compiler */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5430 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5431 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5433 /* Increase the size of a linebuffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5434 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5435 grow_linebuffer (lbp, toksize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5436 linebuffer *lbp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5437 int toksize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5438 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5439 while (lbp->size < toksize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5440 lbp->size *= 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5441 lbp->buffer = xrnew (lbp->buffer, lbp->size, char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5444 /* Like malloc but get fatal error if memory is exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5445 long *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5446 xmalloc (size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5447 unsigned int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5448 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5449 long *result = (long *) malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5450 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5451 fatal ("virtual memory exhausted", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5452 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5453 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5455 long *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5456 xrealloc (ptr, size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5457 char *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5458 unsigned int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5460 long *result = (long *) realloc (ptr, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5461 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5462 fatal ("virtual memory exhausted", (char *)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5463 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5464 }