bc81cb07f195f375444e645d46c61eef4d71e048
11 #include "client_options.h"
12 #include "utilities.h"
15 void options_parse(int argc
, char *argv
[]);
17 static int opt_verbose
= 0;
18 static int opt_displayflag
= 0;
19 static char *opt_servers
= NULL
;
21 int main(int argc
, char *argv
[])
25 memc
= memcached_init(NULL
);
26 options_parse(argc
, argv
);
32 memcached_stat_st
*stat
;
33 memcached_server_st
*server_list
;
35 parse_opt_servers(memc
, opt_servers
);
36 stat
= memcached_stat(memc
, NULL
, &rc
);
38 if (rc
!= MEMCACHED_SUCCESS
|| rc
!= MEMCACHED_SOME_ERRORS
);
40 printf("Failure to communicate with servers (%s)\n",
41 memcached_strerror(memc
, rc
));
45 server_list
= memcached_server_list(memc
);
47 printf("Listing %u Server\n\n", memcached_server_count(memc
));
48 for (x
= 0; x
< memcached_server_count(memc
); x
++)
53 list
= memcached_stat_get_keys(memc
, &stat
[x
], &rc
);
55 assert(rc
== MEMCACHED_SUCCESS
);
57 printf("Server: %s (%u)\n", memcached_server_name(memc
, server_list
[x
]),
58 memcached_server_port(memc
, server_list
[x
]));
59 for (ptr
= list
; *ptr
; ptr
++)
62 char *value
= memcached_stat_get_value(memc
, &stat
[x
], *ptr
, &rc
);
64 printf("\t %s: %s\n", *ptr
, value
);
76 memcached_deinit(memc
);
81 void options_parse(int argc
, char *argv
[])
83 static struct option long_options
[]=
85 {"version", no_argument
, NULL
, OPT_VERSION
},
86 {"help", no_argument
, NULL
, OPT_HELP
},
87 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
88 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
89 {"servers", required_argument
, NULL
, OPT_SERVERS
},
90 {"flag", no_argument
, &opt_displayflag
, OPT_FLAG
},
99 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
100 if (option_rv
== -1) break;
105 case OPT_VERBOSE
: /* --verbose or -v */
106 opt_verbose
= OPT_VERBOSE
;
108 case OPT_DEBUG
: /* --debug or -d */
109 opt_verbose
= OPT_DEBUG
;
111 case OPT_VERSION
: /* --version or -V */
112 printf("memcache tools, memcat, v1.0\n");
115 case OPT_HELP
: /* --help or -h */
116 printf("useful help messages go here\n");
119 case OPT_SERVERS
: /* --servers or -s */
120 opt_servers
= strdup(optarg
);
123 /* getopt_long already printed an error message. */