Zack Weinberg | 5538ada | 1999-02-04 06:36:54 -0500 | [diff] [blame] | 1 | /* CPP Library. |
Jeff Law | 5e7b4e2 | 2000-02-25 22:59:31 -0700 | [diff] [blame] | 2 | Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
| 3 | 1999, 2000 Free Software Foundation, Inc. |
Zack Weinberg | 5538ada | 1999-02-04 06:36:54 -0500 | [diff] [blame] | 4 | 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 | |
| 8 | This program is free software; you can redistribute it and/or modify it |
| 9 | under the terms of the GNU General Public License as published by the |
| 10 | Free Software Foundation; either version 2, or (at your option) any |
| 11 | later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 21 | |
Zack Weinberg | 5538ada | 1999-02-04 06:36:54 -0500 | [diff] [blame] | 22 | #include "config.h" |
| 23 | #include "system.h" |
Richard Kenner | e38992e | 2000-04-18 20:42:00 +0000 | [diff] [blame] | 24 | #include "hashtab.h" |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 25 | #include "cpplib.h" |
| 26 | #include "cpphash.h" |
| 27 | #include "output.h" |
| 28 | #include "prefix.h" |
| 29 | #include "intl.h" |
Kaveh R. Ghazi | 9f8f4ef | 2000-02-15 16:36:35 +0000 | [diff] [blame] | 30 | #include "version.h" |
Zack Weinberg | 49e6c08 | 2000-03-04 19:42:04 +0000 | [diff] [blame] | 31 | #include "mkdeps.h" |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 32 | |
| 33 | /* Predefined symbols, built-in macros, and the default include path. */ |
| 34 | |
| 35 | #ifndef GET_ENV_PATH_LIST |
| 36 | #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0) |
| 37 | #endif |
| 38 | |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 39 | /* Windows does not natively support inodes, and neither does MSDOS. |
| 40 | Cygwin's emulation can generate non-unique inodes, so don't use it. |
| 41 | VMS has non-numeric inodes. */ |
| 42 | #ifdef VMS |
| 43 | #define INO_T_EQ(a, b) (!memcmp (&(a), &(b), sizeof (a))) |
| 44 | #elif (defined _WIN32 && ! defined (_UWIN)) || defined __MSDOS__ |
| 45 | #define INO_T_EQ(a, b) 0 |
| 46 | #else |
| 47 | #define INO_T_EQ(a, b) ((a) == (b)) |
| 48 | #endif |
| 49 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 50 | #ifndef STANDARD_INCLUDE_DIR |
| 51 | #define STANDARD_INCLUDE_DIR "/usr/include" |
| 52 | #endif |
| 53 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 54 | /* We let tm.h override the types used here, to handle trivial differences |
| 55 | such as the choice of unsigned int or long unsigned int for size_t. |
| 56 | When machines start needing nontrivial differences in the size type, |
| 57 | it would be best to do something here to figure out automatically |
| 58 | from other information what type to use. */ |
| 59 | |
| 60 | /* The string value for __SIZE_TYPE__. */ |
| 61 | |
| 62 | #ifndef SIZE_TYPE |
| 63 | #define SIZE_TYPE "long unsigned int" |
| 64 | #endif |
| 65 | |
| 66 | /* The string value for __PTRDIFF_TYPE__. */ |
| 67 | |
| 68 | #ifndef PTRDIFF_TYPE |
| 69 | #define PTRDIFF_TYPE "long int" |
| 70 | #endif |
| 71 | |
| 72 | /* The string value for __WCHAR_TYPE__. */ |
| 73 | |
| 74 | #ifndef WCHAR_TYPE |
| 75 | #define WCHAR_TYPE "int" |
| 76 | #endif |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 77 | |
| 78 | /* The string value for __USER_LABEL_PREFIX__ */ |
| 79 | |
| 80 | #ifndef USER_LABEL_PREFIX |
| 81 | #define USER_LABEL_PREFIX "" |
| 82 | #endif |
| 83 | |
| 84 | /* The string value for __REGISTER_PREFIX__ */ |
| 85 | |
| 86 | #ifndef REGISTER_PREFIX |
| 87 | #define REGISTER_PREFIX "" |
| 88 | #endif |
| 89 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 90 | /* This is the default list of directories to search for include files. |
| 91 | It may be overridden by the various -I and -ixxx options. |
| 92 | |
| 93 | #include "file" looks in the same directory as the current file, |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 94 | then this list. |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 95 | #include <file> just looks in this list. |
| 96 | |
| 97 | All these directories are treated as `system' include directories |
| 98 | (they are not subject to pedantic warnings in some cases). */ |
| 99 | |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 100 | struct default_include |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 101 | { |
Kaveh R. Ghazi | bcc5cac | 1999-09-07 15:41:26 +0000 | [diff] [blame] | 102 | const char *fname; /* The name of the directory. */ |
| 103 | const char *component; /* The component containing the directory |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 104 | (see update_path in prefix.c) */ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 105 | int cplusplus; /* Only look here if we're compiling C++. */ |
| 106 | int cxx_aware; /* Includes in this directory don't need to |
| 107 | be wrapped in extern "C" when compiling |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 108 | C++. */ |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 111 | #ifndef STANDARD_INCLUDE_COMPONENT |
| 112 | #define STANDARD_INCLUDE_COMPONENT 0 |
| 113 | #endif |
| 114 | |
| 115 | #ifdef CROSS_COMPILE |
| 116 | #undef LOCAL_INCLUDE_DIR |
| 117 | #undef SYSTEM_INCLUDE_DIR |
| 118 | #undef STANDARD_INCLUDE_DIR |
| 119 | #else |
| 120 | #undef CROSS_INCLUDE_DIR |
| 121 | #endif |
| 122 | |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 123 | static const struct default_include include_defaults_array[] |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 124 | #ifdef INCLUDE_DEFAULTS |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 125 | = INCLUDE_DEFAULTS; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 126 | #else |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 127 | = { |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 128 | #ifdef GPLUSPLUS_INCLUDE_DIR |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 129 | /* Pick up GNU C++ specific include files. */ |
| 130 | { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 }, |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 131 | #endif |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 132 | #ifdef LOCAL_INCLUDE_DIR |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 133 | /* /usr/local/include comes before the fixincluded header files. */ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 134 | { LOCAL_INCLUDE_DIR, 0, 0, 1 }, |
| 135 | #endif |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 136 | #ifdef GCC_INCLUDE_DIR |
| 137 | /* This is the dir for fixincludes and for gcc's private headers. */ |
| 138 | { GCC_INCLUDE_DIR, "GCC", 0, 0 }, |
| 139 | #endif |
| 140 | #ifdef CROSS_INCLUDE_DIR |
| 141 | /* One place the target system's headers might be. */ |
| 142 | { CROSS_INCLUDE_DIR, "GCC", 0, 0 }, |
| 143 | #endif |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 144 | #ifdef TOOL_INCLUDE_DIR |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 145 | /* Another place the target system's headers might be. */ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 146 | { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 }, |
| 147 | #endif |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 148 | #ifdef SYSTEM_INCLUDE_DIR |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 149 | /* Some systems have an extra dir of include files. */ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 150 | { SYSTEM_INCLUDE_DIR, 0, 0, 0 }, |
| 151 | #endif |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 152 | #ifdef STANDARD_INCLUDE_DIR |
| 153 | /* /usr/include comes dead last. */ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 154 | { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 }, |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 155 | #endif |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 156 | { 0, 0, 0, 0 } |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 157 | }; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 158 | #endif /* no INCLUDE_DEFAULTS */ |
| 159 | |
| 160 | /* Internal structures and prototypes. */ |
| 161 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 162 | /* A `struct pending_option' remembers one -D, -A, -U, -include, or -imacros |
| 163 | switch. There are four lists: one for -D and -U, one for -A, one |
| 164 | for -include, one for -imacros. `undef' is set for -U, clear for |
| 165 | -D, ignored for the others. |
| 166 | (Future: add an equivalent of -U for -A) */ |
Neil Booth | 40eac64 | 2000-03-11 09:13:00 +0000 | [diff] [blame] | 167 | |
Kaveh R. Ghazi | 8be1ddc | 2000-03-12 13:55:52 +0000 | [diff] [blame] | 168 | typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *)); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 169 | struct pending_option |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 170 | { |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 171 | struct pending_option *next; |
Neil Booth | 7ceb359 | 2000-03-11 00:49:44 +0000 | [diff] [blame] | 172 | const char *arg; |
Neil Booth | 40eac64 | 2000-03-11 09:13:00 +0000 | [diff] [blame] | 173 | cl_directive_handler handler; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 174 | }; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 175 | |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 176 | /* The `pending' structure accumulates all the options that are not |
| 177 | actually processed until we hit cpp_start_read. It consists of |
| 178 | several lists, one for each type of option. We keep both head and |
| 179 | tail pointers for quick insertion. */ |
| 180 | struct cpp_pending |
| 181 | { |
Neil Booth | 40eac64 | 2000-03-11 09:13:00 +0000 | [diff] [blame] | 182 | struct pending_option *directive_head, *directive_tail; |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 183 | |
| 184 | struct file_name_list *quote_head, *quote_tail; |
| 185 | struct file_name_list *brack_head, *brack_tail; |
| 186 | struct file_name_list *systm_head, *systm_tail; |
| 187 | struct file_name_list *after_head, *after_tail; |
| 188 | |
| 189 | struct pending_option *imacros_head, *imacros_tail; |
| 190 | struct pending_option *include_head, *include_tail; |
| 191 | }; |
| 192 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 193 | #ifdef __STDC__ |
| 194 | #define APPEND(pend, list, elt) \ |
| 195 | do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \ |
| 196 | else (pend)->list##_tail->next = (elt); \ |
| 197 | (pend)->list##_tail = (elt); \ |
| 198 | } while (0) |
| 199 | #else |
| 200 | #define APPEND(pend, list, elt) \ |
| 201 | do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \ |
| 202 | else (pend)->list/**/_tail->next = (elt); \ |
| 203 | (pend)->list/**/_tail = (elt); \ |
| 204 | } while (0) |
| 205 | #endif |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 206 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 207 | static void print_help PARAMS ((void)); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 208 | static void path_include PARAMS ((cpp_reader *, |
| 209 | struct cpp_pending *, |
| 210 | char *, int)); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 211 | static void initialize_builtins PARAMS ((cpp_reader *)); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 212 | static void append_include_chain PARAMS ((cpp_reader *, |
| 213 | struct cpp_pending *, |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 214 | char *, int, int)); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 215 | static void merge_include_chains PARAMS ((cpp_reader *)); |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 216 | |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 217 | static void dump_special_to_buffer PARAMS ((cpp_reader *, const U_CHAR *, |
| 218 | size_t)); |
Kaveh R. Ghazi | bcc5cac | 1999-09-07 15:41:26 +0000 | [diff] [blame] | 219 | static void initialize_dependency_output PARAMS ((cpp_reader *)); |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 220 | static void initialize_standard_includes PARAMS ((cpp_reader *)); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 221 | static void new_pending_directive PARAMS ((struct cpp_pending *, |
Neil Booth | 40eac64 | 2000-03-11 09:13:00 +0000 | [diff] [blame] | 222 | const char *, |
| 223 | cl_directive_handler)); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 224 | #ifdef HOST_EBCDIC |
| 225 | static int opt_comp PARAMS ((const void *, const void *)); |
| 226 | #endif |
| 227 | static int parse_option PARAMS ((const char *)); |
Zack Weinberg | b0699da | 2000-03-07 20:58:47 +0000 | [diff] [blame] | 228 | static int handle_option PARAMS ((cpp_reader *, int, char **)); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 229 | |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 230 | /* Fourth argument to append_include_chain: chain to use */ |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 231 | enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 232 | |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 233 | /* If we have designated initializers (GCC >2.7) this table can be |
| 234 | initialized, constant data. Otherwise, it has to be filled in at |
| 235 | runtime. */ |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 236 | |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 237 | #if (GCC_VERSION >= 2007) |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 238 | #define init_IStable() /* nothing */ |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 239 | #define ISTABLE __extension__ const unsigned char _cpp_IStable[256] = { |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 240 | #define END }; |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 241 | #define s(p, v) [p] = v, |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 242 | #else |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 243 | #define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \ |
| 244 | static void init_IStable PARAMS ((void)) { \ |
Zack Weinberg | c6491210 | 2000-03-04 17:53:04 +0000 | [diff] [blame] | 245 | unsigned char *x = _cpp_IStable; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 246 | #define END } |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 247 | #define s(p, v) x[p] = v; |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 248 | #endif |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 249 | |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 250 | #define A(x) s(x, ISidnum|ISidstart) |
| 251 | #define N(x) s(x, ISidnum|ISnumstart) |
| 252 | #define H(x) s(x, IShspace|ISspace) |
| 253 | #define S(x) s(x, ISspace) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 254 | |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 255 | ISTABLE |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 256 | A('_') |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 257 | |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 258 | A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i') |
| 259 | A('j') A('k') A('l') A('m') A('n') A('o') A('p') A('q') A('r') |
| 260 | A('s') A('t') A('u') A('v') A('w') A('x') A('y') A('z') |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 261 | |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 262 | A('A') A('B') A('C') A('D') A('E') A('F') A('G') A('H') A('I') |
| 263 | A('J') A('K') A('L') A('M') A('N') A('O') A('P') A('Q') A('R') |
| 264 | A('S') A('T') A('U') A('V') A('W') A('X') A('Y') A('Z') |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 265 | |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 266 | N('1') N('2') N('3') N('4') N('5') N('6') N('7') N('8') N('9') N('0') |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 267 | |
Neil Booth | 64aaf40 | 2000-04-08 04:00:02 +0000 | [diff] [blame] | 268 | H('\0') H(' ') H('\t') H('\v') H('\f') |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 269 | |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 270 | S('\n') |
| 271 | END |
Zack Weinberg | 5538ada | 1999-02-04 06:36:54 -0500 | [diff] [blame] | 272 | |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 273 | #undef A |
| 274 | #undef N |
| 275 | #undef H |
| 276 | #undef S |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 277 | #undef s |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 278 | #undef ISTABLE |
| 279 | #undef END |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 280 | |
| 281 | /* Given a colon-separated list of file names PATH, |
| 282 | add all the names to the search path for include files. */ |
| 283 | |
| 284 | static void |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 285 | path_include (pfile, pend, list, path) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 286 | cpp_reader *pfile; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 287 | struct cpp_pending *pend; |
| 288 | char *list; |
| 289 | int path; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 290 | { |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 291 | char *p, *q, *name; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 292 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 293 | p = list; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 294 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 295 | do |
| 296 | { |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 297 | /* Find the end of this name. */ |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 298 | q = p; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 299 | while (*q != 0 && *q != PATH_SEPARATOR) q++; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 300 | if (q == p) |
| 301 | { |
| 302 | /* An empty name in the path stands for the current directory. */ |
| 303 | name = (char *) xmalloc (2); |
| 304 | name[0] = '.'; |
| 305 | name[1] = 0; |
| 306 | } |
| 307 | else |
| 308 | { |
| 309 | /* Otherwise use the directory that is named. */ |
| 310 | name = (char *) xmalloc (q - p + 1); |
| 311 | memcpy (name, p, q - p); |
| 312 | name[q - p] = 0; |
| 313 | } |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 314 | |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 315 | append_include_chain (pfile, pend, name, path, 0); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 316 | |
| 317 | /* Advance past this name. */ |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 318 | if (*q == 0) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 319 | break; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 320 | p = q + 1; |
| 321 | } |
| 322 | while (1); |
| 323 | } |
| 324 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 325 | /* Append DIR to include path PATH. DIR must be permanently allocated |
| 326 | and writable. */ |
| 327 | static void |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 328 | append_include_chain (pfile, pend, dir, path, cxx_aware) |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 329 | cpp_reader *pfile; |
| 330 | struct cpp_pending *pend; |
| 331 | char *dir; |
| 332 | int path; |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 333 | int cxx_aware; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 334 | { |
| 335 | struct file_name_list *new; |
| 336 | struct stat st; |
| 337 | unsigned int len; |
| 338 | |
Zack Weinberg | b0699da | 2000-03-07 20:58:47 +0000 | [diff] [blame] | 339 | _cpp_simplify_pathname (dir); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 340 | if (stat (dir, &st)) |
| 341 | { |
| 342 | /* Dirs that don't exist are silently ignored. */ |
| 343 | if (errno != ENOENT) |
Zack Weinberg | c1212d2 | 2000-02-06 23:46:18 +0000 | [diff] [blame] | 344 | cpp_notice_from_errno (pfile, dir); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 345 | else if (CPP_OPTION (pfile, verbose)) |
Zack Weinberg | c1212d2 | 2000-02-06 23:46:18 +0000 | [diff] [blame] | 346 | fprintf (stderr, _("ignoring nonexistent directory `%s'\n"), dir); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | |
| 350 | if (!S_ISDIR (st.st_mode)) |
| 351 | { |
Zack Weinberg | c1212d2 | 2000-02-06 23:46:18 +0000 | [diff] [blame] | 352 | cpp_notice (pfile, "%s: Not a directory", dir); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 353 | return; |
| 354 | } |
| 355 | |
| 356 | len = strlen (dir); |
| 357 | if (len > pfile->max_include_len) |
| 358 | pfile->max_include_len = len; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 359 | |
Neil Booth | 7ceb359 | 2000-03-11 00:49:44 +0000 | [diff] [blame] | 360 | new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 361 | new->name = dir; |
| 362 | new->nlen = len; |
| 363 | new->ino = st.st_ino; |
| 364 | new->dev = st.st_dev; |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 365 | if (path == SYSTEM) |
| 366 | new->sysp = cxx_aware ? 1 : 2; |
| 367 | else |
| 368 | new->sysp = 0; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 369 | new->name_map = NULL; |
Dave Brolley | 503cb43 | 1999-09-13 16:58:44 +0000 | [diff] [blame] | 370 | new->next = NULL; |
| 371 | new->alloc = NULL; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 372 | |
| 373 | switch (path) |
| 374 | { |
| 375 | case QUOTE: APPEND (pend, quote, new); break; |
| 376 | case BRACKET: APPEND (pend, brack, new); break; |
| 377 | case SYSTEM: APPEND (pend, systm, new); break; |
| 378 | case AFTER: APPEND (pend, after, new); break; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 382 | /* Merge the four include chains together in the order quote, bracket, |
| 383 | system, after. Remove duplicate dirs (as determined by |
| 384 | INO_T_EQ()). The system_include and after_include chains are never |
| 385 | referred to again after this function; all access is through the |
| 386 | bracket_include path. |
| 387 | |
| 388 | For the future: Check if the directory is empty (but |
| 389 | how?) and possibly preload the include hash. */ |
| 390 | |
| 391 | static void |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 392 | merge_include_chains (pfile) |
| 393 | cpp_reader *pfile; |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 394 | { |
| 395 | struct file_name_list *prev, *cur, *other; |
| 396 | struct file_name_list *quote, *brack, *systm, *after; |
| 397 | struct file_name_list *qtail, *btail, *stail, *atail; |
| 398 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 399 | struct cpp_pending *pend = CPP_OPTION (pfile, pending); |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 400 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 401 | qtail = pend->quote_tail; |
| 402 | btail = pend->brack_tail; |
| 403 | stail = pend->systm_tail; |
| 404 | atail = pend->after_tail; |
| 405 | |
| 406 | quote = pend->quote_head; |
| 407 | brack = pend->brack_head; |
| 408 | systm = pend->systm_head; |
| 409 | after = pend->after_head; |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 410 | |
| 411 | /* Paste together bracket, system, and after include chains. */ |
| 412 | if (stail) |
| 413 | stail->next = after; |
| 414 | else |
| 415 | systm = after; |
| 416 | if (btail) |
| 417 | btail->next = systm; |
| 418 | else |
| 419 | brack = systm; |
| 420 | |
| 421 | /* This is a bit tricky. |
| 422 | First we drop dupes from the quote-include list. |
| 423 | Then we drop dupes from the bracket-include list. |
| 424 | Finally, if qtail and brack are the same directory, |
| 425 | we cut out qtail. |
| 426 | |
| 427 | We can't just merge the lists and then uniquify them because |
| 428 | then we may lose directories from the <> search path that should |
| 429 | be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however |
| 430 | safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written |
| 431 | -Ibar -I- -Ifoo -Iquux. |
| 432 | |
| 433 | Note that this algorithm is quadratic in the number of -I switches, |
| 434 | which is acceptable since there aren't usually that many of them. */ |
| 435 | |
| 436 | for (cur = quote, prev = NULL; cur; cur = cur->next) |
| 437 | { |
| 438 | for (other = quote; other != cur; other = other->next) |
| 439 | if (INO_T_EQ (cur->ino, other->ino) |
| 440 | && cur->dev == other->dev) |
| 441 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 442 | if (CPP_OPTION (pfile, verbose)) |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 443 | fprintf (stderr, _("ignoring duplicate directory `%s'\n"), |
| 444 | cur->name); |
| 445 | |
| 446 | prev->next = cur->next; |
| 447 | free (cur->name); |
| 448 | free (cur); |
| 449 | cur = prev; |
| 450 | break; |
| 451 | } |
| 452 | prev = cur; |
| 453 | } |
| 454 | qtail = prev; |
| 455 | |
| 456 | for (cur = brack; cur; cur = cur->next) |
| 457 | { |
| 458 | for (other = brack; other != cur; other = other->next) |
| 459 | if (INO_T_EQ (cur->ino, other->ino) |
| 460 | && cur->dev == other->dev) |
| 461 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 462 | if (CPP_OPTION (pfile, verbose)) |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 463 | fprintf (stderr, _("ignoring duplicate directory `%s'\n"), |
| 464 | cur->name); |
| 465 | |
| 466 | prev->next = cur->next; |
| 467 | free (cur->name); |
| 468 | free (cur); |
| 469 | cur = prev; |
| 470 | break; |
| 471 | } |
| 472 | prev = cur; |
| 473 | } |
| 474 | |
| 475 | if (quote) |
| 476 | { |
| 477 | if (INO_T_EQ (qtail->ino, brack->ino) && qtail->dev == brack->dev) |
| 478 | { |
| 479 | if (quote == qtail) |
| 480 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 481 | if (CPP_OPTION (pfile, verbose)) |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 482 | fprintf (stderr, _("ignoring duplicate directory `%s'\n"), |
| 483 | quote->name); |
| 484 | |
| 485 | free (quote->name); |
| 486 | free (quote); |
| 487 | quote = brack; |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | cur = quote; |
| 492 | while (cur->next != qtail) |
| 493 | cur = cur->next; |
| 494 | cur->next = brack; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 495 | if (CPP_OPTION (pfile, verbose)) |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 496 | fprintf (stderr, _("ignoring duplicate directory `%s'\n"), |
| 497 | qtail->name); |
| 498 | |
| 499 | free (qtail->name); |
| 500 | free (qtail); |
| 501 | } |
| 502 | } |
| 503 | else |
| 504 | qtail->next = brack; |
| 505 | } |
| 506 | else |
| 507 | quote = brack; |
| 508 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 509 | CPP_OPTION (pfile, quote_include) = quote; |
| 510 | CPP_OPTION (pfile, bracket_include) = brack; |
Zack Weinberg | 88ae23e | 2000-03-08 23:35:19 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 513 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 514 | /* Write out a #define command for the special named MACRO_NAME |
| 515 | to PFILE's token_buffer. */ |
| 516 | |
| 517 | static void |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 518 | dump_special_to_buffer (pfile, macro_name, macro_len) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 519 | cpp_reader *pfile; |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 520 | const U_CHAR *macro_name; |
| 521 | size_t macro_len; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 522 | { |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 523 | static const char define_directive[] = "#define "; |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 524 | CPP_RESERVE (pfile, sizeof(define_directive) + macro_len); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 525 | CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1); |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 526 | CPP_PUTS_Q (pfile, macro_name, macro_len); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 527 | CPP_PUTC_Q (pfile, ' '); |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 528 | _cpp_expand_to_buffer (pfile, macro_name, macro_len); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 529 | CPP_PUTC (pfile, '\n'); |
| 530 | } |
| 531 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 532 | /* Initialize a cpp_reader structure. */ |
| 533 | void |
| 534 | cpp_reader_init (pfile) |
| 535 | cpp_reader *pfile; |
| 536 | { |
Neil Booth | 7ceb359 | 2000-03-11 00:49:44 +0000 | [diff] [blame] | 537 | memset ((char *) pfile, 0, sizeof (cpp_reader)); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 538 | |
| 539 | pfile->token_buffer_size = 200; |
| 540 | pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size); |
| 541 | CPP_SET_WRITTEN (pfile, 0); |
Zack Weinberg | 122ae89 | 1999-02-25 14:24:40 +0000 | [diff] [blame] | 542 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 543 | CPP_OPTION (pfile, dollars_in_ident) = 1; |
| 544 | CPP_OPTION (pfile, cplusplus_comments) = 1; |
| 545 | CPP_OPTION (pfile, warn_import) = 1; |
| 546 | CPP_OPTION (pfile, discard_comments) = 1; |
| 547 | CPP_OPTION (pfile, show_column) = 1; |
Neil Booth | 6ab3e7d | 2000-05-18 11:09:27 +0000 | [diff] [blame] | 548 | CPP_OPTION (pfile, tabstop) = 8; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 549 | |
| 550 | CPP_OPTION (pfile, pending) = |
| 551 | (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); |
| 552 | |
Zack Weinberg | d35364d | 2000-03-12 23:46:05 +0000 | [diff] [blame] | 553 | _cpp_init_macro_hash (pfile); |
| 554 | _cpp_init_include_hash (pfile); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 557 | /* Initialize a cpp_printer structure. As a side effect, open the |
| 558 | output file. */ |
| 559 | cpp_printer * |
| 560 | cpp_printer_init (pfile, print) |
| 561 | cpp_reader *pfile; |
| 562 | cpp_printer *print; |
| 563 | { |
| 564 | memset (print, '\0', sizeof (cpp_printer)); |
| 565 | if (CPP_OPTION (pfile, out_fname) == NULL) |
| 566 | CPP_OPTION (pfile, out_fname) = ""; |
| 567 | |
| 568 | if (CPP_OPTION (pfile, out_fname)[0] == '\0') |
| 569 | print->outf = stdout; |
| 570 | else |
| 571 | { |
| 572 | print->outf = fopen (CPP_OPTION (pfile, out_fname), "w"); |
| 573 | if (! print->outf) |
| 574 | { |
| 575 | cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); |
| 576 | return NULL; |
| 577 | } |
| 578 | } |
| 579 | return print; |
| 580 | } |
| 581 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 582 | /* Free resources used by PFILE. |
| 583 | This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */ |
| 584 | void |
| 585 | cpp_cleanup (pfile) |
| 586 | cpp_reader *pfile; |
| 587 | { |
Zack Weinberg | 38b24ee | 2000-03-08 20:37:23 +0000 | [diff] [blame] | 588 | while (CPP_BUFFER (pfile) != NULL) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 589 | cpp_pop_buffer (pfile); |
| 590 | |
| 591 | if (pfile->token_buffer) |
| 592 | { |
| 593 | free (pfile->token_buffer); |
| 594 | pfile->token_buffer = NULL; |
| 595 | } |
| 596 | |
Zack Weinberg | 2c82621 | 1999-05-10 11:24:36 -0400 | [diff] [blame] | 597 | if (pfile->input_buffer) |
| 598 | { |
| 599 | free (pfile->input_buffer); |
Zack Weinberg | 46d0749 | 2000-04-01 22:02:31 +0000 | [diff] [blame] | 600 | pfile->input_buffer = NULL; |
Zack Weinberg | 2c82621 | 1999-05-10 11:24:36 -0400 | [diff] [blame] | 601 | pfile->input_buffer_len = 0; |
| 602 | } |
| 603 | |
Zack Weinberg | 49e6c08 | 2000-03-04 19:42:04 +0000 | [diff] [blame] | 604 | if (pfile->deps) |
| 605 | deps_free (pfile->deps); |
| 606 | |
Zack Weinberg | d35364d | 2000-03-12 23:46:05 +0000 | [diff] [blame] | 607 | htab_delete (pfile->hashtab); |
| 608 | htab_delete (pfile->all_include_files); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 612 | /* This structure defines one built-in macro. A node of type TYPE will |
| 613 | be entered in the macro hash table under the name NAME, with value |
| 614 | VALUE (if any). FLAGS tweaks the behavior a little: |
| 615 | DUMP write debug info for this macro |
Zack Weinberg | 8c389f8 | 2000-04-10 03:27:21 +0000 | [diff] [blame] | 616 | VERS value is the global version_string, quoted |
| 617 | ULP value is the global user_label_prefix |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 618 | */ |
| 619 | |
| 620 | struct builtin |
| 621 | { |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 622 | const U_CHAR *name; |
| 623 | const U_CHAR *value; |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 624 | unsigned short type; |
| 625 | unsigned short flags; |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 626 | unsigned int len; |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 627 | }; |
| 628 | #define DUMP 0x01 |
Zack Weinberg | 8c389f8 | 2000-04-10 03:27:21 +0000 | [diff] [blame] | 629 | #define VERS 0x02 |
| 630 | #define ULP 0x04 |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 631 | |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 632 | #define B(n, t) { U n, 0, t, 0, sizeof n - 1 } |
| 633 | #define C(n, v) { U n, U v, T_CONST, DUMP, sizeof n - 1 } |
| 634 | #define X(n, v, t, f) { U n, U v, t, DUMP|f, sizeof n - 1 } |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 635 | static const struct builtin builtin_array[] = |
| 636 | { |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 637 | B("__TIME__", T_TIME), |
| 638 | B("__DATE__", T_DATE), |
| 639 | B("__FILE__", T_FILE), |
| 640 | B("__BASE_FILE__", T_BASE_FILE), |
| 641 | B("__LINE__", T_SPECLINE), |
| 642 | B("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL), |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 643 | |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 644 | X("__VERSION__", 0, T_XCONST, VERS), |
| 645 | X("__USER_LABEL_PREFIX__", 0, T_CONST, ULP), |
| 646 | X("__STDC__", "1", T_STDC, 0), |
| 647 | C("__REGISTER_PREFIX__", REGISTER_PREFIX), |
| 648 | C("__HAVE_BUILTIN_SETJMP__", "1"), |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 649 | #ifndef NO_BUILTIN_SIZE_TYPE |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 650 | C("__SIZE_TYPE__", SIZE_TYPE), |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 651 | #endif |
| 652 | #ifndef NO_BUILTIN_PTRDIFF_TYPE |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 653 | C("__PTRDIFF_TYPE__", PTRDIFF_TYPE), |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 654 | #endif |
Zack Weinberg | 0209c34 | 2000-02-28 21:09:54 +0000 | [diff] [blame] | 655 | #ifndef NO_BUILTIN_WCHAR_TYPE |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 656 | C("__WCHAR_TYPE__", WCHAR_TYPE), |
Zack Weinberg | 0209c34 | 2000-02-28 21:09:54 +0000 | [diff] [blame] | 657 | #endif |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 658 | }; |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 659 | #undef B |
| 660 | #undef C |
| 661 | #undef X |
Zack Weinberg | 8c389f8 | 2000-04-10 03:27:21 +0000 | [diff] [blame] | 662 | #define builtin_array_end \ |
| 663 | builtin_array + sizeof(builtin_array)/sizeof(struct builtin) |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 664 | |
| 665 | /* Subroutine of cpp_start_read; reads the builtins table above and |
| 666 | enters the macros into the hash table. */ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 667 | static void |
| 668 | initialize_builtins (pfile) |
| 669 | cpp_reader *pfile; |
| 670 | { |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 671 | const struct builtin *b; |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 672 | const U_CHAR *val; |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 673 | cpp_hashnode *hp; |
Zack Weinberg | 8c389f8 | 2000-04-10 03:27:21 +0000 | [diff] [blame] | 674 | for(b = builtin_array; b < builtin_array_end; b++) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 675 | { |
Zack Weinberg | 8c389f8 | 2000-04-10 03:27:21 +0000 | [diff] [blame] | 676 | if (b->type == T_STDC && CPP_TRADITIONAL (pfile)) |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 677 | continue; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 678 | |
Zack Weinberg | 6feb772 | 2000-03-13 00:10:13 +0000 | [diff] [blame] | 679 | if (b->flags & ULP) |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 680 | val = (const U_CHAR *) user_label_prefix; |
Zack Weinberg | 6feb772 | 2000-03-13 00:10:13 +0000 | [diff] [blame] | 681 | else if (b->flags & VERS) |
Zack Weinberg | 8c389f8 | 2000-04-10 03:27:21 +0000 | [diff] [blame] | 682 | { |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 683 | val = (const U_CHAR *) xmalloc (strlen (version_string) + 3); |
Zack Weinberg | 8c389f8 | 2000-04-10 03:27:21 +0000 | [diff] [blame] | 684 | sprintf ((char *)val, "\"%s\"", version_string); |
| 685 | } |
Zack Weinberg | 6feb772 | 2000-03-13 00:10:13 +0000 | [diff] [blame] | 686 | else |
| 687 | val = b->value; |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 688 | |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 689 | hp = cpp_lookup (pfile, b->name, b->len); |
Zack Weinberg | d35364d | 2000-03-12 23:46:05 +0000 | [diff] [blame] | 690 | hp->value.cpval = val; |
Zack Weinberg | a7abcbb | 2000-05-01 18:20:10 +0000 | [diff] [blame] | 691 | hp->type = b->type; |
Zack Weinberg | d35364d | 2000-03-12 23:46:05 +0000 | [diff] [blame] | 692 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 693 | if ((b->flags & DUMP) && CPP_OPTION (pfile, debug_output)) |
Zack Weinberg | 12cf91f | 2000-05-04 04:38:01 +0000 | [diff] [blame] | 694 | dump_special_to_buffer (pfile, b->name, b->len); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 697 | #undef DUMP |
| 698 | #undef STDC |
Zack Weinberg | 6feb772 | 2000-03-13 00:10:13 +0000 | [diff] [blame] | 699 | #undef VERS |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 700 | #undef ULP |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 701 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 702 | /* Another subroutine of cpp_start_read. This one sets up to do |
| 703 | dependency-file output. */ |
| 704 | static void |
| 705 | initialize_dependency_output (pfile) |
| 706 | cpp_reader *pfile; |
| 707 | { |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 708 | char *spec, *s, *output_file; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 709 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 710 | /* Either of two environment variables can specify output of deps. |
| 711 | Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET", |
| 712 | where OUTPUT_FILE is the file to write deps info to |
| 713 | and DEPS_TARGET is the target to mention in the deps. */ |
| 714 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 715 | if (CPP_OPTION (pfile, print_deps) == 0) |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 716 | { |
| 717 | spec = getenv ("DEPENDENCIES_OUTPUT"); |
| 718 | if (spec) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 719 | CPP_OPTION (pfile, print_deps) = 1; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 720 | else |
| 721 | { |
| 722 | spec = getenv ("SUNPRO_DEPENDENCIES"); |
| 723 | if (spec) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 724 | CPP_OPTION (pfile, print_deps) = 2; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 725 | else |
| 726 | return; |
| 727 | } |
| 728 | |
| 729 | /* Find the space before the DEPS_TARGET, if there is one. */ |
| 730 | s = strchr (spec, ' '); |
| 731 | if (s) |
| 732 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 733 | CPP_OPTION (pfile, deps_target) = s + 1; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 734 | output_file = (char *) xmalloc (s - spec + 1); |
| 735 | memcpy (output_file, spec, s - spec); |
| 736 | output_file[s - spec] = 0; |
| 737 | } |
| 738 | else |
| 739 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 740 | CPP_OPTION (pfile, deps_target) = 0; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 741 | output_file = spec; |
| 742 | } |
| 743 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 744 | CPP_OPTION (pfile, deps_file) = output_file; |
| 745 | CPP_OPTION (pfile, print_deps_append) = 1; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Zack Weinberg | 49e6c08 | 2000-03-04 19:42:04 +0000 | [diff] [blame] | 748 | pfile->deps = deps_init (); |
| 749 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 750 | /* Print the expected object file name as the target of this Make-rule. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 751 | if (CPP_OPTION (pfile, deps_target)) |
| 752 | deps_add_target (pfile->deps, CPP_OPTION (pfile, deps_target)); |
| 753 | else if (*CPP_OPTION (pfile, in_fname) == 0) |
Zack Weinberg | 49e6c08 | 2000-03-04 19:42:04 +0000 | [diff] [blame] | 754 | deps_add_target (pfile->deps, "-"); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 755 | else |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 756 | deps_calc_target (pfile->deps, CPP_OPTION (pfile, in_fname)); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 757 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 758 | if (CPP_OPTION (pfile, in_fname)) |
| 759 | deps_add_dep (pfile->deps, CPP_OPTION (pfile, in_fname)); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 762 | /* And another subroutine. This one sets up the standard include path. */ |
| 763 | static void |
| 764 | initialize_standard_includes (pfile) |
| 765 | cpp_reader *pfile; |
| 766 | { |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 767 | char *path; |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 768 | const struct default_include *p; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 769 | const char *specd_prefix = CPP_OPTION (pfile, include_prefix); |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 770 | |
| 771 | /* Several environment variables may add to the include search path. |
| 772 | CPATH specifies an additional list of directories to be searched |
| 773 | as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, |
| 774 | etc. specify an additional list of directories to be searched as |
| 775 | if specified with -isystem, for the language indicated. */ |
| 776 | |
| 777 | GET_ENV_PATH_LIST (path, "CPATH"); |
| 778 | if (path != 0 && *path != 0) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 779 | path_include (pfile, CPP_OPTION (pfile, pending), path, BRACKET); |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 780 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 781 | switch ((CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus)) |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 782 | { |
| 783 | case 0: |
| 784 | GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH"); |
| 785 | break; |
| 786 | case 1: |
| 787 | GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH"); |
| 788 | break; |
| 789 | case 2: |
| 790 | GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH"); |
| 791 | break; |
| 792 | case 3: |
| 793 | GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH"); |
| 794 | break; |
| 795 | } |
| 796 | if (path != 0 && *path != 0) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 797 | path_include (pfile, CPP_OPTION (pfile, pending), path, SYSTEM); |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 798 | |
| 799 | /* Search "translated" versions of GNU directories. |
| 800 | These have /usr/local/lib/gcc... replaced by specd_prefix. */ |
| 801 | if (specd_prefix != 0) |
| 802 | { |
Dave Pitts | 5f6d382 | 2000-04-16 17:54:25 -0700 | [diff] [blame] | 803 | char *default_prefix = (char *) alloca (sizeof GCC_INCLUDE_DIR - 7); |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 804 | /* Remove the `include' from /usr/local/lib/gcc.../include. |
| 805 | GCC_INCLUDE_DIR will always end in /include. */ |
| 806 | int default_len = sizeof GCC_INCLUDE_DIR - 8; |
| 807 | int specd_len = strlen (specd_prefix); |
| 808 | |
| 809 | memcpy (default_prefix, GCC_INCLUDE_DIR, default_len); |
| 810 | default_prefix[default_len] = '\0'; |
| 811 | |
| 812 | for (p = include_defaults_array; p->fname; p++) |
| 813 | { |
| 814 | /* Some standard dirs are only for C++. */ |
| 815 | if (!p->cplusplus |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 816 | || (CPP_OPTION (pfile, cplusplus) |
| 817 | && !CPP_OPTION (pfile, no_standard_cplusplus_includes))) |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 818 | { |
| 819 | /* Does this dir start with the prefix? */ |
| 820 | if (!strncmp (p->fname, default_prefix, default_len)) |
| 821 | { |
| 822 | /* Yes; change prefix and add to search list. */ |
| 823 | int flen = strlen (p->fname); |
| 824 | int this_len = specd_len + flen - default_len; |
| 825 | char *str = (char *) xmalloc (this_len + 1); |
| 826 | memcpy (str, specd_prefix, specd_len); |
| 827 | memcpy (str + specd_len, |
| 828 | p->fname + default_len, |
| 829 | flen - default_len + 1); |
| 830 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 831 | append_include_chain (pfile, CPP_OPTION (pfile, pending), |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 832 | str, SYSTEM, p->cxx_aware); |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | /* Search ordinary names for GNU include directories. */ |
| 839 | for (p = include_defaults_array; p->fname; p++) |
| 840 | { |
| 841 | /* Some standard dirs are only for C++. */ |
| 842 | if (!p->cplusplus |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 843 | || (CPP_OPTION (pfile, cplusplus) |
| 844 | && !CPP_OPTION (pfile, no_standard_cplusplus_includes))) |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 845 | { |
| 846 | /* XXX Potential memory leak! */ |
| 847 | char *str = xstrdup (update_path (p->fname, p->component)); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 848 | append_include_chain (pfile, CPP_OPTION (pfile, pending), |
| 849 | str, SYSTEM, p->cxx_aware); |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | } |
| 853 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 854 | /* This is called after options have been processed. |
| 855 | * Check options for consistency, and setup for processing input |
| 856 | * from the file named FNAME. (Use standard input if FNAME==NULL.) |
| 857 | * Return 1 on success, 0 on failure. |
| 858 | */ |
| 859 | |
| 860 | int |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 861 | cpp_start_read (pfile, print, fname) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 862 | cpp_reader *pfile; |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 863 | cpp_printer *print; |
Neil Booth | 7ceb359 | 2000-03-11 00:49:44 +0000 | [diff] [blame] | 864 | const char *fname; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 865 | { |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 866 | struct pending_option *p, *q; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 867 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 868 | /* -MG doesn't select the form of output and must be specified with one of |
| 869 | -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't |
| 870 | inhibit compilation. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 871 | if (CPP_OPTION (pfile, print_deps_missing_files) |
| 872 | && (CPP_OPTION (pfile, print_deps) == 0 |
| 873 | || !CPP_OPTION (pfile, no_output))) |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 874 | { |
| 875 | cpp_fatal (pfile, "-MG must be specified with one of -M or -MM"); |
| 876 | return 0; |
| 877 | } |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 878 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 879 | /* Chill should not be used with -trigraphs. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 880 | if (CPP_OPTION (pfile, chill) && CPP_OPTION (pfile, trigraphs)) |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 881 | { |
| 882 | cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive"); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 883 | CPP_OPTION (pfile, trigraphs) = 0; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Zack Weinberg | bfab56e | 2000-04-02 22:50:55 +0000 | [diff] [blame] | 886 | /* -Wtraditional is not useful in C++ mode. */ |
| 887 | if (CPP_OPTION (pfile, cplusplus)) |
| 888 | CPP_OPTION (pfile, warn_traditional) = 0; |
| 889 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 890 | /* Set this if it hasn't been set already. */ |
| 891 | if (user_label_prefix == NULL) |
| 892 | user_label_prefix = USER_LABEL_PREFIX; |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 893 | |
| 894 | /* Don't bother trying to do macro expansion if we've already done |
| 895 | preprocessing. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 896 | if (CPP_OPTION (pfile, preprocessed)) |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 897 | pfile->no_macro_expand++; |
Zack Weinberg | 455d258 | 2000-03-04 01:42:56 +0000 | [diff] [blame] | 898 | |
| 899 | /* Set up the IStable. This doesn't do anything if we were compiled |
| 900 | with a compiler that supports C99 designated initializers. */ |
Zack Weinberg | a9ae448 | 1999-10-29 04:31:14 +0000 | [diff] [blame] | 901 | init_IStable (); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 902 | |
Zack Weinberg | 45b966d | 2000-03-13 22:01:08 +0000 | [diff] [blame] | 903 | /* Set up the tables used by read_and_prescan. */ |
| 904 | _cpp_init_input_buffer (pfile); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 905 | |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 906 | /* Set up the include search path now. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 907 | if (! CPP_OPTION (pfile, no_standard_includes)) |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 908 | initialize_standard_includes (pfile); |
| 909 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 910 | merge_include_chains (pfile); |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 911 | |
| 912 | /* With -v, print the list of dirs to search. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 913 | if (CPP_OPTION (pfile, verbose)) |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 914 | { |
| 915 | struct file_name_list *l; |
| 916 | fprintf (stderr, _("#include \"...\" search starts here:\n")); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 917 | for (l = CPP_OPTION (pfile, quote_include); l; l = l->next) |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 918 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 919 | if (l == CPP_OPTION (pfile, bracket_include)) |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 920 | fprintf (stderr, _("#include <...> search starts here:\n")); |
| 921 | fprintf (stderr, " %s\n", l->name); |
| 922 | } |
| 923 | fprintf (stderr, _("End of search list.\n")); |
| 924 | } |
| 925 | |
Zack Weinberg | 4b3fe5b | 2000-03-30 07:42:55 +0000 | [diff] [blame] | 926 | /* Open the main input file. This must be done early, so we have a |
| 927 | buffer to stand on. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 928 | if (CPP_OPTION (pfile, in_fname) == NULL |
| 929 | || *CPP_OPTION (pfile, in_fname) == 0) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 930 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 931 | CPP_OPTION (pfile, in_fname) = fname; |
| 932 | if (CPP_OPTION (pfile, in_fname) == NULL) |
| 933 | CPP_OPTION (pfile, in_fname) = ""; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 934 | } |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 935 | if (CPP_OPTION (pfile, out_fname) == NULL) |
| 936 | CPP_OPTION (pfile, out_fname) = ""; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 937 | |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 938 | if (!cpp_read_file (pfile, fname)) |
| 939 | return 0; |
| 940 | |
Zack Weinberg | 4b3fe5b | 2000-03-30 07:42:55 +0000 | [diff] [blame] | 941 | initialize_dependency_output (pfile); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 942 | |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 943 | /* -D and friends may produce output, which should be identified |
| 944 | as line 0. */ |
| 945 | |
| 946 | CPP_BUFFER (pfile)->lineno = 0; |
| 947 | |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 948 | if (print) |
| 949 | { |
| 950 | print->lineno = 0; |
| 951 | print->last_fname = CPP_BUFFER (pfile)->nominal_fname; |
| 952 | print->last_bsd = pfile->buffer_stack_depth; |
| 953 | print->written = CPP_WRITTEN (pfile); |
| 954 | } |
| 955 | |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 956 | /* Install __LINE__, etc. */ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 957 | initialize_builtins (pfile); |
| 958 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 959 | /* Do -U's, -D's and -A's in the order they were seen. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 960 | p = CPP_OPTION (pfile, pending)->directive_head; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 961 | while (p) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 962 | { |
Neil Booth | b1b74f9 | 2000-03-12 00:32:01 +0000 | [diff] [blame] | 963 | (*p->handler) (pfile, p->arg); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 964 | q = p->next; |
| 965 | free (p); |
| 966 | p = q; |
| 967 | } |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 968 | pfile->done_initializing = 1; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 969 | pfile->only_seen_white = 2; |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 970 | CPP_BUFFER (pfile)->lineno = 1; |
| 971 | if (print && ! CPP_OPTION (pfile, no_output)) |
| 972 | cpp_output_tokens (pfile, print); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 973 | |
| 974 | /* The -imacros files can be scanned now, but the -include files |
| 975 | have to be pushed onto the include stack and processed later, |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 976 | in the main loop calling cpp_get_token. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 977 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 978 | p = CPP_OPTION (pfile, pending)->imacros_head; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 979 | while (p) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 980 | { |
Zack Weinberg | c45da1c | 2000-03-02 20:14:32 +0000 | [diff] [blame] | 981 | if (cpp_read_file (pfile, p->arg)) |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 982 | cpp_scan_buffer_nooutput (pfile); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 983 | q = p->next; |
| 984 | free (p); |
| 985 | p = q; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 986 | } |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 987 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 988 | p = CPP_OPTION (pfile, pending)->include_head; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 989 | while (p) |
| 990 | { |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 991 | if (cpp_read_file (pfile, p->arg) |
| 992 | && print && ! CPP_OPTION (pfile, no_output)) |
| 993 | cpp_output_tokens (pfile, print); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 994 | q = p->next; |
| 995 | free (p); |
| 996 | p = q; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 997 | } |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 998 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 999 | free (CPP_OPTION (pfile, pending)); |
| 1000 | CPP_OPTION (pfile, pending) = NULL; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1001 | |
| 1002 | return 1; |
| 1003 | } |
| 1004 | |
| 1005 | /* This is called at the end of preprocessing. It pops the |
| 1006 | last buffer and writes dependency output. It should also |
| 1007 | clear macro definitions, such that you could call cpp_start_read |
| 1008 | with a new filename to restart processing. */ |
| 1009 | void |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 1010 | cpp_finish (pfile, print) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1011 | cpp_reader *pfile; |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 1012 | cpp_printer *print; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1013 | { |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 1014 | if (CPP_BUFFER (pfile)) |
| 1015 | { |
| 1016 | cpp_ice (pfile, "buffers still stacked in cpp_finish"); |
| 1017 | while (CPP_BUFFER (pfile)) |
| 1018 | cpp_pop_buffer (pfile); |
| 1019 | } |
Zack Weinberg | c1212d2 | 2000-02-06 23:46:18 +0000 | [diff] [blame] | 1020 | |
Zack Weinberg | 49e6c08 | 2000-03-04 19:42:04 +0000 | [diff] [blame] | 1021 | /* Don't write the deps file if preprocessing has failed. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1022 | if (CPP_OPTION (pfile, print_deps) && pfile->errors == 0) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1023 | { |
| 1024 | /* Stream on which to print the dependency information. */ |
Zack Weinberg | c1212d2 | 2000-02-06 23:46:18 +0000 | [diff] [blame] | 1025 | FILE *deps_stream = 0; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1026 | const char *deps_mode |
| 1027 | = CPP_OPTION (pfile, print_deps_append) ? "a" : "w"; |
| 1028 | if (CPP_OPTION (pfile, deps_file) == 0) |
Zack Weinberg | 49e6c08 | 2000-03-04 19:42:04 +0000 | [diff] [blame] | 1029 | deps_stream = stdout; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1030 | else |
| 1031 | { |
| 1032 | deps_stream = fopen (CPP_OPTION (pfile, deps_file), deps_mode); |
| 1033 | if (deps_stream == 0) |
| 1034 | cpp_notice_from_errno (pfile, CPP_OPTION (pfile, deps_file)); |
| 1035 | } |
Zack Weinberg | 49e6c08 | 2000-03-04 19:42:04 +0000 | [diff] [blame] | 1036 | if (deps_stream) |
| 1037 | { |
| 1038 | deps_write (pfile->deps, deps_stream, 72); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1039 | if (CPP_OPTION (pfile, deps_file)) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1040 | { |
Zack Weinberg | 49e6c08 | 2000-03-04 19:42:04 +0000 | [diff] [blame] | 1041 | if (ferror (deps_stream) || fclose (deps_stream) != 0) |
| 1042 | cpp_fatal (pfile, "I/O error on output"); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | } |
Zack Weinberg | 3caee4a | 1999-04-26 16:41:02 +0000 | [diff] [blame] | 1046 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1047 | if (CPP_OPTION (pfile, dump_macros) == dump_only) |
Zack Weinberg | d35364d | 2000-03-12 23:46:05 +0000 | [diff] [blame] | 1048 | _cpp_dump_macro_hash (pfile); |
Zack Weinberg | f2d5f0c | 2000-04-14 23:29:45 +0000 | [diff] [blame] | 1049 | |
| 1050 | /* Flush any pending output. */ |
| 1051 | if (print) |
| 1052 | { |
| 1053 | cpp_output_tokens (pfile, print); |
| 1054 | if (ferror (print->outf) || fclose (print->outf)) |
| 1055 | cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); |
| 1056 | } |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Richard Henderson | 223dca6 | 1999-12-14 08:05:23 -0800 | [diff] [blame] | 1059 | static void |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1060 | new_pending_directive (pend, text, handler) |
| 1061 | struct cpp_pending *pend; |
Richard Henderson | 223dca6 | 1999-12-14 08:05:23 -0800 | [diff] [blame] | 1062 | const char *text; |
Neil Booth | 40eac64 | 2000-03-11 09:13:00 +0000 | [diff] [blame] | 1063 | cl_directive_handler handler; |
Richard Henderson | 223dca6 | 1999-12-14 08:05:23 -0800 | [diff] [blame] | 1064 | { |
| 1065 | struct pending_option *o = (struct pending_option *) |
| 1066 | xmalloc (sizeof (struct pending_option)); |
| 1067 | |
Neil Booth | 7ceb359 | 2000-03-11 00:49:44 +0000 | [diff] [blame] | 1068 | o->arg = text; |
Richard Henderson | 223dca6 | 1999-12-14 08:05:23 -0800 | [diff] [blame] | 1069 | o->next = NULL; |
Neil Booth | 40eac64 | 2000-03-11 09:13:00 +0000 | [diff] [blame] | 1070 | o->handler = handler; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1071 | APPEND (pend, directive, o); |
Richard Henderson | 223dca6 | 1999-12-14 08:05:23 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1074 | /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string"); |
| 1075 | I.e. a const string initializer with parens around it. That is |
| 1076 | what N_("string") resolves to, so we make no_* be macros instead. */ |
| 1077 | #define no_arg N_("Argument missing after %s") |
| 1078 | #define no_ass N_("Assertion missing after %s") |
| 1079 | #define no_dir N_("Directory name missing after %s") |
| 1080 | #define no_fil N_("File name missing after %s") |
| 1081 | #define no_mac N_("Macro name missing after %s") |
| 1082 | #define no_pth N_("Path name missing after %s") |
Neil Booth | 6ab3e7d | 2000-05-18 11:09:27 +0000 | [diff] [blame] | 1083 | #define no_num N_("Number missing after %s") |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1084 | |
| 1085 | /* This is the list of all command line options, with the leading |
| 1086 | "-" removed. It must be sorted in ASCII collating order. */ |
| 1087 | #define COMMAND_LINE_OPTIONS \ |
| 1088 | DEF_OPT("", 0, OPT_stdin_stdout) \ |
| 1089 | DEF_OPT("$", 0, OPT_dollar) \ |
| 1090 | DEF_OPT("+", 0, OPT_plus) \ |
| 1091 | DEF_OPT("-help", 0, OPT__help) \ |
| 1092 | DEF_OPT("-version", 0, OPT__version) \ |
| 1093 | DEF_OPT("A", no_ass, OPT_A) \ |
| 1094 | DEF_OPT("C", 0, OPT_C) \ |
| 1095 | DEF_OPT("D", no_mac, OPT_D) \ |
| 1096 | DEF_OPT("H", 0, OPT_H) \ |
| 1097 | DEF_OPT("I", no_dir, OPT_I) \ |
| 1098 | DEF_OPT("M", 0, OPT_M) \ |
| 1099 | DEF_OPT("MD", no_fil, OPT_MD) \ |
| 1100 | DEF_OPT("MG", 0, OPT_MG) \ |
| 1101 | DEF_OPT("MM", 0, OPT_MM) \ |
| 1102 | DEF_OPT("MMD", no_fil, OPT_MMD) \ |
| 1103 | DEF_OPT("P", 0, OPT_P) \ |
| 1104 | DEF_OPT("U", no_mac, OPT_U) \ |
| 1105 | DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \ |
| 1106 | DEF_OPT("d", no_arg, OPT_d) \ |
| 1107 | DEF_OPT("fleading-underscore", 0, OPT_fleading_underscore) \ |
| 1108 | DEF_OPT("fno-leading-underscore", 0, OPT_fno_leading_underscore) \ |
| 1109 | DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \ |
| 1110 | DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \ |
| 1111 | DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \ |
| 1112 | DEF_OPT("fshow-column", 0, OPT_fshow_column) \ |
Neil Booth | 6ab3e7d | 2000-05-18 11:09:27 +0000 | [diff] [blame] | 1113 | DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1114 | DEF_OPT("g", no_arg, OPT_g) /* arg optional */ \ |
| 1115 | DEF_OPT("h", 0, OPT_h) \ |
| 1116 | DEF_OPT("idirafter", no_dir, OPT_idirafter) \ |
| 1117 | DEF_OPT("imacros", no_fil, OPT_imacros) \ |
| 1118 | DEF_OPT("include", no_fil, OPT_include) \ |
| 1119 | DEF_OPT("iprefix", no_pth, OPT_iprefix) \ |
| 1120 | DEF_OPT("isystem", no_dir, OPT_isystem) \ |
| 1121 | DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \ |
| 1122 | DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \ |
| 1123 | DEF_OPT("lang-asm", 0, OPT_lang_asm) \ |
| 1124 | DEF_OPT("lang-c", 0, OPT_lang_c) \ |
| 1125 | DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \ |
| 1126 | DEF_OPT("lang-c89", 0, OPT_lang_c89) \ |
| 1127 | DEF_OPT("lang-chill", 0, OPT_lang_chill) \ |
| 1128 | DEF_OPT("lang-fortran", 0, OPT_lang_fortran) \ |
| 1129 | DEF_OPT("lang-objc", 0, OPT_lang_objc) \ |
| 1130 | DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus) \ |
| 1131 | DEF_OPT("nostdinc", 0, OPT_nostdinc) \ |
| 1132 | DEF_OPT("nostdinc++", 0, OPT_nostdincplusplus) \ |
| 1133 | DEF_OPT("o", no_fil, OPT_o) \ |
| 1134 | DEF_OPT("pedantic", 0, OPT_pedantic) \ |
| 1135 | DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \ |
| 1136 | DEF_OPT("remap", 0, OPT_remap) \ |
| 1137 | DEF_OPT("std=c89", 0, OPT_std_c89) \ |
| 1138 | DEF_OPT("std=c99", 0, OPT_std_c99) \ |
| 1139 | DEF_OPT("std=c9x", 0, OPT_std_c9x) \ |
| 1140 | DEF_OPT("std=gnu89", 0, OPT_std_gnu89) \ |
| 1141 | DEF_OPT("std=gnu99", 0, OPT_std_gnu99) \ |
| 1142 | DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x) \ |
| 1143 | DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990) \ |
| 1144 | DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \ |
| 1145 | DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \ |
| 1146 | DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \ |
| 1147 | DEF_OPT("traditional", 0, OPT_traditional) \ |
| 1148 | DEF_OPT("trigraphs", 0, OPT_trigraphs) \ |
| 1149 | DEF_OPT("v", 0, OPT_v) \ |
| 1150 | DEF_OPT("w", 0, OPT_w) |
| 1151 | |
| 1152 | #define DEF_OPT(text, msg, code) code, |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1153 | enum opt_code |
| 1154 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1155 | COMMAND_LINE_OPTIONS |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1156 | N_OPTS |
| 1157 | }; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1158 | #undef DEF_OPT |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1159 | |
| 1160 | struct cl_option |
| 1161 | { |
| 1162 | const char *opt_text; |
| 1163 | const char *msg; |
| 1164 | size_t opt_len; |
| 1165 | enum opt_code opt_code; |
| 1166 | }; |
| 1167 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1168 | #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code }, |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1169 | #ifdef HOST_EBCDIC |
| 1170 | static struct cl_option cl_options[] = |
| 1171 | #else |
| 1172 | static const struct cl_option cl_options[] = |
| 1173 | #endif |
| 1174 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1175 | COMMAND_LINE_OPTIONS |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1176 | }; |
| 1177 | #undef DEF_OPT |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1178 | #undef COMMAND_LINE_OPTIONS |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1179 | |
| 1180 | /* Perform a binary search to find which, if any, option the given |
| 1181 | command-line matches. Returns its index in the option array, |
| 1182 | negative on failure. Complications arise since some options can be |
| 1183 | suffixed with an argument, and multiple complete matches can occur, |
| 1184 | e.g. -iwithprefix and -iwithprefixbefore. Moreover, we want to |
| 1185 | accept options beginning with -g and -W that we do not recognise, |
| 1186 | but not to swallow any subsequent command line argument; these are |
| 1187 | handled as special cases in cpp_handle_option */ |
| 1188 | static int |
| 1189 | parse_option (input) |
| 1190 | const char *input; |
| 1191 | { |
| 1192 | unsigned int md, mn, mx; |
| 1193 | size_t opt_len; |
| 1194 | int comp; |
| 1195 | |
| 1196 | mn = 0; |
| 1197 | mx = N_OPTS; |
| 1198 | |
| 1199 | while (mx > mn) |
| 1200 | { |
| 1201 | md = (mn + mx) / 2; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1202 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1203 | opt_len = cl_options[md].opt_len; |
| 1204 | comp = strncmp (input, cl_options[md].opt_text, opt_len); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1205 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1206 | if (comp > 0) |
| 1207 | mn = md + 1; |
| 1208 | else if (comp < 0) |
| 1209 | mx = md; |
| 1210 | else |
| 1211 | { |
| 1212 | if (input[opt_len] == '\0') |
| 1213 | return md; |
| 1214 | /* We were passed more text. If the option takes an argument, |
| 1215 | we may match a later option or we may have been passed the |
| 1216 | argument. The longest possible option match succeeds. |
| 1217 | If the option takes no arguments we have not matched and |
| 1218 | continue the search (e.g. input="stdc++" match was "stdc") */ |
| 1219 | mn = md + 1; |
| 1220 | if (cl_options[md].msg) |
| 1221 | { |
| 1222 | /* Scan forwards. If we get an exact match, return it. |
| 1223 | Otherwise, return the longest option-accepting match. |
| 1224 | This loops no more than twice with current options */ |
| 1225 | mx = md; |
| 1226 | for (; mn < N_OPTS; mn++) |
| 1227 | { |
| 1228 | opt_len = cl_options[mn].opt_len; |
| 1229 | if (strncmp (input, cl_options[mn].opt_text, opt_len)) |
| 1230 | break; |
| 1231 | if (input[opt_len] == '\0') |
| 1232 | return mn; |
| 1233 | if (cl_options[mn].msg) |
| 1234 | mx = mn; |
| 1235 | } |
| 1236 | return mx; |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | return -1; |
| 1242 | } |
| 1243 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1244 | /* Handle one command-line option in (argc, argv). |
| 1245 | Can be called multiple times, to handle multiple sets of options. |
| 1246 | Returns number of strings consumed. */ |
Richard Kenner | c8d8ed6 | 2000-02-19 01:27:00 +0000 | [diff] [blame] | 1247 | |
Zack Weinberg | b0699da | 2000-03-07 20:58:47 +0000 | [diff] [blame] | 1248 | static int |
| 1249 | handle_option (pfile, argc, argv) |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1250 | cpp_reader *pfile; |
| 1251 | int argc; |
| 1252 | char **argv; |
| 1253 | { |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1254 | int i = 0; |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1255 | struct cpp_pending *pend = CPP_OPTION (pfile, pending); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1256 | |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1257 | if (argv[i][0] != '-') |
| 1258 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1259 | if (CPP_OPTION (pfile, out_fname) != NULL) |
| 1260 | cpp_fatal (pfile, "Too many arguments. Type %s --help for usage info", |
| 1261 | progname); |
| 1262 | else if (CPP_OPTION (pfile, in_fname) != NULL) |
| 1263 | CPP_OPTION (pfile, out_fname) = argv[i]; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1264 | else |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1265 | CPP_OPTION (pfile, in_fname) = argv[i]; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1266 | } |
| 1267 | else |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1268 | { |
| 1269 | enum opt_code opt_code; |
| 1270 | int opt_index; |
Neil Booth | 7ceb359 | 2000-03-11 00:49:44 +0000 | [diff] [blame] | 1271 | const char *arg = 0; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1272 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1273 | /* Skip over '-' */ |
| 1274 | opt_index = parse_option (&argv[i][1]); |
| 1275 | if (opt_index < 0) |
| 1276 | return i; |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1277 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1278 | opt_code = cl_options[opt_index].opt_code; |
| 1279 | if (cl_options[opt_index].msg) |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1280 | { |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1281 | arg = &argv[i][cl_options[opt_index].opt_len + 1]; |
| 1282 | |
| 1283 | /* Yuk. Special case for -g and -W as they must not swallow |
| 1284 | up any following argument. If this becomes common, add |
| 1285 | another field to the cl_options table */ |
| 1286 | if (arg[0] == '\0' && !(opt_code == OPT_g || opt_code == OPT_W)) |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1287 | { |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1288 | arg = argv[++i]; |
| 1289 | if (!arg) |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1290 | { |
Zack Weinberg | d88b89e | 2000-04-18 21:49:16 +0000 | [diff] [blame] | 1291 | cpp_fatal (pfile, cl_options[opt_index].msg, argv[i - 1]); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1292 | return argc; |
| 1293 | } |
| 1294 | } |
| 1295 | } |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1296 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1297 | switch (opt_code) |
| 1298 | { |
| 1299 | case N_OPTS: /* shut GCC up */ |
| 1300 | break; |
| 1301 | case OPT_fleading_underscore: |
| 1302 | user_label_prefix = "_"; |
| 1303 | break; |
| 1304 | case OPT_fno_leading_underscore: |
| 1305 | user_label_prefix = ""; |
| 1306 | break; |
| 1307 | case OPT_fpreprocessed: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1308 | CPP_OPTION (pfile, preprocessed) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1309 | break; |
| 1310 | case OPT_fno_preprocessed: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1311 | CPP_OPTION (pfile, preprocessed) = 0; |
| 1312 | break; |
| 1313 | case OPT_fshow_column: |
| 1314 | CPP_OPTION (pfile, show_column) = 1; |
| 1315 | break; |
| 1316 | case OPT_fno_show_column: |
| 1317 | CPP_OPTION (pfile, show_column) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1318 | break; |
Neil Booth | 6ab3e7d | 2000-05-18 11:09:27 +0000 | [diff] [blame] | 1319 | case OPT_ftabstop: |
| 1320 | /* Silently ignore empty string, non-longs and silly values. */ |
| 1321 | if (arg[0] != '\0') |
| 1322 | { |
| 1323 | char *endptr; |
| 1324 | long tabstop = strtol (arg, &endptr, 10); |
| 1325 | if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100) |
| 1326 | CPP_OPTION (pfile, tabstop) = tabstop; |
| 1327 | } |
| 1328 | break; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1329 | case OPT_w: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1330 | CPP_OPTION (pfile, inhibit_warnings) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | case OPT_g: /* Silently ignore anything but -g3 */ |
| 1333 | if (!strcmp(&argv[i][2], "3")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1334 | CPP_OPTION (pfile, debug_output) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1335 | break; |
| 1336 | case OPT_h: |
| 1337 | case OPT__help: |
| 1338 | print_help (); |
| 1339 | exit (0); /* XXX */ |
| 1340 | break; |
| 1341 | case OPT__version: |
| 1342 | fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string); |
| 1343 | exit (0); /* XXX */ |
| 1344 | break; |
| 1345 | case OPT_C: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1346 | CPP_OPTION (pfile, discard_comments) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1347 | break; |
| 1348 | case OPT_P: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1349 | CPP_OPTION (pfile, no_line_commands) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1350 | break; |
| 1351 | case OPT_dollar: /* Don't include $ in identifiers. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1352 | CPP_OPTION (pfile, dollars_in_ident) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1353 | break; |
| 1354 | case OPT_H: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1355 | CPP_OPTION (pfile, print_include_names) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1356 | break; |
| 1357 | case OPT_D: |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1358 | new_pending_directive (pend, arg, cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1359 | break; |
| 1360 | case OPT_pedantic_errors: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1361 | CPP_OPTION (pfile, pedantic_errors) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1362 | /* fall through */ |
| 1363 | case OPT_pedantic: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1364 | CPP_OPTION (pfile, pedantic) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1365 | break; |
| 1366 | case OPT_traditional: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1367 | CPP_OPTION (pfile, traditional) = 1; |
| 1368 | CPP_OPTION (pfile, cplusplus_comments) = 0; |
| 1369 | CPP_OPTION (pfile, trigraphs) = 0; |
| 1370 | CPP_OPTION (pfile, warn_trigraphs) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1371 | break; |
| 1372 | case OPT_trigraphs: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1373 | CPP_OPTION (pfile, trigraphs) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1374 | break; |
| 1375 | case OPT_plus: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1376 | CPP_OPTION (pfile, cplusplus) = 1; |
| 1377 | CPP_OPTION (pfile, cplusplus_comments) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1378 | break; |
| 1379 | case OPT_remap: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1380 | CPP_OPTION (pfile, remap) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1381 | break; |
| 1382 | case OPT_iprefix: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1383 | CPP_OPTION (pfile, include_prefix) = arg; |
| 1384 | CPP_OPTION (pfile, include_prefix_len) = strlen (arg); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1385 | break; |
| 1386 | case OPT_lang_c: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1387 | CPP_OPTION (pfile, cplusplus) = 0; |
| 1388 | CPP_OPTION (pfile, cplusplus_comments) = 1; |
| 1389 | CPP_OPTION (pfile, c89) = 0; |
| 1390 | CPP_OPTION (pfile, c99) = 1; |
| 1391 | CPP_OPTION (pfile, objc) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1392 | break; |
| 1393 | case OPT_lang_c89: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1394 | CPP_OPTION (pfile, cplusplus) = 0; |
| 1395 | CPP_OPTION (pfile, cplusplus_comments) = 0; |
| 1396 | CPP_OPTION (pfile, c89) = 1; |
| 1397 | CPP_OPTION (pfile, c99) = 0; |
| 1398 | CPP_OPTION (pfile, objc) = 0; |
| 1399 | CPP_OPTION (pfile, trigraphs) = 1; |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1400 | new_pending_directive (pend, "__STRICT_ANSI__", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1401 | break; |
| 1402 | case OPT_lang_cplusplus: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1403 | CPP_OPTION (pfile, cplusplus) = 1; |
| 1404 | CPP_OPTION (pfile, cplusplus_comments) = 1; |
| 1405 | CPP_OPTION (pfile, c89) = 0; |
| 1406 | CPP_OPTION (pfile, c99) = 0; |
| 1407 | CPP_OPTION (pfile, objc) = 0; |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1408 | new_pending_directive (pend, "__cplusplus", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1409 | break; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1410 | case OPT_lang_objcplusplus: |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1411 | CPP_OPTION (pfile, cplusplus) = 1; |
| 1412 | new_pending_directive (pend, "__cplusplus", cpp_define); |
| 1413 | /* fall through */ |
| 1414 | case OPT_lang_objc: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1415 | CPP_OPTION (pfile, cplusplus_comments) = 1; |
| 1416 | CPP_OPTION (pfile, c89) = 0; |
| 1417 | CPP_OPTION (pfile, c99) = 0; |
| 1418 | CPP_OPTION (pfile, objc) = 1; |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1419 | new_pending_directive (pend, "__OBJC__", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1420 | break; |
| 1421 | case OPT_lang_asm: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1422 | CPP_OPTION (pfile, lang_asm) = 1; |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1423 | CPP_OPTION (pfile, dollars_in_ident) = 0; |
| 1424 | new_pending_directive (pend, "__ASSEMBLER__", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1425 | break; |
| 1426 | case OPT_lang_fortran: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1427 | CPP_OPTION (pfile, lang_fortran) = 1; |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1428 | CPP_OPTION (pfile, traditional) = 1; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1429 | CPP_OPTION (pfile, cplusplus_comments) = 0; |
Zack Weinberg | f8f769e | 2000-05-28 05:56:38 +0000 | [diff] [blame^] | 1430 | new_pending_directive (pend, "_LANGUAGE_FORTRAN", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1431 | break; |
| 1432 | case OPT_lang_chill: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1433 | CPP_OPTION (pfile, objc) = 0; |
| 1434 | CPP_OPTION (pfile, cplusplus) = 0; |
| 1435 | CPP_OPTION (pfile, chill) = 1; |
| 1436 | CPP_OPTION (pfile, traditional) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1437 | break; |
| 1438 | case OPT_nostdinc: |
| 1439 | /* -nostdinc causes no default include directories. |
| 1440 | You must specify all include-file directories with -I. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1441 | CPP_OPTION (pfile, no_standard_includes) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1442 | break; |
| 1443 | case OPT_nostdincplusplus: |
| 1444 | /* -nostdinc++ causes no default C++-specific include directories. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1445 | CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1446 | break; |
| 1447 | case OPT_std_gnu89: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1448 | CPP_OPTION (pfile, cplusplus) = 0; |
| 1449 | CPP_OPTION (pfile, cplusplus_comments) = 1; |
| 1450 | CPP_OPTION (pfile, c89) = 1; |
| 1451 | CPP_OPTION (pfile, c99) = 0; |
| 1452 | CPP_OPTION (pfile, objc) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1453 | break; |
| 1454 | case OPT_std_gnu9x: |
| 1455 | case OPT_std_gnu99: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1456 | CPP_OPTION (pfile, cplusplus) = 0; |
| 1457 | CPP_OPTION (pfile, cplusplus_comments) = 1; |
| 1458 | CPP_OPTION (pfile, c89) = 0; |
| 1459 | CPP_OPTION (pfile, c99) = 1; |
| 1460 | CPP_OPTION (pfile, objc) = 0; |
| 1461 | new_pending_directive (CPP_OPTION (pfile, pending), |
| 1462 | "__STDC_VERSION__=199901L", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1463 | break; |
| 1464 | case OPT_std_iso9899_199409: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1465 | new_pending_directive (CPP_OPTION (pfile, pending), |
| 1466 | "__STDC_VERSION__=199409L", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1467 | /* Fall through */ |
| 1468 | case OPT_std_iso9899_1990: |
| 1469 | case OPT_std_c89: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1470 | CPP_OPTION (pfile, cplusplus) = 0; |
| 1471 | CPP_OPTION (pfile, cplusplus_comments) = 0; |
| 1472 | CPP_OPTION (pfile, c89) = 1; |
| 1473 | CPP_OPTION (pfile, c99) = 0; |
| 1474 | CPP_OPTION (pfile, objc) = 0; |
| 1475 | CPP_OPTION (pfile, trigraphs) = 1; |
| 1476 | new_pending_directive (CPP_OPTION (pfile, pending), |
| 1477 | "__STRICT_ANSI__", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1478 | break; |
| 1479 | case OPT_std_iso9899_199x: |
| 1480 | case OPT_std_iso9899_1999: |
| 1481 | case OPT_std_c9x: |
| 1482 | case OPT_std_c99: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1483 | CPP_OPTION (pfile, cplusplus) = 0; |
| 1484 | CPP_OPTION (pfile, cplusplus_comments) = 1; |
| 1485 | CPP_OPTION (pfile, c89) = 0; |
| 1486 | CPP_OPTION (pfile, c99) = 1; |
| 1487 | CPP_OPTION (pfile, objc) = 0; |
| 1488 | CPP_OPTION (pfile, trigraphs) = 1; |
| 1489 | new_pending_directive (CPP_OPTION (pfile, pending), |
| 1490 | "__STRICT_ANSI__", cpp_define); |
| 1491 | new_pending_directive (CPP_OPTION (pfile, pending), |
| 1492 | "__STDC_VERSION__=199901L", cpp_define); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1493 | break; |
| 1494 | case OPT_o: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1495 | if (CPP_OPTION (pfile, out_fname) != NULL) |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1496 | { |
| 1497 | cpp_fatal (pfile, "Output filename specified twice"); |
| 1498 | return argc; |
| 1499 | } |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1500 | CPP_OPTION (pfile, out_fname) = arg; |
| 1501 | if (!strcmp (CPP_OPTION (pfile, out_fname), "-")) |
| 1502 | CPP_OPTION (pfile, out_fname) = ""; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1503 | break; |
| 1504 | case OPT_v: |
| 1505 | fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string); |
| 1506 | #ifdef TARGET_VERSION |
| 1507 | TARGET_VERSION; |
| 1508 | #endif |
| 1509 | fputc ('\n', stderr); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1510 | CPP_OPTION (pfile, verbose) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1511 | break; |
| 1512 | case OPT_stdin_stdout: |
| 1513 | /* JF handle '-' as file name meaning stdin or stdout */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1514 | if (CPP_OPTION (pfile, in_fname) == NULL) |
| 1515 | CPP_OPTION (pfile, in_fname) = ""; |
| 1516 | else if (CPP_OPTION (pfile, out_fname) == NULL) |
| 1517 | CPP_OPTION (pfile, out_fname) = ""; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1518 | break; |
| 1519 | case OPT_d: |
| 1520 | /* Args to -d specify what parts of macros to dump. |
| 1521 | Silently ignore unrecognised options; they may |
| 1522 | be aimed at the compiler proper. */ |
| 1523 | { |
| 1524 | char c; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1525 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1526 | while ((c = *arg++) != '\0') |
| 1527 | switch (c) |
| 1528 | { |
| 1529 | case 'M': |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1530 | CPP_OPTION (pfile, dump_macros) = dump_only; |
| 1531 | CPP_OPTION (pfile, no_output) = 1; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1532 | break; |
| 1533 | case 'N': |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1534 | CPP_OPTION (pfile, dump_macros) = dump_names; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1535 | break; |
| 1536 | case 'D': |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1537 | CPP_OPTION (pfile, dump_macros) = dump_definitions; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1538 | break; |
| 1539 | case 'I': |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1540 | CPP_OPTION (pfile, dump_includes) = 1; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1541 | break; |
| 1542 | } |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1543 | } |
| 1544 | break; |
| 1545 | /* The style of the choices here is a bit mixed. |
| 1546 | The chosen scheme is a hybrid of keeping all options in one string |
| 1547 | and specifying each option in a separate argument: |
| 1548 | -M|-MM|-MD file|-MMD file [-MG]. An alternative is: |
| 1549 | -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely: |
| 1550 | -M[M][G][D file]. This is awkward to handle in specs, and is not |
| 1551 | as extensible. */ |
| 1552 | /* ??? -MG must be specified in addition to one of -M or -MM. |
| 1553 | This can be relaxed in the future without breaking anything. |
| 1554 | The converse isn't true. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1555 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1556 | /* -MG isn't valid with -MD or -MMD. This is checked for later. */ |
| 1557 | case OPT_MG: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1558 | CPP_OPTION (pfile, print_deps_missing_files) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1559 | break; |
| 1560 | case OPT_M: |
| 1561 | case OPT_MD: |
| 1562 | case OPT_MM: |
| 1563 | case OPT_MMD: |
| 1564 | if (opt_code == OPT_M || opt_code == OPT_MD) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1565 | CPP_OPTION (pfile, print_deps) = 2; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1566 | else |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1567 | CPP_OPTION (pfile, print_deps) = 1; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1568 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1569 | /* For -MD and -MMD options, write deps on file named by next arg */ |
| 1570 | /* For -M and -MM, write deps on standard output |
| 1571 | and suppress the usual output. */ |
| 1572 | if (opt_code == OPT_MD || opt_code == OPT_MMD) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1573 | CPP_OPTION (pfile, deps_file) = arg; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1574 | else |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1575 | CPP_OPTION (pfile, no_output) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1576 | break; |
| 1577 | case OPT_A: |
Neil Booth | e1e97c4 | 2000-03-16 14:15:17 +0000 | [diff] [blame] | 1578 | if (arg[0] == '-') |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1579 | { |
Neil Booth | e1e97c4 | 2000-03-16 14:15:17 +0000 | [diff] [blame] | 1580 | /* -A with an argument beginning with '-' acts as |
| 1581 | #unassert on whatever immediately follows the '-'. |
| 1582 | If "-" is the whole argument, we eliminate all |
| 1583 | predefined macros and assertions, including those |
| 1584 | that were specified earlier on the command line. |
| 1585 | That way we can get rid of any that were passed |
| 1586 | automatically in from GCC. */ |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1587 | |
Neil Booth | e1e97c4 | 2000-03-16 14:15:17 +0000 | [diff] [blame] | 1588 | if (arg[1] == '\0') |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1589 | { |
Neil Booth | e1e97c4 | 2000-03-16 14:15:17 +0000 | [diff] [blame] | 1590 | struct pending_option *o1, *o2; |
| 1591 | |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1592 | o1 = CPP_OPTION (pfile, pending)->directive_head; |
Neil Booth | e1e97c4 | 2000-03-16 14:15:17 +0000 | [diff] [blame] | 1593 | while (o1) |
| 1594 | { |
| 1595 | o2 = o1->next; |
| 1596 | free (o1); |
| 1597 | o1 = o2; |
| 1598 | } |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1599 | CPP_OPTION (pfile, pending)->directive_head = NULL; |
| 1600 | CPP_OPTION (pfile, pending)->directive_tail = NULL; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1601 | } |
Neil Booth | e1e97c4 | 2000-03-16 14:15:17 +0000 | [diff] [blame] | 1602 | else |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1603 | new_pending_directive (CPP_OPTION (pfile, pending), |
| 1604 | arg + 1, cpp_unassert); |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1605 | } |
Neil Booth | e1e97c4 | 2000-03-16 14:15:17 +0000 | [diff] [blame] | 1606 | else |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1607 | new_pending_directive (CPP_OPTION (pfile, pending), |
| 1608 | arg, cpp_assert); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1609 | break; |
| 1610 | case OPT_U: |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1611 | new_pending_directive (CPP_OPTION (pfile, pending), arg, cpp_undef); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | case OPT_I: /* Add directory to path for includes. */ |
| 1614 | if (!strcmp (arg, "-")) |
| 1615 | { |
| 1616 | /* -I- means: |
| 1617 | Use the preceding -I directories for #include "..." |
| 1618 | but not #include <...>. |
| 1619 | Don't search the directory of the present file |
| 1620 | for #include "...". (Note that -I. -I- is not the same as |
| 1621 | the default setup; -I. uses the compiler's working dir.) */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1622 | if (! CPP_OPTION (pfile, ignore_srcdir)) |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1623 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1624 | struct cpp_pending *pend = CPP_OPTION (pfile, pending); |
| 1625 | pend->quote_head = pend->brack_head; |
| 1626 | pend->quote_tail = pend->brack_tail; |
| 1627 | pend->brack_head = 0; |
| 1628 | pend->brack_tail = 0; |
| 1629 | CPP_OPTION (pfile, ignore_srcdir) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1630 | } |
| 1631 | else |
| 1632 | { |
| 1633 | cpp_fatal (pfile, "-I- specified twice"); |
| 1634 | return argc; |
| 1635 | } |
| 1636 | } |
| 1637 | else |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1638 | append_include_chain (pfile, CPP_OPTION (pfile, pending), |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1639 | xstrdup (arg), BRACKET, 0); |
| 1640 | break; |
| 1641 | case OPT_isystem: |
| 1642 | /* Add directory to beginning of system include path, as a system |
| 1643 | include directory. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1644 | append_include_chain (pfile, CPP_OPTION (pfile, pending), |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1645 | xstrdup (arg), SYSTEM, 0); |
| 1646 | break; |
| 1647 | case OPT_include: |
| 1648 | { |
| 1649 | struct pending_option *o = (struct pending_option *) |
| 1650 | xmalloc (sizeof (struct pending_option)); |
| 1651 | o->arg = arg; |
| 1652 | |
| 1653 | /* This list has to be built in reverse order so that |
| 1654 | when cpp_start_read pushes all the -include files onto |
| 1655 | the buffer stack, they will be scanned in forward order. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1656 | o->next = CPP_OPTION (pfile, pending)->include_head; |
| 1657 | CPP_OPTION (pfile, pending)->include_head = o; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1658 | } |
| 1659 | break; |
| 1660 | case OPT_imacros: |
| 1661 | { |
| 1662 | struct pending_option *o = (struct pending_option *) |
| 1663 | xmalloc (sizeof (struct pending_option)); |
| 1664 | o->arg = arg; |
| 1665 | o->next = NULL; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1666 | |
| 1667 | APPEND (CPP_OPTION (pfile, pending), imacros, o); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1668 | } |
| 1669 | break; |
| 1670 | case OPT_iwithprefix: |
| 1671 | /* Add directory to end of path for includes, |
| 1672 | with the default prefix at the front of its name. */ |
| 1673 | /* fall through */ |
| 1674 | case OPT_iwithprefixbefore: |
| 1675 | /* Add directory to main path for includes, |
| 1676 | with the default prefix at the front of its name. */ |
| 1677 | { |
| 1678 | char *fname; |
| 1679 | int len; |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1680 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1681 | len = strlen (arg); |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1682 | |
| 1683 | if (CPP_OPTION (pfile, include_prefix) != 0) |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1684 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1685 | size_t ipl = CPP_OPTION (pfile, include_prefix_len); |
| 1686 | fname = xmalloc (ipl + len + 1); |
| 1687 | memcpy (fname, CPP_OPTION (pfile, include_prefix), ipl); |
| 1688 | memcpy (fname + ipl, arg, len + 1); |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1689 | } |
| 1690 | else |
| 1691 | { |
| 1692 | fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len); |
| 1693 | memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9); |
| 1694 | memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, arg, len + 1); |
| 1695 | } |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1696 | |
| 1697 | append_include_chain (pfile, CPP_OPTION (pfile, pending), fname, |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1698 | opt_code == OPT_iwithprefix ? SYSTEM: BRACKET, 0); |
| 1699 | } |
| 1700 | break; |
| 1701 | case OPT_idirafter: |
| 1702 | /* Add directory to end of path for includes. */ |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1703 | append_include_chain (pfile, CPP_OPTION (pfile, pending), |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1704 | xstrdup (arg), AFTER, 0); |
| 1705 | break; |
| 1706 | case OPT_W: |
| 1707 | /* Silently ignore unrecognised options */ |
| 1708 | if (!strcmp (argv[i], "-Wall")) |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1709 | { |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1710 | CPP_OPTION (pfile, warn_trigraphs) = 1; |
| 1711 | CPP_OPTION (pfile, warn_comments) = 1; |
Zack Weinberg | 0b22d65 | 1999-03-15 18:42:46 +0000 | [diff] [blame] | 1712 | } |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1713 | else if (!strcmp (argv[i], "-Wtraditional")) |
Zack Weinberg | 07aa0b0 | 2000-04-01 22:55:25 +0000 | [diff] [blame] | 1714 | CPP_OPTION (pfile, warn_traditional) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1715 | else if (!strcmp (argv[i], "-Wtrigraphs")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1716 | CPP_OPTION (pfile, warn_trigraphs) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1717 | else if (!strcmp (argv[i], "-Wcomment")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1718 | CPP_OPTION (pfile, warn_comments) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1719 | else if (!strcmp (argv[i], "-Wcomments")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1720 | CPP_OPTION (pfile, warn_comments) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1721 | else if (!strcmp (argv[i], "-Wundef")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1722 | CPP_OPTION (pfile, warn_undef) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1723 | else if (!strcmp (argv[i], "-Wimport")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1724 | CPP_OPTION (pfile, warn_import) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1725 | else if (!strcmp (argv[i], "-Werror")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1726 | CPP_OPTION (pfile, warnings_are_errors) = 1; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1727 | else if (!strcmp (argv[i], "-Wno-traditional")) |
Zack Weinberg | 07aa0b0 | 2000-04-01 22:55:25 +0000 | [diff] [blame] | 1728 | CPP_OPTION (pfile, warn_traditional) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1729 | else if (!strcmp (argv[i], "-Wno-trigraphs")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1730 | CPP_OPTION (pfile, warn_trigraphs) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1731 | else if (!strcmp (argv[i], "-Wno-comment")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1732 | CPP_OPTION (pfile, warn_comments) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1733 | else if (!strcmp (argv[i], "-Wno-comments")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1734 | CPP_OPTION (pfile, warn_comments) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1735 | else if (!strcmp (argv[i], "-Wno-undef")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1736 | CPP_OPTION (pfile, warn_undef) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1737 | else if (!strcmp (argv[i], "-Wno-import")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1738 | CPP_OPTION (pfile, warn_import) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1739 | else if (!strcmp (argv[i], "-Wno-error")) |
Zack Weinberg | ae79697 | 2000-03-31 23:16:11 +0000 | [diff] [blame] | 1740 | CPP_OPTION (pfile, warnings_are_errors) = 0; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1741 | break; |
| 1742 | } |
| 1743 | } |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1744 | return i + 1; |
| 1745 | } |
| 1746 | |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1747 | #ifdef HOST_EBCDIC |
| 1748 | static int |
| 1749 | opt_comp (const void *p1, const void *p2) |
| 1750 | { |
| 1751 | return strcmp (((struct cl_option *)p1)->opt_text, |
| 1752 | ((struct cl_option *)p2)->opt_text); |
| 1753 | } |
| 1754 | #endif |
| 1755 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1756 | /* Handle command-line options in (argc, argv). |
| 1757 | Can be called multiple times, to handle multiple sets of options. |
| 1758 | Returns if an unrecognized option is seen. |
| 1759 | Returns number of strings consumed. */ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1760 | int |
| 1761 | cpp_handle_options (pfile, argc, argv) |
| 1762 | cpp_reader *pfile; |
| 1763 | int argc; |
| 1764 | char **argv; |
| 1765 | { |
| 1766 | int i; |
| 1767 | int strings_processed; |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1768 | |
| 1769 | #ifdef HOST_EBCDIC |
| 1770 | static int opts_sorted = 0; |
| 1771 | |
| 1772 | if (!opts_sorted) |
| 1773 | { |
| 1774 | opts_sorted = 1; |
| 1775 | /* For non-ASCII hosts, the array needs to be sorted at runtime */ |
| 1776 | qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp); |
| 1777 | } |
| 1778 | #endif |
| 1779 | |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1780 | for (i = 0; i < argc; i += strings_processed) |
| 1781 | { |
Zack Weinberg | b0699da | 2000-03-07 20:58:47 +0000 | [diff] [blame] | 1782 | strings_processed = handle_option (pfile, argc - i, argv + i); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1783 | if (strings_processed == 0) |
| 1784 | break; |
| 1785 | } |
| 1786 | return i; |
| 1787 | } |
| 1788 | |
| 1789 | static void |
| 1790 | print_help () |
| 1791 | { |
Zack Weinberg | c1212d2 | 2000-02-06 23:46:18 +0000 | [diff] [blame] | 1792 | fprintf (stderr, _("Usage: %s [switches] input output\n"), progname); |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1793 | fputs (_("\ |
| 1794 | Switches:\n\ |
| 1795 | -include <file> Include the contents of <file> before other files\n\ |
| 1796 | -imacros <file> Accept definition of macros in <file>\n\ |
| 1797 | -iprefix <path> Specify <path> as a prefix for next two options\n\ |
| 1798 | -iwithprefix <dir> Add <dir> to the end of the system include path\n\ |
| 1799 | -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\ |
| 1800 | -isystem <dir> Add <dir> to the start of the system include path\n\ |
| 1801 | -idirafter <dir> Add <dir> to the end of the system include path\n\ |
| 1802 | -I <dir> Add <dir> to the end of the main include path\n\ |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1803 | -I- Fine-grained include path control; see info docs\n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1804 | -nostdinc Do not search system include directories\n\ |
| 1805 | (dirs specified with -isystem will still be used)\n\ |
| 1806 | -nostdinc++ Do not search system include directories for C++\n\ |
| 1807 | -o <file> Put output into <file>\n\ |
| 1808 | -pedantic Issue all warnings demanded by strict ANSI C\n\ |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1809 | -pedantic-errors Issue -pedantic warnings as errors instead\n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1810 | -traditional Follow K&R pre-processor behaviour\n\ |
| 1811 | -trigraphs Support ANSI C trigraphs\n\ |
| 1812 | -lang-c Assume that the input sources are in C\n\ |
| 1813 | -lang-c89 Assume that the input sources are in C89\n\ |
| 1814 | -lang-c++ Assume that the input sources are in C++\n\ |
| 1815 | -lang-objc Assume that the input sources are in ObjectiveC\n\ |
| 1816 | -lang-objc++ Assume that the input sources are in ObjectiveC++\n\ |
| 1817 | -lang-asm Assume that the input sources are in assembler\n\ |
Zack Weinberg | 40c79d5 | 2000-01-12 00:35:36 +0000 | [diff] [blame] | 1818 | -lang-fortran Assume that the input sources are in Fortran\n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1819 | -lang-chill Assume that the input sources are in Chill\n\ |
| 1820 | -std=<std name> Specify the conformance standard; one of:\n\ |
Ulrich Drepper | 916269a | 2000-01-29 19:00:43 +0000 | [diff] [blame] | 1821 | gnu89, gnu99, c89, c99, iso9899:1990,\n\ |
| 1822 | iso9899:199409, iso9899:1999\n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1823 | -+ Allow parsing of C++ style features\n\ |
| 1824 | -w Inhibit warning messages\n\ |
| 1825 | -Wtrigraphs Warn if trigraphs are encountered\n\ |
| 1826 | -Wno-trigraphs Do not warn about trigraphs\n\ |
| 1827 | -Wcomment{s} Warn if one comment starts inside another\n\ |
| 1828 | -Wno-comment{s} Do not warn about comments\n\ |
| 1829 | -Wtraditional Warn if a macro argument is/would be turned into\n\ |
| 1830 | a string if -traditional is specified\n\ |
| 1831 | -Wno-traditional Do not warn about stringification\n\ |
| 1832 | -Wundef Warn if an undefined macro is used by #if\n\ |
| 1833 | -Wno-undef Do not warn about testing undefined macros\n\ |
| 1834 | -Wimport Warn about the use of the #import directive\n\ |
| 1835 | -Wno-import Do not warn about the use of #import\n\ |
| 1836 | -Werror Treat all warnings as errors\n\ |
| 1837 | -Wno-error Do not treat warnings as errors\n\ |
| 1838 | -Wall Enable all preprocessor warnings\n\ |
| 1839 | -M Generate make dependencies\n\ |
| 1840 | -MM As -M, but ignore system header files\n\ |
| 1841 | -MD As -M, but put output in a .d file\n\ |
| 1842 | -MMD As -MD, but ignore system header files\n\ |
| 1843 | -MG Treat missing header file as generated files\n\ |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1844 | -g3 Include #define and #undef directives in the output\n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1845 | -D<macro> Define a <macro> with string '1' as its value\n\ |
| 1846 | -D<macro>=<val> Define a <macro> with <val> as its value\n\ |
| 1847 | -A<question> (<answer>) Assert the <answer> to <question>\n\ |
Neil Booth | e1e97c4 | 2000-03-16 14:15:17 +0000 | [diff] [blame] | 1848 | -A-<question> (<answer>) Disable the <answer> to <question>\n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1849 | -U<macro> Undefine <macro> \n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1850 | -v Display the version number\n\ |
| 1851 | -H Print the name of header files as they are used\n\ |
| 1852 | -C Do not discard comments\n\ |
| 1853 | -dM Display a list of macro definitions active at end\n\ |
| 1854 | -dD Preserve macro definitions in output\n\ |
| 1855 | -dN As -dD except that only the names are preserved\n\ |
| 1856 | -dI Include #include directives in the output\n\ |
Neil Booth | 6ab3e7d | 2000-05-18 11:09:27 +0000 | [diff] [blame] | 1857 | -ftabstop=<number> Distance between tab stops for column reporting\n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1858 | -P Do not generate #line directives\n\ |
| 1859 | -$ Do not allow '$' in identifiers\n\ |
| 1860 | -remap Remap file names when including files.\n\ |
Zack Weinberg | e23c0ba | 2000-03-07 23:11:06 +0000 | [diff] [blame] | 1861 | --version Display version information\n\ |
Zack Weinberg | 6de1e2a | 1999-02-18 15:35:49 +0000 | [diff] [blame] | 1862 | -h or --help Display this information\n\ |
| 1863 | "), stdout); |
| 1864 | } |