build: Define Make variables for cppflags.
[paraslash.git] / audioc.c
index f68aee542e1ed2ef48694eae309112cccd3314f2..0edab366efe6ef6fa50f99c22b9ffa3492494640 100644 (file)
--- 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;
@@ -165,8 +166,6 @@ static int audioc_i9e_line_handler(char *line)
 {
        char *args = NULL;
        int ret;
-       if (!line || !*line)
-               return 0;
 
        PARA_DEBUG_LOG("line: %s\n", line);
        ret = create_argv(line, " ", &conf.inputs);
@@ -175,6 +174,8 @@ static int audioc_i9e_line_handler(char *line)
        conf.inputs_num = ret;
        args = concat_args(conf.inputs_num, conf.inputs);
        free_argv(conf.inputs);
+       if (!args)
+               return 0;
        conf.inputs_num = 0; /* required for audioc_cmdline_parser_free() */
        ret = connect_audiod(socket_name, args);
        if (ret < 0)
@@ -210,7 +211,7 @@ __noreturn static void interactive_session(void)
                .loglevel = loglevel,
                .completers = audiod_completers,
        };
-       PARA_NOTICE_LOG("\n%s\n", VERSION_TEXT("audioc"));
+       PARA_NOTICE_LOG("\n%s\n", version_text("audioc"));
        if (conf.history_file_given)
                history_file = para_strdup(conf.history_file_arg);
        else {
@@ -279,6 +280,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.
  *
@@ -297,29 +307,29 @@ static char *configfile_exists(void)
  */
 int main(int argc, char *argv[])
 {
-       int ret = -E_AUDIOC_SYNTAX, fd;
+       int ret, fd;
        char *cf, *buf = NULL, *args = NULL;
        size_t bufsize;
 
-       if (audioc_cmdline_parser(argc, argv, &conf))
-               goto out;
-       HANDLE_VERSION_FLAG("audioc", conf);
+       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 = {
                        .override = 0,
                        .initialize = 0,
                        .check_required = 0,
-                       .check_ambiguity = 0
+                       .check_ambiguity = 0,
+                       .print_errors = 1,
+
                };
-               ret = audioc_cmdline_parser_config_file(cf, &conf, &params);
+               audioc_cmdline_parser_config_file(cf, &conf, &params);
                free(cf);
-               if (ret) {
-                       fprintf(stderr, "parse error in config file\n");
-                       exit(EXIT_FAILURE);
-               }
+               loglevel = get_loglevel_by_name(conf.loglevel_arg);
        }
-       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        if (conf.socket_given)
                socket_name = para_strdup(conf.socket_arg);
        else {