Changeset 5200 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Sep 18, 2005, 3:49:21 AM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.cc
r5199 r5200 378 378 * @return true on success, false otherwise. 379 379 */ 380 #include "stdlibincl.h" 380 381 bool ShellCommandBase::execute(const char* executionString) 381 382 { … … 395 396 if (inputSplits.getCount() == 0) 396 397 return false; 397 // CHECK FOR ALIAS398 398 if (inputSplits.getCount() >= 1) 399 399 { 400 // CHECK FOR ALIAS 400 401 if (ShellCommandClass::aliasList != NULL) 401 402 { … … 410 411 if (objectList != NULL) 411 412 { 412 elemAL->getCommand()->executeCommand(objectList->firstElement(), ""); 413 elemAL->getCommand()->executeCommand(objectList->firstElement(), executionString+inputSplits.getOffset(1)); 414 delete itAL; 413 415 return true; 414 416 } … … 418 420 delete itAL; 419 421 } 422 420 423 } 421 424 -
trunk/src/lib/util/substring.cc
r5184 r5200 34 34 { 35 35 this->strings = NULL; 36 this->offsets = NULL; 36 37 return; 37 38 } … … 44 45 45 46 this->strings = new char*[this->splittersCount]; 46 assert (strings != NULL); 47 this->offsets = new unsigned int[this->splittersCount]; 48 assert (this->strings != NULL && this->offsets != NULL); 47 49 48 50 int i = 0; … … 61 63 strncpy( strings[i], offset, l); 62 64 strings[i][l] = '\0'; 65 this->offsets[i] = offset - string; 63 66 i++; 64 67 end++; … … 71 74 strncpy( strings[i], offset, l); 72 75 strings[i][l] = '\0'; 76 this->offsets[i] = offset - string; 73 77 } 74 78 else … … 76 80 this->strings[0] = new char[strlen(string)+1]; 77 81 strcpy(this->strings[0], string); 82 this->offsets[0] = 0; 78 83 } 79 84 } … … 92 97 { 93 98 this->strings = NULL; 99 this->offsets = NULL; 94 100 return; 95 101 } … … 114 120 // allocate memory 115 121 this->strings = new char*[this->splittersCount]; 116 assert (strings != NULL); 122 this->offsets = new unsigned int[this->splittersCount]; 123 assert (this->strings != NULL && this->offsets != NULL); 117 124 118 125 // split the String into substrings … … 131 138 strncpy( strings[i], offset, l); 132 139 strings[i][l] = '\0'; 140 this->offsets[i] = offset - string; 133 141 end += strspn(end, " \t\n"); 134 142 offset = end; … … 142 150 strncpy(this->strings[0], string, length); 143 151 this->strings[0][length] = '\0'; 152 offsets[0] = 0; 144 153 } 145 154 } … … 156 165 delete[] this->strings; 157 166 } 167 delete[] this->offsets; 158 168 } 159 169 … … 169 179 else 170 180 return NULL; 181 } 182 183 /** 184 * get a particular substring's offset 185 * @param i the ID of the substring to get the offset from 186 * @returns the offset or NULL if an invalid ID was given 187 */ 188 unsigned int SubString::getOffset(unsigned int i) 189 { 190 if( i < this->splittersCount && i >= 0) 191 return this->offsets[i]; 192 else 193 return 0; 171 194 } 172 195 -
trunk/src/lib/util/substring.h
r5183 r5200 17 17 inline unsigned int getCount() { return this->splittersCount; }; 18 18 const char* getString(unsigned int i); 19 unsigned int getOffset(unsigned int i); 19 20 20 21 void debug() const; … … 22 23 private: 23 24 char** strings; //!< strings produced from a single string splitted in multiple strings 25 unsigned int* offsets; //!< offsets of the beginning of the input-string to the beginning of each substring. 24 26 unsigned int splittersCount; //!< how many splitted parts 25 27 };
Note: See TracChangeset
for help on using the changeset viewer.