From bf9b037645a5943e3ba0220be55f7f875445bd5a Mon Sep 17 00:00:00 2001 From: laforge Date: Sun, 22 Oct 2006 14:05:53 +0000 Subject: some further gsmd/libgsmd work git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@96 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/util/libgsmd-tool.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/util/libgsmd-tool.c') diff --git a/src/util/libgsmd-tool.c b/src/util/libgsmd-tool.c index a3da490..e8590c1 100644 --- a/src/util/libgsmd-tool.c +++ b/src/util/libgsmd-tool.c @@ -8,13 +8,42 @@ #include +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + static struct lgsm_handle *lgsmh; static int verbose = 0; +enum mode_enum { + MODE_NONE, + MODE_SHELL, + MODE_EVENTLOG, +}; + +static char *modes[] = { + [MODE_NONE] = "", + [MODE_SHELL] = "shell", + [MODE_EVENTLOG] = "eventlog", +}; + +static int parse_mode(char *modestr) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(modes); i++) { + if (!strcmp(modes[i], modestr)) + return i; + } + + return -1; +} + static struct option opts[] = { { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, { "verbose", 0, 0, 'v' }, + { "mode", 1, 0, 'm' }, { 0, 0, 0, 0 } }; @@ -28,14 +57,14 @@ static void help(void) int main(int argc, char **argv) { - int rc, i; + int rc, i, mode; printf("libgsm-tool - (C) 2006 by Harald Welte\n" "This program is Free Software and has ABSOLUTELY NO WARRANTY\n\n"); while (1) { int c, option_index = 0; - c = getopt_long(argc, argv, "hVv", opts, &option_index); + c = getopt_long(argc, argv, "vVhm:", opts, &option_index); if (c == -1) break; @@ -50,6 +79,13 @@ int main(int argc, char **argv) help(); exit(0); break; + case 'm': + mode = parse_mode(optarg); + if (mode < 0) { + fprintf(stderr, "unknown/unsupported mode `%s'\n", optarg); + exit(2); + } + break; } } @@ -59,6 +95,11 @@ int main(int argc, char **argv) exit(1); } + switch (mode) { + case MODE_SHELL: + shell_main(lgsmh); + break; + } exit(0); } -- cgit v1.2.3