4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * libcfs/include/libcfs/util/parser.h
34 * A command line parser.
41 #define HISTORY 100 /* Don't let history grow unbounded */
44 #define CMD_COMPLETE 0
45 #define CMD_INCOMPLETE 1
50 typedef struct parser_cmd {
52 int (* pc_func)(int, char **);
53 struct parser_cmd * pc_sub_cmd;
57 typedef struct argcmd {
59 int (*ac_func)(int, char **);
63 typedef struct network {
69 int Parser_quit(int argc, char **argv);
70 int Parser_version(int argc, char **argv);
71 void Parser_init(char *, command_t *); /* Set prompt and load command list */
72 int Parser_commands(void); /* Start the command parser */
73 void Parser_qhelp(int, char **); /* Quick help routine */
74 int Parser_help(int, char **); /* Detailed help routine */
75 void Parser_ignore_errors(int ignore); /* Set the ignore errors flag */
76 void Parser_printhelp(char *); /* Detailed help routine */
77 void Parser_exit(int, char **); /* Shuts down command parser */
78 int Parser_execarg(int argc, char **argv, command_t cmds[]);
79 int execute_line(char * line);
81 /* Converts a string to an integer */
82 int Parser_int(char *, int *);
84 /* Prompts for a string, with default values and a maximum length */
85 char *Parser_getstr(const char *prompt, const char *deft, char *res,
88 /* Prompts for an integer, with minimum, maximum and default values and base */
89 int Parser_getint(const char *prompt, long min, long max, long deft,
92 /* Prompts for a yes/no, with default */
93 int Parser_getbool(const char *prompt, int deft);
95 /* Extracts an integer from a string, or prompts if it cannot get one */
96 long Parser_intarg(const char *inp, const char *prompt, int deft,
97 int min, int max, int base);
99 /* Extracts a word from the input, or propmts if it cannot get one */
100 char *Parser_strarg(char *inp, const char *prompt, const char *deft,
101 char *answer, int len);
103 /* Extracts an integer from a string with a base */
104 int Parser_arg2int(const char *inp, long *result, int base);
106 /* Convert human readable size string to and int; "1k" -> 1000 */
107 int Parser_size(int *sizep, char *str);
109 /* Convert a string boolean to an int; "enable" -> 1 */
110 int Parser_bool(int *b, char *str);