Updated for help commands (and a little bit on ketama)
[awesomized/libmemcached] / src / utilities.c
1 #include <ctype.h>
2 #include <strings.h>
3 #include "utilities.h"
4
5
6 long int timedif(struct timeval a, struct timeval b)
7 {
8 register int us, s;
9
10 us = a.tv_usec - b.tv_usec;
11 us /= 1000;
12 s = a.tv_sec - b.tv_sec;
13 s *= 1000;
14 return s + us;
15 }
16
17 void version_command(char *command_name)
18 {
19 printf("%s v%u.%u\n", command_name, 1, 0);
20 exit(0);
21 }
22
23 char *lookup_help(memcached_options option)
24 {
25 switch (option)
26 {
27 case OPT_SERVERS: return("List which servers you wish to connect to.");
28 case OPT_VERSION: return("Display the version of the application and then exit.");
29 case OPT_HELP: return("Diplay this message and then exit.");
30 case OPT_VERBOSE: return("Give more details on the progression of the application.");
31 case OPT_DEBUG: return("Provide output only useful for debugging.");
32 case OPT_FLAG: return("Provide flag information for storage operation.");
33 case OPT_EXPIRE: return("Set the expire option for the object.");
34 case OPT_SET: return("Use set command with memcached when storing.");
35 case OPT_REPLACE: return("Use replace command with memcached when storing.");
36 case OPT_ADD: return("Use add command with memcached when storing.");
37 case OPT_SLAP_EXECUTE_NUMBER: return("Number of times to execute the given test.");
38 case OPT_SLAP_INITIAL_LOAD: return("Number of key pairs to load before executing tests.");
39 case OPT_SLAP_TEST: return("Test to run.");
40 case OPT_SLAP_CONCURRENCY: return("Number of users to simulate with load.");
41 case OPT_SLAP_NON_BLOCK: return("Set TCP up to use non-blocking IO.");
42 case OPT_SLAP_TCP_NODELAY: return("Set TCP socket up to use nodelay.");
43 case OPT_FLUSH: return("Flush servers before running tests.");
44 };
45
46 return "forgot to document this one :)";
47 }
48
49 void help_command(char *command_name, char *description,
50 const struct option *long_options,
51 memcached_programs_help_st *options)
52 {
53 unsigned int x;
54
55 printf("%s v%u.%u\n\n", command_name, 1, 0);
56 printf("\t%s\n\n", description);
57 printf("Current options. A '=' means the option takes a value.\n\n");
58
59 for (x= 0; long_options[x].name; x++)
60 {
61 char *help_message;
62
63 printf("\t --%s%c\n", long_options[x].name,
64 long_options[x].has_arg ? '=' : ' ');
65 if ((help_message= lookup_help(long_options[x].val)))
66 printf("\t\t%s\n", help_message);
67 }
68
69 printf("\n");
70 exit(0);
71 }