645b54ac3d762f7459823e835f6d5b1fda16e47c
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
[])
33 static struct option long_options
[] =
35 {"version", no_argument
, NULL
, OPT_VERSION
},
36 {"help", no_argument
, NULL
, OPT_HELP
},
37 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
38 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
39 {"servers", required_argument
, NULL
, OPT_SERVERS
},
40 {"flag", no_argument
, &opt_displayflag
, OPT_FLAG
},
48 option_rv
= getopt_long(argc
, argv
, "", long_options
, &option_index
);
49 if (option_rv
== -1) break;
53 case OPT_VERSION
: /* --version */
54 printf("memcache tools, memcat, v1.0\n");
57 case OPT_HELP
: /* --help */
58 printf("useful help messages go here\n");
61 case OPT_SERVERS
: /* --servers */
62 opt_servers
= strdup(optarg
);
65 /* getopt_long already printed an error message. */
72 memc
= malloc(sizeof(struct memcached_st
));
74 memc
= parse_opt_servers(memc
, opt_servers
);
75 memc
= memcached_init(memc
);
77 for (x
= 1; x
< argc
; x
++)
79 string
= memcached_get(memc
, argv
[x
], strlen(argv
[x
]),
80 &string_length
, &flags
, &rc
);
81 if (rc
== MEMCACHED_SUCCESS
) {
82 if (opt_displayflag
) {
83 printf("%d\n", flags
);
87 printf("%.*s\n", string_length
, string
);
94 memcached_deinit(memc
);