void Rendering() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glPolygonMode(GL_BACK,GL_FILL); glLoadIdentity(); runPipeline(); testmodel1->draw(); testmodel2->draw(); testmodel3->draw(); testmodel4->draw(); testmodel5->draw(); testmodel6->draw(); testmodel7->draw(); testmodel8->draw(); sphere->draw(); suzanne->draw(); floor_obj->draw(); glfwSwapBuffers(window); glfwPollEvents(); Mortimer(); }
bool compileMethod(CompilationContext* cc) { if(Jitrino::flags.skip) { return false; } runPipeline(cc); bool success = !cc->isCompilationFailed(); return success; }
void runPipeline(pipeline* pl, int* pipeIn) { if(pl == NULL) { return; } if(pl->next == NULL) { execSimple(pl->command, pipeIn, NULL); return; } int pipeOut[2]; pipe(pipeOut); int pid = execSimple(pl->command, pipeIn, pipeOut); runPipeline(pl->next, pipeOut); close(pipeOut[0]); close(pipeOut[1]); }
/** * Runs the command specified by the user. This is the main starting point * for command execution. * * @param commandString The command entered into the prompt * * @returns nothing */ void runCommand(char* commandString, shellInternal* env) { env->piping = 0; env->background = 0; // Parse the given command before running it char* arguments[MAX_ARGUMENTS]; parseCommand(commandString, arguments, env); char* command = arguments[0]; if(!executeBuiltin(command, arguments, env)) { if(env->piping) { runPipeline(arguments, env); } else { pid_t pid = fork(); if(pid == 0) { execute(arguments); exit(0); } else { // Check for running a background process if(!env->background) { waitpid(pid, NULL, 0); } else { sleep(1); printf("%d\n", pid); } } } } clearData(arguments, MAX_ARGUMENTS); }
/* prints to stderr if the number is not in the list */ void executeCommandFromHistory(int command_number) { history_item* theItem; int lastNumber; if(history_list == NULL) { initHistory(); } if(length(history_list) == 0) { return; } lastNumber = ((history_item*)(history_list->tail->data))->command_number - 1; if(command_number > lastNumber || command_number < (lastNumber - HISTORY_LENGTH) || command_number <= 0) { fprintf(stderr, "%d: Event not found.\n", command_number); free(((history_item*)(history_list->tail->data))->command_line); free(history_list->tail->data); removeLast(history_list); } else { char* copy; theItem = find(history_list, historyNumberEquals, &command_number)->data; copy = newstr(theItem->command_line); printf("%s\n", copy); free(((history_item*)(history_list->tail->data))->command_line); ((history_item*)(history_list->tail->data))->command_line = newstr(copy); runPipeline(crack_pipeline(copy)); } }
void execTokens(int numTokens, char** tokens) { pipeline* pl = malloc(sizeof(pipeline)); pl->next = NULL; pl->command = NULL; pipeline* lastPipe = pl; bool hasFileIn = false; int fileIn[2]; // pretends to be a pipe to pass to execSimple // actually just a regular array bool hasSpecial = false; int i; for(i = 0; i < numTokens; hasSpecial = false) { simpleCmd* cmd = malloc(sizeof(simpleCmd)); cmd->name = tokens[i]; // allocate enough space for all remaining tokens, plus null terminator // this will be more than we need in many cases, but it's easy cmd->args = (char**) malloc((numTokens - i + 1) * sizeof(char*)); int j; for(j = 0; j < numTokens - i; j++) { if (isSpecialToken(tokens[i + j])) { hasSpecial = true; break; } cmd->args[j] = tokens[i + j]; } i += j; // advances i to the next token to read if (hasSpecial) { specials: switch(tokens[i][0]) { // deal w/ special token: // '|' -> advance past to next token case '|' : i++; break; // '<' -> open file desriptor, set up pipe case '<' : { i++; if(i >= numTokens) { fprintf(stderr, "%s", "quash: syntax error after '<'\n"); return; } char* filename = tokens[i]; int fd = open(filename, O_RDONLY); if(fd < 0) { fprintf(stderr, "quash: could not open file: %s\n", filename); return; } hasFileIn = true; fileIn[0]=fd; fileIn[1]=fd; i++; // should be followed by a special symbol // rather than a commaand, so jump to the // appropriate place unless we are at the end if(i < numTokens) { goto specials; } break; } // '>' -> convert to new builtin (writef) case '>' : if (tokens[i][1] == '>') { tokens[i] = "appendf"; } else { tokens[i] = "writef"; } break; // '&' -> ? (deal w/ later? Should only occur at end) : dealt with in main } } cmd->args[j] = NULL; pipeline* nextPipe = malloc(sizeof(pipeline)); nextPipe->command = cmd; nextPipe->next = NULL; lastPipe->next = nextPipe; lastPipe = nextPipe; } // drop dummy block, pass null for stdin runPipeline(pl->next, hasFileIn ? fileIn : NULL); freePipeline(pl); if(hasFileIn) { close(fileIn[0]); } }
int main (int argc, const char * argv[]) { char *line; pipeline pl; char *promptstr; initHistory(); initJobs(); /* check for the right number of arguments */ if(argc >= 2) { FILE* theFile = fopen(argv[1], "r"); if(theFile == NULL) { if(errno == ENOENT) { fprintf(stderr, "%s: Command not found.\n", argv[1]); } else { perror("fopen"); } exit(-1); } if(dup2(fileno(theFile), STDIN_FILENO) == -1) { perror("dup2"); exit(-1); } fclose(theFile); } /* set prompt */ promptstr = PROMPT; prompt(promptstr); while ( TRUE ) { if ( NULL == (line = readLongString(stdin))) { if ( feof(stdin) ) { /* end of the input file, we're done */ exit(0); } } else if(line[0] == '\0') { /* do nothing */ } else { /* line is added to history list, and freed from there */ /* copyLine is sent to pipeline, and freed from there */ /* jobs need their own copy of the command_line */ char* copyLine = newstr(line); /* We got a line, send it off to the pipeline cracker and * launch it */ pl = crack_pipeline(copyLine); if(pl != NULL) { addCommandToHistory(line); runPipeline(pl); } free_pipeline(pl); lineno++; /* readLongString trims newlines, so increment it manually */ } fflush(stdout); //tcsetpgrp(STDIN_FILENO, getpgid(0)); prompt(promptstr); } return 0; }