Changeset 5105 in orxonox.OLD for trunk/src/util
- Timestamp:
- Aug 22, 2005, 7:29:27 PM (19 years ago)
- Location:
- trunk/src/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/shell.cc
r5104 r5105 457 457 strcpy(completionLine, this->inputLine); 458 458 459 459 char* commandBegin = strrchr(completionLine, ' '); 460 460 if (commandBegin == NULL) 461 461 commandBegin = completionLine; … … 468 468 } 469 469 470 this->classComplete(commandBegin); 470 char* objectStart; 471 if (objectStart = strstr(commandBegin, "::")) 472 { 473 char* classIdentity = new char[objectStart - commandBegin +1]; 474 strncpy(classIdentity, commandBegin, objectStart - commandBegin); 475 classIdentity[objectStart - commandBegin] = '\0'; 476 this->objectComplete(objectStart+2, ClassList::StringToID(classIdentity)); 477 delete[] classIdentity; 478 } 479 else 480 this->classComplete(commandBegin); 471 481 472 482 delete[] completionLine; … … 482 492 if (unlikely(classBegin == NULL)) 483 493 return false; 484 const tList<const char>* classList = this->createCompleteList(ClassList::getClassList(), classBegin); 485 if (classList->getSize() == 0) 486 { 487 //PRINTF(0)("no completion found for %s\n", commandBegin); 494 const tList<const char>* clList = ClassList::getClassList(); 495 if (clList != NULL) 496 { 497 const tList<const char>* classList = this->createCompleteList(clList, classBegin); 498 if (classList != NULL) 499 this->generalComplete(classList, classBegin, "%s::", "::"); 500 else 501 return false; 502 } 503 else 488 504 return false; 489 } 490 491 const char* addString = classList->firstElement(); 505 return true; 506 } 507 508 /** 509 * autocompletes an ObjectName 510 * @param objectBegin the beginning string of a Object 511 * @param classID the ID of the Class to search for. 512 * @return true on success, false otherwise 513 */ 514 bool Shell::objectComplete(const char* objectBegin, long classID) 515 { 516 printf("%s\n", objectBegin); 517 518 if (unlikely(objectBegin == NULL)) 519 return false; 520 tList<BaseObject>* boList = ClassList::getList(classID); 521 if (boList != NULL) 522 { 523 printf("\n", boList->firstElement()->getName()); 524 const tList<const char>* objectList = this->createCompleteList(boList, objectBegin); 525 if (objectList != NULL) 526 this->generalComplete(objectList, objectBegin, "%s"); 527 else 528 return false; 529 } 530 else 531 return false; 532 return true; 533 } 534 535 bool Shell::functionComplete(const char* functionBegin) 536 { 537 } 538 539 /** 540 * completes the inputline on grounds of an inputList 541 * @param stringList the List to parse through 542 * @param begin the String to search in the inputList, and to extend with it. 543 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::" 544 * @param addBack what should be added at the end of the completion 545 * @param addFront what should be added to the front of one finished completion 546 * @return true if ok, false otherwise 547 */ 548 bool Shell::generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront) 549 { 550 if (stringList->getSize() == 0) 551 return false; 552 553 const char* addString = stringList->firstElement(); 492 554 unsigned int addLength = 0; 493 unsigned int inputLenght = strlen( classBegin);555 unsigned int inputLenght = strlen(begin); 494 556 495 557 if (addString != NULL) 496 558 addLength = strlen(addString); 497 tIterator<const char>* charIterator = classList->getIterator();559 tIterator<const char>* charIterator = stringList->getIterator(); 498 560 const char* charElem = charIterator->nextElement(); 499 561 while (charElem != NULL) 500 562 { 501 PRINTF(0)("%s:: ", charElem); 502 { 503 for (unsigned int i = inputLenght; i < addLength; i++) 504 if (addString[i] != charElem[i]) 505 { 506 addLength = i; 507 break; 508 } 509 } 510 563 PRINTF(0)(displayAs, charElem); 564 for (unsigned int i = inputLenght; i < addLength; i++) 565 if (addString[i] != charElem[i]) 566 { 567 addLength = i; 568 break; 569 } 511 570 charElem = charIterator->nextElement(); 512 571 } … … 520 579 this->removeCharacters(inputLenght); 521 580 this->addCharacters(adder); 522 // this->addCharacters("::"); 581 if (addBack != NULL && stringList->getSize() == 1) 582 this->addCharacters("::"); 523 583 delete[] adder; 524 584 } 525 } 526 527 bool Shell::objectComplete(const char* objectBegin, ClassID classID) 528 { 529 530 } 531 532 bool Shell::functionComplete(const char* functionBegin) 533 { 534 } 585 return true; 586 } 587 535 588 536 589 537 590 /** 538 591 * searches for classes, which beginn with classNameBegin 539 * @param classNameBegin the beginning string of a Class 592 * @param inputList the List to parse through 593 * @param classNameBegin the beginning string 540 594 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards, 541 595 * !! The strings MUST NOT be deleted !! … … 543 597 const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin) 544 598 { 599 if (inputList == NULL || classNameBegin == NULL) 600 return NULL; 545 601 unsigned int searchLength = strlen(classNameBegin); 546 602 if (this->completionList != NULL) … … 566 622 } 567 623 624 /** 625 * searches for classes, which beginn with classNameBegin 626 * @param inputList the List to parse through 627 * @param classNameBegin the beginning string 628 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards, 629 * !! The strings MUST NOT be deleted !! 630 */ 631 const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin) 632 { 633 if (inputList == NULL || classNameBegin == NULL) 634 return NULL; 635 unsigned int searchLength = strlen(classNameBegin); 636 if (this->completionList != NULL) 637 delete this->completionList; 638 this->completionList = new tList<const char>; 639 640 tIterator<BaseObject>* iterator = inputList->getIterator(); 641 BaseObject* enumBO = iterator->nextElement(); 642 while (enumBO != NULL) 643 { 644 if (enumBO->getName() != NULL && 645 strlen(enumBO->getName())>searchLength+1 && 646 !strncasecmp(enumBO->getName(), classNameBegin, searchLength)) 647 { 648 this->completionList->add(enumBO->getName()); 649 } 650 enumBO = iterator->nextElement(); 651 } 652 delete iterator; 653 654 return this->completionList; 655 } 656 568 657 569 658 -
trunk/src/util/shell.h
r5104 r5105 68 68 bool autoComplete(); 69 69 bool classComplete(const char* classBegin); 70 bool objectComplete(const char* objectBegin, ClassIDclassID);70 bool objectComplete(const char* objectBegin, long classID); 71 71 bool functionComplete(const char* functionBegin); 72 72 73 bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); 73 74 74 75 const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin); 76 const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin); 75 77 76 78
Note: See TracChangeset
for help on using the changeset viewer.