JNIEXPORT jboolean JNICALL Java_gov_nasa_jpf_symbolic_dp_NativeInterface_isSatisfiable (JNIEnv *env, jclass cls, jstring constraintString ) { constraint = (char*) (*env)->GetStringUTFChars(env,constraintString, NULL); if( constraint == NULL ){ throwRuntimeException( "out of memory?" ); } //printf( "query: %s\n", constraint); //fflush(stdout); if (constraint[0] == '\0') return TRUE; vc_push(vc); marker = 0; int constraintCount = 1; char c; int i = 0; do{ c = constraint[i++]; if (c == ',') constraintCount++; }while(c != '\0'); Expr* constraintArray = (Expr*) malloc(sizeof(Expr)*constraintCount); i = 0; char token[2]; // it must be just a comma and '\0' do{ constraintArray[i++] = parse(); }while(readToken(token)); Expr andExpr = vc_andExprN(vc, constraintArray, constraintCount); linkedlist_add(&exprPool, andExpr); jboolean result = check(vc, andExpr); //fflush(stdout); //clean up (*env)->ReleaseStringUTFChars(env,constraintString, constraint); free(constraintArray); freeStuff(); vc_pop(vc); return result; }
int main(){ time_t t1, t2; double t0; time(&t1); FILE *dataFile; dataFile = fopen("cs451.conf", "r"); if (dataFile == NULL) { printf("cannot open file\n"); exit(0); } char temp[128]; char item[128]; char maxProcesses[42], timeQuantum[42]; while(fscanf(dataFile, "%s", temp) != EOF) { if (strstr(temp, "processes:") != NULL) { fscanf(dataFile, "%s", maxProcesses); } else if (strstr(temp, "quantum:") != NULL) { fscanf(dataFile, "%s", timeQuantum); } else if (strstr(temp, ":") != NULL) { fscanf(dataFile, "%s", item); } } fclose(dataFile); createFiles(); fillQueue(atoi(maxProcesses)); //printQueue(); simulate(atoi(maxProcesses)); freeStuff(); deleteFiles(); time(&t2); t0 = difftime(t2, t1); printf("Program run-time: %.0f seconds\n", t0); }
int main(){ FILE *dataFile; dataFile = fopen("cs451.conf", "r"); if (dataFile == NULL) { printf("cannot open file\n"); exit(0); } char temp[128]; char item[128]; char maxProcesses[42], timeQuantum[42]; while(fscanf(dataFile, "%s", temp) != EOF) { if (strstr(temp, "processes:") != NULL) { fscanf(dataFile, "%s", maxProcesses); } else if (strstr(temp, "quantum:") != NULL) { fscanf(dataFile, "%s", timeQuantum); } else if (strstr(temp, ":") != NULL) { fscanf(dataFile, "%s", item); //enqueue item //enqueue(atoi(item)); //printf("%s\n", item); } } fclose(dataFile); fillQueue(atoi(maxProcesses)); //printQueue(); simulate(); freeStuff(); }
int main(int argc, char** argv) { if(argc < 2) throwRuntimeException( "must specify the file name that contains the query" ); printf( "argc: %d\n", argc); printf("%s\n",argv[1]); // initialize stuff hashmap_init(&vars, 0, hash_str, cmp_str, NULL, NULL); linkedlist_init(&exprPool, 0, NULL); //flags = vc_createFlags(); //vc_setStringFlag(flags, "dump-log", "test1.cvc"); //vc = vc_createValidityChecker(flags); vc = vc_createValidityChecker(NULL); intType = vc_intType(vc); realType = vc_realType(vc); constraint = (char*) malloc(sizeof(char)*10000); int k = 0; FILE* fpt = fopen(argv[1],"r"); while(1){ char c = fgetc(fpt); if (c == EOF) break; constraint[k++]=c; } constraint[k]='\0'; if (constraint[0] == '\0') return TRUE; vc_push(vc); marker = 0; int constraintCount = 1; char c; int i = 0; do{ c = constraint[i++]; if (c == ',') constraintCount++; }while(c != '\0'); Expr* constraintArray = (Expr*) malloc(sizeof(Expr)*constraintCount); i = 0; char token[2]; // it must be just a comma and '\0' do{ constraintArray[i++] = parse(); }while(readToken(token)); Expr andExpr = vc_andExprN(vc, constraintArray, constraintCount); linkedlist_add(&exprPool, andExpr); jboolean result = check(vc, andExpr); //clean up free(constraintArray); freeStuff(); vc_pop(vc); if(result) printf("satisfiable"); else printf("unsatisfiable"); return EXIT_SUCCESS; }
/** The main thing. * @param argc count of command-line tokens. * @param argv array of command-line tokens. * @return 0 on success, 1-255 on failure. */ int main(int argc, char* argv[]){ struct stat stattemp; int fd; bool done = FALSE; char* commandLine; int* status; stageStruct** pStages; int** pipefd = NULL; numOfPid = 0; pid = NULL; running = NULL; status = NULL; struct sigaction my_act; //new signal response struct sigaction old_act; //old signal response //signal stuff if(sigemptyset(&(my_act.sa_mask)) == -1){ fprintf(stderr, "mush: sigemptyset\n"); _exit(EXIT_FAILURE); } /*behavior modification of signals*/ my_act.sa_flags = 0; my_act.sa_handler = sighandler; if(sigaction(SIGINT, &my_act, &old_act) == -1){ fprintf(stderr, "mush: sigaction\n"); _exit(EXIT_FAILURE); } //handles arguments if(argc >= 3){ fprintf(stderr, "Usage: mush [file]\n"); } else if(argc == 2){ fd = open(argv[1], O_RDONLY); if(fd == -1){ fprintf(stderr,"error on open(%s, O_RDONLY)\n",argv[1]); } if(dup2(fd, STDIN_FILENO) == -1){ fprintf(stderr,"error on dup2(fd, STDIN_FILENO)\n"); _exit(EXIT_FAILURE); } close(fd); } //THE while loop while(!done){ //prompt if(isatty(fileno(stdin)) && isatty(fileno(stdout))){ printf("8-P "); fflush(stdout); } //get the command commandLine = getLine(stdin); //exit if EOF is sent if(feof(stdin)){ break; } if((commandLine == NULL) || (strlen(commandLine) == 0)){ continue; } //parse the command into stage structs pStages = parseline(commandLine); if(pStages == NULL){ continue; } //checking to see if it's a cd command if(strcmp(pStages[0]->argvv[0], "cd") == 0){ if(pStages[0]->argcc == 1){ if(chdir(getenv("HOME")) == -1){ fprintf(stderr,"chdir failed (chdir(HOME))\n"); } } else{ if(chdir(pStages[0]->argvv[1]) == -1){ fprintf(stderr,"chdir failed\n"); } } freeStage(pStages,NULL); continue; } //copy the number of stages numOfPid = pStages[0]->totalStageNumber; //start mallocing everything pid = (pid_t*)malloc(sizeof(pid_t)*numOfPid); running = (bool*)malloc(sizeof(bool)*numOfPid); status = (int*)malloc(sizeof(int)*numOfPid); pipefd = (int**)malloc(sizeof(int*)*(numOfPid)); //mallocing each file descriptors, in and out for(int i = 0; i < numOfPid; i++){ pipefd[i] = (int*)malloc(sizeof(int)*2); } //setting each of the running state to false for(int i = 0; i < numOfPid; i++){ running[i] = FALSE; } for(int i = 0; i < numOfPid; i++){ if(pipe(pipefd[i]) == -1){ fprintf(stderr,"mush: pipe errer"); close(pipefd[i][0]); close(pipefd[i][1]); continue; } } //special case for first pipe in if(pStages[0]->input != NULL){ pipefd[0][0] = open(pStages[0]->input, O_RDONLY); fprintf(stderr,"pipefd[0][0] == %d\n",pipefd[0][0]); if(pipefd[0][0] == -1){ fprintf(stderr,"mush: %s: No such file or directory\n",pStages[0]->input); freeStuff(status,pipefd,running,pid,numOfPid); freeStage(pStages,NULL); continue; } } else{ pipefd[0][0] = STDIN_FILENO; } //special case for last pipe for out if(pStages[numOfPid-1]->output != NULL){ if((stat(pStages[numOfPid-1]->output, &stattemp) == 0 && !(S_ISDIR(stattemp.st_mode))) || errno == ENOENT){ pipefd[numOfPid-1][1] = open(pStages[numOfPid-1]->output, (O_WRONLY|O_CREAT|O_TRUNC), S_IRUSR|S_IWUSR); fprintf(stderr,"pipefd[numOfPid-1][1] == %d\n",pipefd[numOfPid-1][1]); if(pipefd[numOfPid-1][1] == -1){ fprintf(stderr,"file open failed with : %s",pStages[numOfPid-1]->output); close(pipefd[numOfPid-1][0]); freeStuff(status,pipefd,running,pid,numOfPid); freeStage(pStages,NULL); continue; } } else{ //file is a directory fprintf(stderr,"This is a directory\n"); close(pipefd[numOfPid-1][0]); freeStuff(status,pipefd,running,pid,numOfPid); freeStage(pStages,NULL); continue; } } else{ pipefd[numOfPid-1][1] = STDOUT_FILENO; } for(int i = 0; i < numOfPid; i++){ //now start duping and closing the file descriptors running[i] = TRUE; pid[i] = fork(); //something went wrong if(pid[i] == -1){ fprintf(stderr,"mush: fork error\n"); close(pipefd[i][0]); close(pipefd[i][1]); freeStuff(status,pipefd,running,pid,numOfPid); freeStage(pStages,NULL); continue; } //this is the child else if(pid[i] == 0){ //make mushit killable by SIGINT if(sigaction(SIGINT, &old_act, NULL) == -1){ } if(i == 0 && numOfPid == 1){ } if(numOfPid != 1){ dup2(pipefd[i][1],STDIN_FILENO); if(i == (numOfPid-1)){ //fprintf(stderr,"STDOUT_FILENO=%d\n",STDOUT_FILENO); //dup2(1,STDOUT_FILENO); } else{ dup2(pipefd[i+1][0],STDOUT_FILENO); } } if(execvp(pStages[i]->argvv[0], pStages[i]->argvv) == -1){ fprintf(stderr,"execvp failed with : %s\n",pStages[i]->argvv[0]); freeStuff(status,pipefd,running,pid,numOfPid); freeStage(pStages,NULL); _exit(EXIT_FAILURE); } fprintf(stderr,"------------------\n"); } //close if not std if(i != 0){ close(pipefd[i][0]); } if(i != numOfPid-1){ close(pipefd[i][1]); } } //end of the for loop //and now we wait for all the child to come back for(int i = 0; i < numOfPid; i++){ if(waitpid(pid[i], &status[i], 0) == -1){ if(WIFSIGNALED(status[i])){ if(WTERMSIG(status[i]) != SIGINT){ //fprintf(stderr, "mush: waitpid signaled error %d\n", WTERMSIG(status[i])); } } } running[i] = FALSE; } freeStage(pStages,NULL); freeStuff(status,pipefd,running,pid,numOfPid); } //the very long while loop ends here free(commandLine); fprintf(stdout,"Good Bye.\n"); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { globalCost = 0; numWalks = 0; //curtime = time(NULL); //srand(curtime); srand(12212012); head = NULL; tail = NULL; char fname[84]; char dest[84]; char fileName[100]; char start[84]; int fcost; printf("Enter data file: "); scanf("%s", fileName); FILE *dataFile; dataFile = fopen(fileName, "r"); if (dataFile == NULL) { printf("cannot open file\n"); exit(0); } while(fscanf(dataFile, "%s", fname) != EOF) { if(!strcmp(fname, "STOP")) { break; } else { insert(fname); } } while(fscanf(dataFile, "%s %s %d", fname, dest, &fcost) != EOF) { if(!strcmp(fname, "STOP")) { break; } else { createLinks(fname, dest, fcost); } } fscanf(dataFile, "%s", start); int x; if(argc>1) { switch(atoi(argv[1])) { case 0: printf("\nDrunkard's Walk\n"); x = drunkWalk(start); break; case 1: printf("\nGreedy Walk\n"); x = greedy(start); break; case 2: printf("\nGenerous Walk\n"); x = generous(start); break; default: printf("\nNon-applicable argument\n0-Drunkard's Walk\n1-Greedy Walk\n2-Generous Walk\n"); break; } } else { printf("Need command line argument\n"); } //printForwardList(); //printBackwardList(); //printAll(); if(x!=0) { printf("\nYou started at %s\nYou're home and it only cost you %d!\n\n", start, globalCost); } else { printf("Please try again\n\n"); } fclose(dataFile); freeStuff(); }