A Command Interpreter with support for used defined commands, subsystems, macros, help and parameter parsing.

Committer:
wvd_vegt
Date:
Tue Nov 15 09:50:44 2016 +0000
Revision:
27:17ff3b07a392
Parent:
26:34c65d3f6da0
1) Switched to using RawSerial in order to support the latest mBed lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wvd_vegt 27:17ff3b07a392 1 /* mbed Command Interpreter Library
wvd_vegt 27:17ff3b07a392 2 * Copyright (c) 2016 wvd_vegt
wvd_vegt 27:17ff3b07a392 3 *
wvd_vegt 27:17ff3b07a392 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
wvd_vegt 27:17ff3b07a392 5 * of this software and associated documentation files (the "Software"), to deal
wvd_vegt 27:17ff3b07a392 6 * in the Software without restriction, including without limitation the rights
wvd_vegt 27:17ff3b07a392 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wvd_vegt 27:17ff3b07a392 8 * copies of the Software, and to permit persons to whom the Software is
wvd_vegt 27:17ff3b07a392 9 * furnished to do so, subject to the following conditions:
wvd_vegt 27:17ff3b07a392 10 *
wvd_vegt 27:17ff3b07a392 11 * The above copyright notice and this permission notice shall be included in
wvd_vegt 27:17ff3b07a392 12 * all copies or substantial portions of the Software.
wvd_vegt 27:17ff3b07a392 13 *
wvd_vegt 27:17ff3b07a392 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wvd_vegt 27:17ff3b07a392 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wvd_vegt 27:17ff3b07a392 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wvd_vegt 27:17ff3b07a392 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wvd_vegt 27:17ff3b07a392 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wvd_vegt 27:17ff3b07a392 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wvd_vegt 27:17ff3b07a392 20 * THE SOFTWARE.
wvd_vegt 27:17ff3b07a392 21 */
wvd_vegt 27:17ff3b07a392 22
wvd_vegt 26:34c65d3f6da0 23 /*
wvd_vegt 26:34c65d3f6da0 24 _____________________________________________________________________________
wvd_vegt 26:34c65d3f6da0 25
wvd_vegt 26:34c65d3f6da0 26 Project: mBed Command Interpreter
wvd_vegt 26:34c65d3f6da0 27 Filename: cmdb.h
wvd_vegt 27:17ff3b07a392 28 Version: 0.85
wvd_vegt 26:34c65d3f6da0 29 _____________________________________________________________________________
wvd_vegt 26:34c65d3f6da0 30 Date Comment
wvd_vegt 26:34c65d3f6da0 31 -------- --------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 32 10022011 -Rewritten into C++ class.
wvd_vegt 26:34c65d3f6da0 33 -Pass Serial into constructor for printf, putc and getc.
wvd_vegt 26:34c65d3f6da0 34 -CID_<subsystem> must be handled internally.
wvd_vegt 26:34c65d3f6da0 35 -Fixed a number of old Index/Id conflicts.
wvd_vegt 26:34c65d3f6da0 36 -Got a working version. Much work to be done though.
wvd_vegt 26:34c65d3f6da0 37 -Handle CID_HELP internally (like all system commands (IDLE/MACRO etc).
wvd_vegt 26:34c65d3f6da0 38 -Handle subsystems internally.
wvd_vegt 26:34c65d3f6da0 39 -Removed CMD_TBL_LEN.
wvd_vegt 26:34c65d3f6da0 40 -CID_LAST is now defined as CID_HELP+1.
wvd_vegt 26:34c65d3f6da0 41 11022011 -Added Documentation.
wvd_vegt 26:34c65d3f6da0 42 -Added code to take number limits from the C++ Runtime instead of hard defined values.
wvd_vegt 26:34c65d3f6da0 43 -Renamed id to cid in cmd.
wvd_vegt 26:34c65d3f6da0 44 -Added MAX_LONG and MIN_LONG (long==int on mbed).
wvd_vegt 26:34c65d3f6da0 45 -Removed cmdb_ prefix from members.
wvd_vegt 26:34c65d3f6da0 46 -Tested Macro Support and added it to the Demo.
wvd_vegt 26:34c65d3f6da0 47 -Added CID_COMMANDS.
wvd_vegt 26:34c65d3f6da0 48 -Fixed a small bug in parse.
wvd_vegt 26:34c65d3f6da0 49 -v0.76
wvd_vegt 26:34c65d3f6da0 50 24032011 -Fixed some left-over bugs caused by index/id mixup.
wvd_vegt 26:34c65d3f6da0 51 09052011 -Added present(), replace() and indexof() methods.
wvd_vegt 26:34c65d3f6da0 52 replace() can be used to replace the complete command vector
wvd_vegt 26:34c65d3f6da0 53 by a changed done. Inserting directly into cmdb's copy fails
wvd_vegt 26:34c65d3f6da0 54 somehow.
wvd_vegt 26:34c65d3f6da0 55 19092011 -Added PrintSection(), PrintValue() and PrintValuef() for
wvd_vegt 26:34c65d3f6da0 56 easier Windows Ini File style output. As I use it to transfer
wvd_vegt 26:34c65d3f6da0 57 data back to the PC (Easy parsing AND you can add/remove
wvd_vegt 26:34c65d3f6da0 58 debug information without breaking PC code).
wvd_vegt 26:34c65d3f6da0 59 20092011 -Breaking change, Made all cmd object static const like:
wvd_vegt 26:34c65d3f6da0 60
wvd_vegt 26:34c65d3f6da0 61 static const cmd HELP = {"Help",GLOBALCMD,CID_HELP,"%s","Help"};
wvd_vegt 26:34c65d3f6da0 62
wvd_vegt 26:34c65d3f6da0 63 this saves just to much ram memory on the heap.
wvd_vegt 26:34c65d3f6da0 64 Thanks to Igor Skochinsky.
wvd_vegt 26:34c65d3f6da0 65
wvd_vegt 26:34c65d3f6da0 66 -Made some more const string static.
wvd_vegt 26:34c65d3f6da0 67 -v0.80
wvd_vegt 26:34c65d3f6da0 68
wvd_vegt 26:34c65d3f6da0 69 20092011 -Corrected Comment Alignment.
wvd_vegt 26:34c65d3f6da0 70 -v0.81
wvd_vegt 27:17ff3b07a392 71
wvd_vegt 27:17ff3b07a392 72 20092011 -Switched to RawSerial to be compatible with the latest mBed lib (129).
wvd_vegt 27:17ff3b07a392 73 -Serial is no longer an issue because of the Stream class underneath
wvd_vegt 27:17ff3b07a392 74 with its hidden constructor.
wvd_vegt 27:17ff3b07a392 75 -Not fully tested yet.
wvd_vegt 27:17ff3b07a392 76 -v0.85
wvd_vegt 26:34c65d3f6da0 77 -------- --------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 78 TODO's
wvd_vegt 26:34c65d3f6da0 79 10022011 -Tweak and Review Documentation.
wvd_vegt 26:34c65d3f6da0 80 11022011 -Check & Test **PARM masks.
wvd_vegt 26:34c65d3f6da0 81 -Remove prefix from class members?
wvd_vegt 26:34c65d3f6da0 82 -------- --------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 83 _____________________________________________________________________________
wvd_vegt 26:34c65d3f6da0 84 */
wvd_vegt 26:34c65d3f6da0 85
wvd_vegt 26:34c65d3f6da0 86 #include <vector>
wvd_vegt 26:34c65d3f6da0 87 #include <stdlib.h>
wvd_vegt 26:34c65d3f6da0 88 #include <stdio.h>
wvd_vegt 26:34c65d3f6da0 89 #include <stdarg.h>
wvd_vegt 26:34c65d3f6da0 90 #include <ctype.h>
wvd_vegt 26:34c65d3f6da0 91 #include <string.h>
wvd_vegt 26:34c65d3f6da0 92
wvd_vegt 26:34c65d3f6da0 93 #include "cmdb.h"
wvd_vegt 26:34c65d3f6da0 94 #include "mbed.h"
wvd_vegt 26:34c65d3f6da0 95
wvd_vegt 26:34c65d3f6da0 96 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 97
wvd_vegt 27:17ff3b07a392 98 Cmdb::Cmdb(const RawSerial& _serial, std::vector<cmd>& _cmds, void (*_callback)(Cmdb&,int)) :
wvd_vegt 26:34c65d3f6da0 99 serial(_serial), cmds(_cmds) {
wvd_vegt 26:34c65d3f6da0 100 echo = true;
wvd_vegt 26:34c65d3f6da0 101 bold = true;
wvd_vegt 26:34c65d3f6da0 102
wvd_vegt 26:34c65d3f6da0 103 NoComment = NULL;
wvd_vegt 26:34c65d3f6da0 104 DefComPos = 72;
wvd_vegt 26:34c65d3f6da0 105
wvd_vegt 26:34c65d3f6da0 106 subsystem = -1;
wvd_vegt 26:34c65d3f6da0 107
wvd_vegt 26:34c65d3f6da0 108 user_callback = _callback;
wvd_vegt 26:34c65d3f6da0 109
wvd_vegt 26:34c65d3f6da0 110 init(true);
wvd_vegt 26:34c65d3f6da0 111 }
wvd_vegt 26:34c65d3f6da0 112
wvd_vegt 26:34c65d3f6da0 113 const char* Cmdb::NoComment;
wvd_vegt 26:34c65d3f6da0 114
wvd_vegt 26:34c65d3f6da0 115 int Cmdb::DefComPos;
wvd_vegt 26:34c65d3f6da0 116
wvd_vegt 26:34c65d3f6da0 117 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 118 // Public Stuff.
wvd_vegt 26:34c65d3f6da0 119 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 120
wvd_vegt 26:34c65d3f6da0 121 bool Cmdb::macro_hasnext() {
wvd_vegt 26:34c65d3f6da0 122 return macro_ptr!=-1 && macro_ptr<MAX_CMD_LEN && macro_buf[macro_ptr];
wvd_vegt 26:34c65d3f6da0 123 }
wvd_vegt 26:34c65d3f6da0 124
wvd_vegt 26:34c65d3f6da0 125 char Cmdb::macro_next() {
wvd_vegt 26:34c65d3f6da0 126 char ch = macro_buf[macro_ptr++];
wvd_vegt 26:34c65d3f6da0 127
wvd_vegt 26:34c65d3f6da0 128 if (macro_ptr==MAX_CMD_LEN) {
wvd_vegt 26:34c65d3f6da0 129 macro_reset();
wvd_vegt 26:34c65d3f6da0 130 }
wvd_vegt 26:34c65d3f6da0 131
wvd_vegt 26:34c65d3f6da0 132 //Translate Special Characters Back
wvd_vegt 26:34c65d3f6da0 133 switch (ch) {
wvd_vegt 26:34c65d3f6da0 134 case '|':
wvd_vegt 26:34c65d3f6da0 135 return cr;
wvd_vegt 26:34c65d3f6da0 136 case '_':
wvd_vegt 26:34c65d3f6da0 137 return sp;
wvd_vegt 26:34c65d3f6da0 138 default:
wvd_vegt 26:34c65d3f6da0 139 return ch;
wvd_vegt 26:34c65d3f6da0 140 }
wvd_vegt 26:34c65d3f6da0 141 }
wvd_vegt 26:34c65d3f6da0 142
wvd_vegt 26:34c65d3f6da0 143 char Cmdb::macro_peek() {
wvd_vegt 26:34c65d3f6da0 144 return macro_buf[macro_ptr];
wvd_vegt 26:34c65d3f6da0 145 }
wvd_vegt 26:34c65d3f6da0 146
wvd_vegt 26:34c65d3f6da0 147 void Cmdb::macro_reset() {
wvd_vegt 26:34c65d3f6da0 148 macro_ptr = -1;
wvd_vegt 26:34c65d3f6da0 149 macro_buf[0] = '\0';
wvd_vegt 26:34c65d3f6da0 150 }
wvd_vegt 26:34c65d3f6da0 151
wvd_vegt 26:34c65d3f6da0 152 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 153
wvd_vegt 26:34c65d3f6da0 154 bool Cmdb::hasnext() {
wvd_vegt 26:34c65d3f6da0 155 return serial.readable()==1;
wvd_vegt 26:34c65d3f6da0 156 }
wvd_vegt 26:34c65d3f6da0 157
wvd_vegt 26:34c65d3f6da0 158 char Cmdb::next() {
wvd_vegt 26:34c65d3f6da0 159 return serial.getc();
wvd_vegt 26:34c65d3f6da0 160 }
wvd_vegt 26:34c65d3f6da0 161
wvd_vegt 26:34c65d3f6da0 162 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 163
wvd_vegt 26:34c65d3f6da0 164 bool Cmdb::scan(const char c) {
wvd_vegt 26:34c65d3f6da0 165 int i;
wvd_vegt 26:34c65d3f6da0 166
wvd_vegt 26:34c65d3f6da0 167 //See http://www.interfacebus.com/ASCII_Table.html
wvd_vegt 26:34c65d3f6da0 168
wvd_vegt 26:34c65d3f6da0 169 if (c == '\r') { // cr?
wvd_vegt 26:34c65d3f6da0 170 print(crlf); // Output it and ...
wvd_vegt 26:34c65d3f6da0 171 if (cmdndx) {
wvd_vegt 26:34c65d3f6da0 172 strncpy(lstbuf,cmdbuf,cmdndx);
wvd_vegt 26:34c65d3f6da0 173 lstbuf[cmdndx]='\0';
wvd_vegt 26:34c65d3f6da0 174
wvd_vegt 26:34c65d3f6da0 175 cmd_dispatcher(cmdbuf);
wvd_vegt 26:34c65d3f6da0 176 }
wvd_vegt 26:34c65d3f6da0 177 init(false);
wvd_vegt 26:34c65d3f6da0 178 prompt();
wvd_vegt 26:34c65d3f6da0 179
wvd_vegt 26:34c65d3f6da0 180 return true;
wvd_vegt 26:34c65d3f6da0 181 }
wvd_vegt 26:34c65d3f6da0 182
wvd_vegt 26:34c65d3f6da0 183 //TODO BACKSPACE NOT CORRECT FOR TELNET!
wvd_vegt 26:34c65d3f6da0 184
wvd_vegt 26:34c65d3f6da0 185 if (c == '\b') { // Backspace
wvd_vegt 26:34c65d3f6da0 186 if (cmdndx != 0) {
wvd_vegt 26:34c65d3f6da0 187 print(bs);
wvd_vegt 26:34c65d3f6da0 188 cmdbuf [--cmdndx] = '\0';
wvd_vegt 26:34c65d3f6da0 189 } else {
wvd_vegt 26:34c65d3f6da0 190 printch(bell); // Output Error
wvd_vegt 26:34c65d3f6da0 191 }
wvd_vegt 26:34c65d3f6da0 192 return false;
wvd_vegt 26:34c65d3f6da0 193 }
wvd_vegt 26:34c65d3f6da0 194
wvd_vegt 26:34c65d3f6da0 195 if (c == '\177') { // Delete
wvd_vegt 26:34c65d3f6da0 196 while (cmdndx>0) {
wvd_vegt 26:34c65d3f6da0 197 print(bs);
wvd_vegt 26:34c65d3f6da0 198 cmdbuf [--cmdndx] = '\0';
wvd_vegt 26:34c65d3f6da0 199 }
wvd_vegt 26:34c65d3f6da0 200 return false;
wvd_vegt 26:34c65d3f6da0 201 }
wvd_vegt 26:34c65d3f6da0 202
wvd_vegt 26:34c65d3f6da0 203 //Reset Escape Buffer.
wvd_vegt 26:34c65d3f6da0 204 if (c == '\033') {
wvd_vegt 26:34c65d3f6da0 205 if (escndx!=0) {
wvd_vegt 26:34c65d3f6da0 206 //_putchar(bell); // Output Error
wvd_vegt 26:34c65d3f6da0 207 //printf("%s\r\n",escbuf);
wvd_vegt 26:34c65d3f6da0 208 }
wvd_vegt 26:34c65d3f6da0 209 escndx = 0;
wvd_vegt 26:34c65d3f6da0 210 escbuf [escndx] = '\0'; // NULL-Terminate buffer
wvd_vegt 26:34c65d3f6da0 211 }
wvd_vegt 26:34c65d3f6da0 212
wvd_vegt 26:34c65d3f6da0 213 //Extract Escape Sequence.
wvd_vegt 26:34c65d3f6da0 214 if (c == '\033' || escndx ) { // Wait for escape
wvd_vegt 26:34c65d3f6da0 215 escbuf [escndx++] = (unsigned char) c; // Add to the buffer
wvd_vegt 26:34c65d3f6da0 216 escbuf [escndx] = '\0'; // NULL-Terminate buffer
wvd_vegt 26:34c65d3f6da0 217 if (isalpha(c)) {
wvd_vegt 26:34c65d3f6da0 218 switch (escid_search(escbuf)) {
wvd_vegt 26:34c65d3f6da0 219 case EID_CURSOR_LEFT : {
wvd_vegt 26:34c65d3f6da0 220 if (cmdndx != 0) { // Backspace?
wvd_vegt 26:34c65d3f6da0 221 print(bs);
wvd_vegt 26:34c65d3f6da0 222 cmdbuf [--cmdndx] = '\0';
wvd_vegt 26:34c65d3f6da0 223 } else {
wvd_vegt 26:34c65d3f6da0 224 printch(bell); // Output char
wvd_vegt 26:34c65d3f6da0 225 }
wvd_vegt 26:34c65d3f6da0 226 break;
wvd_vegt 26:34c65d3f6da0 227 }
wvd_vegt 26:34c65d3f6da0 228 case EID_CURSOR_UP : {
wvd_vegt 26:34c65d3f6da0 229 for (i=0; i<cmdndx; i++) {
wvd_vegt 26:34c65d3f6da0 230 print(bs);
wvd_vegt 26:34c65d3f6da0 231 }
wvd_vegt 26:34c65d3f6da0 232 cmdndx=strlen(lstbuf);
wvd_vegt 26:34c65d3f6da0 233 strncpy(cmdbuf,lstbuf,cmdndx);
wvd_vegt 26:34c65d3f6da0 234 cmdbuf[cmdndx]='\0';
wvd_vegt 26:34c65d3f6da0 235 printf("%s",cmdbuf);
wvd_vegt 26:34c65d3f6da0 236 break;
wvd_vegt 26:34c65d3f6da0 237 }
wvd_vegt 26:34c65d3f6da0 238 case EID_CURSOR_RIGHT:
wvd_vegt 26:34c65d3f6da0 239 break;
wvd_vegt 26:34c65d3f6da0 240 case EID_CURSOR_DOWN :
wvd_vegt 26:34c65d3f6da0 241 break;
wvd_vegt 26:34c65d3f6da0 242 case EID_LAST :
wvd_vegt 26:34c65d3f6da0 243 break;
wvd_vegt 26:34c65d3f6da0 244 default :
wvd_vegt 26:34c65d3f6da0 245 printch(bell);
wvd_vegt 26:34c65d3f6da0 246 break;
wvd_vegt 26:34c65d3f6da0 247 }
wvd_vegt 26:34c65d3f6da0 248 escndx=0;
wvd_vegt 26:34c65d3f6da0 249 escbuf [escndx] = '\0'; // NULL-Terminate buffer
wvd_vegt 26:34c65d3f6da0 250 }
wvd_vegt 26:34c65d3f6da0 251 return false;
wvd_vegt 26:34c65d3f6da0 252 }
wvd_vegt 26:34c65d3f6da0 253
wvd_vegt 26:34c65d3f6da0 254 if (c=='\n') { // LF
wvd_vegt 26:34c65d3f6da0 255 return false; // Dump it
wvd_vegt 26:34c65d3f6da0 256 }
wvd_vegt 26:34c65d3f6da0 257
wvd_vegt 26:34c65d3f6da0 258 if (!isprint (c)) { // Printable character?
wvd_vegt 26:34c65d3f6da0 259 printch(bell);
wvd_vegt 26:34c65d3f6da0 260 return false;
wvd_vegt 26:34c65d3f6da0 261 }
wvd_vegt 26:34c65d3f6da0 262
wvd_vegt 26:34c65d3f6da0 263 if (cmdndx >= MAX_CMD_LEN) { // Past buffer length?
wvd_vegt 26:34c65d3f6da0 264 printch(bell);
wvd_vegt 26:34c65d3f6da0 265 return false;
wvd_vegt 26:34c65d3f6da0 266 }
wvd_vegt 26:34c65d3f6da0 267
wvd_vegt 26:34c65d3f6da0 268 cmdbuf [cmdndx++] = (unsigned char) c; // Add to the buffer
wvd_vegt 26:34c65d3f6da0 269 cmdbuf [cmdndx] = '\0'; // NULL-Terminate buffer
wvd_vegt 26:34c65d3f6da0 270
wvd_vegt 26:34c65d3f6da0 271 if (echo) {
wvd_vegt 26:34c65d3f6da0 272 printch(c); // Output char
wvd_vegt 26:34c65d3f6da0 273 }
wvd_vegt 26:34c65d3f6da0 274
wvd_vegt 26:34c65d3f6da0 275 return false;
wvd_vegt 26:34c65d3f6da0 276 }
wvd_vegt 26:34c65d3f6da0 277
wvd_vegt 26:34c65d3f6da0 278 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 279
wvd_vegt 26:34c65d3f6da0 280 int Cmdb::printf(const char *format, ...) {
wvd_vegt 26:34c65d3f6da0 281 int cnt;
wvd_vegt 26:34c65d3f6da0 282
wvd_vegt 26:34c65d3f6da0 283 va_list args;
wvd_vegt 26:34c65d3f6da0 284 char buf[1024];
wvd_vegt 26:34c65d3f6da0 285
wvd_vegt 26:34c65d3f6da0 286 memset(buf,'\0',sizeof(buf));
wvd_vegt 26:34c65d3f6da0 287
wvd_vegt 26:34c65d3f6da0 288 va_start(args, format);
wvd_vegt 26:34c65d3f6da0 289 cnt = vsnprintf(buf, sizeof(buf), format, args);
wvd_vegt 26:34c65d3f6da0 290 if (cnt==-1) {
wvd_vegt 26:34c65d3f6da0 291 //Error
wvd_vegt 26:34c65d3f6da0 292 }
wvd_vegt 26:34c65d3f6da0 293 va_end(args);
wvd_vegt 26:34c65d3f6da0 294
wvd_vegt 26:34c65d3f6da0 295 return print(buf);
wvd_vegt 26:34c65d3f6da0 296 }
wvd_vegt 26:34c65d3f6da0 297
wvd_vegt 26:34c65d3f6da0 298 int Cmdb::print(const char *msg) {
wvd_vegt 26:34c65d3f6da0 299 return serial.printf(msg);
wvd_vegt 26:34c65d3f6da0 300 }
wvd_vegt 26:34c65d3f6da0 301
wvd_vegt 26:34c65d3f6da0 302 int Cmdb::println(const char *msg) {
wvd_vegt 26:34c65d3f6da0 303 return serial.printf("%s\r\n", msg);
wvd_vegt 26:34c65d3f6da0 304 }
wvd_vegt 26:34c65d3f6da0 305
wvd_vegt 26:34c65d3f6da0 306 int Cmdb::printsection(const char *section) {
wvd_vegt 26:34c65d3f6da0 307 return printf("[%s]\r\n", section);
wvd_vegt 26:34c65d3f6da0 308 }
wvd_vegt 26:34c65d3f6da0 309
wvd_vegt 26:34c65d3f6da0 310 int Cmdb::printmsg(const char *msg) {
wvd_vegt 26:34c65d3f6da0 311 return printf("Msg=%s\r\n", msg);
wvd_vegt 26:34c65d3f6da0 312 }
wvd_vegt 26:34c65d3f6da0 313
wvd_vegt 26:34c65d3f6da0 314 int Cmdb::printerror(const char *errormsg) {
wvd_vegt 26:34c65d3f6da0 315 int a = printsection("Error");
wvd_vegt 26:34c65d3f6da0 316 return a==0?a:a+printmsg(errormsg);
wvd_vegt 26:34c65d3f6da0 317 }
wvd_vegt 26:34c65d3f6da0 318
wvd_vegt 26:34c65d3f6da0 319 int Cmdb::printerrorf(const char *format, ...) {
wvd_vegt 26:34c65d3f6da0 320 char buf[256];
wvd_vegt 26:34c65d3f6da0 321
wvd_vegt 26:34c65d3f6da0 322 int a = printsection("Error");
wvd_vegt 26:34c65d3f6da0 323
wvd_vegt 26:34c65d3f6da0 324 va_list args;
wvd_vegt 26:34c65d3f6da0 325 va_start(args, format);
wvd_vegt 26:34c65d3f6da0 326
wvd_vegt 26:34c65d3f6da0 327 vsnprintf(buf, sizeof(buf), format, args);
wvd_vegt 26:34c65d3f6da0 328
wvd_vegt 26:34c65d3f6da0 329 va_end(args);
wvd_vegt 26:34c65d3f6da0 330
wvd_vegt 26:34c65d3f6da0 331 return a + printf("Msg=%s\r\n", buf);
wvd_vegt 26:34c65d3f6da0 332 }
wvd_vegt 26:34c65d3f6da0 333
wvd_vegt 26:34c65d3f6da0 334 int Cmdb::printvaluef(const char *key, const char *format, ...) {
wvd_vegt 26:34c65d3f6da0 335 char buf[256];
wvd_vegt 26:34c65d3f6da0 336
wvd_vegt 26:34c65d3f6da0 337 va_list args;
wvd_vegt 26:34c65d3f6da0 338 va_start(args, format);
wvd_vegt 26:34c65d3f6da0 339
wvd_vegt 26:34c65d3f6da0 340 vsnprintf(buf, sizeof(buf), format, args);
wvd_vegt 26:34c65d3f6da0 341
wvd_vegt 26:34c65d3f6da0 342 va_end(args);
wvd_vegt 26:34c65d3f6da0 343
wvd_vegt 26:34c65d3f6da0 344 return printf("%s=%s\r\n",key, buf);
wvd_vegt 26:34c65d3f6da0 345 }
wvd_vegt 26:34c65d3f6da0 346
wvd_vegt 26:34c65d3f6da0 347 int Cmdb::printvaluef(const char *key, const int width, const char *comment, const char *format, ...) {
wvd_vegt 26:34c65d3f6da0 348 char buf[256];
wvd_vegt 26:34c65d3f6da0 349
wvd_vegt 26:34c65d3f6da0 350 int cnt = printf("%s=",key);
wvd_vegt 26:34c65d3f6da0 351
wvd_vegt 26:34c65d3f6da0 352 va_list args;
wvd_vegt 26:34c65d3f6da0 353 va_start(args, format);
wvd_vegt 26:34c65d3f6da0 354
wvd_vegt 26:34c65d3f6da0 355 vsnprintf(buf, sizeof(buf), format, args);
wvd_vegt 26:34c65d3f6da0 356
wvd_vegt 26:34c65d3f6da0 357 va_end(args);
wvd_vegt 26:34c65d3f6da0 358
wvd_vegt 26:34c65d3f6da0 359 if (comment!=NULL) {
wvd_vegt 26:34c65d3f6da0 360 cnt += printf("%s", buf);
wvd_vegt 26:34c65d3f6da0 361
wvd_vegt 26:34c65d3f6da0 362 if (cnt<width) {
wvd_vegt 26:34c65d3f6da0 363 cnt += printf("%-*s ; %s\r\n", width - cnt - 1, "", comment);
wvd_vegt 26:34c65d3f6da0 364 } else {
wvd_vegt 26:34c65d3f6da0 365 cnt += printf("%s ; %s\r\n", "", comment);
wvd_vegt 26:34c65d3f6da0 366 }
wvd_vegt 26:34c65d3f6da0 367 } else {
wvd_vegt 26:34c65d3f6da0 368 cnt += printf("%s\r\n",buf);
wvd_vegt 26:34c65d3f6da0 369 }
wvd_vegt 26:34c65d3f6da0 370
wvd_vegt 26:34c65d3f6da0 371 return cnt;
wvd_vegt 26:34c65d3f6da0 372 }
wvd_vegt 26:34c65d3f6da0 373
wvd_vegt 26:34c65d3f6da0 374 int Cmdb::printvalue(const char *key, const char *value, const char *comment, const int width) {
wvd_vegt 26:34c65d3f6da0 375 if (comment) {
wvd_vegt 26:34c65d3f6da0 376 char buf[256];
wvd_vegt 26:34c65d3f6da0 377 int cnt = 0;
wvd_vegt 26:34c65d3f6da0 378
wvd_vegt 26:34c65d3f6da0 379 memset(buf,'\0',sizeof(buf));
wvd_vegt 26:34c65d3f6da0 380
wvd_vegt 26:34c65d3f6da0 381 cnt = snprintf(buf, sizeof(buf), "%s=%s", key, value);
wvd_vegt 26:34c65d3f6da0 382
wvd_vegt 26:34c65d3f6da0 383 if (cnt<=width) {
wvd_vegt 26:34c65d3f6da0 384 return printf("%-*s ; %s\r\n", width - cnt + 1, buf, comment);
wvd_vegt 26:34c65d3f6da0 385 } else {
wvd_vegt 26:34c65d3f6da0 386 return printf("%s ; %s\r\n", buf, comment);
wvd_vegt 26:34c65d3f6da0 387 }
wvd_vegt 26:34c65d3f6da0 388 } else {
wvd_vegt 26:34c65d3f6da0 389 return printf("%s=%s\r\n", key, value);
wvd_vegt 26:34c65d3f6da0 390 }
wvd_vegt 26:34c65d3f6da0 391 }
wvd_vegt 26:34c65d3f6da0 392
wvd_vegt 26:34c65d3f6da0 393 int Cmdb::printcomment(const char *comment, const int width) {
wvd_vegt 26:34c65d3f6da0 394 return printf("%-*s; %s\r\n", width, "", comment);
wvd_vegt 26:34c65d3f6da0 395 }
wvd_vegt 26:34c65d3f6da0 396
wvd_vegt 26:34c65d3f6da0 397 char Cmdb::printch(const char ch) {
wvd_vegt 26:34c65d3f6da0 398 return serial.putc(ch);
wvd_vegt 26:34c65d3f6da0 399 }
wvd_vegt 26:34c65d3f6da0 400
wvd_vegt 26:34c65d3f6da0 401 //Mode=1 ; Profile Position Mode
wvd_vegt 26:34c65d3f6da0 402 //1234567890123456789012
wvd_vegt 26:34c65d3f6da0 403
wvd_vegt 26:34c65d3f6da0 404 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 405
wvd_vegt 26:34c65d3f6da0 406 void Cmdb::init(const char full) {
wvd_vegt 26:34c65d3f6da0 407 if (full) {
wvd_vegt 26:34c65d3f6da0 408 echo = true;
wvd_vegt 26:34c65d3f6da0 409 bold = true;
wvd_vegt 26:34c65d3f6da0 410
wvd_vegt 26:34c65d3f6da0 411 subsystem = -1;
wvd_vegt 26:34c65d3f6da0 412
wvd_vegt 26:34c65d3f6da0 413 lstbuf [cmdndx] = '\0';
wvd_vegt 26:34c65d3f6da0 414
wvd_vegt 26:34c65d3f6da0 415 macro_reset();
wvd_vegt 26:34c65d3f6da0 416
wvd_vegt 26:34c65d3f6da0 417 prompt();
wvd_vegt 26:34c65d3f6da0 418 }
wvd_vegt 26:34c65d3f6da0 419
wvd_vegt 26:34c65d3f6da0 420 cmdndx = 0;
wvd_vegt 26:34c65d3f6da0 421 cmdbuf [cmdndx] = '\0';
wvd_vegt 26:34c65d3f6da0 422
wvd_vegt 26:34c65d3f6da0 423 escndx = 0;
wvd_vegt 26:34c65d3f6da0 424 escbuf [escndx] = '\0';
wvd_vegt 26:34c65d3f6da0 425 }
wvd_vegt 26:34c65d3f6da0 426
wvd_vegt 26:34c65d3f6da0 427 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 428 //Private Stuff.
wvd_vegt 26:34c65d3f6da0 429 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 430
wvd_vegt 26:34c65d3f6da0 431 int Cmdb::escid_search(char *escstr) {
wvd_vegt 26:34c65d3f6da0 432 for (int i=0; i<ESC_TBL_LEN; i++) {
wvd_vegt 26:34c65d3f6da0 433 if (strcmp (esc_tbl[i].escstr, escstr) == 0)
wvd_vegt 26:34c65d3f6da0 434 return (esc_tbl[i].id);
wvd_vegt 26:34c65d3f6da0 435 }
wvd_vegt 26:34c65d3f6da0 436
wvd_vegt 26:34c65d3f6da0 437 return (EID_LAST);
wvd_vegt 26:34c65d3f6da0 438 }
wvd_vegt 26:34c65d3f6da0 439
wvd_vegt 26:34c65d3f6da0 440 int Cmdb::cmdid_search(char *cmdstr) {
wvd_vegt 26:34c65d3f6da0 441 //Warning, we return the ID but somewhere assume it's equal to the array index!
wvd_vegt 26:34c65d3f6da0 442 for (int i=0; i<cmds.size(); i++) {
wvd_vegt 26:34c65d3f6da0 443 if ((stricmp((char*)cmds[i].cmdstr, cmdstr) == 0) && ((cmds[i].subs == subsystem) || (cmds[i].subs<0)))
wvd_vegt 26:34c65d3f6da0 444 return (cmds[i].cid);
wvd_vegt 26:34c65d3f6da0 445 }
wvd_vegt 26:34c65d3f6da0 446
wvd_vegt 26:34c65d3f6da0 447 return CID_LAST;
wvd_vegt 26:34c65d3f6da0 448 }
wvd_vegt 26:34c65d3f6da0 449
wvd_vegt 26:34c65d3f6da0 450 int Cmdb::cmdid_index(int cmdid) {
wvd_vegt 26:34c65d3f6da0 451 for (int i=0; i<cmds.size(); i++) {
wvd_vegt 26:34c65d3f6da0 452 if (cmds[i].cid==cmdid)
wvd_vegt 26:34c65d3f6da0 453 return i;
wvd_vegt 26:34c65d3f6da0 454 }
wvd_vegt 26:34c65d3f6da0 455
wvd_vegt 26:34c65d3f6da0 456 return -1;
wvd_vegt 26:34c65d3f6da0 457 }
wvd_vegt 26:34c65d3f6da0 458
wvd_vegt 26:34c65d3f6da0 459 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 460
wvd_vegt 26:34c65d3f6da0 461 int Cmdb::parse(char *cmd) {
wvd_vegt 26:34c65d3f6da0 462 //Command
wvd_vegt 26:34c65d3f6da0 463 char cmdstr_buf [1 + MAX_CMD_LEN];
wvd_vegt 26:34c65d3f6da0 464
wvd_vegt 26:34c65d3f6da0 465 //Parameters
wvd_vegt 26:34c65d3f6da0 466 char argstr_buf [1 + MAX_CMD_LEN];
wvd_vegt 26:34c65d3f6da0 467 char *argsep;
wvd_vegt 26:34c65d3f6da0 468
wvd_vegt 26:34c65d3f6da0 469 char prmstr_buf [1 + MAX_CMD_LEN]; //copy of sscanf pattern
wvd_vegt 26:34c65d3f6da0 470 char *tok; //current token
wvd_vegt 26:34c65d3f6da0 471 void *toks[MAX_ARGS]; //pointers to string tokens IN commandline (argstr_buf)
wvd_vegt 26:34c65d3f6da0 472 char *prms[MAX_ARGS]; //patterns IN copy of sscanf string (*parms)
wvd_vegt 26:34c65d3f6da0 473
wvd_vegt 26:34c65d3f6da0 474 char typ = '\0'; //Var type
wvd_vegt 26:34c65d3f6da0 475 char mod = '\0'; //Var modifier (for cardinal types)
wvd_vegt 26:34c65d3f6da0 476 unsigned int base; //Var number base (8,10,16)
wvd_vegt 26:34c65d3f6da0 477 //unsigned int bytes; //Var size in bytes (used for malloc)
wvd_vegt 26:34c65d3f6da0 478
wvd_vegt 26:34c65d3f6da0 479 float f; //Temp var for conversion, 4 bytes
wvd_vegt 26:34c65d3f6da0 480 //unsigned char b; //Temp var for conversion, 1 byte
wvd_vegt 26:34c65d3f6da0 481 //char c; //Temp var for conversion, 1 byte
wvd_vegt 26:34c65d3f6da0 482 //short h; //Temp var for conversion, 2 bytes
wvd_vegt 26:34c65d3f6da0 483 //int k; //Temp var for conversion, 2 bytes
wvd_vegt 26:34c65d3f6da0 484 long l; //Temp var for conversion, 4 bytes
wvd_vegt 26:34c65d3f6da0 485
wvd_vegt 26:34c65d3f6da0 486 char* endptr; //strtoXX() Error detection
wvd_vegt 26:34c65d3f6da0 487
wvd_vegt 26:34c65d3f6da0 488 int cid = -1; //Signals empty string...
wvd_vegt 26:34c65d3f6da0 489 int ndx = -1;
wvd_vegt 26:34c65d3f6da0 490
wvd_vegt 26:34c65d3f6da0 491 //Init (global) variables.
wvd_vegt 26:34c65d3f6da0 492 argfnd=0;
wvd_vegt 26:34c65d3f6da0 493 argcnt=0;
wvd_vegt 26:34c65d3f6da0 494 error =0;
wvd_vegt 26:34c65d3f6da0 495
wvd_vegt 26:34c65d3f6da0 496 //Zero the two string buffers for splitting cmd string into.
wvd_vegt 26:34c65d3f6da0 497 zeromemory((char*)cmdstr_buf,sizeof(cmdstr_buf));
wvd_vegt 26:34c65d3f6da0 498 zeromemory(argstr_buf,sizeof(argstr_buf));
wvd_vegt 26:34c65d3f6da0 499
wvd_vegt 26:34c65d3f6da0 500 //Make it worse in Lint
wvd_vegt 26:34c65d3f6da0 501 for (int i=0; i<MAX_ARGS; i++) {
wvd_vegt 26:34c65d3f6da0 502 parms[i].type=PARM_UNUSED;
wvd_vegt 26:34c65d3f6da0 503 zeromemory((char*)&(parms[i].val),sizeof(parms[i].val));
wvd_vegt 26:34c65d3f6da0 504 }
wvd_vegt 26:34c65d3f6da0 505
wvd_vegt 26:34c65d3f6da0 506 /*------------------------------------------------
wvd_vegt 26:34c65d3f6da0 507 First, copy the command and convert it to all
wvd_vegt 26:34c65d3f6da0 508 uppercase.
wvd_vegt 26:34c65d3f6da0 509 ------------------------------------------------*/
wvd_vegt 26:34c65d3f6da0 510
wvd_vegt 26:34c65d3f6da0 511 strncpy(cmdstr_buf, cmd, sizeof (cmdstr_buf) - 1);
wvd_vegt 26:34c65d3f6da0 512 cmdstr_buf [sizeof (cmdstr_buf) - 1] = '\0';
wvd_vegt 26:34c65d3f6da0 513
wvd_vegt 26:34c65d3f6da0 514 /*------------------------------------------------
wvd_vegt 26:34c65d3f6da0 515 Next, find the end of the first thing in the
wvd_vegt 26:34c65d3f6da0 516 buffer. Since the command ends with a space,
wvd_vegt 26:34c65d3f6da0 517 we'll look for that. NULL-Terminate the command
wvd_vegt 26:34c65d3f6da0 518 and keep a pointer to the arguments.
wvd_vegt 26:34c65d3f6da0 519 ------------------------------------------------*/
wvd_vegt 26:34c65d3f6da0 520
wvd_vegt 26:34c65d3f6da0 521 argsep = strchr(cmdstr_buf, ' ');
wvd_vegt 26:34c65d3f6da0 522
wvd_vegt 26:34c65d3f6da0 523 if (argsep == NULL) {
wvd_vegt 26:34c65d3f6da0 524 argstr_buf [0] = '\0';
wvd_vegt 26:34c65d3f6da0 525 } else {
wvd_vegt 26:34c65d3f6da0 526 strcpy (argstr_buf, argsep + 1);
wvd_vegt 26:34c65d3f6da0 527 *argsep = '\0';
wvd_vegt 26:34c65d3f6da0 528 }
wvd_vegt 26:34c65d3f6da0 529
wvd_vegt 26:34c65d3f6da0 530 /*------------------------------------------------
wvd_vegt 26:34c65d3f6da0 531 Search for a command ID, then switch on it.
wvd_vegt 26:34c65d3f6da0 532 ------------------------------------------------*/
wvd_vegt 26:34c65d3f6da0 533
wvd_vegt 26:34c65d3f6da0 534 //1) Find the Command Id
wvd_vegt 26:34c65d3f6da0 535 cid = cmdid_search(cmdstr_buf);
wvd_vegt 26:34c65d3f6da0 536
wvd_vegt 26:34c65d3f6da0 537 if (cid!=CID_LAST) {
wvd_vegt 26:34c65d3f6da0 538 //2) Tokenize a copy of the parms from the cmd_tbl.
wvd_vegt 26:34c65d3f6da0 539
wvd_vegt 26:34c65d3f6da0 540 ndx = cmdid_index(cid);
wvd_vegt 26:34c65d3f6da0 541
wvd_vegt 26:34c65d3f6da0 542 //Get Format patterns from cmd_tbl[id].parms.
wvd_vegt 26:34c65d3f6da0 543 //note: strtok inserts \0 into the original string. Hence the copy.
wvd_vegt 26:34c65d3f6da0 544 zeromemory((char *)(&prmstr_buf),sizeof(prmstr_buf));
wvd_vegt 26:34c65d3f6da0 545
wvd_vegt 26:34c65d3f6da0 546 strncpy (prmstr_buf, cmds[ndx].parms, sizeof (prmstr_buf) - 1);
wvd_vegt 26:34c65d3f6da0 547
wvd_vegt 26:34c65d3f6da0 548 argcnt=0;
wvd_vegt 26:34c65d3f6da0 549 tok = strtok(prmstr_buf, " ");
wvd_vegt 26:34c65d3f6da0 550 while (tok != NULL) {
wvd_vegt 26:34c65d3f6da0 551 //Store Pointers
wvd_vegt 26:34c65d3f6da0 552 prms[argcnt++] = tok;
wvd_vegt 26:34c65d3f6da0 553
wvd_vegt 26:34c65d3f6da0 554 //printf("prm_%2.2d='%s'\r\n",argcnt, tok);
wvd_vegt 26:34c65d3f6da0 555
wvd_vegt 26:34c65d3f6da0 556 tok = strtok(NULL, " ");
wvd_vegt 26:34c65d3f6da0 557 }
wvd_vegt 26:34c65d3f6da0 558
wvd_vegt 26:34c65d3f6da0 559 //3) Tokenize the commandline.
wvd_vegt 26:34c65d3f6da0 560
wvd_vegt 26:34c65d3f6da0 561 //Get Tokens from arguments.
wvd_vegt 26:34c65d3f6da0 562 //Note: strtok inserts \0 into the original string. Won't harm here as we do not re-use it.
wvd_vegt 26:34c65d3f6da0 563
wvd_vegt 26:34c65d3f6da0 564 argfnd=0;
wvd_vegt 26:34c65d3f6da0 565
wvd_vegt 26:34c65d3f6da0 566 if (strlen(argstr_buf)!=0) {
wvd_vegt 26:34c65d3f6da0 567 tok = strtok(argstr_buf, " ");
wvd_vegt 26:34c65d3f6da0 568 } else {
wvd_vegt 26:34c65d3f6da0 569 tok=NULL;
wvd_vegt 26:34c65d3f6da0 570 }
wvd_vegt 26:34c65d3f6da0 571
wvd_vegt 26:34c65d3f6da0 572 while (tok != NULL) {
wvd_vegt 26:34c65d3f6da0 573 //Store Pointers
wvd_vegt 26:34c65d3f6da0 574 toks[argfnd++]=tok;
wvd_vegt 26:34c65d3f6da0 575
wvd_vegt 26:34c65d3f6da0 576 //printf("tok_%2.2d='%s'\r\n",argfnd, tok);
wvd_vegt 26:34c65d3f6da0 577
wvd_vegt 26:34c65d3f6da0 578 tok = strtok(NULL, " ");
wvd_vegt 26:34c65d3f6da0 579 }
wvd_vegt 26:34c65d3f6da0 580
wvd_vegt 26:34c65d3f6da0 581 if (argfnd==argcnt || (cid==CID_HELP && argfnd==0)) {
wvd_vegt 26:34c65d3f6da0 582
wvd_vegt 26:34c65d3f6da0 583 error = 0;
wvd_vegt 26:34c65d3f6da0 584
wvd_vegt 26:34c65d3f6da0 585 for (int i=0; i<argcnt; i++) {
wvd_vegt 26:34c65d3f6da0 586 //printf("prm_%2.2d=%s\r\n",i, prms[i]);
wvd_vegt 26:34c65d3f6da0 587
wvd_vegt 26:34c65d3f6da0 588 switch (strlen(prms[i])) {
wvd_vegt 26:34c65d3f6da0 589 case 0:
wvd_vegt 26:34c65d3f6da0 590 break;
wvd_vegt 26:34c65d3f6da0 591 case 1:
wvd_vegt 26:34c65d3f6da0 592 break;
wvd_vegt 26:34c65d3f6da0 593 case 2: //Simple pattern, no modifier
wvd_vegt 26:34c65d3f6da0 594 mod='\0';
wvd_vegt 26:34c65d3f6da0 595 typ=prms[i][1];
wvd_vegt 26:34c65d3f6da0 596
wvd_vegt 26:34c65d3f6da0 597 break;
wvd_vegt 26:34c65d3f6da0 598 case 3: //pattern with Modifier.
wvd_vegt 26:34c65d3f6da0 599 mod=prms[i][1];
wvd_vegt 26:34c65d3f6da0 600 typ=prms[i][2];
wvd_vegt 26:34c65d3f6da0 601
wvd_vegt 26:34c65d3f6da0 602 break;
wvd_vegt 26:34c65d3f6da0 603 default:
wvd_vegt 26:34c65d3f6da0 604 break;
wvd_vegt 26:34c65d3f6da0 605 }
wvd_vegt 26:34c65d3f6da0 606
wvd_vegt 26:34c65d3f6da0 607 switch (typ) {
wvd_vegt 26:34c65d3f6da0 608 case 'o' :
wvd_vegt 26:34c65d3f6da0 609 base=8;
wvd_vegt 26:34c65d3f6da0 610 break;
wvd_vegt 26:34c65d3f6da0 611 case 'x' :
wvd_vegt 26:34c65d3f6da0 612 base=16;
wvd_vegt 26:34c65d3f6da0 613 break;
wvd_vegt 26:34c65d3f6da0 614 default:
wvd_vegt 26:34c65d3f6da0 615 base=10;
wvd_vegt 26:34c65d3f6da0 616 break;
wvd_vegt 26:34c65d3f6da0 617 }
wvd_vegt 26:34c65d3f6da0 618
wvd_vegt 26:34c65d3f6da0 619 endptr = (char*)toks[i];
wvd_vegt 26:34c65d3f6da0 620
wvd_vegt 26:34c65d3f6da0 621 switch (typ) {
wvd_vegt 26:34c65d3f6da0 622 //Signed Cardinal Types
wvd_vegt 26:34c65d3f6da0 623 case 'd' : //Check mod
wvd_vegt 26:34c65d3f6da0 624 case 'i' : //Check mod
wvd_vegt 26:34c65d3f6da0 625 switch (mod) {
wvd_vegt 26:34c65d3f6da0 626 case 'b' : //char
wvd_vegt 26:34c65d3f6da0 627 //test range
wvd_vegt 26:34c65d3f6da0 628 l=strtol((char*)toks[i], &endptr, base);
wvd_vegt 26:34c65d3f6da0 629 if (l>=MIN_CHAR && l<=MAX_CHAR) {
wvd_vegt 26:34c65d3f6da0 630 parms[i].type=PARM_CHAR;
wvd_vegt 26:34c65d3f6da0 631 parms[i].val.uc =(unsigned char)l;
wvd_vegt 26:34c65d3f6da0 632 } else {
wvd_vegt 26:34c65d3f6da0 633 error = i+1;
wvd_vegt 26:34c65d3f6da0 634 }
wvd_vegt 26:34c65d3f6da0 635
wvd_vegt 26:34c65d3f6da0 636 break;
wvd_vegt 26:34c65d3f6da0 637 case 'h' : //short
wvd_vegt 26:34c65d3f6da0 638 l=strtol((char*)toks[i], &endptr, base);
wvd_vegt 26:34c65d3f6da0 639 if (l>=MIN_SHORT && l<=MAX_SHORT) {
wvd_vegt 26:34c65d3f6da0 640 parms[i].type=PARM_SHORT;
wvd_vegt 26:34c65d3f6da0 641 parms[i].val.w=(short)l;
wvd_vegt 26:34c65d3f6da0 642 } else {
wvd_vegt 26:34c65d3f6da0 643 error = i+1;
wvd_vegt 26:34c65d3f6da0 644 }
wvd_vegt 26:34c65d3f6da0 645
wvd_vegt 26:34c65d3f6da0 646 break;
wvd_vegt 26:34c65d3f6da0 647 case 'l' : //long
wvd_vegt 26:34c65d3f6da0 648 l=strtol((char*)toks[i], &endptr, base);
wvd_vegt 26:34c65d3f6da0 649 parms[i].type=PARM_LONG;
wvd_vegt 26:34c65d3f6da0 650 parms[i].val.l=l;
wvd_vegt 26:34c65d3f6da0 651
wvd_vegt 26:34c65d3f6da0 652 break;
wvd_vegt 26:34c65d3f6da0 653 default: //int
wvd_vegt 26:34c65d3f6da0 654 l=strtol((char*)toks[i], &endptr, base);
wvd_vegt 26:34c65d3f6da0 655 if (l>=MIN_INT && l<=MAX_INT) {
wvd_vegt 26:34c65d3f6da0 656 parms[i].type=PARM_INT;
wvd_vegt 26:34c65d3f6da0 657 parms[i].val.l=(int)l;
wvd_vegt 26:34c65d3f6da0 658 } else {
wvd_vegt 26:34c65d3f6da0 659 error = i+1;
wvd_vegt 26:34c65d3f6da0 660 }
wvd_vegt 26:34c65d3f6da0 661 break;
wvd_vegt 26:34c65d3f6da0 662 }
wvd_vegt 26:34c65d3f6da0 663
wvd_vegt 26:34c65d3f6da0 664 if (error==0 &&
wvd_vegt 26:34c65d3f6da0 665 (endptr==toks[i] //No Conversion at all.
wvd_vegt 26:34c65d3f6da0 666 || *endptr)) { //Incomplete conversion.
wvd_vegt 26:34c65d3f6da0 667 error = i+1;
wvd_vegt 26:34c65d3f6da0 668 }
wvd_vegt 26:34c65d3f6da0 669
wvd_vegt 26:34c65d3f6da0 670 break;
wvd_vegt 26:34c65d3f6da0 671
wvd_vegt 26:34c65d3f6da0 672 //Unsigned Cardinal Types
wvd_vegt 26:34c65d3f6da0 673 case 'u' : //Check mod
wvd_vegt 26:34c65d3f6da0 674 case 'o' : //Check mod
wvd_vegt 26:34c65d3f6da0 675 case 'x' : //Check mod
wvd_vegt 26:34c65d3f6da0 676 switch (mod) {
wvd_vegt 26:34c65d3f6da0 677 case 'b' : //char
wvd_vegt 26:34c65d3f6da0 678 //test range
wvd_vegt 26:34c65d3f6da0 679 l=strtol((char*)toks[i], &endptr, base);
wvd_vegt 26:34c65d3f6da0 680 if (l>=MIN_BYTE && l<=MAX_BYTE) {
wvd_vegt 26:34c65d3f6da0 681 parms[i].type=PARM_CHAR;
wvd_vegt 26:34c65d3f6da0 682 parms[i].val.uc =(unsigned char)l;
wvd_vegt 26:34c65d3f6da0 683 } else {
wvd_vegt 26:34c65d3f6da0 684 error = i+1;
wvd_vegt 26:34c65d3f6da0 685 }
wvd_vegt 26:34c65d3f6da0 686
wvd_vegt 26:34c65d3f6da0 687 break;
wvd_vegt 26:34c65d3f6da0 688 case 'h' : //short
wvd_vegt 26:34c65d3f6da0 689 l=strtol((char*)toks[i], &endptr, base);
wvd_vegt 26:34c65d3f6da0 690 if (l>=MIN_USHORT && l<=MAX_USHORT) {
wvd_vegt 26:34c65d3f6da0 691 parms[i].type=PARM_SHORT;
wvd_vegt 26:34c65d3f6da0 692 parms[i].val.w=(short)l;
wvd_vegt 26:34c65d3f6da0 693 } else {
wvd_vegt 26:34c65d3f6da0 694 error = i+1;
wvd_vegt 26:34c65d3f6da0 695 }
wvd_vegt 26:34c65d3f6da0 696
wvd_vegt 26:34c65d3f6da0 697 break;
wvd_vegt 26:34c65d3f6da0 698 case 'l' : //long
wvd_vegt 26:34c65d3f6da0 699 l=strtol((char*)toks[i], &endptr, base);
wvd_vegt 26:34c65d3f6da0 700 parms[i].type=PARM_LONG;
wvd_vegt 26:34c65d3f6da0 701 parms[i].val.l=l;
wvd_vegt 26:34c65d3f6da0 702
wvd_vegt 26:34c65d3f6da0 703 break;
wvd_vegt 26:34c65d3f6da0 704 default: //int
wvd_vegt 26:34c65d3f6da0 705 l=strtol((char*)toks[i], &endptr, base);
wvd_vegt 26:34c65d3f6da0 706 if (l>=MIN_UINT && l<=MAX_UINT) {
wvd_vegt 26:34c65d3f6da0 707 parms[i].type=PARM_INT;
wvd_vegt 26:34c65d3f6da0 708 parms[i].val.l=(int)l;
wvd_vegt 26:34c65d3f6da0 709 } else {
wvd_vegt 26:34c65d3f6da0 710 error = i+1;
wvd_vegt 26:34c65d3f6da0 711 }
wvd_vegt 26:34c65d3f6da0 712 break;
wvd_vegt 26:34c65d3f6da0 713 }
wvd_vegt 26:34c65d3f6da0 714
wvd_vegt 26:34c65d3f6da0 715 if (error==0 &&
wvd_vegt 26:34c65d3f6da0 716 (endptr==toks[i] //No Conversion at all.
wvd_vegt 26:34c65d3f6da0 717 || *endptr)) { //Incomplete conversion.
wvd_vegt 26:34c65d3f6da0 718 error = i+1;
wvd_vegt 26:34c65d3f6da0 719 }
wvd_vegt 26:34c65d3f6da0 720
wvd_vegt 26:34c65d3f6da0 721 break;
wvd_vegt 26:34c65d3f6da0 722 }
wvd_vegt 26:34c65d3f6da0 723
wvd_vegt 26:34c65d3f6da0 724 //Floating Point Types
wvd_vegt 26:34c65d3f6da0 725 switch (typ) {
wvd_vegt 26:34c65d3f6da0 726 case 'e' :
wvd_vegt 26:34c65d3f6da0 727 case 'f' :
wvd_vegt 26:34c65d3f6da0 728 case 'g' :
wvd_vegt 26:34c65d3f6da0 729 f = strtod((char*)toks[i], &endptr);
wvd_vegt 26:34c65d3f6da0 730
wvd_vegt 26:34c65d3f6da0 731 parms[i].type=PARM_FLOAT;
wvd_vegt 26:34c65d3f6da0 732 parms[i].val.f=f;
wvd_vegt 26:34c65d3f6da0 733
wvd_vegt 26:34c65d3f6da0 734 if (error==0 &&
wvd_vegt 26:34c65d3f6da0 735 (endptr==toks[i] //No Conversion at all.
wvd_vegt 26:34c65d3f6da0 736 || *endptr)) { //Incomplete conversion.
wvd_vegt 26:34c65d3f6da0 737 error = i;
wvd_vegt 26:34c65d3f6da0 738 }
wvd_vegt 26:34c65d3f6da0 739
wvd_vegt 26:34c65d3f6da0 740 break;
wvd_vegt 26:34c65d3f6da0 741 }
wvd_vegt 26:34c65d3f6da0 742
wvd_vegt 26:34c65d3f6da0 743 //String types
wvd_vegt 26:34c65d3f6da0 744 switch (typ) {
wvd_vegt 26:34c65d3f6da0 745 case 'c' :
wvd_vegt 26:34c65d3f6da0 746 parms[i].type=PARM_CHAR;
wvd_vegt 26:34c65d3f6da0 747 parms[i].val.c=((char*)toks[i])[0];
wvd_vegt 26:34c65d3f6da0 748
wvd_vegt 26:34c65d3f6da0 749 if (error==0 && strlen((char*)toks[i])!=1) { //Incomplete conversion.
wvd_vegt 26:34c65d3f6da0 750 error = i;
wvd_vegt 26:34c65d3f6da0 751 }
wvd_vegt 26:34c65d3f6da0 752
wvd_vegt 26:34c65d3f6da0 753 break;
wvd_vegt 26:34c65d3f6da0 754
wvd_vegt 26:34c65d3f6da0 755 case 's' :
wvd_vegt 26:34c65d3f6da0 756 parms[i].type=PARM_STRING;
wvd_vegt 26:34c65d3f6da0 757 strncpy(parms[i].val.s,(char*)toks[i], strlen((char*)toks[i]));
wvd_vegt 26:34c65d3f6da0 758
wvd_vegt 26:34c65d3f6da0 759 break;
wvd_vegt 26:34c65d3f6da0 760 }
wvd_vegt 26:34c65d3f6da0 761 }
wvd_vegt 26:34c65d3f6da0 762 } else {
wvd_vegt 26:34c65d3f6da0 763 //cid=CID_LAST;
wvd_vegt 26:34c65d3f6da0 764 }
wvd_vegt 26:34c65d3f6da0 765 }
wvd_vegt 26:34c65d3f6da0 766
wvd_vegt 26:34c65d3f6da0 767 return cid;
wvd_vegt 26:34c65d3f6da0 768 }
wvd_vegt 26:34c65d3f6da0 769
wvd_vegt 26:34c65d3f6da0 770 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 771
wvd_vegt 26:34c65d3f6da0 772 void Cmdb::cmd_dispatcher(char *cmd) {
wvd_vegt 26:34c65d3f6da0 773 int cid;
wvd_vegt 26:34c65d3f6da0 774 int ndx;
wvd_vegt 26:34c65d3f6da0 775
wvd_vegt 26:34c65d3f6da0 776 cid = parse(cmd);
wvd_vegt 26:34c65d3f6da0 777 ndx = cmdid_index(cid);
wvd_vegt 26:34c65d3f6da0 778
wvd_vegt 26:34c65d3f6da0 779 if (cid!=-1) {
wvd_vegt 26:34c65d3f6da0 780 //printf("cmds[%d]=%d\r\n",ndx, cid);
wvd_vegt 26:34c65d3f6da0 781
wvd_vegt 26:34c65d3f6da0 782 /*------------------------------------------------
wvd_vegt 26:34c65d3f6da0 783 Process the command and it's arguments that are
wvd_vegt 26:34c65d3f6da0 784 found. id contains the command id and argcnt &
wvd_vegt 26:34c65d3f6da0 785 argfnd the number of found and expected paramaters
wvd_vegt 26:34c65d3f6da0 786 parms contains the parsed argument values and their
wvd_vegt 26:34c65d3f6da0 787 types.
wvd_vegt 26:34c65d3f6da0 788 ------------------------------------------------*/
wvd_vegt 26:34c65d3f6da0 789
wvd_vegt 26:34c65d3f6da0 790 //printf("cmds[%d]=%d\r\n",ndx, cid);
wvd_vegt 26:34c65d3f6da0 791
wvd_vegt 26:34c65d3f6da0 792 if (cid==CID_LAST) {
wvd_vegt 26:34c65d3f6da0 793 print("Unknown command, type 'Help' for a list of available commands.\r\n");
wvd_vegt 26:34c65d3f6da0 794 } else {
wvd_vegt 26:34c65d3f6da0 795 //printf("cmds[%d]=%d [%s]\r\n",ndx, cid, cmds[ndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 796
wvd_vegt 26:34c65d3f6da0 797 //Test for more commandline than allowed too.
wvd_vegt 26:34c65d3f6da0 798 //i.e. run 1 is wrong.
wvd_vegt 26:34c65d3f6da0 799
wvd_vegt 26:34c65d3f6da0 800 if (argcnt==0 && argfnd==0 && error==0 && ndx!=-1 && cmds[ndx].subs==SUBSYSTEM) {
wvd_vegt 26:34c65d3f6da0 801 //Handle all SubSystems.
wvd_vegt 26:34c65d3f6da0 802 subsystem=cid;
wvd_vegt 26:34c65d3f6da0 803 } else if ( ((cid==CID_HELP) || (argcnt==argfnd)) && error==0 ) {
wvd_vegt 26:34c65d3f6da0 804 switch (cid) {
wvd_vegt 26:34c65d3f6da0 805
wvd_vegt 26:34c65d3f6da0 806 #ifdef ENABLEMACROS
wvd_vegt 26:34c65d3f6da0 807 /////// GLOBAL MACRO COMMANDS ///////
wvd_vegt 26:34c65d3f6da0 808
wvd_vegt 26:34c65d3f6da0 809 //Define Macro from commandline
wvd_vegt 26:34c65d3f6da0 810 case CID_MACRO:
wvd_vegt 26:34c65d3f6da0 811 macro_ptr=-1;
wvd_vegt 26:34c65d3f6da0 812
wvd_vegt 26:34c65d3f6da0 813 zeromemory((char*)macro_buf, sizeof(macro_buf));
wvd_vegt 26:34c65d3f6da0 814 strncpy(macro_buf, STRINGPARM(0), sizeof(macro_buf) - 1);
wvd_vegt 26:34c65d3f6da0 815
wvd_vegt 26:34c65d3f6da0 816 //DEBUG
wvd_vegt 26:34c65d3f6da0 817 printf("Macro=%s\r\n",macro_buf);
wvd_vegt 26:34c65d3f6da0 818 break;
wvd_vegt 26:34c65d3f6da0 819
wvd_vegt 26:34c65d3f6da0 820 //Run Macro
wvd_vegt 26:34c65d3f6da0 821 case CID_RUN:
wvd_vegt 26:34c65d3f6da0 822 macro_ptr=0;
wvd_vegt 26:34c65d3f6da0 823 break;
wvd_vegt 26:34c65d3f6da0 824
wvd_vegt 26:34c65d3f6da0 825 //List Macro's
wvd_vegt 26:34c65d3f6da0 826 case CID_MACROS:
wvd_vegt 26:34c65d3f6da0 827 print("[Macro]\r\n");
wvd_vegt 26:34c65d3f6da0 828 if (macro_buf[0]!='\0') {
wvd_vegt 26:34c65d3f6da0 829 printf("Value=%s\r\n",macro_buf);
wvd_vegt 26:34c65d3f6da0 830 } else {
wvd_vegt 26:34c65d3f6da0 831 printf(";No Macro Defined\r\n");
wvd_vegt 26:34c65d3f6da0 832 }
wvd_vegt 26:34c65d3f6da0 833 break;
wvd_vegt 26:34c65d3f6da0 834
wvd_vegt 26:34c65d3f6da0 835 #endif //ENABLEMACROS
wvd_vegt 26:34c65d3f6da0 836
wvd_vegt 26:34c65d3f6da0 837 #ifdef STATEMACHINE
wvd_vegt 26:34c65d3f6da0 838 /////// GLOBAL STATEMACHINE COMMANDS ///////
wvd_vegt 26:34c65d3f6da0 839
wvd_vegt 26:34c65d3f6da0 840 //Start State Machine
wvd_vegt 26:34c65d3f6da0 841 case CID_STATE:
wvd_vegt 26:34c65d3f6da0 842 statemachine(BYTEPARM(0));
wvd_vegt 26:34c65d3f6da0 843
wvd_vegt 26:34c65d3f6da0 844 break;
wvd_vegt 26:34c65d3f6da0 845 #endif
wvd_vegt 26:34c65d3f6da0 846
wvd_vegt 26:34c65d3f6da0 847 /////// GLOBAL COMMANDS ///////
wvd_vegt 26:34c65d3f6da0 848 case CID_COMMANDS:
wvd_vegt 26:34c65d3f6da0 849 cmd_dump();
wvd_vegt 26:34c65d3f6da0 850 break;
wvd_vegt 26:34c65d3f6da0 851
wvd_vegt 26:34c65d3f6da0 852 //Echo
wvd_vegt 26:34c65d3f6da0 853 case CID_ECHO:
wvd_vegt 26:34c65d3f6da0 854 echo = BOOLPARM(0);
wvd_vegt 26:34c65d3f6da0 855 break;
wvd_vegt 26:34c65d3f6da0 856
wvd_vegt 26:34c65d3f6da0 857 //Bold
wvd_vegt 26:34c65d3f6da0 858 case CID_BOLD:
wvd_vegt 26:34c65d3f6da0 859 bold = BOOLPARM(0);
wvd_vegt 26:34c65d3f6da0 860 break;
wvd_vegt 26:34c65d3f6da0 861
wvd_vegt 26:34c65d3f6da0 862 //Warm Boot
wvd_vegt 26:34c65d3f6da0 863 case CID_BOOT:
wvd_vegt 26:34c65d3f6da0 864 mbed_reset();
wvd_vegt 26:34c65d3f6da0 865 break;
wvd_vegt 26:34c65d3f6da0 866
wvd_vegt 26:34c65d3f6da0 867 //Sends an ANSI escape code to clear the screen.
wvd_vegt 26:34c65d3f6da0 868 case CID_CLS:
wvd_vegt 26:34c65d3f6da0 869 print(cls);
wvd_vegt 26:34c65d3f6da0 870 break;
wvd_vegt 26:34c65d3f6da0 871
wvd_vegt 26:34c65d3f6da0 872 //Returns to CMD> prompt where most commands are disabled.
wvd_vegt 26:34c65d3f6da0 873 case CID_IDLE:
wvd_vegt 26:34c65d3f6da0 874 subsystem=-1;
wvd_vegt 26:34c65d3f6da0 875 break;
wvd_vegt 26:34c65d3f6da0 876
wvd_vegt 26:34c65d3f6da0 877 //Help
wvd_vegt 26:34c65d3f6da0 878 case CID_HELP: {
wvd_vegt 26:34c65d3f6da0 879 print("\r\n");
wvd_vegt 26:34c65d3f6da0 880
wvd_vegt 26:34c65d3f6da0 881 if (argfnd>0) {
wvd_vegt 26:34c65d3f6da0 882 cid = cmdid_search(STRINGPARM(0));
wvd_vegt 26:34c65d3f6da0 883 } else {
wvd_vegt 26:34c65d3f6da0 884 cid=CID_LAST;
wvd_vegt 26:34c65d3f6da0 885 }
wvd_vegt 26:34c65d3f6da0 886
wvd_vegt 26:34c65d3f6da0 887 if (argfnd>0 && cid!=CID_LAST) {
wvd_vegt 26:34c65d3f6da0 888
wvd_vegt 26:34c65d3f6da0 889 //Help with a valid command as first parameter
wvd_vegt 26:34c65d3f6da0 890 ndx = cmdid_index(cid);
wvd_vegt 26:34c65d3f6da0 891
wvd_vegt 26:34c65d3f6da0 892 switch (cmds[ndx].subs) {
wvd_vegt 26:34c65d3f6da0 893 case SUBSYSTEM: { //Dump whole subsystem
wvd_vegt 26:34c65d3f6da0 894 printf("%s subsystem commands:\r\n\r\n",cmds[ndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 895
wvd_vegt 26:34c65d3f6da0 896 //Count SubSystem Commands.
wvd_vegt 26:34c65d3f6da0 897 int subcmds =0;
wvd_vegt 26:34c65d3f6da0 898 for (int i=0; i<cmds.size(); i++) {
wvd_vegt 26:34c65d3f6da0 899 if (cmds[i].subs==cid) {
wvd_vegt 26:34c65d3f6da0 900 subcmds++;
wvd_vegt 26:34c65d3f6da0 901 }
wvd_vegt 26:34c65d3f6da0 902 }
wvd_vegt 26:34c65d3f6da0 903
wvd_vegt 26:34c65d3f6da0 904 //Print SubSystem Commands.
wvd_vegt 26:34c65d3f6da0 905 for (int i=0; i<cmds.size()-1; i++) {
wvd_vegt 26:34c65d3f6da0 906 if (cmds[i].subs==cid) {
wvd_vegt 26:34c65d3f6da0 907 subcmds--;
wvd_vegt 26:34c65d3f6da0 908 if (subcmds!=0) {
wvd_vegt 26:34c65d3f6da0 909 cmd_help("",i,",\r\n");
wvd_vegt 26:34c65d3f6da0 910 } else {
wvd_vegt 26:34c65d3f6da0 911 cmd_help("",i,".\r\n");
wvd_vegt 26:34c65d3f6da0 912 }
wvd_vegt 26:34c65d3f6da0 913 }
wvd_vegt 26:34c65d3f6da0 914 }
wvd_vegt 26:34c65d3f6da0 915 }
wvd_vegt 26:34c65d3f6da0 916 break;
wvd_vegt 26:34c65d3f6da0 917
wvd_vegt 26:34c65d3f6da0 918 case GLOBALCMD: //Dump command only
wvd_vegt 26:34c65d3f6da0 919 //print("Global command:\r\n\r\n",cmd_tbl[cmd_tbl[ndx].subs].cmdstr);
wvd_vegt 26:34c65d3f6da0 920 cmd_help("Syntax: ",ndx,".\r\n");
wvd_vegt 26:34c65d3f6da0 921
wvd_vegt 26:34c65d3f6da0 922 break;
wvd_vegt 26:34c65d3f6da0 923
wvd_vegt 26:34c65d3f6da0 924 default: { //Dump one subsystem command
wvd_vegt 26:34c65d3f6da0 925 int sndx = cmdid_index(cmds[ndx].subs);
wvd_vegt 26:34c65d3f6da0 926
wvd_vegt 26:34c65d3f6da0 927 printf("%s subsystem command:\r\n\r\n",cmds[sndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 928
wvd_vegt 26:34c65d3f6da0 929 cmd_help("Syntax: ",ndx,".\r\n");
wvd_vegt 26:34c65d3f6da0 930 }
wvd_vegt 26:34c65d3f6da0 931 break;
wvd_vegt 26:34c65d3f6da0 932 }
wvd_vegt 26:34c65d3f6da0 933 } else {
wvd_vegt 26:34c65d3f6da0 934 if (argfnd>0) {
wvd_vegt 26:34c65d3f6da0 935 //Help with invalid command as first parameter
wvd_vegt 26:34c65d3f6da0 936 print("Unknown command, type 'Help' for a list of available commands.\r\n");
wvd_vegt 26:34c65d3f6da0 937 } else {
wvd_vegt 26:34c65d3f6da0 938 //Help
wvd_vegt 26:34c65d3f6da0 939
wvd_vegt 26:34c65d3f6da0 940 //Dump Active Subsystem, Global & Other (dormant) Subsystems
wvd_vegt 26:34c65d3f6da0 941 //-1 because we want comma's and for the last a .
wvd_vegt 26:34c65d3f6da0 942 for (int i=0; i<cmds.size()-1; i++) {
wvd_vegt 26:34c65d3f6da0 943 if ((cmds[i].subs<0) || (cmds[i].subs==subsystem)) {
wvd_vegt 26:34c65d3f6da0 944 cmd_help("",i,",\r\n");
wvd_vegt 26:34c65d3f6da0 945 }
wvd_vegt 26:34c65d3f6da0 946 }
wvd_vegt 26:34c65d3f6da0 947 cmd_help("",cmds.size()-1,".\r\n");
wvd_vegt 26:34c65d3f6da0 948 }
wvd_vegt 26:34c65d3f6da0 949 }
wvd_vegt 26:34c65d3f6da0 950 print("\r\n");
wvd_vegt 26:34c65d3f6da0 951 break;
wvd_vegt 26:34c65d3f6da0 952 } //CID_HELP
wvd_vegt 26:34c65d3f6da0 953
wvd_vegt 26:34c65d3f6da0 954 default : {
wvd_vegt 26:34c65d3f6da0 955 // Do a Call to the Application's Command Dispatcher.
wvd_vegt 26:34c65d3f6da0 956 (*user_callback)(*this, cid);
wvd_vegt 26:34c65d3f6da0 957 }
wvd_vegt 26:34c65d3f6da0 958 }
wvd_vegt 26:34c65d3f6da0 959 } else {
wvd_vegt 26:34c65d3f6da0 960 cmd_help("Syntax: ",ndx,".\r\n");
wvd_vegt 26:34c65d3f6da0 961 }
wvd_vegt 26:34c65d3f6da0 962
wvd_vegt 26:34c65d3f6da0 963 }
wvd_vegt 26:34c65d3f6da0 964
wvd_vegt 26:34c65d3f6da0 965 } else {
wvd_vegt 26:34c65d3f6da0 966 //cid==-1
wvd_vegt 26:34c65d3f6da0 967 }
wvd_vegt 26:34c65d3f6da0 968 }
wvd_vegt 26:34c65d3f6da0 969
wvd_vegt 26:34c65d3f6da0 970 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 971 //----Dump commands table as a ini file.
wvd_vegt 26:34c65d3f6da0 972 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 973
wvd_vegt 26:34c65d3f6da0 974 void Cmdb::cmd_dump() {
wvd_vegt 26:34c65d3f6da0 975 int ndx;
wvd_vegt 26:34c65d3f6da0 976 int j;
wvd_vegt 26:34c65d3f6da0 977 int k;
wvd_vegt 26:34c65d3f6da0 978 int lastmod;
wvd_vegt 26:34c65d3f6da0 979
wvd_vegt 26:34c65d3f6da0 980 k = 0;
wvd_vegt 26:34c65d3f6da0 981 lastmod = 0;
wvd_vegt 26:34c65d3f6da0 982
wvd_vegt 26:34c65d3f6da0 983 for (ndx=0; ndx<cmds.size(); ndx++) {
wvd_vegt 26:34c65d3f6da0 984
wvd_vegt 26:34c65d3f6da0 985 #ifndef SHOWHIDDEN
wvd_vegt 26:34c65d3f6da0 986 if (cmds[ndx].subs==HIDDENSUB) {
wvd_vegt 26:34c65d3f6da0 987 continue;
wvd_vegt 26:34c65d3f6da0 988 }
wvd_vegt 26:34c65d3f6da0 989 #endif
wvd_vegt 26:34c65d3f6da0 990
wvd_vegt 26:34c65d3f6da0 991 switch (cmds[ndx].subs) {
wvd_vegt 26:34c65d3f6da0 992 case SUBSYSTEM :
wvd_vegt 26:34c65d3f6da0 993 printf("[command%2.2d]\r\n",ndx+1);
wvd_vegt 26:34c65d3f6da0 994 print("type=Subsystem\r\n");
wvd_vegt 26:34c65d3f6da0 995 print("subsystem=Global\r\n");
wvd_vegt 26:34c65d3f6da0 996 break;
wvd_vegt 26:34c65d3f6da0 997 case HIDDENSUB :
wvd_vegt 26:34c65d3f6da0 998 #ifdef SHOWHIDDEN
wvd_vegt 26:34c65d3f6da0 999 printf("[command%2.2d]\r\n",ndx+1);
wvd_vegt 26:34c65d3f6da0 1000 print("type=HiddenSubystem\r\n");
wvd_vegt 26:34c65d3f6da0 1001 print("subsystem=Global\r\n");
wvd_vegt 26:34c65d3f6da0 1002 #endif
wvd_vegt 26:34c65d3f6da0 1003 break;
wvd_vegt 26:34c65d3f6da0 1004 case GLOBALCMD :
wvd_vegt 26:34c65d3f6da0 1005 printf("[command%2.2d]\r\n",ndx+1);
wvd_vegt 26:34c65d3f6da0 1006 print("type=GlobalCommand\r\n");
wvd_vegt 26:34c65d3f6da0 1007 print("subsystem=Global\r\n");
wvd_vegt 26:34c65d3f6da0 1008 break;
wvd_vegt 26:34c65d3f6da0 1009 default :
wvd_vegt 26:34c65d3f6da0 1010 int sndx = cmdid_index(cmds[ndx].subs);
wvd_vegt 26:34c65d3f6da0 1011
wvd_vegt 26:34c65d3f6da0 1012 if (cmds[sndx].subs==HIDDENSUB) {
wvd_vegt 26:34c65d3f6da0 1013 #ifdef SHOWHIDDEN
wvd_vegt 26:34c65d3f6da0 1014 printf("[command%2.2d]\r\n",ndx+1);
wvd_vegt 26:34c65d3f6da0 1015 print("type=HiddenCommand\r\n");
wvd_vegt 26:34c65d3f6da0 1016 print("subsystem=HiddenSubystem\r\n");
wvd_vegt 26:34c65d3f6da0 1017 #endif
wvd_vegt 26:34c65d3f6da0 1018 continue;
wvd_vegt 26:34c65d3f6da0 1019 }
wvd_vegt 26:34c65d3f6da0 1020
wvd_vegt 26:34c65d3f6da0 1021 printf("[command%2.2d]\r\n",ndx+1);
wvd_vegt 26:34c65d3f6da0 1022 print("type=Command\r\n");
wvd_vegt 26:34c65d3f6da0 1023 printf("subsystem=%s\r\n",cmds[sndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 1024 }
wvd_vegt 26:34c65d3f6da0 1025
wvd_vegt 26:34c65d3f6da0 1026 if (cmds[ndx].subs==HIDDENSUB) {
wvd_vegt 26:34c65d3f6da0 1027 continue;
wvd_vegt 26:34c65d3f6da0 1028 }
wvd_vegt 26:34c65d3f6da0 1029
wvd_vegt 26:34c65d3f6da0 1030 printf("command=%s\r\n",cmds[ndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 1031 printf("helpmsg=%s\r\n",cmds[ndx].cmddescr);
wvd_vegt 26:34c65d3f6da0 1032 print("parameters=");
wvd_vegt 26:34c65d3f6da0 1033 for (j=0; j<strlen(cmds[ndx].parms); j++) {
wvd_vegt 26:34c65d3f6da0 1034 switch (cmds[ndx].parms[j]) {
wvd_vegt 26:34c65d3f6da0 1035 case '%' :
wvd_vegt 26:34c65d3f6da0 1036 lastmod=0;
wvd_vegt 26:34c65d3f6da0 1037 break;
wvd_vegt 26:34c65d3f6da0 1038
wvd_vegt 26:34c65d3f6da0 1039 case 'b' :
wvd_vegt 26:34c65d3f6da0 1040 lastmod=8;
wvd_vegt 26:34c65d3f6da0 1041 break;
wvd_vegt 26:34c65d3f6da0 1042 case 'h' :
wvd_vegt 26:34c65d3f6da0 1043 lastmod=16;
wvd_vegt 26:34c65d3f6da0 1044 break;
wvd_vegt 26:34c65d3f6da0 1045 case 'l' :
wvd_vegt 26:34c65d3f6da0 1046 lastmod=32;
wvd_vegt 26:34c65d3f6da0 1047 break;
wvd_vegt 26:34c65d3f6da0 1048
wvd_vegt 26:34c65d3f6da0 1049 case 'd' :
wvd_vegt 26:34c65d3f6da0 1050 case 'i' : {
wvd_vegt 26:34c65d3f6da0 1051 switch (lastmod) {
wvd_vegt 26:34c65d3f6da0 1052 case 0 :
wvd_vegt 26:34c65d3f6da0 1053 case 16 :
wvd_vegt 26:34c65d3f6da0 1054 print("int");
wvd_vegt 26:34c65d3f6da0 1055 k+=3;
wvd_vegt 26:34c65d3f6da0 1056 break;
wvd_vegt 26:34c65d3f6da0 1057 case 8 :
wvd_vegt 26:34c65d3f6da0 1058 print("shortint");
wvd_vegt 26:34c65d3f6da0 1059 k+=8;
wvd_vegt 26:34c65d3f6da0 1060 break;
wvd_vegt 26:34c65d3f6da0 1061 case 32:
wvd_vegt 26:34c65d3f6da0 1062 print("longint");
wvd_vegt 26:34c65d3f6da0 1063 k+=7;
wvd_vegt 26:34c65d3f6da0 1064 break;
wvd_vegt 26:34c65d3f6da0 1065 }
wvd_vegt 26:34c65d3f6da0 1066 break;
wvd_vegt 26:34c65d3f6da0 1067 }
wvd_vegt 26:34c65d3f6da0 1068
wvd_vegt 26:34c65d3f6da0 1069 case 'u' :
wvd_vegt 26:34c65d3f6da0 1070 case 'o' :
wvd_vegt 26:34c65d3f6da0 1071 case 'x' : {
wvd_vegt 26:34c65d3f6da0 1072 switch (lastmod) {
wvd_vegt 26:34c65d3f6da0 1073 case 0 :
wvd_vegt 26:34c65d3f6da0 1074 case 16 :
wvd_vegt 26:34c65d3f6da0 1075 print("word");
wvd_vegt 26:34c65d3f6da0 1076 k+=4;
wvd_vegt 26:34c65d3f6da0 1077 break;
wvd_vegt 26:34c65d3f6da0 1078 case 8 :
wvd_vegt 26:34c65d3f6da0 1079 print("byte");
wvd_vegt 26:34c65d3f6da0 1080 k+=4;
wvd_vegt 26:34c65d3f6da0 1081 break;
wvd_vegt 26:34c65d3f6da0 1082 case 32 :
wvd_vegt 26:34c65d3f6da0 1083 print("dword");
wvd_vegt 26:34c65d3f6da0 1084 k+=5;
wvd_vegt 26:34c65d3f6da0 1085 break;
wvd_vegt 26:34c65d3f6da0 1086 }
wvd_vegt 26:34c65d3f6da0 1087
wvd_vegt 26:34c65d3f6da0 1088 switch (cmds[ndx].parms[j]) {
wvd_vegt 26:34c65d3f6da0 1089 case 'o' :
wvd_vegt 26:34c65d3f6da0 1090 print("[o]");
wvd_vegt 26:34c65d3f6da0 1091 k+=3;
wvd_vegt 26:34c65d3f6da0 1092 break;
wvd_vegt 26:34c65d3f6da0 1093 case 'x' :
wvd_vegt 26:34c65d3f6da0 1094 print("[h]");
wvd_vegt 26:34c65d3f6da0 1095 k+=3;
wvd_vegt 26:34c65d3f6da0 1096 break;
wvd_vegt 26:34c65d3f6da0 1097 }
wvd_vegt 26:34c65d3f6da0 1098
wvd_vegt 26:34c65d3f6da0 1099 break;
wvd_vegt 26:34c65d3f6da0 1100 }
wvd_vegt 26:34c65d3f6da0 1101
wvd_vegt 26:34c65d3f6da0 1102 case 'e' :
wvd_vegt 26:34c65d3f6da0 1103 case 'f' :
wvd_vegt 26:34c65d3f6da0 1104 case 'g' :
wvd_vegt 26:34c65d3f6da0 1105 print("float");
wvd_vegt 26:34c65d3f6da0 1106 k+=5;
wvd_vegt 26:34c65d3f6da0 1107 break;
wvd_vegt 26:34c65d3f6da0 1108
wvd_vegt 26:34c65d3f6da0 1109 case 'c' :
wvd_vegt 26:34c65d3f6da0 1110 print("char");
wvd_vegt 26:34c65d3f6da0 1111 k+=4;
wvd_vegt 26:34c65d3f6da0 1112 break;
wvd_vegt 26:34c65d3f6da0 1113
wvd_vegt 26:34c65d3f6da0 1114 case 's' :
wvd_vegt 26:34c65d3f6da0 1115 print("string");
wvd_vegt 26:34c65d3f6da0 1116 k+=6;
wvd_vegt 26:34c65d3f6da0 1117 break;
wvd_vegt 26:34c65d3f6da0 1118
wvd_vegt 26:34c65d3f6da0 1119 case ' ' :
wvd_vegt 26:34c65d3f6da0 1120 printch(sp);
wvd_vegt 26:34c65d3f6da0 1121 k++;
wvd_vegt 26:34c65d3f6da0 1122 break;
wvd_vegt 26:34c65d3f6da0 1123 }
wvd_vegt 26:34c65d3f6da0 1124 }
wvd_vegt 26:34c65d3f6da0 1125 print("\r\n");
wvd_vegt 26:34c65d3f6da0 1126 printf("syntax=%s\r\n",cmds[ndx].parmdescr);
wvd_vegt 26:34c65d3f6da0 1127 }
wvd_vegt 26:34c65d3f6da0 1128 }
wvd_vegt 26:34c65d3f6da0 1129
wvd_vegt 26:34c65d3f6da0 1130 void Cmdb::prompt(void) {
wvd_vegt 26:34c65d3f6da0 1131 #ifdef SUBSYSTEMPROMPTS
wvd_vegt 26:34c65d3f6da0 1132 if (subsystem!=-1) {
wvd_vegt 26:34c65d3f6da0 1133 int ndx = cmdid_index(subsystem);
wvd_vegt 26:34c65d3f6da0 1134
wvd_vegt 26:34c65d3f6da0 1135 printf("%s>",cmds[ndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 1136
wvd_vegt 26:34c65d3f6da0 1137 return;
wvd_vegt 26:34c65d3f6da0 1138 }
wvd_vegt 26:34c65d3f6da0 1139 #endif //SUBSYSTEMPROMPTS
wvd_vegt 26:34c65d3f6da0 1140
wvd_vegt 26:34c65d3f6da0 1141 printf(PROMPT);
wvd_vegt 26:34c65d3f6da0 1142 }
wvd_vegt 26:34c65d3f6da0 1143
wvd_vegt 26:34c65d3f6da0 1144 void Cmdb::cmd_help(char *pre, int ndx, char *post) {
wvd_vegt 26:34c65d3f6da0 1145 int j;
wvd_vegt 26:34c65d3f6da0 1146 int k;
wvd_vegt 26:34c65d3f6da0 1147 int lastmod;
wvd_vegt 26:34c65d3f6da0 1148
wvd_vegt 26:34c65d3f6da0 1149 k=0;
wvd_vegt 26:34c65d3f6da0 1150 lastmod=0;
wvd_vegt 26:34c65d3f6da0 1151
wvd_vegt 26:34c65d3f6da0 1152 switch (cmds[ndx].subs) {
wvd_vegt 26:34c65d3f6da0 1153 case SUBSYSTEM :
wvd_vegt 26:34c65d3f6da0 1154 break;
wvd_vegt 26:34c65d3f6da0 1155 case GLOBALCMD :
wvd_vegt 26:34c65d3f6da0 1156 break;
wvd_vegt 26:34c65d3f6da0 1157 case HIDDENSUB :
wvd_vegt 26:34c65d3f6da0 1158 return;
wvd_vegt 26:34c65d3f6da0 1159 default :
wvd_vegt 26:34c65d3f6da0 1160 if (strlen(pre)==0 && bold) {
wvd_vegt 26:34c65d3f6da0 1161 print(boldon);
wvd_vegt 26:34c65d3f6da0 1162 }
wvd_vegt 26:34c65d3f6da0 1163 break;
wvd_vegt 26:34c65d3f6da0 1164 }
wvd_vegt 26:34c65d3f6da0 1165
wvd_vegt 26:34c65d3f6da0 1166 print(pre);
wvd_vegt 26:34c65d3f6da0 1167 k+=strlen(pre);
wvd_vegt 26:34c65d3f6da0 1168
wvd_vegt 26:34c65d3f6da0 1169 if (k==0) {
wvd_vegt 26:34c65d3f6da0 1170 printf("%12s",cmds[ndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 1171 k+=12;
wvd_vegt 26:34c65d3f6da0 1172 } else {
wvd_vegt 26:34c65d3f6da0 1173 if (strlen(pre)>0 && bold) {
wvd_vegt 26:34c65d3f6da0 1174 print(boldon);
wvd_vegt 26:34c65d3f6da0 1175 }
wvd_vegt 26:34c65d3f6da0 1176
wvd_vegt 26:34c65d3f6da0 1177 printf("%s",cmds[ndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 1178 k+=strlen(cmds[ndx].cmdstr);
wvd_vegt 26:34c65d3f6da0 1179
wvd_vegt 26:34c65d3f6da0 1180 if (strlen(pre)>0 && bold) {
wvd_vegt 26:34c65d3f6da0 1181 print(boldoff);
wvd_vegt 26:34c65d3f6da0 1182 }
wvd_vegt 26:34c65d3f6da0 1183 }
wvd_vegt 26:34c65d3f6da0 1184
wvd_vegt 26:34c65d3f6da0 1185 if (strlen(cmds[ndx].parms)) {
wvd_vegt 26:34c65d3f6da0 1186 printch(sp);
wvd_vegt 26:34c65d3f6da0 1187 k++;
wvd_vegt 26:34c65d3f6da0 1188 }
wvd_vegt 26:34c65d3f6da0 1189
wvd_vegt 26:34c65d3f6da0 1190 for (j=0; j<strlen(cmds[ndx].parms); j++) {
wvd_vegt 26:34c65d3f6da0 1191 switch (cmds[ndx].parms[j]) {
wvd_vegt 26:34c65d3f6da0 1192 case '%' :
wvd_vegt 26:34c65d3f6da0 1193 lastmod=0;
wvd_vegt 26:34c65d3f6da0 1194 break;
wvd_vegt 26:34c65d3f6da0 1195
wvd_vegt 26:34c65d3f6da0 1196 case 'b' :
wvd_vegt 26:34c65d3f6da0 1197 lastmod=8;
wvd_vegt 26:34c65d3f6da0 1198 break;
wvd_vegt 26:34c65d3f6da0 1199 case 'h' :
wvd_vegt 26:34c65d3f6da0 1200 lastmod=16;
wvd_vegt 26:34c65d3f6da0 1201 break;
wvd_vegt 26:34c65d3f6da0 1202 case 'l' :
wvd_vegt 26:34c65d3f6da0 1203 lastmod=32;
wvd_vegt 26:34c65d3f6da0 1204 break;
wvd_vegt 26:34c65d3f6da0 1205
wvd_vegt 26:34c65d3f6da0 1206 case 'd' :
wvd_vegt 26:34c65d3f6da0 1207 case 'i' : {
wvd_vegt 26:34c65d3f6da0 1208 switch (lastmod) {
wvd_vegt 26:34c65d3f6da0 1209 case 0 :
wvd_vegt 26:34c65d3f6da0 1210 case 16 :
wvd_vegt 26:34c65d3f6da0 1211 print("int");
wvd_vegt 26:34c65d3f6da0 1212 k+=3;
wvd_vegt 26:34c65d3f6da0 1213 break;
wvd_vegt 26:34c65d3f6da0 1214 case 8 :
wvd_vegt 26:34c65d3f6da0 1215 print("shortint");
wvd_vegt 26:34c65d3f6da0 1216 k+=8;
wvd_vegt 26:34c65d3f6da0 1217 break;
wvd_vegt 26:34c65d3f6da0 1218 case 32:
wvd_vegt 26:34c65d3f6da0 1219 print("longint");
wvd_vegt 26:34c65d3f6da0 1220 k+=7;
wvd_vegt 26:34c65d3f6da0 1221 break;
wvd_vegt 26:34c65d3f6da0 1222 }
wvd_vegt 26:34c65d3f6da0 1223 break;
wvd_vegt 26:34c65d3f6da0 1224 }
wvd_vegt 26:34c65d3f6da0 1225
wvd_vegt 26:34c65d3f6da0 1226 case 'u' :
wvd_vegt 26:34c65d3f6da0 1227 case 'o' :
wvd_vegt 26:34c65d3f6da0 1228 case 'x' : {
wvd_vegt 26:34c65d3f6da0 1229 switch (lastmod) {
wvd_vegt 26:34c65d3f6da0 1230 case 0 :
wvd_vegt 26:34c65d3f6da0 1231 case 16 :
wvd_vegt 26:34c65d3f6da0 1232 print("word");
wvd_vegt 26:34c65d3f6da0 1233 k+=4;
wvd_vegt 26:34c65d3f6da0 1234 break;
wvd_vegt 26:34c65d3f6da0 1235 case 8 :
wvd_vegt 26:34c65d3f6da0 1236 print("byte");
wvd_vegt 26:34c65d3f6da0 1237 k+=4;
wvd_vegt 26:34c65d3f6da0 1238 break;
wvd_vegt 26:34c65d3f6da0 1239 case 32 :
wvd_vegt 26:34c65d3f6da0 1240 print("dword");
wvd_vegt 26:34c65d3f6da0 1241 k+=5;
wvd_vegt 26:34c65d3f6da0 1242 break;
wvd_vegt 26:34c65d3f6da0 1243 }
wvd_vegt 26:34c65d3f6da0 1244
wvd_vegt 26:34c65d3f6da0 1245 switch (cmds[ndx].parms[j]) {
wvd_vegt 26:34c65d3f6da0 1246 case 'o' :
wvd_vegt 26:34c65d3f6da0 1247 print("[o]");
wvd_vegt 26:34c65d3f6da0 1248 k+=3;
wvd_vegt 26:34c65d3f6da0 1249 break;
wvd_vegt 26:34c65d3f6da0 1250 case 'x' :
wvd_vegt 26:34c65d3f6da0 1251 print("[h]");
wvd_vegt 26:34c65d3f6da0 1252 k+=3;
wvd_vegt 26:34c65d3f6da0 1253 break;
wvd_vegt 26:34c65d3f6da0 1254 }
wvd_vegt 26:34c65d3f6da0 1255
wvd_vegt 26:34c65d3f6da0 1256 break;
wvd_vegt 26:34c65d3f6da0 1257 }
wvd_vegt 26:34c65d3f6da0 1258
wvd_vegt 26:34c65d3f6da0 1259 case 'e' :
wvd_vegt 26:34c65d3f6da0 1260 case 'f' :
wvd_vegt 26:34c65d3f6da0 1261 case 'g' :
wvd_vegt 26:34c65d3f6da0 1262 print("float");
wvd_vegt 26:34c65d3f6da0 1263 k+=5;
wvd_vegt 26:34c65d3f6da0 1264 break;
wvd_vegt 26:34c65d3f6da0 1265
wvd_vegt 26:34c65d3f6da0 1266 case 'c' :
wvd_vegt 26:34c65d3f6da0 1267 print("char");
wvd_vegt 26:34c65d3f6da0 1268 k+=4;
wvd_vegt 26:34c65d3f6da0 1269 break;
wvd_vegt 26:34c65d3f6da0 1270
wvd_vegt 26:34c65d3f6da0 1271 case 's' :
wvd_vegt 26:34c65d3f6da0 1272 print("string");
wvd_vegt 26:34c65d3f6da0 1273 k+=6;
wvd_vegt 26:34c65d3f6da0 1274 break;
wvd_vegt 26:34c65d3f6da0 1275
wvd_vegt 26:34c65d3f6da0 1276 case ' ' :
wvd_vegt 26:34c65d3f6da0 1277 printch(sp);
wvd_vegt 26:34c65d3f6da0 1278 k++;
wvd_vegt 26:34c65d3f6da0 1279 break;
wvd_vegt 26:34c65d3f6da0 1280 }
wvd_vegt 26:34c65d3f6da0 1281 }
wvd_vegt 26:34c65d3f6da0 1282
wvd_vegt 26:34c65d3f6da0 1283 for (j=k; j<40; j++) printch(sp);
wvd_vegt 26:34c65d3f6da0 1284
wvd_vegt 26:34c65d3f6da0 1285 switch (cmds[ndx].subs) {
wvd_vegt 26:34c65d3f6da0 1286 case SUBSYSTEM :
wvd_vegt 26:34c65d3f6da0 1287 if (ndx==subsystem) {
wvd_vegt 26:34c65d3f6da0 1288 printf("- %s (active subsystem)%s",cmds[ndx].cmddescr,post);
wvd_vegt 26:34c65d3f6da0 1289 } else {
wvd_vegt 26:34c65d3f6da0 1290 printf("- %s (dormant subsystem)%s",cmds[ndx].cmddescr,post);
wvd_vegt 26:34c65d3f6da0 1291 }
wvd_vegt 26:34c65d3f6da0 1292 break;
wvd_vegt 26:34c65d3f6da0 1293 case HIDDENSUB :
wvd_vegt 26:34c65d3f6da0 1294 break;
wvd_vegt 26:34c65d3f6da0 1295 case GLOBALCMD :
wvd_vegt 26:34c65d3f6da0 1296 printf("- %s (global command)%s",cmds[ndx].cmddescr,post);
wvd_vegt 26:34c65d3f6da0 1297 break;
wvd_vegt 26:34c65d3f6da0 1298 default :
wvd_vegt 26:34c65d3f6da0 1299 printf("- %s%s",cmds[ndx].cmddescr,post);
wvd_vegt 26:34c65d3f6da0 1300 if (strlen(pre)==0 && bold) {
wvd_vegt 26:34c65d3f6da0 1301 print(boldoff);
wvd_vegt 26:34c65d3f6da0 1302 }
wvd_vegt 26:34c65d3f6da0 1303 break;
wvd_vegt 26:34c65d3f6da0 1304 }
wvd_vegt 26:34c65d3f6da0 1305
wvd_vegt 26:34c65d3f6da0 1306 if (strlen(pre)>0 && strlen(cmds[ndx].parmdescr)) {
wvd_vegt 26:34c65d3f6da0 1307 printf("Params: %s",cmds[ndx].parmdescr);
wvd_vegt 26:34c65d3f6da0 1308 print("\r\n");
wvd_vegt 26:34c65d3f6da0 1309 }
wvd_vegt 26:34c65d3f6da0 1310 }
wvd_vegt 26:34c65d3f6da0 1311
wvd_vegt 26:34c65d3f6da0 1312 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 1313 //----Wrappers
wvd_vegt 26:34c65d3f6da0 1314 //------------------------------------------------------------------------------
wvd_vegt 26:34c65d3f6da0 1315
wvd_vegt 26:34c65d3f6da0 1316 void Cmdb::zeromemory(char *p,unsigned int siz) {
wvd_vegt 26:34c65d3f6da0 1317 memset(p,'\0',siz);
wvd_vegt 26:34c65d3f6da0 1318 }
wvd_vegt 26:34c65d3f6da0 1319
wvd_vegt 26:34c65d3f6da0 1320 int Cmdb::stricmp (char *s1, char *s2) {
wvd_vegt 26:34c65d3f6da0 1321 int i;
wvd_vegt 26:34c65d3f6da0 1322 int len1,len2;
wvd_vegt 26:34c65d3f6da0 1323
wvd_vegt 26:34c65d3f6da0 1324 len1=strlen(s1);
wvd_vegt 26:34c65d3f6da0 1325 len2=strlen(s2);
wvd_vegt 26:34c65d3f6da0 1326
wvd_vegt 26:34c65d3f6da0 1327 for (i = 0; (i<len1) && (i<len2); i++) {
wvd_vegt 26:34c65d3f6da0 1328 if ( toupper (s1[i])<toupper(s2[i]) ) return (-1);
wvd_vegt 26:34c65d3f6da0 1329 if ( toupper (s1[i])>toupper(s2[i]) ) return (+1);
wvd_vegt 26:34c65d3f6da0 1330 }
wvd_vegt 26:34c65d3f6da0 1331
wvd_vegt 26:34c65d3f6da0 1332 if (len1<len2) return (-1);
wvd_vegt 26:34c65d3f6da0 1333 if (len1>len2) return (+1);
wvd_vegt 26:34c65d3f6da0 1334
wvd_vegt 26:34c65d3f6da0 1335 return (0);
wvd_vegt 26:34c65d3f6da0 1336 }
wvd_vegt 26:34c65d3f6da0 1337
wvd_vegt 26:34c65d3f6da0 1338 //------------------------------------------------------------------------------