From: Mark Atwood Date: Wed, 19 Sep 2007 09:17:32 +0000 (-0700) Subject: getopt_long added to src/memcat.c X-Git-Tag: 0.2~22^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=21fc482405fde4edd7985c3b0ea30f6b0c4069cb;p=awesomized%2Flibmemcached getopt_long added to src/memcat.c --- diff --git a/src/memcat.c b/src/memcat.c index ba20f3e7..134017fa 100644 --- a/src/memcat.c +++ b/src/memcat.c @@ -1,29 +1,69 @@ #include +#include +#include #include +static int opt_verbose; +static int opt_displayflag; +static char *opt_servers; + int main(int argc, char *argv[]) { memcached_st *memc; char *string; - unsigned int x; size_t string_length; uint16_t flags; memcached_return rc; - if (argc == 1) - return 0; + static struct option long_options[] = + { + {"version", no_argument, NULL, 257}, + {"help", no_argument, NULL, 258}, + {"verbose", no_argument, &opt_verbose, 1}, + {"debug", no_argument, &opt_verbose, 2}, + {"servers", required_argument, NULL, 259}, + {"flag", no_argument, &opt_displayflag, 1}, + {0, 0, 0, 0}, + }; + int option_index = 0; + int option_rv; + + while (1) { + option_rv = getopt_long(argc, argv, "", long_options, &option_index); + if (option_rv == -1) break; + switch (option_rv) { + case 0: + break; + case 257: /* --version */ + printf("memcache tools, memcat, v1.0\n"); + exit(0); + break; + case 258: /* --help */ + printf("useful help messages go here\n"); + exit(0); + break; + case 259: /* --servers */ + opt_servers = strdup(optarg); + break; + case '?': + /* getopt_long already printed an error message. */ + exit(1); + default: + abort(); + } + } + /* todo, turn opt_servers into something to pass to memcached_init */ memc= memcached_init(NULL); - for (x= 1; x <= argc; x++) - { - string= memcached_get(memc, argv[1], strlen(argv[1]), + while (optind < argc) { + string= memcached_get(memc, argv[optind], strlen(argv[optind]), &string_length, &flags, &rc); - if (string) - { + if (string) { printf("%.*s\n", string_length, string); free(string); } + optind++; } memcached_deinit(memc); diff --git a/tests/test.c b/tests/test.c index 9c93a87b..020bfc53 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,4 +1,3 @@ -#include /* Sample test application. */