diff options
author | laforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2006-10-22 14:05:53 +0000 |
---|---|---|
committer | laforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2006-10-22 14:05:53 +0000 |
commit | bf9b037645a5943e3ba0220be55f7f875445bd5a (patch) | |
tree | 56083023e677d9ffaedbaac1d847c742db9dff39 /src/util | |
parent | 8045fdfb09c2e3b466f371b2ab64ff01f9f7aec1 (diff) |
some further gsmd/libgsmd work
git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@96 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 2 | ||||
-rw-r--r-- | src/util/libgsmd-tool.c | 45 | ||||
-rw-r--r-- | src/util/shell.c | 25 |
3 files changed, 69 insertions, 3 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index bb257f5..bec625a 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -3,7 +3,7 @@ AM_CFLAGS = -std=gnu99 bin_PROGRAMS = libgsmd-tool -libgsmd_tool_SOURCES = libgsmd-tool.c +libgsmd_tool_SOURCES = libgsmd-tool.c shell.c libgsmd_tool_LDADD = ../libgsmd/libgsmd.la libgsmd_tool_LDFLAGS = -dynamic 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 <libgsmd/libgsmd.h> +#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); } diff --git a/src/util/shell.c b/src/util/shell.c new file mode 100644 index 0000000..eb1991d --- /dev/null +++ b/src/util/shell.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <string.h> + +#include <libgsmd/libgsmd.h> + +#define STDIN_BUF_SIZE 1024 + +int shell_main(struct lgsmd_handle *lgsmh) +{ + int rc; + char buf[STDIN_BUF_SIZE+1]; + + while (1) { + rc = fscanf(stdin, "%s", buf); + if (rc == EOF) { + printf("EOF\n"); + return -1; + } + if (rc <= 0) { + printf("NULL\n"); + continue; + } + printf("STR=`%s'\n", buf); + } +} |