projects
/
xboard.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Switch to use of short menu references
[xboard.git]
/
parser.c
diff --git
a/parser.c
b/parser.c
index
a0a7ad1
..
c195d7e
100644
(file)
--- a/
parser.c
+++ b/
parser.c
@@
-51,7
+51,8
@@
static char fromString = 0, lastChar = '\n';
#define ALPHABETIC 2
#define BADNUMBER (-2000000000)
#define ALPHABETIC 2
#define BADNUMBER (-2000000000)
-int ReadLine()
+int
+ReadLine ()
{ // Read one line from the input file, and append to the buffer
char c, *start = inPtr;
if(fromString) return 0; // parsing string, so the end is a hard end
{ // Read one line from the input file, and append to the buffer
char c, *start = inPtr;
if(fromString) return 0; // parsing string, so the end is a hard end
@@
-66,7
+67,8
@@
int ReadLine()
return 1;
}
return 1;
}
-int Scan(char c, char **p)
+int
+Scan (char c, char **p)
{ // line-spanning skip to mentioned character or EOF
do {
while(**p) if(*(*p)++ == c) return 0;
{ // line-spanning skip to mentioned character or EOF
do {
while(**p) if(*(*p)++ == c) return 0;
@@
-75,7
+77,8
@@
int Scan(char c, char **p)
return 1;
}
return 1;
}
-int SkipWhite(char **p)
+int
+SkipWhite (char **p)
{ // skip spaces tabs and newlines; return 1 if anything was skipped
char *start = *p;
do{
{ // skip spaces tabs and newlines; return 1 if anything was skipped
char *start = *p;
do{
@@
-84,7
+87,8
@@
int SkipWhite(char **p)
return *p != start;
}
return *p != start;
}
-inline 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++;
{
char *p = pattern, *s = *ptr;
while(*p && (*p == *s++ || s[-1] == '\r' && *p--)) p++;
@@
-95,7
+99,8
@@
inline int Match(char *pattern, char **ptr)
return 0; // no match, no ptr update
}
return 0; // no match, no ptr update
}
-inline 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
{
if(Match(pattern, p)) return 1;
if(*pattern >= 'a' && *pattern <= 'z' && *pattern - **p == 'a' - 'A') { // capitalized
@@
-106,15
+111,16
@@
inline int Word(char *pattern, char **p)
return 0;
}
return 0;
}
-int Verb(char *pattern, char **p)
+int
+Verb (char *pattern, char **p)
{
int res = Word(pattern, p);
if(res && !Match("s", p)) Match("ed", p); // eat conjugation suffix, if any
return res;
}
{
int res = Word(pattern, p);
if(res && !Match("s", p)) Match("ed", p); // eat conjugation suffix, if any
return res;
}
-
-
int Number
(char **p)
+int
+
Number
(char **p)
{
int val = 0;
if(**p < '0' || **p > '9') return BADNUMBER;
{
int val = 0;
if(**p < '0' || **p > '9') return BADNUMBER;
@@
-124,7
+130,8
@@
int Number(char **p)
return val;
}
return val;
}
-int RdTime(char c, char **p)
+int
+RdTime (char c, char **p)
{
char *start = ++(*p), *sec; // increment *p, as it was pointing to the opening ( or {
if(Number(p) == BADNUMBER) return 0;
{
char *start = ++(*p), *sec; // increment *p, as it was pointing to the opening ( or {
if(Number(p) == BADNUMBER) return 0;
@@
-139,7
+146,8
@@
int RdTime(char c, char **p)
return 0;
}
return 0;
}
-char PromoSuffix(char **p)
+char
+PromoSuffix (char **p)
{
char *start = *p;
if(**p == 'e' && (Match("ep", p) || Match("e.p.", p))) { *p = start; return NULLCHAR; } // non-compliant e.p. suffix is no promoChar!
{
char *start = *p;
if(**p == 'e' && (Match("ep", p) || Match("e.p.", p))) { *p = start; return NULLCHAR; } // non-compliant e.p. suffix is no promoChar!
@@
-151,7
+159,8
@@
char PromoSuffix(char **p)
return NULLCHAR; // no suffix detected
}
return NULLCHAR; // no suffix detected
}
-int NextUnit(char **p)
+int
+NextUnit (char **p)
{ // Main parser routine
int coord[4], n, result, piece, i;
char type[4], promoted, separator, slash, *oldp, *commentEnd, c;
{ // Main parser routine
int coord[4], n, result, piece, i;
char type[4], promoted, separator, slash, *oldp, *commentEnd, c;
@@
-211,7
+220,6
@@
int NextUnit(char **p)
type[1] = NOTHING; // disambiguator goes in first two positions
n = 4;
}
type[1] = NOTHING; // disambiguator goes in first two positions
n = 4;
}
-if(appData.debugMode)fprintf(debugFP, "trial %d,%d,%d,%d type %d%d%d%d\n", coord[0], coord[1], coord[2], coord[3], type[0], type[1], type[2], type[3]);
// we always get here; move must be completely read now, with to-square coord(s) at end
if(n == 3) { // incomplete to-square. Could be Xiangqi traditional, or stuff like fxg
if(piece && type[1] == NOTHING && type[0] == NUMERIC && type[2] == NUMERIC &&
// we always get here; move must be completely read now, with to-square coord(s) at end
if(n == 3) { // incomplete to-square. Could be Xiangqi traditional, or stuff like fxg
if(piece && type[1] == NOTHING && type[0] == NUMERIC && type[2] == NUMERIC &&
@@
-533,12
+541,14
@@
badMove:// we failed to find algebraic move
/*
Return offset of next pattern in the current file.
*/
/*
Return offset of next pattern in the current file.
*/
-int yyoffset()
+int
+yyoffset ()
{
return ftell(inputFile) - (inPtr - parsePtr); // subtract what is read but not yet parsed
}
{
return ftell(inputFile) - (inPtr - parsePtr); // subtract what is read but not yet parsed
}
-void yynewfile (FILE *f)
+void
+yynewfile (FILE *f)
{ // prepare parse buffer for reading file
inputFile = f;
inPtr = parsePtr = inputBuf;
{ // prepare parse buffer for reading file
inputFile = f;
inPtr = parsePtr = inputBuf;
@@
-547,14
+557,16
@@
void yynewfile (FILE *f)
*inPtr = NULLCHAR; // make sure we will start by reading a line
}
*inPtr = NULLCHAR; // make sure we will start by reading a line
}
-void yynewstr P((char *s))
+void
+yynewstr P((char *s))
{
parsePtr = s;
inputFile = NULL;
fromString = 1;
}
{
parsePtr = s;
inputFile = NULL;
fromString = 1;
}
-int yylex()
+int
+yylex ()
{ // this replaces the flex-generated parser
int result = NextUnit(&parsePtr);
char *p = parseStart, *q = yytext;
{ // this replaces the flex-generated parser
int result = NextUnit(&parsePtr);
char *p = parseStart, *q = yytext;
@@
-564,7
+576,8
@@
int yylex()
return result;
}
return result;
}
-int Myylex()
+int
+Myylex ()
{ // [HGM] wrapper for yylex, which treats nesting of parentheses
int symbol, nestingLevel = 0, i=0;
char *p;
{ // [HGM] wrapper for yylex, which treats nesting of parentheses
int symbol, nestingLevel = 0, i=0;
char *p;
@@
-584,7
+597,8
@@
int Myylex()
return symbol;
}
return symbol;
}
-ChessMove yylexstr(int boardIndex, char *s, char *buf, int buflen)
+ChessMove
+yylexstr (int boardIndex, char *s, char *buf, int buflen)
{
ChessMove ret;
char *savPP = parsePtr;
{
ChessMove ret;
char *savPP = parsePtr;
@@
-598,4
+612,3
@@
ChessMove yylexstr(int boardIndex, char *s, char *buf, int buflen)
fromString = 0;
return ret;
}
fromString = 0;
return ret;
}
-