5 #include "client_options.h"
7 static int opt_verbose
;
8 static int opt_displayflag
;
9 static char *opt_servers
;
11 struct memcached_st
*parse_opt_servers (struct memcached_st
*m
,
16 while (s
= strsep(&opt_servers
, ",")) {
17 hostname
= strsep(&s
, ":");
19 memcached_server_add(m
, hostname
, portnum
);
24 int main(int argc
, char *argv
[])
32 static struct option long_options
[] =
34 {"version", no_argument
, NULL
, OPT_VERSION
},
35 {"help", no_argument
, NULL
, OPT_HELP
},
36 {"verbose", no_argument
, &opt_verbose
, 1},
37 {"debug", no_argument
, &opt_verbose
, 2},
38 {"servers", required_argument
, NULL
, OPT_SERVERS
},
39 {"flag", no_argument
, &opt_displayflag
, OPT_FLAG
},
47 option_rv
= getopt_long(argc
, argv
, "", long_options
, &option_index
);
48 if (option_rv
== -1) break;
52 case OPT_VERSION
: /* --version */
53 printf("memcache tools, memcat, v1.0\n");
56 case OPT_HELP
: /* --help */
57 printf("useful help messages go here\n");
60 case OPT_SERVERS
: /* --servers */
61 opt_servers
= strdup(optarg
);
64 /* getopt_long already printed an error message. */
71 memc
= memcached_init(NULL
);
72 memc
= parse_opt_servers(memc
, opt_servers
);
74 while (optind
< argc
) {
75 string
= memcached_get(memc
, argv
[optind
], strlen(argv
[optind
]),
76 &string_length
, &flags
, &rc
);
77 if (rc
== MEMCACHED_SUCCESS
) {
78 if (opt_displayflag
) {
79 printf("%d\n", flags
);
83 printf("%.*s\n", string_length
, string
);
92 memcached_deinit(memc
);