]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
write_common: Make check_writer_arg() exit on syntax errors.
authorAndre Noll <maan@systemlinux.org>
Sat, 6 Aug 2011 20:32:49 +0000 (22:32 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 13 Aug 2011 11:01:30 +0000 (13:01 +0200)
This function parses the argument of the --writer option to extract
the name of the writer, which is the first word of the argument. If
this word is not the name of a supported writer, the function
returns NULL to indicate that the given writer does not exist.
Otherwise check_writer_arg() calls the ->parse_config_or_die method
of this writer which parses the remaining part of the argument and
exits on errors.

It is more consistent and simpler to let this function exit also
in case the writer was not found. This simplifies the callers a bit
since they do not have to check the return value any more. It also
allows to kill E_WRITE_COMMON_SYNTAX.

audiod.c
error.h
write.c
write_common.c
write_common.h

index 5af79b04f4af5d2378ac1d0ccb9d76a7a4f48fe9..c78df5b83bab6e0685eda33274c68a2f8f3f454f 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -776,16 +776,13 @@ static int parse_writer_args(void)
 
                ret = parse_stream_command(conf.writer_arg[i], &cmd);
                if (ret < 0)
-                       goto out;
+                       return ret;
                af_mask = ret;
                FOR_EACH_AUDIO_FORMAT(j) {
                        a = afi + j;
                        if ((af_mask & (1 << j)) == 0) /* no match */
                                continue;
-                       ret = -E_WRITE_COMMON_SYNTAX;
-                       wconf = check_writer_arg(cmd, &writer_num);
-                       if (!wconf)
-                               goto out;
+                       wconf = check_writer_arg_or_die(cmd, &writer_num);
                        nw = a->num_writers;
                        a->writer_nums = para_realloc(a->writer_nums, (nw + 1) * sizeof(int));
                        a->writer_conf = para_realloc(a->writer_conf, (nw + 1) * sizeof(void *));
@@ -810,9 +807,7 @@ static int parse_writer_args(void)
                a->writer_conf[0] = w->parse_config_or_die("");
                a->num_writers = 1;
        }
-       ret = 1;
-out:
-       return ret;
+       return 1;
 }
 
 static int parse_receiver_args(void)
diff --git a/error.h b/error.h
index 1e4bf044fe98d49490604b352517afbcba6f2ab8..79ead6dbae446325dc19648d9426906cc6e0569c 100644 (file)
--- a/error.h
+++ b/error.h
@@ -441,7 +441,6 @@ extern const char **para_errlist[];
 
 
 #define WRITE_COMMON_ERRORS \
-       PARA_ERROR(WRITE_COMMON_SYNTAX, "syntax error in write option"), \
        PARA_ERROR(WRITE_COMMON_EOF, "end of file"), \
 
 
diff --git a/write.c b/write.c
index fcb477f80a1d2bcaf94d0f4b1b220164fb8d67c5..3b5f2d193f31ddc1d8c130703637810f807f255f 100644 (file)
--- a/write.c
+++ b/write.c
@@ -185,19 +185,16 @@ __noreturn static void print_help_and_die(void)
  *
  * \return Standard.
  */
-static int setup_writer_node(const char *arg, struct btr_node *parent,
+static void setup_writer_node(const char *arg, struct btr_node *parent,
                struct writer_node *wn)
 {
        if (arg)
-               wn->conf = check_writer_arg(arg, &wn->writer_num);
+               wn->conf = check_writer_arg_or_die(arg, &wn->writer_num);
        else {
                wn->writer_num = DEFAULT_WRITER;
                wn->conf = writers[DEFAULT_WRITER].parse_config_or_die("");
        }
-       if (!wn->conf)
-               return -E_WRITE_COMMON_SYNTAX;
        register_writer_node(wn, parent);
-       return 1;
 }
 
 static int setup_and_schedule(void)
@@ -225,20 +222,14 @@ static int setup_and_schedule(void)
        register_task(&cwt->task);
 
        if (!conf.writer_given) {
-               i = 0;
                wns = para_calloc(sizeof(*wns));
-               ret = setup_writer_node(NULL, cwt->btrn, wns);
-               if (ret < 0)
-                       goto out;
+               setup_writer_node(NULL, cwt->btrn, wns);
                i = 1;
        } else {
                wns = para_calloc(conf.writer_given * sizeof(*wns));
-               for (i = 0; i < conf.writer_given; i++) {
-                       ret = setup_writer_node(conf.writer_arg[i],
-                               cwt->btrn, wns + i);
-                       if (ret < 0)
-                               goto out;
-               }
+               for (i = 0; i < conf.writer_given; i++)
+                       setup_writer_node(conf.writer_arg[i], cwt->btrn,
+                               wns + i);
        }
 
        s.default_timeout.tv_sec = 10;
@@ -258,7 +249,6 @@ static int setup_and_schedule(void)
                        }
                }
        }
-out:
        for (i--; i >= 0; i--) {
                struct writer_node *wn = wns + i;
                struct writer *w = writers + wn->writer_num;
index 2c149dfd6c295eab522c0cabdbf28d4376cabc08..b85699367acd45d88eb4044da6450d2717f48437 100644 (file)
@@ -47,14 +47,13 @@ void writer_init(void)
  *
  * \return On success, a pointer to the gengetopt args info struct is returned
  * and \a writer_num contains the number of the writer. Otherwise this function
- * returns \p NULL.
+ * prints an error message and calls exit().
  */
-void *check_writer_arg(const char *wa, int *writer_num)
+void *check_writer_arg_or_die(const char *wa, int *writer_num)
 {
        int i;
 
-       *writer_num = -E_WRITE_COMMON_SYNTAX;
-       PARA_INFO_LOG("checking  %s\n", wa);
+       PARA_INFO_LOG("checking %s\n", wa);
        FOR_EACH_WRITER(i) {
                const char *name = writer_names[i];
                size_t len = strlen(name);
@@ -69,8 +68,8 @@ void *check_writer_arg(const char *wa, int *writer_num)
                *writer_num = i;
                return writers[i].parse_config_or_die(c? wa + len + 1 : "");
        }
-       PARA_ERROR_LOG("writer not found\n");
-       return NULL;
+       PARA_EMERG_LOG("invalid writer %s\n", wa);
+       exit(EXIT_FAILURE);
 }
 
 /**
index fc702ca0b69d1ba8530dc20a808886b8b8267be8..00ded8f37bb29f4219340286edee7f66a82fa0bf 100644 (file)
@@ -7,7 +7,7 @@
 /** \file write_common.h Exported symbols from write_common.c. */
 
 void writer_init(void);
-void *check_writer_arg(const char *wa, int *writer_num);
+void *check_writer_arg_or_die(const char *wa, int *writer_num);
 void print_writer_helps(int detailed);
 void register_writer_node(struct writer_node *wn, struct btr_node *parent);
 void get_btr_sample_rate(struct btr_node *btrn, int32_t *result);