#include #include #include #include #include #include "smsh.h" #include "varlib.h" /** ** small-shell version 4 ** first really useful version after prompting shell ** this one parses the command line into strings ** uses fork, exec, wait, and ignores signals **/ #define DFL_PROMPT "> " int main() { char *cmdline, *prompt, **arglist; int result, process(char **); void setup(); prompt = DFL_PROMPT ; setup(); while ( (cmdline = next_cmd(prompt, stdin)) != NULL ){ if ( (arglist = splitline(cmdline)) != NULL ){ result = process(arglist); freelist(arglist); } free(cmdline); } return 0; } void setup() /* * purpose: initialize shell * returns: nothing. calls fatal() if trouble */ { extern char **environ; VLenviron2table(environ); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); } void fatal(char *s1, char *s2, int n) { fprintf(stderr,"Error: %s,%s\n", s1, s2); exit(n); }