example: add common FP command line option parser
Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
parent
89de310021
commit
aeff319a24
|
@ -9,6 +9,7 @@ PROGRAMS += pp-wait-page
|
|||
destdir := usr/share/dect/examples
|
||||
|
||||
common-obj += common.o event_ops.o keys.o dummy_ops.o debug.o
|
||||
fp-common-obj += $(common-obj) fp-common.o
|
||||
pp-common-obj += $(common-obj) pp-common.o pp-auth.o
|
||||
|
||||
ss-destdir := $(destdir)
|
||||
|
@ -16,21 +17,21 @@ ss-obj += $(common-obj)
|
|||
ss-obj += ss.o
|
||||
|
||||
fp-mm-destdir := $(destdir)
|
||||
fp-mm-obj += $(common-obj)
|
||||
fp-mm-obj += $(fp-common-obj)
|
||||
fp-mm-obj += fp-mm.o
|
||||
|
||||
fp-cc-destdir := $(destdir)
|
||||
fp-cc-obj += $(common-obj)
|
||||
fp-cc-obj += $(fp-common-obj)
|
||||
fp-cc-obj += audio.o
|
||||
fp-cc-obj += fp-cc.o
|
||||
fp-cc-ldflags += -lSDL
|
||||
|
||||
fp-clms-destdir := $(destdir)
|
||||
fp-clms-obj += $(common-obj)
|
||||
fp-clms-obj += $(fp-common-obj)
|
||||
fp-clms-obj += fp-clms.o
|
||||
|
||||
fp-broadcast-page-destdir := $(destdir)
|
||||
fp-broadcast-page-obj += $(common-obj)
|
||||
fp-broadcast-page-obj += $(fp-common-obj)
|
||||
fp-broadcast-page-obj += fp-broadcast-page.o
|
||||
|
||||
pp-access-rights-destdir := $(destdir)
|
||||
|
|
|
@ -26,6 +26,8 @@ extern int dect_write_uak(const struct dect_ipui *ipui,
|
|||
extern int dect_read_uak(const struct dect_ipui *ipui,
|
||||
uint8_t uak[DECT_AUTH_KEY_LEN]);
|
||||
|
||||
extern void dect_fp_common_options(int argc, char **argv);
|
||||
|
||||
extern void dect_pp_auth_init(struct dect_ops *ops,
|
||||
const struct dect_ipui *ipui);
|
||||
extern void dect_pp_common_init(struct dect_ops *ops, const char *cluster,
|
||||
|
|
|
@ -9,7 +9,8 @@ static struct dect_ops ops;
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
dect_common_init(&ops, argv[1]);
|
||||
dect_fp_common_options(argc, argv);
|
||||
dect_common_init(&ops, cluster);
|
||||
|
||||
dect_lce_group_ring_req(dh, 0);
|
||||
dect_event_loop();
|
||||
|
|
|
@ -216,7 +216,8 @@ static struct dect_ops ops = {
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
dect_common_init(&ops, argv[1]);
|
||||
dect_fp_common_options(argc, argv);
|
||||
dect_common_init(&ops, cluster);
|
||||
|
||||
dect_open_call(dh, &ipui);
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ static struct dect_ops ops;
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
dect_common_init(&ops, argv[1]);
|
||||
dect_fp_common_options(argc, argv);
|
||||
dect_common_init(&ops, cluster);
|
||||
|
||||
dect_invoke_clms(dh);
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* DECT PP common functions
|
||||
*
|
||||
* Copyright (c) 2010 Patrick McHardy <kaber@trash.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <getopt.h>
|
||||
#include "common.h"
|
||||
|
||||
enum {
|
||||
OPT_CLUSTER,
|
||||
OPT_HELP,
|
||||
};
|
||||
|
||||
static const struct option options[] = {
|
||||
{ .name = "cluster", .has_arg = true, .flag = NULL, .val = OPT_CLUSTER },
|
||||
{ .name = "help", .has_arg = false, .flag = NULL, .val = OPT_HELP },
|
||||
|
||||
{ },
|
||||
};
|
||||
|
||||
void dect_fp_common_options(int argc, char **argv)
|
||||
{
|
||||
int optidx = 0, c;
|
||||
|
||||
for (;;) {
|
||||
c = getopt_long(argc, argv, "c:h", options, &optidx);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case OPT_CLUSTER:
|
||||
cluster = optarg;
|
||||
break;
|
||||
case OPT_HELP:
|
||||
printf("%s: [ -c/--cluster NAME ] [ -h/--help ]\n",
|
||||
argv[0]);
|
||||
exit(0);
|
||||
case '?':
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -219,7 +219,8 @@ int main(int argc, char **argv)
|
|||
if (rand_fd < 0)
|
||||
pexit("open /dev/urandom");
|
||||
|
||||
dect_common_init(&ops, argv[1]);
|
||||
dect_fp_common_options(argc, argv);
|
||||
dect_common_init(&ops, cluster);
|
||||
|
||||
dect_event_loop();
|
||||
|
||||
|
|
Reference in New Issue