diff options
author | espindola <espindola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-04-16 14:31:45 +0000 |
---|---|---|
committer | espindola <espindola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-04-16 14:31:45 +0000 |
commit | 2dfeb300f788760c436633d99e144ab97192d63c (patch) | |
tree | c6fbd7f9013fa3335143a10692c790200c87a198 /gcc/plugin.c | |
parent | 0b35ccd7157213cf19130941a2644ed76ab4304b (diff) | |
download | gcc-2dfeb300f788760c436633d99e144ab97192d63c.tar.gz |
2009-04-16 Rafael Avila de Espindola <espindola@google.com>
* common.opt (fhelp): Add Var(help_flag).
* gcc-plugin.h (plugin_info): Add help.
* plugin.c (plugin_name_args): Add help.
(register_plugin_info): Set plugin->help.
(print_help_one_plugin): New.
(print_plugins_help): New.
* plugin.h (print_plugins_help): New.
* toplev.c (toplev_main): Call print_plugins_help if needed.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146195 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/plugin.c')
-rw-r--r-- | gcc/plugin.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/gcc/plugin.c b/gcc/plugin.c index 95297a7d395..4d4addd3bd8 100644 --- a/gcc/plugin.c +++ b/gcc/plugin.c @@ -61,6 +61,7 @@ struct plugin_name_args int argc; struct plugin_argument *argv; const char *version; + const char *help; }; /* Hash table for the plugin_name_args objects created during command-line @@ -461,6 +462,7 @@ register_plugin_info (const char* name, struct plugin_info *info) void **slot = htab_find_slot (plugin_name_args_tab, name, NO_INSERT); struct plugin_name_args *plugin = (struct plugin_name_args *) *slot; plugin->version = info->version; + plugin->help = info->help; } /* Called from the plugin's initialization code. Register a single callback. @@ -708,6 +710,51 @@ print_plugins_versions (FILE *file, const char *indent) htab_traverse_noresize (plugin_name_args_tab, print_version_one_plugin, &opt); } +/* Print help for one plugin. SLOT is the hash table slot. DATA is the + argument to htab_traverse_noresize. */ + +static int +print_help_one_plugin (void **slot, void *data) +{ + struct print_options *opt = (struct print_options *) data; + struct plugin_name_args *plugin = (struct plugin_name_args *) *slot; + const char *help = plugin->help ? plugin->help : "No help available ."; + + char *dup = xstrdup (help); + char *p, *nl; + fprintf (opt->file, " %s%s:\n", opt->indent, plugin->base_name); + + for (p = nl = dup; nl; p = nl) + { + nl = strchr (nl, '\n'); + if (nl) + { + *nl = '\0'; + nl++; + } + fprintf (opt->file, " %s %s\n", opt->indent, p); + } + + free (dup); + return 1; +} + +/* Print help for each plugin. The output goes to FILE and every line starts + with INDENT. */ + +void +print_plugins_help (FILE *file, const char *indent) +{ + struct print_options opt; + opt.file = file; + opt.indent = indent; + if (!plugin_name_args_tab || htab_elements (plugin_name_args_tab) == 0) + return; + + fprintf (file, "%sHelp for the loaded plugins:\n", indent); + htab_traverse_noresize (plugin_name_args_tab, print_help_one_plugin, &opt); +} + /* Return true if plugins have been loaded. */ |