/* 09_pgn_tags.c -- PGN header tags and writing a game score.
 *
 * Functions demonstrated:
 *   SANTagLocate() -- find a tag by name (e.g. "White", "Event")
 *   SANTagUpdate() -- change a tag's value
 *   SANPGNEventReport() -- write the current game (tags + move text)
 *                          as PGN to a FILE*
 *
 * The seven "Seven Tag Roster" fields required by the PGN standard
 * (Event, Site, Date, Round, White, Black, Result) already exist as
 * soon as SANInit() runs, pre-created with empty values; you only
 * need to fill them in. Extra, non-standard tags can be added with
 * SANTagCreate().
 */

#include "_common.h"

#include "sanint.h"
#include "sanmnd.h"
#include "sanmpu.h"
#include "santag.h"
#include "sanpgn.h"

static void
play (char *text)
{
  sanT buf;
  mptrT mptr;

  strncpy (buf, text, sanL - 1);
  buf[sanL - 1] = '\0';
  mptr = SANDecodeAux (buf);
  SANPlayMove (mptr);

  return;
}

static void
set_tag (char *name, char *value)
{
  tagptrT tagptr;

  tagptr = SANTagLocate (name);
  if (tagptr != NULL)
    SANTagUpdate (tagptr, value);

  return;
}

int
main (void)
{
  SANInit ();
  optnv[optn_nabd] = 1;
  optnv[optn_namd] = 1;

  play ("e4"); play ("c5"); play ("Nf3"); play ("d6");
  play ("d4"); play ("cxd4"); play ("Nxd4"); play ("Nf6");
  play ("Nc3");

  set_tag ("Event", "SAN Kit examples");
  set_tag ("Site", "?");
  set_tag ("Date", "????.??.??");
  set_tag ("Round", "9");
  set_tag ("White", "Example Program");
  set_tag ("Black", "Example Program");
  set_tag ("Result", "*");

  SANPGNEventReport (stdout);

  return (0);
}
