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