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.
21 #include <libmemcached/memcached.h>
23 #include "utilities.h"
25 #define PROGRAM_NAME "memerror"
26 #define PROGRAM_DESCRIPTION "Translate a memcached errror code into a string."
30 void options_parse(int argc
, char *argv
[]);
32 static int opt_verbose
= 0;
34 int main(int argc
, char *argv
[])
36 options_parse(argc
, argv
);
43 unsigned long value
= strtoul(argv
[1], (char **) NULL
, 10);
45 if (value
< MEMCACHED_MAXIMUM_RETURN
)
47 std::cout
<< memcached_strerror(NULL
, (memcached_return_t
)value
) << std::endl
;
51 std::cerr
<< memcached_strerror(NULL
, MEMCACHED_MAXIMUM_RETURN
) << std::endl
;
59 void options_parse(int argc
, char *argv
[])
61 static struct option long_options
[]=
63 {(OPTIONSTRING
)"version", no_argument
, NULL
, OPT_VERSION
},
64 {(OPTIONSTRING
)"help", no_argument
, NULL
, OPT_HELP
},
65 {(OPTIONSTRING
)"quiet", no_argument
, NULL
, OPT_QUIET
},
66 {(OPTIONSTRING
)"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
67 {(OPTIONSTRING
)"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
71 bool opt_version
= false;
76 int option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
87 case OPT_VERBOSE
: /* --verbose or -v */
88 opt_verbose
= OPT_VERBOSE
;
91 case OPT_DEBUG
: /* --debug or -d */
92 opt_verbose
= OPT_DEBUG
;
95 case OPT_VERSION
: /* --version or -V */
99 case OPT_HELP
: /* --help or -h */
108 /* getopt_long already printed an error message. */
118 version_command(PROGRAM_NAME
);
124 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, NULL
);