// this is UNSUPPORTED code to provide a front-end to findmoves.c
// I strongly recommend a rewrite, but I'm putting it online as
// a help to anyone who wants to hook these engines into a web site...
// - graham toal 13Jul03
//
// The master copy is in /usr/local/apache2/cgi-src/bsdi/
// The other version of this file, "allmoves.c" is the stable
// working version before I started to make it more 8-bit clean.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <locale.h>
#include "cgi_c/www.h"

#include "global_analysis/latin1.c"

#define TRUE (0==0)
#define FALSE (0!=0)

static char saved[15][15];
static char rack1[7];
/*static char rack2[7];*/
static int score = 0;
static int remaining = 0;
static long thisrand = 10000L;
#define DEFDICT "SAOL"
static char *dict = DEFDICT;

const char *dicts[] = {
"SAOL",
/* only foreign languages which use A-Z for now... */
NULL
};

const char premium[6] = {
/*  "star", "empty", "double", "triplet", "doublwrd", "triplwrd"*/
/*  "dws", "sq", "dls", "tls", "dws", "tws" */
'+', '.', '-', '=', '+', '#'
};

const int premiums[15][15] = {
{5,1,1,2,1,1,1,5,1,1,1,2,1,1,5},
{1,4,1,1,1,3,1,1,1,3,1,1,1,4,1},
{1,1,4,1,1,1,2,1,2,1,1,1,4,1,1},
{2,1,1,4,1,1,1,2,1,1,1,4,1,1,2},
{1,1,1,1,4,1,1,1,1,1,4,1,1,1,1},
{1,3,1,1,1,3,1,1,1,3,1,1,1,3,1},
{1,1,2,1,1,1,2,1,2,1,1,1,2,1,1},
{5,1,1,2,1,1,1,0,1,1,1,2,1,1,5},
{1,1,2,1,1,1,2,1,2,1,1,1,2,1,1},
{1,3,1,1,1,3,1,1,1,3,1,1,1,3,1},
{1,1,1,1,4,1,1,1,1,1,4,1,1,1,1},
{2,1,1,4,1,1,1,2,1,1,1,4,1,1,2},
{1,1,4,1,1,1,2,1,2,1,1,1,4,1,1},
{1,4,1,1,1,3,1,1,1,3,1,1,1,4,1},
{5,1,1,2,1,1,1,5,1,1,1,2,1,1,5}
};

char *safedict(char *s)
{
  int i = 0;
  for (;;) {
    if (dicts[i] == NULL) break;
    if (strcmp(dicts[i], s) == 0) return(s);
    i += 1;
  }
  return(DEFDICT);
}

long getseq(void)
{
  int rc;
  long seq = 10000L;
  FILE *seqfile = fopen("/home/gtoal/public_html/scrabble/boardgen/SEQNO", "r");

  if (seqfile == NULL) {
    return(random() & 65535L);
  } else {
    /* read seq from file */
    rc = fscanf(seqfile, "%ld", &seq);
    fclose(seqfile);
    seqfile = fopen("/home/gtoal/public_html/scrabble/boardgen/SEQNO", "w");
    /* write seq to file */
    fprintf(seqfile, "%0ld\n", seq+1L);
    fclose(seqfile);
    if (rc == 1) {
      return(seq);
    } else return(random() & 65535L);
  }
}

