X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fmemcat.c;h=dedcb94595e5bc79f9417c0cefaffe17aeaa68f6;hb=6030db2543337976c1df861272ce90b25ef83820;hp=77c0f8586829348619b1c4081391254665ab3d32;hpb=aadeadec9c2ca09c41a5dc2d63a34c465d39df3a;p=awesomized%2Flibmemcached diff --git a/src/memcat.c b/src/memcat.c index 77c0f858..dedcb945 100644 --- a/src/memcat.c +++ b/src/memcat.c @@ -2,7 +2,13 @@ #include #include #include + #include "client_options.h" +#include "utilities.h" + + +/* Prototypes */ +void options_parse(int argc, char *argv[]); static int opt_verbose; static int opt_displayflag; @@ -17,6 +23,40 @@ int main(int argc, char *argv[]) memcached_return rc; unsigned int x; + memc= memcached_init(NULL); + + options_parse(argc, argv); + + parse_opt_servers(memc, opt_servers); + + for (x= 1; x < argc; x++) + { + string= memcached_get(memc, argv[x], strlen(argv[x]), + &string_length, &flags, &rc); + if (rc == MEMCACHED_SUCCESS) { + if (opt_displayflag) { + printf("%d\n", flags); + } else { + if (string) + { + printf("%.*s\n", string_length, string); + free(string); + } + } + } + } + + memcached_deinit(memc); + + return 0; +}; + + +void options_parse(int argc, char *argv[]) +{ + int option_index = 0; + int option_rv; + static struct option long_options[] = { {"version", no_argument, NULL, OPT_VERSION}, @@ -27,8 +67,6 @@ int main(int argc, char *argv[]) {"flag", no_argument, &opt_displayflag, OPT_FLAG}, {0, 0, 0, 0}, }; - int option_index = 0; - int option_rv; while (1) { @@ -46,7 +84,7 @@ int main(int argc, char *argv[]) exit(0); break; case OPT_SERVERS: /* --servers */ - opt_servers = strdup(optarg); + opt_servers= strdup(optarg); break; case '?': /* getopt_long already printed an error message. */ @@ -55,22 +93,4 @@ int main(int argc, char *argv[]) abort(); } } - - /* todo, turn opt_servers into something to pass to memcached_init */ - memc= memcached_init(NULL); - - for (x= 1; x < argc; x++) - { - string= memcached_get(memc, argv[x], strlen(argv[x]), - &string_length, &flags, &rc); - if (string) - { - printf("%.*s\n", string_length, string); - free(string); - } - } - - memcached_deinit(memc); - - return 0; -}; +}