From: Date: Wed, 19 Sep 2007 09:55:18 +0000 (+0200) Subject: Merge from Mark's code. Modified memcat to use enum for options. X-Git-Tag: 0.2~22 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=aadeadec9c2ca09c41a5dc2d63a34c465d39df3a;p=awesomized%2Flibmemcached Merge from Mark's code. Modified memcat to use enum for options. --- aadeadec9c2ca09c41a5dc2d63a34c465d39df3a diff --cc src/client_options.h index 00000000,00000000..354b2736 new file mode 100644 --- /dev/null +++ b/src/client_options.h @@@ -1,0 -1,0 +1,8 @@@ ++typedef enum { ++ OPT_SERVERS= 1, ++ OPT_VERSION, ++ OPT_HELP, ++ OPT_VERBOSE, ++ OPT_DEBUG, ++ OPT_FLAG, ++} memcached_options; diff --cc src/memcat.c index 0fc38d6c,134017fa..77c0f858 --- a/src/memcat.c +++ b/src/memcat.c @@@ -1,5 -1,11 +1,12 @@@ #include + #include + #include #include ++#include "client_options.h" + + static int opt_verbose; + static int opt_displayflag; + static char *opt_servers; int main(int argc, char *argv[]) { @@@ -8,19 -14,52 +15,56 @@@ size_t string_length; uint16_t flags; memcached_return rc; ++ unsigned int x; + + 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}, ++ {"version", no_argument, NULL, OPT_VERSION}, ++ {"help", no_argument, NULL, OPT_HELP}, ++ {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, ++ {"debug", no_argument, &opt_verbose, OPT_DEBUG}, ++ {"servers", required_argument, NULL, OPT_SERVERS}, ++ {"flag", no_argument, &opt_displayflag, OPT_FLAG}, + {0, 0, 0, 0}, + }; + int option_index = 0; + int option_rv; - if (argc == 1) - return 0; - while (1) { ++ 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 */ ++ case OPT_VERSION: /* --version */ + printf("memcache tools, memcat, v1.0\n"); + exit(0); + break; - case 258: /* --help */ ++ case OPT_HELP: /* --help */ + printf("useful help messages go here\n"); + exit(0); + break; - case 259: /* --servers */ ++ case OPT_SERVERS: /* --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); - while (optind < argc) { - string= memcached_get(memc, argv[optind], strlen(argv[optind]), + for (x= 1; x < argc; x++) + { + string= memcached_get(memc, argv[x], strlen(argv[x]), &string_length, &flags, &rc); - if (string) - if (string) { ++ if (string) + { printf("%.*s\n", string_length, string); free(string); }