int main(int argc, char** argv) { const char* command = "list"; bool verbose = false; int c; while ((c = getopt_long(argc, argv, "+hv", kLongOptions, NULL)) != -1) { switch (c) { case 0: break; case 'h': usage(0); break; case 'v': verbose = true; break; default: usage(1); break; } } if (argc - optind >= 1) command = argv[optind]; if (strcmp(command, "list") == 0) { list_jobs(verbose); } else if (strcmp(command, "list-targets") == 0) { list_targets(verbose); } else if (strcmp(command, "log") == 0) { get_log(argc - optind, &argv[optind]); } else if (argc == optind + 1) { // For convenience (the "info" command can be omitted) get_info(command); } else { // All commands that need a name following const char* name = argv[argc - 1]; if (strcmp(command, "info") == 0) { get_info(name); } else if (strcmp(command, "start") == 0) { start_job(name); } else if (strcmp(command, "stop") == 0) { stop_job(name); } else if (strcmp(command, "restart") == 0) { restart_job(name); } else if (strcmp(command, "enable") == 0) { enable_job(name, true); } else if (strcmp(command, "disable") == 0) { enable_job(name, false); } else { fprintf(stderr, "%s: Unknown command \"%s\".\n", kProgramName, command); } } return 0; }
int main() { init_shell(); job_array = (pid_t *) malloc(20*sizeof(pid_t)); while(1) { if(!readcmdline(promptmsg())) { if (feof(stdin)) { /* End of file (ctrl-d) */ fflush(stdout); printf("\n"); exit(EXIT_SUCCESS); } continue; /* NOOP; user entered return or spaces with return */ } /* Only for debugging purposes and to show parser output */ //print_job(); job_t * next_job = first_job; while(next_job){ if(next_job->pgid ==-1){ int lowest = find_lowest_index(); //printf("%s %d\n","Lowest index: ", lowest); if(lowest != -1){ bool bg = next_job->bg; process_t * p = next_job->first_process; char* cmd = p->argv[0]; if(strcmp (cmd,"cd") == 0){ //printf("%s\n", "found cd"); } else if (strcmp (cmd, "jobs") == 0) { list_jobs(next_job, 0); job_t *tmp = next_job; if (next_job->next) next_job=next_job->next; remove_and_free(tmp); //why are we remove and freeing a built in command } else if (strcmp(cmd, "fg") == 0) { } else if (strcmp(cmd, "bg") == 0) { } else { /*If not built-in*/ spawn_job(next_job, !bg); next_job = next_job->next; } break; } } else next_job = next_job->next; } /* You need to loop through jobs list since a command line can contain ;*/ /* Check for built-in commands */ /* If not built-in */ /* If job j runs in foreground */ /* spawn_job(j,true) */ /* else */ /* spawn_job(j,false) */ } }