blob: bc8886c112665324007190100941e56ed5ab5e6a [file] [log] [blame]
Zack Weinberg5538ada1999-02-04 06:36:54 -05001/* CPP Library.
Jeff Law5e7b4e22000-02-25 22:59:31 -07002 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
Neil Booth03b9ab42001-01-04 10:25:55 +00003 1999, 2000, 2001 Free Software Foundation, Inc.
Zack Weinberg5538ada1999-02-04 06:36:54 -05004 Contributed by Per Bothner, 1994-95.
5 Based on CCCP program by Paul Rubin, June 1986
6 Adapted to ANSI C, Richard Stallman, Jan 1987
7
8This program is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License as published by the
10Free Software Foundation; either version 2, or (at your option) any
11later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
Zack Weinberg5538ada1999-02-04 06:36:54 -050022#include "config.h"
23#include "system.h"
Zack Weinberg6de1e2a1999-02-18 15:35:49 +000024#include "cpplib.h"
25#include "cpphash.h"
26#include "output.h"
27#include "prefix.h"
28#include "intl.h"
Kaveh R. Ghazi9f8f4ef2000-02-15 16:36:35 +000029#include "version.h"
Zack Weinberg49e6c082000-03-04 19:42:04 +000030#include "mkdeps.h"
Zack Weinberg60893f42000-07-06 22:52:03 +000031#include "cppdefault.h"
Zack Weinberg6de1e2a1999-02-18 15:35:49 +000032
Neil Booth4a58aab2000-11-18 12:18:09 +000033/* Predefined symbols, built-in macros, and the default include path. */
Zack Weinberg6de1e2a1999-02-18 15:35:49 +000034
35#ifndef GET_ENV_PATH_LIST
36#define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
37#endif
38
Zack Weinberg88ae23e2000-03-08 23:35:19 +000039/* Windows does not natively support inodes, and neither does MSDOS.
40 Cygwin's emulation can generate non-unique inodes, so don't use it.
Kazu Hirataec5c56d2001-08-01 17:57:27 +000041 VMS has non-numeric inodes. */
Zack Weinberg88ae23e2000-03-08 23:35:19 +000042#ifdef VMS
Douglas B Ruppca47c892001-11-21 16:55:36 -050043# define INO_T_EQ(A, B) (!memcmp (&(A), &(B), sizeof (A)))
44# define INO_T_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof (SRC))
Zack Weinberg88ae23e2000-03-08 23:35:19 +000045#else
Michael Sokolov3943e752001-01-21 02:26:27 +000046# if (defined _WIN32 && ! defined (_UWIN)) || defined __MSDOS__
Douglas B Ruppca47c892001-11-21 16:55:36 -050047# define INO_T_EQ(A, B) 0
Michael Sokolov3943e752001-01-21 02:26:27 +000048# else
Douglas B Ruppca47c892001-11-21 16:55:36 -050049# define INO_T_EQ(A, B) ((A) == (B))
Michael Sokolov3943e752001-01-21 02:26:27 +000050# endif
Douglas B Ruppca47c892001-11-21 16:55:36 -050051# define INO_T_COPY(DEST, SRC) (DEST) = (SRC)
Zack Weinberg88ae23e2000-03-08 23:35:19 +000052#endif
53
Neil Booth4a58aab2000-11-18 12:18:09 +000054/* Internal structures and prototypes. */
Zack Weinberg6de1e2a1999-02-18 15:35:49 +000055
Neil Booth4a58aab2000-11-18 12:18:09 +000056/* A `struct pending_option' remembers one -D, -A, -U, -include, or
57 -imacros switch. */
Neil Booth40eac642000-03-11 09:13:00 +000058
Kaveh R. Ghazi8be1ddc2000-03-12 13:55:52 +000059typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *));
Zack Weinberg0b22d651999-03-15 18:42:46 +000060struct pending_option
Zack Weinberg6de1e2a1999-02-18 15:35:49 +000061{
Zack Weinberg0b22d651999-03-15 18:42:46 +000062 struct pending_option *next;
Neil Booth7ceb3592000-03-11 00:49:44 +000063 const char *arg;
Neil Booth40eac642000-03-11 09:13:00 +000064 cl_directive_handler handler;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +000065};
Zack Weinberg0b22d651999-03-15 18:42:46 +000066
Zack Weinberg88ae23e2000-03-08 23:35:19 +000067/* The `pending' structure accumulates all the options that are not
Neil Boothf5e99452001-11-15 10:01:10 +000068 actually processed until we hit cpp_read_main_file. It consists of
Zack Weinberg88ae23e2000-03-08 23:35:19 +000069 several lists, one for each type of option. We keep both head and
Neil Booth4a58aab2000-11-18 12:18:09 +000070 tail pointers for quick insertion. */
Zack Weinberg88ae23e2000-03-08 23:35:19 +000071struct cpp_pending
72{
Neil Booth40eac642000-03-11 09:13:00 +000073 struct pending_option *directive_head, *directive_tail;
Zack Weinberg88ae23e2000-03-08 23:35:19 +000074
Neil Booth591e15a2001-03-02 07:35:12 +000075 struct search_path *quote_head, *quote_tail;
76 struct search_path *brack_head, *brack_tail;
77 struct search_path *systm_head, *systm_tail;
78 struct search_path *after_head, *after_tail;
Zack Weinberg88ae23e2000-03-08 23:35:19 +000079
80 struct pending_option *imacros_head, *imacros_tail;
81 struct pending_option *include_head, *include_tail;
82};
83
Zack Weinberg0b22d651999-03-15 18:42:46 +000084#ifdef __STDC__
85#define APPEND(pend, list, elt) \
86 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
87 else (pend)->list##_tail->next = (elt); \
88 (pend)->list##_tail = (elt); \
89 } while (0)
90#else
91#define APPEND(pend, list, elt) \
92 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
93 else (pend)->list/**/_tail->next = (elt); \
94 (pend)->list/**/_tail = (elt); \
95 } while (0)
96#endif
Zack Weinberg6de1e2a1999-02-18 15:35:49 +000097
Zack Weinberg6de1e2a1999-02-18 15:35:49 +000098static void print_help PARAMS ((void));
Zack Weinberg0b22d651999-03-15 18:42:46 +000099static void path_include PARAMS ((cpp_reader *,
Zack Weinberg0b22d651999-03-15 18:42:46 +0000100 char *, int));
Neil Booth674c3b42001-01-08 18:52:09 +0000101static void init_library PARAMS ((void));
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000102static void init_builtins PARAMS ((cpp_reader *));
Zack Weinberg0b22d651999-03-15 18:42:46 +0000103static void append_include_chain PARAMS ((cpp_reader *,
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000104 char *, int, int));
Nathan Sidwell002ee642001-07-20 10:30:47 +0000105static struct search_path * remove_dup_dir PARAMS ((cpp_reader *,
Neil Booth591e15a2001-03-02 07:35:12 +0000106 struct search_path *));
Nathan Sidwell002ee642001-07-20 10:30:47 +0000107static struct search_path * remove_dup_dirs PARAMS ((cpp_reader *,
Neil Booth591e15a2001-03-02 07:35:12 +0000108 struct search_path *));
Zack Weinbergae796972000-03-31 23:16:11 +0000109static void merge_include_chains PARAMS ((cpp_reader *));
Neil Boothd7bc7a92001-08-21 06:20:18 +0000110static bool push_include PARAMS ((cpp_reader *,
111 struct pending_option *));
112static void free_chain PARAMS ((struct pending_option *));
Neil Boothdd07b882000-11-20 18:27:32 +0000113static void set_lang PARAMS ((cpp_reader *, enum c_lang));
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000114static void init_dependency_output PARAMS ((cpp_reader *));
115static void init_standard_includes PARAMS ((cpp_reader *));
Neil Boothf5e99452001-11-15 10:01:10 +0000116static void read_original_filename PARAMS ((cpp_reader *));
Zack Weinberg2c0accc2000-07-15 19:29:14 +0000117static void new_pending_directive PARAMS ((struct cpp_pending *,
Neil Booth40eac642000-03-11 09:13:00 +0000118 const char *,
119 cl_directive_handler));
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000120static void output_deps PARAMS ((cpp_reader *));
Zack Weinberge23c0ba2000-03-07 23:11:06 +0000121static int parse_option PARAMS ((const char *));
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000122
Zack Weinbergcb773842001-03-02 00:42:28 +0000123/* Fourth argument to append_include_chain: chain to use.
124 Note it's never asked to append to the quote chain. */
125enum { BRACKET = 0, SYSTEM, AFTER };
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000126
Neil Booth61d03462000-08-18 17:35:58 +0000127/* If we have designated initializers (GCC >2.7) these tables can be
128 initialized, constant data. Otherwise, they have to be filled in at
Zack Weinberg12cf91f2000-05-04 04:38:01 +0000129 runtime. */
Neil Booth61d03462000-08-18 17:35:58 +0000130#if HAVE_DESIGNATED_INITIALIZERS
Zack Weinberga9ae4481999-10-29 04:31:14 +0000131
Neil Booth4a58aab2000-11-18 12:18:09 +0000132#define init_trigraph_map() /* Nothing. */
Neil Booth61d03462000-08-18 17:35:58 +0000133#define TRIGRAPH_MAP \
134__extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = {
135
Zack Weinberga9ae4481999-10-29 04:31:14 +0000136#define END };
Zack Weinberg455d2582000-03-04 01:42:56 +0000137#define s(p, v) [p] = v,
Neil Booth61d03462000-08-18 17:35:58 +0000138
Zack Weinberga9ae4481999-10-29 04:31:14 +0000139#else
Neil Booth61d03462000-08-18 17:35:58 +0000140
Neil Booth61d03462000-08-18 17:35:58 +0000141#define TRIGRAPH_MAP U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
142 static void init_trigraph_map PARAMS ((void)) { \
143 unsigned char *x = _cpp_trigraph_map;
144
Zack Weinbergae796972000-03-31 23:16:11 +0000145#define END }
Zack Weinberg455d2582000-03-04 01:42:56 +0000146#define s(p, v) x[p] = v;
Neil Booth61d03462000-08-18 17:35:58 +0000147
Zack Weinberga9ae4481999-10-29 04:31:14 +0000148#endif
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000149
Neil Booth61d03462000-08-18 17:35:58 +0000150TRIGRAPH_MAP
151 s('=', '#') s(')', ']') s('!', '|')
152 s('(', '[') s('\'', '^') s('>', '}')
153 s('/', '\\') s('<', '{') s('-', '~')
154END
155
Zack Weinberga9ae4481999-10-29 04:31:14 +0000156#undef s
Zack Weinberg455d2582000-03-04 01:42:56 +0000157#undef END
Neil Booth61d03462000-08-18 17:35:58 +0000158#undef TRIGRAPH_MAP
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000159
160/* Given a colon-separated list of file names PATH,
161 add all the names to the search path for include files. */
162
163static void
Neil Boothe33f6252000-08-17 17:58:24 +0000164path_include (pfile, list, path)
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000165 cpp_reader *pfile;
Zack Weinberg0b22d651999-03-15 18:42:46 +0000166 char *list;
167 int path;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000168{
Zack Weinberg0b22d651999-03-15 18:42:46 +0000169 char *p, *q, *name;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000170
Zack Weinberg0b22d651999-03-15 18:42:46 +0000171 p = list;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000172
Zack Weinberg0b22d651999-03-15 18:42:46 +0000173 do
174 {
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000175 /* Find the end of this name. */
Zack Weinberg0b22d651999-03-15 18:42:46 +0000176 q = p;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000177 while (*q != 0 && *q != PATH_SEPARATOR) q++;
Zack Weinberg0b22d651999-03-15 18:42:46 +0000178 if (q == p)
179 {
180 /* An empty name in the path stands for the current directory. */
181 name = (char *) xmalloc (2);
182 name[0] = '.';
183 name[1] = 0;
184 }
185 else
186 {
187 /* Otherwise use the directory that is named. */
188 name = (char *) xmalloc (q - p + 1);
189 memcpy (name, p, q - p);
190 name[q - p] = 0;
191 }
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000192
Neil Boothe33f6252000-08-17 17:58:24 +0000193 append_include_chain (pfile, name, path, 0);
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000194
195 /* Advance past this name. */
Zack Weinberg0b22d651999-03-15 18:42:46 +0000196 if (*q == 0)
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000197 break;
Zack Weinberg0b22d651999-03-15 18:42:46 +0000198 p = q + 1;
199 }
200 while (1);
201}
202
Neil Boothbef985f2001-08-11 12:37:19 +0000203/* Append DIR to include path PATH. DIR must be allocated on the
204 heap; this routine takes responsibility for freeing it. */
Zack Weinberg0b22d651999-03-15 18:42:46 +0000205static void
Neil Boothe33f6252000-08-17 17:58:24 +0000206append_include_chain (pfile, dir, path, cxx_aware)
Zack Weinberg0b22d651999-03-15 18:42:46 +0000207 cpp_reader *pfile;
Zack Weinberg0b22d651999-03-15 18:42:46 +0000208 char *dir;
209 int path;
Zack Weinberg7d4918a2001-02-07 18:32:42 +0000210 int cxx_aware ATTRIBUTE_UNUSED;
Zack Weinberg0b22d651999-03-15 18:42:46 +0000211{
Neil Boothe33f6252000-08-17 17:58:24 +0000212 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
Neil Booth591e15a2001-03-02 07:35:12 +0000213 struct search_path *new;
Zack Weinberg0b22d651999-03-15 18:42:46 +0000214 struct stat st;
215 unsigned int len;
216
Neil Boothf9200da2001-04-06 07:22:01 +0000217 if (*dir == '\0')
Neil Boothbef985f2001-08-11 12:37:19 +0000218 {
219 free (dir);
220 dir = xstrdup (".");
221 }
Zack Weinbergb0699da2000-03-07 20:58:47 +0000222 _cpp_simplify_pathname (dir);
Neil Boothbef985f2001-08-11 12:37:19 +0000223
Zack Weinberg0b22d651999-03-15 18:42:46 +0000224 if (stat (dir, &st))
225 {
Neil Boothf9200da2001-04-06 07:22:01 +0000226 /* Dirs that don't exist are silently ignored. */
Zack Weinberg0b22d651999-03-15 18:42:46 +0000227 if (errno != ENOENT)
Zack Weinbergc1212d22000-02-06 23:46:18 +0000228 cpp_notice_from_errno (pfile, dir);
Zack Weinbergae796972000-03-31 23:16:11 +0000229 else if (CPP_OPTION (pfile, verbose))
Zack Weinberg041c3192000-07-04 01:58:21 +0000230 fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir);
Neil Boothbef985f2001-08-11 12:37:19 +0000231 free (dir);
Zack Weinberg0b22d651999-03-15 18:42:46 +0000232 return;
233 }
234
235 if (!S_ISDIR (st.st_mode))
236 {
Zack Weinbergc1212d22000-02-06 23:46:18 +0000237 cpp_notice (pfile, "%s: Not a directory", dir);
Neil Boothbef985f2001-08-11 12:37:19 +0000238 free (dir);
Zack Weinberg0b22d651999-03-15 18:42:46 +0000239 return;
240 }
241
242 len = strlen (dir);
243 if (len > pfile->max_include_len)
244 pfile->max_include_len = len;
Zack Weinbergae796972000-03-31 23:16:11 +0000245
Neil Booth591e15a2001-03-02 07:35:12 +0000246 new = (struct search_path *) xmalloc (sizeof (struct search_path));
Zack Weinberg0b22d651999-03-15 18:42:46 +0000247 new->name = dir;
Neil Booth591e15a2001-03-02 07:35:12 +0000248 new->len = len;
Douglas B Ruppca47c892001-11-21 16:55:36 -0500249 INO_T_COPY (new->ino, st.st_ino);
Zack Weinberg0b22d651999-03-15 18:42:46 +0000250 new->dev = st.st_dev;
Christopher Faylor4737b272001-03-02 17:20:30 +0000251 /* Both systm and after include file lists should be treated as system
252 include files since these two lists are really just a concatenation
Kazu Hirataec5c56d2001-08-01 17:57:27 +0000253 of one "system" list. */
Christopher Faylor4737b272001-03-02 17:20:30 +0000254 if (path == SYSTEM || path == AFTER)
Jakub Jelinek52b357e2001-02-03 21:48:32 +0100255#ifdef NO_IMPLICIT_EXTERN_C
256 new->sysp = 1;
257#else
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000258 new->sysp = cxx_aware ? 1 : 2;
Jakub Jelinek52b357e2001-02-03 21:48:32 +0100259#endif
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000260 else
261 new->sysp = 0;
Zack Weinberg0b22d651999-03-15 18:42:46 +0000262 new->name_map = NULL;
Dave Brolley503cb431999-09-13 16:58:44 +0000263 new->next = NULL;
Zack Weinberg0b22d651999-03-15 18:42:46 +0000264
265 switch (path)
266 {
Zack Weinberg0b22d651999-03-15 18:42:46 +0000267 case BRACKET: APPEND (pend, brack, new); break;
268 case SYSTEM: APPEND (pend, systm, new); break;
269 case AFTER: APPEND (pend, after, new); break;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000270 }
271}
272
Neil Boothdd69c712000-08-17 18:03:59 +0000273/* Handle a duplicated include path. PREV is the link in the chain
274 before the duplicate. The duplicate is removed from the chain and
275 freed. Returns PREV. */
Nathan Sidwell002ee642001-07-20 10:30:47 +0000276static struct search_path *
Neil Boothdd69c712000-08-17 18:03:59 +0000277remove_dup_dir (pfile, prev)
278 cpp_reader *pfile;
Neil Booth591e15a2001-03-02 07:35:12 +0000279 struct search_path *prev;
Neil Boothdd69c712000-08-17 18:03:59 +0000280{
Neil Booth591e15a2001-03-02 07:35:12 +0000281 struct search_path *cur = prev->next;
Neil Boothdd69c712000-08-17 18:03:59 +0000282
283 if (CPP_OPTION (pfile, verbose))
284 fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
285
286 prev->next = cur->next;
Neil Booth591e15a2001-03-02 07:35:12 +0000287 free ((PTR) cur->name);
Neil Boothdd69c712000-08-17 18:03:59 +0000288 free (cur);
289
290 return prev;
291}
292
293/* Remove duplicate directories from a chain. Returns the tail of the
294 chain, or NULL if the chain is empty. This algorithm is quadratic
295 in the number of -I switches, which is acceptable since there
296 aren't usually that many of them. */
Nathan Sidwell002ee642001-07-20 10:30:47 +0000297static struct search_path *
Neil Boothdd69c712000-08-17 18:03:59 +0000298remove_dup_dirs (pfile, head)
299 cpp_reader *pfile;
Neil Booth591e15a2001-03-02 07:35:12 +0000300 struct search_path *head;
Neil Boothdd69c712000-08-17 18:03:59 +0000301{
Neil Booth591e15a2001-03-02 07:35:12 +0000302 struct search_path *prev = NULL, *cur, *other;
Neil Boothdd69c712000-08-17 18:03:59 +0000303
304 for (cur = head; cur; cur = cur->next)
305 {
306 for (other = head; other != cur; other = other->next)
307 if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
308 {
Nathan Sidwell002ee642001-07-20 10:30:47 +0000309 if (cur->sysp && !other->sysp)
Nathan Sidwelldbead492001-07-04 20:06:27 +0000310 {
311 cpp_warning (pfile,
312 "changing search order for system directory \"%s\"",
313 cur->name);
314 if (strcmp (cur->name, other->name))
Nathan Sidwell002ee642001-07-20 10:30:47 +0000315 cpp_warning (pfile,
316 " as it is the same as non-system directory \"%s\"",
Nathan Sidwelldbead492001-07-04 20:06:27 +0000317 other->name);
318 else
Nathan Sidwell002ee642001-07-20 10:30:47 +0000319 cpp_warning (pfile,
320 " as it has already been specified as a non-system directory");
Nathan Sidwelldbead492001-07-04 20:06:27 +0000321 }
Neil Boothdd69c712000-08-17 18:03:59 +0000322 cur = remove_dup_dir (pfile, prev);
323 break;
324 }
325 prev = cur;
326 }
327
328 return prev;
329}
330
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000331/* Merge the four include chains together in the order quote, bracket,
332 system, after. Remove duplicate dirs (as determined by
333 INO_T_EQ()). The system_include and after_include chains are never
334 referred to again after this function; all access is through the
335 bracket_include path.
336
337 For the future: Check if the directory is empty (but
Neil Booth4a58aab2000-11-18 12:18:09 +0000338 how?) and possibly preload the include hash. */
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000339
340static void
Zack Weinbergae796972000-03-31 23:16:11 +0000341merge_include_chains (pfile)
342 cpp_reader *pfile;
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000343{
Neil Booth591e15a2001-03-02 07:35:12 +0000344 struct search_path *quote, *brack, *systm, *qtail;
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000345
Zack Weinbergae796972000-03-31 23:16:11 +0000346 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000347
Zack Weinbergae796972000-03-31 23:16:11 +0000348 quote = pend->quote_head;
349 brack = pend->brack_head;
350 systm = pend->systm_head;
Neil Boothdd69c712000-08-17 18:03:59 +0000351 qtail = pend->quote_tail;
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000352
Neil Boothdd69c712000-08-17 18:03:59 +0000353 /* Paste together bracket, system, and after include chains. */
354 if (systm)
355 pend->systm_tail->next = pend->after_head;
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000356 else
Neil Boothdd69c712000-08-17 18:03:59 +0000357 systm = pend->after_head;
358
359 if (brack)
360 pend->brack_tail->next = systm;
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000361 else
362 brack = systm;
363
Neil Boothdd69c712000-08-17 18:03:59 +0000364 /* This is a bit tricky. First we drop dupes from the quote-include
365 list. Then we drop dupes from the bracket-include list.
366 Finally, if qtail and brack are the same directory, we cut out
Zack Weinbergcb773842001-03-02 00:42:28 +0000367 brack and move brack up to point to qtail.
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000368
369 We can't just merge the lists and then uniquify them because
370 then we may lose directories from the <> search path that should
371 be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
372 safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
Neil Boothdd69c712000-08-17 18:03:59 +0000373 -Ibar -I- -Ifoo -Iquux. */
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000374
Neil Boothdd69c712000-08-17 18:03:59 +0000375 remove_dup_dirs (pfile, brack);
376 qtail = remove_dup_dirs (pfile, quote);
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000377
378 if (quote)
379 {
Neil Boothdd69c712000-08-17 18:03:59 +0000380 qtail->next = brack;
381
382 /* If brack == qtail, remove brack as it's simpler. */
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000383 if (INO_T_EQ (qtail->ino, brack->ino) && qtail->dev == brack->dev)
Neil Boothdd69c712000-08-17 18:03:59 +0000384 brack = remove_dup_dir (pfile, qtail);
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000385 }
386 else
Neil Boothbef985f2001-08-11 12:37:19 +0000387 quote = brack;
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000388
Zack Weinbergae796972000-03-31 23:16:11 +0000389 CPP_OPTION (pfile, quote_include) = quote;
390 CPP_OPTION (pfile, bracket_include) = brack;
Zack Weinberg88ae23e2000-03-08 23:35:19 +0000391}
392
Neil Boothdd07b882000-11-20 18:27:32 +0000393/* Sets internal flags correctly for a given language, and defines
394 macros if necessary. */
Zack Weinberga01eb542001-07-02 18:55:35 +0000395
396struct lang_flags
397{
398 char c99;
399 char objc;
400 char cplusplus;
401 char extended_numbers;
402 char trigraphs;
403 char dollars_in_ident;
404 char cplusplus_comments;
405 char digraphs;
406};
407
408/* ??? Enable $ in identifiers in assembly? */
409static const struct lang_flags lang_defaults[] =
410{ /* c99 objc c++ xnum trig dollar c++comm digr */
411 /* GNUC89 */ { 0, 0, 0, 1, 0, 1, 1, 1 },
412 /* GNUC99 */ { 1, 0, 0, 1, 0, 1, 1, 1 },
413 /* STDC89 */ { 0, 0, 0, 0, 1, 0, 0, 0 },
414 /* STDC94 */ { 0, 0, 0, 0, 1, 0, 0, 1 },
415 /* STDC99 */ { 1, 0, 0, 1, 1, 0, 1, 1 },
416 /* GNUCXX */ { 0, 0, 1, 1, 0, 1, 1, 1 },
417 /* CXX98 */ { 0, 0, 1, 1, 1, 0, 1, 1 },
418 /* OBJC */ { 0, 1, 0, 1, 0, 1, 1, 1 },
419 /* OBJCXX */ { 0, 1, 1, 1, 0, 1, 1, 1 },
420 /* ASM */ { 0, 0, 0, 1, 0, 0, 1, 0 }
421};
422
Neil Boothdd07b882000-11-20 18:27:32 +0000423static void
424set_lang (pfile, lang)
425 cpp_reader *pfile;
426 enum c_lang lang;
427{
Zack Weinberga01eb542001-07-02 18:55:35 +0000428 const struct lang_flags *l = &lang_defaults[(int) lang];
429
Neil Boothbdb05a72000-11-26 17:31:13 +0000430 CPP_OPTION (pfile, lang) = lang;
Neil Boothdd07b882000-11-20 18:27:32 +0000431
Zack Weinberga01eb542001-07-02 18:55:35 +0000432 CPP_OPTION (pfile, c99) = l->c99;
433 CPP_OPTION (pfile, objc) = l->objc;
434 CPP_OPTION (pfile, cplusplus) = l->cplusplus;
435 CPP_OPTION (pfile, extended_numbers) = l->extended_numbers;
436 CPP_OPTION (pfile, trigraphs) = l->trigraphs;
437 CPP_OPTION (pfile, dollars_in_ident) = l->dollars_in_ident;
438 CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments;
439 CPP_OPTION (pfile, digraphs) = l->digraphs;
Neil Boothdd07b882000-11-20 18:27:32 +0000440}
441
Neil Boothcf44ea52000-11-28 21:13:35 +0000442#ifdef HOST_EBCDIC
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000443static int opt_comp PARAMS ((const void *, const void *));
444
445/* Run-time sorting of options array. */
446static int
447opt_comp (p1, p2)
448 const void *p1, *p2;
449{
450 return strcmp (((struct cl_option *) p1)->opt_text,
451 ((struct cl_option *) p2)->opt_text);
452}
Neil Boothcf44ea52000-11-28 21:13:35 +0000453#endif
454
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000455/* init initializes library global state. It might not need to
456 do anything depending on the platform and compiler. */
Neil Boothcf44ea52000-11-28 21:13:35 +0000457
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000458static void
Neil Booth674c3b42001-01-08 18:52:09 +0000459init_library ()
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000460{
461 static int initialized = 0;
462
463 if (! initialized)
464 {
465 initialized = 1;
466
467#ifdef HOST_EBCDIC
468 /* For non-ASCII hosts, the cl_options array needs to be sorted at
469 runtime. */
470 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
471#endif
472
473 /* Set up the trigraph map. This doesn't need to do anything if
474 we were compiled with a compiler that supports C99 designated
475 initializers. */
476 init_trigraph_map ();
477 }
Neil Boothcf44ea52000-11-28 21:13:35 +0000478}
479
Kazu Hirataec5c56d2001-08-01 17:57:27 +0000480/* Initialize a cpp_reader structure. */
Neil Boothcf44ea52000-11-28 21:13:35 +0000481cpp_reader *
Neil Boothf5e99452001-11-15 10:01:10 +0000482cpp_create_reader (lang)
Neil Boothdd07b882000-11-20 18:27:32 +0000483 enum c_lang lang;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000484{
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000485 cpp_reader *pfile;
Neil Booth93c803682000-10-28 17:59:06 +0000486
Neil Boothcf44ea52000-11-28 21:13:35 +0000487 /* Initialise this instance of the library if it hasn't been already. */
Neil Booth674c3b42001-01-08 18:52:09 +0000488 init_library ();
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000489
490 pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
Neil Booth93c803682000-10-28 17:59:06 +0000491
Neil Boothc740cee2001-02-20 22:52:11 +0000492 set_lang (pfile, lang);
Zack Weinbergae796972000-03-31 23:16:11 +0000493 CPP_OPTION (pfile, warn_import) = 1;
494 CPP_OPTION (pfile, discard_comments) = 1;
495 CPP_OPTION (pfile, show_column) = 1;
Neil Booth6ab3e7d2000-05-18 11:09:27 +0000496 CPP_OPTION (pfile, tabstop) = 8;
Jakub Jelinekbe768052000-12-15 16:49:28 +0100497 CPP_OPTION (pfile, operator_names) = 1;
Zack Weinbergae796972000-03-31 23:16:11 +0000498
499 CPP_OPTION (pfile, pending) =
500 (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
501
Neil Boothf7114e12001-01-06 00:15:29 +0000502 /* It's simplest to just create this struct whether or not it will
503 be needed. */
504 pfile->deps = deps_init ();
505
Neil Booth50410422001-09-15 10:18:03 +0000506 /* Initialise the line map. Start at logical line 1, so we can use
507 a line number of zero for special states. */
Neil Boothd82fc102001-08-02 23:03:31 +0000508 init_line_maps (&pfile->line_maps);
Neil Booth50410422001-09-15 10:18:03 +0000509 pfile->line = 1;
Neil Boothd82fc102001-08-02 23:03:31 +0000510
Neil Booth4a58aab2000-11-18 12:18:09 +0000511 /* Initialize lexer state. */
Neil Booth93c803682000-10-28 17:59:06 +0000512 pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
Zack Weinberg3cb553b2000-08-20 21:36:18 +0000513
Neil Booth4ed5bcf2001-09-24 22:53:12 +0000514 /* Set up static tokens. */
Neil Booth93c803682000-10-28 17:59:06 +0000515 pfile->date.type = CPP_EOF;
Neil Booth4ed5bcf2001-09-24 22:53:12 +0000516 pfile->avoid_paste.type = CPP_PADDING;
517 pfile->avoid_paste.val.source = NULL;
518 pfile->eof.type = CPP_EOF;
519 pfile->eof.flags = 0;
Neil Booth93c803682000-10-28 17:59:06 +0000520
Neil Booth5fddcff2001-09-11 07:00:12 +0000521 /* Create a token buffer for the lexer. */
522 _cpp_init_tokenrun (&pfile->base_run, 250);
523 pfile->cur_run = &pfile->base_run;
524 pfile->cur_token = pfile->base_run.base;
Neil Booth5fddcff2001-09-11 07:00:12 +0000525
Neil Booth93c803682000-10-28 17:59:06 +0000526 /* Initialise the base context. */
527 pfile->context = &pfile->base_context;
528 pfile->base_context.macro = 0;
529 pfile->base_context.prev = pfile->base_context.next = 0;
530
Neil Booth8c3b2692001-09-30 10:03:11 +0000531 /* Aligned and unaligned storage. */
532 pfile->a_buff = _cpp_get_buff (pfile, 0);
Neil Boothece54d52001-09-28 09:40:22 +0000533 pfile->u_buff = _cpp_get_buff (pfile, 0);
Neil Booth93c803682000-10-28 17:59:06 +0000534
Neil Booth2a967f32001-05-20 06:26:45 +0000535 /* Initialise the buffer obstack. */
536 gcc_obstack_init (&pfile->buffer_ob);
537
Zack Weinbergc71f8352000-07-05 05:33:57 +0000538 _cpp_init_includes (pfile);
Neil Boothcf44ea52000-11-28 21:13:35 +0000539
540 return pfile;
Zack Weinbergf2d5f0c2000-04-14 23:29:45 +0000541}
542
Neil Booth400023a2001-01-14 22:00:20 +0000543/* Free resources used by PFILE. Accessing PFILE after this function
544 returns leads to undefined behaviour. */
545int
546cpp_destroy (pfile)
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000547 cpp_reader *pfile;
548{
Neil Booth400023a2001-01-14 22:00:20 +0000549 int result;
Neil Booth591e15a2001-03-02 07:35:12 +0000550 struct search_path *dir, *dirn;
Neil Booth93c803682000-10-28 17:59:06 +0000551 cpp_context *context, *contextn;
Neil Booth50410422001-09-15 10:18:03 +0000552 tokenrun *run, *runn;
Neil Booth709e9e52000-08-17 18:01:43 +0000553
Zack Weinberg38b24ee2000-03-08 20:37:23 +0000554 while (CPP_BUFFER (pfile) != NULL)
Neil Boothef6e9582001-08-04 12:01:59 +0000555 _cpp_pop_buffer (pfile);
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000556
Neil Booth93c803682000-10-28 17:59:06 +0000557 if (pfile->macro_buffer)
Alexandre Oliva4b49c362001-01-09 09:30:43 +0000558 {
559 free ((PTR) pfile->macro_buffer);
560 pfile->macro_buffer = NULL;
561 pfile->macro_buffer_len = 0;
562 }
Neil Booth93c803682000-10-28 17:59:06 +0000563
Neil Boothf7114e12001-01-06 00:15:29 +0000564 deps_free (pfile->deps);
Neil Booth2a967f32001-05-20 06:26:45 +0000565 obstack_free (&pfile->buffer_ob, 0);
Zack Weinberg49e6c082000-03-04 19:42:04 +0000566
Neil Booth2a967f32001-05-20 06:26:45 +0000567 _cpp_destroy_hashtable (pfile);
Zack Weinbergbfb9dc72000-07-08 19:00:39 +0000568 _cpp_cleanup_includes (pfile);
Neil Booth93c803682000-10-28 17:59:06 +0000569
Neil Booth8c3b2692001-09-30 10:03:11 +0000570 _cpp_free_buff (pfile->a_buff);
Neil Boothece54d52001-09-28 09:40:22 +0000571 _cpp_free_buff (pfile->u_buff);
Neil Boothb8af0ca2001-09-26 17:52:50 +0000572 _cpp_free_buff (pfile->free_buffs);
Neil Booth93c803682000-10-28 17:59:06 +0000573
Neil Booth50410422001-09-15 10:18:03 +0000574 for (run = &pfile->base_run; run; run = runn)
575 {
576 runn = run->next;
577 free (run->base);
578 if (run != &pfile->base_run)
579 free (run);
580 }
581
Neil Booth93c803682000-10-28 17:59:06 +0000582 for (dir = CPP_OPTION (pfile, quote_include); dir; dir = dirn)
Neil Booth709e9e52000-08-17 18:01:43 +0000583 {
Neil Booth93c803682000-10-28 17:59:06 +0000584 dirn = dir->next;
Neil Booth591e15a2001-03-02 07:35:12 +0000585 free ((PTR) dir->name);
Neil Booth709e9e52000-08-17 18:01:43 +0000586 free (dir);
587 }
Neil Booth93c803682000-10-28 17:59:06 +0000588
589 for (context = pfile->base_context.next; context; context = contextn)
590 {
591 contextn = context->next;
592 free (context);
593 }
Neil Booth400023a2001-01-14 22:00:20 +0000594
Neil Boothd82fc102001-08-02 23:03:31 +0000595 free_line_maps (&pfile->line_maps);
596
Neil Booth400023a2001-01-14 22:00:20 +0000597 result = pfile->errors;
598 free (pfile);
599
600 return result;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000601}
602
603
Neil Booth93c803682000-10-28 17:59:06 +0000604/* This structure defines one built-in identifier. A node will be
605 entered in the hash table under the name NAME, with value VALUE (if
606 any). If flags has OPERATOR, the node's operator field is used; if
Neil Booth618cdda2001-02-25 09:43:03 +0000607 flags has BUILTIN the node's builtin field is used. Macros that are
608 known at build time should not be flagged BUILTIN, as then they do
609 not appear in macro dumps with e.g. -dM or -dD.
Zack Weinberg92936ec2000-07-19 20:18:08 +0000610
611 Two values are not compile time constants, so we tag
Zack Weinberg041c3192000-07-04 01:58:21 +0000612 them in the FLAGS field instead:
Zack Weinberg8c389f82000-04-10 03:27:21 +0000613 VERS value is the global version_string, quoted
614 ULP value is the global user_label_prefix
Zack Weinberg92936ec2000-07-19 20:18:08 +0000615
Neil Booth93c803682000-10-28 17:59:06 +0000616 Also, macros with CPLUS set in the flags field are entered only for C++. */
Zack Weinberga9ae4481999-10-29 04:31:14 +0000617
618struct builtin
619{
Zack Weinberg12cf91f2000-05-04 04:38:01 +0000620 const U_CHAR *name;
Zack Weinberg041c3192000-07-04 01:58:21 +0000621 const char *value;
Neil Booth93c803682000-10-28 17:59:06 +0000622 unsigned char builtin;
623 unsigned char operator;
Zack Weinberga9ae4481999-10-29 04:31:14 +0000624 unsigned short flags;
Neil Booth93c803682000-10-28 17:59:06 +0000625 unsigned short len;
Zack Weinberga9ae4481999-10-29 04:31:14 +0000626};
Neil Booth93c803682000-10-28 17:59:06 +0000627#define VERS 0x01
628#define ULP 0x02
629#define CPLUS 0x04
630#define BUILTIN 0x08
631#define OPERATOR 0x10
Zack Weinberga9ae4481999-10-29 04:31:14 +0000632
Neil Booth93c803682000-10-28 17:59:06 +0000633#define B(n, t) { U n, 0, t, 0, BUILTIN, sizeof n - 1 }
634#define C(n, v) { U n, v, 0, 0, 0, sizeof n - 1 }
635#define X(n, f) { U n, 0, 0, 0, f, sizeof n - 1 }
636#define O(n, c, f) { U n, 0, 0, c, OPERATOR | f, sizeof n - 1 }
Zack Weinberga9ae4481999-10-29 04:31:14 +0000637static const struct builtin builtin_array[] =
638{
Neil Booth93c803682000-10-28 17:59:06 +0000639 B("__TIME__", BT_TIME),
640 B("__DATE__", BT_DATE),
641 B("__FILE__", BT_FILE),
642 B("__BASE_FILE__", BT_BASE_FILE),
643 B("__LINE__", BT_SPECLINE),
644 B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
Neil Booth644edda2001-10-02 12:57:24 +0000645 B("_Pragma", BT_PRAGMA),
Zack Weinberga9ae4481999-10-29 04:31:14 +0000646
Zack Weinberg041c3192000-07-04 01:58:21 +0000647 X("__VERSION__", VERS),
648 X("__USER_LABEL_PREFIX__", ULP),
Zack Weinberg12cf91f2000-05-04 04:38:01 +0000649 C("__REGISTER_PREFIX__", REGISTER_PREFIX),
650 C("__HAVE_BUILTIN_SETJMP__", "1"),
Zack Weinberga9ae4481999-10-29 04:31:14 +0000651#ifndef NO_BUILTIN_SIZE_TYPE
Zack Weinberg12cf91f2000-05-04 04:38:01 +0000652 C("__SIZE_TYPE__", SIZE_TYPE),
Zack Weinberga9ae4481999-10-29 04:31:14 +0000653#endif
654#ifndef NO_BUILTIN_PTRDIFF_TYPE
Zack Weinberg12cf91f2000-05-04 04:38:01 +0000655 C("__PTRDIFF_TYPE__", PTRDIFF_TYPE),
Zack Weinberga9ae4481999-10-29 04:31:14 +0000656#endif
Zack Weinberg0209c342000-02-28 21:09:54 +0000657#ifndef NO_BUILTIN_WCHAR_TYPE
Zack Weinberg12cf91f2000-05-04 04:38:01 +0000658 C("__WCHAR_TYPE__", WCHAR_TYPE),
Zack Weinberg0209c342000-02-28 21:09:54 +0000659#endif
Joseph Myersd6777972000-08-04 13:45:57 +0100660#ifndef NO_BUILTIN_WINT_TYPE
661 C("__WINT_TYPE__", WINT_TYPE),
662#endif
Neil Booth618cdda2001-02-25 09:43:03 +0000663#ifdef STDC_0_IN_SYSTEM_HEADERS
664 B("__STDC__", BT_STDC),
665#else
666 C("__STDC__", "1"),
667#endif
Zack Weinberg92936ec2000-07-19 20:18:08 +0000668
669 /* Named operators known to the preprocessor. These cannot be #defined
670 and always have their stated meaning. They are treated like normal
Neil Booth93c803682000-10-28 17:59:06 +0000671 identifiers except for the type code and the meaning. Most of them
Zack Weinberg92936ec2000-07-19 20:18:08 +0000672 are only for C++ (but see iso646.h). */
Zack Weinberg92936ec2000-07-19 20:18:08 +0000673 O("and", CPP_AND_AND, CPLUS),
674 O("and_eq", CPP_AND_EQ, CPLUS),
675 O("bitand", CPP_AND, CPLUS),
676 O("bitor", CPP_OR, CPLUS),
677 O("compl", CPP_COMPL, CPLUS),
678 O("not", CPP_NOT, CPLUS),
679 O("not_eq", CPP_NOT_EQ, CPLUS),
680 O("or", CPP_OR_OR, CPLUS),
681 O("or_eq", CPP_OR_EQ, CPLUS),
682 O("xor", CPP_XOR, CPLUS),
Neil Booth93c803682000-10-28 17:59:06 +0000683 O("xor_eq", CPP_XOR_EQ, CPLUS)
Zack Weinberga9ae4481999-10-29 04:31:14 +0000684};
Zack Weinberg12cf91f2000-05-04 04:38:01 +0000685#undef B
686#undef C
687#undef X
Jakub Jelinekbe768052000-12-15 16:49:28 +0100688#undef O
Zack Weinberg8c389f82000-04-10 03:27:21 +0000689#define builtin_array_end \
690 builtin_array + sizeof(builtin_array)/sizeof(struct builtin)
Zack Weinberga9ae4481999-10-29 04:31:14 +0000691
Neil Boothf5e99452001-11-15 10:01:10 +0000692/* Subroutine of cpp_read_main_file; reads the builtins table above and
Zack Weinberga9ae4481999-10-29 04:31:14 +0000693 enters the macros into the hash table. */
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000694static void
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000695init_builtins (pfile)
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000696 cpp_reader *pfile;
697{
Zack Weinberga9ae4481999-10-29 04:31:14 +0000698 const struct builtin *b;
Neil Booth771c4df2000-09-07 20:31:06 +0000699
Zack Weinberg8c389f82000-04-10 03:27:21 +0000700 for(b = builtin_array; b < builtin_array_end; b++)
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000701 {
Neil Booth93c803682000-10-28 17:59:06 +0000702 if ((b->flags & CPLUS) && ! CPP_OPTION (pfile, cplusplus))
Zack Weinberg92936ec2000-07-19 20:18:08 +0000703 continue;
704
Jakub Jelinekbe768052000-12-15 16:49:28 +0100705 if ((b->flags & OPERATOR) && ! CPP_OPTION (pfile, operator_names))
706 continue;
707
Neil Booth93c803682000-10-28 17:59:06 +0000708 if (b->flags & (OPERATOR | BUILTIN))
709 {
710 cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
711 if (b->flags & OPERATOR)
712 {
713 hp->flags |= NODE_OPERATOR;
714 hp->value.operator = b->operator;
715 }
716 else
717 {
718 hp->type = NT_MACRO;
Neil Booth618cdda2001-02-25 09:43:03 +0000719 hp->flags |= NODE_BUILTIN | NODE_WARN;
Neil Booth93c803682000-10-28 17:59:06 +0000720 hp->value.builtin = b->builtin;
721 }
722 }
723 else /* A standard macro of some kind. */
Zack Weinberg8c389f82000-04-10 03:27:21 +0000724 {
Zack Weinberg041c3192000-07-04 01:58:21 +0000725 const char *val;
726 char *str;
727
728 if (b->flags & VERS)
729 {
Zack Weinberg2c8f0512000-08-29 18:37:37 +0000730 /* Allocate enough space for 'name "value"\n\0'. */
731 str = alloca (b->len + strlen (version_string) + 5);
732 sprintf (str, "%s \"%s\"\n", b->name, version_string);
Zack Weinberg041c3192000-07-04 01:58:21 +0000733 }
734 else
735 {
736 if (b->flags & ULP)
Neil Booth771c4df2000-09-07 20:31:06 +0000737 val = CPP_OPTION (pfile, user_label_prefix);
Zack Weinberg041c3192000-07-04 01:58:21 +0000738 else
739 val = b->value;
740
Zack Weinberg2c8f0512000-08-29 18:37:37 +0000741 /* Allocate enough space for "name value\n\0". */
742 str = alloca (b->len + strlen (val) + 3);
743 sprintf(str, "%s %s\n", b->name, val);
Zack Weinberg041c3192000-07-04 01:58:21 +0000744 }
Neil Boothc154ba62000-08-17 17:52:48 +0000745
Zack Weinberg2c8f0512000-08-29 18:37:37 +0000746 _cpp_define_builtin (pfile, str);
Zack Weinberg8c389f82000-04-10 03:27:21 +0000747 }
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000748 }
Neil Boothc740cee2001-02-20 22:52:11 +0000749
750 if (CPP_OPTION (pfile, cplusplus))
Neil Booth618cdda2001-02-25 09:43:03 +0000751 {
752 _cpp_define_builtin (pfile, "__cplusplus 1");
753 if (SUPPORTS_ONE_ONLY)
754 _cpp_define_builtin (pfile, "__GXX_WEAK__ 1");
755 else
756 _cpp_define_builtin (pfile, "__GXX_WEAK__ 0");
757 }
Neil Boothc740cee2001-02-20 22:52:11 +0000758 if (CPP_OPTION (pfile, objc))
759 _cpp_define_builtin (pfile, "__OBJC__ 1");
760
761 if (CPP_OPTION (pfile, lang) == CLK_STDC94)
762 _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
763 else if (CPP_OPTION (pfile, c99))
764 _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
765
766 if (CPP_OPTION (pfile, lang) == CLK_STDC89
767 || CPP_OPTION (pfile, lang) == CLK_STDC94
768 || CPP_OPTION (pfile, lang) == CLK_STDC99)
769 _cpp_define_builtin (pfile, "__STRICT_ANSI__ 1");
770 else if (CPP_OPTION (pfile, lang) == CLK_ASM)
771 _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000772}
Neil Booth93c803682000-10-28 17:59:06 +0000773#undef BUILTIN
774#undef OPERATOR
Zack Weinberg6feb7722000-03-13 00:10:13 +0000775#undef VERS
Zack Weinberga9ae4481999-10-29 04:31:14 +0000776#undef ULP
Neil Booth93c803682000-10-28 17:59:06 +0000777#undef CPLUS
Zack Weinberg041c3192000-07-04 01:58:21 +0000778#undef builtin_array_end
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000779
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000780/* And another subroutine. This one sets up the standard include path. */
781static void
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000782init_standard_includes (pfile)
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000783 cpp_reader *pfile;
784{
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000785 char *path;
Zack Weinberg455d2582000-03-04 01:42:56 +0000786 const struct default_include *p;
Zack Weinbergae796972000-03-31 23:16:11 +0000787 const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000788
789 /* Several environment variables may add to the include search path.
790 CPATH specifies an additional list of directories to be searched
791 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
792 etc. specify an additional list of directories to be searched as
793 if specified with -isystem, for the language indicated. */
794
795 GET_ENV_PATH_LIST (path, "CPATH");
796 if (path != 0 && *path != 0)
Neil Boothe33f6252000-08-17 17:58:24 +0000797 path_include (pfile, path, BRACKET);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000798
Zack Weinbergae796972000-03-31 23:16:11 +0000799 switch ((CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus))
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000800 {
801 case 0:
802 GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH");
803 break;
804 case 1:
805 GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH");
806 break;
807 case 2:
808 GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH");
809 break;
810 case 3:
811 GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH");
812 break;
813 }
814 if (path != 0 && *path != 0)
Neil Boothe33f6252000-08-17 17:58:24 +0000815 path_include (pfile, path, SYSTEM);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000816
817 /* Search "translated" versions of GNU directories.
818 These have /usr/local/lib/gcc... replaced by specd_prefix. */
Zack Weinberg60893f42000-07-06 22:52:03 +0000819 if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len)
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000820 {
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000821 /* Remove the `include' from /usr/local/lib/gcc.../include.
Kazu Hirataec5c56d2001-08-01 17:57:27 +0000822 GCC_INCLUDE_DIR will always end in /include. */
Zack Weinberg60893f42000-07-06 22:52:03 +0000823 int default_len = cpp_GCC_INCLUDE_DIR_len;
824 char *default_prefix = (char *) alloca (default_len + 1);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000825 int specd_len = strlen (specd_prefix);
826
Zack Weinberg60893f42000-07-06 22:52:03 +0000827 memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000828 default_prefix[default_len] = '\0';
829
Zack Weinberg60893f42000-07-06 22:52:03 +0000830 for (p = cpp_include_defaults; p->fname; p++)
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000831 {
832 /* Some standard dirs are only for C++. */
833 if (!p->cplusplus
Zack Weinbergae796972000-03-31 23:16:11 +0000834 || (CPP_OPTION (pfile, cplusplus)
835 && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000836 {
837 /* Does this dir start with the prefix? */
Neil Booth61d03462000-08-18 17:35:58 +0000838 if (!memcmp (p->fname, default_prefix, default_len))
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000839 {
840 /* Yes; change prefix and add to search list. */
841 int flen = strlen (p->fname);
842 int this_len = specd_len + flen - default_len;
843 char *str = (char *) xmalloc (this_len + 1);
844 memcpy (str, specd_prefix, specd_len);
845 memcpy (str + specd_len,
846 p->fname + default_len,
847 flen - default_len + 1);
848
Neil Boothe33f6252000-08-17 17:58:24 +0000849 append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000850 }
851 }
852 }
853 }
854
855 /* Search ordinary names for GNU include directories. */
Zack Weinberg60893f42000-07-06 22:52:03 +0000856 for (p = cpp_include_defaults; p->fname; p++)
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000857 {
858 /* Some standard dirs are only for C++. */
859 if (!p->cplusplus
Zack Weinbergae796972000-03-31 23:16:11 +0000860 || (CPP_OPTION (pfile, cplusplus)
861 && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000862 {
Neil Booth51c04252001-08-20 06:14:53 +0000863 char *str = update_path (p->fname, p->component);
Neil Boothe33f6252000-08-17 17:58:24 +0000864 append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000865 }
866 }
867}
868
Neil Boothd7bc7a92001-08-21 06:20:18 +0000869/* Pushes a -imacro and -include file given on the command line onto
870 the buffer stack. Returns non-zero if successful. */
871static bool
872push_include (pfile, p)
Neil Booth4a58aab2000-11-18 12:18:09 +0000873 cpp_reader *pfile;
874 struct pending_option *p;
Neil Booth4a58aab2000-11-18 12:18:09 +0000875{
Neil Boothd7bc7a92001-08-21 06:20:18 +0000876 cpp_token header;
Neil Booth4a58aab2000-11-18 12:18:09 +0000877
Neil Boothd7bc7a92001-08-21 06:20:18 +0000878 /* Later: maybe update this to use the #include "" search path
879 if cpp_read_file fails. */
880 header.type = CPP_STRING;
881 header.val.str.text = (const unsigned char *) p->arg;
882 header.val.str.len = strlen (p->arg);
883 /* Make the command line directive take up a line. */
Neil Booth50410422001-09-15 10:18:03 +0000884 pfile->line++;
Neil Boothd7bc7a92001-08-21 06:20:18 +0000885
886 return _cpp_execute_include (pfile, &header, IT_CMDLINE);
887}
888
889/* Frees a pending_option chain. */
890static void
891free_chain (head)
892 struct pending_option *head;
893{
894 struct pending_option *next;
895
896 while (head)
897 {
898 next = head->next;
899 free (head);
900 head = next;
Neil Booth4a58aab2000-11-18 12:18:09 +0000901 }
902}
903
Neil Boothf5e99452001-11-15 10:01:10 +0000904/* This is called after options have been parsed, and partially
905 processed. Setup for processing input from the file named FNAME,
906 or stdin if it is the empty string. Return the original filename
907 on success (e.g. foo.i->foo.c), or NULL on failure. */
908const char *
909cpp_read_main_file (pfile, fname, table)
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000910 cpp_reader *pfile;
Neil Booth7ceb3592000-03-11 00:49:44 +0000911 const char *fname;
Neil Boothf5e99452001-11-15 10:01:10 +0000912 hash_table *table;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +0000913{
Neil Boothf5e99452001-11-15 10:01:10 +0000914 /* The front ends don't set up the hash table until they have
915 finished processing the command line options, so initializing the
916 hashtable is deferred until now. */
917 _cpp_init_hashtable (pfile, table);
918
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000919 /* Set up the include search path now. */
Zack Weinbergae796972000-03-31 23:16:11 +0000920 if (! CPP_OPTION (pfile, no_standard_includes))
Neil Booth7ca3d2b2001-01-07 11:15:13 +0000921 init_standard_includes (pfile);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000922
Zack Weinbergae796972000-03-31 23:16:11 +0000923 merge_include_chains (pfile);
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000924
925 /* With -v, print the list of dirs to search. */
Zack Weinbergae796972000-03-31 23:16:11 +0000926 if (CPP_OPTION (pfile, verbose))
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000927 {
Neil Booth591e15a2001-03-02 07:35:12 +0000928 struct search_path *l;
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000929 fprintf (stderr, _("#include \"...\" search starts here:\n"));
Zack Weinbergae796972000-03-31 23:16:11 +0000930 for (l = CPP_OPTION (pfile, quote_include); l; l = l->next)
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000931 {
Zack Weinbergae796972000-03-31 23:16:11 +0000932 if (l == CPP_OPTION (pfile, bracket_include))
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000933 fprintf (stderr, _("#include <...> search starts here:\n"));
934 fprintf (stderr, " %s\n", l->name);
935 }
936 fprintf (stderr, _("End of search list.\n"));
937 }
938
Neil Booth96302432001-01-07 15:17:07 +0000939 if (CPP_OPTION (pfile, print_deps))
Jakub Jelinek7855db72001-01-24 19:44:40 +0100940 /* Set the default target (if there is none already). */
Neil Booth373e2172001-02-21 07:29:56 +0000941 deps_add_default_target (pfile->deps, fname);
Neil Booth96302432001-01-07 15:17:07 +0000942
Neil Boothf5e99452001-11-15 10:01:10 +0000943 /* Open the main input file. */
Neil Booth614c7d32000-12-04 07:32:04 +0000944 if (!_cpp_read_file (pfile, fname))
Neil Boothf5e99452001-11-15 10:01:10 +0000945 return NULL;
Zack Weinbergc45da1c2000-03-02 20:14:32 +0000946
Neil Booth59930192001-08-21 21:17:48 +0000947 /* Set this after cpp_post_options so the client can change the
948 option if it wishes, and after stacking the main file so we don't
949 trace the main file. */
950 pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names);
951
Neil Boothf5e99452001-11-15 10:01:10 +0000952 /* For foo.i, read the original filename foo.c now, for the benefit
953 of the front ends. */
954 if (CPP_OPTION (pfile, preprocessed))
955 read_original_filename (pfile);
956
957 return pfile->map->to_file;
958}
959
960/* For preprocessed files, if the first tokens are of the form # NUM.
961 handle the directive so we know the original file name. This will
962 generate file_change callbacks, which the front ends must handle
963 appropriately given their state of initialization. */
964static void
965read_original_filename (pfile)
966 cpp_reader *pfile;
967{
968 const cpp_token *token, *token1;
969
970 /* Lex ahead; if the first tokens are of the form # NUM, then
971 process the directive, otherwise back up. */
972 token = _cpp_lex_direct (pfile);
973 if (token->type == CPP_HASH)
974 {
975 token1 = _cpp_lex_direct (pfile);
976 _cpp_backup_tokens (pfile, 1);
977
978 /* If it's a #line directive, handle it. */
979 if (token1->type == CPP_NUMBER)
980 {
981 _cpp_handle_directive (pfile, token->flags & PREV_WHITE);
982 return;
983 }
984 }
985
986 /* Backup as if nothing happened. */
987 _cpp_backup_tokens (pfile, 1);
988}
989
990/* Handle pending command line options: -D, -U, -A, -imacros and
991 -include. This should be called after debugging has been properly
992 set up in the front ends. */
993void
994cpp_finish_options (pfile)
995 cpp_reader *pfile;
996{
Neil Boothd7bc7a92001-08-21 06:20:18 +0000997 /* Install builtins and process command line macros etc. in the order
998 they appeared, but only if not already preprocessed. */
Neil Booth05e81722001-01-11 21:30:16 +0000999 if (! CPP_OPTION (pfile, preprocessed))
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001000 {
Neil Boothd7bc7a92001-08-21 06:20:18 +00001001 struct pending_option *p;
1002
1003 _cpp_do_file_change (pfile, LC_RENAME, _("<builtin>"), 1, 0);
1004 init_builtins (pfile);
1005 _cpp_do_file_change (pfile, LC_RENAME, _("<command line>"), 1, 0);
1006 for (p = CPP_OPTION (pfile, pending)->directive_head; p; p = p->next)
Neil Booth05e81722001-01-11 21:30:16 +00001007 (*p->handler) (pfile, p->arg);
Neil Boothd7bc7a92001-08-21 06:20:18 +00001008
1009 /* Scan -imacros files after command line defines, but before
1010 files given with -include. */
Neil Booth53aabfb2001-09-01 10:22:17 +00001011 while ((p = CPP_OPTION (pfile, pending)->imacros_head) != NULL)
Neil Boothd7bc7a92001-08-21 06:20:18 +00001012 {
1013 if (push_include (pfile, p))
1014 {
1015 pfile->buffer->return_at_eof = true;
1016 cpp_scan_nooutput (pfile);
1017 }
Neil Booth53aabfb2001-09-01 10:22:17 +00001018 CPP_OPTION (pfile, pending)->imacros_head = p->next;
1019 free (p);
Neil Boothd7bc7a92001-08-21 06:20:18 +00001020 }
Zack Weinberg0b22d651999-03-15 18:42:46 +00001021 }
Neil Booth05e81722001-01-11 21:30:16 +00001022
Neil Boothd7bc7a92001-08-21 06:20:18 +00001023 free_chain (CPP_OPTION (pfile, pending)->directive_head);
Neil Boothd7bc7a92001-08-21 06:20:18 +00001024 _cpp_push_next_buffer (pfile);
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001025}
1026
Neil Boothd7bc7a92001-08-21 06:20:18 +00001027/* Called to push the next buffer on the stack given by -include. If
1028 there are none, free the pending structure and restore the line map
1029 for the main file. */
1030bool
1031_cpp_push_next_buffer (pfile)
1032 cpp_reader *pfile;
1033{
1034 bool pushed = false;
1035
Neil Booth53aabfb2001-09-01 10:22:17 +00001036 /* This is't pretty; we'd rather not be relying on this as a boolean
1037 for reverting the line map. Further, we only free the chains in
1038 this conditional, so an early call to cpp_finish / cpp_destroy
1039 will leak that memory. */
1040 if (CPP_OPTION (pfile, pending)
1041 && CPP_OPTION (pfile, pending)->imacros_head == NULL)
Neil Boothd7bc7a92001-08-21 06:20:18 +00001042 {
1043 while (!pushed)
1044 {
1045 struct pending_option *p = CPP_OPTION (pfile, pending)->include_head;
1046
1047 if (p == NULL)
1048 break;
1049 if (! CPP_OPTION (pfile, preprocessed))
1050 pushed = push_include (pfile, p);
1051 CPP_OPTION (pfile, pending)->include_head = p->next;
1052 free (p);
1053 }
1054
1055 if (!pushed)
1056 {
1057 free (CPP_OPTION (pfile, pending));
1058 CPP_OPTION (pfile, pending) = NULL;
1059
1060 /* Restore the line map for the main file. */
1061 if (! CPP_OPTION (pfile, preprocessed))
1062 _cpp_do_file_change (pfile, LC_RENAME,
1063 pfile->line_maps.maps[0].to_file, 1, 0);
1064 }
1065 }
1066
1067 return pushed;
1068}
1069
Neil Booth2f638f92001-01-10 23:28:00 +00001070/* Use mkdeps.c to output dependency information. */
Neil Booth7ca3d2b2001-01-07 11:15:13 +00001071static void
1072output_deps (pfile)
1073 cpp_reader *pfile;
1074{
1075 /* Stream on which to print the dependency information. */
1076 FILE *deps_stream = 0;
Kaveh R. Ghazi27c38fb2001-09-12 17:18:03 +00001077 const char *const deps_mode =
1078 CPP_OPTION (pfile, print_deps_append) ? "a" : "w";
Neil Booth7ca3d2b2001-01-07 11:15:13 +00001079
1080 if (CPP_OPTION (pfile, deps_file) == 0)
1081 deps_stream = stdout;
1082 else
1083 {
1084 deps_stream = fopen (CPP_OPTION (pfile, deps_file), deps_mode);
1085 if (deps_stream == 0)
1086 {
1087 cpp_notice_from_errno (pfile, CPP_OPTION (pfile, deps_file));
1088 return;
1089 }
1090 }
1091
1092 deps_write (pfile->deps, deps_stream, 72);
1093
1094 if (CPP_OPTION (pfile, deps_phony_targets))
1095 deps_phony_targets (pfile->deps, deps_stream);
1096
1097 /* Don't close stdout. */
1098 if (CPP_OPTION (pfile, deps_file))
1099 {
1100 if (ferror (deps_stream) || fclose (deps_stream) != 0)
1101 cpp_fatal (pfile, "I/O error on output");
1102 }
1103}
1104
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001105/* This is called at the end of preprocessing. It pops the
1106 last buffer and writes dependency output. It should also
1107 clear macro definitions, such that you could call cpp_start_read
Neil Booth4a58aab2000-11-18 12:18:09 +00001108 with a new filename to restart processing. */
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001109void
Neil Booth93c803682000-10-28 17:59:06 +00001110cpp_finish (pfile)
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001111 cpp_reader *pfile;
1112{
Neil Booth7364fdd2001-08-07 20:37:26 +00001113 /* cpplex.c leaves the final buffer on the stack. This it so that
1114 it returns an unending stream of CPP_EOFs to the client. If we
1115 popped the buffer, we'd derefence a NULL buffer pointer and
1116 segfault. It's nice to allow the client to do worry-free excess
1117 cpp_get_token calls. */
1118 while (pfile->buffer)
1119 _cpp_pop_buffer (pfile);
Zack Weinbergc1212d22000-02-06 23:46:18 +00001120
Zack Weinberg49e6c082000-03-04 19:42:04 +00001121 /* Don't write the deps file if preprocessing has failed. */
Zack Weinbergae796972000-03-31 23:16:11 +00001122 if (CPP_OPTION (pfile, print_deps) && pfile->errors == 0)
Neil Booth7ca3d2b2001-01-07 11:15:13 +00001123 output_deps (pfile);
Zack Weinberg3caee4a1999-04-26 16:41:02 +00001124
Zack Weinbergd4506962000-06-28 19:03:08 +00001125 /* Report on headers that could use multiple include guards. */
1126 if (CPP_OPTION (pfile, print_include_names))
Zack Weinbergc71f8352000-07-05 05:33:57 +00001127 _cpp_report_missing_guards (pfile);
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001128}
1129
Richard Henderson223dca61999-12-14 08:05:23 -08001130static void
Zack Weinbergae796972000-03-31 23:16:11 +00001131new_pending_directive (pend, text, handler)
1132 struct cpp_pending *pend;
Richard Henderson223dca61999-12-14 08:05:23 -08001133 const char *text;
Neil Booth40eac642000-03-11 09:13:00 +00001134 cl_directive_handler handler;
Richard Henderson223dca61999-12-14 08:05:23 -08001135{
1136 struct pending_option *o = (struct pending_option *)
1137 xmalloc (sizeof (struct pending_option));
1138
Neil Booth7ceb3592000-03-11 00:49:44 +00001139 o->arg = text;
Richard Henderson223dca61999-12-14 08:05:23 -08001140 o->next = NULL;
Neil Booth40eac642000-03-11 09:13:00 +00001141 o->handler = handler;
Zack Weinbergae796972000-03-31 23:16:11 +00001142 APPEND (pend, directive, o);
Richard Henderson223dca61999-12-14 08:05:23 -08001143}
1144
Zack Weinbergae796972000-03-31 23:16:11 +00001145/* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
1146 I.e. a const string initializer with parens around it. That is
1147 what N_("string") resolves to, so we make no_* be macros instead. */
1148#define no_arg N_("Argument missing after %s")
1149#define no_ass N_("Assertion missing after %s")
1150#define no_dir N_("Directory name missing after %s")
1151#define no_fil N_("File name missing after %s")
1152#define no_mac N_("Macro name missing after %s")
1153#define no_pth N_("Path name missing after %s")
Neil Booth6ab3e7d2000-05-18 11:09:27 +00001154#define no_num N_("Number missing after %s")
Neil Booth03b9ab42001-01-04 10:25:55 +00001155#define no_tgt N_("Target missing after %s")
Zack Weinbergae796972000-03-31 23:16:11 +00001156
1157/* This is the list of all command line options, with the leading
1158 "-" removed. It must be sorted in ASCII collating order. */
1159#define COMMAND_LINE_OPTIONS \
Zack Weinbergae796972000-03-31 23:16:11 +00001160 DEF_OPT("$", 0, OPT_dollar) \
1161 DEF_OPT("+", 0, OPT_plus) \
1162 DEF_OPT("-help", 0, OPT__help) \
Chandra Chavva91606ce2000-11-14 12:06:06 -05001163 DEF_OPT("-target-help", 0, OPT_target__help) \
Zack Weinbergae796972000-03-31 23:16:11 +00001164 DEF_OPT("-version", 0, OPT__version) \
1165 DEF_OPT("A", no_ass, OPT_A) \
1166 DEF_OPT("C", 0, OPT_C) \
1167 DEF_OPT("D", no_mac, OPT_D) \
1168 DEF_OPT("H", 0, OPT_H) \
1169 DEF_OPT("I", no_dir, OPT_I) \
1170 DEF_OPT("M", 0, OPT_M) \
Neil Boothe5822482001-01-09 14:45:44 +00001171 DEF_OPT("MD", no_fil, OPT_MD) \
Neil Booth96302432001-01-07 15:17:07 +00001172 DEF_OPT("MF", no_fil, OPT_MF) \
Zack Weinbergae796972000-03-31 23:16:11 +00001173 DEF_OPT("MG", 0, OPT_MG) \
1174 DEF_OPT("MM", 0, OPT_MM) \
Neil Boothe5822482001-01-09 14:45:44 +00001175 DEF_OPT("MMD", no_fil, OPT_MMD) \
Neil Bootha5a4ce32001-01-05 07:50:24 +00001176 DEF_OPT("MP", 0, OPT_MP) \
Neil Boothf7114e12001-01-06 00:15:29 +00001177 DEF_OPT("MQ", no_tgt, OPT_MQ) \
Neil Booth03b9ab42001-01-04 10:25:55 +00001178 DEF_OPT("MT", no_tgt, OPT_MT) \
Zack Weinbergae796972000-03-31 23:16:11 +00001179 DEF_OPT("P", 0, OPT_P) \
1180 DEF_OPT("U", no_mac, OPT_U) \
1181 DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \
1182 DEF_OPT("d", no_arg, OPT_d) \
1183 DEF_OPT("fleading-underscore", 0, OPT_fleading_underscore) \
1184 DEF_OPT("fno-leading-underscore", 0, OPT_fno_leading_underscore) \
Jakub Jelinekbe768052000-12-15 16:49:28 +01001185 DEF_OPT("fno-operator-names", 0, OPT_fno_operator_names) \
Zack Weinbergae796972000-03-31 23:16:11 +00001186 DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \
1187 DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
1188 DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
1189 DEF_OPT("fshow-column", 0, OPT_fshow_column) \
Neil Booth6ab3e7d2000-05-18 11:09:27 +00001190 DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \
Zack Weinbergae796972000-03-31 23:16:11 +00001191 DEF_OPT("h", 0, OPT_h) \
1192 DEF_OPT("idirafter", no_dir, OPT_idirafter) \
1193 DEF_OPT("imacros", no_fil, OPT_imacros) \
1194 DEF_OPT("include", no_fil, OPT_include) \
1195 DEF_OPT("iprefix", no_pth, OPT_iprefix) \
1196 DEF_OPT("isystem", no_dir, OPT_isystem) \
1197 DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \
1198 DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \
1199 DEF_OPT("lang-asm", 0, OPT_lang_asm) \
1200 DEF_OPT("lang-c", 0, OPT_lang_c) \
1201 DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
1202 DEF_OPT("lang-c89", 0, OPT_lang_c89) \
Zack Weinbergae796972000-03-31 23:16:11 +00001203 DEF_OPT("lang-objc", 0, OPT_lang_objc) \
1204 DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus) \
1205 DEF_OPT("nostdinc", 0, OPT_nostdinc) \
1206 DEF_OPT("nostdinc++", 0, OPT_nostdincplusplus) \
1207 DEF_OPT("o", no_fil, OPT_o) \
1208 DEF_OPT("pedantic", 0, OPT_pedantic) \
1209 DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \
1210 DEF_OPT("remap", 0, OPT_remap) \
Neil Boothdd07b882000-11-20 18:27:32 +00001211 DEF_OPT("std=c++98", 0, OPT_std_cplusplus98) \
Zack Weinbergae796972000-03-31 23:16:11 +00001212 DEF_OPT("std=c89", 0, OPT_std_c89) \
1213 DEF_OPT("std=c99", 0, OPT_std_c99) \
1214 DEF_OPT("std=c9x", 0, OPT_std_c9x) \
1215 DEF_OPT("std=gnu89", 0, OPT_std_gnu89) \
1216 DEF_OPT("std=gnu99", 0, OPT_std_gnu99) \
1217 DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x) \
1218 DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990) \
1219 DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
1220 DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
1221 DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
Zack Weinbergae796972000-03-31 23:16:11 +00001222 DEF_OPT("trigraphs", 0, OPT_trigraphs) \
1223 DEF_OPT("v", 0, OPT_v) \
Zack Weinbergf4cdc362001-01-05 23:41:00 +00001224 DEF_OPT("version", 0, OPT_version) \
Zack Weinbergae796972000-03-31 23:16:11 +00001225 DEF_OPT("w", 0, OPT_w)
1226
1227#define DEF_OPT(text, msg, code) code,
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001228enum opt_code
1229{
Zack Weinbergae796972000-03-31 23:16:11 +00001230 COMMAND_LINE_OPTIONS
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001231 N_OPTS
1232};
Zack Weinbergae796972000-03-31 23:16:11 +00001233#undef DEF_OPT
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001234
1235struct cl_option
1236{
1237 const char *opt_text;
1238 const char *msg;
1239 size_t opt_len;
1240 enum opt_code opt_code;
1241};
1242
Zack Weinbergae796972000-03-31 23:16:11 +00001243#define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001244#ifdef HOST_EBCDIC
1245static struct cl_option cl_options[] =
1246#else
1247static const struct cl_option cl_options[] =
1248#endif
1249{
Zack Weinbergae796972000-03-31 23:16:11 +00001250 COMMAND_LINE_OPTIONS
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001251};
1252#undef DEF_OPT
Zack Weinbergae796972000-03-31 23:16:11 +00001253#undef COMMAND_LINE_OPTIONS
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001254
1255/* Perform a binary search to find which, if any, option the given
1256 command-line matches. Returns its index in the option array,
1257 negative on failure. Complications arise since some options can be
1258 suffixed with an argument, and multiple complete matches can occur,
Neil Booth05e81722001-01-11 21:30:16 +00001259 e.g. -iwithprefix and -iwithprefixbefore. Moreover, we need to
1260 accept options beginning with -W that we do not recognise, but not
1261 to swallow any subsequent command line argument; this is handled as
1262 special cases in cpp_handle_option. */
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001263static int
1264parse_option (input)
1265 const char *input;
1266{
1267 unsigned int md, mn, mx;
1268 size_t opt_len;
1269 int comp;
1270
1271 mn = 0;
1272 mx = N_OPTS;
1273
1274 while (mx > mn)
1275 {
1276 md = (mn + mx) / 2;
Zack Weinbergae796972000-03-31 23:16:11 +00001277
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001278 opt_len = cl_options[md].opt_len;
Neil Booth61d03462000-08-18 17:35:58 +00001279 comp = memcmp (input, cl_options[md].opt_text, opt_len);
Zack Weinbergae796972000-03-31 23:16:11 +00001280
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001281 if (comp > 0)
1282 mn = md + 1;
1283 else if (comp < 0)
1284 mx = md;
1285 else
1286 {
1287 if (input[opt_len] == '\0')
1288 return md;
1289 /* We were passed more text. If the option takes an argument,
1290 we may match a later option or we may have been passed the
1291 argument. The longest possible option match succeeds.
1292 If the option takes no arguments we have not matched and
Neil Booth4a58aab2000-11-18 12:18:09 +00001293 continue the search (e.g. input="stdc++" match was "stdc"). */
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001294 mn = md + 1;
1295 if (cl_options[md].msg)
1296 {
1297 /* Scan forwards. If we get an exact match, return it.
1298 Otherwise, return the longest option-accepting match.
Neil Booth4a58aab2000-11-18 12:18:09 +00001299 This loops no more than twice with current options. */
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001300 mx = md;
John David Anglin37b85242001-03-02 01:11:50 +00001301 for (; mn < (unsigned int) N_OPTS; mn++)
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001302 {
1303 opt_len = cl_options[mn].opt_len;
Neil Booth61d03462000-08-18 17:35:58 +00001304 if (memcmp (input, cl_options[mn].opt_text, opt_len))
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001305 break;
1306 if (input[opt_len] == '\0')
1307 return mn;
1308 if (cl_options[mn].msg)
1309 mx = mn;
1310 }
1311 return mx;
1312 }
1313 }
1314 }
1315
1316 return -1;
1317}
1318
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001319/* Handle one command-line option in (argc, argv).
1320 Can be called multiple times, to handle multiple sets of options.
1321 Returns number of strings consumed. */
Richard Kennerc8d8ed62000-02-19 01:27:00 +00001322
Zack Weinberg2c0accc2000-07-15 19:29:14 +00001323int
1324cpp_handle_option (pfile, argc, argv)
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001325 cpp_reader *pfile;
1326 int argc;
1327 char **argv;
1328{
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001329 int i = 0;
Zack Weinbergf8f769e2000-05-28 05:56:38 +00001330 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001331
Neil Booth373e2172001-02-21 07:29:56 +00001332 /* Interpret "-" or a non-option as a file name. */
1333 if (argv[i][0] != '-' || argv[i][1] == '\0')
Zack Weinberg0b22d651999-03-15 18:42:46 +00001334 {
Neil Booth373e2172001-02-21 07:29:56 +00001335 if (CPP_OPTION (pfile, in_fname) == NULL)
1336 CPP_OPTION (pfile, in_fname) = argv[i];
1337 else if (CPP_OPTION (pfile, out_fname) == NULL)
Zack Weinbergae796972000-03-31 23:16:11 +00001338 CPP_OPTION (pfile, out_fname) = argv[i];
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001339 else
Neil Booth373e2172001-02-21 07:29:56 +00001340 cpp_fatal (pfile, "Too many filenames. Type %s --help for usage info",
1341 progname);
Zack Weinberg0b22d651999-03-15 18:42:46 +00001342 }
1343 else
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001344 {
1345 enum opt_code opt_code;
1346 int opt_index;
Neil Booth7ceb3592000-03-11 00:49:44 +00001347 const char *arg = 0;
Zack Weinberg0b22d651999-03-15 18:42:46 +00001348
Neil Booth4a58aab2000-11-18 12:18:09 +00001349 /* Skip over '-'. */
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001350 opt_index = parse_option (&argv[i][1]);
1351 if (opt_index < 0)
1352 return i;
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001353
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001354 opt_code = cl_options[opt_index].opt_code;
1355 if (cl_options[opt_index].msg)
Zack Weinberg0b22d651999-03-15 18:42:46 +00001356 {
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001357 arg = &argv[i][cl_options[opt_index].opt_len + 1];
1358
Neil Booth5c5d1ea2001-01-10 21:32:15 +00001359 /* Yuk. Special case for -W as it must not swallow
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001360 up any following argument. If this becomes common, add
Neil Booth4a58aab2000-11-18 12:18:09 +00001361 another field to the cl_options table. */
Neil Booth5c5d1ea2001-01-10 21:32:15 +00001362 if (arg[0] == '\0' && opt_code != OPT_W)
Zack Weinberg0b22d651999-03-15 18:42:46 +00001363 {
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001364 arg = argv[++i];
1365 if (!arg)
Zack Weinberg0b22d651999-03-15 18:42:46 +00001366 {
Zack Weinbergd88b89e2000-04-18 21:49:16 +00001367 cpp_fatal (pfile, cl_options[opt_index].msg, argv[i - 1]);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001368 return argc;
1369 }
1370 }
1371 }
Zack Weinbergae796972000-03-31 23:16:11 +00001372
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001373 switch (opt_code)
1374 {
Neil Booth4a58aab2000-11-18 12:18:09 +00001375 case N_OPTS: /* Shut GCC up. */
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001376 break;
1377 case OPT_fleading_underscore:
Neil Booth771c4df2000-09-07 20:31:06 +00001378 CPP_OPTION (pfile, user_label_prefix) = "_";
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001379 break;
1380 case OPT_fno_leading_underscore:
Neil Booth771c4df2000-09-07 20:31:06 +00001381 CPP_OPTION (pfile, user_label_prefix) = "";
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001382 break;
Jakub Jelinekbe768052000-12-15 16:49:28 +01001383 case OPT_fno_operator_names:
1384 CPP_OPTION (pfile, operator_names) = 0;
1385 break;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001386 case OPT_fpreprocessed:
Zack Weinbergae796972000-03-31 23:16:11 +00001387 CPP_OPTION (pfile, preprocessed) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001388 break;
1389 case OPT_fno_preprocessed:
Zack Weinbergae796972000-03-31 23:16:11 +00001390 CPP_OPTION (pfile, preprocessed) = 0;
1391 break;
1392 case OPT_fshow_column:
1393 CPP_OPTION (pfile, show_column) = 1;
1394 break;
1395 case OPT_fno_show_column:
1396 CPP_OPTION (pfile, show_column) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001397 break;
Neil Booth6ab3e7d2000-05-18 11:09:27 +00001398 case OPT_ftabstop:
1399 /* Silently ignore empty string, non-longs and silly values. */
1400 if (arg[0] != '\0')
1401 {
1402 char *endptr;
1403 long tabstop = strtol (arg, &endptr, 10);
1404 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1405 CPP_OPTION (pfile, tabstop) = tabstop;
1406 }
1407 break;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001408 case OPT_w:
Zack Weinbergae796972000-03-31 23:16:11 +00001409 CPP_OPTION (pfile, inhibit_warnings) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001410 break;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001411 case OPT_h:
1412 case OPT__help:
1413 print_help ();
Neil Booth7e96d762001-01-13 01:00:01 +00001414 CPP_OPTION (pfile, help_only) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001415 break;
Chandra Chavva91606ce2000-11-14 12:06:06 -05001416 case OPT_target__help:
Zack Weinbergf4cdc362001-01-05 23:41:00 +00001417 /* Print if any target specific options. cpplib has none, but
1418 make sure help_only gets set. */
Neil Booth7e96d762001-01-13 01:00:01 +00001419 CPP_OPTION (pfile, help_only) = 1;
Chandra Chavva91606ce2000-11-14 12:06:06 -05001420 break;
Zack Weinbergf4cdc362001-01-05 23:41:00 +00001421
1422 /* --version inhibits compilation, -version doesn't. -v means
1423 verbose and -version. Historical reasons, don't ask. */
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001424 case OPT__version:
Neil Booth7e96d762001-01-13 01:00:01 +00001425 CPP_OPTION (pfile, help_only) = 1;
Zack Weinbergcb773842001-03-02 00:42:28 +00001426 pfile->print_version = 1;
1427 break;
Zack Weinbergf4cdc362001-01-05 23:41:00 +00001428 case OPT_v:
1429 CPP_OPTION (pfile, verbose) = 1;
Zack Weinbergcb773842001-03-02 00:42:28 +00001430 pfile->print_version = 1;
1431 break;
Zack Weinbergf4cdc362001-01-05 23:41:00 +00001432 case OPT_version:
Zack Weinbergcb773842001-03-02 00:42:28 +00001433 pfile->print_version = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001434 break;
Zack Weinbergf4cdc362001-01-05 23:41:00 +00001435
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001436 case OPT_C:
Zack Weinbergae796972000-03-31 23:16:11 +00001437 CPP_OPTION (pfile, discard_comments) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001438 break;
1439 case OPT_P:
Zack Weinbergae796972000-03-31 23:16:11 +00001440 CPP_OPTION (pfile, no_line_commands) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001441 break;
Neil Booth4a58aab2000-11-18 12:18:09 +00001442 case OPT_dollar: /* Don't include $ in identifiers. */
Zack Weinbergae796972000-03-31 23:16:11 +00001443 CPP_OPTION (pfile, dollars_in_ident) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001444 break;
1445 case OPT_H:
Zack Weinbergae796972000-03-31 23:16:11 +00001446 CPP_OPTION (pfile, print_include_names) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001447 break;
1448 case OPT_D:
Zack Weinbergf8f769e2000-05-28 05:56:38 +00001449 new_pending_directive (pend, arg, cpp_define);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001450 break;
1451 case OPT_pedantic_errors:
Zack Weinbergae796972000-03-31 23:16:11 +00001452 CPP_OPTION (pfile, pedantic_errors) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001453 /* fall through */
1454 case OPT_pedantic:
Zack Weinbergae796972000-03-31 23:16:11 +00001455 CPP_OPTION (pfile, pedantic) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001456 break;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001457 case OPT_trigraphs:
Zack Weinbergae796972000-03-31 23:16:11 +00001458 CPP_OPTION (pfile, trigraphs) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001459 break;
1460 case OPT_plus:
Zack Weinbergae796972000-03-31 23:16:11 +00001461 CPP_OPTION (pfile, cplusplus) = 1;
1462 CPP_OPTION (pfile, cplusplus_comments) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001463 break;
1464 case OPT_remap:
Zack Weinbergae796972000-03-31 23:16:11 +00001465 CPP_OPTION (pfile, remap) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001466 break;
1467 case OPT_iprefix:
Zack Weinbergae796972000-03-31 23:16:11 +00001468 CPP_OPTION (pfile, include_prefix) = arg;
1469 CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001470 break;
1471 case OPT_lang_c:
Neil Boothdd07b882000-11-20 18:27:32 +00001472 set_lang (pfile, CLK_GNUC89);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001473 break;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001474 case OPT_lang_cplusplus:
Neil Boothdd07b882000-11-20 18:27:32 +00001475 set_lang (pfile, CLK_GNUCXX);
1476 break;
1477 case OPT_lang_objc:
1478 set_lang (pfile, CLK_OBJC);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001479 break;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001480 case OPT_lang_objcplusplus:
Neil Boothdd07b882000-11-20 18:27:32 +00001481 set_lang (pfile, CLK_OBJCXX);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001482 break;
1483 case OPT_lang_asm:
Neil Boothdd07b882000-11-20 18:27:32 +00001484 set_lang (pfile, CLK_ASM);
1485 break;
1486 case OPT_std_cplusplus98:
1487 set_lang (pfile, CLK_CXX98);
1488 break;
1489 case OPT_std_gnu89:
1490 set_lang (pfile, CLK_GNUC89);
1491 break;
1492 case OPT_std_gnu9x:
1493 case OPT_std_gnu99:
1494 set_lang (pfile, CLK_GNUC99);
1495 break;
1496 case OPT_std_iso9899_199409:
1497 set_lang (pfile, CLK_STDC94);
1498 break;
1499 case OPT_std_iso9899_1990:
1500 case OPT_std_c89:
1501 case OPT_lang_c89:
1502 set_lang (pfile, CLK_STDC89);
1503 break;
1504 case OPT_std_iso9899_199x:
1505 case OPT_std_iso9899_1999:
1506 case OPT_std_c9x:
1507 case OPT_std_c99:
1508 set_lang (pfile, CLK_STDC99);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001509 break;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001510 case OPT_nostdinc:
1511 /* -nostdinc causes no default include directories.
1512 You must specify all include-file directories with -I. */
Zack Weinbergae796972000-03-31 23:16:11 +00001513 CPP_OPTION (pfile, no_standard_includes) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001514 break;
1515 case OPT_nostdincplusplus:
Kazu Hirataec5c56d2001-08-01 17:57:27 +00001516 /* -nostdinc++ causes no default C++-specific include directories. */
Zack Weinbergae796972000-03-31 23:16:11 +00001517 CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001518 break;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001519 case OPT_o:
Neil Booth373e2172001-02-21 07:29:56 +00001520 if (CPP_OPTION (pfile, out_fname) == NULL)
1521 CPP_OPTION (pfile, out_fname) = arg;
1522 else
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001523 {
1524 cpp_fatal (pfile, "Output filename specified twice");
1525 return argc;
1526 }
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001527 break;
1528 case OPT_d:
1529 /* Args to -d specify what parts of macros to dump.
1530 Silently ignore unrecognised options; they may
Neil Booth4a58aab2000-11-18 12:18:09 +00001531 be aimed at the compiler proper. */
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001532 {
1533 char c;
Zack Weinbergae796972000-03-31 23:16:11 +00001534
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001535 while ((c = *arg++) != '\0')
1536 switch (c)
1537 {
1538 case 'M':
Zack Weinbergae796972000-03-31 23:16:11 +00001539 CPP_OPTION (pfile, dump_macros) = dump_only;
1540 CPP_OPTION (pfile, no_output) = 1;
Zack Weinberg0b22d651999-03-15 18:42:46 +00001541 break;
1542 case 'N':
Zack Weinbergae796972000-03-31 23:16:11 +00001543 CPP_OPTION (pfile, dump_macros) = dump_names;
Zack Weinberg0b22d651999-03-15 18:42:46 +00001544 break;
1545 case 'D':
Zack Weinbergae796972000-03-31 23:16:11 +00001546 CPP_OPTION (pfile, dump_macros) = dump_definitions;
Zack Weinberg0b22d651999-03-15 18:42:46 +00001547 break;
1548 case 'I':
Zack Weinbergae796972000-03-31 23:16:11 +00001549 CPP_OPTION (pfile, dump_includes) = 1;
Zack Weinberg0b22d651999-03-15 18:42:46 +00001550 break;
1551 }
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001552 }
1553 break;
Zack Weinbergae796972000-03-31 23:16:11 +00001554
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001555 case OPT_MG:
Zack Weinbergae796972000-03-31 23:16:11 +00001556 CPP_OPTION (pfile, print_deps_missing_files) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001557 break;
1558 case OPT_M:
Neil Booth96302432001-01-07 15:17:07 +00001559 CPP_OPTION (pfile, print_deps) = 2;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001560 break;
Neil Booth96302432001-01-07 15:17:07 +00001561 case OPT_MM:
1562 CPP_OPTION (pfile, print_deps) = 1;
1563 break;
1564 case OPT_MF:
1565 CPP_OPTION (pfile, deps_file) = arg;
1566 break;
1567 case OPT_MP:
Neil Bootha5a4ce32001-01-05 07:50:24 +00001568 CPP_OPTION (pfile, deps_phony_targets) = 1;
1569 break;
Neil Boothf7114e12001-01-06 00:15:29 +00001570 case OPT_MQ:
Neil Booth03b9ab42001-01-04 10:25:55 +00001571 case OPT_MT:
Neil Boothf7114e12001-01-06 00:15:29 +00001572 /* Add a target. -MQ quotes for Make. */
1573 deps_add_target (pfile->deps, arg, opt_code == OPT_MQ);
Neil Booth03b9ab42001-01-04 10:25:55 +00001574 break;
1575
Neil Boothe5822482001-01-09 14:45:44 +00001576 /* -MD and -MMD for cpp0 are deprecated and undocumented
1577 (use -M or -MM with -MF instead), and probably should be
1578 removed with the next major GCC version. For the moment
1579 we allow these for the benefit of Automake 1.4, which
1580 uses these when dependency tracking is enabled. Automake
1581 1.5 will fix this. */
1582 case OPT_MD:
1583 CPP_OPTION (pfile, print_deps) = 2;
1584 CPP_OPTION (pfile, deps_file) = arg;
1585 break;
1586 case OPT_MMD:
1587 CPP_OPTION (pfile, print_deps) = 1;
1588 CPP_OPTION (pfile, deps_file) = arg;
1589 break;
1590
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001591 case OPT_A:
Neil Boothe1e97c42000-03-16 14:15:17 +00001592 if (arg[0] == '-')
Zack Weinberg0b22d651999-03-15 18:42:46 +00001593 {
Neil Boothe1e97c42000-03-16 14:15:17 +00001594 /* -A with an argument beginning with '-' acts as
1595 #unassert on whatever immediately follows the '-'.
1596 If "-" is the whole argument, we eliminate all
1597 predefined macros and assertions, including those
1598 that were specified earlier on the command line.
1599 That way we can get rid of any that were passed
1600 automatically in from GCC. */
Zack Weinberg0b22d651999-03-15 18:42:46 +00001601
Neil Boothe1e97c42000-03-16 14:15:17 +00001602 if (arg[1] == '\0')
Zack Weinberg0b22d651999-03-15 18:42:46 +00001603 {
Neil Booth29401c32001-08-22 20:37:20 +00001604 free_chain (pend->directive_head);
Neil Boothe33f6252000-08-17 17:58:24 +00001605 pend->directive_head = NULL;
1606 pend->directive_tail = NULL;
Zack Weinberg0b22d651999-03-15 18:42:46 +00001607 }
Neil Boothe1e97c42000-03-16 14:15:17 +00001608 else
Neil Boothe33f6252000-08-17 17:58:24 +00001609 new_pending_directive (pend, arg + 1, cpp_unassert);
Zack Weinberg0b22d651999-03-15 18:42:46 +00001610 }
Neil Boothe1e97c42000-03-16 14:15:17 +00001611 else
Neil Boothe33f6252000-08-17 17:58:24 +00001612 new_pending_directive (pend, arg, cpp_assert);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001613 break;
1614 case OPT_U:
Neil Boothe33f6252000-08-17 17:58:24 +00001615 new_pending_directive (pend, arg, cpp_undef);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001616 break;
1617 case OPT_I: /* Add directory to path for includes. */
1618 if (!strcmp (arg, "-"))
1619 {
1620 /* -I- means:
1621 Use the preceding -I directories for #include "..."
1622 but not #include <...>.
1623 Don't search the directory of the present file
1624 for #include "...". (Note that -I. -I- is not the same as
1625 the default setup; -I. uses the compiler's working dir.) */
Zack Weinbergae796972000-03-31 23:16:11 +00001626 if (! CPP_OPTION (pfile, ignore_srcdir))
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001627 {
Zack Weinbergae796972000-03-31 23:16:11 +00001628 pend->quote_head = pend->brack_head;
1629 pend->quote_tail = pend->brack_tail;
1630 pend->brack_head = 0;
1631 pend->brack_tail = 0;
1632 CPP_OPTION (pfile, ignore_srcdir) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001633 }
1634 else
1635 {
1636 cpp_fatal (pfile, "-I- specified twice");
1637 return argc;
1638 }
1639 }
1640 else
Neil Boothe33f6252000-08-17 17:58:24 +00001641 append_include_chain (pfile, xstrdup (arg), BRACKET, 0);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001642 break;
1643 case OPT_isystem:
1644 /* Add directory to beginning of system include path, as a system
Neil Booth4a58aab2000-11-18 12:18:09 +00001645 include directory. */
Neil Boothe33f6252000-08-17 17:58:24 +00001646 append_include_chain (pfile, xstrdup (arg), SYSTEM, 0);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001647 break;
1648 case OPT_include:
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001649 case OPT_imacros:
1650 {
1651 struct pending_option *o = (struct pending_option *)
1652 xmalloc (sizeof (struct pending_option));
1653 o->arg = arg;
1654 o->next = NULL;
Zack Weinbergae796972000-03-31 23:16:11 +00001655
Neil Boothd7bc7a92001-08-21 06:20:18 +00001656 if (opt_code == OPT_include)
1657 APPEND (pend, include, o);
1658 else
1659 APPEND (pend, imacros, o);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001660 }
1661 break;
1662 case OPT_iwithprefix:
1663 /* Add directory to end of path for includes,
1664 with the default prefix at the front of its name. */
1665 /* fall through */
1666 case OPT_iwithprefixbefore:
1667 /* Add directory to main path for includes,
1668 with the default prefix at the front of its name. */
1669 {
1670 char *fname;
1671 int len;
Zack Weinbergae796972000-03-31 23:16:11 +00001672
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001673 len = strlen (arg);
Zack Weinbergae796972000-03-31 23:16:11 +00001674
1675 if (CPP_OPTION (pfile, include_prefix) != 0)
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001676 {
Zack Weinbergae796972000-03-31 23:16:11 +00001677 size_t ipl = CPP_OPTION (pfile, include_prefix_len);
1678 fname = xmalloc (ipl + len + 1);
1679 memcpy (fname, CPP_OPTION (pfile, include_prefix), ipl);
1680 memcpy (fname + ipl, arg, len + 1);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001681 }
Zack Weinberg60893f42000-07-06 22:52:03 +00001682 else if (cpp_GCC_INCLUDE_DIR_len)
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001683 {
Zack Weinberg60893f42000-07-06 22:52:03 +00001684 fname = xmalloc (cpp_GCC_INCLUDE_DIR_len + len + 1);
1685 memcpy (fname, cpp_GCC_INCLUDE_DIR, cpp_GCC_INCLUDE_DIR_len);
1686 memcpy (fname + cpp_GCC_INCLUDE_DIR_len, arg, len + 1);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001687 }
Zack Weinberg60893f42000-07-06 22:52:03 +00001688 else
1689 fname = xstrdup (arg);
Zack Weinbergae796972000-03-31 23:16:11 +00001690
Neil Boothe33f6252000-08-17 17:58:24 +00001691 append_include_chain (pfile, fname,
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001692 opt_code == OPT_iwithprefix ? SYSTEM: BRACKET, 0);
1693 }
1694 break;
1695 case OPT_idirafter:
1696 /* Add directory to end of path for includes. */
Neil Boothe33f6252000-08-17 17:58:24 +00001697 append_include_chain (pfile, xstrdup (arg), AFTER, 0);
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001698 break;
1699 case OPT_W:
Neil Booth4a58aab2000-11-18 12:18:09 +00001700 /* Silently ignore unrecognised options. */
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001701 if (!strcmp (argv[i], "-Wall"))
Zack Weinberg0b22d651999-03-15 18:42:46 +00001702 {
Zack Weinbergae796972000-03-31 23:16:11 +00001703 CPP_OPTION (pfile, warn_trigraphs) = 1;
1704 CPP_OPTION (pfile, warn_comments) = 1;
Zack Weinberg0b22d651999-03-15 18:42:46 +00001705 }
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001706 else if (!strcmp (argv[i], "-Wtraditional"))
Zack Weinberg07aa0b02000-04-01 22:55:25 +00001707 CPP_OPTION (pfile, warn_traditional) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001708 else if (!strcmp (argv[i], "-Wtrigraphs"))
Zack Weinbergae796972000-03-31 23:16:11 +00001709 CPP_OPTION (pfile, warn_trigraphs) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001710 else if (!strcmp (argv[i], "-Wcomment"))
Zack Weinbergae796972000-03-31 23:16:11 +00001711 CPP_OPTION (pfile, warn_comments) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001712 else if (!strcmp (argv[i], "-Wcomments"))
Zack Weinbergae796972000-03-31 23:16:11 +00001713 CPP_OPTION (pfile, warn_comments) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001714 else if (!strcmp (argv[i], "-Wundef"))
Zack Weinbergae796972000-03-31 23:16:11 +00001715 CPP_OPTION (pfile, warn_undef) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001716 else if (!strcmp (argv[i], "-Wimport"))
Zack Weinbergae796972000-03-31 23:16:11 +00001717 CPP_OPTION (pfile, warn_import) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001718 else if (!strcmp (argv[i], "-Werror"))
Zack Weinbergae796972000-03-31 23:16:11 +00001719 CPP_OPTION (pfile, warnings_are_errors) = 1;
Branko Cibej317639a2000-09-26 00:54:04 +02001720 else if (!strcmp (argv[i], "-Wsystem-headers"))
1721 CPP_OPTION (pfile, warn_system_headers) = 1;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001722 else if (!strcmp (argv[i], "-Wno-traditional"))
Zack Weinberg07aa0b02000-04-01 22:55:25 +00001723 CPP_OPTION (pfile, warn_traditional) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001724 else if (!strcmp (argv[i], "-Wno-trigraphs"))
Zack Weinbergae796972000-03-31 23:16:11 +00001725 CPP_OPTION (pfile, warn_trigraphs) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001726 else if (!strcmp (argv[i], "-Wno-comment"))
Zack Weinbergae796972000-03-31 23:16:11 +00001727 CPP_OPTION (pfile, warn_comments) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001728 else if (!strcmp (argv[i], "-Wno-comments"))
Zack Weinbergae796972000-03-31 23:16:11 +00001729 CPP_OPTION (pfile, warn_comments) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001730 else if (!strcmp (argv[i], "-Wno-undef"))
Zack Weinbergae796972000-03-31 23:16:11 +00001731 CPP_OPTION (pfile, warn_undef) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001732 else if (!strcmp (argv[i], "-Wno-import"))
Zack Weinbergae796972000-03-31 23:16:11 +00001733 CPP_OPTION (pfile, warn_import) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001734 else if (!strcmp (argv[i], "-Wno-error"))
Zack Weinbergae796972000-03-31 23:16:11 +00001735 CPP_OPTION (pfile, warnings_are_errors) = 0;
Branko Cibej317639a2000-09-26 00:54:04 +02001736 else if (!strcmp (argv[i], "-Wno-system-headers"))
1737 CPP_OPTION (pfile, warn_system_headers) = 0;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001738 break;
1739 }
1740 }
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001741 return i + 1;
1742}
1743
1744/* Handle command-line options in (argc, argv).
1745 Can be called multiple times, to handle multiple sets of options.
1746 Returns if an unrecognized option is seen.
1747 Returns number of strings consumed. */
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001748int
1749cpp_handle_options (pfile, argc, argv)
1750 cpp_reader *pfile;
1751 int argc;
1752 char **argv;
1753{
1754 int i;
1755 int strings_processed;
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001756
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001757 for (i = 0; i < argc; i += strings_processed)
1758 {
Zack Weinberg2c0accc2000-07-15 19:29:14 +00001759 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001760 if (strings_processed == 0)
1761 break;
1762 }
Neil Booth96302432001-01-07 15:17:07 +00001763
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001764 return i;
1765}
1766
Neil Booth96302432001-01-07 15:17:07 +00001767/* Extra processing when all options are parsed, after all calls to
1768 cpp_handle_option[s]. Consistency checks etc. */
1769void
1770cpp_post_options (pfile)
1771 cpp_reader *pfile;
1772{
Zack Weinbergcb773842001-03-02 00:42:28 +00001773 if (pfile->print_version)
1774 {
1775 fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string);
1776#ifdef TARGET_VERSION
1777 TARGET_VERSION;
1778#endif
1779 fputc ('\n', stderr);
1780 }
1781
Neil Booth373e2172001-02-21 07:29:56 +00001782 /* Canonicalize in_fname and out_fname. We guarantee they are not
1783 NULL, and that the empty string represents stdin / stdout. */
1784 if (CPP_OPTION (pfile, in_fname) == NULL
1785 || !strcmp (CPP_OPTION (pfile, in_fname), "-"))
1786 CPP_OPTION (pfile, in_fname) = "";
1787
1788 if (CPP_OPTION (pfile, out_fname) == NULL
1789 || !strcmp (CPP_OPTION (pfile, out_fname), "-"))
1790 CPP_OPTION (pfile, out_fname) = "";
1791
Neil Booth96302432001-01-07 15:17:07 +00001792 /* -Wtraditional is not useful in C++ mode. */
1793 if (CPP_OPTION (pfile, cplusplus))
1794 CPP_OPTION (pfile, warn_traditional) = 0;
1795
Kazu Hirataec5c56d2001-08-01 17:57:27 +00001796 /* Set this if it hasn't been set already. */
Neil Booth96302432001-01-07 15:17:07 +00001797 if (CPP_OPTION (pfile, user_label_prefix) == NULL)
1798 CPP_OPTION (pfile, user_label_prefix) = USER_LABEL_PREFIX;
1799
Zack Weinberg6d4587f2001-05-10 00:07:23 +00001800 /* Permanently disable macro expansion if we are rescanning
1801 preprocessed text. */
1802 if (CPP_OPTION (pfile, preprocessed))
1803 pfile->state.prevent_expansion = 1;
1804
Neil Booth96302432001-01-07 15:17:07 +00001805 /* We need to do this after option processing and before
1806 cpp_start_read, as cppmain.c relies on the options->no_output to
1807 set its callbacks correctly before calling cpp_start_read. */
1808 init_dependency_output (pfile);
1809
Neil Boothe5822482001-01-09 14:45:44 +00001810 /* After checking the environment variables, check if -M or -MM has
1811 not been specified, but other -M options have. */
1812 if (CPP_OPTION (pfile, print_deps) == 0 &&
1813 (CPP_OPTION (pfile, print_deps_missing_files)
1814 || CPP_OPTION (pfile, deps_file)
1815 || CPP_OPTION (pfile, deps_phony_targets)))
1816 cpp_fatal (pfile, "you must additionally specify either -M or -MM");
Neil Booth96302432001-01-07 15:17:07 +00001817}
1818
Neil Booth7ca3d2b2001-01-07 11:15:13 +00001819/* Set up dependency-file output. */
1820static void
1821init_dependency_output (pfile)
1822 cpp_reader *pfile;
1823{
1824 char *spec, *s, *output_file;
1825
1826 /* Either of two environment variables can specify output of deps.
1827 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
1828 where OUTPUT_FILE is the file to write deps info to
1829 and DEPS_TARGET is the target to mention in the deps. */
1830
1831 if (CPP_OPTION (pfile, print_deps) == 0)
1832 {
1833 spec = getenv ("DEPENDENCIES_OUTPUT");
1834 if (spec)
1835 CPP_OPTION (pfile, print_deps) = 1;
1836 else
1837 {
1838 spec = getenv ("SUNPRO_DEPENDENCIES");
1839 if (spec)
1840 CPP_OPTION (pfile, print_deps) = 2;
1841 else
1842 return;
1843 }
1844
1845 /* Find the space before the DEPS_TARGET, if there is one. */
1846 s = strchr (spec, ' ');
1847 if (s)
1848 {
1849 /* Let the caller perform MAKE quoting. */
1850 deps_add_target (pfile->deps, s + 1, 0);
1851 output_file = (char *) xmalloc (s - spec + 1);
1852 memcpy (output_file, spec, s - spec);
1853 output_file[s - spec] = 0;
1854 }
1855 else
1856 output_file = spec;
1857
Neil Booth96302432001-01-07 15:17:07 +00001858 /* Command line overrides environment variables. */
1859 if (CPP_OPTION (pfile, deps_file) == 0)
1860 CPP_OPTION (pfile, deps_file) = output_file;
Neil Booth7ca3d2b2001-01-07 11:15:13 +00001861 CPP_OPTION (pfile, print_deps_append) = 1;
1862 }
1863
Neil Boothe5822482001-01-09 14:45:44 +00001864 /* If dependencies go to standard output, or -MG is used, we should
Neil Boothdf07e072001-07-29 14:40:45 +00001865 suppress output, including -dM, -dI etc. */
Neil Boothe5822482001-01-09 14:45:44 +00001866 if (CPP_OPTION (pfile, deps_file) == 0
1867 || CPP_OPTION (pfile, print_deps_missing_files))
Neil Boothdf07e072001-07-29 14:40:45 +00001868 {
1869 CPP_OPTION (pfile, no_output) = 1;
1870 CPP_OPTION (pfile, dump_macros) = 0;
1871 CPP_OPTION (pfile, dump_includes) = 0;
1872 }
Neil Booth7ca3d2b2001-01-07 11:15:13 +00001873}
1874
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001875static void
1876print_help ()
1877{
Zack Weinbergc1212d22000-02-06 23:46:18 +00001878 fprintf (stderr, _("Usage: %s [switches] input output\n"), progname);
Donn Terryaaaf7842000-07-08 06:21:13 +00001879 /* To keep the lines from getting too long for some compilers, limit
Kazu Hirataec5c56d2001-08-01 17:57:27 +00001880 to about 500 characters (6 lines) per chunk. */
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001881 fputs (_("\
1882Switches:\n\
1883 -include <file> Include the contents of <file> before other files\n\
1884 -imacros <file> Accept definition of macros in <file>\n\
1885 -iprefix <path> Specify <path> as a prefix for next two options\n\
1886 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1887 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1888 -isystem <dir> Add <dir> to the start of the system include path\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001889"), stdout);
1890 fputs (_("\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001891 -idirafter <dir> Add <dir> to the end of the system include path\n\
1892 -I <dir> Add <dir> to the end of the main include path\n\
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001893 -I- Fine-grained include path control; see info docs\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001894 -nostdinc Do not search system include directories\n\
1895 (dirs specified with -isystem will still be used)\n\
1896 -nostdinc++ Do not search system include directories for C++\n\
1897 -o <file> Put output into <file>\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001898"), stdout);
1899 fputs (_("\
Zack Weinberg041c3192000-07-04 01:58:21 +00001900 -pedantic Issue all warnings demanded by strict ISO C\n\
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001901 -pedantic-errors Issue -pedantic warnings as errors instead\n\
Zack Weinberg041c3192000-07-04 01:58:21 +00001902 -trigraphs Support ISO C trigraphs\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001903 -lang-c Assume that the input sources are in C\n\
1904 -lang-c89 Assume that the input sources are in C89\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001905"), stdout);
1906 fputs (_("\
Zack Weinbergf9a0e962000-07-13 02:32:41 +00001907 -lang-c++ Assume that the input sources are in C++\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001908 -lang-objc Assume that the input sources are in ObjectiveC\n\
1909 -lang-objc++ Assume that the input sources are in ObjectiveC++\n\
1910 -lang-asm Assume that the input sources are in assembler\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001911"), stdout);
1912 fputs (_("\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001913 -std=<std name> Specify the conformance standard; one of:\n\
Ulrich Drepper916269a2000-01-29 19:00:43 +00001914 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1915 iso9899:199409, iso9899:1999\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001916 -+ Allow parsing of C++ style features\n\
1917 -w Inhibit warning messages\n\
1918 -Wtrigraphs Warn if trigraphs are encountered\n\
1919 -Wno-trigraphs Do not warn about trigraphs\n\
1920 -Wcomment{s} Warn if one comment starts inside another\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001921"), stdout);
1922 fputs (_("\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001923 -Wno-comment{s} Do not warn about comments\n\
Zack Weinbergf9a0e962000-07-13 02:32:41 +00001924 -Wtraditional Warn about features not present in traditional C\n\
1925 -Wno-traditional Do not warn about traditional C\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001926 -Wundef Warn if an undefined macro is used by #if\n\
1927 -Wno-undef Do not warn about testing undefined macros\n\
1928 -Wimport Warn about the use of the #import directive\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001929"), stdout);
1930 fputs (_("\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001931 -Wno-import Do not warn about the use of #import\n\
1932 -Werror Treat all warnings as errors\n\
1933 -Wno-error Do not treat warnings as errors\n\
Branko Cibej317639a2000-09-26 00:54:04 +02001934 -Wsystem-headers Do not suppress warnings from system headers\n\
1935 -Wno-system-headers Suppress warnings from system headers\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001936 -Wall Enable all preprocessor warnings\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001937"), stdout);
1938 fputs (_("\
Branko Cibej317639a2000-09-26 00:54:04 +02001939 -M Generate make dependencies\n\
1940 -MM As -M, but ignore system header files\n\
Neil Booth96302432001-01-07 15:17:07 +00001941 -MF <file> Write dependency output to the given file\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001942 -MG Treat missing header file as generated files\n\
Neil Booth96302432001-01-07 15:17:07 +00001943"), stdout);
1944 fputs (_("\
1945 -MP Generate phony targets for all headers\n\
1946 -MQ <target> Add a MAKE-quoted target\n\
1947 -MT <target> Add an unquoted target\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001948"), stdout);
1949 fputs (_("\
Branko Cibej317639a2000-09-26 00:54:04 +02001950 -D<macro> Define a <macro> with string '1' as its value\n\
1951 -D<macro>=<val> Define a <macro> with <val> as its value\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001952 -A<question> (<answer>) Assert the <answer> to <question>\n\
Neil Boothe1e97c42000-03-16 14:15:17 +00001953 -A-<question> (<answer>) Disable the <answer> to <question>\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001954 -U<macro> Undefine <macro> \n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001955 -v Display the version number\n\
Donn Terryaaaf7842000-07-08 06:21:13 +00001956"), stdout);
1957 fputs (_("\
Branko Cibej317639a2000-09-26 00:54:04 +02001958 -H Print the name of header files as they are used\n\
1959 -C Do not discard comments\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001960 -dM Display a list of macro definitions active at end\n\
1961 -dD Preserve macro definitions in output\n\
1962 -dN As -dD except that only the names are preserved\n\
1963 -dI Include #include directives in the output\n\
Branko Cibej317639a2000-09-26 00:54:04 +02001964"), stdout);
1965 fputs (_("\
Neil Booth3bce8a02001-06-09 22:55:49 +00001966 -fpreprocessed Treat the input file as already preprocessed\n\
Neil Booth6ab3e7d2000-05-18 11:09:27 +00001967 -ftabstop=<number> Distance between tab stops for column reporting\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001968 -P Do not generate #line directives\n\
1969 -$ Do not allow '$' in identifiers\n\
1970 -remap Remap file names when including files.\n\
Zack Weinberge23c0ba2000-03-07 23:11:06 +00001971 --version Display version information\n\
Zack Weinberg6de1e2a1999-02-18 15:35:49 +00001972 -h or --help Display this information\n\
1973"), stdout);
1974}