layer23: Enable combining the long options
authorHolger Hans Peter Freyther <zecke@selfish.org>
Mon, 27 Dec 2010 13:51:13 +0000 (14:51 +0100)
committerHolger Hans Peter Freyther <zecke@selfish.org>
Mon, 27 Dec 2010 18:01:37 +0000 (19:01 +0100)
Combine the long options from the base and the application. Provide
the long option for the cell log application.

src/host/layer23/include/osmocom/bb/common/l23_app.h
src/host/layer23/src/common/main.c
src/host/layer23/src/misc/app_cell_log.c

index fcfd4bd..e4c5d55 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _L23_APP_H
 #define _L23_APP_H
 
+struct option;
+
 /* Options supported by the l23 app */
 enum {
        L23_OPT_SAP     = 1,
@@ -24,6 +26,7 @@ struct l23_app_info {
        char *getopt_string;
        int (*cfg_supported)();
        int (*cfg_print_help)();
+       int (*cfg_getopt_opt)(struct option **options);
        int (*cfg_handle_opt)(int c,const char *optarg);
 };
 
index a791ccf..cb9564a 100644 (file)
@@ -110,6 +110,9 @@ static void print_help()
 static void build_config(char **opt, struct option **option)
 {
        struct l23_app_info *app;
+       struct option *app_opp = NULL;
+       int app_len = 0, len;
+
        static struct option long_options[] = {
                {"help", 0, 0, 'h'},
                {"socket", 1, 0, 's'},
@@ -124,9 +127,14 @@ static void build_config(char **opt, struct option **option)
        app = l23_app_info();
        *opt = talloc_asprintf(l23_ctx, "hs:S:a:i:v:d:%s",
                               app && app->getopt_string ? app->getopt_string : "");
-       *option = talloc_zero_array(l23_ctx, struct option,
-                                   ARRAY_SIZE(long_options) + 1);
+
+       len = ARRAY_SIZE(long_options);
+       if (app && app->cfg_getopt_opt)
+               app_len = app->cfg_getopt_opt(&app_opp);
+
+       *option = talloc_zero_array(l23_ctx, struct option, len + app_len + 1);
        memcpy(*option, long_options, sizeof(long_options));
+       memcpy(*option + len, app_opp, app_len * sizeof(struct option));
 }
 
 static void handle_options(int argc, char **argv)
index e80a7b2..a0a1c09 100644 (file)
@@ -23,6 +23,7 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <time.h>
+#include <getopt.h>
 
 #include <osmocom/bb/common/osmocom_data.h>
 #include <osmocom/bb/common/l1ctl.h>
@@ -31,6 +32,7 @@
 #include <osmocom/bb/misc/cell_log.h>
 
 #include <osmocore/talloc.h>
+#include <osmocore/utils.h>
 
 extern struct log_target *stderr_target;
 extern void *l23_ctx;
@@ -82,6 +84,16 @@ static int l23_cfg_supported()
        return L23_OPT_TAP | L23_OPT_DBG;
 }
 
+static int l23_getopt_options(struct option **options)
+{
+       static struct option opts [] = {
+               {"logfile", 1, 0, 'l'},
+       };
+
+       *options = opts;
+       return ARRAY_SIZE(opts);
+}
+
 static int l23_cfg_print_help()
 {
        printf("\nApplication specific\n");
@@ -104,6 +116,7 @@ static struct l23_app_info info = {
        .copyright      = "Copyright (C) 2010 Andreas Eversberg\n",
        .getopt_string  = "l:",
        .cfg_supported  = l23_cfg_supported,
+       .cfg_getopt_opt = l23_getopt_options,
        .cfg_handle_opt = l23_cfg_handle,
        .cfg_print_help = l23_cfg_print_help,
 };