#include "cgi.h"
#include <iostream>
#include <string>

using namespace std;
using namespace cgi_tools;

int
main()
{
   cout << "Content-Type: text/html\r\n\r\n" << flush;

   CGI form_data;
   string name;
   char * p;

   p = form_data["name"];

   if(p == 0)
      name = "you";
   else
      name = string(p);

   if(name.size() == 0)
      name = "you";

   cout << "<HTML><HEAD><TITLE>Hello, " << name 
        << "!</TITLE></HEAD>" << endl
        << "<FONT SIZE=\"+1\" FACE=\"Arial\">" << endl
        << "<HR><BR>" << endl
        << "<H2>Hello, " << name << "!</H2>" << endl
        << "<HR><BR>" << endl
        << "<H1>GET REQUEST METHOD</H1>" << endl
        << "<TABLE BORDER=\"1\">" << endl
        << "<FORM ACTION=\"/scripts/hello_cgi.exe\" METHOD=\"GET\">" << endl
        << "<TR><TD>Name:</TD><TD><INPUT TYPE=\"TEXT\" NAME=\"name\" "
        << "VALUE=\"\">" 
        << "</TD></TR>" << endl
        << "<TR><TD><INPUT TYPE=SUBMIT></TD>" << endl
        << "<TD><INPUT TYPE=RESET></TD></TR>" << endl
        << "</FONT></FORM></TABLE>" << endl
        << "<H1>POST REQUEST METHOD</H1>" << endl
        << "<TABLE BORDER=\"1\">" << endl
        << "<FORM ACTION=\"/scripts/hello_cgi.exe\" METHOD=\"POST\">" << endl
        << "<TR><TD>Name:</TD><TD><INPUT TYPE=\"TEXT\" NAME=\"name\" "
        << "VALUE=\"\">"
        << "</TD></TR>" << endl
        << "<TR><TD><INPUT TYPE=SUBMIT></TD>" << endl
        << "<TD><INPUT TYPE=RESET></TD></TR>" << endl
        << "</FONT></FORM></TABLE></HTML>" << endl << flush;

   return 0;
}
