Changeset 333 in Sophya for trunk/SophyaPI/PIext/piacmd.cc
- Timestamp:
- Jul 12, 1999, 1:12:29 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/piacmd.cc
r330 r333 141 141 usage += " set unset listvar listcommands exec shell \n"; 142 142 usage += " > set varname 'string' # To set a variable, $varname \n"; 143 usage += " > setol varname patt # Fills varname with object list \n"; 143 144 usage += " > unset varname # clear variable definition \n"; 145 usage += " > echo string # output string \n"; 144 146 usage += " > listvars # List of variable names and values \n"; 145 147 usage += " > listcommands # List of all known commands \n"; … … 282 284 int PIACmd::Interpret(string& s) 283 285 { 284 286 int rc = 0; 285 287 cmdtok tokens; 286 288 if (s.length() < 1) return(0); … … 334 336 else if (kw == "set") { 335 337 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); } 336 mVars[tokens[0]] = tokens[1]; 338 string xx = ""; 339 for (int kk=0; kk<tokens.size(); kk++) xx += (tokens[kk] + ' '); 340 mVars[tokens[0]] = xx; 341 } 342 else if (kw == "setol") { 343 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: setol varname objnamepattern" << endl; return(0); } 344 vector<string> ol; 345 mObjMgr->GetObjList(tokens[1], ol); 346 string vol = ""; 347 for (int kk=0; kk<ol.size(); kk++) vol += (ol[kk] + ' '); 348 mVars[tokens[0]] = vol; 337 349 } 338 350 else if (kw == "unset") { … … 341 353 if (it != mVars.end()) mVars.erase(it); 342 354 else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl; 355 } 356 else if (kw == "echo") { 357 for (int kk=0; kk<tokens.size(); kk++) cout << tokens[kk] << " " ; 358 cout << endl; 343 359 } 344 360 else if (kw == "listvars") { … … 379 395 } 380 396 // Execution d'une commande enregistree 381 else { 382 CmdExmap::iterator it = cmdexmap.find(kw); 383 if (it == cmdexmap.end()) cout << "No such command : " << kw << " ! " << endl; 397 else rc = ExecuteCommand(kw, tokens); 398 399 if (timing) gltimer->Split(); 400 return(rc); 401 } 402 403 /* --Methode-- */ 404 int PIACmd::ExecuteCommandLine(string& line) 405 { 406 cmdtok tokens; 407 if (line.length() < 1) return(0); 408 409 string toks,kw; 410 size_t p = line.find_first_not_of(" "); 411 line = line.substr(p); 412 p = 0; 413 size_t q = line.find_first_of(" "); 414 size_t l = line.length(); 415 416 if (q < l) 417 { kw = line.substr(p,q-p); toks = line.substr(q, l-q); } 418 else { kw = line.substr(p,l-p); toks = ""; } 419 420 q = 0; 421 while (q < l) { 422 p = toks.find_first_not_of(" ",q+1); // au debut d'un token 423 if (p>=l) break; 424 q = toks.find_first_of(" ",p); // la fin du token; 425 string token = toks.substr(p,q-p); 426 tokens.push_back(token); 427 } 428 429 return(ExecuteCommand(kw, tokens)); 430 } 431 432 /* --Methode-- */ 433 int PIACmd::ExecuteCommand(string& keyw, vector<string>& args) 434 { 435 int rc = -1; 436 CmdExmap::iterator it = cmdexmap.find(keyw); 437 if (it == cmdexmap.end()) cout << "No such command : " << keyw << " ! " << endl; 384 438 else { 385 if ((*it).second.cex) (*it).second.cex->Execute(kw, tokens);386 else cout << "Dont know how to execute " << k w << " ? " << endl;439 if ((*it).second.cex) rc = (*it).second.cex->Execute(keyw, args); 440 else cout << "Dont know how to execute " << keyw << " ? " << endl; 387 441 } 388 } 389 390 if (timing) gltimer->Split(); 391 return(0); 392 } 393 442 return(rc); 443 } 394 444 395 445 /* --Methode-- */
Note:
See TracChangeset
for help on using the changeset viewer.