5654c212bc75670e9f27c82c865f20f024dfcdc0
[awesomized/libmemcached] / clients / memerror.c
1 #include <stdio.h>
2 #include <inttypes.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <getopt.h>
6 #include <stdlib.h>
7 #include <libmemcached/memcached.h>
8
9 #include "utilities.h"
10
11 #define PROGRAM_NAME "memerror"
12 #define PROGRAM_DESCRIPTION "Translate a memcached errror code into a string."
13
14
15 /* Prototypes */
16 void options_parse(int argc, char *argv[]);
17
18 static int opt_verbose= 0;
19
20 int main(int argc, char *argv[])
21 {
22 options_parse(argc, argv);
23
24 if (argc != 2)
25 return 1;
26
27 printf("%s\n", memcached_strerror(NULL, atoi(argv[1])));
28
29 return 0;
30 }
31
32
33 void options_parse(int argc, char *argv[])
34 {
35 int option_index= 0;
36 int option_rv;
37
38 memcached_programs_help_st help_options[]=
39 {
40 {0},
41 };
42
43 static struct option long_options[]=
44 {
45 {"version", no_argument, NULL, OPT_VERSION},
46 {"help", no_argument, NULL, OPT_HELP},
47 {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
48 {"debug", no_argument, &opt_verbose, OPT_DEBUG},
49 {0, 0, 0, 0},
50 };
51
52 while (1)
53 {
54 option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
55 if (option_rv == -1) break;
56 switch (option_rv)
57 {
58 case 0:
59 break;
60 case OPT_VERBOSE: /* --verbose or -v */
61 opt_verbose = OPT_VERBOSE;
62 break;
63 case OPT_DEBUG: /* --debug or -d */
64 opt_verbose = OPT_DEBUG;
65 break;
66 case OPT_VERSION: /* --version or -V */
67 version_command(PROGRAM_NAME);
68 break;
69 case OPT_HELP: /* --help or -h */
70 help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
71 break;
72 case '?':
73 /* getopt_long already printed an error message. */
74 exit(1);
75 default:
76 abort();
77 }
78 }
79 }