QWidget* createEnvs(QWidget* parent) { parent->setObjectName("envs1"); QGridLayout* grid = new QGridLayout(parent); grid->addWidget(createEnv(new QGroupBox(), 0), 0, 0); grid->addWidget(createEnv(new QGroupBox(), 1), 0, 1); grid->addWidget(createEnv(new QGroupBox(), 2), 0, 2); grid->addWidget(createEnv(new QGroupBox(), 3), 0, 3); grid->setRowStretch(1, 1); grid->setHorizontalSpacing(5); return parent; }
//this function handles simple commands of cd, dirs, wait and the built ins //parameters are the command list and the boolean of if the command is //backgrounded //returns int simple(CMD *cmdList, bool bkgd){ pid_t pid, wpid; int status; //if the command is cd to move directories if(strcmp(cmdList->argv[0], "cd") == 0){ int ret = 0; if(cmdList->argc == 2) { ret = chdir(cmdList->argv[1]); } else if(cmdList->argc == 1){ ret = chdir(getenv("HOME")); } else { //incorrect number of arguments perror("usage"); } if (ret != 0) { //problem with chdir perror("chdir error"); } //is if command is dirs command to print path to directory } else if(strcmp(cmdList->argv[0], "dirs") == 0) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) != NULL && cmdList->argc == 1){ printf( "%s\n", cwd); } else { //incorrect number of arguments perror("usage"); } //if command is to wait which means wait for previous processes to //terminate }else if(strcmp(cmdList->argv[0], "wait") == 0){ if(cmdList->argc != 1) perror("usage"); int status; pid_t waiting; //reap the zombies while ((waiting = wait (&status)) > 0 ) fprintf(stderr, "Completed: %d (%d)\n",waiting, status); }else { pid = fork(); if (pid == 0) { //Child Process //start at the bottom of the function table createEnv(cmdList); //set file descriptors if necessary int saved_stdout = NULL; int saved_stdin = NULL; int dupsval = dups(cmdList, &saved_stdout, &saved_stdin); if(dupsval != -1) exit(EXIT_FAILURE); //check return of exec if (execvp(cmdList->argv[0], cmdList->argv) == -1) { perror("execvp"); } //reset file descriptors resetDups(cmdList, &saved_stdout, &saved_stdin); exit(EXIT_FAILURE); } else if (pid < 0) { // Error forking perror("fork"); } else if(!bkgd){ // Parent process that is only done if not backgrounded do { //pointer to wait wpid = waitpid(pid, &status, WUNTRACED); // fprintf(stderr, "status %d wpid %d \n", status, wpid); } while (!WIFEXITED(status) && !WIFSIGNALED(status)); int wistat = setStatus(status); return wistat; } else if(bkgd) fprintf(stderr, "Backgrounded: %d\n", pid); } return 0; }