void parse_release(parse_info_t * info) { parse_close(info); parse_dispose_line(info); free(info); }
static void parse_id(uci_t * uci, const char string[]) { parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; ASSERT(uci!=NULL); ASSERT(string!=NULL); // init strcpy(command,"id"); parse_open(parse,string); parse_add_keyword(parse,"author"); parse_add_keyword(parse,"name"); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"author")) { ASSERT(!my_string_empty(argument)); my_string_set(&uci->author,argument); } else if (my_string_equal(option,"name")) { ASSERT(!my_string_empty(argument)); my_string_set(&uci->name,argument); } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); if (UseDebug) my_log("POLYGLOT engine name \"%s\" author \"%s\"\n",uci->name,uci->author); }
static void parse_score(uci_t * uci, const char string[]) { parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; int n; ASSERT(uci_is_ok(uci)); ASSERT(string!=NULL); // init strcpy(command,"score"); parse_open(parse,string); parse_add_keyword(parse,"cp"); parse_add_keyword(parse,"lowerbound"); parse_add_keyword(parse,"mate"); parse_add_keyword(parse,"upperbound"); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"cp")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); uci->score = n; } else if (my_string_equal(option,"lowerbound")) { ASSERT(my_string_empty(argument)); } else if (my_string_equal(option,"mate")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n!=0); uci->score = mate_score(n); } else if (my_string_equal(option,"upperbound")) { ASSERT(my_string_empty(argument)); } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); }
static void parse_option(uci_t * uci, const char string[]) { option_t * opt; parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; ASSERT(uci!=NULL); ASSERT(string!=NULL); // init strcpy(command,"option"); if (uci->option_nb >= OptionNb) return; opt = &uci->option[uci->option_nb]; uci->option_nb++; opt->value=NULL; my_string_set(&opt->value,"<empty>"); opt->mode=0; opt->name = NULL; my_string_set(&opt->name,"<empty>"); opt->default_ = NULL; my_string_set(&opt->default_,"<empty>"); opt->max = NULL; my_string_set(&opt->max,"<empty>"); opt->min = NULL; my_string_set(&opt->min,"<empty>"); opt->type = NULL; my_string_set(&opt->type,"<empty>"); opt->var_nb=0; parse_open(parse,string); parse_add_keyword(parse,"default"); parse_add_keyword(parse,"max"); parse_add_keyword(parse,"min"); parse_add_keyword(parse,"name"); parse_add_keyword(parse,"type"); parse_add_keyword(parse,"var"); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"default")) { // ASSERT(!my_string_empty(argument)); // HACK for Pepito if (!my_string_empty(argument)) { my_string_set(&opt->default_,argument); my_string_set(&opt->value,argument); } } else if (my_string_equal(option,"max")) { ASSERT(!my_string_empty(argument)); my_string_set(&opt->max,argument); } else if (my_string_equal(option,"min")) { ASSERT(!my_string_empty(argument)); my_string_set(&opt->min,argument); } else if (my_string_equal(option,"name")) { ASSERT(!my_string_empty(argument)); if (!my_string_empty(argument)) { my_string_set(&opt->name,argument); } } else if (my_string_equal(option,"type")) { ASSERT(!my_string_empty(argument)); my_string_set(&opt->type,argument); } else if (my_string_equal(option,"var")) { ASSERT(!my_string_empty(argument)); my_string_set(&opt->var[opt->var_nb++],argument); if(opt->var_nb==VarNb) break; } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); if (UseDebug) my_log("POLYGLOT option name \"%s\" default \"%s\"\n",opt->name,opt->default_); }
static int parse_info(uci_t * uci, const char string[]) { int event; parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; int n; int multipvline=0; sint64 ln; ASSERT(uci_is_ok(uci)); ASSERT(string!=NULL); // init event = EVENT_NONE; strcpy(command,"info"); parse_open(parse,string); parse_add_keyword(parse,"cpuload"); parse_add_keyword(parse,"currline"); parse_add_keyword(parse,"currmove"); parse_add_keyword(parse,"currmovenumber"); parse_add_keyword(parse,"depth"); parse_add_keyword(parse,"hashfull"); parse_add_keyword(parse,"multipv"); parse_add_keyword(parse,"nodes"); parse_add_keyword(parse,"nps"); parse_add_keyword(parse,"pv"); parse_add_keyword(parse,"refutation"); parse_add_keyword(parse,"score"); parse_add_keyword(parse,"seldepth"); parse_add_keyword(parse,"string"); parse_add_keyword(parse,"tbhits"); parse_add_keyword(parse,"time"); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"cpuload")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->cpu = double(n) / 1000.0; } else if (my_string_equal(option,"currline")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->current_line,uci->board,argument,LineSize); } else if (my_string_equal(option,"currmove")) { ASSERT(!my_string_empty(argument)); uci->root_move = move_from_can(argument,uci->board); ASSERT(uci->root_move!=MoveNone); } else if (my_string_equal(option,"currmovenumber")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=1&&n<=uci->root_move_nb); if (n >= 1 && n <= uci->root_move_nb) { uci->root_move_pos = n - 1; ASSERT(uci->root_move_pos>=0&&uci->root_move_pos<uci->root_move_nb); } } else if (my_string_equal(option,"depth")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=1); if (n >= 0) { if (n > uci->depth) event |= EVENT_DEPTH; uci->depth = n; } } else if (my_string_equal(option,"hashfull")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->hash = double(n) / 1000.0; } else if (my_string_equal(option,"multipv")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); if(Uci->multipv_mode) multipvline=n; ASSERT(n>=1); } else if (my_string_equal(option,"nodes")) { ASSERT(!my_string_empty(argument)); ln = my_atoll(argument); ASSERT(ln>=0); if (ln >= 0) uci->node_nb = ln; } else if (my_string_equal(option,"nps")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->speed = double(n); } else if (my_string_equal(option,"pv")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->pv,uci->board,argument,LineSize); event |= EVENT_PV; } else if (my_string_equal(option,"refutation")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->pv,uci->board,argument,LineSize); } else if (my_string_equal(option,"score")) { ASSERT(!my_string_empty(argument)); parse_score(uci,argument); } else if (my_string_equal(option,"seldepth")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->sel_depth = n; } else if (my_string_equal(option,"string")) { if(!strncmp(argument,"DrawOffer",9)) event |= EVENT_DRAW; if(!strncmp(argument,"Resign",6)) event |= EVENT_RESIGN; // TODO: argument to EOS ASSERT(!my_string_empty(argument)); } else if (my_string_equal(option,"tbhits")) { ASSERT(!my_string_empty(argument)); ln = my_atoll(argument); ASSERT(ln>=0); } else if (my_string_equal(option,"time")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->time = double(n) / 1000.0; } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); // update display //lousy uci,filter out lower depth multipv lines that have been repeated from the engine if(multipvline>1 && uci->depth<uci->best_depth) event &= ~EVENT_PV; if ((event & EVENT_PV) != 0) { uci->best_score = uci->score; uci->best_depth = uci->depth; if(multipvline==1)uci->depth=-1; //HACK ,clears the engine outpout window,see send_pv in adapter.cpp uci->best_sel_depth = uci->sel_depth; line_copy(uci->best_pv,uci->pv); } return event; }
static int parse_bestmove(uci_t * uci, const char string[]) { parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; board_t board[1]; ASSERT(uci_is_ok(uci)); ASSERT(string!=NULL); // init strcpy(command,"bestmove"); parse_open(parse,string); parse_add_keyword(parse,"ponder"); // bestmove if (!parse_get_string(parse,argument,StringSize)) { my_fatal("parse_bestmove(): missing argument\n"); } uci->best_move = move_from_can(argument,uci->board); if (uci->best_move == MoveNone) my_fatal("parse_bestmove(): not a move \"%s\"\n",argument); ASSERT(uci->best_move!=MoveNone); ASSERT(move_is_legal(uci->best_move,uci->board)); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"ponder")) { ASSERT(!my_string_empty(argument)); board_copy(board,uci->board); move_do(board,uci->best_move); uci->ponder_move = move_from_can(argument,board); // if (uci->ponder_move == MoveNone) my_fatal("parse_bestmove(): not a move \"%s\"\n",argument); ASSERT(uci->ponder_move!=MoveNone); ASSERT(move_is_legal(uci->ponder_move,board)); } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); return EVENT_MOVE; }
int uci_parse(uci_t * uci, const char string[]) { int event; parse_t parse[1]; char command[StringSize]; char argument[StringSize]; ASSERT(uci_is_ok(uci)); ASSERT(string!=NULL); // init event = EVENT_NONE; // parse parse_open(parse,string); if (parse_get_word(parse,command,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" ARGUMENT \"%s\"\n",command,argument); if (false) { } else if (my_string_equal(command,"bestmove")) { // search end ASSERT(uci->pending_nb>0); if (uci->searching && uci->pending_nb == 1) { // current search uci->searching = false; uci->pending_nb--; event = parse_bestmove(uci,argument); // updates uci->best_move and uci->ponder_move } else { // obsolete search if (uci->pending_nb > 0) { uci->pending_nb--; if (uci->pending_nb == 0) event = EVENT_STOP; } } } else if (my_string_equal(command,"id")) { parse_id(uci,argument); } else if (my_string_equal(command,"info")) { // search information if (uci->searching && uci->pending_nb == 1) { // current search event = parse_info(uci,argument); } } else if (my_string_equal(command,"option")) { parse_option(uci,argument); } else if (my_string_equal(command,"readyok")) { // engine is ready ASSERT(uci->ready_nb>0); if (uci->ready_nb > 0) { uci->ready_nb--; if (uci->ready_nb == 0) event = EVENT_READY; } } else if (my_string_equal(command,"uciok")) { event = EVENT_UCI; } else { if (UseDebug) my_log("POLYGLOT unknown command \"%s\"\n",command); } } parse_close(parse); return event; }
/** * Parse an RFC-822 style file. * * donep may be NULL. * If donep is not NULL only one package's information is expected. */ int parsedb(const char *filename, enum parsedbflags flags, struct pkginfo **donep) { struct pkgset tmp_set; struct pkginfo *new_pkg, *db_pkg; struct pkgbin *new_pkgbin, *db_pkgbin; struct pkg_parse_object pkg_obj; int fieldencountered[array_count(fieldinfos)]; int pdone; struct parsedb_state ps; struct field_state fs; memset(&fs, 0, sizeof(fs)); fs.fieldencountered = fieldencountered; parse_open(&ps, filename, flags); new_pkg = &tmp_set.pkg; if (flags & pdb_recordavailable) new_pkgbin = &new_pkg->available; else new_pkgbin = &new_pkg->installed; ps.pkg = new_pkg; ps.pkgbin = new_pkgbin; pkg_obj.pkg = new_pkg; pkg_obj.pkgbin = new_pkgbin; pdone= 0; /* Loop per package. */ for (;;) { memset(fieldencountered, 0, sizeof(fieldencountered)); pkgset_blank(&tmp_set); if (!parse_stanza(&ps, &fs, pkg_parse_field, &pkg_obj)) break; if (pdone && donep) parse_error(&ps, _("several package info entries found, only one allowed")); pkg_parse_verify(&ps, new_pkg, new_pkgbin); db_pkg = pkg_db_find_pkg(new_pkg->set->name, new_pkgbin->arch); if (flags & pdb_recordavailable) db_pkgbin = &db_pkg->available; else db_pkgbin = &db_pkg->installed; if ((flags & pdb_ignoreolder) && versioncompare(&new_pkgbin->version, &db_pkgbin->version) < 0) continue; pkg_parse_copy(&ps, db_pkg, db_pkgbin, new_pkg, new_pkgbin); if (donep) *donep = db_pkg; pdone++; if (parse_EOF(&ps)) break; } parse_close(&ps); varbuf_destroy(&fs.value); if (donep && !pdone) ohshit(_("no package information in `%.255s'"),filename); return pdone; }