-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.c
4913 lines (4555 loc) · 167 KB
/
system.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-
* Copyright (c) 1998, 2002-2008 Kiyoshi Matsui <[email protected]>
* All rights reserved.
*
* Some parts of this code are derived from the public domain software
* DECUS cpp (1984,1985) written by Martin Minow.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* S Y S T E M . C
* S y s t e m D e p e n d e n t R o u t i n e s
*
* Routines dependent on O.S., compiler or compiler-driver.
* To port MCPP for the systems not yet ported, you must
* 1. specify the constants in "configed.H" or "noconfig.H",
* 2. append the system-dependent routines in this file.
*/
#if PREPROCESSED
#include "mcpp.H"
#else
#include "system.H"
#include "internal.H"
#endif
#if HOST_SYS_FAMILY == SYS_UNIX
#include "unistd.h" /* For getcwd(), readlink() */
#elif HOST_COMPILER == MSC || HOST_COMPILER == LCC
#include "direct.h"
#define getcwd( buf, size) _getcwd( buf, size)
#elif HOST_COMPILER == BORLANDC
#include "dir.h"
#endif
#include "sys/types.h"
#include "sys/stat.h" /* For stat() */
#if ! defined( S_ISREG)
#define S_ISREG( mode) (mode & S_IFREG)
#define S_ISDIR( mode) (mode & S_IFDIR)
#endif
#if HOST_COMPILER == MSC
#define S_IFREG _S_IFREG
#define S_IFDIR _S_IFDIR
#define stat( path, stbuf) _stat( path, stbuf)
#endif
/* Function to compare path-list */
#if FNAME_FOLD
#if HOST_COMPILER == GNUC /* CYGWIN, MINGW, MAC */
#include <strings.h> /* POSIX 1, 2001 */
#define str_case_eq( str1, str2) (strcasecmp( str1, str2) == 0)
#else /* MSC, BORLANDC, LCC */
#if HOST_COMPILER == MSC
#define stricmp( str1, str2) _stricmp( str1, str2)
#endif
#define str_case_eq( str1, str2) (stricmp( str1, str2) == 0)
#endif
#else /* ! FNAME_FOLD */
#define str_case_eq( str1, str2) (strcmp( str1, str2) == 0)
#endif
/*
* PATH_DELIM is defined for the O.S. which has single byte path-delimiter.
* Note: '\\' or any other character identical to second byte of MBCHAR should
* not be used for PATH_DELIM for convenience of path-list parsing.
*/
#if SYS_FAMILY == SYS_UNIX || SYS_FAMILY == SYS_WIN || SYSTEM == SYS_UNKNOWN
#define PATH_DELIM '/'
#define SPECIAL_PATH_DELIM FALSE
#else /* Any other path-delimiter, define PATH_DELIM by yourself */
#define SPECIAL_PATH_DELIM TRUE /* Any path-delimiter other than '/' */
#endif
/*
* OBJEXT is the suffix to denote "object" file.
*/
#ifndef OBJEXT
#if SYS_FAMILY == SYS_UNIX || HOST_COMPILER == GNUC
#define OBJEXT "o"
#elif SYS_FAMILY == SYS_WIN
#define OBJEXT "obj"
#elif 1
/* Add here appropriate definitions for other systems. */
#endif
#endif
static void version( void);
/* Print version message */
static void usage( int opt);
/* Putout usage of MCPP */
static void set_opt_list( char * optlist);
/* Set list of legal option chars */
static int parse_warn_level( const char * mcpp_optarg, int opt);
/* Parse warning level option */
static void def_a_macro( int opt, char * def);
/* Do a -D option */
static void chk_opts( int sflag, int trad);
/* Check consistency of options */
#if COMPILER != GNUC
static void init_cpu_macro( int gval, int sse);
/* Predefine CPU-dependent macros */
#endif
static void init_predefines( void);
/* Set and unset predefined macros */
static void init_std_defines( void);
/* Predefine Standard macros */
static void set_limit( void);
/* Set minimum translation limits */
static void set_pragma_op( void);
/* Set the _Pragma() operator */
static void put_info( FILEINFO * sharp_file);
/* Print compiler-specific-inf */
static char * set_files( int argc, char ** argv, char ** in_pp
, char ** out_pp);
/* Set input, output, diagnostic */
static void set_sys_dirs( int set_cplus_dir);
/* Set system-specific include dirs */
static void set_env_dirs( void);
/* Set user-defined include dirs */
static void parse_env( const char * env);
/* Parse environment variables */
static void set_a_dir( const char * dirname);
/* Append an include directory */
static char * norm_dir( const char * dirname, int framework);
/* Normalize include directory path */
static char * norm_path( const char * dir, const char * fname, int inf
, int hmap); /* Normalize pathname to compare */
#if SYS_FAMILY == SYS_UNIX
static void deref_syml( char * slbuf1, char * slbuf2, char * chk_start);
/* Dereference symbolic linked directory and file */
#endif
#if COMPILER == GNUC
static void init_gcc_macro( void);
/* Predefine GCC-specific macros */
static void chk_env( void);
/* Check the environment variables */
#elif COMPILER == MSC
static void init_msc_macro( void);
/* Predefine Visual C-specific macros */
#endif
static void def_macros( void);
/* Define macros specified by -D */
static void undef_macros( void);
/* Undefine macros specified by -U */
static char * md_init( const char * filename, char * output);
/* Initialize makefile dependency */
static char * md_quote( char * output);
/* 'Quote' special characters */
static int open_include( char * filename, int searchlocal, int next);
/* Open the file to include */
static int has_directory( const char * source, char * directory);
/* Get directory part of fname */
static int is_full_path( const char * path);
/* The path is absolute path list ? */
static int search_dir( char * filename, int searchlocal, int next);
/* Search the include directories */
static int open_file( const char ** dirp, const char * src_dir
, const char * filename, int local, int include_opt, int sys_frame);
/* Open a source file */
static const char * set_fname( const char * filename);
/* Remember the source filename */
#if SYSTEM == SYS_MAC
#if COMPILER == GNUC
static char * search_header_map( const char * hmap_file
, const char * filename, char * pathlist);
/* Search header map file for a header */
static unsigned hmap_hash( const char * fname);
/* Get hash value for the fname */
#endif
static void init_framework( void);
/* Initialize framework[] */
static int search_framework( char * filename);
/* Search "Framework" directories */
static int search_subdir( char * fullname, char * cp, char * frame
, char * fname, int sys_frame);
/* Search "Headers" and other dirs */
#endif /* SYSTEM == SYS_MAC */
#if 0 /* This function is only for debugging use */
static int chk_dirp( const char ** dirp);
/* Check validity of dirp arg for open_file() */
#endif
static void cur_file( FILEINFO * file, FILEINFO * sharp_file, int marker);
/* Output current source file name */
#if SYS_FAMILY == SYS_WIN
static char * bsl2sl( char * filename);
/* Convert \ to / in path-list */
#endif
static int is_junk( void);
/* The directive has trailing junk? */
static void do_once( const char * fullname);
/* Process #pragma once */
static int included( const char * fullname);
/* The file has been once included? */
static void push_or_pop( int direction);
/* Push or pop a macro definition */
static int do_prestd_directive( void);
/* Process pre-Standard directives */
static void do_preprocessed( void);
/* Process preprocessed file */
static int do_debug( int set);
/* #pragma MCPP debug, #debug */
static void dump_path( void);
/* Print include search path */
static void do_asm( int asm_start);
/* Process #asm, #endasm */
static int mcpp_getopt( int argc, char * const * argv, const char * opts);
/* getopt() to prevent linking of glibc getopt */
/* for mcpp_getopt() */
static int mcpp_optind = 1;
static int mcpp_opterr = 1;
static int mcpp_optopt;
static char * mcpp_optarg;
static int mb_changed = FALSE; /* Flag of -e option */
static char cur_work_dir[ PATHMAX + 1]; /* Current working directory*/
/*
* incdir[] stores the -I directories (and the system-specific #include <...>
* directories). This is set by set_a_dir(). A trailing PATH_DELIM is
* appended if absent.
*/
static const char ** incdir; /* Include directories */
static const char ** incend; /* -> active end of incdir */
static int max_inc; /* Number of incdir[] */
typedef struct inc_list { /* List of directories or files */
char * name; /* Filename or directory-name */
size_t len; /* Length of 'name' */
} INC_LIST;
/*
* fnamelist[] stores the souce file names opened by #include directive for
* debugging information.
*/
static INC_LIST * fnamelist; /* Source file names */
static INC_LIST * fname_end; /* -> active end of fnamelist */
static int max_fnamelist; /* Number of fnamelist[] */
/* once_list[] stores the #pragma once file names. */
static INC_LIST * once_list; /* Once opened file */
static INC_LIST * once_end; /* -> active end of once_list */
static int max_once; /* Number of once_list[] */
#define INIT_NUM_INCLUDE 32 /* Initial number of incdir[] */
#define INIT_NUM_FNAMELIST 256 /* Initial number of fnamelist[] */
#define INIT_NUM_ONCE 64 /* Initial number of once_list[] */
/*
* 'search_rule' holds searching rule of #include "header.h" to search first
* before searching user specified or system-specific include directories.
* 'search_rule' is initialized to SEARCH_INIT. It can be changed by -I1, -I2
* or -I3 option. -I1 specifies CURRENT, -I2 SOURCE and -I3 both.
*/
static int search_rule = SEARCH_INIT; /* Rule to search include file */
static int nflag = FALSE; /* Flag of -N (-undef) option */
static long std_val = -1L; /* Value of __STDC_VERSION__ or __cplusplus */
#define MAX_DEF 256
#define MAX_UNDEF (MAX_DEF/4)
static char * def_list[ MAX_DEF]; /* Macros to be defined */
static char * undef_list[ MAX_UNDEF]; /* Macros to be undefined */
static int def_cnt; /* Count of def_list */
static int undef_cnt; /* Count of undef_list */
/* Values of mkdep. */
#define MD_MKDEP 1 /* Output source file dependency line */
#define MD_SYSHEADER 2 /* Print also system-header names */
#define MD_FILE 4 /* Output to the file named *.d */
#define MD_PHONY 8 /* Print also phony targets for each header */
#define MD_QUOTE 16 /* 'Quote' $ and space in target name */
static FILE * mkdep_fp; /* For -Mx option */
static char * mkdep_target;
/* For -MT TARGET option and for GCC's queer environment variables. */
static char * mkdep_mf; /* Argument of -MF option */
static char * mkdep_md; /* Argument of -MD option */
static char * mkdep_mq; /* Argument of -MQ option */
static char * mkdep_mt; /* Argument of -MT option */
/* sharp_filename is filename for #line line, used only in cur_file() */
static char * sharp_filename = NULL;
static char * argv0; /* argv[ 0] for usage() and version() */
static int ansi; /* __STRICT_ANSI__ flag for GNUC */
static int compat_mode;
/* "Compatible" mode of recursive macro expansion */
#define MAX_ARCH_LEN 16
static char arch[ MAX_ARCH_LEN]; /* -arch or -m64, -m32 options */
#if COMPILER == GNUC
#define N_QUOTE_DIR 8
/* quote_dir[]: Include directories for "header" specified by -iquote */
/* quote_dir_end: Active end of quote_dir */
static const char * quote_dir[ N_QUOTE_DIR];
static const char ** quote_dir_end = quote_dir;
/* sys_dirp indicates the first directory to search for system headers. */
static const char ** sys_dirp = NULL; /* System header directory */
static const char * sysroot = NULL; /* Logical root directory of header */
static int i_split = FALSE; /* For -I- option */
static int gcc_work_dir = FALSE; /* For -fworking-directory */
static int gcc_maj_ver; /* __GNUC__ */
static int gcc_min_ver; /* __GNUC_MINOR__ */
static int dDflag = FALSE; /* Flag of -dD option */
static int dMflag = FALSE; /* Flag of -dM option */
#endif
#if COMPILER == GNUC || COMPILER == MSC
/*
* preinclude points to the file specified by -include (-Fl for MSC) option,
* which is included prior to the main input file.
*/
#define NPREINCLUDE 8
static char * preinclude[ NPREINCLUDE]; /* File to pre-include */
static char ** preinc_end = preinclude; /* -> active end of preinclude */
#endif
#if COMPILER == MSC
static int wchar_t_modified = FALSE; /* -Zc:wchar_t flag */
#endif
#if COMPILER == LCC
static const char * optim_name = "__LCCOPTIMLEVEL";
#endif
#if SYSTEM == SYS_CYGWIN
static int no_cygwin = FALSE; /* -mno-cygwin */
#elif SYSTEM == SYS_MAC
#define MAX_FRAMEWORK 8
static char * framework[ MAX_FRAMEWORK]; /* Framework directories*/
static int num_framework; /* Current number of framework[] */
static int sys_framework; /* System framework dir */
static const char ** to_search_framework;
/* Search framework[] next to the directory */
static int in_import; /* #import rather than #include */
#endif
#define NO_DIR FALSE
#if NO_DIR
/* Unofficial feature to strip directory part of include file */
static int no_dir;
#endif
#if MCPP_LIB
void init_system( void)
/* Initialize static variables */
{
if (sharp_filename)
free( sharp_filename);
sharp_filename = NULL;
incend = incdir = NULL;
fnamelist = once_list = NULL;
search_rule = SEARCH_INIT;
mb_changed = nflag = ansi = compat_mode = FALSE;
mkdep_fp = NULL;
mkdep_target = mkdep_mf = mkdep_md = mkdep_mq = mkdep_mt = NULL;
std_val = -1L;
def_cnt = undef_cnt = 0;
mcpp_optind = mcpp_opterr = 1;
#if COMPILER == GNUC
sys_dirp = NULL;
sysroot = NULL;
gcc_work_dir = i_split = FALSE;
quote_dir_end = quote_dir;
dDflag = dMflag = FALSE;
#endif
#if COMPILER == MSC
wchar_t_modified = FALSE;
#endif
#if COMPILER == GNUC || COMPILER == MSC
preinc_end = preinclude;
#endif
#if SYSTEM == SYS_CYGWIN
no_cygwin = FALSE;
#elif SYSTEM == SYS_MAC
num_framework = sys_framework = 0;
to_search_framework = NULL;
#endif
#if NO_DIR
no_dir = FALSE;
#endif
}
#endif
#define OPTLISTLEN 80
void do_options(
int argc,
char ** argv,
char ** in_pp, /* Input file name */
char ** out_pp /* Output file name */
)
/*
* Process command line arguments, called only at MCPP startup.
*/
{
char optlist[ OPTLISTLEN]; /* List of option letter*/
const char * warning = "warning: -%c%s option is ignored\n";
int opt;
int unset_sys_dirs;
/* Unset system-specific and site-specific include directories ? */
int set_cplus_dir; /* Set C++ include directory ? (for GCC)*/
int show_path; /* Show include directory list */
DEFBUF * defp;
VAL_SIGN * valp;
int sflag; /* -S option or similar */
int trad; /* -traditional */
int old_mode; /* backup of 'mcpp_mode'*/
int gval, sse;
char * cp;
int i;
#if COMPILER == GNUC
#define NSYSDIR 8
/* System include directory specified by -isystem */
char * sysdir[ NSYSDIR] = { NULL, };
char ** sysdir_end = sysdir;
int integrated_cpp; /* Flag of cc1 which integrates cpp in it */
#elif COMPILER == LCC
const char * debug_name = "__LCCDEBUGLEVEL";
#endif
argv0 = argv[ 0];
nflag = unset_sys_dirs = show_path = sflag = trad = FALSE;
arch[ 0] = 0;
gval = sse = 0;
set_cplus_dir = TRUE;
/* Get current directory for -I option and #pragma once */
getcwd( cur_work_dir, PATHMAX);
#if SYS_FAMILY == SYS_WIN
bsl2sl( cur_work_dir);
#endif
sprintf( cur_work_dir + strlen( cur_work_dir), "%c%c", PATH_DELIM, EOS);
/* Append trailing path-delimiter */
#if COMPILER == GNUC
defp = look_id( "__GNUC__"); /* Already defined by init_defines() */
gcc_maj_ver = atoi( defp->repl);
defp = look_id( "__GNUC_MINOR__");
gcc_min_ver = atoi( defp->repl);
integrated_cpp = ((gcc_maj_ver == 3 && gcc_min_ver >= 3)
|| gcc_maj_ver == 4);
#endif
#if COMPILER == GNUC || COMPILER == MSC
option_flags.dollar_in_name = TRUE;
/* GCC and Visual C allows '$' in name by default */
#endif
set_opt_list( optlist);
opt_search: ;
while (mcpp_optind < argc
&& (opt = mcpp_getopt( argc, argv, optlist)) != EOF) {
switch (opt) { /* Command line option character */
#if COMPILER == GNUC
case '$': /* Forbid '$' in identifier */
option_flags.dollar_in_name = FALSE;
break;
#endif
case '+':
#if COMPILER == GNUC
plus:
#endif
if (cplus_val || sflag) {
mcpp_fputs( "warning: -+ option is ignored\n", ERR);
break;
}
cplus_val = CPLUS;
break;
#if COMPILER == GNUC
case '-':
if (memcmp( mcpp_optarg, "sysroot", 7) == 0) {
if (mcpp_optarg[ 7] == '=') /* --sysroot=DIR */
sysroot = mcpp_optarg + 8;
else if (mcpp_optarg[ 7] == EOS) /* --sysroot DIR */
sysroot = argv[ mcpp_optind++];
else
usage( opt);
break;
} else {
usage( opt);
}
#endif
case '2': /* Reverse digraphs recognition */
option_flags.dig = ! option_flags.dig;
break;
case '3': /* Reverse trigraph recogniion */
option_flags.trig = ! option_flags.trig;
break;
case '@': /* Special preprocessing mode */
old_mode = mcpp_mode;
if (str_eq( mcpp_optarg, "post")
|| str_eq( mcpp_optarg, "poststd"))
mcpp_mode = POST_STD; /* 'post-Standard' mode */
else if (str_eq( mcpp_optarg, "old")
|| str_eq( mcpp_optarg, "oldprep"))
mcpp_mode = OLD_PREP; /* 'old-Preprocessor' mode */
else if (str_eq( mcpp_optarg, "kr"))
mcpp_mode = KR; /* 'K&R 1st' mode */
else if (str_eq( mcpp_optarg, "std"))
mcpp_mode = STD; /* 'Standard' mode (default)*/
else if (str_eq( mcpp_optarg, "compat")) {
compat_mode = TRUE; /* 'compatible' mode */
mcpp_mode = STD;
}
else
usage( opt);
standard = (mcpp_mode == STD || mcpp_mode == POST_STD);
if (old_mode != STD && old_mode != mcpp_mode)
mcpp_fprintf( ERR, "Mode is redefined to: %s\n", mcpp_optarg);
break;
#if COMPILER == GNUC
case 'A': /* Ignore -A system(gnu), -A cpu(vax) or so */
break;
case 'a':
if (str_eq( mcpp_optarg, "nsi")) { /* -ansi */
look_and_install( "__STRICT_ANSI__", DEF_NOARGS_PREDEF, null
, "1");
ansi = TRUE;
break;
} else if (memcmp( mcpp_optarg, "uxbase", 6) == 0) {
mcpp_optind++;
break; /* Ignore '-auxbase some' or such nonsence */
#if SYSTEM == SYS_MAC
} else if (str_eq( mcpp_optarg, "rch")) { /* -arch */
strcpy( arch, argv[ mcpp_optind++]);
if (str_eq( arch, "ppc") || str_eq( arch, "ppc7400")
|| str_eq( arch, "ppc64")
|| str_eq( arch, "i386") || str_eq( arch, "i686")
|| str_eq( arch, "x86_64") || str_eq( arch, "amd64")) {
if (str_eq( arch, "i686"))
strcpy( arch, "i386");
else if (str_eq( arch, "amd64"))
strcpy( arch, "x86_64");
else if (str_eq( arch, "ppc7400"))
strcpy( arch, "ppc");
break;
} /* Else usage() */
#endif
}
usage( opt);
#elif COMPILER == MSC
case 'a':
if (memcmp( mcpp_optarg, "rch", 3) == 0) {
if (str_eq( mcpp_optarg + 3, ":SSE") /* -arch:SSE */
|| str_eq( mcpp_optarg + 3, ":sse"))
sse = 1;
else if (str_eq( mcpp_optarg + 3, ":SSE2") /* -arch:SSE2 */
|| str_eq( mcpp_optarg + 3, ":sse2"))
sse = 2;
/* Else ignore */
} else {
usage( opt);
}
break;
case 'A':
option_flags.lang_asm = TRUE; /* "assembler" source */
break;
#else
case 'a':
option_flags.lang_asm = TRUE; /* "assembler" source */
break;
#endif
#if ! STD_LINE_PREFIX
case 'b':
std_line_prefix = TRUE; /* Putout line and file infor- */
break; /* mation in C source style. */
#endif
case 'C': /* Keep comments */
option_flags.c = TRUE;
break;
#if COMPILER == GNUC
case 'c':
if (! integrated_cpp)
usage( opt);
break; /* Else ignore this option */
case 'd':
if (str_eq( mcpp_optarg, "M")) { /* -dM */
dMflag = TRUE;
no_output++;
} else if (str_eq( mcpp_optarg, "D")) { /* -dD */
dDflag = TRUE;
} else if (str_eq( mcpp_optarg, "igraphs")) { /* -digraphs */
option_flags.dig = TRUE;
} else if (str_eq( mcpp_optarg, "umpbase")) { /* -dumpbase */
; /* Ignore */
} else {
usage( opt);
}
break;
#endif /* COMPILER == GNUC */
case 'D': /* Define symbol */
if (def_cnt >= MAX_DEF) {
mcpp_fputs( "Too many -D options.\n", ERR);
longjmp( error_exit, -1);
}
def_list[ def_cnt++] = mcpp_optarg;
break;
case 'e':
/* Change the default MBCHAR encoding */
if (set_encoding( mcpp_optarg, FALSE, 0) == NULL)
usage( opt);
mb_changed = TRUE;
break;
#if COMPILER == GNUC
case 'E':
if (! integrated_cpp)
usage( opt);
break; /* Ignore this option */
case 'f':
if (memcmp( mcpp_optarg, "input-charset=", 14) == 0) {
/* Treat -finput-charset= as the same option as -e */
if (set_encoding( mcpp_optarg + 14, FALSE, 0) == NULL)
usage( opt);
mb_changed = TRUE;
} else if (str_eq( mcpp_optarg, "working-directory")) {
gcc_work_dir = TRUE;
} else if (str_eq( mcpp_optarg, "no-working-directory")) {
gcc_work_dir = FALSE;
} else if (str_eq( mcpp_optarg, "stack-protector")) {
look_and_install( "__SSP__", DEF_NOARGS_PREDEF, null, "1");
} else if (str_eq( mcpp_optarg, "stack-protector-all")) {
look_and_install( "__SSP_ALL__", DEF_NOARGS_PREDEF, null, "2");
} else if (str_eq( mcpp_optarg, "exceptions")) {
look_and_install( "__EXCEPTIONS", DEF_NOARGS_PREDEF, null
, "1");
} else if (str_eq( mcpp_optarg, "no-exceptions")) {
undef_list[ undef_cnt++] = "__EXCEPTIONS";
} else if (str_eq( mcpp_optarg, "PIC")
|| str_eq( mcpp_optarg, "pic")
|| str_eq( mcpp_optarg, "PIE")
|| str_eq( mcpp_optarg, "pie")) {
look_and_install( "__PIC__", DEF_NOARGS_PREDEF, null, "1");
look_and_install( "__pic__", DEF_NOARGS_PREDEF, null, "1");
} else if (str_eq( mcpp_optarg, "no-dollars-in-identifiers")) {
option_flags.dollar_in_name = FALSE;
} else if (str_eq( mcpp_optarg, "no-show-column")) {
; /* Ignore this option */
} else if (! integrated_cpp) {
usage( opt);
}
break;
case 'g':
if (!isdigit( *mcpp_optarg)
&& str_eq( argv[ mcpp_optind - 2], "-g"))
/* Neither '-g 0' nor '-ggdb' -- No argument */
mcpp_optind--;
break; /* Ignore the option */
#elif COMPILER == LCC
case 'g': /* Define __LCCDEBUGLEVEL as <n> */
if (*(mcpp_optarg + 1) == EOS && isdigit( *mcpp_optarg)) {
defp = look_id( debug_name);
strcpy( defp->repl, mcpp_optarg);
} else {
usage( opt);
}
break;
#elif COMPILER == MSC
case 'G':
if (*(mcpp_optarg + 1) == EOS) { /* -Gx */
switch (*mcpp_optarg) {
case '3': case '4': case '5': case '6':
gval = *mcpp_optarg;
break;
case 'B': /* -GB */
gval = '6';
break;
case 'R':
look_and_install( "_CPPRTTI", DEF_NOARGS_PREDEF, null
, "1");
break;
case 'X':
look_and_install( "_CPPUNWIND", DEF_NOARGS_PREDEF, null
, "1");
break;
case 'Z':
look_and_install( "__MSVC_RUNTIME_CHECKS"
, DEF_NOARGS_PREDEF, null, "1");
break;
default :
mcpp_fprintf( ERR, warning, opt, mcpp_optarg);
}
} else {
usage( opt);
}
break;
#endif
#if SYSTEM == SYS_MAC
case 'F':
framework[ num_framework++] = mcpp_optarg;
break;
#endif
case 'h':
if (*(mcpp_optarg + 1) == EOS && isdigit( *mcpp_optarg))
/* a digit */
look_and_install( "__STDC_HOSTED__", DEF_NOARGS_PREDEF, null
, mcpp_optarg);
else
usage( opt);
break;
#if COMPILER == MSC
case 'X':
unset_sys_dirs = TRUE;
break;
#endif
case 'I': /* Include directory */
if (str_eq( mcpp_optarg, "-")) { /* -I- */
#if COMPILER == GNUC
sys_dirp = incend; /* Split include directories */
i_split = TRUE;
#else
unset_sys_dirs = TRUE;
/* Unset pre-specified include directories */
#endif
} else if (*(mcpp_optarg + 1) == EOS && isdigit( *mcpp_optarg)
&& (i = *mcpp_optarg - '0') != 0
&& (i & ~(CURRENT | SOURCE)) == 0) {
search_rule = i; /* -I1, -I2 or -I3 */
} else { /* Not '-' nor a digit */
set_a_dir( mcpp_optarg); /* User-defined dir */
}
break;
#if COMPILER == MSC
case 'F':
if (str_eq( mcpp_optarg, "l")) { /* -Fl */
if (preinc_end >= &preinclude[ NPREINCLUDE]) {
mcpp_fputs( "Too many -Fl options.\n", ERR);
longjmp( error_exit, -1);
}
*preinc_end++ = argv[ mcpp_optind++];
} else {
usage( opt);
}
break;
#endif
#if COMPILER == GNUC
case 'i':
if (str_eq( mcpp_optarg, "nclude")) { /* -include */
if (preinc_end >= &preinclude[ NPREINCLUDE]) {
mcpp_fputs( "Too many -include options.\n", ERR);
longjmp( error_exit, -1);
}
*preinc_end++ = argv[ mcpp_optind++];
} else if (str_eq( mcpp_optarg, "system")) { /* -isystem */
if (sysdir_end >= &sysdir[ NSYSDIR]) {
mcpp_fputs( "Too many -isystem options.\n", ERR);
longjmp( error_exit, -1);
}
*sysdir_end++ = argv[ mcpp_optind++];
/* Add the directory before system include directory*/
} else if (str_eq( mcpp_optarg, "quote")) { /* -iquote */
if (quote_dir_end >= "e_dir[ N_QUOTE_DIR]) {
mcpp_fputs( "Too many -iquote options.\n", ERR);
longjmp( error_exit, -1);
}
*quote_dir_end++ = argv[ mcpp_optind++];
/* Add the directory for #include "header" */
} else if (memcmp( mcpp_optarg, "sysroot", 7) == 0) {
if (mcpp_optarg[ 7] == '=') /* -isysroot=DIR */
sysroot = mcpp_optarg + 8;
else if (mcpp_optarg[ 7] == EOS) /* -isysroot DIR */
sysroot = argv[ mcpp_optind++];
else
usage( opt);
} else if (str_eq( mcpp_optarg, "prefix") /* -iprefix */
|| str_eq( mcpp_optarg, "withprefix") /* -iwithprefix */
|| str_eq( mcpp_optarg, "withprefixbefore")
/* -iwithprefixbefore */
|| str_eq( mcpp_optarg, "dirafter") /* -idirafter */
|| str_eq( mcpp_optarg, "multilib")) { /* -imultilib */
mcpp_optind++; /* Skip the argument */
/* Ignore these options */
} else {
usage( opt);
}
break;
#endif
case 'j':
option_flags.no_source_line = TRUE;
break; /* Do not output the source line in diagnostics */
#if COMPILER == MSC
case 'J':
look_and_install( "_CHAR_UNSIGNED", DEF_NOARGS_PREDEF, null, "1");
break;
#endif
case 'K':
mcpp_debug |= MACRO_CALL;
/*
* Putout macro expansion informations embedded in comments.
* Same with '#pragma MCPP debug macro_call'.
*/
/* Enable white spaces preservation, too */
/* Fall through */
case 'k':
option_flags.k = TRUE;
/* Keep white spaces of input lines as they are */
break;
#if COMPILER == GNUC
case 'l':
if (memcmp( mcpp_optarg, "ang-", 4) != 0) {
usage( opt);
} else if (str_eq( mcpp_optarg + 4, "c")) { /* -lang-c */
; /* Ignore this option */
} else if (str_eq( mcpp_optarg + 4, "c99") /* -lang-c99*/
|| str_eq( mcpp_optarg + 4, "c9x")) { /* -lang-c9x*/
if (! sflag) {
stdc_val = 1; /* Define __STDC__ to 1 */
std_val = 199901L;
sflag = TRUE;
}
} else if (str_eq( mcpp_optarg + 4, "c89")) { /* -lang-c89*/
if (! sflag) {
stdc_val = 1; /* Define __STDC__ to 1 */
sflag = TRUE;
}
} else if (str_eq( mcpp_optarg + 4, "c++")) { /* -lang-c++*/
goto plus;
} else if (str_eq( mcpp_optarg + 4, "asm")) { /* -lang-asm*/
option_flags.lang_asm = TRUE;
} else {
usage( opt);
}
break;
#endif /* COMPILER == GNUC */
case 'M': /* Output source file dependency line */
if (str_eq( mcpp_optarg, "M")) { /* -MM */
;
} else if (str_eq( mcpp_optarg, "D")) { /* -MD */
mkdep |= (MD_SYSHEADER | MD_FILE);
} else if (str_eq( mcpp_optarg, "MD")) { /* -MMD */
mkdep |= MD_FILE;
} else if (str_eq( mcpp_optarg, "P")) { /* -MP */
mkdep |= MD_PHONY;
} else if (str_eq( mcpp_optarg, "Q")) { /* -MQ target */
mkdep |= MD_QUOTE;
mkdep_mq = argv[ mcpp_optind++];
} else if (str_eq( mcpp_optarg, "T")) { /* -MT target */
mkdep_mt = argv[ mcpp_optind++];
} else if (str_eq( mcpp_optarg, "F")) { /* -MF file */
mkdep_mf = argv[ mcpp_optind++];
} else if (argv[ mcpp_optind - 1] == mcpp_optarg) { /* -M */
mkdep |= MD_SYSHEADER;
mcpp_optind--;
} else {
usage( opt);
}
if (str_eq( mcpp_optarg, "D") || str_eq( mcpp_optarg, "MD")) {
cp = argv[ mcpp_optind];
if (cp && *cp != '-') /* -MD (-MMD) file */
mkdep_md = argv[ mcpp_optind++];
}
mkdep |= MD_MKDEP;
break;
#if SYS_FAMILY == SYS_UNIX
case 'm':
if (str_eq( mcpp_optarg, "64")) { /* -m64 */
if (str_eq( CPU, "i386"))
strcpy( arch, "x86_64");
else if (str_eq( CPU, "ppc"))
strcpy( arch, "ppc64");
/* Else ignore */
break;
} else if (str_eq( mcpp_optarg, "32")) { /* -m32 */
if (str_eq( CPU, "x86_64"))
strcpy( arch, "i386");
else if (str_eq( CPU, "ppc64"))
strcpy( arch, "ppc");
/* Else ignore */
break;
} else if (str_eq( mcpp_optarg, "mmx")) { /* -mmmx */
look_and_install( "__MMX__", DEF_NOARGS_PREDEF, null, "1");
break;
} else if (str_eq( mcpp_optarg, "no-mmx")) { /* -mno-mmx */
undef_list[ undef_cnt++] = "__MMX__";
break;
}
#endif /* SYS_FAMILY == UNIX */
#if COMPILER == GNUC
#if SYSTEM == SYS_CYGWIN
if (str_eq( mcpp_optarg, "no-cygwin")) { /* -mno-cygwin */
no_cygwin = TRUE;
break;
}
#endif
if (! integrated_cpp)
usage( opt);
break;
case 'u':
if (! str_eq( mcpp_optarg, "ndef")) /* -undef */
usage( opt); /* Else fall through */
#endif /* COMPILER == GNUC */
#if COMPILER == MSC
case 'u':
#endif
case 'N':
/* No predefines: remove "unix", "__unix__" and friends. */
nflag = TRUE;
break;
#if COMPILER == GNUC || NO_DIR
case 'n':
#if NO_DIR
if (str_eq( mcpp_optarg, "odir")) { /* -nodir */
no_dir = TRUE;
}
#endif
#if COMPILER == GNUC
if (str_eq( mcpp_optarg, "ostdinc")) { /* -nostdinc */
unset_sys_dirs = TRUE; /* Unset pre-specified directories */
} else if (str_eq( mcpp_optarg, "ostdinc++")) { /* -nostdinc++ */
set_cplus_dir = FALSE; /* Unset C++-specific directories */
} else if (str_eq( mcpp_optarg, "oprecomp")) { /* -noprecomp */
mcpp_fprintf( ERR, warning, opt, mcpp_optarg);
break;
}
#endif
else {
usage( opt);
}
break;
#endif
#if COMPILER == GNUC
case 'O':
if (integrated_cpp) {
if (*mcpp_optarg == '-') /* No argument */
mcpp_optind--;
else if ((isdigit( *mcpp_optarg) && *mcpp_optarg != '0')
|| *mcpp_optarg == 's' || *mcpp_optarg == 'z')
/* -O1, -O2 -Os, -Oz */
look_and_install( "__OPTIMIZE__", DEF_NOARGS_PREDEF, null
, "1");
else if (! isdigit( *mcpp_optarg))
usage( opt);
/* Else -O0: ignore */
} else {
usage( opt);
}
break; /* Else ignore -Ox option */
#elif COMPILER == LCC
case 'O': /* Define __LCCOPTIMLEVEL as 1 */
defp = look_id( optim_name);
strcpy( defp->repl, "1");
break;
#endif
case 'o':
*out_pp = mcpp_optarg; /* Output file name */
break;
case 'P': /* No #line output */