Allow arbitrary nesting of sub-variations in PGN input
[xboard.git] / pgntags.c
index 6317c8b..202b0d9 100644 (file)
--- a/pgntags.c
+++ b/pgntags.c
@@ -1,23 +1,25 @@
 /*
  * pgntags.c -- Functions to manage PGN tags
- * XBoard $Id: pgntags.c,v 2.1 2003/10/27 19:21:00 mann Exp $
  *
- * Copyright 1995 Free Software Foundation, Inc.
+ * Copyright 1995, 2009, 2010 Free Software Foundation, Inc.
+ *
+ * Enhancements Copyright 2005 Alessandro Scotti
  *
  * ------------------------------------------------------------------------
- * This program is free software; you can redistribute it and/or modify
+ *
+ * GNU XBoard is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * GNU XBoard is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+ * along with this program. If not, see http://www.gnu.org/licenses/.  *
+ *
  * ------------------------------------------------------------------------
  *
  * This file could well be a part of backend.c, but I prefer it this
@@ -105,6 +107,10 @@ int ParsePGNTag(tag, gameInfo)
        else
            gameInfo->result = GameUnfinished;
        success = TRUE;
+    } else if (StrCaseCmp(name, "TimeControl") == 0) {
+//     int tc, mps, inc = -1;
+//     if(sscanf(value, "%d/%d", &mps, &tc) == 2 || )
+       success = StrSavePtr(value, &gameInfo->timeControl) != NULL;
     } else if (StrCaseCmp(name, "FEN") == 0) {
        success = StrSavePtr(value, &gameInfo->fen) != NULL;
     } else if (StrCaseCmp(name, "SetUp") == 0) {
@@ -149,41 +155,41 @@ static char *PGNTagsStatic(gameInfo)
 
     buf[0] = NULLCHAR;
 
-    sprintf(buf1, "[Event \"%s\"]\n",
+    snprintf(buf1, MSG_SIZ, "[Event \"%s\"]\n",
            gameInfo->event ? gameInfo->event : "?");
     strcat(buf, buf1);
-    sprintf(buf1, "[Site \"%s\"]\n",
+    snprintf(buf1, MSG_SIZ, "[Site \"%s\"]\n",
            gameInfo->site ? gameInfo->site : "?");
     strcat(buf, buf1);
-    sprintf(buf1, "[Date \"%s\"]\n",
+    snprintf(buf1, MSG_SIZ, "[Date \"%s\"]\n",
            gameInfo->date ? gameInfo->date : "?");
     strcat(buf, buf1);
-    sprintf(buf1, "[Round \"%s\"]\n",
+    snprintf(buf1, MSG_SIZ, "[Round \"%s\"]\n",
            gameInfo->round ? gameInfo->round : "-");
     strcat(buf, buf1);
-    sprintf(buf1, "[White \"%s\"]\n",
+    snprintf(buf1, MSG_SIZ, "[White \"%s\"]\n",
            gameInfo->white ? gameInfo->white : "?");
     strcat(buf, buf1);
-    sprintf(buf1, "[Black \"%s\"]\n",
+    snprintf(buf1, MSG_SIZ, "[Black \"%s\"]\n",
            gameInfo->black ? gameInfo->black : "?");
     strcat(buf, buf1);
-    sprintf(buf1, "[Result \"%s\"]\n", PGNResult(gameInfo->result));
+    snprintf(buf1, MSG_SIZ, "[Result \"%s\"]\n", PGNResult(gameInfo->result));
     strcat(buf, buf1);
+
     if (gameInfo->whiteRating >= 0 ) {
-       sprintf(buf1, "[WhiteElo \"%d\"]\n", gameInfo->whiteRating );
+       snprintf(buf1, MSG_SIZ, "[WhiteElo \"%d\"]\n", gameInfo->whiteRating );
        strcat(buf, buf1);
     }
     if ( gameInfo->blackRating >= 0 ) {
-       sprintf(buf1, "[BlackElo \"%d\"]\n", gameInfo->blackRating );
+       snprintf(buf1, MSG_SIZ, "[BlackElo \"%d\"]\n", gameInfo->blackRating );
        strcat(buf, buf1);
-    }    
+    }
     if (gameInfo->timeControl != NULL) {
-       sprintf(buf1, "[TimeControl \"%s\"]\n", gameInfo->timeControl);
+       snprintf(buf1, MSG_SIZ, "[TimeControl \"%s\"]\n", gameInfo->timeControl);
        strcat(buf, buf1);
     }
     if (gameInfo->variant != VariantNormal) {
-        sprintf(buf1, "[Variant \"%s\"]\n", VariantName(gameInfo->variant));
+        snprintf(buf1, MSG_SIZ, "[Variant \"%s\"]\n", VariantName(gameInfo->variant));
        strcat(buf, buf1);
     }
     if (gameInfo->extraTags != NULL) {
@@ -193,7 +199,7 @@ static char *PGNTagsStatic(gameInfo)
 }
 
 
+
 /* Print game info
  */
 void PrintPGNTags(fp, gameInfo)
@@ -229,7 +235,7 @@ char *PGNResult(result)
       case GameIsDrawn:
        return "1/2-1/2";
     }
-}  
+}
 
 /* Returns 0 for success, nonzero for error */
 int
@@ -244,13 +250,13 @@ ReplaceTags(tags, gameInfo)
     yynewstr(tags);
     for (;;) {
        yyboardindex = 0;
-       moveType = (ChessMove) yylex();
+       moveType = (ChessMove) Myylex();
        if (moveType == (ChessMove) 0) {
            break;
        } else if (moveType == PGNTag) {
            err = ParsePGNTag(yy_text, gameInfo);
            if (err != 0) return err;
-       } 
+       }
     }
     /* just one problem...if there is a result in the new tags,
      * DisplayMove() won't ever show it because ClearGameInfo() set