6 #include "client_options.h"
11 void options_parse(int argc
, char *argv
[]);
13 static int opt_verbose
= 0;
14 static int opt_displayflag
= 0;
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("%x\n", flags
);
47 printf("key: %s\nflags: %x\nlength: %zu\nvalue: ",
48 argv
[optind
], flags
, string_length
);
49 printf("%.*s\n", (int)string_length
, string
);
55 fprintf(stderr
, "memcat: %s: memcache error %s\n",
56 argv
[optind
], memcached_strerror(memc
, rc
));
61 memcached_deinit(memc
);
69 void options_parse(int argc
, char *argv
[])
74 static struct option long_options
[]=
76 {"version", no_argument
, NULL
, OPT_VERSION
},
77 {"help", no_argument
, NULL
, OPT_HELP
},
78 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
79 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
80 {"servers", required_argument
, NULL
, OPT_SERVERS
},
81 {"flag", no_argument
, &opt_displayflag
, OPT_FLAG
},
87 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
88 if (option_rv
== -1) break;
93 case OPT_VERBOSE
: /* --verbose or -v */
94 opt_verbose
= OPT_VERBOSE
;
96 case OPT_DEBUG
: /* --debug or -d */
97 opt_verbose
= OPT_DEBUG
;
99 case OPT_VERSION
: /* --version or -V */
100 printf("memcache tools, memcat, v1.0\n");
103 case OPT_HELP
: /* --help or -h */
104 printf("useful help messages go here\n");
107 case OPT_SERVERS
: /* --servers or -s */
108 opt_servers
= strdup(optarg
);
111 /* getopt_long already printed an error message. */