Whamcloud - gitweb
Another slightly less rough cut at XML based configuration. There
[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 100
6
7 typedef struct parser_cmd {
8         char    *pc_name;
9         int     (* pc_func)(int, char **);
10         struct parser_cmd * pc_sub_cmd;
11         char *pc_help;
12 } command_t;
13
14 typedef struct argcmd {
15         char    *ac_name;
16         int      (*ac_func)(int, char **);
17         char     *ac_help;
18 } argcmd_t;
19
20 typedef struct network {
21         char    *type;
22         char    *server;
23         int     port;
24 } network_t;
25
26 int  Parser_quit(int argc, char **argv);
27 void Parser_init(char *, command_t *);  /* Set prompt and load command list */
28 int Parser_commands(void);                      /* Start the command parser */
29 void Parser_qhelp(int, char **);        /* Quick help routine */
30 int Parser_help(int, char **);          /* Detailed help routine */
31 void Parser_exit(int, char **);         /* Shuts down command parser */
32 int Parser_execarg(int argc, char **argv, command_t cmds[]);
33 int execute_line(char * line);
34
35 /* Converts a string to an integer */
36 int Parser_int(char *, int *);
37
38 /* Prompts for a string, with default values and a maximum length */
39 char *Parser_getstr(const char *prompt, const char *deft, char *res, 
40                     size_t len);
41
42 /* Prompts for an integer, with minimum, maximum and default values and base */
43 int Parser_getint(const char *prompt, long min, long max, long deft,
44                   int base);
45
46 /* Prompts for a yes/no, with default */
47 int Parser_getbool(const char *prompt, int deft);
48
49 /* Extracts an integer from a string, or prompts if it cannot get one */
50 long Parser_intarg(const char *inp, const char *prompt, int deft,
51                    int min, int max, int base);
52
53 /* Extracts a word from the input, or propmts if it cannot get one */
54 char *Parser_strarg(char *inp, const char *prompt, const char *deft,
55                     char *answer, int len);
56
57 /* Extracts an integer from a string  with a base */
58 int Parser_arg2int(const char *inp, long *result, int base);
59
60
61 #endif