1 // SPDX-License-Identifier: MIT
3 * 'sparse' library helper routines.
5 * Copyright (C) 2003 Transmeta Corp.
6 * 2003-2004 Linus Torvalds
7 * 2017-2020 Luc Van Oostenryck
23 # define __GNUC_MINOR__ 95
24 # define __GNUC_PATCHLEVEL__ 0
35 int gcc_major
= __GNUC__
;
36 int gcc_minor
= __GNUC_MINOR__
;
37 int gcc_patchlevel
= __GNUC_PATCHLEVEL__
;
45 #define CMDLINE_INCLUDE 20
46 int cmdline_include_nr
= 0;
47 char *cmdline_include
[CMDLINE_INCLUDE
];
49 const char *base_filename
;
50 const char *diag_prefix
= "";
51 const char *gcc_base_dir
= GCC_BASE
;
52 const char *multiarch_dir
= MULTIARCH_TRIPLET
;
53 const char *outfile
= NULL
;
55 enum standard standard
= STANDARD_GNU89
;
57 int arch_big_endian
= ARCH_BIG_ENDIAN
;
58 int arch_cmodel
= CMODEL_UNKNOWN
;
59 int arch_fp_abi
= FP_ABI_NATIVE
;
60 int arch_m64
= ARCH_M64_DEFAULT
;
61 int arch_msize_long
= 0;
62 int arch_os
= OS_NATIVE
;
69 int dbg_postorder
= 0;
71 int dump_macro_defs
= 0;
72 int dump_macros_only
= 0;
74 unsigned long fdump_ir
;
76 unsigned int fmax_errors
= 100;
77 unsigned int fmax_warnings
= 100;
79 unsigned long long fmemcpy_max_count
= 100000;
80 unsigned long fpasses
= ~0UL;
84 int funsigned_bitfields
= 0;
85 int funsigned_char
= 0;
88 int Waddress_space
= 1;
90 int Wbitwise_pointer
= 0;
91 int Wcast_from_as
= 0;
93 int Wcast_truncate
= 1;
94 int Wconstant_suffix
= 0;
95 int Wconstexpr_not_const
= 0;
98 int Wdeclarationafterstatement
= -1;
99 int Wdefault_bitfield_sign
= 0;
100 int Wdesignated_init
= 1;
102 int Wenum_mismatch
= 1;
103 int Wexternal_function_has_definition
= 1;
104 int Wflexible_array_array
= 1;
105 int Wflexible_array_nested
= 0;
106 int Wflexible_array_sizeof
= 0;
107 int Wflexible_array_union
= 0;
108 int Wimplicit_int
= 1;
109 int Winit_cstring
= 0;
110 int Wint_to_pointer_cast
= 1;
111 int Wmemcpy_max_count
= 1;
112 int Wnewline_eof
= 1;
113 int Wnon_pointer_null
= 1;
114 int Wold_initializer
= 1;
115 int Wold_style_definition
= 1;
116 int Wone_bit_signed_bitfield
= 1;
117 int Woverride_init
= 1;
118 int Woverride_init_all
= 0;
119 int Woverride_init_whole_range
= 0;
120 int Wparen_string
= 0;
121 int Wpast_deep_designator
= 0;
123 int Wpointer_arith
= 0;
124 int Wpointer_to_int_cast
= 1;
125 int Wptr_subtraction_blows
= 0;
126 int Wreturn_void
= 0;
128 int Wshift_count_negative
= 1;
129 int Wshift_count_overflow
= 1;
130 int Wsizeof_bool
= 0;
131 int Wsparse_error
= FLAG_FORCE_OFF
;
132 int Wstrict_prototypes
= 1;
133 int Wtautological_compare
= 0;
134 int Wtransparent_union
= 0;
137 int Wuninitialized
= 1;
139 int Wuniversal_initializer
= 0;
140 int Wunknown_attribute
= 0;
143 ////////////////////////////////////////////////////////////////////////////////
144 // Helpers for option parsing
146 static const char *match_option(const char *arg
, const char *prefix
)
148 unsigned int n
= strlen(prefix
);
149 if (strncmp(arg
, prefix
, n
) == 0)
160 static int handle_subopt_val(const char *opt
, const char *arg
, const struct val_map
*map
, int *flag
)
165 die("missing argument for option '%s'", opt
);
166 for (;(name
= map
->name
); map
++) {
167 if (strcmp(name
, arg
) == 0 || strcmp(name
, "*") == 0) {
171 if (strcmp(name
, "?") == 0)
172 die("invalid argument '%s' in option '%s'", arg
, opt
);
183 static int apply_mask(unsigned long *val
, const char *str
, unsigned len
, const struct mask_map
*map
, int neg
)
187 for (;(name
= map
->name
); map
++) {
188 if (!strncmp(name
, str
, len
) && !name
[len
]) {
199 static int handle_suboption_mask(const char *arg
, const char *opt
, const struct mask_map
*map
, unsigned long *flag
)
202 apply_mask(flag
, "", 0, map
, 0);
208 unsigned int len
= strcspn(opt
, ",+");
212 if (!strncmp(opt
, "no-", 3)) {
217 if (apply_mask(flag
, opt
, len
, map
, neg
))
218 die("error: wrong option '%.*s' for \'%s\'", len
, opt
, arg
);
229 #define OPT_INVERSE 1
234 int (*fun
)(const char *arg
, const char *opt
, const struct flag
*, int options
);
239 static int handle_switches(const char *ori
, const char *opt
, const struct flag
*flags
)
241 const char *arg
= opt
;
244 // Prefixe "no-" mean to turn flag off.
245 if (strncmp(arg
, "no-", 3) == 0) {
250 for (; flags
->name
; flags
++) {
251 const char *opt
= match_option(arg
, flags
->name
);
260 options
|= OPT_INVERSE
;
261 if ((rc
= flags
->fun(ori
, opt
, flags
, options
)))
266 if (opt
[0] == '\0' && flags
->flag
) {
267 if (flags
->mask
& OPT_VAL
)
269 if (flags
->mask
& OPT_INVERSE
)
280 static char **handle_onoff_switch(char *arg
, char **next
, const struct flag flags
[])
286 // Prefixes "no" and "no-" mean to turn warning off.
287 if (p
[0] == 'n' && p
[1] == 'o') {
291 flag
= FLAG_FORCE_OFF
;
294 for (i
= 0; flags
[i
].name
; i
++) {
295 if (!strcmp(p
,flags
[i
].name
)) {
296 *flags
[i
].flag
= flag
;
305 static void handle_onoff_switch_finalize(const struct flag flags
[])
309 for (i
= 0; flags
[i
].name
; i
++) {
310 if (*flags
[i
].flag
== FLAG_FORCE_OFF
)
311 *flags
[i
].flag
= FLAG_OFF
;
315 static int handle_switch_setval(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
317 *(flag
->flag
) = flag
->mask
;
322 #define OPTNUM_ZERO_IS_INF 1
323 #define OPTNUM_UNLIMITED 2
325 #define OPT_NUMERIC(NAME, TYPE, FUNCTION) \
326 static int opt_##NAME(const char *arg, const char *opt, TYPE *ptr, int flag) \
331 val = FUNCTION(opt, &end, 0); \
332 if (*end != '\0' || end == opt) { \
333 if ((flag & OPTNUM_UNLIMITED) && !strcmp(opt, "unlimited")) \
336 die("error: wrong argument to \'%s\'", arg); \
338 if ((flag & OPTNUM_ZERO_IS_INF) && val == 0) \
344 OPT_NUMERIC(ullong
, unsigned long long, strtoull
)
345 OPT_NUMERIC(uint
, unsigned int, strtoul
)
347 ////////////////////////////////////////////////////////////////////////////////
350 static char **handle_switch_a(char *arg
, char **next
)
352 if (!strcmp(arg
, "ansi"))
353 standard
= STANDARD_C89
;
358 static char **handle_switch_D(char *arg
, char **next
)
360 const char *name
= arg
+ 1;
361 const char *value
= "1";
366 die("argument to `-D' is missing");
381 add_pre_buffer("#define %s %s\n", name
, value
);
385 static char **handle_switch_d(char *arg
, char **next
)
387 char *arg_char
= arg
+ 1;
390 * -d<CHARS>, where <CHARS> is a sequence of characters, not preceded
391 * by a space. If you specify characters whose behaviour conflicts,
392 * the result is undefined.
396 case 'M': /* dump just the macro definitions */
397 dump_macros_only
= 1;
400 case 'D': /* like 'M', but also output pre-processed text */
402 dump_macros_only
= 0;
404 case 'N': /* like 'D', but only output macro names not bodies */
406 case 'I': /* like 'D', but also output #include directives */
408 case 'U': /* like 'D', but only output expanded macros */
416 static char **handle_switch_E(char *arg
, char **next
)
423 static int handle_ftabstop(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
429 die("error: missing argument to \"%s\"", arg
);
431 /* we silently ignore silly values */
432 val
= strtoul(opt
, &end
, 10);
433 if (*end
== '\0' && 1 <= val
&& val
<= 100)
439 static int handle_fpasses(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
445 if (options
& OPT_INVERSE
)
451 if (options
& OPT_INVERSE
)
453 if (!strcmp(opt
, "-enable")) {
457 if (!strcmp(opt
, "-disable")) {
461 if (!strcmp(opt
, "=last")) {
462 // clear everything above
470 static int handle_fdiagnostic_prefix(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
474 diag_prefix
= "sparse: ";
477 diag_prefix
= xasprintf("%s: ", opt
+1);
484 static int handle_fdump_ir(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
486 static const struct mask_map dump_ir_options
[] = {
487 { "", PASS_LINEARIZE
},
488 { "linearize", PASS_LINEARIZE
},
489 { "mem2reg", PASS_MEM2REG
},
490 { "final", PASS_FINAL
},
494 return handle_suboption_mask(arg
, opt
, dump_ir_options
, &fdump_ir
);
497 static int handle_fmemcpy_max_count(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
499 opt_ullong(arg
, opt
, &fmemcpy_max_count
, OPTNUM_ZERO_IS_INF
|OPTNUM_UNLIMITED
);
503 static int handle_fmax_errors(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
505 opt_uint(arg
, opt
, &fmax_errors
, OPTNUM_UNLIMITED
);
509 static int handle_fmax_warnings(const char *arg
, const char *opt
, const struct flag
*flag
, int options
)
511 opt_uint(arg
, opt
, &fmax_warnings
, OPTNUM_UNLIMITED
);
515 static struct flag fflags
[] = {
516 { "diagnostic-prefix", NULL
, handle_fdiagnostic_prefix
},
517 { "dump-ir", NULL
, handle_fdump_ir
},
518 { "freestanding", &fhosted
, NULL
, OPT_INVERSE
},
519 { "hosted", &fhosted
},
520 { "linearize", NULL
, handle_fpasses
, PASS_LINEARIZE
},
521 { "max-errors=", NULL
, handle_fmax_errors
},
522 { "max-warnings=", NULL
, handle_fmax_warnings
},
523 { "mem-report", &fmem_report
},
524 { "memcpy-max-count=", NULL
, handle_fmemcpy_max_count
},
525 { "tabstop=", NULL
, handle_ftabstop
},
526 { "mem2reg", NULL
, handle_fpasses
, PASS_MEM2REG
},
527 { "optim", NULL
, handle_fpasses
, PASS_OPTIM
},
528 { "pic", &fpic
, handle_switch_setval
, 1 },
529 { "PIC", &fpic
, handle_switch_setval
, 2 },
530 { "pie", &fpie
, handle_switch_setval
, 1 },
531 { "PIE", &fpie
, handle_switch_setval
, 2 },
532 { "signed-bitfields", &funsigned_bitfields
, NULL
, OPT_INVERSE
},
533 { "unsigned-bitfields", &funsigned_bitfields
, NULL
, },
534 { "signed-char", &funsigned_char
, NULL
, OPT_INVERSE
},
535 { "short-wchar", &fshort_wchar
},
536 { "unsigned-char", &funsigned_char
, NULL
, },
540 static char **handle_switch_f(char *arg
, char **next
)
542 if (handle_switches(arg
-1, arg
+1, fflags
))
548 static char **handle_switch_G(char *arg
, char **next
)
550 if (!strcmp(arg
, "G") && *next
)
551 return next
+ 1; // "-G 0"
553 return next
; // "-G0" or (bogus) terminal "-G"
556 static char **handle_base_dir(char *arg
, char **next
)
558 gcc_base_dir
= *++next
;
560 die("missing argument for -gcc-base-dir option");
564 static char **handle_switch_g(char *arg
, char **next
)
566 if (!strcmp(arg
, "gcc-base-dir"))
567 return handle_base_dir(arg
, next
);
572 static char **handle_switch_I(char *arg
, char **next
)
578 add_pre_buffer("#split_include\n");
581 case '\0': /* Plain "-I" */
584 die("missing argument for -I option");
587 add_pre_buffer("#add_include \"%s/\"\n", path
);
592 static void add_cmdline_include(char *filename
)
594 if (cmdline_include_nr
>= CMDLINE_INCLUDE
)
595 die("too many include files for %s\n", filename
);
596 cmdline_include
[cmdline_include_nr
++] = filename
;
599 static char **handle_switch_i(char *arg
, char **next
)
601 if (*next
&& !strcmp(arg
, "include"))
602 add_cmdline_include(*++next
);
603 else if (*next
&& !strcmp(arg
, "imacros"))
604 add_cmdline_include(*++next
);
605 else if (*next
&& !strcmp(arg
, "isystem")) {
606 char *path
= *++next
;
608 die("missing argument for -isystem option");
609 add_pre_buffer("#add_isystem \"%s/\"\n", path
);
610 } else if (*next
&& !strcmp(arg
, "idirafter")) {
611 char *path
= *++next
;
613 die("missing argument for -idirafter option");
614 add_pre_buffer("#add_dirafter \"%s/\"\n", path
);
619 static char **handle_switch_M(char *arg
, char **next
)
621 if (!strcmp(arg
, "MF") || !strcmp(arg
,"MQ") || !strcmp(arg
,"MT")) {
623 die("missing argument for -%s option", arg
);
629 static int handle_march(const char *opt
, const char *arg
, const struct flag
*flag
, int options
)
631 if (arch_target
->parse_march
)
632 arch_target
->parse_march(arg
);
636 static int handle_mcmodel(const char *opt
, const char *arg
, const struct flag
*flag
, int options
)
638 static const struct val_map cmodels
[] = {
639 { "kernel", CMODEL_KERNEL
},
640 { "large", CMODEL_LARGE
},
641 { "medany", CMODEL_MEDANY
},
642 { "medium", CMODEL_MEDIUM
},
643 { "medlow", CMODEL_MEDLOW
},
644 { "small", CMODEL_SMALL
},
645 { "tiny", CMODEL_TINY
},
648 return handle_subopt_val(opt
, arg
, cmodels
, flag
->flag
);
651 static int handle_mfloat_abi(const char *opt
, const char *arg
, const struct flag
*flag
, int options
) {
652 static const struct val_map fp_abis
[] = {
653 { "hard", FP_ABI_HARD
},
654 { "soft", FP_ABI_SOFT
},
655 { "softfp", FP_ABI_HYBRID
},
658 return handle_subopt_val(opt
, arg
, fp_abis
, flag
->flag
);
661 static char **handle_multiarch_dir(char *arg
, char **next
)
663 multiarch_dir
= *++next
;
665 die("missing argument for -multiarch-dir option");
669 static const struct flag mflags
[] = {
670 { "64", &arch_m64
, NULL
, OPT_VAL
, ARCH_LP64
},
671 { "32", &arch_m64
, NULL
, OPT_VAL
, ARCH_LP32
},
672 { "31", &arch_m64
, NULL
, OPT_VAL
, ARCH_LP32
},
673 { "16", &arch_m64
, NULL
, OPT_VAL
, ARCH_LP32
},
674 { "x32",&arch_m64
, NULL
, OPT_VAL
, ARCH_X32
},
675 { "size-llp64", &arch_m64
, NULL
, OPT_VAL
, ARCH_LLP64
},
676 { "size-long", &arch_msize_long
},
677 { "arch=", NULL
, handle_march
},
678 { "big-endian", &arch_big_endian
, NULL
},
679 { "little-endian", &arch_big_endian
, NULL
, OPT_INVERSE
},
680 { "cmodel", &arch_cmodel
, handle_mcmodel
},
681 { "float-abi", &arch_fp_abi
, handle_mfloat_abi
},
682 { "hard-float", &arch_fp_abi
, NULL
, OPT_VAL
, FP_ABI_HARD
},
683 { "soft-float", &arch_fp_abi
, NULL
, OPT_VAL
, FP_ABI_SOFT
},
687 static char **handle_switch_m(char *arg
, char **next
)
689 if (!strcmp(arg
, "multiarch-dir")) {
690 return handle_multiarch_dir(arg
, next
);
692 handle_switches(arg
-1, arg
+1, mflags
);
698 static char **handle_nostdinc(char *arg
, char **next
)
700 add_pre_buffer("#nostdinc\n");
704 static char **handle_switch_n(char *arg
, char **next
)
706 if (!strcmp(arg
, "nostdinc"))
707 return handle_nostdinc(arg
, next
);
712 static char **handle_switch_O(char *arg
, char **next
)
715 if (arg
[1] >= '0' && arg
[1] <= '9')
716 level
= arg
[1] - '0';
717 optimize_level
= level
;
718 optimize_size
= arg
[1] == 's';
722 static char **handle_switch_o(char *arg
, char **next
)
724 if (!strcmp(arg
, "o")) { // "-o foo"
726 die("argument to '-o' is missing");
734 static const struct flag pflags
[] = {
735 { "pedantic", &Wpedantic
, NULL
, OPT_VAL
, FLAG_ON
},
739 static char **handle_switch_p(char *arg
, char **next
)
741 handle_switches(arg
-1, arg
, pflags
);
745 static char **handle_switch_s(const char *arg
, char **next
)
747 if ((arg
= match_option(arg
, "std="))) {
748 if (!strcmp(arg
, "c89") ||
749 !strcmp(arg
, "iso9899:1990"))
750 standard
= STANDARD_C89
;
752 else if (!strcmp(arg
, "iso9899:199409"))
753 standard
= STANDARD_C94
;
755 else if (!strcmp(arg
, "c99") ||
756 !strcmp(arg
, "c9x") ||
757 !strcmp(arg
, "iso9899:1999") ||
758 !strcmp(arg
, "iso9899:199x"))
759 standard
= STANDARD_C99
;
761 else if (!strcmp(arg
, "gnu89"))
762 standard
= STANDARD_GNU89
;
764 else if (!strcmp(arg
, "gnu99") || !strcmp(arg
, "gnu9x"))
765 standard
= STANDARD_GNU99
;
767 else if (!strcmp(arg
, "c11") ||
768 !strcmp(arg
, "c1x") ||
769 !strcmp(arg
, "iso9899:2011"))
770 standard
= STANDARD_C11
;
772 else if (!strcmp(arg
, "gnu11"))
773 standard
= STANDARD_GNU11
;
775 else if (!strcmp(arg
, "c17") ||
776 !strcmp(arg
, "c18") ||
777 !strcmp(arg
, "iso9899:2017") ||
778 !strcmp(arg
, "iso9899:2018"))
779 standard
= STANDARD_C17
;
780 else if (!strcmp(arg
, "gnu17") ||
781 !strcmp(arg
, "gnu18"))
782 standard
= STANDARD_GNU17
;
785 die("Unsupported C dialect");
791 static char **handle_switch_U(char *arg
, char **next
)
793 const char *name
= arg
+ 1;
798 die("argument to `-U' is missing");
800 add_pre_buffer("#undef %s\n", name
);
804 static struct flag debugs
[] = {
805 { "compound", &dbg_compound
},
806 { "dead", &dbg_dead
},
807 { "domtree", &dbg_domtree
},
808 { "entry", &dbg_entry
},
810 { "postorder", &dbg_postorder
},
814 static char **handle_switch_v(char *arg
, char **next
)
816 char ** ret
= handle_onoff_switch(arg
, next
, debugs
);
823 } while (*++arg
== 'v');
827 static void handle_switch_v_finalize(void)
829 handle_onoff_switch_finalize(debugs
);
832 static const struct flag warnings
[] = {
833 { "address", &Waddress
},
834 { "address-space", &Waddress_space
},
835 { "bitwise", &Wbitwise
},
836 { "bitwise-pointer", &Wbitwise_pointer
},
837 { "cast-from-as", &Wcast_from_as
},
838 { "cast-to-as", &Wcast_to_as
},
839 { "cast-truncate", &Wcast_truncate
},
840 { "constant-suffix", &Wconstant_suffix
},
841 { "constexpr-not-const", &Wconstexpr_not_const
},
842 { "context", &Wcontext
},
844 { "declaration-after-statement", &Wdeclarationafterstatement
},
845 { "default-bitfield-sign", &Wdefault_bitfield_sign
},
846 { "designated-init", &Wdesignated_init
},
847 { "do-while", &Wdo_while
},
848 { "enum-mismatch", &Wenum_mismatch
},
849 { "external-function-has-definition", &Wexternal_function_has_definition
},
850 { "flexible-array-array", &Wflexible_array_array
},
851 { "flexible-array-nested", &Wflexible_array_nested
},
852 { "flexible-array-sizeof", &Wflexible_array_sizeof
},
853 { "flexible-array-union", &Wflexible_array_union
},
854 { "implicit-int", &Wimplicit_int
},
855 { "init-cstring", &Winit_cstring
},
856 { "int-to-pointer-cast", &Wint_to_pointer_cast
},
857 { "memcpy-max-count", &Wmemcpy_max_count
},
858 { "non-pointer-null", &Wnon_pointer_null
},
859 { "newline-eof", &Wnewline_eof
},
860 { "old-initializer", &Wold_initializer
},
861 { "old-style-definition", &Wold_style_definition
},
862 { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield
},
863 { "override-init", &Woverride_init
},
864 { "override-init-all", &Woverride_init_all
},
865 { "paren-string", &Wparen_string
},
866 { "past-deep-designator", &Wpast_deep_designator
},
867 { "pedantic", &Wpedantic
},
868 { "pointer-to-int-cast", &Wpointer_to_int_cast
},
869 { "ptr-subtraction-blows", &Wptr_subtraction_blows
},
870 { "return-void", &Wreturn_void
},
871 { "shadow", &Wshadow
},
872 { "shift-count-negative", &Wshift_count_negative
},
873 { "shift-count-overflow", &Wshift_count_overflow
},
874 { "sizeof-bool", &Wsizeof_bool
},
875 { "strict-prototypes", &Wstrict_prototypes
},
876 { "pointer-arith", &Wpointer_arith
},
877 { "sparse-error", &Wsparse_error
},
878 { "tautological-compare", &Wtautological_compare
},
879 { "transparent-union", &Wtransparent_union
},
880 { "typesign", &Wtypesign
},
881 { "undef", &Wundef
},
882 { "uninitialized", &Wuninitialized
},
883 { "union-cast", &Wunion_cast
},
884 { "universal-initializer", &Wuniversal_initializer
},
885 { "unknown-attribute", &Wunknown_attribute
},
890 static char **handle_switch_W(char *arg
, char **next
)
892 char ** ret
= handle_onoff_switch(arg
, next
, warnings
);
896 if (!strcmp(arg
, "Wsparse-all")) {
898 for (i
= 0; warnings
[i
].name
; i
++) {
899 if (*warnings
[i
].flag
!= FLAG_FORCE_OFF
)
900 *warnings
[i
].flag
= FLAG_ON
;
908 static void handle_switch_W_finalize(void)
910 handle_onoff_switch_finalize(warnings
);
912 /* default Wdeclarationafterstatement based on the C dialect */
913 if (-1 == Wdeclarationafterstatement
) {
917 Wdeclarationafterstatement
= 1;
920 Wdeclarationafterstatement
= 0;
926 static char **handle_switch_x(char *arg
, char **next
)
929 die("missing argument for -x option");
934 static char **handle_arch(char *arg
, char **next
)
939 die("missing argument for --arch option");
941 mach
= target_parse(arg
);
942 if (mach
!= MACH_UNKNOWN
)
948 static char **handle_param(char *arg
, char **next
)
952 /* For now just skip any '--param=*' or '--param *' */
955 } else if (isspace((unsigned char)*arg
) || *arg
== '=') {
960 die("missing argument for --param option");
965 static char **handle_os(char *arg
, char **next
)
968 die("missing argument for --os option");
975 static char **handle_version(char *arg
, char **next
)
977 printf("%s\n", SPARSE_VERSION
);
983 char **(*fn
)(char *, char **);
984 unsigned int prefix
:1;
987 static char **handle_long_options(char *arg
, char **next
)
989 static struct switches cmd
[] = {
990 { "arch", handle_arch
, 1 },
991 { "os", handle_os
, 1 },
992 { "param", handle_param
, 1 },
993 { "version", handle_version
},
996 struct switches
*s
= cmd
;
999 int optlen
= strlen(s
->name
);
1000 if (!strncmp(s
->name
, arg
, optlen
+ !s
->prefix
))
1001 return s
->fn(arg
+ optlen
, next
);
1007 char **handle_switch(char *arg
, char **next
)
1010 case 'a': return handle_switch_a(arg
, next
);
1011 case 'D': return handle_switch_D(arg
, next
);
1012 case 'd': return handle_switch_d(arg
, next
);
1013 case 'E': return handle_switch_E(arg
, next
);
1014 case 'f': return handle_switch_f(arg
, next
);
1015 case 'g': return handle_switch_g(arg
, next
);
1016 case 'G': return handle_switch_G(arg
, next
);
1017 case 'I': return handle_switch_I(arg
, next
);
1018 case 'i': return handle_switch_i(arg
, next
);
1019 case 'M': return handle_switch_M(arg
, next
);
1020 case 'm': return handle_switch_m(arg
, next
);
1021 case 'n': return handle_switch_n(arg
, next
);
1022 case 'o': return handle_switch_o(arg
, next
);
1023 case 'O': return handle_switch_O(arg
, next
);
1024 case 'p': return handle_switch_p(arg
, next
);
1025 case 's': return handle_switch_s(arg
, next
);
1026 case 'U': return handle_switch_U(arg
, next
);
1027 case 'v': return handle_switch_v(arg
, next
);
1028 case 'W': return handle_switch_W(arg
, next
);
1029 case 'x': return handle_switch_x(arg
, next
);
1030 case '-': return handle_long_options(arg
+ 1, next
);
1036 * Ignore unknown command line options:
1037 * they're probably gcc switches
1042 void handle_switch_finalize(void)
1044 handle_switch_v_finalize();
1045 handle_switch_W_finalize();