bool program_passes(ast_t* program, pass_opt_t* options) { bool r; if(do_pass(&program, &r, options, PASS_IMPORT, pass_import, NULL)) return r; if(do_pass(&program, &r, options, PASS_NAME_RESOLUTION, NULL, pass_names)) return r; if(do_pass(&program, &r, options, PASS_FLATTEN, NULL, pass_flatten)) return r; if(do_pass(&program, &r, options, PASS_TRAITS, pass_traits, NULL)) return r; if(options->docs) generate_docs(program, options); if(do_pass(&program, &r, options, PASS_EXPR, pass_pre_expr, pass_expr)) return r; if(!pass_finalisers(program)) return false; return true; }
bool package_passes(ast_t* package, pass_opt_t* options) { bool r; if(do_pass(&package, &r, options, PASS_SUGAR, pass_sugar, NULL)) return r; if(do_pass(&package, &r, options, PASS_SCOPE, pass_scope, NULL)) return r; return true; }
void main_loop() { int retval; retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd); if (retval) { log_messages.printf(MSG_CRITICAL, "boinc_db.open: %s\n", boincerror(retval) ); exit(1); } while (1) { log_messages.printf(MSG_DEBUG, "doing a pass\n"); if (1) { bool did_something = do_pass(); if (one_pass) break; if (did_something) continue; #ifdef GCL_SIMULATOR continue_simulation("transitioner"); signal(SIGUSR2, simulator_signal_handler); pause(); #else log_messages.printf(MSG_DEBUG, "sleeping %d\n", sleep_interval); daemon_sleep(sleep_interval); #endif } } }
bool module_passes(ast_t* package, pass_opt_t* options, source_t* source) { if(!pass_parse(package, source)) return false; ast_t* module = ast_child(package); bool r; if(do_pass(&module, &r, options, PASS_SYNTAX, pass_syntax, NULL)) return r; return true; }
void Board::do_move(Move move) { if (move.is_pass()) { do_pass(); return; } Rotation* rot = &block_set[move.block_id()]->rotations[move.direction()]; int px = move.x() + rot->offset_x; int py = move.y() + rot->offset_y; Piece *piece = rot->piece; unsigned char block = is_violet() ? VIOLET_BLOCK : ORANGE_BLOCK; unsigned char side_bit = is_violet() ? VIOLET_SIDE : ORANGE_SIDE; unsigned char edge_bit = is_violet() ? VIOLET_EDGE : ORANGE_EDGE; for (int i = 0; i < piece->size; i++) { int x = px + piece->coords[i].x; int y = py + piece->coords[i].y; at(x, y) |= block; if (in_bounds(x-1, y)) at(x-1, y) |= side_bit; if (in_bounds(x, y-1)) at(x, y-1) |= side_bit; if (in_bounds(x+1, y)) at(x+1, y) |= side_bit; if (in_bounds(x, y+1)) at(x, y+1) |= side_bit; if (in_bounds(x-1,y-1)) at(x-1,y-1) |= edge_bit; if (in_bounds(x+1,y-1)) at(x+1,y-1) |= edge_bit; if (in_bounds(x-1,y+1)) at(x-1,y+1) |= edge_bit; if (in_bounds(x+1,y+1)) at(x+1,y+1) |= edge_bit; } int blk = is_violet() ? move.block_id() : move.block_id() + NBLOCK; block_info[blk] = move.xy() + 0x11; block_info[NBLOCK*2 + move.block_id()] |= is_violet() ? move.direction() : move.direction() << 4; turn_++; }
int main(int argc, char** argv) { int retval; bool one_pass = false; int i; DB_APP app; check_stop_daemons(); *app.name='\0'; for (i=1; i<argc; i++) { if (is_arg(argv[i], "one_pass")) { one_pass = true; } else if (is_arg(argv[i], "dont_retry_errors")) { dont_retry_errors = true; } else if (is_arg(argv[i], "preserve_wu_files")) { preserve_wu_files = true; } else if (is_arg(argv[i], "preserve_result_files")) { preserve_result_files = true; } else if (is_arg(argv[i], "app")) { strcpy(app.name, argv[++i]); } else if (is_arg(argv[i], "appid")) { if (!argv[++i]) { log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); usage(argv[0]); exit(1); } appid = atoi(argv[i]); } else if (is_arg(argv[i], "d") || is_arg(argv[i], "debug_level")) { if (!argv[++i]) { log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); usage(argv[0]); exit(1); } int dl = atoi(argv[i]); log_messages.set_debug_level(dl); if (dl == 4) g_print_queries = true; } else if (is_arg(argv[i], "mod")) { if (!argv[i+1] || !argv[i+2]) { log_messages.printf(MSG_CRITICAL, "%s requires two arguments\n\n", argv[i]); usage(argv[0]); exit(1); } id_modulus = atoi(argv[++i]); id_remainder = atoi(argv[++i]); } else if (is_arg(argv[i], "dont_delete_antiques")) { dont_delete_antiques = true; } else if (is_arg(argv[i], "delete_antiques_interval")) { antique_interval = atoi(argv[++i]); } else if (is_arg(argv[i], "delete_antiques_limit")) { antique_limit = atoi(argv[++i]); } else if (is_arg(argv[i], "dont_delete_batches")) { dont_delete_batches = true; } else if (is_arg(argv[i], "delete_antiques_now")) { antique_delay = 0; } else if (is_arg(argv[i], "input_files_only")) { do_output_files = false; dont_delete_antiques = true; } else if (is_arg(argv[i], "output_files_only")) { do_input_files = false; } else if (is_arg(argv[i], "sleep_interval")) { if (!argv[++i]) { log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); usage(argv[0]); exit(1); } sleep_interval = atoi(argv[i]); } else if (is_arg(argv[i], "h") || is_arg(argv[i], "help")) { usage(argv[0]); exit(0); } else if (is_arg(argv[i], "v") || is_arg(argv[i], "version")) { printf("%s\n", SVN_VERSION); exit(0); } else { log_messages.printf(MSG_CRITICAL, "unknown command line argument: %s\n\n", argv[i]); usage(argv[0]); exit(1); } } if (id_modulus) { log_messages.printf(MSG_DEBUG, "Using mod'ed WU/result enumeration. mod = %d rem = %d\n", id_modulus, id_remainder ); } retval = config.parse_file(); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't parse config.xml: %s\n", boincerror(retval) ); exit(1); } log_messages.printf(MSG_NORMAL, "Starting\n"); retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd); if (retval) { log_messages.printf(MSG_CRITICAL, "can't open DB\n"); exit(1); } retval = boinc_db.set_isolation_level(READ_UNCOMMITTED); if (retval) { log_messages.printf(MSG_CRITICAL, "boinc_db.set_isolation_level: %s; %s\n", boincerror(retval), boinc_db.error_string() ); } if (*app.name && !appid) { char buf[256]; sprintf(buf, "where name='%s'", app.name); retval = app.lookup(buf); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't find app\n"); exit(1); } appid=app.id; log_messages.printf(MSG_DEBUG, "Deleting files of appid %d\n",appid); } install_stop_signal_handler(); bool retry_errors_now = !dont_retry_errors; double next_error_time=0; double next_antique_time = dtime() + antique_delay; while (1) { bool got_any = do_pass(false); if (retry_errors_now) { bool got_any_errors = do_pass(true); if (got_any_errors) { got_any = true; } else { retry_errors_now = false; next_error_time = dtime() + ERROR_INTERVAL; log_messages.printf(MSG_DEBUG, "ending retry of previous errors\n" ); } } if (!got_any) { if (one_pass) break; sleep(sleep_interval); } if (!dont_delete_antiques && (dtime() > next_antique_time)) { log_messages.printf(MSG_DEBUG, "Doing antique deletion pass\n" ); do_antique_pass(); next_antique_time = dtime() + antique_interval; } if (!dont_retry_errors && !retry_errors_now && (dtime() > next_error_time)) { retry_errors_now = true; log_messages.printf(MSG_DEBUG, "starting retry of previous errors\n" ); } } }
int main(int argc, char** argv) { int retval; char buf[256]; for (int i=1; i<argc; i++) { if (!strcmp(argv[i], "--app_name")) { app_name = argv[++i]; } else if (!strcmp(argv[i], "--lo")) { lo = atoi(argv[++i]); } else if (!strcmp(argv[i], "--hi")) { hi = atoi(argv[++i]); } else if (!strcmp(argv[i], "-d")) { log_messages.set_debug_level(atoi(argv[++i])); } else if (!strcmp(argv[i], "--debug_leveld")) { log_messages.set_debug_level(atoi(argv[++i])); } else if (!strcmp(argv[i], "--sleep_time")) { sleep_time = atoi(argv[++i]); } else if (!strcmp(argv[i], "--random_order")) { order_clause = " order by random "; } else if (!strcmp(argv[i], "--priority_asc")) { order_clause = " order by priority asc "; } else if (!strcmp(argv[i], "--priority_order")) { order_clause = " order by priority desc "; } else if (!strcmp(argv[i], "--priority_order_create_time")) { order_clause = " order by priority desc, workunitid "; } else { usage(); } } if (!app_name || !lo || !hi || !sleep_time) { usage(); } log_messages.printf(MSG_NORMAL, "Starting\n"); retval = config.parse_file(); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't parse config.xml: %s\n", boincerror(retval) ); exit(1); } retval = boinc_db.open( config.db_name, config.db_host, config.db_user, config.db_passwd ); if (retval) { log_messages.printf(MSG_CRITICAL, "boinc_db.open: %d; %s\n", retval, boinc_db.error_string() ); exit(1); } sprintf(buf, "where name='%s'", app_name); if (app.lookup(buf)) { log_messages.printf(MSG_CRITICAL, "no such app: %s\n", app_name); exit(1); } if (app.n_size_classes < 2) { log_messages.printf(MSG_CRITICAL, "app '%s' is not multi-size\n", app_name); exit(1); } while (1) { bool action; retval = do_pass(action); if (retval) { log_messages.printf(MSG_CRITICAL, "do_pass(): %s", boincerror(retval) ); exit(1); } if (!action) { log_messages.printf(MSG_NORMAL, "sleeping\n"); daemon_sleep(sleep_time); } } }
int main(int argc, char** argv) { int retval; bool one_pass = false; int i; check_stop_daemons(); for (i=1; i<argc; i++) { if (!strcmp(argv[i], "-one_pass")) { one_pass = true; } else if (!strcmp(argv[i], "-dont_retry_errors")) { dont_retry_errors = true; } else if (!strcmp(argv[i], "-preserve_wu_files")) { preserve_wu_files = true; } else if (!strcmp(argv[i], "-preserve_result_files")) { preserve_result_files = true; } else if (!strcmp(argv[i], "-appid")) { appid = atoi(argv[++i]); } else if (!strcmp(argv[i], "-d")) { log_messages.set_debug_level(atoi(argv[++i])); } else if (!strcmp(argv[i], "-mod")) { id_modulus = atoi(argv[++i]); id_remainder = atoi(argv[++i]); } else if (!strcmp(argv[i], "-dont_delete_antiques")) { dont_delete_antiques = true; } else if (!strcmp(argv[i], "-dont_delete_batches")) { dont_delete_batches = true; } else if (!strcmp(argv[i], "-delete_antiques_now")) { antique_delay = 0; } else if (!strcmp(argv[i], "-input_files_only")) { do_output_files = false; dont_delete_antiques = true; } else if (!strcmp(argv[i], "-output_files_only")) { do_input_files = false; } else if (!strcmp(argv[i], "-sleep_interval")) { sleep_interval = atoi(argv[++i]); } else if (!strcmp(argv[i], "-help")) { usage(); } else { log_messages.printf(MSG_CRITICAL, "Unrecognized arg: %s\n", argv[i] ); usage(); } } if (id_modulus) { log_messages.printf(MSG_DEBUG, "Using mod'ed WU/result enumeration. mod = %d rem = %d\n", id_modulus, id_remainder ); } retval = config.parse_file(); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't parse config.xml: %s\n", boincerror(retval) ); exit(1); } log_messages.printf(MSG_NORMAL, "Starting\n"); retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd); if (retval) { log_messages.printf(MSG_CRITICAL, "can't open DB\n"); exit(1); } retval = boinc_db.set_isolation_level(READ_UNCOMMITTED); if (retval) { log_messages.printf(MSG_CRITICAL, "boinc_db.set_isolation_level: %d; %s\n", retval, boinc_db.error_string() ); } install_stop_signal_handler(); bool retry_errors_now = !dont_retry_errors; double next_error_time=0; double next_antique_time = dtime() + antique_delay; while (1) { bool got_any = do_pass(false); if (retry_errors_now) { bool got_any_errors = do_pass(true); if (got_any_errors) { got_any = true; } else { retry_errors_now = false; next_error_time = dtime() + ERROR_INTERVAL; log_messages.printf(MSG_DEBUG, "ending retry of previous errors\n" ); } } if (!got_any) { if (one_pass) break; sleep(sleep_interval); } if (!dont_delete_antiques && (dtime() > next_antique_time)) { log_messages.printf(MSG_DEBUG, "Doing antique deletion pass\n" ); do_antique_pass(); next_antique_time = dtime() + ANTIQUE_INTERVAL; } if (!dont_retry_errors && !retry_errors_now && (dtime() > next_error_time)) { retry_errors_now = true; log_messages.printf(MSG_DEBUG, "starting retry of previous errors\n" ); } } }
int main(int argc, char** argv) { int retval; bool one_pass = false; int i; int sleep_sec = 600; check_stop_daemons(); for (i=1; i<argc; i++) { if (is_arg(argv[i], "one_pass")) { one_pass = true; } else if (is_arg(argv[i], "dont_delete")) { dont_delete = true; } else if (is_arg(argv[i], "d") || is_arg(argv[i], "debug_level")) { if (!argv[++i]) { log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); usage(argv[0]); exit(1); } int dl = atoi(argv[i]); log_messages.set_debug_level(dl); if (dl == 4) g_print_queries = true; } else if (is_arg(argv[i], "min_age_days")) { if (!argv[++i]) { log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); usage(argv[0]); exit(1); } min_age_days = atof(argv[i]); } else if (is_arg(argv[i], "max")) { if (!argv[++i]) { log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); usage(argv[0]); exit(1); } max_number_workunits_to_purge= atoi(argv[i]); } else if (is_arg(argv[i], "daily_dir")) { daily_dir=true; } else if (is_arg(argv[i], "zip")) { compression_type=COMPRESSION_ZIP; } else if (is_arg(argv[i], "gzip")) { compression_type=COMPRESSION_GZIP; } else if (is_arg(argv[i], "max_wu_per_file")) { if(!argv[++i]) { log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); usage(argv[0]); exit(1); } max_wu_per_file = atoi(argv[i]); } else if (is_arg(argv[i], "no_archive")) { no_archive = true; } else if (is_arg(argv[i], "-sleep")) { if(!argv[++i]) { log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); usage(argv[0]); exit(1); } sleep_sec = atoi(argv[i]); if (sleep_sec < 1 || sleep_sec > 86400) { log_messages.printf(MSG_CRITICAL, "Unreasonable value of sleep interval: %d seconds\n", sleep_sec ); usage(argv[0]); exit(1); } } else if (is_arg(argv[i], "--help") || is_arg(argv[i], "-help") || is_arg(argv[i], "-h")) { usage(argv[0]); return 0; } else if (is_arg(argv[i], "--version") || is_arg(argv[i], "-version")) { printf("%s\n", SVN_VERSION); exit(0); } else { log_messages.printf(MSG_CRITICAL, "unknown command line argument: %s\n\n", argv[i] ); usage(argv[0]); exit(1); } } retval = config.parse_file(); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't parse config.xml: %s\n", boincerror(retval) ); exit(1); } log_messages.printf(MSG_NORMAL, "Starting\n"); retval = boinc_db.open( config.db_name, config.db_host, config.db_user, config.db_passwd ); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't open DB\n"); exit(2); } install_stop_signal_handler(); boinc_mkdir(config.project_path("archives")); // on exit, either via the check_stop_daemons signal handler, or // through a regular call to exit, these functions will be called // in the opposite order of registration. // atexit(close_db_exit_handler); atexit(close_all_archives); while (1) { if (time_to_quit()) { break; } if (!do_pass() && !one_pass) { log_messages.printf(MSG_NORMAL, "Sleeping....\n"); sleep(sleep_sec); } if (one_pass) { break; } } // files and database are closed by exit handler exit(0); }
void do_play_ascii(Gameinfo *gameinfo) { int m, num; float fnum; int passes = 0; /* two passes and its over */ int tmp; char line[80]; char *line_ptr = line; char *command; char *tmpstring; int state = 1; if (have_time_settings()) clock_on = 1; while (state == 1) { state = 0; /* No score is estimated yet. */ current_score_estimate = NO_SCORE; /* Allow resignation at interface level (the engine may still be not * allowed to resign. */ resignation_allowed = 1; printf("\nBeginning ASCII mode game.\n\n"); gameinfo_print(gameinfo); /* Does the computer play first? If so, make a move. */ if (gameinfo->computer_player == gameinfo->to_move) state = computer_move(gameinfo, &passes); /* main ASCII Play loop */ while (state == 0) { /* Display game board. */ if (opt_showboard) ascii_showboard(); #if !READLINE /* Print the prompt */ mprintf("%s(%d): ", color_to_string(gameinfo->to_move), movenum + 1); /* Read a line of input. */ line_ptr = line; if (!fgets(line, 80, stdin)) return; #else snprintf(line, 79, "%s(%d): ", color_to_string(gameinfo->to_move), movenum + 1); if (!(line_ptr = readline(line))) return; add_history(line_ptr); #endif while (state == 0 && (command = strtok(line_ptr, ";"), line_ptr = 0, command)) { /* Get the command or move. */ switch (get_command(command)) { case RESIGN: state = ascii_endgame(gameinfo, 1); break; case END: case EXIT: case QUIT: return; case HELP: show_commands(); break; case CMD_HELPDEBUG: printf(DEBUG_COMMANDS); break; case SHOWBOARD: opt_showboard = !opt_showboard; break; case INFO: printf("\n"); gameinfo_print(gameinfo); break; case SETBOARDSIZE: if (sgf_initialized) { printf("Boardsize cannot be changed after record is started!\n"); break; } command += 10; if (sscanf(command, "%d", &num) != 1) { printf("\nInvalid command syntax!\n"); break; } if (!check_boardsize(num, stdout)) break; /* Init board. */ board_size = num; clear_board(); /* In case max handicap changes on smaller board. */ gameinfo->handicap = place_fixed_handicap(gameinfo->handicap); sgfOverwritePropertyInt(sgftree.root, "SZ", board_size); sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap); break; case SETHANDICAP: if (sgf_initialized) { printf("Handicap cannot be changed after game is started!\n"); break; } command += 9; if (sscanf(command, "%d", &num) != 1) { printf("\nInvalid command syntax!\n"); break; } if (num < 0 || num > MAX_HANDICAP) { printf("\nInvalid handicap: %d\n", num); break; } /* Init board. */ clear_board(); /* Place stones on board but don't record sgf * in case we change more info. */ gameinfo->handicap = place_fixed_handicap(num); printf("\nSet handicap to %d\n", gameinfo->handicap); gameinfo->to_move = (gameinfo->handicap ? WHITE : BLACK); break; case FREEHANDICAP: if (sgf_initialized) { printf("Handicap cannot be changed after game is started!\n"); break; } while (*command && *command != ' ') command++; ascii_free_handicap(gameinfo, command); break; case SETKOMI: if (sgf_initialized) { printf("Komi cannot be modified after game record is started!\n"); break; } command += 5; if (sscanf(command, "%f", &fnum) != 1) { printf("\nInvalid command syntax!\n"); break; } komi = fnum; printf("\nSet Komi to %.1f\n", komi); break; case SETDEPTH: command += 6; if (sscanf(command, "%d", &num) != 1) { printf("\nInvalid command syntax!\n"); break; } mandated_depth = num; printf("\nSet depth to %d\n", mandated_depth); break; case SETLEVEL: command += 6; if (sscanf(command, "%d", &num) != 1) { printf("\nInvalid command syntax!\n"); break; } set_level(num); printf("\nSet level to %d\n", num); break; case DISPLAY: if (!opt_showboard) ascii_showboard(); break; case FORCE: command += 6; /* skip the force part... */ switch (get_command(command)) { case MOVE: state = do_move(gameinfo, command, &passes, 1); break; case PASS: state = do_pass(gameinfo, &passes, 1); break; default: printf("Illegal forced move: %s %d\n", command, get_command(command)); break; } break; case MOVE: state = do_move(gameinfo, command, &passes, 0); break; case PASS: state = do_pass(gameinfo, &passes, 0); break; case PLAY: command += 5; if (sscanf(command, "%d", &num) != 1) { printf("\nInvalid command syntax!\n"); break; } if (num >= 0) for (m = 0; m < num; m++) { gameinfo->computer_player = OTHER_COLOR(gameinfo->computer_player); state = computer_move(gameinfo, &passes); if (state) break; if (passes >= 2) break; } else { printf("\nInvalid number of moves specified: %d\n", num); break; } break; case PLAYBLACK: if (gameinfo->computer_player == WHITE) gameinfo->computer_player = BLACK; if (gameinfo->computer_player == gameinfo->to_move) state = computer_move(gameinfo, &passes); break; case PLAYWHITE: if (gameinfo->computer_player == BLACK) gameinfo->computer_player = WHITE; if (gameinfo->computer_player == gameinfo->to_move) state = computer_move(gameinfo, &passes); break; case SWITCH: gameinfo->computer_player = OTHER_COLOR(gameinfo->computer_player); state = computer_move(gameinfo, &passes); break; case UNDO: case CMD_BACK: if (undo_move(1)) { sgftreeAddComment(&sgftree, "undone"); sgftreeBack(&sgftree); gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); } else printf("\nCan't undo.\n"); break; case CMD_FORWARD: if (sgftreeForward(&sgftree)) gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode, gameinfo->to_move); else printf("\nEnd of game tree.\n"); break; case CMD_LAST: while (sgftreeForward(&sgftree)) gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode, gameinfo->to_move); break; case COMMENT: printf("\nEnter comment. Press ENTER when ready.\n"); fgets(line, 80, stdin); sgftreeAddComment(&sgftree, line); break; case SCORE: showscore = !showscore; if (!showscore) current_score_estimate = NO_SCORE; break; case CMD_DEAD: silent_examine_position(FULL_EXAMINE_DRAGONS); showdead = !showdead; break; case CMD_CAPTURE: strtok(command, " "); showcapture(strtok(NULL, " ")); break; case CMD_DEFEND: strtok(command, " "); showdefense(strtok(NULL, " ")); break; case CMD_SHOWMOYO: tmp = printmoyo; printmoyo = PRINTMOYO_MOYO; silent_examine_position(EXAMINE_DRAGONS); printmoyo = tmp; break; case CMD_SHOWTERRI: tmp = printmoyo; printmoyo = PRINTMOYO_TERRITORY; silent_examine_position(EXAMINE_DRAGONS); printmoyo = tmp; break; case CMD_SHOWAREA: tmp = printmoyo; printmoyo = PRINTMOYO_AREA; silent_examine_position(EXAMINE_DRAGONS); printmoyo = tmp; break; case CMD_SHOWDRAGONS: silent_examine_position(EXAMINE_DRAGONS); showboard(1); break; case CMD_GOTO: strtok(command, " "); ascii_goto(gameinfo, strtok(NULL, " ")); break; case CMD_SAVE: strtok(command, " "); tmpstring = strtok(NULL, " "); if (tmpstring) { /* discard newline */ tmpstring[strlen(tmpstring) - 1] = 0; /* make sure we are saving proper handicap */ init_sgf(gameinfo); writesgf(sgftree.root, tmpstring); printf("You may resume the game"); printf(" with -l %s --mode ascii\n", tmpstring); printf("or load %s\n", tmpstring); } else printf("Please specify filename\n"); break; case CMD_LOAD: strtok(command, " "); tmpstring = strtok(NULL, " "); if (tmpstring) { /* discard newline */ tmpstring[strlen(tmpstring) - 1] = 0; if (!sgftree_readfile(&sgftree, tmpstring)) { fprintf(stderr, "Cannot open or parse '%s'\n", tmpstring); break; } /* to avoid changing handicap etc. */ if (gameinfo_play_sgftree(gameinfo, &sgftree, NULL) == EMPTY) fprintf(stderr, "Cannot load '%s'\n", tmpstring); else { sgf_initialized = 1; sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap); } } else printf("Please specify a filename\n"); break; case CMD_LISTDRAGONS: silent_examine_position(EXAMINE_DRAGONS); show_dragons(); break; default: printf("\nInvalid command: %s", command); break; } if (passes >= 2) state = ascii_endgame(gameinfo, 0); } #if READLINE free(line_ptr); #endif } sgffile_output(&sgftree); passes = 0; /* Play a different game next time. */ update_random_seed(); /* Free the sgf tree and prepare for a new game. */ sgfFreeNode(sgftree.root); sgftree_clear(&sgftree); sgftreeCreateHeaderNode(&sgftree, board_size, komi, gameinfo->handicap); sgf_initialized = 0; gameinfo_clear(gameinfo); } }