// this function is called when we need to detect next option entry in argv // return value: // true - next option entry found, retval not used // false - no more options, retval - reason (-1 no more options, 1 - argument processed as default // option with code 1) static bool detect_next_option(int argc, char* const argv[], const getopt_param& param, int& retval) { if (!is_option(argv[optind])) { // if optind points to non-option - then check it... if (is_finish(argv[optind])) { // is it terminate sequence ('--')? optind++; if(!param.posix && !param.process_all) swap_values(argc, (char**)argv, optind); retval = -1; return false; } else if (param.process_all) {// processing all elements optarg = (char*)argv[optind]; optind++; retval = 1; return false; } else if (param.posix) { retval = -1; return false; } else { int next_ind = look_for_option(argc, argv, optind); assert(next_ind != optind); // should not be same if (next_ind > 0) { add_to_swap(optind, next_ind - optind); // marking elements for swap /* NOTE: in swap_list stored indexes of elements which are not detected as options and not detected as arguments (if argv[x] is detected as option - stsrts with '-', it doesn't added to this list). later, when no more element may be detected, these stored elements are moved to end of argv vector */ optind = next_ind; } else {// no more options found swap_values(argc, (char**)argv, optind); retval = -1; return false; } } if (is_finish(argv[optind])) { optind++; if (!param.posix && !param.process_all) swap_values(argc, (char**)argv, optind); retval = -1; return false; } } return true; }
// looking for nearest option or terminate sequence ('--') in argv from optind index // if no option found - return -1, else - index of found option static int look_for_option(int argc, char* const argv[], int optind) { assert(argv); for (int i = optind; i < argc; i++) if (is_option(argv[i]) || is_finish(argv[i])) return i; return -1; }
// ----- begin of function WorldScanTraverser::remove -------// // // delete current element, delete the one which get_unit returns // // automatically traverse to next unit, don't call next() immediately // void WorldScanTraverser::remove() { err_when( is_finish() ); // remove is not prefered as it take time to memmove // if( scan_count > 0 ) // { // misc.del_array_rec( unit_recno_array, scan_count, sizeof(*unit_recno_array), traverse_count+1 ); // --scan_count; // --traverse_count; // move backward so next() will advance traverse_count // } unit_recno_array[traverse_count].unit_recno = 0; }
/* This function ask a moves, save it, apply it and return 0 if the game is finish (won or tie) */ int next_move(struct game *myGame){ struct move currMove; /* this is need for game_state_transtiction */ // struct state s1; printf("Player: %c\n", myGame->players[myGame->current_player]); /* continue to ask until the move is correct */ while(!move_is_valid(myGame, &currMove)); game_update(myGame, &currMove); // game_state_transition(&myGame->state, &currMove, &s1, myGame); /* update the moves history */ // TODO this can be used as history replay mode // if(update_moves(&currMove) !=0) // return 1; /* print the table */ game_print(myGame); /* check if there is a winner or it is tie */ return is_finish(myGame, &currMove); }
// ----- begin of function WorldScanTraverser::set_weight -------// // void WorldScanTraverser::set_weight(short w) { err_when( is_finish() ); unit_recno_array[traverse_count].sort_weight = w; }
// ----- begin of function WorldScanTraverser::get_weight -------// // short WorldScanTraverser::get_weight() { err_when( is_finish() ); return unit_recno_array[traverse_count].sort_weight; }
// ----- begin of function WorldScanTraverser::get_unit -------// // int WorldScanTraverser::get_unit() { err_when( is_finish() ); return unit_recno_array[traverse_count].unit_recno; }