Whamcloud - gitweb
land v0.9.1 on HEAD, in preparation for a 1.0.x branch
[fs/lustre-release.git] / lustre / utils / parser.h
1 #ifndef _PARSER_H_
2 #define _PARSER_H_
3
4 #define HISTORY 100             /* Don't let history grow unbounded    */
5 #define MAXARGS 512
6
7 #define CMD_COMPLETE    0
8 #define CMD_INCOMPLETE  1
9 #define CMD_NONE        2
10 #define CMD_AMBIG       3
11 #define CMD_HELP        4
12
13 typedef struct parser_cmd {
14         char    *pc_name;
15         int     (* pc_func)(int, char **);
16         struct parser_cmd * pc_sub_cmd;
17         char *pc_help;
18 } command_t;
19
20 typedef struct argcmd {
21         char    *ac_name;
22         int      (*ac_func)(int, char **);
23         char     *ac_help;
24 } argcmd_t;
25
26 typedef struct network {
27         char    *type;
28         char    *server;
29         int     port;
30 } network_t;
31
32 int  Parser_quit(int argc, char **argv);
33 void Parser_init(char *, command_t *);  /* Set prompt and load command list */
34 int Parser_commands(void);                      /* Start the command parser */
35 void Parser_qhelp(int, char **);        /* Quick help routine */
36 int Parser_help(int, char **);          /* Detailed help routine */
37 void Parser_ignore_errors(int ignore);  /* Set the ignore errors flag */
38 void Parser_printhelp(char *);          /* Detailed help routine */
39 void Parser_exit(int, char **);         /* Shuts down command parser */
40 int Parser_execarg(int argc, char **argv, command_t cmds[]);
41 int execute_line(char * line);
42
43 /* Converts a string to an integer */
44 int Parser_int(char *, int *);
45
46 /* Prompts for a string, with default values and a maximum length */
47 char *Parser_getstr(const char *prompt, const char *deft, char *res, 
48                     size_t len);
49
50 /* Prompts for an integer, with minimum, maximum and default values and base */
51 int Parser_getint(const char *prompt, long min, long max, long deft,
52                   int base);
53
54 /* Prompts for a yes/no, with default */
55 int Parser_getbool(const char *prompt, int deft);
56
57 /* Extracts an integer from a string, or prompts if it cannot get one */
58 long Parser_intarg(const char *inp, const char *prompt, int deft,
59                    int min, int max, int base);
60
61 /* Extracts a word from the input, or propmts if it cannot get one */
62 char *Parser_strarg(char *inp, const char *prompt, const char *deft,
63                     char *answer, int len);
64
65 /* Extracts an integer from a string  with a base */
66 int Parser_arg2int(const char *inp, long *result, int base);
67
68 /* Convert human readable size string to and int; "1k" -> 1000 */
69 int Parser_size(int *sizep, char *str);
70
71 /* Convert a string boolean to an int; "enable" -> 1 */
72 int Parser_bool(int *b, char *str);
73
74 #endif