#include <stdio.h>\r
+#include <unistd.h>\r
+#include <getopt.h>\r
#include <memcached.h>\r
\r
+static int opt_verbose;\r
+static int opt_displayflag;\r
+static char *opt_servers;\r
+\r
int main(int argc, char *argv[])\r
{\r
memcached_st *memc;\r
char *string;\r
- unsigned int x;\r
size_t string_length;\r
uint16_t flags;\r
memcached_return rc;\r
\r
- if (argc == 1)\r
- return 0;\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
+ {0, 0, 0, 0},\r
+ };\r
+ int option_index = 0;\r
+ int option_rv;\r
+\r
+ while (1) {\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
+ printf("memcache tools, memcat, v1.0\n");\r
+ exit(0);\r
+ break;\r
+ case 258: /* --help */\r
+ printf("useful help messages go here\n");\r
+ exit(0);\r
+ break;\r
+ case 259: /* --servers */\r
+ opt_servers = strdup(optarg);\r
+ break;\r
+ case '?':\r
+ /* getopt_long already printed an error message. */\r
+ exit(1);\r
+ default:\r
+ abort();\r
+ }\r
+ }\r
\r
+ /* todo, turn opt_servers into something to pass to memcached_init */\r
memc= memcached_init(NULL);\r
\r
- for (x= 1; x <= argc; x++)\r
- {\r
- string= memcached_get(memc, argv[1], strlen(argv[1]),\r
+ while (optind < argc) {\r
+ string= memcached_get(memc, argv[optind], strlen(argv[optind]),\r
&string_length, &flags, &rc);\r
- if (string)\r
- {\r
+ if (string) {\r
printf("%.*s\n", string_length, string);\r
free(string);\r
}\r
+ optind++;\r
}\r
\r
memcached_deinit(memc);\r