Commit 209d7562 authored by Matthew Burket's avatar Matthew Burket

Got History working

parent fbe3eac4
......@@ -66,14 +66,14 @@ int main() {
if (strcmp(tokens[0], "history") == 0) {
if (historyPos == -1) {
fprintf(stderr, "\nNo commands in history\n");
storeHist(readBuff, &historyPos, historyBuff, 0);
storeHist(tokens, &historyPos, historyBuff, numTokens);
free(tokens);
continue;
}
for (int i = historyPos; i >= 0; i--) {
fprintf(stdout, "%2d %s\n", i + 1, historyBuff[i]);
}
storeHist(readBuff, &historyPos, historyBuff, 0);
storeHist(tokens, &historyPos, historyBuff, numTokens);
free(tokens);
continue;
}
......@@ -82,7 +82,7 @@ int main() {
if (strcmp(tokens[0], "!!") == 0) {
if (historyPos == -1) {
fprintf(stderr, "\nbsh: No such command in history.\n");
storeHist(readBuff, &historyPos, historyBuff, 0);
storeHist(tokens, &historyPos, historyBuff, numTokens);
free(tokens);
continue;
} else {
......@@ -101,14 +101,13 @@ int main() {
free(tokens);
continue;
}
if (cmdNum <= 0 || cmdNum > historyPos) {
if (cmdNum <= 0 || cmdNum-1 > historyPos) {
printf("\nInvalid history command lookup!\n");
free(tokens);
continue;
} else {
numTokens = tokenize(historyBuff[cmdNum - 1], tokens);
}
free(ptr);
}
......@@ -140,7 +139,7 @@ void storeHist(char **readBuff, int *historyPos, char historyBuff[50][5000], int
*historyPos = *historyPos + 1;
for (int i = 0; i < numTokens - 1; i++) {
strcat(historyBuff[*historyPos], readBuff[i]);
int nextIter = i+1;
int nextIter = i + 1;
if (nextIter < numTokens - 1) {
strcat(historyBuff[*historyPos], " ");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment