From 48d4117789e92489b9a3c6f3456b0770b3fdb290 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 28 Jan 2017 13:23:40 +0000 Subject: [PATCH] fish: Handle changed type of 'len' parameter in gperf 3.1 (RHBZ#1416941). Commit 004de6cf45cfe66ca166cbdcb1c3125a2a81eb31 was not sufficient to solve this problem. We are also using gperf in guestfish. Rewrite the code in the same way to avoid having to prototype the hash function. --- fish/Makefile.am | 7 ++++ fish/cmds-gperf.h | 2 - generator/fish.ml | 99 +++++++++++++++++++++++++---------------------- 3 files changed, 59 insertions(+), 49 deletions(-) diff --git a/fish/Makefile.am b/fish/Makefile.am index 38409cb8a..fa345d611 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -106,7 +106,14 @@ librc_protocol_la_CFLAGS = -Wall -Wno-unused -fno-strict-aliasing # Build the command lookup perfect hash code. The generated code has # lots of warnings so we must compile it in a separate mini-library. libcmds_la_SOURCES = cmds-gperf.c +libcmds_la_CPPFLAGS = \ + -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ + -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(srcdir)/../gnulib/lib -I../gnulib/lib libcmds_la_CFLAGS = +libcmds_la_LIBADD = \ + $(top_builddir)/common/utils/libutils.la \ + $(LTLIBINTL) cmds-gperf.c: cmds-gperf.gperf rm -f $@ diff --git a/fish/cmds-gperf.h b/fish/cmds-gperf.h index bcb3b5dfd..11da15b12 100644 --- a/fish/cmds-gperf.h +++ b/fish/cmds-gperf.h @@ -40,6 +40,4 @@ struct command_table { struct command_entry *entry; }; -const struct command_table *lookup_fish_command (register const char *str, register unsigned int len); - #endif /* FISH_CMDS_GPERF_H */ diff --git a/generator/fish.ml b/generator/fish.ml index ca85997b7..8be1f1ac4 100644 --- a/generator/fish.ml +++ b/generator/fish.ml @@ -671,52 +671,7 @@ let generate_fish_cmds () = pr " printf (\" %%s\\n\","; pr " _(\"Use -h / help to show detailed help for a command.\"));\n"; pr "}\n"; - pr "\n"; - - (* display_command function, which implements guestfish -h cmd *) - pr "int\n"; - pr "display_command (const char *cmd)\n"; - pr "{\n"; - pr " const struct command_table *ct;\n"; - pr "\n"; - pr " ct = lookup_fish_command (cmd, strlen (cmd));\n"; - pr " if (ct) {\n"; - pr " fputs (ct->entry->help, stdout);\n"; - pr " return 0;\n"; - pr " }\n"; - pr " else\n"; - pr " return display_builtin_command (cmd);\n"; - pr "}\n"; - pr "\n"; - - (* run_action function *) - pr "int\n"; - pr "run_action (const char *cmd, size_t argc, char *argv[])\n"; - pr "{\n"; - pr " const struct command_table *ct;\n"; - pr " int ret = -1;\n"; - pr "\n"; - pr " ct = lookup_fish_command (cmd, strlen (cmd));\n"; - pr " if (ct) {\n"; - pr " ret = ct->entry->run (cmd, argc, argv);\n"; - pr " /* run function may return magic value -2 (RUN_WRONG_ARGS) to indicate\n"; - pr " * that this function should print the command synopsis.\n"; - pr " */\n"; - pr " if (ret == RUN_WRONG_ARGS) {\n"; - pr " fprintf (stderr, _(\"error: incorrect number of arguments\\n\"));\n"; - pr " if (ct->entry->synopsis)\n"; - pr " fprintf (stderr, _(\"usage: %%s\\n\"), ct->entry->synopsis);\n"; - pr " fprintf (stderr, _(\"type 'help %%s' for more help on %%s\\n\"), cmd, cmd);\n"; - pr " ret = -1;\n"; - pr " }\n"; - pr " }\n"; - pr " else {\n"; - pr " fprintf (stderr, _(\"%%s: unknown command\\n\"), cmd);\n"; - pr " if (command_num == 1)\n"; - pr " extended_help_message ();\n"; - pr " }\n"; - pr " return ret;\n"; - pr "}\n" + pr "\n" and generate_fish_cmds_h () = generate_header CStyle GPLv2plus; @@ -749,9 +704,13 @@ and generate_fish_cmds_gperf () = #include +#include #include #include +#include +#include \"fish.h\" +#include \"run.h\" #include \"cmds-gperf.h\" "; @@ -786,7 +745,53 @@ struct command_table; fun alias -> pr "%s, &%s_cmd_entry\n" alias name; ) aliases; - ) fish_functions_and_commands_sorted + ) fish_functions_and_commands_sorted; + + pr "\ +%%%% + +int +display_command (const char *cmd) +{ + const struct command_table *ct; + + ct = lookup_fish_command (cmd, strlen (cmd)); + if (ct) { + fputs (ct->entry->help, stdout); + return 0; + } + else + return display_builtin_command (cmd); +} + +int +run_action (const char *cmd, size_t argc, char *argv[]) +{ + const struct command_table *ct; + int ret = -1; + + ct = lookup_fish_command (cmd, strlen (cmd)); + if (ct) { + ret = ct->entry->run (cmd, argc, argv); + /* run function may return magic value -2 (RUN_WRONG_ARGS) to indicate + * that this function should print the command synopsis. + */ + if (ret == RUN_WRONG_ARGS) { + fprintf (stderr, _(\"error: incorrect number of arguments\\n\")); + if (ct->entry->synopsis) + fprintf (stderr, _(\"usage: %%s\\n\"), ct->entry->synopsis); + fprintf (stderr, _(\"type 'help %%s' for more help on %%s\\n\"), cmd, cmd); + ret = -1; + } + } + else { + fprintf (stderr, _(\"%%s: unknown command\\n\"), cmd); + if (command_num == 1) + extended_help_message (); + } + return ret; +} +" (* Readline completion for guestfish. *) and generate_fish_completion () =