1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Command interpreter defs			File: ui_command.h
5    *
6    *  This file contains structures related to the
7    *  command interpreter.
8    *
9    *  Author:  Mitch Lichtenberg (mpl@broadcom.com)
10    *
11    *********************************************************************
12    *
13    *  Copyright 2000,2001,2002,2003
14    *  Broadcom Corporation. All rights reserved.
15    *
16    *  This software is furnished under license and may be used and
17    *  copied only in accordance with the following terms and
18    *  conditions.  Subject to these conditions, you may download,
19    *  copy, install, use, modify and distribute modified or unmodified
20    *  copies of this software in source and/or binary form.  No title
21    *  or ownership is transferred hereby.
22    *
23    *  1) Any source code used, modified or distributed must reproduce
24    *     and retain this copyright notice and list of conditions
25    *     as they appear in the source file.
26    *
27    *  2) No right is granted to use any trade name, trademark, or
28    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
29    *     name may not be used to endorse or promote products derived
30    *     from this software without the prior written permission of
31    *     Broadcom Corporation.
32    *
33    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45    *     THE POSSIBILITY OF SUCH DAMAGE.
46    ********************************************************************* */
47
48#ifndef _LIB_QUEUE_H
49#include "lib_queue.h"
50#endif
51
52typedef struct ui_cmdsw_s {
53    int swidx;
54    char *swname;
55    char *swvalue;
56} ui_cmdsw_t;
57
58#define MAX_TOKENS	64
59#define MAX_SWITCHES	16
60#define MAX_TOKEN_SIZE  1000
61typedef struct ui_cmdline_s {
62    int argc;
63    char *argv[MAX_TOKENS];
64    int swc;
65    ui_cmdsw_t swv[MAX_SWITCHES];
66    int (*func)(struct ui_cmdline_s *,int argc,char *argv[]);
67    int argidx;
68    char *ref;
69    char *usage;
70    char *switches;
71} ui_cmdline_t;
72
73typedef struct ui_command_s {
74    queue_t list;
75    int term;
76    char *ptr;
77    queue_t head;
78} ui_command_t;
79
80typedef struct ui_token_s {
81    queue_t qb;
82    char token;
83} ui_token_t;
84
85#define CMD_TERM_EOL	0
86#define CMD_TERM_SEMI	1
87#define CMD_TERM_AND	2
88#define CMD_TERM_OR	3
89
90int cmd_sw_value(ui_cmdline_t *cmd,char *swname,char **swvalue);
91int cmd_sw_posn(ui_cmdline_t *cmd,char *swname);
92char *cmd_sw_name(ui_cmdline_t *cmd,int swidx);
93int cmd_sw_isset(ui_cmdline_t *cmd,char *swname);
94char *cmd_getarg(ui_cmdline_t *cmd,int argnum);
95void cmd_free(ui_cmdline_t *cmd);
96int cmd_sw_validate(ui_cmdline_t *cmd,char *validstr);
97void cmd_parse(ui_cmdline_t *cmd,char *line);
98int cmd_addcmd(char *command,
99	       int (*func)(ui_cmdline_t *,int argc,char *argv[]),
100	       void *ref,
101	       char *help,
102	       char *usage,
103	       char *switches);
104int cmd_lookup(queue_t *head,ui_cmdline_t *cmd);
105void cmd_init(void);
106int cmd_getcommand(ui_cmdline_t *cmd);
107void cmd_showusage(ui_cmdline_t *cmd);
108
109
110
111#define CMD_ERR_INVALID	-1
112#define CMD_ERR_AMBIGUOUS -2
113#define CMD_ERR_BLANK -3
114
115
116/*  *********************************************************************
117    *  Prototypes (public routines)
118    ********************************************************************* */
119
120const char *ui_errstring(int errcode);
121int ui_showerror(int errcode,char *tmplt,...);
122int ui_showusage(ui_cmdline_t *cmd);
123int ui_docommands(char *str);
124#define ui_docommand(str) ui_docommands(str)
125void ui_restart(int);
126int ui_init_cmddisp(void);
127
128
129/*  *********************************************************************
130    *  Prototypes (internal routines)
131    ********************************************************************* */
132
133ui_command_t *cmd_readcommand(queue_t *head);
134void cmd_build_list(queue_t *qb,char *buf);
135void cmd_walk_and_expand(queue_t *qb);
136ui_command_t *cmd_readcommand(queue_t *head);
137void cmd_free_tokens(queue_t *list);
138void cmd_build_cmdline(queue_t *head, ui_cmdline_t *cmd);
139
140
141