--- /dev/null
+#include <stdio.h>\r
+#include <unistd.h>\r
+#include <getopt.h>\r
+#include <memcached.h>\r
+#include "client_options.h"\r
+#include "utilities.h"\r
+\r
+static int opt_verbose= 0;\r
+static time_t opt_expire= 0;\r
+static char *opt_servers= NULL;\r
+\r
+/* Prototypes */\r
+void options_parse(int argc, char *argv[]);\r
+\r
+int main(int argc, char *argv[])\r
+{\r
+ memcached_st *memc;\r
+ memcached_return rc;\r
+ WATCHPOINT;\r
+ options_parse(argc, argv);\r
+ WATCHPOINT;\r
+\r
+ memc= memcached_init(NULL);\r
+ WATCHPOINT;\r
+\r
+ if (opt_servers)\r
+ parse_opt_servers(memc, opt_servers);\r
+ WATCHPOINT;\r
+ \r
+ rc = memcached_flush(memc, opt_expire);\r
+ WATCHPOINT;\r
+\r
+ if (rc != MEMCACHED_SUCCESS) \r
+ {\r
+ fprintf(stderr, "memflush: %s: memcache error %s\n", \r
+ argv[optind], memcached_strerror(memc, rc));\r
+ }\r
+ WATCHPOINT;\r
+\r
+ memcached_deinit(memc);\r
+ WATCHPOINT;\r
+\r
+ free(opt_servers);\r
+ WATCHPOINT;\r
+\r
+ return 0;\r
+}\r
+\r
+\r
+void options_parse(int argc, char *argv[])\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, OPT_VERBOSE},\r
+ {"debug", no_argument, &opt_verbose, OPT_DEBUG},\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, "Vhvds:", long_options, &option_index);\r
+ if (option_rv == -1) break;\r
+ switch (option_rv)\r
+ {\r
+ case 0:\r
+ break;\r
+ case OPT_VERBOSE: /* --verbose or -v */\r
+ opt_verbose = OPT_VERBOSE;\r
+ break;\r
+ case OPT_DEBUG: /* --debug or -d */\r
+ opt_verbose = OPT_DEBUG;\r
+ break;\r
+ case OPT_VERSION: /* --version or -V */\r
+ printf("memcache tools, memflush, v1.0\n");\r
+ exit(0);\r
+ break;\r
+ case OPT_HELP: /* --help or -h */\r
+ printf("useful help messages go here\n");\r
+ exit(0);\r
+ break;\r
+ case OPT_SERVERS: /* --servers or -s */\r
+ opt_servers= strdup(optarg);\r
+ break;\r
+ case OPT_EXPIRE: /* --expire */\r
+ opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);\r
+ break;\r
+ case '?':\r
+ /* getopt_long already printed an error message. */\r
+ exit(1);\r
+ default:\r
+ abort();\r
+ }\r
+ }\r
+}\r