From 042767ce4032ee7bec7df1716411a175259cfbf1 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 12 Apr 2013 14:24:54 +0200 Subject: [PATCH] Use self-made help to avoid recompilations on version changes. This provides print_help() for all remaining commands so that we can get rid of the gengetopt generated help output completely. Hence the *.cmdline.[ch] files no longer depend on git-version.h which saves a lot of recompilations. --- afh.c | 14 +++++++ audioc.c | 12 ++++++ client_common.c | 12 ++++++ configure.ac | 88 ++++++++++++++++++++++++++++++++++++------ fade.c | 12 ++++++ gui.c | 12 ++++++ m4/gengetopt/afh.m4 | 2 +- m4/gengetopt/audioc.m4 | 2 +- m4/gengetopt/client.m4 | 2 +- m4/gengetopt/fade.m4 | 2 +- m4/gengetopt/gui.m4 | 2 +- m4/gengetopt/makefile | 2 +- m4/gengetopt/server.m4 | 2 +- server.c | 12 ++++++ 14 files changed, 157 insertions(+), 19 deletions(-) diff --git a/afh.c b/afh.c index f02b47b1..9ab694cf 100644 --- a/afh.c +++ b/afh.c @@ -15,6 +15,7 @@ #include "afh.h" #include "error.h" #include "version.h" +#include "ggo.h" static struct afh_args_info conf; INIT_AFH_ERRLISTS; @@ -56,6 +57,16 @@ static void print_chunk_table(struct afh_info *afhi) } } +__noreturn static void print_help_and_die(void) +{ + struct ggo_help h = DEFINE_GGO_HELP(afh); + int d = conf.detailed_help_given; + unsigned flags = d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS; + + ggo_print_help(&h, flags); + exit(EXIT_SUCCESS); +} + /** * The main function of para_afh. * @@ -74,6 +85,9 @@ int main(int argc, char **argv) afh_cmdline_parser(argc, argv, &conf); loglevel = get_loglevel_by_name(conf.loglevel_arg); version_handle_flag("afh", conf.version_given); + if (conf.help_given || conf.detailed_help_given) + print_help_and_die(); + afh_init(); ret = -E_AFH_SYNTAX; if (conf.inputs_num == 0) goto out; diff --git a/audioc.c b/audioc.c index 0147b4cf..164a1554 100644 --- a/audioc.c +++ b/audioc.c @@ -17,6 +17,7 @@ #include "net.h" #include "string.h" #include "fd.h" +#include "ggo.h" #include "version.h" INIT_AUDIOC_ERRLISTS; @@ -263,6 +264,15 @@ static char *configfile_exists(void) return NULL; } +__noreturn static void print_help_and_die(void) +{ + struct ggo_help h = DEFINE_GGO_HELP(audioc); + bool d = conf.detailed_help_given; + + ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS); + exit(0); +} + /** * The client program to connect to para_audiod. * @@ -288,6 +298,8 @@ int main(int argc, char *argv[]) audioc_cmdline_parser(argc, argv, &conf); loglevel = get_loglevel_by_name(conf.loglevel_arg); version_handle_flag("audioc", conf.version_given); + if (conf.help_given || conf.detailed_help_given) + print_help_and_die(); cf = configfile_exists(); if (cf) { struct audioc_cmdline_parser_params params = { diff --git a/client_common.c b/client_common.c index 754b5bf2..1ecba730 100644 --- a/client_common.c +++ b/client_common.c @@ -22,6 +22,7 @@ #include "client.h" #include "buffer_tree.h" #include "version.h" +#include "ggo.h" /** The size of the receiving buffer. */ #define CLIENT_BUFSIZE 4000 @@ -611,6 +612,15 @@ err_out: return ret; } +__noreturn static void print_help_and_die(struct client_task *ct) +{ + struct ggo_help h = DEFINE_GGO_HELP(client); + bool d = ct->conf.detailed_help_given; + + ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS); + exit(0); +} + /** * Parse a client configuration. * @@ -642,6 +652,8 @@ int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr, if (client_cmdline_parser(argc, argv, &ct->conf)) goto out; version_handle_flag("client", ct->conf.version_given); + if (ct->conf.help_given || ct->conf.detailed_help_given) + print_help_and_die(ct); ct->config_file = ct->conf.config_file_given? para_strdup(ct->conf.config_file_arg) : diff --git a/configure.ac b/configure.ac index e3d1b40e..3a0a36f6 100644 --- a/configure.ac +++ b/configure.ac @@ -124,7 +124,14 @@ filter_ldflags="-lm" filters=" compress wav amp fecdec wmadec prebuffer" audioc_cmdline_objs="add_cmdline(audioc)" -audioc_errlist_objs="audioc string net fd version" +audioc_errlist_objs=" + audioc + string + net + fd + version + ggo +" audioc_ldflags="" audiod_cmdline_objs="add_cmdline(audiod compress_filter http_recv dccp_recv file_write client amp_filter udp_recv prebuffer_filter)" @@ -149,12 +156,38 @@ writers=" file" default_writer="FILE_WRITE" client_cmdline_objs="add_cmdline(client)" -client_errlist_objs="client net string fd sched stdin stdout time sideband - client_common buffer_tree crypt_common version" +client_errlist_objs=" + client + net + string + fd + sched + stdin + stdout + time + sideband + client_common + buffer_tree + crypt_common + version + ggo +" client_ldflags="" gui_cmdline_objs="add_cmdline(gui)" -gui_errlist_objs="exec signal string stat ringbuffer fd gui gui_theme version time" +gui_errlist_objs=" + exec + signal + string + stat + ringbuffer + fd + gui + gui_theme + time + version + ggo +" gui_objs="$gui_cmdline_objs $gui_errlist_objs" play_errlist_objs="play fd sched ggo buffer_tree time string net afh_recv afh_common @@ -292,12 +325,43 @@ else extras="$extras server" executables="$executables server" server_cmdline_objs="add_cmdline(server)" - server_errlist_objs="server afh_common mp3_afh vss command net - 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 wma_afh wma_common sideband - version" + server_errlist_objs=" + server + afh_common + mp3_afh + vss command + net + 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 + wma_afh + wma_common + sideband + version + ggo + " 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 @@ -889,7 +953,7 @@ AC_CHECK_HEADER(sys/soundcard.h, [ write_errlist_objs="$write_errlist_objs oss_write" write_cmdline_objs="$write_cmdline_objs add_cmdline(oss_write)" - fade_errlist_objs="$fade_errlist_objs oss_mix version" + fade_errlist_objs="$fade_errlist_objs oss_mix" all_errlist_objs="$all_errlist_objs oss_write oss_mix" writers="$writers oss" @@ -968,7 +1032,7 @@ if test -n "$mixers"; then extras="$extras fade" executables="$executables fade" all_errlist_objs="$all_errlist_objs fade" - fade_errlist_objs="$fade_errlist_objs fade exec string fd" + fade_errlist_objs="$fade_errlist_objs fade exec string fd version ggo" fade_cmdline_objs="add_cmdline(fade)" fade_objs="$fade_cmdline_objs $fade_errlist_objs" AC_SUBST(fade_objs, add_dot_o($fade_objs)) diff --git a/fade.c b/fade.c index 76d6a8b4..878b83a1 100644 --- a/fade.c +++ b/fade.c @@ -14,6 +14,7 @@ #include "string.h" #include "mix.h" #include "error.h" +#include "ggo.h" #include "version.h" INIT_FADE_ERRLISTS; @@ -286,6 +287,15 @@ static struct mixer *get_mixer_or_die(void) exit(EXIT_FAILURE); } +__noreturn static void print_help_and_die(void) +{ + struct ggo_help h = DEFINE_GGO_HELP(fade); + bool d = conf.detailed_help_given; + + ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS); + exit(0); +} + int main(int argc, char *argv[]) { int ret; @@ -295,6 +305,8 @@ int main(int argc, char *argv[]) fade_cmdline_parser(argc, argv, &conf); loglevel = get_loglevel_by_name(conf.loglevel_arg); version_handle_flag("fade", conf.version_given); + if (conf.help_given || conf.detailed_help_given) + print_help_and_die(); ret = configfile_exists(); if (!ret && conf.config_file_given) { PARA_EMERG_LOG("can not read config file %s\n", diff --git a/gui.c b/gui.c index 4e293feb..b874d082 100644 --- a/gui.c +++ b/gui.c @@ -23,6 +23,7 @@ #include "list.h" #include "sched.h" #include "signal.h" +#include "ggo.h" #include "version.h" /** define the array of error lists needed by para_gui */ @@ -1511,6 +1512,15 @@ static void handle_command(int c) km_keyname(c)); } +__noreturn static void print_help_and_die(void) +{ + struct ggo_help h = DEFINE_GGO_HELP(gui); + bool d = conf.detailed_help_given; + + ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS); + exit(0); +} + int main(int argc, char *argv[]) { int ret; @@ -1522,6 +1532,8 @@ int main(int argc, char *argv[]) gui_cmdline_parser(argc, argv, &conf); /* exits on errors */ loglevel = get_loglevel_by_name(conf.loglevel_arg); version_handle_flag("gui", conf.version_given); + if (conf.help_given || conf.detailed_help_given) + print_help_and_die(); cf = configfile_exists(); if (!cf && conf.config_file_given) { fprintf(stderr, "can not read config file %s\n", diff --git a/m4/gengetopt/afh.m4 b/m4/gengetopt/afh.m4 index 6fd4ab69..f8e29fea 100644 --- a/m4/gengetopt/afh.m4 +++ b/m4/gengetopt/afh.m4 @@ -1,4 +1,4 @@ -args "--unamed-opts=audio_file --no-handle-version" +args "--unamed-opts=audio_file --no-handle-version --no-handle-help" purpose "Print information about audio file(s)." diff --git a/m4/gengetopt/audioc.m4 b/m4/gengetopt/audioc.m4 index 2865900e..36520bfa 100644 --- a/m4/gengetopt/audioc.m4 +++ b/m4/gengetopt/audioc.m4 @@ -1,4 +1,4 @@ -args "--unamed-opts=command --conf-parser --no-handle-version" +args "--unamed-opts=command --conf-parser --no-handle-version --no-handle-help" purpose "Communicate with para_audiod through a local socket." diff --git a/m4/gengetopt/client.m4 b/m4/gengetopt/client.m4 index a14b59c0..f0bbc0bd 100644 --- a/m4/gengetopt/client.m4 +++ b/m4/gengetopt/client.m4 @@ -1,4 +1,4 @@ -args "--unamed-opts=command --no-handle-error --conf-parser --no-handle-version" +args "--unamed-opts=command --no-handle-error --conf-parser --no-handle-version --no-handle-help" purpose "Communicate with para_server through the paraslash control port." diff --git a/m4/gengetopt/fade.m4 b/m4/gengetopt/fade.m4 index 8b81975b..7c731c2b 100644 --- a/m4/gengetopt/fade.m4 +++ b/m4/gengetopt/fade.m4 @@ -1,4 +1,4 @@ -args "--conf-parser --no-handle-version" +args "--conf-parser --no-handle-version --no-handle-help" purpose "An alarm clock and volume-fader for OSS and ALSA." diff --git a/m4/gengetopt/gui.m4 b/m4/gengetopt/gui.m4 index af1ca145..1f5cf6e4 100644 --- a/m4/gengetopt/gui.m4 +++ b/m4/gengetopt/gui.m4 @@ -1,4 +1,4 @@ -args "--conf-parser --no-handle-version" +args "--conf-parser --no-handle-version --no-handle-help" purpose "Show para_audiod status in a curses window." diff --git a/m4/gengetopt/makefile b/m4/gengetopt/makefile index c816bd74..548a3d5d 100644 --- a/m4/gengetopt/makefile +++ b/m4/gengetopt/makefile @@ -9,7 +9,7 @@ endef .PRECIOUS: $(cmdline_dir)/%.cmdline.c $(cmdline_dir)/%.cmdline.h $(ggo_dir)/%.ggo -$(cmdline_dir)/%.cmdline.h $(cmdline_dir)/%.cmdline.c: $(ggo_dir)/%.ggo git-version.h | $(cmdline_dir) +$(cmdline_dir)/%.cmdline.h $(cmdline_dir)/%.cmdline.c: $(ggo_dir)/%.ggo | $(cmdline_dir) @[ -z "$(Q)" ] || echo 'GGO $<' $(Q) $(GENGETOPT) $(ggo_opts) < $< ifeq ($(ggo_descriptions_declared),no) diff --git a/m4/gengetopt/server.m4 b/m4/gengetopt/server.m4 index 6596d934..8707554f 100644 --- a/m4/gengetopt/server.m4 +++ b/m4/gengetopt/server.m4 @@ -1,4 +1,4 @@ -args "--conf-parser --no-handle-version" +args "--conf-parser --no-handle-version --no-handle-help" purpose "Manage and stream audio files." diff --git a/server.c b/server.c index cd985c6d..f26abef5 100644 --- a/server.c +++ b/server.c @@ -91,6 +91,7 @@ #include "signal.h" #include "user_list.h" #include "color.h" +#include "ggo.h" #include "version.h" __printf_2_3 void (*para_log)(int, const char*, ...) = daemon_log; @@ -473,6 +474,15 @@ static int init_afs(int argc, char **argv) return afs_server_socket[0]; } +__noreturn static void print_help_and_die(void) +{ + struct ggo_help h = DEFINE_GGO_HELP(server); + bool d = conf.detailed_help_given; + + ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS); + exit(0); +} + static void server_init(int argc, char **argv) { struct server_cmdline_parser_params params = { @@ -490,6 +500,8 @@ static void server_init(int argc, char **argv) server_cmdline_parser_ext(argc, argv, &conf, ¶ms); daemon_set_loglevel(conf.loglevel_arg); version_handle_flag("server", conf.version_given); + if (conf.help_given || conf.detailed_help_given) + print_help_and_die(); drop_privileges_or_die(conf.user_arg, conf.group_arg); /* parse config file, open log and set defaults */ parse_config_or_die(0); -- 2.30.2