4253aa00fc2663e0a4ab6804f9eb7f9d100f93c7
6 #include "client_options.h"
11 void options_parse(int argc
, char *argv
[]);
13 static int opt_verbose
;
14 static int opt_displayflag
;
15 static char *opt_servers
;
17 int main(int argc
, char *argv
[])
25 memc
= memcached_init(NULL
);
27 options_parse(argc
, argv
);
30 parse_opt_servers(memc
, opt_servers
);
32 while (optind
<= argc
)
34 string
= memcached_get(memc
, argv
[optind
], strlen(argv
[optind
]),
35 &string_length
, &flags
, &rc
);
36 if (rc
== MEMCACHED_SUCCESS
)
41 printf("key: %s\nflags: ", argv
[optind
]);
42 printf("%u\n", flags
);
47 printf("key: %s\nflags: %u\nlength: %uz\nvalue: ",
48 argv
[optind
], flags
, string_length
);
49 printf("%.*s\n", string_length
, string
);
55 fprintf(stderr
, "memcat: %s: memcache error %s\n",
56 argv
[optind
], memcached_strerror(memc
, rc
));
61 memcached_deinit(memc
);
67 void options_parse(int argc
, char *argv
[])
72 static struct option long_options
[] =
74 {"version", no_argument
, NULL
, OPT_VERSION
},
75 {"help", no_argument
, NULL
, OPT_HELP
},
76 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
77 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
78 {"servers", required_argument
, NULL
, OPT_SERVERS
},
79 {"flag", no_argument
, &opt_displayflag
, OPT_FLAG
},
85 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
86 if (option_rv
== -1) break;
90 case OPT_VERSION
: /* --version or -V */
91 printf("memcache tools, memcat, v1.0\n");
94 case OPT_HELP
: /* --help or -h */
95 printf("useful help messages go here\n");
98 case OPT_SERVERS
: /* --servers or -s */
102 /* getopt_long already printed an error message. */