From c9df5dfaa915915e0717c1992bc8498f6432dba8 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 28 Jun 2012 04:23:32 +0200 Subject: [PATCH] command_util: Write array definition in header mode. 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 | 1 + audiod.cmd | 1 + audiod_command.c | 3 +++ command.c | 3 +++ command_util.sh | 20 ++++++++++++++++++++ configure.ac | 10 ++++------ error.h | 3 --- server.cmd | 1 + 8 files changed, 33 insertions(+), 9 deletions(-) diff --git a/afs.cmd b/afs.cmd index 2dd55735..e2295272 100644 --- 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 diff --git a/audiod.cmd b/audiod.cmd index 5ec57874..04c8f624 100644 --- a/audiod.cmd +++ b/audiod.cmd @@ -1,3 +1,4 @@ +BN: audiod OF: audiod_command_list SF: audiod_command.c AT: audiod_command diff --git a/audiod_command.c b/audiod_command.c index 9d92d1c3..1c3b0582 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -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++) diff --git a/command.c b/command.c index 72f8e04e..e051aae4 100644 --- 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 diff --git a/command_util.sh b/command_util.sh index 875b5e69..abae4ec2 100755 --- a/command_util.sh +++ b/command_util.sh @@ -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() diff --git a/configure.ac b/configure.ac index c616b0a5..90521dfe 100644 --- a/configure.ac +++ b/configure.ac @@ -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 3100b312..2474e0ab 100644 --- 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 diff --git a/server.cmd b/server.cmd index e676aa68..a80e2312 100644 --- a/server.cmd +++ b/server.cmd @@ -1,3 +1,4 @@ +BN: server OF: server_command_list SF: command.c AT: server_command -- 2.39.2