void generate_graphic(char saved[15][15], char *format)
{
  int x,y;
  int pass;
  FILE *outf, *commfile;
  char *NL, *GT, *LT;
  char *path = "/usr/local/bin/";

  remove("/tmp/SCRABBLEBOARD");
  commfile = fopen("/tmp/SCRABBLEBOARD", "w");
  if (commfile == NULL) {
    fprintf(stdout, "ERROR: Cannot generate script file /tmp/SCRABBLEBOARD - %s<BR>\n",
      strerror(errno));
    return;
  }
  thisrand = getseq();
  for (pass = 1; pass >= 0; --pass) {
    if (pass == 0) {
      NL = "<BR>";
      GT = "&gt;";
      LT = "&lt;";
      outf = stdout;
    } else {
      NL = "";
      GT = ">";
      LT = "<";
      outf = commfile;
    }
    if (pass == 0) fprintf(outf, "<!--\n");
    fprintf(outf, "#!/bin/sh%s\n", NL);
    fprintf(outf, "cd /home/gtoal/public_html/scrabble/in-progress/png\n", NL);
    fprintf(outf, "cat %s /home/gtoal/public_html/scrabble/boardgen/temp/wsc_%0ld.dat %s%sEOD%s\n", GT, thisrand, LT, LT, NL);
    for (y = 0; y < 15; y++) {
      for (x = 
0; x < 15; x++) {
        if (latin1_isalpha(saved[x][y])) {
          if (latin1_islower(saved[x][y])) {
            fprintf(outf, "%c", latin1_toupper(saved[x][y]));
	  } else {
            fprintf(outf, "%c", latin1_tolower(saved[x][y]));
	  }
        } else {
          fprintf(outf, "%c", premium[premiums[x][y]]);
        }
      }
      fprintf(outf, "%s\n", NL);
    }

    for (x = 0; x < 7; x++) {
      if (latin1_isalpha(rack1[x])) {
        fprintf(outf, "%c", latin1_toupper(rack1[x]));
      } else if (rack1[x] == '?') {
        fprintf(outf, "*");
      } else if (rack1[x] == ' ') {
        fprintf(outf, "?");
      }
    }

/***
    fprintf(outf, "?");

    for (x = 0; x < 7; x++) {
      if (latin1_isalpha(rack2[x])) {
        fprintf(outf, "%c", latin1_toupper(rack2[x]));
      } else if (rack2[x] == '?') {
        fprintf(outf, "_");
      } else if (rack2[x] == ' ') {
      }
    }
***/

    /* Add score and tiles left (0 prints as nothing) */

    fprintf(outf, " %d %d%s\n", score, remaining, NL);
    fprintf(outf, "EOD%s\n", NL);
    fprintf(outf,
      "./wsc_png /home/gtoal/public_html/scrabble/boardgen/temp/wsc_%0ld.dat /home/gtoal/public_html/scrabble/boardgen/temp/wsc_%0ld.png %s\n",
      thisrand, thisrand, NL);
      /* Find all plays! */

    /* print board */
    if (pass == 0) {
      char command[1024];
      fprintf(stdout, "\n-->\n<IMG SRC='http://www.gtoal.com/wordgames/boardgen/temp/wsc_%0ld.png'>%s\n", thisrand, NL);
      fprintf(stdout, "<H2>Here are all the possible plays on this board:</H2>\n<PRE>");
      fflush(stdout);
      sprintf(command,
        "/home/gtoal/public_html/scrabble/scrabble_solver/findmoves /home/gtoal/public_html/scrabble/boardgen/temp/wsc_%0ld.dat %s",
        thisrand, safedict(dict));
      system(command);
      fflush(stdout);
      fprintf(stdout, "</PRE>\n");
      fprintf(stdout,
        "You can bookmark these results at <A HREF=\"http://www.gtoal.com/cgi-bin/allmoves-latin1?savedgame=%0ld\">http://www.gtoal.com/cgi-bin/allmoves-latin1?savedgame=%0ld</A><BR>\n",
        thisrand, thisrand);
      fflush(stdout);
    }

    fflush(outf);
    if (pass == 1) {
      char cline[256];
      fclose(commfile);
      /* Execute the batch file now */
      fprintf(stdout, "\n<PRE>\n");
      fflush(stdout);
      remove("/tmp/SCRABBLELOG");
      system("/bin/chmod +x /tmp/SCRABBLEBOARD");
      system("/bin/sh -x < /tmp/SCRABBLEBOARD > /tmp/SCRABBLELOG 2>&1");
      system("/bin/chmod 777 /tmp/SCRABBLELOG");
      sprintf(cline, "/bin/rm /home/gtoal/public_html/scrabble/boardgen/temp/sc%0ld-*.pnm", thisrand);
/*      system(cline);*/
      sprintf(cline, "/bin/rm /home/gtoal/public_html/scrabble/boardgen/temp/ra%0ld*.pnm", thisrand);
/*      system(cline);*/
      fflush(stdout);
      fprintf(stdout, "\n</PRE>\n");
      fflush(stdout);
    }
  }
}

