X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=parser.c;h=797a40cdda286f7fb40c889f51dcd0621f5b30b9;hb=v4.9.x;hp=8378132b9618e451bb333f9299ab9fe628f4e665;hpb=981710835fb91625593928380d26952642118781;p=xboard.git diff --git a/parser.c b/parser.c index 8378132..797a40c 100644 --- a/parser.c +++ b/parser.c @@ -172,7 +172,7 @@ unsigned char kanjiTab[] = { int NextUnit P((char **p)); -int kifu = 0; +int kifu = 0, xqUBB = 0; char GetKanji (char **p, int start) @@ -285,7 +285,7 @@ KifuMove (char **p) int ReadLine () { // Read one line from the input file, and append to the buffer - char c, *start = inPtr; + int c; char *start = inPtr; if(fromString) return 0; // parsing string, so the end is a hard end if(!inputFile) return 0; while((c = fgetc(inputFile)) != EOF) { @@ -426,6 +426,14 @@ NextUnit (char **p) if(q = strchr(s, **p)) (*p)++, piece += 64*(q - s + 1); if(**p == '/') slash = *(*p)++; } + + if(xqUBB) { // Xiangqi UBB movelist + while(isdigit(**p)) { + type[n] = NUMERIC; coord[n++] = *(*p)++ - '0'; + if(n >= 4) break; + } + if(n < 4) *p -= n, xqUBB = n = 0; else type[0] = type[2] = ALPHABETIC, coord[1] = 9 - coord[1], coord[3] = 9 - coord[3]; + } while(n < 4) { if(**p >= 'a' && **p < 'x') coord[n] = *(*p)++ - 'a', type[n++] = ALPHABETIC; else if((i = Number(p)) != BADNUMBER) coord[n] = i, type[n++] = NUMERIC; @@ -604,6 +612,13 @@ badMove:// we failed to find algebraic move *p = oldp; } SkipWhite(p); + if(Match("DhtmlXQ", p)) { // Xiangqi UBB tags + int res = Nothing; + if(**p == ']') strcpy(parseStart = yytext, "[Variant \"xiangqi\"]"), res = PGNTag; else + if(Match("_movelist", p)) xqUBB = 1; else Scan(']', p); + Scan(']', p); // for non-movelist tags this skips to the closing tag (disarming any enclosed kanji)! + return res; + } else if(Match("/DhtmlXQ", p)) { Scan(']', p); return Nothing; } if(isdigit(**p) || isalpha(**p)) { do (*p)++; while(isdigit(**p) || isalpha(**p) || **p == '+' || **p == '-' || **p == '=' || **p == '_' || **p == '#'); @@ -627,9 +642,12 @@ badMove:// we failed to find algebraic move Match("OO", p) || Match("oo", p) || Match("00", p)) castlingType = 1; if(castlingType) { //code from old parser, collapsed for both castling types, and streamlined a bit int rf, ff, rt, ft; ChessSquare king; - char promo=NULLCHAR; + char promo=NULLCHAR, gate = 0; - if(gameInfo.variant == VariantSChess) promo = PromoSuffix(p); + if(gameInfo.variant == VariantSChess) { + promo = PromoSuffix(p); + if(promo && **p >= 'a' && **p < AAA + BOARD_RGHT) gate = *(*p)++; + } if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */ @@ -665,6 +683,12 @@ badMove:// we failed to find algebraic move if (appData.debugMode) fprintf(debugFP, "Parser FRC (type=%d) %d %d\n", castlingType, ff, ft); if(ff == NoRights || ft == NoRights) return ImpossibleMove; } + if(gate) { // gating disambiguator present + if(gate != ff + AAA) { + int h = ft; ft = ff; ff = h; // reverse for gating at Rook square + if(gate != AAA + initialRights[castlingType+(wom?-1:2)]) return ImpossibleMove; + } + } sprintf(currentMoveString, "%c%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE,promo); if (appData.debugMode) fprintf(debugFP, "(%d-type) castling %d %d\n", castlingType, ff, ft);