--- /dev/null
+#include <stdio.h>\r
+#include <unistd.h>\r
+#include <getopt.h>\r
+#include <memcached.h>\r
+#include "client_options.h"\r
+\r
+static int opt_verbose;\r
+static char *opt_servers;\r
+\r
+struct memcached_st *parse_opt_servers (struct memcached_st *m,\r
+ char *opt_servers)\r
+{\r
+ char *s, *hostname;\r
+ unsigned int portnum;\r
+ while (s = strsep(&opt_servers, ",")) {\r
+ hostname = strsep(&s, ":");\r
+ portnum = atoi(s);\r
+ memcached_server_add(m, hostname, portnum);\r
+ }\r
+ return m;\r
+}\r
+\r
+int main(int argc, char *argv[])\r
+{\r
+ memcached_st *memc;\r
+ char *string;\r
+ size_t string_length;\r
+ time_t expires = 0;\r
+ memcached_return rc;\r
+\r
+ static struct option long_options[] =\r
+ {\r
+ {"version", no_argument, NULL, OPT_VERSION},\r
+ {"help", no_argument, NULL, OPT_HELP},\r
+ {"verbose", no_argument, &opt_verbose, 1},\r
+ {"debug", no_argument, &opt_verbose, 2},\r
+ {"servers", required_argument, NULL, OPT_SERVERS},\r
+ {"expire", required_argument, NULL, OPT_EXPIRE},\r
+ {0, 0, 0, 0},\r
+ };\r
+ int option_index = 0;\r
+ int option_rv;\r
+\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 OPT_VERSION: /* --version */\r
+ printf("memcache tools, memrm, v1.0\n");\r
+ exit(0);\r
+ break;\r
+ case OPT_HELP: /* --help */\r
+ printf("useful help messages go here\n");\r
+ exit(0);\r
+ break;\r
+ case OPT_SERVERS: /* --servers */\r
+ opt_servers = strdup(optarg);\r
+ break;\r
+ case OPT_EXPIRE: /* --expire */\r
+ expires = (time_t)atoi(optarg);\r
+ break;\r
+ case '?':\r
+ /* getopt_long already printed an error message. */\r
+ exit(1);\r
+ default:\r
+ abort();\r
+ }\r
+ }\r
+\r
+ memc= memcached_init(NULL);\r
+ memc= parse_opt_servers(memc, opt_servers);\r
+ \r
+ while (optind <= argc) {\r
+\r
+ rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), expires);\r
+\r
+ optind++;\r
+ }\r
+\r
+ memcached_deinit(memc);\r
+\r
+ return 0;\r
+};\r