void partialOscillation(LifeList *cells, LifeList *working, int testUpTo, int testPhases, int nmatches, PartialOscillatorDesc *posc) { int i,j; History hist; Transformation normT; Transformation oscT; normT= normalize(cells); hist= makeHistory(cells, testUpTo+testPhases); initMatchList(posc, nmatches); for (i=1; i<=testUpTo; i++) { int matchSize; int tx, ty; for (j=0; j<testPhases; j++) { getGeneration(cells, hist, j); getGeneration(working, hist, i+j); bestMatches(cells, working, i, nmatches, posc); } } getGeneration(cells, hist, 0); freeHistory(hist); transformBack(cells->cellList, normT, cells->ncells); }
/* At exit we'll try to fix the terminal to the initial conditions. */ static void linenoiseAtExit(void) { #ifdef _WIN32 SetConsoleMode(hIn, consolemode); CloseHandle(hOut); CloseHandle(hIn); #else disableRawMode(STDIN_FILENO); #endif freeHistory(); }
int main(int argc, char const *argv[]) { struct commit *first = new_commit(0, 0, "First !"); struct commit *tmp, *victim, *last; /*first->display = display_commit_major;*/ list_add(&first->lhead, &list_complete); list_add(&first->major_list, &list_major); display_commit_major(first); printf("\n"); display_history(first); tmp = add_minor_commit(first, "Work 1"); tmp = add_minor_commit(tmp, "Work 2"); victim = add_minor_commit(tmp, "Work 3"); last = add_minor_commit(victim, "Work 4"); display_history(first); del_commit(victim); display_history(first); tmp = add_major_commit(last, "Release 1"); tmp = add_minor_commit(tmp, "Work 1"); tmp = add_minor_commit(tmp, "Work 2"); tmp = add_major_commit(tmp, "Release 2"); tmp = add_minor_commit(tmp, "Work 1"); display_history(first); add_minor_commit(last, "Oversight !!!"); display_history(first); infos(first, 1, 2); infos(first, 1, 7); infos(first, 4, 2); #ifdef DEBUG printf("\n== TEST SUPP MAJEUR ==\n"); del_commit(first); display_history(NULL); #endif freeHistory(); return 0; }
int main(int argc, char* argv[]) { bool running = true; struct SudokuBoard board = { 0 }; struct SudokuCommandInput commandInput = { 0 }; const struct SudokuCommand *command = NULL; SudokuCommandResult status = SUDOKU_COMMAND_SUCCESS; initializeSudokuBoard(&board); initializeString(&commandInput.string); puts("========== Sudoku Game =========="); puts(showAllCommandsPrompt); putchar('\n'); // if one argument was provided, go ahead and load sudoku board from textfile if (argc > 1) { // if filename provided by argument cannot be found/read, loadSudokuBoard will // print an error statement, and execution will continue with a blank board loadSudokuBoard(argv[1], &board); } printSudokuBoard(&board); while (running) { // put extra space between previous output and command prompt putchar('\n'); command = getCommand(&commandInput); status = command->commandFunction(&board, &commandInput); if (status == SUDOKU_COMMAND_USAGE) { printf("Usage: '%s'\n", command->usagePrompt); } else if (status == SUDOKU_COMMAND_EXIT) { running = false; } } freeHistory(&board.history); return 0; }
/* At exit we'll try to fix the terminal to the initial conditions. */ static void linenoiseAtExit(void) { disableRawMode(STDIN_FILENO); freeHistory(); }
/* At exit we'll try to fix the terminal to the initial conditions. */ static void linenoiseAtExit(void) { freeHistory(); }
// *********************************************************************** // myShell - command line interpreter // // Project 1 - implement a Shell (CLI) that: // // 1. Prompts the user for a command line. // 2. WAIT's until a user line has been entered. // 3. Parses the global char array inBuffer. // 4. Creates new argc, argv variables using malloc. // 5. Searches a command list for valid OS commands. // 6. If found, perform a function variable call passing argc/argv variables. // 7. Supports background execution of non-intrinsic commands. // int P1_shellTask(int argc, char* argv[]) { int i, found, newArgc; // # of arguments char** newArgv; // pointers to arguments bool newTask = FALSE; // bool if & found at end // initialize shell commands commands = P1_init(); // init shell commands initializeHistory(); // init history sigAction(mySIGINTHandler, mySIGINT); sigAction(mySIGTSTPHandler, mySIGTSTP); sigAction(mySIGCONTHandler, mySIGCONT); sigAction(mySIGTERMHandler, mySIGTERM); while (1) { // output prompt if (diskMounted) printf("\n%s>>", dirPath); else printf("\n%ld>>", swapCount); SEM_WAIT(inBufferReady); // wait for input buffer semaphore if (!inBuffer[0]) continue; // ignore blank lines // printf("%s", inBuffer); ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); // get window size // printf ("lines %d\n", w.ws_row); // printf ("columns %d\n", w.ws_col); saveCommandInHistory(inBuffer); // save command history SWAP // do context switch { // ?? >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // ?? parse command line into argc, argv[] variables // ?? must use malloc for argv storage! static char *sp, *myArgv[MAX_ARGS]; // init arguments newArgc = 1; myArgv[0] = sp = inBuffer; // point to input string for (i=1; i<MAX_ARGS; i++) myArgv[i] = 0; // parse input string while ((sp = strchr(sp, ' '))) { if(isspace(sp[1])) { *sp++ = 0; continue; } *sp++ = 0; myArgv[newArgc++] = sp; if (sp[0]=='"') { char * quoteCopy2 = strchr((sp + 1),'"'); if(quoteCopy2 == NULL) // second quote wasn't found break; sp = quoteCopy2 + 1; //*sp++ = 0; //myArgv[newArgc++] = sp; } } SWAP // remove whitespace args int i; for ( i = 0 ; i < newArgc ; i++ ) { if(is_empty(myArgv[i])){ int j; for ( j = i ; j < newArgc ; j++) { int i; for ( i = 0 ; i <= strlen(myArgv[j]); i++ ) myArgv[j][i] = 0; if(j != (newArgc - 1)) strcpy(myArgv[j],myArgv[j+1]); } i = i - 1; newArgc = newArgc - 1; } } SWAP // if blank after clearing whitespace, ignore line if(is_empty(myArgv[0])) continue; // check for trailing ampersand if(strchr(myArgv[newArgc-1],'&') != NULL && strlen(strchr(myArgv[newArgc-1],'&')) == 1) { if (strlen(myArgv[newArgc - 1]) != 1) { // remove trailing ampersand if on last arg myArgv[newArgc - 1][strlen(myArgv[newArgc - 1]) - 1] = 0; } else { // remove trailing ampersand if is last arg newArgc = newArgc - 1; } newTask = TRUE; } else newTask = FALSE; SWAP // malloc argv stuff. newArgv = (char**) malloc(sizeof(char*) * newArgc); int z; for (z = 0; z < newArgc ; z++) { newArgv[z] = malloc((strlen(myArgv[z]) + 1) * sizeof(char)); strcpy(newArgv[z], myArgv[z]); // printf("newArgv[%d] = '%s'\n", z, newArgv[z]); } } // ?? >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SWAP // look for command for (found = i = 0; i < NUM_COMMANDS; i++) { char newArgvInsensitive[sizeof(newArgv[0])/sizeof(char)]; strcpy(newArgvInsensitive,newArgv[0]); int j; for(j = 0; newArgvInsensitive[j]; j++){ newArgvInsensitive[j] = tolower(newArgvInsensitive[j]); } if (!strcmp(newArgvInsensitive, commands[i]->command) || !strcmp(newArgvInsensitive, commands[i]->shortcut)) { // command found if(newTask) { createTask(&(*commands[i]->description), &(*commands[i]->func), MED_PRIORITY, newArgc, newArgv); } else { int retValue = (*commands[i]->func)(newArgc, newArgv); if (retValue) printf("\nCommand Error %d", retValue); } found = TRUE; break; } } if (!found) printf("\nInvalid command %s.",newArgv[0]); SWAP // ?? free up any malloc'd argv parameters int z; for (z = 0; z < newArgc ; z++) { free(newArgv[z]); } free(newArgv); for (i=0; i<INBUF_SIZE; i++) inBuffer[i] = 0; } freeHistory(); return 0; // terminate task } // end P1_shellTask