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/Makefile.am | 2 +- src/util/libgsmd-tool.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- src/util/shell.c | 25 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/util/shell.c (limited to 'src/util') 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 +#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 +#include + +#include + +#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); + } +} -- cgit v1.2.3