svn merge -r102224:107263 svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-3_4-branch
[official-gcc.git] / gcc / opts.c
blobc1182c22483907304049cd658d40f3fe0d546526
1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "intl.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "ggc.h"
30 #include "output.h"
31 #include "langhooks.h"
32 #include "opts.h"
33 #include "options.h"
34 #include "flags.h"
35 #include "toplev.h"
36 #include "params.h"
37 #include "diagnostic.h"
38 #include "tm_p.h" /* For OPTIMIZATION_OPTIONS. */
39 #include "insn-attr.h" /* For INSN_SCHEDULING. */
41 /* Value of the -G xx switch, and whether it was passed or not. */
42 unsigned HOST_WIDE_INT g_switch_value;
43 bool g_switch_set;
45 /* True if we should exit after parsing options. */
46 bool exit_after_options;
48 /* If -version. */
49 bool version_flag;
51 /* Print various extra warnings. -W/-Wextra. */
52 bool extra_warnings;
54 /* Don't print warning messages. -w. */
55 bool inhibit_warnings;
57 /* Treat warnings as errors. -Werror. */
58 bool warnings_are_errors;
60 /* Warn if a function returns an aggregate, since there are often
61 incompatible calling conventions for doing this. */
62 bool warn_aggregate_return;
64 /* Nonzero means warn about pointer casts that increase the required
65 alignment of the target type (and might therefore lead to a crash
66 due to a misaligned access). */
67 bool warn_cast_align;
69 /* Nonzero means warn about uses of __attribute__((deprecated))
70 declarations. */
71 bool warn_deprecated_decl = true;
73 /* Warn when an optimization pass is disabled. */
74 bool warn_disabled_optimization;
76 /* Nonzero means warn if inline function is too large. */
77 bool warn_inline;
79 /* True to warn about any objects definitions whose size is larger
80 than N bytes. Also want about function definitions whose returned
81 values are larger than N bytes, where N is `larger_than_size'. */
82 bool warn_larger_than;
83 HOST_WIDE_INT larger_than_size;
85 /* Warn about functions which might be candidates for attribute noreturn. */
86 bool warn_missing_noreturn;
88 /* True to warn about code which is never reached. */
89 bool warn_notreached;
91 /* Warn if packed attribute on struct is unnecessary and inefficient. */
92 bool warn_packed;
94 /* Warn when gcc pads a structure to an alignment boundary. */
95 bool warn_padded;
97 /* True means warn about all declarations which shadow others. */
98 bool warn_shadow;
100 /* Nonzero means warn about constructs which might not be
101 strict-aliasing safe. */
102 bool warn_strict_aliasing;
104 /* True to warn if a switch on an enum, that does not have a default
105 case, fails to have a case for every enum value. */
106 bool warn_switch;
108 /* Warn if a switch does not have a default case. */
109 bool warn_switch_default;
111 /* Warn if a switch on an enum fails to have a case for every enum
112 value (regardless of the presence or otherwise of a default case). */
113 bool warn_switch_enum;
115 /* Don't suppress warnings from system headers. -Wsystem-headers. */
116 bool warn_system_headers;
118 /* True to warn about variables used before they are initialized. */
119 int warn_uninitialized;
121 /* True to warn about unused variables, functions et.al. */
122 bool warn_unused_function;
123 bool warn_unused_label;
124 bool warn_unused_parameter;
125 bool warn_unused_variable;
126 bool warn_unused_value;
128 /* Hack for cooperation between set_Wunused and set_Wextra. */
129 static bool maybe_warn_unused_parameter;
131 /* Type(s) of debugging information we are producing (if any). See
132 flags.h for the definitions of the different possible types of
133 debugging information. */
134 enum debug_info_type write_symbols = NO_DEBUG;
136 /* Level of debugging information we are producing. See flags.h for
137 the definitions of the different possible levels. */
138 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
140 /* Nonzero means use GNU-only extensions in the generated symbolic
141 debugging information. Currently, this only has an effect when
142 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
143 bool use_gnu_debug_info_extensions;
145 /* The default visibility for all symbols (unless overridden) */
146 enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
148 /* Global visibility options. */
149 struct visibility_flags visibility_options;
151 /* Columns of --help display. */
152 static unsigned int columns = 80;
154 /* What to print when a switch has no documentation. */
155 static const char undocumented_msg[] = N_("This switch lacks documentation");
157 /* Used for bookkeeping on whether user set these flags so
158 -fprofile-use/-fprofile-generate does not use them. */
159 static bool profile_arc_flag_set, flag_profile_values_set;
160 static bool flag_unroll_loops_set, flag_tracer_set;
161 static bool flag_value_profile_transformations_set;
162 static bool flag_peel_loops_set, flag_branch_probabilities_set;
164 /* Input file names. */
165 const char **in_fnames;
166 unsigned num_in_fnames;
168 static size_t find_opt (const char *, int);
169 static int common_handle_option (size_t scode, const char *arg, int value);
170 static void handle_param (const char *);
171 static void set_Wextra (int);
172 static unsigned int handle_option (const char **argv, unsigned int lang_mask);
173 static char *write_langs (unsigned int lang_mask);
174 static void complain_wrong_lang (const char *, const struct cl_option *,
175 unsigned int lang_mask);
176 static void handle_options (unsigned int, const char **, unsigned int);
177 static void wrap_help (const char *help, const char *item, unsigned int);
178 static void print_help (void);
179 static void print_param_help (void);
180 static void print_filtered_help (unsigned int flag);
181 static unsigned int print_switch (const char *text, unsigned int indent);
182 static void set_debug_level (enum debug_info_type type, int extended,
183 const char *arg);
185 /* Perform a binary search to find which option the command-line INPUT
186 matches. Returns its index in the option array, and N_OPTS
187 (cl_options_count) on failure.
189 This routine is quite subtle. A normal binary search is not good
190 enough because some options can be suffixed with an argument, and
191 multiple sub-matches can occur, e.g. input of "-pedantic" matching
192 the initial substring of "-pedantic-errors".
194 A more complicated example is -gstabs. It should match "-g" with
195 an argument of "stabs". Suppose, however, that the number and list
196 of switches are such that the binary search tests "-gen-decls"
197 before having tested "-g". This doesn't match, and as "-gen-decls"
198 is less than "-gstabs", it will become the lower bound of the
199 binary search range, and "-g" will never be seen. To resolve this
200 issue, opts.sh makes "-gen-decls" point, via the back_chain member,
201 to "-g" so that failed searches that end between "-gen-decls" and
202 the lexicographically subsequent switch know to go back and see if
203 "-g" causes a match (which it does in this example).
205 This search is done in such a way that the longest match for the
206 front end in question wins. If there is no match for the current
207 front end, the longest match for a different front end is returned
208 (or N_OPTS if none) and the caller emits an error message. */
209 static size_t
210 find_opt (const char *input, int lang_mask)
212 size_t mn, mx, md, opt_len;
213 size_t match_wrong_lang;
214 int comp;
216 mn = 0;
217 mx = cl_options_count;
219 /* Find mn such this lexicographical inequality holds:
220 cl_options[mn] <= input < cl_options[mn + 1]. */
221 while (mx - mn > 1)
223 md = (mn + mx) / 2;
224 opt_len = cl_options[md].opt_len;
225 comp = strncmp (input, cl_options[md].opt_text + 1, opt_len);
227 if (comp < 0)
228 mx = md;
229 else
230 mn = md;
233 /* This is the switch that is the best match but for a different
234 front end, or cl_options_count if there is no match at all. */
235 match_wrong_lang = cl_options_count;
237 /* Backtrace the chain of possible matches, returning the longest
238 one, if any, that fits best. With current GCC switches, this
239 loop executes at most twice. */
242 const struct cl_option *opt = &cl_options[mn];
244 /* Is this switch a prefix of the input? */
245 if (!strncmp (input, opt->opt_text + 1, opt->opt_len))
247 /* If language is OK, and the match is exact or the switch
248 takes a joined argument, return it. */
249 if ((opt->flags & lang_mask)
250 && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
251 return mn;
253 /* If we haven't remembered a prior match, remember this
254 one. Any prior match is necessarily better. */
255 if (match_wrong_lang == cl_options_count)
256 match_wrong_lang = mn;
259 /* Try the next possibility. This is cl_options_count if there
260 are no more. */
261 mn = opt->back_chain;
263 while (mn != cl_options_count);
265 /* Return the best wrong match, or cl_options_count if none. */
266 return match_wrong_lang;
269 /* If ARG is a non-negative integer made up solely of digits, return its
270 value, otherwise return -1. */
271 static int
272 integral_argument (const char *arg)
274 const char *p = arg;
276 while (*p && ISDIGIT (*p))
277 p++;
279 if (*p == '\0')
280 return atoi (arg);
282 return -1;
285 /* Return a malloced slash-separated list of languages in MASK. */
286 static char *
287 write_langs (unsigned int mask)
289 unsigned int n = 0, len = 0;
290 const char *lang_name;
291 char *result;
293 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
294 if (mask & (1U << n))
295 len += strlen (lang_name) + 1;
297 result = xmalloc (len);
298 len = 0;
299 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
300 if (mask & (1U << n))
302 if (len)
303 result[len++] = '/';
304 strcpy (result + len, lang_name);
305 len += strlen (lang_name);
308 result[len] = 0;
310 return result;
313 /* Complain that switch OPT_INDEX does not apply to this front end. */
314 static void
315 complain_wrong_lang (const char *text, const struct cl_option *option,
316 unsigned int lang_mask)
318 char *ok_langs, *bad_lang;
320 ok_langs = write_langs (option->flags);
321 bad_lang = write_langs (lang_mask);
323 /* Eventually this should become a hard error IMO. */
324 warning ("command line option \"%s\" is valid for %s but not for %s",
325 text, ok_langs, bad_lang);
327 free (ok_langs);
328 free (bad_lang);
331 /* Handle the switch beginning at ARGV for the language indicated by
332 LANG_MASK. Returns the number of switches consumed. */
333 static unsigned int
334 handle_option (const char **argv, unsigned int lang_mask)
336 size_t opt_index;
337 const char *opt, *arg = 0;
338 char *dup = 0;
339 int value = 1;
340 unsigned int result = 0;
341 const struct cl_option *option;
343 opt = argv[0];
345 /* Drop the "no-" from negative switches. */
346 if ((opt[1] == 'W' || opt[1] == 'f')
347 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
349 size_t len = strlen (opt) - 3;
351 dup = xmalloc (len + 1);
352 dup[0] = '-';
353 dup[1] = opt[1];
354 memcpy (dup + 2, opt + 5, len - 2 + 1);
355 opt = dup;
356 value = 0;
359 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
360 if (opt_index == cl_options_count)
361 goto done;
363 option = &cl_options[opt_index];
365 /* Reject negative form of switches that don't take negatives as
366 unrecognized. */
367 if (!value && (option->flags & CL_REJECT_NEGATIVE))
368 goto done;
370 /* We've recognized this switch. */
371 result = 1;
373 /* Sort out any argument the switch takes. */
374 if (option->flags & CL_JOINED)
376 /* Have arg point to the original switch. This is because
377 some code, such as disable_builtin_function, expects its
378 argument to be persistent until the program exits. */
379 arg = argv[0] + cl_options[opt_index].opt_len + 1;
380 if (!value)
381 arg += strlen ("no-");
383 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
385 if (option->flags & CL_SEPARATE)
387 arg = argv[1];
388 result = 2;
390 else
391 /* Missing argument. */
392 arg = NULL;
395 else if (option->flags & CL_SEPARATE)
397 arg = argv[1];
398 result = 2;
401 /* Now we've swallowed any potential argument, complain if this
402 is a switch for a different front end. */
403 if (!(option->flags & (lang_mask | CL_COMMON)))
405 complain_wrong_lang (argv[0], option, lang_mask);
406 goto done;
409 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
411 if (!(*lang_hooks.missing_argument) (opt, opt_index))
412 error ("missing argument to \"%s\"", opt);
413 goto done;
416 /* If the switch takes an integer, convert it. */
417 if (arg && (option->flags & CL_UINTEGER))
419 value = integral_argument (arg);
420 if (value == -1)
422 error ("argument to \"%s\" should be a non-negative integer",
423 option->opt_text);
424 goto done;
428 if (option->flags & lang_mask)
429 if ((*lang_hooks.handle_option) (opt_index, arg, value) == 0)
430 result = 0;
432 if (result && (option->flags & CL_COMMON))
433 if (common_handle_option (opt_index, arg, value) == 0)
434 result = 0;
436 done:
437 if (dup)
438 free (dup);
439 return result;
442 /* Decode and handle the vector of command line options. LANG_MASK
443 contains has a single bit set representing the current
444 language. */
445 static void
446 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
448 unsigned int n, i;
450 for (i = 1; i < argc; i += n)
452 const char *opt = argv[i];
454 /* Interpret "-" or a non-switch as a file name. */
455 if (opt[0] != '-' || opt[1] == '\0')
457 if (main_input_filename == NULL)
458 main_input_filename = opt;
459 add_input_filename (opt);
460 n = 1;
461 continue;
464 n = handle_option (argv + i, lang_mask);
466 if (!n)
468 n = 1;
469 error ("unrecognized command line option \"%s\"", opt);
474 /* Handle FILENAME from the command line. */
475 void
476 add_input_filename (const char *filename)
478 num_in_fnames++;
479 in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
480 in_fnames[num_in_fnames - 1] = filename;
483 /* Parse command line options and set default flag values. Do minimal
484 options processing. */
485 void
486 decode_options (unsigned int argc, const char **argv)
488 unsigned int i, lang_mask;
490 /* Perform language-specific options initialization. */
491 lang_mask = (*lang_hooks.init_options) (argc, argv);
493 lang_hooks.initialize_diagnostics (global_dc);
495 /* Scan to see what optimization level has been specified. That will
496 determine the default value of many flags. */
497 for (i = 1; i < argc; i++)
499 if (!strcmp (argv[i], "-O"))
501 optimize = 1;
502 optimize_size = 0;
504 else if (argv[i][0] == '-' && argv[i][1] == 'O')
506 /* Handle -Os, -O2, -O3, -O69, ... */
507 const char *p = &argv[i][2];
509 if ((p[0] == 's') && (p[1] == 0))
511 optimize_size = 1;
513 /* Optimizing for size forces optimize to be 2. */
514 optimize = 2;
516 else
518 const int optimize_val = read_integral_parameter (p, p - 2, -1);
519 if (optimize_val != -1)
521 optimize = optimize_val;
522 optimize_size = 0;
528 if (!optimize)
530 flag_merge_constants = 0;
533 if (optimize >= 1)
535 flag_defer_pop = 1;
536 flag_thread_jumps = 1;
537 #ifdef DELAY_SLOTS
538 flag_delayed_branch = 1;
539 #endif
540 #ifdef CAN_DEBUG_WITHOUT_FP
541 flag_omit_frame_pointer = 1;
542 #endif
543 flag_guess_branch_prob = 1;
544 flag_cprop_registers = 1;
545 flag_loop_optimize = 1;
546 flag_if_conversion = 1;
547 flag_if_conversion2 = 1;
550 if (optimize >= 2)
552 flag_crossjumping = 1;
553 flag_optimize_sibling_calls = 1;
554 flag_cse_follow_jumps = 1;
555 flag_cse_skip_blocks = 1;
556 flag_gcse = 1;
557 flag_expensive_optimizations = 1;
558 flag_strength_reduce = 1;
559 flag_rerun_cse_after_loop = 1;
560 flag_rerun_loop_opt = 1;
561 flag_caller_saves = 1;
562 flag_force_mem = 1;
563 flag_peephole2 = 1;
564 #ifdef INSN_SCHEDULING
565 flag_schedule_insns = 1;
566 flag_schedule_insns_after_reload = 1;
567 #endif
568 flag_regmove = 1;
569 flag_strict_aliasing = 1;
570 flag_delete_null_pointer_checks = 1;
571 flag_reorder_blocks = 1;
572 flag_reorder_functions = 1;
573 flag_unit_at_a_time = 1;
576 if (optimize >= 3)
578 flag_inline_functions = 1;
579 flag_rename_registers = 1;
580 flag_unswitch_loops = 1;
581 flag_web = 1;
584 if (optimize < 2 || optimize_size)
586 align_loops = 1;
587 align_jumps = 1;
588 align_labels = 1;
589 align_functions = 1;
591 /* Don't reorder blocks when optimizing for size because extra
592 jump insns may be created; also barrier may create extra padding.
594 More correctly we should have a block reordering mode that tried
595 to minimize the combined size of all the jumps. This would more
596 or less automatically remove extra jumps, but would also try to
597 use more short jumps instead of long jumps. */
598 flag_reorder_blocks = 0;
601 /* Initialize whether `char' is signed. */
602 flag_signed_char = DEFAULT_SIGNED_CHAR;
603 #ifdef DEFAULT_SHORT_ENUMS
604 /* Initialize how much space enums occupy, by default. */
605 flag_short_enums = DEFAULT_SHORT_ENUMS;
606 #endif
608 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
609 modify it. */
610 target_flags = 0;
611 set_target_switch ("");
613 /* Unwind tables are always present in an ABI-conformant IA-64
614 object file, so the default should be ON. */
615 #ifdef IA64_UNWIND_INFO
616 flag_unwind_tables = IA64_UNWIND_INFO;
617 #endif
619 #ifdef OPTIMIZATION_OPTIONS
620 /* Allow default optimizations to be specified on a per-machine basis. */
621 OPTIMIZATION_OPTIONS (optimize, optimize_size);
622 #endif
624 handle_options (argc, argv, lang_mask);
626 if (flag_pie)
627 flag_pic = flag_pie;
628 if (flag_pic && !flag_pie)
629 flag_shlib = 1;
631 if (flag_no_inline == 2)
632 flag_no_inline = 0;
633 else
634 flag_really_no_inline = flag_no_inline;
636 /* Set flag_no_inline before the post_options () hook. The C front
637 ends use it to determine tree inlining defaults. FIXME: such
638 code should be lang-independent when all front ends use tree
639 inlining, in which case it, and this condition, should be moved
640 to the top of process_options() instead. */
641 if (optimize == 0)
643 /* Inlining does not work if not optimizing,
644 so force it not to be done. */
645 flag_no_inline = 1;
646 warn_inline = 0;
648 /* The c_decode_option function and decode_option hook set
649 this to `2' if -Wall is used, so we can avoid giving out
650 lots of errors for people who don't realize what -Wall does. */
651 if (warn_uninitialized == 1)
652 warning ("-Wuninitialized is not supported without -O");
655 if (flag_really_no_inline == 2)
656 flag_really_no_inline = flag_no_inline;
659 /* Handle target- and language-independent options. Return zero to
660 generate an "unknown option" message. */
661 static int
662 common_handle_option (size_t scode, const char *arg,
663 int value ATTRIBUTE_UNUSED)
665 enum opt_code code = (enum opt_code) scode;
667 switch (code)
669 default:
670 abort ();
672 case OPT__help:
673 print_help ();
674 exit_after_options = true;
675 break;
677 case OPT__param:
678 handle_param (arg);
679 break;
681 case OPT__target_help:
682 display_target_options ();
683 exit_after_options = true;
684 break;
686 case OPT__version:
687 print_version (stderr, "");
688 exit_after_options = true;
689 break;
691 case OPT_G:
692 g_switch_value = value;
693 g_switch_set = true;
694 break;
696 case OPT_O:
697 case OPT_Os:
698 /* Currently handled in a prescan. */
699 break;
701 case OPT_W:
702 /* For backward compatibility, -W is the same as -Wextra. */
703 set_Wextra (value);
704 break;
706 case OPT_Waggregate_return:
707 warn_aggregate_return = value;
708 break;
710 case OPT_Wcast_align:
711 warn_cast_align = value;
712 break;
714 case OPT_Wdeprecated_declarations:
715 warn_deprecated_decl = value;
716 break;
718 case OPT_Wdisabled_optimization:
719 warn_disabled_optimization = value;
720 break;
722 case OPT_Werror:
723 warnings_are_errors = value;
724 break;
726 case OPT_Wextra:
727 set_Wextra (value);
728 break;
730 case OPT_Winline:
731 warn_inline = value;
732 break;
734 case OPT_Wlarger_than_:
735 larger_than_size = value;
736 warn_larger_than = value != -1;
737 break;
739 case OPT_Wmissing_noreturn:
740 warn_missing_noreturn = value;
741 break;
743 case OPT_Wpacked:
744 warn_packed = value;
745 break;
747 case OPT_Wpadded:
748 warn_padded = value;
749 break;
751 case OPT_Wshadow:
752 warn_shadow = value;
753 break;
755 case OPT_Wstrict_aliasing:
756 warn_strict_aliasing = value;
757 break;
759 case OPT_Wswitch:
760 warn_switch = value;
761 break;
763 case OPT_Wswitch_default:
764 warn_switch_default = value;
765 break;
767 case OPT_Wswitch_enum:
768 warn_switch_enum = value;
769 break;
771 case OPT_Wsystem_headers:
772 warn_system_headers = value;
773 break;
775 case OPT_Wuninitialized:
776 warn_uninitialized = value;
777 break;
779 case OPT_Wunreachable_code:
780 warn_notreached = value;
781 break;
783 case OPT_Wunused:
784 set_Wunused (value);
785 break;
787 case OPT_Wunused_function:
788 warn_unused_function = value;
789 break;
791 case OPT_Wunused_label:
792 warn_unused_label = value;
793 break;
795 case OPT_Wunused_parameter:
796 warn_unused_parameter = value;
797 break;
799 case OPT_Wunused_value:
800 warn_unused_value = value;
801 break;
803 case OPT_Wunused_variable:
804 warn_unused_variable = value;
805 break;
807 case OPT_aux_info:
808 case OPT_aux_info_:
809 aux_info_file_name = arg;
810 flag_gen_aux_info = 1;
811 break;
813 case OPT_auxbase:
814 aux_base_name = arg;
815 break;
817 case OPT_auxbase_strip:
819 char *tmp = xstrdup (arg);
820 strip_off_ending (tmp, strlen (tmp));
821 if (tmp[0])
822 aux_base_name = tmp;
824 break;
826 case OPT_d:
827 decode_d_option (arg);
828 break;
830 case OPT_dumpbase:
831 dump_base_name = arg;
832 break;
834 case OPT_fPIC:
835 flag_pic = value + value;
836 break;
838 case OPT_fPIE:
839 flag_pie = value + value;
840 break;
842 case OPT_fabi_version_:
843 flag_abi_version = value;
844 break;
846 case OPT_falign_functions:
847 align_functions = !value;
848 break;
850 case OPT_falign_functions_:
851 align_functions = value;
852 break;
854 case OPT_falign_jumps:
855 align_jumps = !value;
856 break;
858 case OPT_falign_jumps_:
859 align_jumps = value;
860 break;
862 case OPT_falign_labels:
863 align_labels = !value;
864 break;
866 case OPT_falign_labels_:
867 align_labels = value;
868 break;
870 case OPT_falign_loops:
871 align_loops = !value;
872 break;
874 case OPT_falign_loops_:
875 align_loops = value;
876 break;
878 case OPT_fargument_alias:
879 flag_argument_noalias = !value;
880 break;
882 case OPT_fargument_noalias:
883 flag_argument_noalias = value;
884 break;
886 case OPT_fargument_noalias_global:
887 flag_argument_noalias = value + value;
888 break;
890 case OPT_fasynchronous_unwind_tables:
891 flag_asynchronous_unwind_tables = value;
892 break;
894 case OPT_fbounds_check:
895 flag_bounds_check = value;
896 break;
898 case OPT_fbranch_count_reg:
899 flag_branch_on_count_reg = value;
900 break;
902 case OPT_fbranch_probabilities:
903 flag_branch_probabilities_set = true;
904 flag_branch_probabilities = value;
905 break;
907 case OPT_fbranch_target_load_optimize:
908 flag_branch_target_load_optimize = value;
909 break;
911 case OPT_fbranch_target_load_optimize2:
912 flag_branch_target_load_optimize2 = value;
913 break;
915 case OPT_fcall_used_:
916 fix_register (arg, 0, 1);
917 break;
919 case OPT_fcall_saved_:
920 fix_register (arg, 0, 0);
921 break;
923 case OPT_fcaller_saves:
924 flag_caller_saves = value;
925 break;
927 case OPT_fcommon:
928 flag_no_common = !value;
929 break;
931 case OPT_fcprop_registers:
932 flag_cprop_registers = value;
933 break;
935 case OPT_fcrossjumping:
936 flag_crossjumping = value;
937 break;
939 case OPT_fcse_follow_jumps:
940 flag_cse_follow_jumps = value;
941 break;
943 case OPT_fcse_skip_blocks:
944 flag_cse_skip_blocks = value;
945 break;
947 case OPT_fdata_sections:
948 flag_data_sections = value;
949 break;
951 case OPT_fdefer_pop:
952 flag_defer_pop = value;
953 break;
955 case OPT_fdelayed_branch:
956 flag_delayed_branch = value;
957 break;
959 case OPT_fdelete_null_pointer_checks:
960 flag_delete_null_pointer_checks = value;
961 break;
963 case OPT_fdiagnostics_show_location_:
964 if (!strcmp (arg, "once"))
965 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
966 else if (!strcmp (arg, "every-line"))
967 diagnostic_prefixing_rule (global_dc)
968 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
969 else
970 return 0;
971 break;
973 case OPT_fdump_unnumbered:
974 flag_dump_unnumbered = value;
975 break;
977 case OPT_feliminate_dwarf2_dups:
978 flag_eliminate_dwarf2_dups = value;
979 break;
981 case OPT_feliminate_unused_debug_types:
982 flag_eliminate_unused_debug_types = value;
983 break;
985 case OPT_feliminate_unused_debug_symbols:
986 flag_debug_only_used_symbols = value;
987 break;
989 case OPT_fexceptions:
990 flag_exceptions = value;
991 break;
993 case OPT_fexpensive_optimizations:
994 flag_expensive_optimizations = value;
995 break;
997 case OPT_ffast_math:
998 set_fast_math_flags (value);
999 break;
1001 case OPT_ffinite_math_only:
1002 flag_finite_math_only = value;
1003 break;
1005 case OPT_ffixed_:
1006 fix_register (arg, 1, 1);
1007 break;
1009 case OPT_ffunction_cse:
1010 flag_no_function_cse = !value;
1011 break;
1013 case OPT_ffloat_store:
1014 flag_float_store = value;
1015 break;
1017 case OPT_fforce_addr:
1018 flag_force_addr = value;
1019 break;
1021 case OPT_fforce_mem:
1022 flag_force_mem = value;
1023 break;
1025 case OPT_ffunction_sections:
1026 flag_function_sections = value;
1027 break;
1029 case OPT_fgcse:
1030 flag_gcse = value;
1031 break;
1033 case OPT_fgcse_lm:
1034 flag_gcse_lm = value;
1035 break;
1037 case OPT_fgcse_sm:
1038 flag_gcse_sm = value;
1039 break;
1041 case OPT_fgcse_las:
1042 flag_gcse_las = value;
1043 break;
1045 case OPT_fguess_branch_probability:
1046 flag_guess_branch_prob = value;
1047 break;
1049 case OPT_fident:
1050 flag_no_ident = !value;
1051 break;
1053 case OPT_fif_conversion:
1054 flag_if_conversion = value;
1055 break;
1057 case OPT_fif_conversion2:
1058 flag_if_conversion2 = value;
1059 break;
1061 case OPT_finhibit_size_directive:
1062 flag_inhibit_size_directive = value;
1063 break;
1065 case OPT_finline:
1066 flag_no_inline = !value;
1067 break;
1069 case OPT_finline_functions:
1070 flag_inline_functions = value;
1071 break;
1073 case OPT_finline_limit_:
1074 case OPT_finline_limit_eq:
1075 set_param_value ("max-inline-insns-single", value / 2);
1076 set_param_value ("max-inline-insns-auto", value / 2);
1077 set_param_value ("max-inline-insns-rtl", value);
1078 break;
1080 case OPT_finstrument_functions:
1081 flag_instrument_function_entry_exit = value;
1082 break;
1084 case OPT_fkeep_inline_functions:
1085 flag_keep_inline_functions =value;
1086 break;
1088 case OPT_fkeep_static_consts:
1089 flag_keep_static_consts = value;
1090 break;
1092 case OPT_fleading_underscore:
1093 flag_leading_underscore = value;
1094 break;
1096 case OPT_floop_optimize:
1097 flag_loop_optimize = value;
1098 break;
1100 case OPT_fmath_errno:
1101 flag_errno_math = value;
1102 break;
1104 case OPT_fmem_report:
1105 mem_report = value;
1106 break;
1108 case OPT_fmerge_all_constants:
1109 flag_merge_constants = value + value;
1110 break;
1112 case OPT_fmerge_constants:
1113 flag_merge_constants = value;
1114 break;
1116 case OPT_fmessage_length_:
1117 pp_set_line_maximum_length (global_dc->printer, value);
1118 break;
1120 case OPT_fmove_all_movables:
1121 flag_move_all_movables = value;
1122 break;
1124 case OPT_fnew_ra:
1125 flag_new_regalloc = value;
1126 break;
1128 case OPT_fnon_call_exceptions:
1129 flag_non_call_exceptions = value;
1130 break;
1132 case OPT_fold_unroll_all_loops:
1133 flag_old_unroll_all_loops = value;
1134 break;
1136 case OPT_fold_unroll_loops:
1137 flag_old_unroll_loops = value;
1138 break;
1140 case OPT_fomit_frame_pointer:
1141 flag_omit_frame_pointer = value;
1142 break;
1144 case OPT_foptimize_register_move:
1145 flag_regmove = value;
1146 break;
1148 case OPT_foptimize_sibling_calls:
1149 flag_optimize_sibling_calls = value;
1150 break;
1152 case OPT_fpack_struct:
1153 flag_pack_struct = value;
1154 break;
1156 case OPT_fpeel_loops:
1157 flag_peel_loops_set = true;
1158 flag_peel_loops = value;
1159 break;
1161 case OPT_fpcc_struct_return:
1162 flag_pcc_struct_return = value;
1163 break;
1165 case OPT_fpeephole:
1166 flag_no_peephole = !value;
1167 break;
1169 case OPT_fpeephole2:
1170 flag_peephole2 = value;
1171 break;
1173 case OPT_fpic:
1174 flag_pic = value;
1175 break;
1177 case OPT_fpie:
1178 flag_pie = value;
1179 break;
1181 case OPT_fprefetch_loop_arrays:
1182 flag_prefetch_loop_arrays = value;
1183 break;
1185 case OPT_fprofile:
1186 profile_flag = value;
1187 break;
1189 case OPT_fprofile_arcs:
1190 profile_arc_flag_set = true;
1191 profile_arc_flag = value;
1192 break;
1194 case OPT_fprofile_use:
1195 if (!flag_branch_probabilities_set)
1196 flag_branch_probabilities = value;
1197 if (!flag_profile_values_set)
1198 flag_profile_values = value;
1199 if (!flag_unroll_loops_set)
1200 flag_unroll_loops = value;
1201 if (!flag_peel_loops_set)
1202 flag_peel_loops = value;
1203 if (!flag_tracer_set)
1204 flag_tracer = value;
1205 if (!flag_value_profile_transformations_set)
1206 flag_value_profile_transformations = value;
1207 break;
1209 case OPT_fprofile_generate:
1210 if (!profile_arc_flag_set)
1211 profile_arc_flag = value;
1212 if (!flag_profile_values_set)
1213 flag_profile_values = value;
1214 if (!flag_value_profile_transformations_set)
1215 flag_value_profile_transformations = value;
1216 break;
1218 case OPT_fprofile_values:
1219 flag_profile_values_set = true;
1220 flag_profile_values = value;
1221 break;
1223 case OPT_fvisibility_:
1225 if (!strcmp(arg, "default"))
1226 default_visibility = VISIBILITY_DEFAULT;
1227 else if (!strcmp(arg, "internal"))
1228 default_visibility = VISIBILITY_INTERNAL;
1229 else if (!strcmp(arg, "hidden"))
1230 default_visibility = VISIBILITY_HIDDEN;
1231 else if (!strcmp(arg, "protected"))
1232 default_visibility = VISIBILITY_PROTECTED;
1233 else
1234 error ("unrecognised visibility value \"%s\"", arg);
1236 break;
1238 case OPT_fvpt:
1239 flag_value_profile_transformations_set = value;
1240 flag_value_profile_transformations = value;
1241 break;
1243 case OPT_frandom_seed:
1244 /* The real switch is -fno-random-seed. */
1245 if (value)
1246 return 0;
1247 flag_random_seed = NULL;
1248 break;
1250 case OPT_frandom_seed_:
1251 flag_random_seed = arg;
1252 break;
1254 case OPT_freduce_all_givs:
1255 flag_reduce_all_givs = value;
1256 break;
1258 case OPT_freg_struct_return:
1259 flag_pcc_struct_return = !value;
1260 break;
1262 case OPT_fregmove:
1263 flag_regmove = value;
1264 break;
1266 case OPT_frename_registers:
1267 flag_rename_registers = value;
1268 break;
1270 case OPT_freorder_blocks:
1271 flag_reorder_blocks = value;
1272 break;
1274 case OPT_freorder_functions:
1275 flag_reorder_functions = value;
1276 break;
1278 case OPT_frerun_cse_after_loop:
1279 flag_rerun_cse_after_loop = value;
1280 break;
1282 case OPT_frerun_loop_opt:
1283 flag_rerun_loop_opt = value;
1284 break;
1286 case OPT_frounding_math:
1287 flag_rounding_math = value;
1288 break;
1290 case OPT_fsched_interblock:
1291 flag_schedule_interblock = value;
1292 break;
1294 case OPT_fsched_spec:
1295 flag_schedule_speculative = value;
1296 break;
1298 case OPT_fsched_spec_load:
1299 flag_schedule_speculative_load = value;
1300 break;
1302 case OPT_fsched_spec_load_dangerous:
1303 flag_schedule_speculative_load_dangerous = value;
1304 break;
1306 case OPT_fsched_verbose_:
1307 #ifdef INSN_SCHEDULING
1308 fix_sched_param ("verbose", arg);
1309 break;
1310 #else
1311 return 0;
1312 #endif
1314 case OPT_fsched2_use_superblocks:
1315 flag_sched2_use_superblocks = value;
1316 break;
1318 case OPT_fsched2_use_traces:
1319 flag_sched2_use_traces = value;
1320 break;
1322 case OPT_fschedule_insns:
1323 flag_schedule_insns = value;
1324 break;
1326 case OPT_fschedule_insns2:
1327 flag_schedule_insns_after_reload = value;
1328 break;
1330 case OPT_fsched_stalled_insns:
1331 flag_sched_stalled_insns = value;
1332 break;
1334 case OPT_fsched_stalled_insns_:
1335 flag_sched_stalled_insns = value;
1336 if (flag_sched_stalled_insns == 0)
1337 flag_sched_stalled_insns = -1;
1338 break;
1340 case OPT_fsched_stalled_insns_dep:
1341 flag_sched_stalled_insns_dep = 1;
1342 break;
1344 case OPT_fsched_stalled_insns_dep_:
1345 flag_sched_stalled_insns_dep = value;
1346 break;
1348 case OPT_fshared_data:
1349 flag_shared_data = value;
1350 break;
1352 case OPT_fsignaling_nans:
1353 flag_signaling_nans = value;
1354 break;
1356 case OPT_fsingle_precision_constant:
1357 flag_single_precision_constant = value;
1358 break;
1360 case OPT_fstack_check:
1361 flag_stack_check = value;
1362 break;
1364 case OPT_fstack_limit:
1365 /* The real switch is -fno-stack-limit. */
1366 if (value)
1367 return 0;
1368 stack_limit_rtx = NULL_RTX;
1369 break;
1371 case OPT_fstack_limit_register_:
1373 int reg = decode_reg_name (arg);
1374 if (reg < 0)
1375 error ("unrecognized register name \"%s\"", arg);
1376 else
1377 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1379 break;
1381 case OPT_fstack_limit_symbol_:
1382 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1383 break;
1385 case OPT_fstrength_reduce:
1386 flag_strength_reduce = value;
1387 break;
1389 case OPT_fstrict_aliasing:
1390 flag_strict_aliasing = value;
1391 break;
1393 case OPT_fsyntax_only:
1394 flag_syntax_only = value;
1395 break;
1397 case OPT_ftest_coverage:
1398 flag_test_coverage = value;
1399 break;
1401 case OPT_fthread_jumps:
1402 flag_thread_jumps = value;
1403 break;
1405 case OPT_ftime_report:
1406 time_report = value;
1407 break;
1409 case OPT_ftls_model_:
1410 if (!strcmp (arg, "global-dynamic"))
1411 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1412 else if (!strcmp (arg, "local-dynamic"))
1413 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1414 else if (!strcmp (arg, "initial-exec"))
1415 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1416 else if (!strcmp (arg, "local-exec"))
1417 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1418 else
1419 warning ("unknown tls-model \"%s\"", arg);
1420 break;
1422 case OPT_ftracer:
1423 flag_tracer_set = true;
1424 flag_tracer = value;
1425 break;
1427 case OPT_ftrapping_math:
1428 flag_trapping_math = value;
1429 break;
1431 case OPT_ftrapv:
1432 flag_trapv = value;
1433 break;
1435 case OPT_funit_at_a_time:
1436 flag_unit_at_a_time = value;
1437 break;
1439 case OPT_funroll_all_loops:
1440 flag_unroll_all_loops = value;
1441 break;
1443 case OPT_funroll_loops:
1444 flag_unroll_loops_set = true;
1445 flag_unroll_loops = value;
1446 break;
1448 case OPT_funsafe_math_optimizations:
1449 flag_unsafe_math_optimizations = value;
1450 break;
1452 case OPT_funswitch_loops:
1453 flag_unswitch_loops = value;
1454 break;
1456 case OPT_funwind_tables:
1457 flag_unwind_tables = value;
1458 break;
1460 case OPT_fvar_tracking:
1461 flag_var_tracking = value;
1462 break;
1464 case OPT_fverbose_asm:
1465 flag_verbose_asm = value;
1466 break;
1468 case OPT_fweb:
1469 flag_web = value;
1470 break;
1472 case OPT_fwrapv:
1473 flag_wrapv = value;
1474 break;
1476 case OPT_fwritable_strings:
1477 flag_writable_strings = value;
1478 if (flag_writable_strings)
1479 inform ("-fwritable-strings is deprecated; "
1480 "see documentation for details");
1481 break;
1483 case OPT_fzero_initialized_in_bss:
1484 flag_zero_initialized_in_bss = value;
1485 break;
1487 case OPT_g:
1488 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
1489 break;
1491 case OPT_gcoff:
1492 set_debug_level (SDB_DEBUG, false, arg);
1493 break;
1495 case OPT_gdwarf_2:
1496 set_debug_level (DWARF2_DEBUG, false, arg);
1497 break;
1499 case OPT_ggdb:
1500 set_debug_level (NO_DEBUG, 2, arg);
1501 break;
1503 case OPT_gstabs:
1504 case OPT_gstabs_:
1505 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
1506 break;
1508 case OPT_gvms:
1509 set_debug_level (VMS_DEBUG, false, arg);
1510 break;
1512 case OPT_gxcoff:
1513 case OPT_gxcoff_:
1514 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
1515 break;
1517 case OPT_m:
1518 set_target_switch (arg);
1519 break;
1521 case OPT_o:
1522 asm_file_name = arg;
1523 break;
1525 case OPT_p:
1526 profile_flag = 1;
1527 break;
1529 case OPT_pedantic:
1530 pedantic = 1;
1531 break;
1533 case OPT_pedantic_errors:
1534 flag_pedantic_errors = pedantic = 1;
1535 break;
1537 case OPT_quiet:
1538 quiet_flag = 1;
1539 break;
1541 case OPT_version:
1542 version_flag = 1;
1543 break;
1545 case OPT_w:
1546 inhibit_warnings = true;
1547 break;
1550 return 1;
1553 /* Handle --param NAME=VALUE. */
1554 static void
1555 handle_param (const char *carg)
1557 char *equal, *arg;
1558 int value;
1560 arg = xstrdup (carg);
1561 equal = strchr (arg, '=');
1562 if (!equal)
1563 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1564 else
1566 value = integral_argument (equal + 1);
1567 if (value == -1)
1568 error ("invalid --param value `%s'", equal + 1);
1569 else
1571 *equal = '\0';
1572 set_param_value (arg, value);
1576 free (arg);
1579 /* Handle -W and -Wextra. */
1580 static void
1581 set_Wextra (int setting)
1583 extra_warnings = setting;
1584 warn_unused_value = setting;
1585 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1587 /* We save the value of warn_uninitialized, since if they put
1588 -Wuninitialized on the command line, we need to generate a
1589 warning about not using it without also specifying -O. */
1590 if (setting == 0)
1591 warn_uninitialized = 0;
1592 else if (warn_uninitialized != 1)
1593 warn_uninitialized = 2;
1596 /* Initialize unused warning flags. */
1597 void
1598 set_Wunused (int setting)
1600 warn_unused_function = setting;
1601 warn_unused_label = setting;
1602 /* Unused function parameter warnings are reported when either
1603 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1604 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1605 otherwise set maybe_warn_extra_parameter, which will be picked up
1606 by set_Wextra. */
1607 maybe_warn_unused_parameter = setting;
1608 warn_unused_parameter = (setting && extra_warnings);
1609 warn_unused_variable = setting;
1610 warn_unused_value = setting;
1613 /* The following routines are useful in setting all the flags that
1614 -ffast-math and -fno-fast-math imply. */
1615 void
1616 set_fast_math_flags (int set)
1618 flag_trapping_math = !set;
1619 flag_unsafe_math_optimizations = set;
1620 flag_finite_math_only = set;
1621 flag_errno_math = !set;
1622 if (set)
1624 flag_signaling_nans = 0;
1625 flag_rounding_math = 0;
1629 /* Return true iff flags are set as if -ffast-math. */
1630 bool
1631 fast_math_flags_set_p (void)
1633 return (!flag_trapping_math
1634 && flag_unsafe_math_optimizations
1635 && flag_finite_math_only
1636 && !flag_errno_math);
1639 /* Handle a debug output -g switch. EXTENDED is true or false to support
1640 extended output (2 is special and means "-ggdb" was given). */
1641 static void
1642 set_debug_level (enum debug_info_type type, int extended, const char *arg)
1644 static bool type_explicit;
1646 use_gnu_debug_info_extensions = extended;
1648 if (type == NO_DEBUG)
1650 if (write_symbols == NO_DEBUG)
1652 write_symbols = PREFERRED_DEBUGGING_TYPE;
1654 if (extended == 2)
1656 #ifdef DWARF2_DEBUGGING_INFO
1657 write_symbols = DWARF2_DEBUG;
1658 #elif defined DBX_DEBUGGING_INFO
1659 write_symbols = DBX_DEBUG;
1660 #endif
1663 if (write_symbols == NO_DEBUG)
1664 warning ("target system does not support debug output");
1667 else
1669 /* Does it conflict with an already selected type? */
1670 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1671 error ("debug format \"%s\" conflicts with prior selection",
1672 debug_type_names[type]);
1673 write_symbols = type;
1674 type_explicit = true;
1677 /* A debug flag without a level defaults to level 2. */
1678 if (*arg == '\0')
1680 if (!debug_info_level)
1681 debug_info_level = 2;
1683 else
1685 debug_info_level = integral_argument (arg);
1686 if (debug_info_level == (unsigned int) -1)
1687 error ("unrecognised debug output level \"%s\"", arg);
1688 else if (debug_info_level > 3)
1689 error ("debug output level %s is too high", arg);
1693 /* Output --help text. */
1694 static void
1695 print_help (void)
1697 size_t i;
1698 const char *p;
1700 GET_ENVIRONMENT (p, "COLUMNS");
1701 if (p)
1703 int value = atoi (p);
1704 if (value > 0)
1705 columns = value;
1708 puts (_("The following options are language-independent:\n"));
1710 print_filtered_help (CL_COMMON);
1711 print_param_help ();
1713 for (i = 0; lang_names[i]; i++)
1715 printf (_("The %s front end recognizes the following options:\n\n"),
1716 lang_names[i]);
1717 print_filtered_help (1U << i);
1720 display_target_options ();
1723 /* Print the help for --param. */
1724 static void
1725 print_param_help (void)
1727 size_t i;
1729 puts (_("The --param option recognizes the following as parameters:\n"));
1731 for (i = 0; i < LAST_PARAM; i++)
1733 const char *help = compiler_params[i].help;
1734 const char *param = compiler_params[i].option;
1736 if (help == NULL || *help == '\0')
1737 help = undocumented_msg;
1739 /* Get the translation. */
1740 help = _(help);
1742 wrap_help (help, param, strlen (param));
1745 putchar ('\n');
1748 /* Print help for a specific front-end, etc. */
1749 static void
1750 print_filtered_help (unsigned int flag)
1752 unsigned int i, len, filter, indent = 0;
1753 bool duplicates = false;
1754 const char *help, *opt, *tab;
1755 static char *printed;
1757 if (flag == CL_COMMON)
1759 filter = flag;
1760 if (!printed)
1761 printed = xmalloc (cl_options_count);
1762 memset (printed, 0, cl_options_count);
1764 else
1766 /* Don't print COMMON options twice. */
1767 filter = flag | CL_COMMON;
1769 for (i = 0; i < cl_options_count; i++)
1771 if ((cl_options[i].flags & filter) != flag)
1772 continue;
1774 /* Skip help for internal switches. */
1775 if (cl_options[i].flags & CL_UNDOCUMENTED)
1776 continue;
1778 /* Skip switches that have already been printed, mark them to be
1779 listed later. */
1780 if (printed[i])
1782 duplicates = true;
1783 indent = print_switch (cl_options[i].opt_text, indent);
1787 if (duplicates)
1789 putchar ('\n');
1790 putchar ('\n');
1794 for (i = 0; i < cl_options_count; i++)
1796 if ((cl_options[i].flags & filter) != flag)
1797 continue;
1799 /* Skip help for internal switches. */
1800 if (cl_options[i].flags & CL_UNDOCUMENTED)
1801 continue;
1803 /* Skip switches that have already been printed. */
1804 if (printed[i])
1805 continue;
1807 printed[i] = true;
1809 help = cl_options[i].help;
1810 if (!help)
1811 help = undocumented_msg;
1813 /* Get the translation. */
1814 help = _(help);
1816 tab = strchr (help, '\t');
1817 if (tab)
1819 len = tab - help;
1820 opt = help;
1821 help = tab + 1;
1823 else
1825 opt = cl_options[i].opt_text;
1826 len = strlen (opt);
1829 wrap_help (help, opt, len);
1832 putchar ('\n');
1835 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1836 word-wrapped HELP in a second column. */
1837 static unsigned int
1838 print_switch (const char *text, unsigned int indent)
1840 unsigned int len = strlen (text) + 1; /* trailing comma */
1842 if (indent)
1844 putchar (',');
1845 if (indent + len > columns)
1847 putchar ('\n');
1848 putchar (' ');
1849 indent = 1;
1852 else
1853 putchar (' ');
1855 putchar (' ');
1856 fputs (text, stdout);
1858 return indent + len + 1;
1861 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1862 word-wrapped HELP in a second column. */
1863 static void
1864 wrap_help (const char *help, const char *item, unsigned int item_width)
1866 unsigned int col_width = 27;
1867 unsigned int remaining, room, len;
1869 remaining = strlen (help);
1873 room = columns - 3 - MAX (col_width, item_width);
1874 if (room > columns)
1875 room = 0;
1876 len = remaining;
1878 if (room < len)
1880 unsigned int i;
1882 for (i = 0; help[i]; i++)
1884 if (i >= room && len != remaining)
1885 break;
1886 if (help[i] == ' ')
1887 len = i;
1888 else if ((help[i] == '-' || help[i] == '/')
1889 && help[i + 1] != ' '
1890 && i > 0 && ISALPHA (help[i - 1]))
1891 len = i + 1;
1895 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1896 item_width = 0;
1897 while (help[len] == ' ')
1898 len++;
1899 help += len;
1900 remaining -= len;
1902 while (remaining);