]> git.tue.mpg.de Git - paraslash.git/commitdiff
command_util.bash: Kill make_proto().
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 13 Jan 2015 23:52:02 +0000 (00:52 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 12 Aug 2015 21:23:47 +0000 (23:23 +0200)
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
command.c
command_util.bash
play.c

index 2b18837b7603de5e37b06ce579c0a604d10a34bb..68cc15fbeca828d436be083f23f9aec19dac28e4 100644 (file)
 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. */
index 5d6a0990597165bc5b17a7cfaf5595e73955ca09..eac09f056af21cbfc9c5b4994c7150f200606ae5 100644 (file)
--- a/command.c
+++ b/command.c
 #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. */
index e33e0769d9cbc2230bf02b70813d5435f2447430..5e9dbcc77e77ac8101e27513d5c0105cf0aa6c33 100755 (executable)
@@ -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 4fb2050019d2dbfeee61c660bd7f7fa3c4e086fe..61c30aed08b131384e099a945cfed3011b9a0f97 100644 (file)
--- 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++)