ec2fad9b2d45f8ebf085480035ec0adcb80b7d88
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
);
29 parse_opt_servers(memc
, opt_servers
);
31 while (optind
<= argc
)
33 string
= memcached_get(memc
, argv
[argc
], strlen(argv
[argc
]),
34 &string_length
, &flags
, &rc
);
35 if (rc
== MEMCACHED_SUCCESS
)
40 printf("key: %.*s\nflags: ", argv
[argc
]);
41 printf("%d\n", flags
);
46 printf("key: %.*s\nflags: %d\nlength: %d\nvalue: ",
47 argv
[argc
], flags
, string_length
);
48 printf("%.*s\n", string_length
, string
);
54 fprintf(stderr
, "memcat: %s: memcache error %s\n",
55 argv
[argc
], memcached_strerror(memc
, rc
));
60 memcached_deinit(memc
);
66 void options_parse(int argc
, char *argv
[])
71 static struct option long_options
[] =
73 {"version", no_argument
, NULL
, OPT_VERSION
},
74 {"help", no_argument
, NULL
, OPT_HELP
},
75 {"verbose", no_argument
, &opt_verbose
, 1},
76 {"debug", no_argument
, &opt_verbose
, 2},
77 {"servers", required_argument
, NULL
, OPT_SERVERS
},
78 {"flag", no_argument
, &opt_displayflag
, OPT_FLAG
},
84 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
85 if (option_rv
== -1) break;
89 case OPT_VERSION
: /* --version or -V */
90 printf("memcache tools, memcat, v1.0\n");
93 case OPT_HELP
: /* --help or -h */
94 printf("useful help messages go here\n");
97 case OPT_SERVERS
: /* --servers or -s */
101 /* getopt_long already printed an error message. */