Temp save for Monty.
[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
12 #include "libmemcached/common.h"
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 options_parse(argc, argv);
35
36 if (argc != 2)
37 return 1;
38
39 printf("%s\n", memcached_strerror(NULL, atoi(argv[1])));
40
41 return 0;
42 }
43
44
45 void options_parse(int argc, char *argv[])
46 {
47 int option_index= 0;
48 int option_rv;
49
50 memcached_programs_help_st help_options[]=
51 {
52 {0},
53 };
54
55 static struct option long_options[]=
56 {
57 {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
58 {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
59 {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
60 {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
61 {0, 0, 0, 0},
62 };
63
64 while (1)
65 {
66 option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
67 if (option_rv == -1) break;
68 switch (option_rv)
69 {
70 case 0:
71 break;
72 case OPT_VERBOSE: /* --verbose or -v */
73 opt_verbose = OPT_VERBOSE;
74 break;
75 case OPT_DEBUG: /* --debug or -d */
76 opt_verbose = OPT_DEBUG;
77 break;
78 case OPT_VERSION: /* --version or -V */
79 version_command(PROGRAM_NAME);
80 break;
81 case OPT_HELP: /* --help or -h */
82 help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
83 break;
84 case '?':
85 /* getopt_long already printed an error message. */
86 exit(1);
87 default:
88 abort();
89 }
90 }
91 }