Ignore *.exe
[awesomized/libmemcached] / clients / memerror.c
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary:
9 *
10 */
11 #include "config.h"
12
13 #include <stdio.h>
14 #include <inttypes.h>
15 #include <string.h>
16 #include <unistd.h>
17 #include <getopt.h>
18 #include <stdlib.h>
19 #include <libmemcached/memcached.h>
20
21 #include "utilities.h"
22
23 #define PROGRAM_NAME "memerror"
24 #define PROGRAM_DESCRIPTION "Translate a memcached errror code into a string."
25
26
27 /* Prototypes */
28 void options_parse(int argc, char *argv[]);
29
30 static int opt_verbose= 0;
31
32 int main(int argc, char *argv[])
33 {
34 unsigned long value;
35 options_parse(argc, argv);
36
37 if (argc != 2)
38 return 1;
39
40 value= strtoul(argv[1], (char **) NULL, 10);
41
42 if (value < MEMCACHED_MAXIMUM_RETURN)
43 {
44 printf("%s\n", memcached_strerror(NULL, (memcached_return_t)value));
45 }
46 else
47 {
48 fprintf(stderr, "Unknown Error Code\n");
49 return 1;
50 }
51
52 return 0;
53 }
54
55
56 void options_parse(int argc, char *argv[])
57 {
58 int option_index= 0;
59 int option_rv;
60
61 memcached_programs_help_st help_options[]=
62 {
63 {0},
64 };
65
66 static struct option long_options[]=
67 {
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},
72 {0, 0, 0, 0},
73 };
74
75 while (1)
76 {
77 option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
78 if (option_rv == -1) break;
79 switch (option_rv)
80 {
81 case 0:
82 break;
83 case OPT_VERBOSE: /* --verbose or -v */
84 opt_verbose = OPT_VERBOSE;
85 break;
86 case OPT_DEBUG: /* --debug or -d */
87 opt_verbose = OPT_DEBUG;
88 break;
89 case OPT_VERSION: /* --version or -V */
90 version_command(PROGRAM_NAME);
91 break;
92 case OPT_HELP: /* --help or -h */
93 help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
94 break;
95 case '?':
96 /* getopt_long already printed an error message. */
97 exit(1);
98 default:
99 abort();
100 }
101 }
102 }