2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
19 #include <libmemcached/memcached.h>
21 #include "utilities.h"
23 #define PROGRAM_NAME "memerror"
24 #define PROGRAM_DESCRIPTION "Translate a memcached errror code into a string."
28 void options_parse(int argc
, char *argv
[]);
30 static int opt_verbose
= 0;
32 int main(int argc
, char *argv
[])
35 options_parse(argc
, argv
);
40 value
= strtoul(argv
[1], (char **) NULL
, 10);
42 if (value
< MEMCACHED_MAXIMUM_RETURN
)
44 printf("%s\n", memcached_strerror(NULL
, (memcached_return_t
)value
));
48 fprintf(stderr
, "Unknown Error Code\n");
56 void options_parse(int argc
, char *argv
[])
61 memcached_programs_help_st help_options
[]=
66 static struct option long_options
[]=
68 {(OPTIONSTRING
)"version", no_argument
, NULL
, OPT_VERSION
},
69 {(OPTIONSTRING
)"help", no_argument
, NULL
, OPT_HELP
},
70 {(OPTIONSTRING
)"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
71 {(OPTIONSTRING
)"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
77 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
78 if (option_rv
== -1) break;
83 case OPT_VERBOSE
: /* --verbose or -v */
84 opt_verbose
= OPT_VERBOSE
;
86 case OPT_DEBUG
: /* --debug or -d */
87 opt_verbose
= OPT_DEBUG
;
89 case OPT_VERSION
: /* --version or -V */
90 version_command(PROGRAM_NAME
);
92 case OPT_HELP
: /* --help or -h */
93 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, help_options
);
96 /* getopt_long already printed an error message. */