int cmd_quit(tok_t arg[]) { printf("Bye\n"); free(s); freeToks(PATH); exit(0); return 1; }
int shell (int argc, char *argv[]) { char *s=NULL; //= malloc(INPUT_STRING_SIZE+1); /* user input string */ tok_t *t; /* tokens parsed from input */ int lineNum = 0; int fundex = -1; pid_t pid = getpid(); /* get current processes PID */ pid_t ppid = getppid(); /* get parents PID */ pid_t cpid, tcpid, cpgid; init_shell(); printf("%s running as PID %d under %d\n",argv[0],pid,ppid); lineNum=0; set_dir(); fprintf(stdout, "%d:%s $ ", lineNum,cdir); while ((s = freadln(stdin))) { t = getToks(s); /* break the line into tokens */ //printf("args s: %s\n",s); fundex = lookup(t[0]); /* Is first token a shell literal */ if(fundex >= 0) cmd_table[fundex].fun(&t[1]); else { if(t[0]) { terminal_cmd(t); } //fprintf(stdout, "This shell only supports built-ins. Replace this to run programs as commands.\n"); } free(s); freeToks(t); fprintf(stdout, "%d:%s $ ", lineNum,cdir); } return 0; }
int shell(int argc, char *argv[]) { tok_t tok_special_indexes[MAXTOKS]; fprintf(stdout, "Welcome to Shelley v1.0\n...\n"); tok_t *t; /* tokens parsed from input */ int fundex = -1, tok_num = 0, bg = 0; pid_t pid = getpid(), /* get current processes PID */ ppid = getppid(), /* get parents PID */ cpid, tcpid, cpgid; init_shell(); PATH = getToks(getenv("PATH"), &tok_num, tok_special_indexes, &bg); do { t = getToks(s, &tok_num, tok_special_indexes, &bg); /* break the line into tokens */ if (t != NULL) { fundex = lookup(t[0]); /* Is first token a shell literal */ if (fundex >= 0) cmd_table[fundex].fun(&t[1]); else { create_process(t, tok_num, tok_special_indexes, bg); freeToks(t); } } prompter(); } while ((s = freadln(stdin))); return cmd_table[lookup("quit")].fun(&t[1]); }