/*****************************************************************************
 *
 * FILE:	printenv.c
 * DESCRIPTION:	print environment variables
 * DATE:	Wed, Jan 31 2001
 * UPDATE:	Sun, Aug 19 2007
 * AUTHOR:	Kouichi ABE (WALL) / °¤Éô¹¯°ì
 * E-MAIL:	kouichi@MysticWALL.COM
 * URL:		http://www.MysticWALL.COM/
 * COPYRIGHT:	(c) 2001-2007 °¤Éô¹¯°ì¡¿Kouichi ABE (WALL), All rights reserved.
 * COMPILE:	gcc -export-dynamic printenv.c -o printenv.cgi
 *		-I/usr/local/include -L/usr/local/lib
 *		-lcockatrice -lcatoblepas -lwkf -lmd
 * $Id: printenv.c,v 1.2 2007/08/19 16:50:38 kouichi Exp $
 *
 *****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <cockatrice.h>
#include <catoblepas.h>

int
main(argc, argv)
	int	argc;
	char *	argv[];
{
  CGI *		cgi;

  cgi = newCGI(CC_MODULE_DATE);
  if (cgi) {
    HTML *	html;

    html = newHTML401(HTML4_Transitional);
    if (html) {
      extern char **	environ;
      char **		ep;

      cgi->header("text/html");

      html->html.attr.lang = "ja";
      html->html.begin();
      html->head.begin();
      html->title("Environment Variables");
      html->head.end();

      html->body.begin();
      html->div.attr.trans.align = ALIGN_CENTER;
      html->div.begin();
	html->p.begin();
	  html->print(cgi->date->today());
	  html->print(cgi->date->time());
	html->p.end();
	html->table.attr.border = 1;
	html->table.begin();
	for (ep = environ; *ep; ep++) {
	  String	key;
	  String	value;

	  key   = *ep;
	  value = (String)strchr(key, '=');
	  if (value != NULL) {
	    *value++ = EOL;
	  }
	  html->tr.begin();
	    html->td.begin();
	      html->print(key);
	    html->td.end();
	    html->td.begin();
	      html->printe(value);
	    html->td.end();
	  html->tr.end();
	}
	html->table.end();
      html->div.end();
      html->body.end();
      html->html.end();

      html->done();
    }
    cgi->done();
  }

  return 0;
}
