return *p != start;
}
-int Match(char *pattern, char **ptr)
+inline int Match(char *pattern, char **ptr)
{
char *p = pattern, *s = *ptr;
while(*p && (*p == *s++ || s[-1] == '\r' && *p--)) p++;
return 0; // no match, no ptr update
}
-int Word(char *pattern, char **p)
+inline int Word(char *pattern, char **p)
{
if(Match(pattern, p)) return 1;
if(*pattern >= 'a' && *pattern <= 'z' && *pattern - **p == 'a' - 'A') { // capitalized
}
parseStart = oldp = *p; // remember where we begin
- // Next we do some common symbols where the first character commits us to things that cannot possibly be a move
- // (but not {} comments, as those force time-consuming matching of PGN results immediately after it)
-
- // ********* PGN tags ******************************************
- if(**p == '[') {
- oldp = ++(*p);
- if(Match("--", p)) { // "[--" could be start of position diagram
- if(!Scan(']', p) && (*p)[-3] == '-' && (*p)[-2] == '-') return PositionDiagram;
- *p = oldp;
- }
- SkipWhite(p);
- if(isdigit(**p) || isalpha(**p)) {
- do (*p)++; while(isdigit(**p) || isalpha(**p) || **p == '+' ||
- **p == '-' || **p == '=' || **p == '_' || **p == '#');
- SkipWhite(p);
- if(*(*p)++ == '"') {
- while(**p != '\n' && (*(*p)++ != '"'|| (*p)[-2] == '\\')); // look for unescaped quote
- if((*p)[-1] !='"') { *p = oldp; Scan(']', p); return Comment; } // string closing delimiter missing
- SkipWhite(p); if(*(*p)++ == ']') return PGNTag;
- }
- }
- Scan(']', p); return Comment;
- }
-
-
- // ********* variations (nesting) ******************************
- if(**p =='(') {
- if(RdTime(')', p)) return ElapsedTime;
- return Open;
- }
- if(**p ==')') { (*p)++; return Close; }
- if(**p == ';') { while(**p != '\n') (*p)++; return Comment; }
-
// ********* attempt to recognize a SAN move in the leading non-blank text *****
piece = separator = promoted = slash = n = 0;
&& (coord[0] != 14 || coord[2] != 14) /* reserve oo for castling! */ ) {
piece = 'P'; n = 4; // kludge alert: fake full to-square
}
- }
+ } else if(n == 1 && type[0] == NUMERIC && coord[0] > 1) { while(**p == '.') (*p)++; return Nothing; } // fast exit for move numbers
if(n == 4 && type[2] != type[3] && // we have a valid to-square (kludge: type[3] can be NOTHING on fxg type move)
(piece || !promoted) && // promoted indicator only valid on named piece type
(type[2] == ALPHABETIC || gameInfo.variant == VariantShogi)) { // in Shogi also allow alphabetic rank
}
}
badMove:// we failed to find algebraic move
+ *p = oldp;
+ // Next we do some common symbols where the first character commits us to things that cannot possibly be a move
+
+ // ********* PGN tags ******************************************
+ if(**p == '[') {
+ oldp = ++(*p);
+ if(Match("--", p)) { // "[--" could be start of position diagram
+ if(!Scan(']', p) && (*p)[-3] == '-' && (*p)[-2] == '-') return PositionDiagram;
+ *p = oldp;
+ }
+ SkipWhite(p);
+ if(isdigit(**p) || isalpha(**p)) {
+ do (*p)++; while(isdigit(**p) || isalpha(**p) || **p == '+' ||
+ **p == '-' || **p == '=' || **p == '_' || **p == '#');
+ SkipWhite(p);
+ if(*(*p)++ == '"') {
+ while(**p != '\n' && (*(*p)++ != '"'|| (*p)[-2] == '\\')); // look for unescaped quote
+ if((*p)[-1] !='"') { *p = oldp; Scan(']', p); return Comment; } // string closing delimiter missing
+ SkipWhite(p); if(*(*p)++ == ']') return PGNTag;
+ }
+ }
+ Scan(']', p); return Comment;
+ }
+
// ********* SAN Castings *************************************
- *p = oldp;
if(**p == 'O' || **p == 'o' || **p == '0') {
int castlingType = 0;
if(Match("O-O-O", p) || Match("o-o-o", p) || Match("0-0-0", p) ||
}
+ // ********* variations (nesting) ******************************
+ if(**p =='(') {
+ if(RdTime(')', p)) return ElapsedTime;
+ return Open;
+ }
+ if(**p ==')') { (*p)++; return Close; }
+ if(**p == ';') { while(**p != '\n') (*p)++; return Comment; }
+
+
// ********* Comments and result messages **********************
*p = oldp; commentEnd = NULL; result = 0;
if(**p == '{') {