diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-07-08 05:25:39 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-07-08 05:25:39 +0000 |
commit | 53b8e5c1608b8311cb12839a51a6c8fcf24fb4b7 (patch) | |
tree | 795cec94203bc9cbd2c0c078978129faa9d33ea5 /gcc/opts.c | |
parent | 2ef278d887f0a3dea06a183715933fa3bb0a1aa5 (diff) | |
download | gcc-53b8e5c1608b8311cb12839a51a6c8fcf24fb4b7.tar.gz |
* Makefile.in: Update.
* c-opts.c (c_common_handle_option): opt_text now contains the '-'.
* c.opt: Update documentation.
* common.opt: Add some help text.
* opts.c: Include intl.h.
(wrap_help, print_help): New.
(find_opt, handle_option, common_handle_option): opt_text now
contains the '-'. Use print_help to output help.
* opts.h (struct cl_option): New member "help".
* opts.sh: Update to handle help text output and to prepend
options with '-'.
* toplev.c (display_help): Remove some help text.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69068 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/opts.c')
-rw-r--r-- | gcc/opts.c | 91 |
1 files changed, 87 insertions, 4 deletions
diff --git a/gcc/opts.c b/gcc/opts.c index 85c759dbdab..ec8af200406 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -21,6 +21,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "config.h" #include "system.h" +#include "intl.h" #include "coretypes.h" #include "tm.h" #include "tree.h" @@ -136,6 +137,8 @@ static char *write_langs (unsigned int lang_mask); static void complain_wrong_lang (const char *, const struct cl_option *, unsigned int lang_mask); static void handle_options (unsigned int, const char **, unsigned int); +static void wrap_help (const char *help, const char *item, size_t item_width); +static void print_help (void); /* Perform a binary search to find which option the command-line INPUT matches. Returns its index in the option array, and N_OPTS @@ -177,7 +180,7 @@ find_opt (const char *input, int lang_mask) { md = (mn + mx) / 2; opt_len = cl_options[md].opt_len; - comp = strncmp (input, cl_options[md].opt_text, opt_len); + comp = strncmp (input, cl_options[md].opt_text + 1, opt_len); if (comp < 0) mx = md; @@ -197,7 +200,7 @@ find_opt (const char *input, int lang_mask) const struct cl_option *opt = &cl_options[mn]; /* Is this switch a prefix of the input? */ - if (!strncmp (input, opt->opt_text, opt->opt_len)) + if (!strncmp (input, opt->opt_text + 1, opt->opt_len)) { /* If language is OK, and the match is exact or the switch takes a joined argument, return it. */ @@ -374,7 +377,7 @@ handle_option (const char **argv, unsigned int lang_mask) value = integral_argument (arg); if (value == -1) { - error ("argument to \"-%s\" should be a non-negative integer", + error ("argument to \"%s\" should be a non-negative integer", option->opt_text); goto done; } @@ -612,7 +615,7 @@ common_handle_option (size_t scode, const char *arg, abort (); case OPT__help: - display_help (); + print_help (); exit_after_options = true; break; @@ -1477,3 +1480,83 @@ fast_math_flags_set_p (void) && flag_finite_math_only && !flag_errno_math); } + +/* Output --help text. */ +static void +print_help (void) +{ + size_t i, len; + + printf (_("\nThe following options are language-independent:\n")); + + for (i = 0; i < cl_options_count; i++) + { + const char *help = cl_options[i].help; + const char *opt, *tab; + + /* During transition, ignore switches with no help. */ + if (!help) + continue; + + /* Get the translation. */ + help = _(help); + + tab = strchr (help, '\t'); + if (tab) + { + len = tab - help; + opt = help; + help = tab + 1; + } + else + { + opt = cl_options[i].opt_text; + len = strlen (opt); + } + + wrap_help (help, opt, len); + } + + puts ( "\n" ); + display_help (); +} + +/* Output ITEM, of length ITEM_WIDTH, in the left column, followed by + word-wrapped HELP in a second column. */ +static void +wrap_help (const char *help, const char *item, size_t item_width) +{ + const size_t columns = 80, col_width = 27; + size_t remaining, room, len; + + remaining = strlen (help); + + do + { + room = columns - 3 - MAX (col_width, item_width); + len = remaining; + + if (room < len) + { + size_t i; + + for (i = 0; help[i]; i++) + { + if (i >= room && len != remaining) + break; + if (help[i] == ' ') + len = i; + else if (help[i] == '-') + len = i + 1; + } + } + + printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help); + item_width = 0; + while (help[len] == ' ') + len++; + help += len; + remaining -= len; + } + while (remaining); +} |