/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * This file is part of SanKit -- A multiplatform set of C code
 * for reading and writing PGN formatted chess games. In addition
 * it can be used as an engine to determine in real time if proposed
 * moves are legal or not. It appears to generate near perfect PGN
 * from incorrectly formatted files.
 *
 * Copyright 2012 David Hoerl All Rights Reserved.
 *
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>

extern "C"
{
	#include "sandef.h"
	#include "sanmnd.h"
	#include "sanvar.h"

	#include "sanint.h"
	#include "sandci.h"
	#include "sanmpu.h"
	#include "santrm.h"

	#include "sanenu.h"

	#include "sanutl.h"
	#include "sanpgn.h"

	#include "sanrdr.h"
	#include "santag.h"

	#include "sangtc.h"
}

#include "CompareFiles.h"

using namespace std;

int main (int argc, const char *argv[])
{
	if(argc != 3) {
		fprintf(stderr, "%s usage: %s input_file result_file\n", argv[0], argv[0]);
		exit(1);
	}

	const char *boards = "/tmp/PGNmoves.txt";
    SANInit();

    optnv[optn_nabd] = 0;	// no auto board display
    optnv[optn_namd] = 1;	// no auto move display
    optnv[optn_napr] = 1;	// no auto program reply
    optnv[optn_emde] = 1;	// extraordinary move disambiguation effort

	siT count = 0;
	siptrT countP = &count;
	
	unlink(boards);
	do_fptr = fopen(boards, "w");
	st_fptr = NULL;

	assert(do_fptr);

	SANRGSetGRTM(grtm_pgn);	// tell it we want PGN
	siT i = SANRGMultiple((const charptrT)argv[1], (const charptrT)argv[2], countP);
	fclose(do_fptr), do_fptr = NULL;

	if(i) {
		CompareFilesPGN cp(argv[1], argv[2], boards);
		if(cp.Compare()) {
			printf("Successful compared %u games\n\n", cp.GetGameCount());
		}
		string ret = cp.GetResults();
		printf("%s\n", ret.c_str());
	} else {
		printf("Error: failed after game %u at this line %s.\n", gameCount, parseError);
	}

	return 0;
}

