Whamcloud - gitweb
i=adilger
[fs/lustre-release.git] / lnet / 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_printhelp(char *);          /* Detailed help routine */
38 void Parser_exit(int, char **);         /* Shuts down command parser */
39 int Parser_execarg(int argc, char **argv, command_t cmds[]);
40 int execute_line(char * line);
41
42 /* Converts a string to an integer */
43 int Parser_int(char *, int *);
44
45 /* Prompts for a string, with default values and a maximum length */
46 char *Parser_getstr(const char *prompt, const char *deft, char *res, 
47                     size_t len);
48
49 /* Prompts for an integer, with minimum, maximum and default values and base */
50 int Parser_getint(const char *prompt, long min, long max, long deft,
51                   int base);
52
53 /* Prompts for a yes/no, with default */
54 int Parser_getbool(const char *prompt, int deft);
55
56 /* Extracts an integer from a string, or prompts if it cannot get one */
57 long Parser_intarg(const char *inp, const char *prompt, int deft,
58                    int min, int max, int base);
59
60 /* Extracts a word from the input, or propmts if it cannot get one */
61 char *Parser_strarg(char *inp, const char *prompt, const char *deft,
62                     char *answer, int len);
63
64 /* Extracts an integer from a string  with a base */
65 int Parser_arg2int(const char *inp, long *result, int base);
66
67 #endif