This method takes a vector (inputVector, member variable) and splits it into char*[]'s. Whenever you come across a ";" in the vector, print out the last set of char*s stored in args. Even though the vector size is 14, the loop exits on the 5th loop.
Vector data (newline separates items):
/bin/echo
killroy
was
here;
;
xyzzy
;
nonexistent-program
;
/bin/true
;
/bin/false
;
void TrivialShell::splitArguments() {
char* args[MAX_ARGS];
int inputVectorIdx = 0;
int currentArgsIdx = 0;
int startingArgsIdx = 0;
while (inputVectorIdx < inputVector.size()) {
if (inputVector[inputVectorIdx] == ";") {
for (int k = startingArgsIdx; k <= currentArgsIdx; k++) {
cout << args[k];
}
startingArgsIdx = currentArgsIdx + 1;
}
else {
args[currentArgsIdx] =
const_cast<char*>(inputVector[inputVectorIdx].c_str());
}
inputVectorIdx++;
currentArgsIdx++;
}
}