bugfixes and formating fixes
[awesomized/libmemcached] / src / memrm.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <getopt.h>
4 #include <memcached.h>
5 #include "client_options.h"
6
7 static int opt_verbose;
8 static char *opt_servers;
9
10 int main(int argc, char *argv[])
11 {
12 memcached_st *memc;
13 char *string;
14 size_t string_length;
15 time_t expires= 0;
16 memcached_return rc;
17
18 static struct option long_options[]=
19 {
20 {"version", no_argument, NULL, OPT_VERSION},
21 {"help", no_argument, NULL, OPT_HELP},
22 {"verbose", no_argument, &opt_verbose, 1},
23 {"debug", no_argument, &opt_verbose, 2},
24 {"servers", required_argument, NULL, OPT_SERVERS},
25 {"expire", required_argument, NULL, OPT_EXPIRE},
26 {0, 0, 0, 0},
27 };
28 int option_index= 0;
29 int option_rv;
30
31 while (1)
32 {
33 option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
34 if (option_rv == -1) break;
35 switch (option_rv)
36 {
37 case 0:
38 break;
39 case OPT_VERSION: /* --version or -V */
40 printf("memcache tools, memrm, v1.0\n");
41 exit(0);
42 break;
43 case OPT_HELP: /* --help or -h */
44 printf("useful help messages go here\n");
45 exit(0);
46 break;
47 case OPT_SERVERS: /* --servers or -s */
48 opt_servers= optarg;
49 break;
50 case OPT_EXPIRE: /* --expire */
51 expires= (time_t)strtol(optarg, (char **)NULL, 10);
52 break;
53 case '?':
54 /* getopt_long already printed an error message. */
55 exit(1);
56 default:
57 abort();
58 }
59 }
60
61 memc= memcached_init(NULL);
62 parse_opt_servers(memc, opt_servers);
63
64 while (optind <= argc)
65 {
66 if (opt_verbose)
67 printf("key: %s\nexpires: %ld\n", argv[optind], expires);
68
69 rc= memcached_delete(memc, argv[optind], strlen(argv[optind]), expires);
70
71 if (rc != MEMCACHED_SUCCESS)
72 fprintf(stderr, "memrm: %s: memcache error %s\n",
73 argv[optind], memcached_strerror(memc, rc));
74
75 optind++;
76 }
77
78 memcached_deinit(memc);
79
80 return 0;
81 }