From 0a405367cdc8f3b0f49fb5ec3798378a2fc4589b Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 11 Feb 2007 17:06:46 +0100 Subject: [PATCH] command_util.sh: Make it read the function prototype from the source file This is much cleaner as the commands differ by gcc attribute usage, e.g. __a_unused. But it also means that in the source code (a) the opening bracket for the function body must not be on the same line (com_hist got this wrong), (b) for all command handlers, the parameters must be called fd, argc and argv, (c) If a command handler uses __noreturn, that attribute must be the first word, see audiod's com_term(). So change the few occasions where this was not the case. --- audiod.cmd | 3 ++- audiod_command.c | 2 +- command.c | 34 +++++++++++++++++----------------- command_util.sh | 21 ++++++++++----------- error.h | 2 +- mysql_selector.c | 3 ++- mysql_selector.cmd | 3 ++- playlist_selector.cmd | 3 ++- random_selector.cmd | 3 ++- server.cmd | 3 ++- 10 files changed, 41 insertions(+), 36 deletions(-) diff --git a/audiod.cmd b/audiod.cmd index 8300e441..f6d1a1f6 100644 --- a/audiod.cmd +++ b/audiod.cmd @@ -1,4 +1,5 @@ -FN: audiod_command_list +OF: audiod_command_list +SF: audiod_command.c HC: prototypes for the audiod command handlers CC: array of audiod commands AT: audiod_command diff --git a/audiod_command.c b/audiod_command.c index d1e36490..524fb57d 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -350,7 +350,7 @@ err_out: return 1; } -int __noreturn com_term(int fd, __a_unused int argc, __a_unused char **argv) +__noreturn int com_term(int fd, __a_unused int argc, __a_unused char **argv) { close(fd); clean_exit(EXIT_SUCCESS, "terminating on user request"); diff --git a/command.c b/command.c index 9ef62925..d0d9047b 100644 --- a/command.c +++ b/command.c @@ -341,18 +341,18 @@ int com_si(int fd, int argc, __a_unused char **argv) } /* version */ -int com_version(int socket_fd, int argc, __a_unused char **argv) +int com_version(int fd, int argc, __a_unused char **argv) { if (argc != 1) return -E_COMMAND_SYNTAX; - return send_buffer(socket_fd, VERSION_TEXT("server") + return send_buffer(fd, VERSION_TEXT("server") "built: " BUILD_DATE "\n" SYSTEM ", " CC_VERSION "\n" ); } /* sc */ -int com_sc(int socket_fd, int argc, char **argv) +int com_sc(int fd, int argc, char **argv) { char *name = NULL; int ret, old = 0, count = -1; /* print af change forever */ @@ -367,7 +367,7 @@ repeat: } mmd_unlock(); if (name) { - ret = send_va_buffer(socket_fd, "%s\n", name); + ret = send_va_buffer(fd, "%s\n", name); free(name); name = NULL; if (ret < 0) @@ -380,7 +380,7 @@ repeat: } /* sb */ -int com_sb(int socket_fd, int argc, char **argv) +int com_sb(int fd, int argc, char **argv) { char *sb; int ret, nr = -1; /* status bar will be printed that many @@ -393,7 +393,7 @@ int com_sb(int socket_fd, int argc, char **argv) mmd_lock(); sb = get_sb_string(mmd); mmd_unlock(); - ret = send_va_buffer(socket_fd, "%s\n", sb); + ret = send_va_buffer(fd, "%s\n", sb); free(sb); if (ret < 0) return ret; @@ -407,7 +407,7 @@ int com_sb(int socket_fd, int argc, char **argv) } /* stat */ -int com_stat(int socket_fd, int argc, char **argv) +int com_stat(int fd, int argc, char **argv) { int ret, num = 0;/* status will be printed that many * times. num <= 0 means: print forever @@ -423,7 +423,7 @@ int com_stat(int socket_fd, int argc, char **argv) mmd_dup(nmmd); s = get_status(nmmd); - ret = send_buffer(socket_fd, s); + ret = send_buffer(fd, s); free(s); if (ret < 0) goto out; @@ -525,7 +525,7 @@ int com_help(int fd, int argc, char **argv) } /* hup */ -int com_hup(__a_unused int socket_fd, int argc, __a_unused char **argv) +int com_hup(__a_unused int fd, int argc, __a_unused char **argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -534,7 +534,7 @@ int com_hup(__a_unused int socket_fd, int argc, __a_unused char **argv) } /* term */ -int com_term(__a_unused int socket_fd, int argc, __a_unused char **argv) +int com_term(__a_unused int fd, int argc, __a_unused char **argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -542,7 +542,7 @@ int com_term(__a_unused int socket_fd, int argc, __a_unused char **argv) return 1; } -int com_play(__a_unused int socket_fd, int argc, __a_unused char **argv) +int com_play(__a_unused int fd, int argc, __a_unused char **argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -555,7 +555,7 @@ int com_play(__a_unused int socket_fd, int argc, __a_unused char **argv) } /* stop */ -int com_stop(__a_unused int socket_fd, int argc, __a_unused char **argv) +int com_stop(__a_unused int fd, int argc, __a_unused char **argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -568,7 +568,7 @@ int com_stop(__a_unused int socket_fd, int argc, __a_unused char **argv) } /* pause */ -int com_pause(__a_unused int socket_fd, int argc, __a_unused char **argv) +int com_pause(__a_unused int fd, int argc, __a_unused char **argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -607,7 +607,7 @@ int com_chs(int fd, int argc, char **argv) } /* next */ -int com_next(__a_unused int socket_fd, int argc, __a_unused char **argv) +int com_next(__a_unused int fd, int argc, __a_unused char **argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -619,7 +619,7 @@ int com_next(__a_unused int socket_fd, int argc, __a_unused char **argv) } /* nomore */ -int com_nomore(__a_unused int socket_fd, int argc, __a_unused char **argv) +int com_nomore(__a_unused int fd, int argc, __a_unused char **argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -631,7 +631,7 @@ int com_nomore(__a_unused int socket_fd, int argc, __a_unused char **argv) } /* ff */ -int com_ff(__a_unused int socket_fd, int argc, char **argv) +int com_ff(__a_unused int fd, int argc, char **argv) { long promille; int ret, backwards = 0; @@ -670,7 +670,7 @@ out: } /* jmp */ -int com_jmp(__a_unused int socket_fd, int argc, char **argv) +int com_jmp(__a_unused int fd, int argc, char **argv) { long unsigned int i; int ret; diff --git a/command_util.sh b/command_util.sh index 326bb032..4a9a03cc 100755 --- a/command_util.sh +++ b/command_util.sh @@ -36,10 +36,13 @@ read_header() CC:) c_file_comment="$value" ;; - FN:) - file_name="$value" + OF:) + output_file="$value" array_name=${value%command_list}cmds ;; + SF:) + source_file="$value" + ;; AT:) array_type="$value" ;; @@ -49,14 +52,14 @@ read_header() #include \"$i.h\"" done includes="$includes -#include \"$file_name.h\"" +#include \"$output_file.h\"" ;; SN:) section_name="$value" esac done if test -z "$header_comment" -o -z "$c_file_comment" \ - -o -z "$file_name"; then + -o -z "$output_file"; then echo "header error" 1&>2 exit 1 fi @@ -166,7 +169,7 @@ com_man() com_c_file() { - echo "/** \file $file_name.c $c_file_comment */" + echo "/** \file $output_file.c $c_file_comment */" echo "$includes" echo "struct $array_type $array_name[] = {" while : ; do @@ -199,17 +202,13 @@ dump_proto() echo ' * ' echo "$help_txt" | sed -e 's/^/ * /g' echo ' */' - if test $line_handler -eq 0; then - echo "int com_$name_txt(int fd, int argc, char **argv);" - else - echo "int com_$name_txt(int fd, char *cmdline);" - fi + grep "^\(__noreturn \)*int com_$name_txt(" $source_file | sed -e 's/$/;/1' echo } com_header() { - echo "/** \file $file_name.h $header_comment */" + echo "/** \file $output_file.h $header_comment */" echo echo "extern struct $array_type $array_name[];" while : ; do diff --git a/error.h b/error.h index 9563303f..34b18f19 100644 --- a/error.h +++ b/error.h @@ -518,7 +518,7 @@ extern const char **para_errlist[]; */ #define PARA_ERROR(err, msg) E_ ## err -#define SS_NAME(ss) para_errlist[ss]? para_errlist[ss][0] : "" +// #define SS_NAME(ss) para_errlist[ss]? para_errlist[ss][0] : "" /** \cond popcorn time */ SS_ENUM(GUI); diff --git a/mysql_selector.c b/mysql_selector.c index f8885f9a..b059de70 100644 --- a/mysql_selector.c +++ b/mysql_selector.c @@ -459,7 +459,8 @@ int com_laa(int fd, int argc, __a_unused char *argv[]) /* * history */ -int com_hist(int fd, int argc, char *argv[]) { +int com_hist(int fd, int argc, char *argv[]) +{ int ret; void *result = NULL; char *q, *atts; diff --git a/mysql_selector.cmd b/mysql_selector.cmd index df88a220..7696352d 100644 --- a/mysql_selector.cmd +++ b/mysql_selector.cmd @@ -1,4 +1,5 @@ -FN: mysql_selector_command_list +OF: mysql_selector_command_list +SF: mysql_selector.c HC: prototypes for the commands of the mysql audio file selector CC: array of commands for the mysql audio file selector AT: server_command diff --git a/playlist_selector.cmd b/playlist_selector.cmd index f829028a..e84e97ee 100644 --- a/playlist_selector.cmd +++ b/playlist_selector.cmd @@ -1,4 +1,5 @@ -FN: playlist_selector_command_list +OF: playlist_selector_command_list +SF: playlist_selector.c HC: prototypes for the commands of the playlist audio file selector CC: array of commands for the playlist audio file selector AT: server_command diff --git a/random_selector.cmd b/random_selector.cmd index fe3ef724..f1901f88 100644 --- a/random_selector.cmd +++ b/random_selector.cmd @@ -1,4 +1,5 @@ -FN: random_selector_command_list +OF: random_selector_command_list +SF: random_selector.c HC: prototypes for the commands of the random audio file selector CC: array of commands for the random audio file selector AT: server_command diff --git a/server.cmd b/server.cmd index 71ed6d9e..ad175c8d 100644 --- a/server.cmd +++ b/server.cmd @@ -1,4 +1,5 @@ -FN: server_command_list +OF: server_command_list +SF: command.c HC: prototypes for the server command handlers CC: array of server commands AT: server_command -- 2.39.2