removed trailing whitespace
[xboard.git] / parser.c
index a0a7ad1..e0b4ff4 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1,7 +1,7 @@
 /*
  * parser.c --
  *
- * Copyright 2011, 2012 Free Software Foundation, Inc.
+ * Copyright 2011, 2012, 2013 Free Software Foundation, Inc.
  * ------------------------------------------------------------------------
  *
  * GNU XBoard is free software: you can redistribute it and/or modify
@@ -51,7 +51,8 @@ static char fromString = 0, lastChar = '\n';
 #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
@@ -66,7 +67,8 @@ int ReadLine()
     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;
@@ -75,7 +77,8 @@ int Scan(char c, char **p)
     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{
@@ -84,7 +87,8 @@ int SkipWhite(char **p)
     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++;
@@ -95,7 +99,8 @@ inline int Match(char *pattern, char **ptr)
     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
@@ -106,15 +111,16 @@ inline int Word(char *pattern, char **p)
     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 Number(char **p)
+int
+Number (char **p)
 {
     int val = 0;
     if(**p < '0' || **p > '9') return BADNUMBER;
@@ -124,7 +130,8 @@ int Number(char **p)
     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;
@@ -139,19 +146,21 @@ int RdTime(char c, char **p)
     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!
-    if(**p == '+' && gameInfo.variant == VariantShogi) { (*p)++; return '+'; } 
+    if(**p == '+' && gameInfo.variant == VariantShogi) { (*p)++; return '+'; }
     if(**p == '=' || (gameInfo.variant == VariantSChess) && **p == '/') (*p)++; // optional = (or / for Seirawan gating)
-    if(**p == '(' && (*p)[2] == ')' && isalpha( (*p)[1] )) { (*p) += 3; return (*p)[-2]; }
-    if(isalpha(**p)) return *(*p)++;
+    if(**p == '(' && (*p)[2] == ')' && isalpha( (*p)[1] )) { (*p) += 3; return ToLower((*p)[-2]); }
+    if(isalpha(**p)) return ToLower(*(*p)++);
     if(*p != start) return '='; // must be the optional =
     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;
@@ -211,10 +220,9 @@ int NextUnit(char **p)
            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 && 
+           if(piece && type[1] == NOTHING && type[0] == NUMERIC && type[2] == NUMERIC &&
                (separator == '+' || separator == '=' || separator == '-')) {
                     // Xiangqi traditional
 
@@ -326,7 +334,7 @@ badMove:// we failed to find algebraic move
        if(**p == '[') {
            oldp = ++(*p);
            if(Match("--", p)) { // "[--" could be start of position diagram
-               if(!Scan(']', p) && (*p)[-3] == '-' && (*p)[-2] == '-') return PositionDiagram; 
+               if(!Scan(']', p) && (*p)[-3] == '-' && (*p)[-2] == '-') return PositionDiagram;
                *p = oldp;
            }
            SkipWhite(p);
@@ -347,7 +355,7 @@ badMove:// we failed to find algebraic move
        // ********* SAN Castings *************************************
        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) || 
+           if(Match("O-O-O", p) || Match("o-o-o", p) || Match("0-0-0", p) ||
               Match("OOO", p) || Match("ooo", p) || Match("000", p)) castlingType = 2;
            else if(Match("O-O", p) || Match("o-o", p) || Match("0-0", p) ||
                    Match("OO", p) || Match("oo", p) || Match("00", p)) castlingType = 1;
@@ -533,12 +541,14 @@ badMove:// we failed to find algebraic move
 /*
     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
 }
 
-void yynewfile (FILE *f)
+void
+yynewfile (FILE *f)
 {   // 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
 }
 
-void yynewstr P((char *s))
+void
+yynewstr P((char *s))
 {
     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;
@@ -564,7 +576,8 @@ int yylex()
     return result;
 }
 
-int Myylex()
+int
+Myylex ()
 {   // [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;
 }
 
-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;
@@ -598,4 +612,3 @@ ChessMove yylexstr(int boardIndex, char *s, char *buf, int buflen)
     fromString = 0;
     return ret;
 }
-