From 6aea41e619e9ec72167483465ca959715faa8e55 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 14 Jan 2015 00:52:02 +0100 Subject: [PATCH] command_util.bash: Kill make_proto(). It is always a bad idea to parse C code with a regex in a script. In addition, it is completely unnecessary in this case. This commit changes command_util.bash to define, in addition to the old XXX_CMD_ARRAY, another preprocessor macro XXX__COMMAND_HANDLERS containing the comma separated list of command handlers without any type information instead of grepping the source files. A simple typedef is used to declare all command handlers. Avoiding all the grep/sed calls reduces the (warm cache) make dep time by ~10%. --- audiod_command.c | 5 ++++- command.c | 6 +++++- command_util.bash | 32 +++++++++----------------------- play.c | 8 ++++++-- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/audiod_command.c b/audiod_command.c index 2b18837b..68cc15fb 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -35,11 +35,14 @@ extern struct sched sched; extern char *stat_item_values[NUM_STAT_ITEMS]; +typedef int audiod_command_handler_t(int, int, char **); +static audiod_command_handler_t AUDIOD_COMMAND_HANDLERS; + /* Defines one command of para_audiod. */ struct audiod_command { const char *name; /* Pointer to the function that handles the command. */ - int (*handler)(int, int, char **); + audiod_command_handler_t *handler; /* One-line description. */ const char *description; /* Summary of the command line options. */ diff --git a/command.c b/command.c index 5d6a0990..eac09f05 100644 --- a/command.c +++ b/command.c @@ -40,12 +40,16 @@ #include "signal.h" #include "version.h" +typedef int server_command_handler_t(struct command_context *); +static server_command_handler_t SERVER_COMMAND_HANDLERS; +server_command_handler_t AFS_COMMAND_HANDLERS; + /* Defines one command of para_server. */ struct server_command { /* The name of the command. */ const char *name; /* Pointer to the function that handles the command. */ - int (*handler)(struct command_context *); + server_command_handler_t *handler; /* The privileges a user must have to execute this command. */ unsigned int perms; /* One-line description of the command. */ diff --git a/command_util.bash b/command_util.bash index e33e0769..5e9dbcc7 100755 --- a/command_util.bash +++ b/command_util.bash @@ -162,24 +162,9 @@ com_man() done } -make_proto() +cmd_handler_name() { - local regex='\(__noreturn \)*\(static \)*int com_' - local source_file match="" all_commands CR=' -' - if test -n "$prototype"; then - result="$prototype$CR" - return - fi - all_commands="$(cat $source_files | grep "$regex")" - result= - for source_file in $source_files; do - match=$(grep "$regex$name_txt(" <<< "$all_commands" | head -n 1 | sed -e 's/$/;/1') - if test -n "$match"; then - result="$result$match$CR" - break - fi - done + result="com_$name_txt," } make_array_member() @@ -239,7 +224,7 @@ template_loop() com_header() { - local array_members CR=' + local array_members handlers= CR=' ' while : ; do @@ -251,19 +236,20 @@ com_header() break fi if test $template -eq 0; then - make_proto - printf "%s" "$result" + cmd_handler_name + handlers+="$result" make_array_member array_members="$array_members$result" continue fi - template_loop make_proto - printf "%s" "$result" + template_loop cmd_handler_name + handlers+="$result" template_loop make_array_member array_members="$array_members$result" done array_members="$array_members{.name = NULL} \\$CR" - echo "#define DEFINE_$(tr 'a-z' 'A-Z' <<< "$base_name")_CMD_ARRAY $array_members" + echo "#define DEFINE_${base_name^^}_CMD_ARRAY $array_members" + echo "#define ${base_name^^}_COMMAND_HANDLERS ${handlers%,}" } com_completion() diff --git a/play.c b/play.c index 4fb20500..61c30aed 100644 --- a/play.c +++ b/play.c @@ -633,16 +633,20 @@ static char **get_mapped_keyseqs(void) return result; } +#include "play.command_list.h" + +typedef int play_command_handler_t(struct play_task *, int, char**); +static play_command_handler_t PLAY_COMMAND_HANDLERS; + /* defines one command of para_play */ struct pp_command { const char *name; - int (*handler)(struct play_task *, int, char**); + play_command_handler_t *handler; const char *description; const char *usage; const char *help; }; -#include "play.command_list.h" static struct pp_command pp_cmds[] = {DEFINE_PLAY_CMD_ARRAY}; #define FOR_EACH_COMMAND(c) for (c = 0; pp_cmds[c].name; c++) -- 2.30.2