Convert receivers to lopsub.
[paraslash.git] / recv.c
diff --git a/recv.c b/recv.c
index 9de3033..abebbfc 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -8,11 +8,13 @@
 
 #include <regex.h>
 #include <sys/types.h>
 
 #include <regex.h>
 #include <sys/types.h>
+#include <inttypes.h>
+#include <lopsub.h>
 
 
+#include "recv_cmd.lsg.h"
 #include "para.h"
 #include "list.h"
 #include "sched.h"
 #include "para.h"
 #include "list.h"
 #include "sched.h"
-#include "ggo.h"
 #include "buffer_tree.h"
 #include "recv.h"
 #include "recv.cmdline.h"
 #include "buffer_tree.h"
 #include "recv.h"
 #include "recv.cmdline.h"
 /** Array of error strings. */
 DEFINE_PARA_ERRLIST;
 
 /** Array of error strings. */
 DEFINE_PARA_ERRLIST;
 
-extern void afh_recv_init(struct receiver *r);
-#undef AFH_RECEIVER
-#define AFH_RECEIVER {.name = "afh", .init = afh_recv_init},
-DEFINE_RECEIVER_ARRAY;
-
 /** The gengetopt args info struct. */
 static struct recv_args_info conf;
 
 /** The gengetopt args info struct. */
 static struct recv_args_info conf;
 
@@ -39,12 +36,13 @@ INIT_STDERR_LOGGING(loglevel);
 
 __noreturn static void print_help_and_die(void)
 {
 
 __noreturn static void print_help_and_die(void)
 {
-       struct ggo_help h = DEFINE_GGO_HELP(recv);
        bool d = conf.detailed_help_given;
        bool d = conf.detailed_help_given;
-
-       ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS);
-       print_receiver_helps(d? GPH_MODULE_FLAGS_DETAILED : GPH_MODULE_FLAGS);
-       exit(0);
+       if (d)
+               recv_cmdline_parser_print_detailed_help();
+       else
+               recv_cmdline_parser_print_help();
+       print_receiver_helps(d);
+       exit(EXIT_SUCCESS);
 }
 
 /**
 }
 
 /**
@@ -60,12 +58,15 @@ __noreturn static void print_help_and_die(void)
  */
 int main(int argc, char *argv[])
 {
  */
 int main(int argc, char *argv[])
 {
-       int ret, r_opened = 0, receiver_num;
-       struct receiver *r = NULL;
+       int ret;
+       bool r_opened = false;
+       const struct receiver *r = NULL;
        struct receiver_node rn;
        struct stdout_task sot = {.btrn = NULL};
        static struct sched s;
        struct task_info ti;
        struct receiver_node rn;
        struct stdout_task sot = {.btrn = NULL};
        static struct sched s;
        struct task_info ti;
+       const struct lls_command *cmd;
+       struct lls_parse_result *receiver_lpr; /* receiver specific options */
 
        recv_cmdline_parser(argc, argv, &conf);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
 
        recv_cmdline_parser(argc, argv, &conf);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
@@ -75,26 +76,25 @@ int main(int argc, char *argv[])
                print_help_and_die();
 
        memset(&rn, 0, sizeof(struct receiver_node));
                print_help_and_die();
 
        memset(&rn, 0, sizeof(struct receiver_node));
-       rn.conf = check_receiver_arg(conf.receiver_arg, &receiver_num);
-       if (!rn.conf) {
-               PARA_EMERG_LOG("invalid receiver specifier\n");
-               ret = -E_RECV_SYNTAX;
+       ret = check_receiver_arg(conf.receiver_arg, &receiver_lpr);
+       if (ret < 0)
                goto out;
                goto out;
-       }
-       r = &receivers[receiver_num];
+       cmd = lls_cmd(ret, recv_cmd_suite);
+       r = lls_user_data(cmd);
        rn.receiver = r;
        rn.receiver = r;
+       rn.lpr = receiver_lpr;
        rn.btrn = btr_new_node(&(struct btr_node_description)
        rn.btrn = btr_new_node(&(struct btr_node_description)
-               EMBRACE(.name = r->name));
+               EMBRACE(.name = lls_command_name(cmd)));
        ret = r->open(&rn);
        if (ret < 0)
        ret = r->open(&rn);
        if (ret < 0)
-               goto out;
-       r_opened = 1;
+               goto free_receiver_lpr;
+       r_opened = true;
 
        sot.btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.parent = rn.btrn, .name = "stdout"));
        stdout_task_register(&sot, &s);
 
 
        sot.btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.parent = rn.btrn, .name = "stdout"));
        stdout_task_register(&sot, &s);
 
-       ti.name = r->name;
+       ti.name = lls_command_name(cmd);
        ti.pre_select = r->pre_select;
        ti.post_select = r->post_select;
        ti.context = &rn;
        ti.pre_select = r->pre_select;
        ti.post_select = r->post_select;
        ti.context = &rn;
@@ -104,13 +104,16 @@ int main(int argc, char *argv[])
        s.default_timeout.tv_usec = 0;
        ret = schedule(&s);
        sched_shutdown(&s);
        s.default_timeout.tv_usec = 0;
        ret = schedule(&s);
        sched_shutdown(&s);
+       r->close(&rn);
+       btr_remove_node(&sot.btrn);
+       btr_remove_node(&rn.btrn);
+free_receiver_lpr:
+       lls_free_parse_result(receiver_lpr, cmd);
 out:
        if (r_opened)
                r->close(&rn);
        btr_remove_node(&rn.btrn);
        btr_remove_node(&sot.btrn);
 out:
        if (r_opened)
                r->close(&rn);
        btr_remove_node(&rn.btrn);
        btr_remove_node(&sot.btrn);
-       if (rn.conf)
-               r->free_config(rn.conf);
 
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));
 
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));