Reputation: 1
I am completely new to programming in C, taking a C/UNIX course currently. I am having a bit of an issue starting this assignment...it is the first C program we've been assigned, but the professor has been extremely scant in explaining what is needed to accomplish it or where to begin, and asking him hasn't accomplished much. Being that I've done very little C, I'm not sure where to begin with this.
The program is a simple shell that I am supposed to implement some history features into. The source code for the shell has been given. Supposed to add these abilities:
history - type history at command line, most recent shell commands displayed with number in front (starting at 1). Commands are to be stored in a text file. I am assuming the history command will just print this text file each time.
!number - type this at command line, the command in the file with that number will be re-executed
!string - type this at command line, re-execute the last command that begins with that string
!! - type at command line, re-execute the previous command
Source code (this is one of three files for the shell, but I believe the one that is supposed to be edited):
#include "parser.h"
#include "shell.h"
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char input[MAXINPUTLINE];
signal_c_init();
printf("Welcome to the sample shell! You may enter commands here, one\n");
printf("per line. When you're finished, press Ctrl+D on a line by\n");
printf("itself. I understand basic commands and arguments separated by\n");
printf("spaces, redirection with < and >, up to two commands joined\n");
printf("by a pipe, tilde expansion, and background commands with &.\n\n");
while (fgets(input, sizeof(input), stdin)) {
stripcrlf(input);
parse(input);
printf("\n$ ");
}
return 0;
}
Let me just state for the record that I'm not asking anyone to do my homework here. I just literally do not know where to begin with this and no indications have been given. Without much experience in this language prior to the class, I don't have comparable knowledge of how this type of thing is achieved. Any kind of resource or functions that I could begin with would be helpful.
Upvotes: 0
Views: 1424
Reputation: 11791
To handle history (and command line editing, and...) check out the readline or editline libraries.
Upvotes: 1