Fix castling rights when copying FEN to clipboard (again)
[xboard.git] / parser.l
index 77837a7..d96b95a 100755 (executable)
--- a/parser.l
+++ b/parser.l
@@ -9,9 +9,10 @@
  * parser.l -- lex parser of algebraic chess moves for XBoard\r
  *\r
  * Copyright 1991 by Digital Equipment Corporation, Maynard,\r
- * Massachusetts.  Enhancements Copyright\r
- * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software\r
- * Foundation, Inc.\r
+ * Massachusetts.\r
+ *\r
+ * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005,\r
+ * 2006, 2007, 2008, 2009 Free Software Foundation, Inc.\r
  *\r
  * The following terms apply to Digital Equipment Corporation's copyright\r
  * interest in XBoard:\r
@@ -705,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
@@ -845,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
@@ -918,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
@@ -984,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
@@ -996,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