Fix compile error of CMDB which occurred by mbed-src modification.

Dependents:   mbed_controller_demo

Fork of CMDB by Wim van der Vegt

Committer:
hillkim7
Date:
Thu Mar 12 12:05:53 2015 +0000
Revision:
27:ed36b4c73d4c
Parent:
26:34c65d3f6da0
Fix compile error.; Error: "mbed::Stream::Stream(const mbed::Stream &)"

Who changed what in which revision?

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