command_util: Write array definition in header mode.
authorAndre Noll <maan@systemlinux.org>
Thu, 28 Jun 2012 02:23:32 +0000 (04:23 +0200)
committerAndre Noll <maan@systemlinux.org>
Fri, 29 Jun 2012 19:36:31 +0000 (21:36 +0200)
This modifies command_util.sh so that when it is called in header mode,
it also defines a macro for the array of all commands. command.c and
audiod_command.c are changed to use the new preprocessor macro.

This allows to get rid of the *command_list.c files completely. We may
hence remove these files from the various lists of errlist objects
in configure.ac. and from error.h. A subsequent patch will clean up
the parts that have become unused by this commit.

afs.cmd
audiod.cmd
audiod_command.c
command.c
command_util.sh
configure.ac
error.h
server.cmd

diff --git a/afs.cmd b/afs.cmd
index 2dd5573..e229527 100644 (file)
--- a/afs.cmd
+++ b/afs.cmd
@@ -1,3 +1,4 @@
+BN: afs
 OF: afs_command_list
 SF: afs.c aft.c attribute.c
 AT: server_command
index 5ec5787..04c8f62 100644 (file)
@@ -1,3 +1,4 @@
+BN: audiod
 OF: audiod_command_list
 SF: audiod_command.c
 AT: audiod_command
index 9d92d1c..1c3b058 100644 (file)
@@ -29,6 +29,9 @@
 extern struct sched sched;
 extern char *stat_item_values[NUM_STAT_ITEMS];
 
+
+struct audiod_command audiod_cmds[] = {DEFINE_AUDIOD_CMD_ARRAY};
+
 /** Iterate over the array of all audiod commands. */
 #define FOR_EACH_COMMAND(c) for (c = 0; audiod_cmds[c].name; c++)
 
index 72f8e04..e051aae 100644 (file)
--- a/command.c
+++ b/command.c
@@ -36,6 +36,9 @@
 #include "signal.h"
 #include "version.h"
 
+struct server_command afs_cmds[] = {DEFINE_AFS_CMD_ARRAY};
+struct server_command server_cmds[] = {DEFINE_SERVER_CMD_ARRAY};
+
 /** Commands including options must be shorter than this. */
 #define MAX_COMMAND_LEN 32768
 
index 875b5e6..abae4ec 100755 (executable)
@@ -10,6 +10,9 @@ read_header()
                ---)
                        break
                        ;;
+               BN:)
+                       base_name="$value"
+                       ;;
                OF:)
                        output_file="$value"
                        array_name=${value%command_list}cmds
@@ -248,10 +251,18 @@ template_loop()
                usage_txt=$(echo "$t_usage" | $sed_cmd)
                help_txt=$(printf "%s\n" "$t_help" | $sed_cmd)
                prototype=$(echo "$template_prototype" | $sed_cmd)
+               result=
                $1
                loop_result="$loop_result$result"
        done
        result="$loop_result"
+       # reset global variables
+       name_txt="$t_name"
+       perms_txt="$t_perms"
+       desc_txt="$t_desc"
+       usage_txt="$t_usage"
+       help_txt="$t_help"
+       source_files="$t_source_files"
 }
 
 com_c_file()
@@ -280,6 +291,9 @@ com_c_file()
 
 com_header()
 {
+       local array_members CR='
+'
+
        echo "extern struct $array_type $array_name[];"
        while : ; do
                read_one_command
@@ -292,11 +306,17 @@ com_header()
                if test $template -eq 0; then
                        make_proto
                        printf "%s" "$result"
+                       make_array_member
+                       array_members="$array_members$result"
                        continue
                fi
                template_loop make_proto
                printf "%s" "$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"
 }
 
 com_completion()
index c616b0a..90521df 100644 (file)
@@ -98,7 +98,7 @@ all_errlist_objs="mp3_afh afh_common net string signal time daemon
        dccp_recv recv_common write_common file_write audiod_command
        client_common recv stdout filter stdin audioc write client
        exec send_common ggo udp_recv color fec fecdec_filter
-       prebuffer_filter audiod_command_list bitstream imdct
+       prebuffer_filter bitstream imdct
        wma_afh wma_common wmadec_filter buffer_tree crypt_common
        gui gui_theme sideband"
 
@@ -125,7 +125,7 @@ audiod_cmdline_objs="add_cmdline(audiod compress_filter http_recv dccp_recv file
 audiod_errlist_objs="audiod signal string daemon stat net crypt_common sideband
        time grab_client filter_common wav_filter compress_filter amp_filter http_recv dccp_recv
        recv_common fd sched write_common file_write audiod_command fecdec_filter
-       client_common ggo udp_recv color fec prebuffer_filter audiod_command_list
+       client_common ggo udp_recv color fec prebuffer_filter
        bitstream imdct wma_common wmadec_filter buffer_tree"
 audiod_ldflags="-lm"
 audiod_audio_formats="wma"
@@ -269,13 +269,11 @@ else
                string signal time daemon http_send close_on_fork mm
                crypt_common ipc dccp_send fd user_list chunk_queue
                afs aft mood score attribute blob playlist sched acl
-               send_common udp_send color fec server_command_list
-               afs_command_list wma_afh wma_common sideband"
-
+               send_common udp_send color fec wma_afh wma_common sideband"
        all_errlist_objs="$all_errlist_objs server vss command
                http_send close_on_fork mm ipc dccp_send user_list
                chunk_queue afs aft mood score attribute blob playlist
-               acl udp_send server_command_list afs_command_list"
+               acl udp_send"
 
        server_ldflags=""
        server_audio_formats="mp3 wma"
diff --git a/error.h b/error.h
index 3100b31..2474e0a 100644 (file)
--- a/error.h
+++ b/error.h
@@ -29,9 +29,6 @@ DEFINE_ERRLIST_OBJECT_ENUM;
 #define COLOR_ERRORS
 #define SIGNAL_ERRORS
 #define FADE_ERRORS
-#define SERVER_COMMAND_LIST_ERRORS
-#define AFS_COMMAND_LIST_ERRORS
-#define AUDIOD_COMMAND_LIST_ERRORS
 #define STDOUT_ERRORS
 #define FILE_WRITE_ERRORS
 #define STDIN_ERRORS
index e676aa6..a80e231 100644 (file)
@@ -1,3 +1,4 @@
+BN: server
 OF: server_command_list
 SF: command.c
 AT: server_command