Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lnet / utils / parser.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see [sun.com URL with a
20  * copy of GPLv2].
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _PARSER_H_
38 #define _PARSER_H_
39
40 #define HISTORY 100             /* Don't let history grow unbounded    */
41 #define MAXARGS 512
42
43 #define CMD_COMPLETE    0
44 #define CMD_INCOMPLETE  1
45 #define CMD_NONE        2
46 #define CMD_AMBIG       3
47 #define CMD_HELP        4
48
49 typedef struct parser_cmd {
50         char    *pc_name;
51         int     (* pc_func)(int, char **);
52         struct parser_cmd * pc_sub_cmd;
53         char *pc_help;
54 } command_t;
55
56 typedef struct argcmd {
57         char    *ac_name;
58         int      (*ac_func)(int, char **);
59         char     *ac_help;
60 } argcmd_t;
61
62 typedef struct network {
63         char    *type;
64         char    *server;
65         int     port;
66 } network_t;
67
68 int  Parser_quit(int argc, char **argv);
69 void Parser_init(char *, command_t *);  /* Set prompt and load command list */
70 int Parser_commands(void);                      /* Start the command parser */
71 void Parser_qhelp(int, char **);        /* Quick help routine */
72 int Parser_help(int, char **);          /* Detailed help routine */
73 void Parser_printhelp(char *);          /* Detailed help routine */
74 void Parser_exit(int, char **);         /* Shuts down command parser */
75 int Parser_execarg(int argc, char **argv, command_t cmds[]);
76 int execute_line(char * line);
77
78 /* Converts a string to an integer */
79 int Parser_int(char *, int *);
80
81 /* Prompts for a string, with default values and a maximum length */
82 char *Parser_getstr(const char *prompt, const char *deft, char *res, 
83                     size_t len);
84
85 /* Prompts for an integer, with minimum, maximum and default values and base */
86 int Parser_getint(const char *prompt, long min, long max, long deft,
87                   int base);
88
89 /* Prompts for a yes/no, with default */
90 int Parser_getbool(const char *prompt, int deft);
91
92 /* Extracts an integer from a string, or prompts if it cannot get one */
93 long Parser_intarg(const char *inp, const char *prompt, int deft,
94                    int min, int max, int base);
95
96 /* Extracts a word from the input, or propmts if it cannot get one */
97 char *Parser_strarg(char *inp, const char *prompt, const char *deft,
98                     char *answer, int len);
99
100 /* Extracts an integer from a string  with a base */
101 int Parser_arg2int(const char *inp, long *result, int base);
102
103 #endif