void dumpargs(stringArray name, stringArray value, int num)
{
  int i;
  char *s;

  fprintf(stdout, "<H1>CGI FORM test script reports:</H1>\n");
  fprintf(stdout, "The following %d name/value pairs are submitted<p>\n",num);
  fprintf(stdout, "<ul>\n");
  for(i=0; i < num; i++)
    fprintf(stdout, "<li> <code>%s = %s</code>\n",name[i],value[i]);
  fprintf(stdout, "</ul>\n");
}

void cgi_bin(int argc, char **argv)
{
  int t, r, c, i, num;
  char tile[128];

  char *board, *s, *oldboard, *startline;
  char urls[1024], *url;
  char *line[128];
  int lines = 0;
  int startrow, startcol;
  int Found = FALSE;

  char *format;
  stringArray name;  /* name[i]  is a string of char with a passed name */
  stringArray value; /* value[i] is a string of char with a passed value */


  tile[0] = '\0';

  num = getnamevalue(&name, &value);

  if (strcasecmp(getenv("REQUEST_METHOD"), "GET") == 0) {

  for (i = 0; i < num; i++) {
    if ((name[i] != NULL) && (strcasecmp(name[i], "savedgame")) == 0) {
      /* file number is in 'value[i]' */
      if (value[i] != NULL) {
        char command[1024];
        int fnum;

        if (isdigit(value[i][0])) fnum = (int)atol(value[i]); else break;
        /* display saved game and exit */

        fprintf(stdout, "Content-type: text/html\n");
        fprintf(stdout, "\n");
        fprintf(stdout, "<HTML><HEAD><TITLE>Scrabble Move Generator</TITLE></HEAD><BODY BGCOLOR='#FFFFFF'>\n");
        fprintf(stdout, "\n");
        fprintf(stdout, "<IMG SRC='http://www.gtoal.com/wordgames/boardgen/temp/wsc_%0ld.png'>\n", fnum);
        fprintf(stdout, "<H2>Here are all the possible plays on this board:</H2>\n<PRE>");
        fflush(stdout);
        sprintf(command,
          "/home/gtoal/public_html/scrabble/scrabble_solver/findmoves /home/gtoal/public_html/scrabble/boardgen/temp/wsc_%0ld.dat %s",
          fnum, "SAOL"); /* Hack */
        system(command);
        fflush(stdout);
        fprintf(stdout, "</PRE>\n"); fflush(stdout);

        exit(0);
      }
    }
  }

  fprintf(stdout, "Content-type: text/html\n");
  fprintf(stdout, "\n");

  fprintf(stdout, "<HTML><HEAD><TITLE>Scrabble Move Generator</TITLE></HEAD><BODY BGCOLOR='#FFFFFF'>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<FORM ACTION='/cgi-bin/allmoves-latin1' METHOD='POST'>\n");
  fprintf(stdout, "Enter your Scrabble position and I'll generate all the possible moves using ");
  fprintf(stdout, "<select name=\"dict\"><option selected>SAOL");
  fprintf(stdout, "</select>");
  fprintf(stdout, ".<BR><BR>\n");
  fprintf(stdout, "Enter your rack here:<BR>\n");
  fprintf(stdout, "<select name=\"R0\" size=\"1\"><option>a<option><option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option><option>p<option>r<option>s<option>t<option>u<option>v<option>x<option>y<option>z<option><option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"R1\" size=\"1\"><option>a<option><option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option><option>p<option>r<option>s<option>t<option>u<option>v<option>x<option>y<option>z<option><option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"R2\" size=\"1\"><option>a<option><option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option><option>p<option>r<option>s<option>t<option>u<option>v<option>x<option>y<option>z<option><option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"R3\" size=\"1\"><option>a<option><option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option><option>p<option>r<option>s<option>t<option>u<option>v<option>x<option>y<option>z<option><option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"R4\" size=\"1\"><option>a<option><option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option><option>p<option>r<option>s<option>t<option>u<option>v<option>x<option>y<option>z<option><option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"R5\" size=\"1\"><option>a<option><option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option><option>p<option>r<option>s<option>t<option>u<option>v<option>x<option>y<option>z<option><option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"R6\" size=\"1\"><option>a<option><option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option><option>p<option>r<option>s<option>t<option>u<option>v<option>x<option>y<option>z<option><option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "\n");
#ifdef NEVER
  fprintf(stdout, "Enter Player 2's rack here:<BR>\n");
  fprintf(stdout, "<select name=\"S0\" size=\"1\"><option>a<option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option>p<option>q<option>r<option>s<option>t<option>u<option>v<option>w<option>x<option>y<option>z<option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"S1\" size=\"1\"><option>a<option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option>p<option>q<option>r<option>s<option>t<option>u<option>v<option>w<option>x<option>y<option>z<option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"S2\" size=\"1\"><option>a<option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option>p<option>q<option>r<option>s<option>t<option>u<option>v<option>w<option>x<option>y<option>z<option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"S3\" size=\"1\"><option>a<option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option>p<option>q<option>r<option>s<option>t<option>u<option>v<option>w<option>x<option>y<option>z<option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"S4\" size=\"1\"><option>a<option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option>p<option>q<option>r<option>s<option>t<option>u<option>v<option>w<option>x<option>y<option>z<option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"S5\" size=\"1\"><option>a<option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option>p<option>q<option>r<option>s<option>t<option>u<option>v<option>w<option>x<option>y<option>z<option>BLANK<option selected>No tile</SELECT>");
  fprintf(stdout, "<select name=\"S6\" size=\"1\"><option>a<option>b<option>c<option>d<option>e<option>f<option>g<option>h<option>i<option>j<option>k<option>l<option>m<option>n<option>o<option>p<option>q<option>r<option>s<option>t<option>u<option>v<option>w<option>x<option>y<option>z<option>BLANK<option selected>No tile</select><br>\n");
  fprintf(stdout, "\n");
#endif
  fprintf(stdout, "Score: <INPUT NAME=score VALUE=\"\"><BR>\n");
  fprintf(stdout, "Number of tiles left: <INPUT NAME=remaining VALUE=\"\"><BR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TABLE BORDER Align='center'>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "Enter this play in <em>lower case</em>.  Enter blanks in UPPER CASE.\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD></TD>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD><TD>J</TD><TD>K</TD><TD>L</TD><TD>M</TD><TD>N</TD><TD>O</TD></TR>\n");
  fprintf(stdout, "<TR Align='center'><TD>1</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='a15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>2</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='b15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>3</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='c15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>4</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='d15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>5</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='e15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>6</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='f15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>7</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='g15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>8</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='h15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>9</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='i15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>10</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='j15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>11</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='k15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>12</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='l15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>13</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='m15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>14</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='n15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<TR Align='center'><TD>15</TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o1' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o2' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o3' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o4' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o5' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o6' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o7' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o8' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o9' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o10' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o11' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o12' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o13' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o14' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "<TD><INPUT TYPE='Text' NAME='o15' VALUE='' SIZE=1 MAXLENGTH=1></TD>\n");
  fprintf(stdout, "</TR>\n");
  fprintf(stdout, "</TABLE><BR>\n");
  fprintf(stdout, "\n");
  fprintf(stdout, "<INPUT TYPE='submit' VALUE='Find all moves!'>\n");
  fprintf(stdout, "</FORM><BR>\n");

  } else if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0) {
    int i;
    int row, col, x, y;

  fprintf(stdout, "Content-type: text/html\n");
  fprintf(stdout, "\n");

#ifdef NEVER
    fprintf(stdout, "<HTML><HEAD><TITLE>Scrabble Move Generator</TITLE></HEAD><BODY BGCOLOR='#FFFFFF'>\n");
    fprintf(stdout, "<PRE>\n"); fflush(stdout);
    for (r = 0; r <= argc; r++) {
      fprintf(stdout, "Argv[%d] = \"%s\"<BR>\n", r, (argv[r] == NULL ? "NULL" : argv[r]));
    }
    fprintf(stdout, "QUERY_STRING = \"%s\"<BR>\n", (getenv("QUERY_STRING") == NULL ? "NULL" : getenv("QUERY_STRING")));
    fflush(stdout); fprintf(stdout, "</PRE>\n");
    fprintf(stdout, "<PRE>\n"); fflush(stdout);
    system("printenv");
    fflush(stdout);
    fprintf(stdout, "*********** POST DATA:");
    for (;;) {
      i = fgetc(stdin);
      if (i == EOF) break;
      fputc(i&255, stdout);
    }
    fprintf(stdout, ":POST DATA **********\n");
    dumpargs(name, value, num);
    fprintf(stdout, "</PRE>\n");
#else
    fprintf(stdout, "<HTML><HEAD><TITLE>Scrabble Move Generator</TITLE></HEAD><BODY BGCOLOR='#FFFFFF'>\n");
    for (x = 0; x < 15; x++) {
      for (y = 0; y < 15; y++) {
        saved[x][y] = '.';
      }
    }
    format = "GIF";
    for (i = 0; i < num; i++) {
      if (strcasecmp(name[i], "format") == 0) {
        format = strdup(value[i]);
      } else if (strcasecmp(name[i], "dict") == 0) {
          dict = value[i]; /* TO DO - IMPORTANT - VET THE FILENAME */
      } else if (strcasecmp(name[i], "score") == 0) {
          if (value[i] != NULL) if (isdigit(value[i][0])) score = (int)atol(value[i]);
      } else if (strcasecmp(name[i], "remaining") == 0) {
          if (value[i] != NULL) if (isdigit(value[i][0])) remaining = (int)atol(value[i]);
      } else if (latin1_isalpha(name[i][0]) && isdigit(name[i][1])) {
	if (name[i][0] == 'R') {
          /* Rack element */
          int tile  = value[i][0];
          if (tile == 'B') tile = '?';
          if (tile == 'N') tile = ' ';
          rack1[name[i][1]-'0'] = tile;
#ifdef NEVER
	} else if (name[i][0] == 'S') {
          /* Rack element */
          int tile  = value[i][0];
          if (tile == 'B') tile = '?';
          if (tile == 'N') tile = ' ';
          rack2[name[i][1]-'0'] = tile;
#endif
	} else {
          /* Must be a board square */
        if (name[i] != NULL) {
          y = (name[i][0])-'a'; /* 0-15 */
          x = (atoi(name[i]+1))-1; /* 0-15 */
          /* Should have an assertion for 0..15 */
          if (value[i] == NULL) {
            saved[x][y] = '.';
          } else {
            saved[x][y] = value[i][0];
          }
	}
	}
      }
    }
    generate_graphic(saved, format);
#endif
    fflush(stdout);
  } else {
    fprintf(stdout, "Content-type: text/html\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "<HTML><BODY>Error!\n");
    /* ERROR */
  }

  fprintf(stdout, "<BR>\n");
  fprintf(stdout, "</BODY></HTML>\n\n");
  fflush(stdout);
}

int main(int argc, char **argv)
{
// http://www.opengroup.org/onlinepubs/007904975/functions/setlocale.html
  char *s = setlocale(LC_CTYPE,"sv"); // sv_SV.ISO-8859-1
  if (s == NULL) {
    FILE *f = fopen("/tmp/ERROR2", "w");
    fprintf(f, "Argh\n");
    fclose(f);
  }
  cgi_bin(argc, argv);
  exit(0);
  return(0);
}