/*
 * Revision Control Information
 *
 * $Source$
 * $Author$
 * $Revision$
 * $Date$
 *
 */
/*
 *  Main driver for espresso
 *
 *  Old style -do xxx, -out xxx, etc. are still supported.
 */

#include "espresso.h"
#include "main.h"		/* table definitions for options */
#include "espresso_include.h"

static FILE *last_fp;
static int input_type = FD_type;


__declspec(dllexport) int __cdecl minimalizace_espresso(char* inputfile,char* outfilename)
{
    int  first, last, strategy, out_type, option;
    pPLA PLA;
    bool error, exact_cover;
    extern char *optarg;
    extern int optind;
	FILE * outfile;	
	FILE * infile;
    error = FALSE;
 
#ifdef RANDOM
    srandom(314973);
#endif

	optind=2;
    option = 0;			/* default -D: ESPRESSO */
    out_type = F_type;		/* default -o: default is ON-set only */
    debug = 0;			/* default -d: no debugging info */
    verbose_debug = FALSE;	/* default -v: not verbose */
	print_solution = FALSE;	/* default -x: print the solution (!) */
    summary = FALSE;		/* default -s: no summary */
    trace = FALSE;		/* default -t: no trace information */
    strategy = 0;		/* default -S: strategy number */
    first = -1;			/* default -R: select range */
    last = -1;
    remove_essential = TRUE;	/* default -e: */
    force_irredundant = TRUE;
    unwrap_onset = TRUE;
    single_expand = FALSE;
    pos = FALSE;
    recompute_onset = FALSE;
    use_super_gasp = FALSE;
    use_random_order = FALSE;
    kiss = FALSE;
    echo_comments = TRUE;
    echo_unknown_commands = TRUE;
    exact_cover = FALSE;	/* for -qm option, the default */
    PLA = NIL(PLA_t);
    
	if ((infile = fopen(inputfile, "r")) == NULL) {
	    fprintf(stderr, "Espresso: Unable to open %s\n", inputfile);
	    return(1);
    }
    if (read_pla(infile, TRUE, TRUE, input_type, &PLA) == EOF) {
	fprintf(stderr, "Espresso: Unable to find PLA on file %s\n", inputfile);
	return(1);
    }
    PLA->filename = util_strsav(inputfile);
    filename = PLA->filename;
    (void) fclose(infile);

	
	PLA->F = espresso(PLA->F, PLA->D, PLA->R);

	outfile=fopen(outfilename, "w" );
	fprint_pla(outfile, PLA, out_type);
	(void) fclose(outfile);

    free_PLA(PLA);
    FREE(cube.part_size);
    setdown_cube();             /* free the cube/cdata structure data */
    sf_cleanup();               /* free unused set structures */
    sm_cleanup();               /* sparse matrix cleanup */
	return 0;
}