#include <unistd.h>\r
#include <getopt.h>\r
#include <memcached.h>\r
+#include "client_options.h"\r
\r
static int opt_verbose;\r
static int opt_displayflag;\r
size_t string_length;\r
uint16_t flags;\r
memcached_return rc;\r
+ unsigned int x;\r
\r
static struct option long_options[] =\r
{\r
- {"version", no_argument, NULL, 257},\r
- {"help", no_argument, NULL, 258},\r
- {"verbose", no_argument, &opt_verbose, 1},\r
- {"debug", no_argument, &opt_verbose, 2},\r
- {"servers", required_argument, NULL, 259},\r
- {"flag", no_argument, &opt_displayflag, 1},\r
+ {"version", no_argument, NULL, OPT_VERSION},\r
+ {"help", no_argument, NULL, OPT_HELP},\r
+ {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},\r
+ {"debug", no_argument, &opt_verbose, OPT_DEBUG},\r
+ {"servers", required_argument, NULL, OPT_SERVERS},\r
+ {"flag", no_argument, &opt_displayflag, OPT_FLAG},\r
{0, 0, 0, 0},\r
};\r
int option_index = 0;\r
int option_rv;\r
\r
- while (1) {\r
+ while (1) \r
+ {\r
option_rv = getopt_long(argc, argv, "", long_options, &option_index);\r
if (option_rv == -1) break;\r
switch (option_rv) {\r
case 0:\r
break;\r
- case 257: /* --version */\r
+ case OPT_VERSION: /* --version */\r
printf("memcache tools, memcat, v1.0\n");\r
exit(0);\r
break;\r
- case 258: /* --help */\r
+ case OPT_HELP: /* --help */\r
printf("useful help messages go here\n");\r
exit(0);\r
break;\r
- case 259: /* --servers */\r
+ case OPT_SERVERS: /* --servers */\r
opt_servers = strdup(optarg);\r
break;\r
case '?':\r
/* todo, turn opt_servers into something to pass to memcached_init */\r
memc= memcached_init(NULL);\r
\r
- while (optind < argc) {\r
- string= memcached_get(memc, argv[optind], strlen(argv[optind]),\r
+ for (x= 1; x < argc; x++)\r
+ {\r
+ string= memcached_get(memc, argv[x], strlen(argv[x]),\r
&string_length, &flags, &rc);\r
- if (string) {\r
+ if (string) \r
+ {\r
printf("%.*s\n", string_length, string);\r
free(string);\r
}\r
- optind++;\r
}\r
\r
memcached_deinit(memc);\r