#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "d5.h"

#define BUFFERLEN 4096

void dointeractive(void);

/*============================================================
main
============================================================*/
int main(int argc, char *argv[])
{
D5_Puzzle puzzle;

if (argc<2)
  {
  dointeractive();
  return 1;
  }

puzzle=D5_createPuzzle();
D5_setCipherString(puzzle,argv[1]);
if (argc>2)
  D5_setClueString(puzzle,argv[2]);
else
  D5_setClueString(puzzle,"");

D5_letterAnalyze(puzzle);
D5_sortWords(puzzle);
D5_wordSolve(puzzle);

return 0;
}

/*============================================================
dointeractive
============================================================*/
void dointeractive(void)
{
D5_Puzzle puzzle;
char	buffer[BUFFERLEN];

puzzle=D5_createPuzzle();

printf("%s\n",D5_COPYRIGHTSTRING);

printf("Enter the puzzle:\n");
gets(buffer);
D5_setCipherString(puzzle, buffer);

printf("Enter any clues in the format \"A=E B=D\", etc.:\n");
gets(buffer);
D5_setClueString(puzzle, buffer);

printf("Entropy 1: %f\n",D5_getEstimatedEntropy(puzzle));
D5_letterAnalyze(puzzle);
printf("Entropy 2: %f\n",D5_getEstimatedEntropy(puzzle));
D5_sortWords(puzzle);
D5_wordSolve(puzzle);
printf("Entropy Actual: %f\n",D5_getActualEntropy(puzzle));

}
