console.c revision 981801b95b81e6d1c7a2085967406e86af0f08fc
1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * console.c
3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright 2001-2009 Texas Instruments, Inc. - http://www.ti.com/
5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Licensed under the Apache License, Version 2.0 (the "License");
7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * you may not use this file except in compliance with the License.
8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * You may obtain a copy of the License at
9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     http://www.apache.org/licenses/LICENSE-2.0
11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Unless required by applicable law or agreed to in writing, software
13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * distributed under the License is distributed on an "AS IS" BASIS,
14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * See the License for the specific language governing permissions and
16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * limitations under the License.
17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*   MODULE:  console.c
22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*   PURPOSE:
24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*   DESCRIPTION:
26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*   ============
27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt****************************************************************************/
30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* includes */
32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************/
33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "cu_osapi.h"
34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "console.h"
35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "cu_cmd.h"
36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* defines */
38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/***********/
39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define INBUF_LENGTH            2100
40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define MAX_NAME_LEN        64
41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define MAX_HELP_LEN        40
42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define MAX_PARM_LEN        20
43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define ALIAS_LEN           1
44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define TOKEN_UP           ".."
46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define TOKEN_ROOT         "/"
47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define TOKEN_BREAK        "#"
48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define TOKEN_HELP         "?"
49981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define TOKEN_DIRHELP      "help"
50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
51981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* local types */
52981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/***************/
53981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef enum
55981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
56981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Dir,
57981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Token
58981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} ConEntry_type_t;
59981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
60981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Token types */
61981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef enum
62981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    EmptyToken,
64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    UpToken,
65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    RootToken,
66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    BreakToken,
67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    HelpToken,
68981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    DirHelpToken,
69981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    NameToken
70981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} TokenType_t;
71981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
72981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
73981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Monitor token structure */
74981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef struct ConEntry_t
75981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
76981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    struct ConEntry_t   *next;
77981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8                  name[MAX_NAME_LEN+1];    /* Entry name */
78981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8                  help[MAX_HELP_LEN+1];    /* Help string */
79981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PS8                 alias;                  /* Alias - always in upper case*/
80981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_type_t     sel;                   /* Entry selector */
81981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
82981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    union
83981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
84981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        struct
85981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
86981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            struct ConEntry_t   *upper;            /* Upper directory */
87981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            struct ConEntry_t   *first;            /* First entry */
88981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        } dir;
89981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        struct t_Token
90981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
91981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            FuncToken_t    f_tokenFunc;            /* Token handler */
92981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            S32            totalParams;
93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            ConParm_t      *parm;                  /* Parameters array with totalParams size */
94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            PS8            *name;                 /* Parameter name with totalParams size */
95981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        } token;
96981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    } u;
97981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} ConEntry_t;
98981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
99981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Module control block */
100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef struct Console_t
101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
102981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THandle hCuCmd;
103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
104981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S32 isDeviceOpen;
105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_mon_root;
107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_cur_dir;
108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PS8         p_inbuf;
109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    volatile S32 stop_UI_Monitor;
110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} Console_t;
111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* local variables */
113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*******************/
114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* local fucntions */
116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*******************/
117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic VOID Console_allocRoot(Console_t* pConsole);
118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
120981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Remove leading blanks */
121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic PS8 Console_ltrim(PS8 s)
122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
123981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while( *s == ' ' || *s == '\t' ) s++;
124981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return s;
125981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
126981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
127981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
128981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtMake a preliminary analizis of <name> token.
129981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtReturns a token type (Empty, Up, Root, Break, Name)
130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/
131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TokenType_t Console_analizeToken( PS8 name )
132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
133981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!name[0])
134981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return EmptyToken;
135981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
136981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!os_strcmp(name, (PS8)TOKEN_UP ) )
137981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return UpToken;
138981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
139981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!os_strcmp(name, (PS8)TOKEN_ROOT ) )
140981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return RootToken;
141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!os_strcmp(name, (PS8)TOKEN_BREAK ) )
143981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return BreakToken;
144981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
145981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!os_strcmp(name, (PS8)TOKEN_HELP ) )
146981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return HelpToken;
147981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
148981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!os_strcmp(name, (PS8)TOKEN_DIRHELP ) )
149981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return DirHelpToken;
150981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return NameToken;
152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Compare strings case insensitive */
156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic S32 Console_stricmp( PS8 s1, PS8 s2, U16 len )
157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S32  i;
159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for( i=0; i<len && s1[i] && s2[i]; i++ )
161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (os_tolower(s1[i])  != os_tolower(s2[i] ))
163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return ( (len - i) * (s1[i] - s2[i]) );
167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Convert string s to lower case. Return pointer to s */
170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic PS8 Console_strlwr( PS8 s )
171981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PS8 s0=s;
173981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
174981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while( *s )
175981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
176981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        *s = (S8)os_tolower(*s );
177981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        ++s;
178981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
179981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
180981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return s0;
181981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
183981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* free the entries tree */
184981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic VOID Console_FreeEntry(ConEntry_t *pEntry)
185981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
186981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *pEntryTemp,*pEntryTemp1;
187981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
188981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(pEntry->sel == Dir)
189981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
190981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pEntryTemp = pEntry->u.dir.first;
191981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
192981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        while (pEntryTemp)
193981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
194981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pEntryTemp1 = pEntryTemp->next;
195981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            Console_FreeEntry(pEntryTemp);
196981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pEntryTemp = pEntryTemp1;
197981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
198981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
199981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
200981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* free the current entry */
201981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_MemoryFree(pEntry);
202981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
203981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
204981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
205981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Allocate root directory */
206981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic VOID Console_allocRoot(Console_t* pConsole)
207981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
208981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* The very first call. Allocate root structure */
209981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ((pConsole->p_mon_root=(ConEntry_t *)os_MemoryCAlloc(sizeof( ConEntry_t ), 1) ) == NULL)
210981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
211981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_error_printf(CU_MSG_ERROR, (PS8)( "ERROR - Console_allocRoot(): cant allocate root\n") );
212981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return;
213981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
214981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_strcpy((PS8)pConsole->p_mon_root->name, (PS8)("\\") );
215981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->p_mon_root->sel = Dir;
216981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->p_cur_dir = pConsole->p_mon_root;
217981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
218981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
219981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Display current directory */
220981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic VOID Console_displayDir(Console_t* pConsole)
221981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
222981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8 out_buf[512];
223981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_token;
224981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_dir = pConsole->p_cur_dir;
225981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
226981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_sprintf((PS8)out_buf, (PS8)("%s%s> "), (PS8)(p_dir==pConsole->p_mon_root)? (PS8)("") : (PS8)(".../"), (PS8)p_dir->name );
227981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_token = p_dir->u.dir.first;
228981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while( p_token )
229981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
230981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if( (os_strlen(out_buf) + os_strlen(p_token->name) + 2)>= sizeof(out_buf) )
231981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
232981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_ERROR, ( (PS8)"ERROR - Console_displayDir(): buffer too small....\n") );
233981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
234981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
235981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_strcat(out_buf, p_token->name );
236981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if ( p_token->sel == Dir )
237981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_strcat((PS8)out_buf, (PS8)("/" ) );
238981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token = p_token->next;
239981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token)
240981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_strcat((PS8)out_buf, (PS8)(", ") );
241981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
242981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
243981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_error_printf(CU_MSG_INFO2, (PS8)("%s\n"), (PS8)out_buf );
244981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
245981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
246981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
247981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
248981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtCut the first U16 from <p_inbuf>.
249981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtReturn the U16 in <name> and updated <p_inbuf>
250981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/
251981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TokenType_t Console_getWord(Console_t* pConsole, PS8 name, U16 len )
252981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
253981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16         i=0;
254981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TokenType_t tType;
255981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
256981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->p_inbuf = Console_ltrim(pConsole->p_inbuf);
257981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
258981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while( *pConsole->p_inbuf && *pConsole->p_inbuf!=' ' && i<len )
259981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        name[i++] = *(pConsole->p_inbuf++);
260981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
261981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (i<len)
262981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        name[i] = 0;
263981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
264981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tType   = Console_analizeToken( name );
265981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
266981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return tType;
267981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
268981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
269981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TokenType_t Console_getStrParam(Console_t* pConsole, PS8 buf, ConParm_t *param )
270981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
271981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TokenType_t tType;
272981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U32         i, len = param->hi_val;
273981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PS8         end_buf;
274981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
275981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->p_inbuf = Console_ltrim(pConsole->p_inbuf);
276981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
277981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if( param->flags & CON_PARM_LINE )
278981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
279981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_strcpy(buf, (PS8)pConsole->p_inbuf );
280981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pConsole->p_inbuf += os_strlen(pConsole->p_inbuf);
281981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
282981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
283981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
284981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if( *pConsole->p_inbuf == '\"' )
285981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
286981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            end_buf = os_strchr(pConsole->p_inbuf+1, '\"' );
287981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if( !end_buf )
288981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
289981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_ERROR, (PS8)("ERROR - invalid string param: '%s'\n"), (PS8)pConsole->p_inbuf );
290981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pConsole->p_inbuf += os_strlen(pConsole->p_inbuf);
291981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return EmptyToken;
292981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
293981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if( (end_buf - pConsole->p_inbuf - 1) > (int)len )
294981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
295981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_ERROR, (PS8)("ERROR - param is too long: '%s'\n"), (PS8)pConsole->p_inbuf );
296981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pConsole->p_inbuf += os_strlen(pConsole->p_inbuf);
297981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return EmptyToken;
298981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
299981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            *end_buf = 0;
300981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_strcpy( buf, (PS8)(pConsole->p_inbuf+1 ) );
301981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pConsole->p_inbuf = end_buf + 1;
302981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
303981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
304981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
305981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            for( i=0; *pConsole->p_inbuf && *pConsole->p_inbuf!=' ' && i<len; i++ )
306981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                buf[i] = *(pConsole->p_inbuf++);
307981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
308981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            buf[i] = 0;
309981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if( *pConsole->p_inbuf && *pConsole->p_inbuf != ' ' )
310981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
311981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_ERROR, (PS8)("ERROR - param is too long: '%s'\n"), (PS8)( pConsole->p_inbuf-os_strlen( buf) ) );
312981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pConsole->p_inbuf += os_strlen(pConsole->p_inbuf);
313981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return EmptyToken;
314981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
315981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
316981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
317981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
318981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tType   = Console_analizeToken( buf );
319981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
320981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return tType;
321981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
322981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
323981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Returns number of parameters of the given token
324981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/
325981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic U16 Console_getNParms( ConEntry_t *p_token )
326981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
327981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16 i;
328981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ( !p_token->u.token.parm )
329981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return 0;
330981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for( i=0;
331981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         (i<p_token->u.token.totalParams) &&
332981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          p_token->u.token.parm[i].name &&
333981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          p_token->u.token.parm[i].name[0];
334981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         i++ )
335981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        ;
336981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return i;
337981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
338981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
339981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Parse p_inbuf string based on parameter descriptions in <p_token>.
340981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtFill parameter values in <p_token>.
341981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtReturns the number of parameters filled.
342981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTo Do: add a option of one-by-one user input of missing parameters.
343981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/
344981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic S32 Console_parseParms(Console_t* pConsole, ConEntry_t *p_token, U16 *pnParms )
345981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
346981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16 nTotalParms = Console_getNParms( p_token );
347981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16 nParms=0;
348981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PS8 end_buf = NULL;
349981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8  parm[INBUF_LENGTH];
350981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16 i, print_params = 0;
351981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U32 val = 0;
352981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S32 sval = 0;
353981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
354981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Mark all parameters as don't having an explicit value */
355981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for( i=0; i<nTotalParms; i++ )
356981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token->u.token.parm[i].flags |= CON_PARM_NOVAL;
357981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
358981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*        -----------------              */
359981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->p_inbuf = Console_ltrim(pConsole->p_inbuf);
360981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if( pConsole->p_inbuf[0] == '!' && pConsole->p_inbuf[1] == '!' )
361981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
362981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pConsole->p_inbuf += 2; print_params = 1;
363981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
364981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*        -----------------              */
365981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
366981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Build a format string */
367981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for( i=0; i<nTotalParms; i++ )
368981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
369981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token->u.token.parm[i].flags & (CON_PARM_STRING | CON_PARM_LINE) )
370981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
371981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* For a string parameter value is the string address */
372981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* and hi_val is the string length                   */
373981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (Console_getStrParam(pConsole, parm, &p_token->u.token.parm[i] ) != NameToken)
374981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                break;
375981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if( os_strlen( parm) > p_token->u.token.parm[i].hi_val ||
376981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                (p_token->u.token.parm[i].low_val && p_token->u.token.parm[i].low_val > os_strlen( parm) ) )
377981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
378981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_ERROR, (PS8)("ERROR - param '%s' must be %ld..%ld chars\n"), (PS8)p_token->u.token.parm[i].name,
379981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    (PS8)p_token->u.token.parm[i].low_val, (PS8)p_token->u.token.parm[i].hi_val);
380981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return FALSE;
381981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
382981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_strcpy((PS8)(char *)p_token->u.token.parm[i].value, (PS8)parm);
383981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
384981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
385981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
386981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (Console_getWord(pConsole, parm, MAX_PARM_LEN ) != NameToken)
387981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                break;
388981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
389981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (p_token->u.token.parm[i].flags & CON_PARM_SIGN)
390981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
391981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                sval = os_strtol( parm, &end_buf, 0 );
392981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
393981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
394981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
395981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                val = os_strtoul( parm, &end_buf, 0 );
396981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
397981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if( end_buf <= parm )
398981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                break;
399981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
400981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Check value */
401981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (p_token->u.token.parm[i].flags & CON_PARM_RANGE)
402981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
403981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                if (p_token->u.token.parm[i].flags & CON_PARM_SIGN)
404981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                {
405981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    if ((sval < (S32)p_token->u.token.parm[i].low_val) ||
406981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                        (sval > (S32)p_token->u.token.parm[i].hi_val) )
407981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    {
408981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                        os_error_printf(CU_MSG_ERROR, (PS8)("%s: %d out of range (%d, %d)\n"),
409981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                            (PS8)p_token->u.token.parm[i].name, (int)sval,
410981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                            (int)p_token->u.token.parm[i].low_val, (int)p_token->u.token.parm[i].hi_val );
411981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                        return FALSE;
412981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    }
413981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
414981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                }
415981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                else
416981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                {
417981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    if ((val < p_token->u.token.parm[i].low_val) ||
418981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                        (val > p_token->u.token.parm[i].hi_val) )
419981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    {
420981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                        os_error_printf(CU_MSG_ERROR , (PS8)("%s: %ld out of range (%ld, %ld)\n"),
421981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                            (PS8)p_token->u.token.parm[i].name, (PS8)val,
422981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                            (PS8)p_token->u.token.parm[i].low_val, (PS8)p_token->u.token.parm[i].hi_val );
423981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                        return FALSE;
424981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    }
425981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                }
426981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
427981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
428981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (p_token->u.token.parm[i].flags & CON_PARM_SIGN)
429981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                p_token->u.token.parm[i].value = sval;
430981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
431981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                p_token->u.token.parm[i].value = val;
432981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
433981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
434981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token->u.token.parm[i].flags &= ~CON_PARM_NOVAL;
435981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        ++nParms;
436981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
437981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
438981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Process default values */
439981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for( ; i<nTotalParms; i++ )
440981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
441981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if ((p_token->u.token.parm[i].flags & CON_PARM_DEFVAL) != 0)
442981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
443981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_token->u.token.parm[i].flags &= ~CON_PARM_NOVAL;
444981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            ++nParms;
445981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
446981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else if (!(p_token->u.token.parm[i].flags & CON_PARM_OPTIONAL) )
447981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
448981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Mandatory parameter missing */
449981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return FALSE;
450981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
451981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
452981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
453981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if( print_params )
454981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
455981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_error_printf((S32)CU_MSG_INFO2, (PS8)("Params: %d\n"), nParms );
456981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        for (i=0; i<nParms; i++ )
457981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
458981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_INFO2, (PS8)("%d: %s - flags:%d"),
459981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                i+1, (PS8)p_token->u.token.parm[i].name,
460981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                p_token->u.token.parm[i].flags);
461981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
462981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (p_token->u.token.parm[i].flags & CON_PARM_SIGN)
463981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_INFO2, (PS8)("min:%d, max:%d, value:%d "),(PS8)p_token->u.token.parm[i].low_val, (PS8)p_token->u.token.parm[i].hi_val,
464981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                (PS8)p_token->u.token.parm[i].value);
465981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
466981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_INFO2, (PS8)("min:%ld, max:%ld, value:%ld "),(PS8)p_token->u.token.parm[i].low_val, (PS8)p_token->u.token.parm[i].hi_val,
467981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                (PS8)p_token->u.token.parm[i].value);
468981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
469981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_INFO2, (PS8)("(%#lx)"),(PS8)p_token->u.token.parm[i].value );
470981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
471981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if( p_token->u.token.parm[i].flags & (CON_PARM_LINE | CON_PARM_STRING ))
472981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
473981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_INFO2, (PS8)(" - '%s'"), (PS8)(char *) p_token->u.token.parm[i].value );
474981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
475981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_INFO2, (PS8)("\n") );
476981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
477981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
478981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
479981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *pnParms = nParms;
480981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
481981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TRUE;
482981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
483981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
484981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Serach a token by name in the current directory */
485981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic ConEntry_t *Console_searchToken( ConEntry_t *p_dir, PS8 name )
486981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
487981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_token;
488981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16        name_len = (U16)os_strlen( name );
489981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
490981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Check alias */
491981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_token = p_dir->u.dir.first;
492981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while( p_token )
493981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
494981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token->alias &&
495981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            (name_len == ALIAS_LEN) &&
496981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            !Console_stricmp( p_token->alias, name, ALIAS_LEN ) )
497981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return p_token;
498981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token = p_token->next;
499981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
500981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
501981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Check name */
502981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_token = p_dir->u.dir.first;
503981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while( p_token )
504981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
505981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (!Console_stricmp( p_token->name, name, name_len ) )
506981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
507981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token = p_token->next;
508981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
509981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
510981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return p_token;
511981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
512981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
513981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
514981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Display help for each entry in the current directory */
515981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtVOID  Console_dirHelp(Console_t* pConsole)
516981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
517981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_token;
518981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8        print_str[80];
519981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
520981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_token = pConsole->p_cur_dir->u.dir.first;
521981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
522981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while( p_token )
523981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
524981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token->sel == Dir)
525981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_sprintf( print_str, (PS8)"%s: directory\n", (PS8)p_token->name );
526981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
527981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_sprintf( print_str, (PS8)("%s(%d parms): %s\n"),
528981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            (PS8)p_token->name, Console_getNParms(p_token), p_token->help );
529981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_error_printf(CU_MSG_INFO2,  (PS8)print_str );
530981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token = p_token->next;
531981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
532981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
533981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_error_printf(CU_MSG_INFO2, (PS8)("Type ? <name> for command help, \"/\"-root, \"..\"-upper\n") );
534981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
535981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
536981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
537981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Display help a token */
538981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic VOID  Console_displayHelp(Console_t* pConsole, ConEntry_t *p_token )
539981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
540981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8 bra, ket;
541981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16 nTotalParms = Console_getNParms( p_token );
542981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16 i;
543981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
544981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
545981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_error_printf(CU_MSG_INFO2, (PS8)("%s: %s "), (PS8)p_token->help, (PS8)p_token->name );
546981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for( i=0; i<nTotalParms; i++ )
547981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
548981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token->u.token.parm[i].flags & CON_PARM_OPTIONAL)
549981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
550981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            bra = '['; ket=']';
551981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
552981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
553981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
554981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            bra = '<'; ket='>';
555981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
556981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_error_printf(CU_MSG_INFO2, (PS8)("%c%s"), bra, (PS8)p_token->u.token.parm[i].name );
557981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token->u.token.parm[i].flags & CON_PARM_DEFVAL)
558981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
559981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_INFO2, (PS8)("=%lu"), (PS8)p_token->u.token.parm[i].value);
560981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
561981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token->u.token.parm[i].flags & CON_PARM_RANGE)
562981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
563981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_INFO2, (PS8)(p_token->u.token.parm[i].flags & CON_PARM_SIGN) ? (PS8)(" (%d..%d%s)") : (PS8)(" (%lu..%lu%s)"),
564981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                (PS8)p_token->u.token.parm[i].low_val,
565981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                (PS8)p_token->u.token.parm[i].hi_val,
566981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                (PS8)(p_token->u.token.parm[i].flags & (CON_PARM_STRING | CON_PARM_LINE)) ? (PS8)(" chars") : (PS8)("") );
567981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
568981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
569981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_error_printf(CU_MSG_INFO2, (PS8)("%c \n"),ket );
570981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
571981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
572981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
573981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Choose unique alias for <name> in <p_dir> */
574981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Currently only single-character aliases are supported */
575981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic S32 Console_chooseAlias( ConEntry_t *p_dir, ConEntry_t *p_new_token )
576981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
577981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_token;
578981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S32         i;
579981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8          c;
580981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    PS8         new_alias = NULL;
581981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
582981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* find alias given from user */
583981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for(i=0; p_new_token->name[i]; i++ )
584981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
585981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if( os_isupper( p_new_token->name[i]) )
586981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
587981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            new_alias = &p_new_token->name[i];
588981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
589981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
590981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
591981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
592981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_strlwr( p_new_token->name );
593981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
594981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if( new_alias )
595981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
596981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token = p_dir->u.dir.first;
597981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
598981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        while( p_token )
599981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
600981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (p_token->alias && (os_tolower(*p_token->alias ) == *new_alias) )
601981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
602981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_ERROR, (PS8)("Error - duplicated alias '%c' in <%s> and <%s>**\n"), *new_alias,
603981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    (PS8)p_token->name, (PS8)p_new_token->name );
604981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return 0;
605981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
606981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_token = p_token->next;
607981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
608981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        *new_alias = (S8)os_toupper(*new_alias);
609981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_new_token->alias = new_alias;
610981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return 1;
611981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
612981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
613981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    i = 0;
614981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while( p_new_token->name[i] )
615981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
616981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        c = p_new_token->name[i];
617981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token = p_dir->u.dir.first;
618981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
619981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        while( p_token )
620981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
621981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (p_token->alias &&
622981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                (os_tolower(*p_token->alias ) == c) )
623981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                break;
624981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_token = p_token->next;
625981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
626981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token)
627981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            ++i;
628981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
629981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
630981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_new_token->name[i] = (S8)os_toupper( c );
631981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_new_token->alias   = &p_new_token->name[i];
632981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
633981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
634981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
635981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return 1;
636981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
637981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
638981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Parse the given input string and exit.
639981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtAll commands in the input string are executed one by one.
640981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/
641981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic VOID Console_ParseString(Console_t* pConsole, PS8 input_string )
642981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
643981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t  *p_token;
644981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8          name[MAX_NAME_LEN];
645981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TokenType_t tType;
646981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16         nParms;
647981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
648981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!pConsole->p_mon_root)
649981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return;
650981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
651981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(!pConsole->isDeviceOpen)
652981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
653981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        Console_GetDeviceStatus(pConsole);
654981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if(!pConsole->isDeviceOpen)
655981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
656981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_ERROR, (PS8)("ERROR - Console_ParseString - Device isn't loaded !!!\n") );
657981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return;
658981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
659981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
660981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
661981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if( input_string[os_strlen( input_string)-1] == '\n' )
662981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
663981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        PS8 s = &input_string[os_strlen( input_string)-1];
664981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        *s = 0;
665981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
666981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->p_inbuf = input_string;
667981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->stop_UI_Monitor = FALSE;
668981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
669981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Interpret empty string as "display directory" */
670981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ( pConsole->p_inbuf && !*pConsole->p_inbuf )
671981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        Console_displayDir(pConsole);
672981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
673981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while(!pConsole->stop_UI_Monitor && pConsole->p_inbuf && *pConsole->p_inbuf)
674981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
675981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        tType = Console_getWord(pConsole, name, MAX_NAME_LEN );
676981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        switch( tType )
677981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
678981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
679981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case NameToken:
680981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_token = Console_searchToken( pConsole->p_cur_dir, name );
681981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (p_token == NULL)
682981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
683981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_ERROR, (PS8)("**Error: '%s'**\n"),name);
684981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pConsole->p_inbuf = NULL;
685981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
686981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else if (p_token->sel == Dir)
687981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
688981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pConsole->p_cur_dir = p_token;
689981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                Console_displayDir(pConsole);
690981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
691981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
692981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {  /* Function token */
693981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                if (!Console_parseParms(pConsole, p_token, &nParms ))
694981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                {
695981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    Console_displayHelp(pConsole, p_token );
696981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                }
697981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                else
698981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                {
699981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    p_token->u.token.f_tokenFunc(pConsole->hCuCmd, p_token->u.token.parm, nParms );
700981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                }
701981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
702981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
703981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
704981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case UpToken: /* Go to upper directory */
705981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pConsole->p_cur_dir->u.dir.upper)
706981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pConsole->p_cur_dir = pConsole->p_cur_dir->u.dir.upper;
707981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            Console_displayDir(pConsole);
708981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
709981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
710981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case RootToken: /* Go to the root directory */
711981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pConsole->p_cur_dir->u.dir.upper)
712981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pConsole->p_cur_dir = pConsole->p_mon_root;
713981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            Console_displayDir(pConsole);
714981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
715981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
716981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case HelpToken: /* Display help */
717981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (( Console_getWord(pConsole, name, MAX_NAME_LEN ) == NameToken ) &&
718981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                ((p_token = Console_searchToken( pConsole->p_cur_dir, name )) != NULL ) &&
719981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                (p_token->sel == Token) )
720981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                Console_displayHelp(pConsole, p_token);
721981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
722981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                Console_dirHelp(pConsole);
723981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
724981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
725981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case DirHelpToken:
726981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            Console_displayDir(pConsole);
727981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_INFO2, (PS8)("Type ? <name> for command help, \"/\"-root, \"..\"-upper\n") );
728981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
729981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
730981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case BreakToken: /* Clear buffer */
731981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pConsole->p_inbuf = NULL;
732981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
733981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
734981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case EmptyToken:
735981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
736981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
737981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
738981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
739981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
740981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
741981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* functions */
742981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*************/
743981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
744981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTHandle Console_Create(const PS8 device_name, S32 BypassSupplicant, PS8 pSupplIfFile)
745981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
746981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_t* pConsole = (Console_t*)os_MemoryCAlloc(sizeof(Console_t), sizeof(U8));
747981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(pConsole == NULL)
748981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
749981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_error_printf(CU_MSG_ERROR, (PS8)("Error - Console_Create - cant allocate control block\n") );
750981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return NULL;
751981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
752981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
753981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->hCuCmd = CuCmd_Create(device_name, pConsole, BypassSupplicant, pSupplIfFile);
754981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(pConsole->hCuCmd == NULL)
755981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
756981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        Console_Destroy(pConsole);
757981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return NULL;
758981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
759981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
760981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_allocRoot(pConsole);
761981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
762981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->isDeviceOpen = FALSE;
763981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
764981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return pConsole;
765981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
766981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
767981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtVOID Console_Destroy(THandle hConsole)
768981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
769981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_t* pConsole = (Console_t*)hConsole;
770981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
771981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(pConsole->hCuCmd)
772981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
773981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        CuCmd_Destroy(pConsole->hCuCmd);
774981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
775981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pConsole->p_mon_root)
776981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
777981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_FreeEntry(pConsole->p_mon_root);
778981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
779981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_MemoryFree(pConsole);
780981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
781981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
782981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtVOID Console_Stop(THandle hConsole)
783981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
784981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ((Console_t*)hConsole)->stop_UI_Monitor = TRUE;
785981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
786981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
787981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Monitor driver */
788981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtVOID Console_Start(THandle hConsole)
789981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
790981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_t* pConsole = (Console_t*)hConsole;
791981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S8  inbuf[INBUF_LENGTH];
792981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    S32 res;
793981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
794981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!pConsole->p_mon_root)
795981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return;
796981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
797981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pConsole->stop_UI_Monitor = FALSE;
798981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_displayDir(pConsole);
799981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
800981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while(!pConsole->stop_UI_Monitor)
801981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
802981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* get input string */
803981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        res = os_getInputString(inbuf, sizeof(inbuf));
804981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (res == FALSE)
805981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
806981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if(pConsole->stop_UI_Monitor)
807981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
808981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                continue;
809981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
810981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
811981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
812981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return;
813981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
814981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
815981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
816981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if(res == OS_GETINPUTSTRING_CONTINUE)
817981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
818981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
819981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* change to NULL terminated strings */
820981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if( inbuf[os_strlen(inbuf)-1] == '\n' )
821981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            inbuf[os_strlen(inbuf)-1] = 0;
822981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
823981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* parse the string */
824981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        Console_ParseString(pConsole, inbuf);
825981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
826981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
827981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
828981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
829981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtVOID Console_GetDeviceStatus(THandle hConsole)
830981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
831981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_t* pConsole = (Console_t*)hConsole;
832981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
833981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(OK == CuCmd_GetDeviceStatus(pConsole->hCuCmd))
834981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
835981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pConsole->isDeviceOpen = TRUE;
836981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
837981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
838981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
839981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
840981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/***************************************************************
841981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
842981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  Function : consoleAddDirExt
843981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
844981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Description: Add subdirectory
845981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
846981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Parameters: p_root - root directory handle (might be NULL)
847981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      name   - directory name
848981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
849981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        Output:  the new created directory handle
850981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        =NULL - failure
851981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt***************************************************************/
852981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTHandle Console_AddDirExt(THandle  hConsole,
853981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          THandle   hRoot,         /* Upper directory handle. NULL=root */
854981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          const PS8  name,          /* New directory name */
855981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                          const PS8  desc )         /* Optional dir description */
856981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
857981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_t* pConsole = (Console_t*)hConsole;
858981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_root = (ConEntry_t *)hRoot;
859981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_dir;
860981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t **p_e;
861981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
862981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!p_root)
863981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_root = pConsole->p_mon_root;
864981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
865981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(!( p_root && (p_root->sel == Dir)))
866981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return NULL;
867981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
868981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ( (p_dir=(ConEntry_t *)os_MemoryAlloc(sizeof( ConEntry_t )) ) == NULL)
869981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return NULL;
870981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
871981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_memset( p_dir, 0, sizeof( ConEntry_t ) );
872981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_strncpy( p_dir->name, name, MAX_NAME_LEN );
873981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_strncpy( p_dir->help, desc, MAX_HELP_LEN );
874981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_dir->sel = Dir;
875981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
876981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_chooseAlias( p_root, p_dir );
877981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
878981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Add new directory to the root's list */
879981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_dir->u.dir.upper = p_root;
880981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_e = &(p_root->u.dir.first);
881981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while (*p_e)
882981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_e = &((*p_e)->next);
883981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *p_e = p_dir;
884981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
885981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return p_dir;
886981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
887981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
888981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/***************************************************************
889981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
890981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  Function : consoleAddToken
891981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
892981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Description: Add token
893981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
894981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Parameters: p_dir  - directory handle (might be NULL=root)
895981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      name   - token name
896981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      help   - help string
897981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      p_func - token handler
898981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      p_parms- array of parameter descriptions.
899981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Must be terminated with {0}.
900981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Each parm descriptor is a struct
901981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      { "myname",         - name
902981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      10,               - low value
903981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      20,               - high value
904981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      0 }               - default value =-1 no default
905981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      or address for string parameter
906981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
907981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        Output:  E_OK - OK
908981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        !=0 - error
909981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt***************************************************************/
910981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtconsoleErr Console_AddToken(  THandle hConsole,
911981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                THandle      hDir,
912981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                const PS8     name,
913981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                const PS8     help,
914981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                FuncToken_t   p_func,
915981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                ConParm_t     p_parms[] )
916981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
917981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_t* pConsole = (Console_t*)hConsole;
918981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_dir = (ConEntry_t *)hDir;
919981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t *p_token;
920981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ConEntry_t **p_e;
921981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    U16       i;
922981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
923981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!pConsole->p_mon_root)
924981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Console_allocRoot(pConsole);
925981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
926981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (!p_dir)
927981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      p_dir = pConsole->p_mon_root;
928981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
929981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(!( p_dir && (p_dir->sel == Dir)))
930981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return E_ERROR;
931981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
932981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
933981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Initialize token structure */
934981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if((p_token = (ConEntry_t *)os_MemoryCAlloc(1,sizeof(ConEntry_t))) == NULL)
935981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
936981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     os_error_printf(CU_MSG_ERROR, (PS8)("** no memory **\n") );
937981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      return E_NOMEMORY;
938981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
939981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
940981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
941981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Copy name */
942981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_strncpy( p_token->name, name, MAX_NAME_LEN );
943981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_strncpy( p_token->help, help, MAX_HELP_LEN );
944981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_token->sel = Token;
945981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_token->u.token.f_tokenFunc = p_func;
946981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_token->u.token.totalParams = 0;
947981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
948981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Convert name to lower case and choose alias */
949981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    Console_chooseAlias( p_dir, p_token );
950981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
951981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Copy parameters */
952981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ( p_parms )
953981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
954981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       ConParm_t     *p_tmpParms = p_parms;
955981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
956981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       /* find the number of params */
957981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       while( p_tmpParms->name && p_tmpParms->name[0] )
958981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       {
959981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_token->u.token.totalParams++;
960981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_tmpParms++;
961981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       }
962981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       /* allocate the parameters info */
963981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       p_token->u.token.parm = (ConParm_t *)os_MemoryAlloc(p_token->u.token.totalParams * sizeof(ConParm_t));
964981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       p_token->u.token.name = (PS8*)os_MemoryAlloc(p_token->u.token.totalParams * sizeof(PS8));
965981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       if ((p_token->u.token.parm == NULL) || (p_token->u.token.name == NULL))
966981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       {
967981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_ERROR, (PS8)("** no memory for params\n") );
968981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_MemoryFree(p_token);
969981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return E_NOMEMORY;
970981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       }
971981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       for (i=0; i < p_token->u.token.totalParams; i++)
972981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       {
973981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         ConParm_t *p_token_parm = &p_token->u.token.parm[i];
974981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
975981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         /* String parameter must have an address */
976981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         if(p_parms->flags & (CON_PARM_STRING | CON_PARM_LINE))
977981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         {
978981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if ( p_parms->hi_val >= INBUF_LENGTH )
979981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
980981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               os_error_printf(CU_MSG_ERROR, (PS8)("** buffer too big: %s/%s\n"), p_dir->name, name);
981981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token->u.token.parm);
982981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token->u.token.name);
983981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token);
984981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return E_NOMEMORY;
985981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
986981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
987981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (p_parms->hi_val == 0 || (p_parms->flags & CON_PARM_RANGE) )
988981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
989981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               os_error_printf(CU_MSG_ERROR, (PS8)("** Bad string param definition: %s/%s\n"), p_dir->name, name );
990981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token->u.token.parm);
991981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token->u.token.name);
992981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token);
993981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return E_BADPARM;
994981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
995981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_parms->value = (U32)os_MemoryCAlloc(1,p_parms->hi_val+1);
996981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if( !p_parms->value )
997981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
998981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_error_printf(CU_MSG_ERROR, (PS8)("** No memory: %s/%s (max.size=%ld)\n"), p_dir->name, name, p_parms->hi_val );
999981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token->u.token.parm);
1000981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token->u.token.name);
1001981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_MemoryFree(p_token);
1002981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return E_NOMEMORY;
1003981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1004981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1005981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1006981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Copy parameter */
1007981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        *p_token_parm = *p_parms;
1008981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if( p_token_parm->hi_val || p_token_parm->low_val )
1009981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            p_token_parm->flags |= CON_PARM_RANGE;
1010981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1011981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        p_token->u.token.name[i] = os_MemoryAlloc(os_strlen(p_parms->name));
1012981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (p_token->u.token.name[i] == NULL)
1013981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1014981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_error_printf(CU_MSG_ERROR, (PS8)("** Error allocate param name\n"));
1015981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_MemoryFree(p_token->u.token.parm);
1016981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_MemoryFree(p_token->u.token.name);
1017981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_MemoryFree(p_token);
1018981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return E_NOMEMORY;
1019981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
1020981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         p_token_parm->name = (PS8)p_token->u.token.name[i];
1021981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         os_strncpy( p_token->u.token.name[i], p_parms->name, os_strlen(p_parms->name) );
1022981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         ++p_parms;
1023981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      } /*end of for loop*/
1024981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
1025981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1026981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Add token to the directory */
1027981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    p_e = &(p_dir->u.dir.first);
1028981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while (*p_e)
1029981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      p_e = &((*p_e)->next);
1030981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    *p_e = p_token;
1031981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1032981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return E_OK;
1033981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1034981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1035