Whamcloud - gitweb
Mass conversion of all copyright messages to Oracle.
[fs/lustre-release.git] / libcfs / include / libcfs / util / 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
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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 (c) 2008, 2010, Oracle and/or its affiliates. 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  * libcfs/include/libcfs/util/parser.h
37  *
38  * A command line parser.
39  *
40  */
41
42 #ifndef _PARSER_H_
43 #define _PARSER_H_
44
45 #define HISTORY 100             /* Don't let history grow unbounded    */
46 #define MAXARGS 512
47
48 #define CMD_COMPLETE    0
49 #define CMD_INCOMPLETE  1
50 #define CMD_NONE        2
51 #define CMD_AMBIG       3
52 #define CMD_HELP        4
53
54 typedef struct parser_cmd {
55         char    *pc_name;
56         int     (* pc_func)(int, char **);
57         struct parser_cmd * pc_sub_cmd;
58         char *pc_help;
59 } command_t;
60
61 typedef struct argcmd {
62         char    *ac_name;
63         int      (*ac_func)(int, char **);
64         char     *ac_help;
65 } argcmd_t;
66
67 typedef struct network {
68         char    *type;
69         char    *server;
70         int     port;
71 } network_t;
72
73 int  Parser_quit(int argc, char **argv);
74 void Parser_init(char *, command_t *);  /* Set prompt and load command list */
75 int Parser_commands(void);                      /* Start the command parser */
76 void Parser_qhelp(int, char **);        /* Quick help routine */
77 int Parser_help(int, char **);          /* Detailed help routine */
78 void Parser_ignore_errors(int ignore);  /* Set the ignore errors flag */
79 void Parser_printhelp(char *);          /* Detailed help routine */
80 void Parser_exit(int, char **);         /* Shuts down command parser */
81 int Parser_execarg(int argc, char **argv, command_t cmds[]);
82 int execute_line(char * line);
83
84 /* Converts a string to an integer */
85 int Parser_int(char *, int *);
86
87 /* Prompts for a string, with default values and a maximum length */
88 char *Parser_getstr(const char *prompt, const char *deft, char *res, 
89                     size_t len);
90
91 /* Prompts for an integer, with minimum, maximum and default values and base */
92 int Parser_getint(const char *prompt, long min, long max, long deft,
93                   int base);
94
95 /* Prompts for a yes/no, with default */
96 int Parser_getbool(const char *prompt, int deft);
97
98 /* Extracts an integer from a string, or prompts if it cannot get one */
99 long Parser_intarg(const char *inp, const char *prompt, int deft,
100                    int min, int max, int base);
101
102 /* Extracts a word from the input, or propmts if it cannot get one */
103 char *Parser_strarg(char *inp, const char *prompt, const char *deft,
104                     char *answer, int len);
105
106 /* Extracts an integer from a string  with a base */
107 int Parser_arg2int(const char *inp, long *result, int base);
108
109 /* Convert human readable size string to and int; "1k" -> 1000 */
110 int Parser_size(int *sizep, char *str);
111
112 /* Convert a string boolean to an int; "enable" -> 1 */
113 int Parser_bool(int *b, char *str);
114
115 #endif