Fix 'mamer bug' in Chat Boxes
[xboard.git] / parser.l
index 82957eb..d3585c7 100755 (executable)
--- a/parser.l
+++ b/parser.l
@@ -12,7 +12,7 @@
  * Massachusetts.\r
  *\r
  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005,\r
- * 2006, 2007, 2008, 2009 Free Software Foundation, Inc.\r
+ * 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.\r
  *\r
  * The following terms apply to Digital Equipment Corporation's copyright\r
  * interest in XBoard:\r
@@ -317,7 +317,7 @@ extern void CopyBoard P((Board to, Board from));
     if (currentMoveString[4] == NULLCHAR &&\r
         (result == WhitePromotionKnight || result == BlackPromotionKnight ||\r
          result == WhitePromotionQueen  || result == BlackPromotionQueen)) {\r
-        if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier)\r
+        if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)\r
             currentMoveString[4] = PieceToChar(BlackFerz);\r
         else if(gameInfo.variant == VariantGreat)\r
             currentMoveString[4] = PieceToChar(BlackMan);\r
@@ -505,7 +505,7 @@ extern void CopyBoard P((Board to, Board from));
          result == WhitePromotionKnight || result == BlackPromotionKnight)) {\r
         currentMoveString[4] = PieceToChar(BlackQueen);\r
        // [HGM] shatranj: take care of variants without Queen\r
-       if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier)\r
+       if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)\r
             currentMoveString[4] = PieceToChar(BlackFerz);\r
        if(gameInfo.variant == VariantGreat)\r
             currentMoveString[4] = PieceToChar(BlackMan);\r
@@ -698,7 +698,7 @@ extern void CopyBoard P((Board to, Board from));
             ft = BOARD_LEFT+2;\r
        }\r
     }\r
-    if(gameInfo.variant == VariantFischeRandom) {\r
+    if(PosFlags(0) & F_FRC_TYPE_CASTLING) {
         if (WhiteOnMove(yyboardindex)) {\r
             ff = initialRights[2];\r
             ft = initialRights[1];\r
@@ -706,7 +706,10 @@ extern void CopyBoard P((Board to, Board from));
             ff = initialRights[5];\r
             ft = initialRights[4];\r
         }\r
-        fprintf(debugFP, "Parser FRC long %d %d\n", ff, ft);\r
+        if (appData.debugMode) \r
+        {\r
+          fprintf(debugFP, "Parser FRC long %d %d\n", ff, ft);\r
+        };\r
         if(ff < 0 || ft < 0) return 0;\r
     }\r
     sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE);\r
@@ -752,7 +755,7 @@ extern void CopyBoard P((Board to, Board from));
             ft = BOARD_RGHT-2;\r
        }\r
     }\r
-    if(gameInfo.variant == VariantFischeRandom) {\r
+    if(PosFlags(0) & F_FRC_TYPE_CASTLING) {
         if (WhiteOnMove(yyboardindex)) {\r
             ff = initialRights[2];\r
             ft = initialRights[0];\r
@@ -846,11 +849,11 @@ extern void CopyBoard P((Board to, Board from));
     return (int) GameIsDrawn;\r
 }\r
 \r
-(([Ww](hite)?)|([Bb](lack)?))" "([Mm]ate(s|ed)?)|([Ww][io]n(s)?.*)  {\r
+(([Ww](hite)?)|([Bb](lack)?))" "(([Mm]ates)|([Ww][io]n(s)?)) { \r
     return (int) (ToUpper(yytext[0]) == 'W' ? WhiteWins : BlackWins);\r
 }\r
 \r
-(([Ww](hite)?)|([Bb](lack)?))" "([Mm]ate(s|ed)?)|([Ll]os[tes]+.*)  {\r
+(([Ww](hite)?)|([Bb](lack)?))" "(([Mm]ated)|([Ll]os[tes]+)) { \r
     return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins);\r
 }\r
 \r
@@ -919,7 +922,7 @@ extern void CopyBoard P((Board to, Board from));
     return (int) Comment; \r
 }\r
 \r
-\([^()]*(\([^()]*\)[^()]*)+[^()]*\)  {                 /* nested () */\r
+\([^()]*(\([^()]*(\([^()]*(\([^()]*\)[^()]*)*\)[^()]*)*\)[^()]*)+[^()]*\)  { /* very nested () */\r
     return (int) Comment; \r
 }\r
 \r
@@ -985,7 +988,7 @@ int yyoffset()
 static void output(ch)\r
      int ch;\r
 {\r
-    fprintf(stderr, "PARSER BUG: unmatched character '%c' (0%o)\n",\r
+    if(appData.debugMode) fprintf(debugFP, "PARSER BUG: unmatched character '%c' (0%o)\n",\r
            ch, ch);\r
 }\r
 \r
@@ -997,7 +1000,7 @@ static void unput(ch)
        StringToLex--;\r
     } else {\r
        if (unputCount >= UNPUT_BUF_SIZE)\r
-         fprintf(stderr, "PARSER BUG: unput buffer overflow '%c' (0%o)\n",\r
+         if(appData.debugMode) fprintf(debugFP, "PARSER BUG: unput buffer overflow '%c' (0%o)\n",\r
                  ch, ch);\r
        unputBuffer[unputCount++] = ch;\r
     }\r