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