fix bug in calling parse_opt_servers
[awesomized/libmemcached] / src / memstat.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <sys/types.h>
5 #include <sys/mman.h>
6 #include <fcntl.h>
7 #include <getopt.h>
8
9 #include <memcached.h>
10
11 #include "client_options.h"
12 #include "utilities.h"
13
14 /* Prototypes */
15 void options_parse(int argc, char *argv[]);
16
17 static int opt_verbose;
18 static int opt_displayflag;
19 static char *opt_servers;
20
21 int main(int argc, char *argv[])
22 {
23 memcached_st *memc;
24
25 memc= memcached_init(NULL);
26 options_parse(argc, argv);
27
28 if (opt_servers)
29 parse_opt_servers(memc, opt_servers);
30
31 memcached_deinit(memc);
32
33 return 0;
34 }
35
36 void options_parse(int argc, char *argv[])
37 {
38 static struct option long_options[]=
39 {
40 {"version", no_argument, NULL, OPT_VERSION},
41 {"help", no_argument, NULL, OPT_HELP},
42 {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
43 {"debug", no_argument, &opt_verbose, OPT_DEBUG},
44 {"servers", required_argument, NULL, OPT_SERVERS},
45 {"flag", no_argument, &opt_displayflag, OPT_FLAG},
46 {0, 0, 0, 0},
47 };
48
49 int option_index= 0;
50 int option_rv;
51
52 while (1)
53 {
54 option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
55 if (option_rv == -1) break;
56 switch (option_rv)
57 {
58 case 0:
59 break;
60 case OPT_VERBOSE: /* --verbose or -v */
61 opt_verbose = OPT_VERBOSE;
62 break;
63 case OPT_DEBUG: /* --debug or -d */
64 opt_verbose = OPT_DEBUG;
65 break;
66 case OPT_VERSION: /* --version or -V */
67 printf("memcache tools, memcat, v1.0\n");
68 exit(0);
69 break;
70 case OPT_HELP: /* --help or -h */
71 printf("useful help messages go here\n");
72 exit(0);
73 break;
74 case OPT_SERVERS: /* --servers or -s */
75 opt_servers= optarg;
76 break;
77 case '?':
78 /* getopt_long already printed an error message. */
79 exit(1);
80 default:
81 abort();
82 }
83 }
84 }