#!/usr/local/bin/perl
# $Id: csv2html.pl,v 1.2 1998/08/20 04:40:43 tsumura Exp $

require 'jcode.pl';
$FORMTYPE = 1;		# ?file=hoge.csv or ?hoge.csv

$RCSID	= "$Id: csv2html.pl,v 1.2 1998/08/20 04:40:43 tsumura Exp $dummy";
$RCSID	=~ /csv2html\.pl,v ([0-9\.]+) [0-9\/]+ [0-9:]+/;
$VERSION = $1;

print "Content-Type: text/html\n\n";
if($FORMTYPE){
  $args = $ENV{"QUERY_STRING"};
  @terms = split('&', $args);
  foreach (@terms) {
    ($tag, $value) = split(/=/, $_, 2);
    $value =~ s/\+/ /g;
    $value =~ s/%(..)/pack("c", hex($1))/ge;
    $tags{$tag} = $value;
  }
  $FILE		= $tags{"file"};
}else{
  $FILE		= $ENV{"QUERY_STRING"};
}

$HTMLROOT	= "/home/home2/share/WWW/html/members/tsumura";
$CSVROOT	= "csv";
$FILENAME	= $HTMLROOT . "/" . $CSVROOT . "/" . $FILE;

print<<EofHdr;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<TITLE>TSUMURA,Tomoaki: $FILE</TITLE>
<LINK REV=MADE HREF="mailto:tsumura\@kuis.kyoto-u.ac.jp">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-2022-JP">
</HEAD>
<BODY text="#ffffff" link="#00EEEE" vlink="#00BBBB" bgcolor="#004030">

<h1><font color="#87cefa">$FILE</font></h1>
<div align=left>csv2html.pl ver.$VERSION</div>
<div align=right>
<a href="/~tsumura/$CSVROOT/$FILE">original csv file</a>
</div>
<HR>

EofHdr

print "<table border=1>\n";
open(FILE, $FILENAME) || die ("cannot open file $FILENAME\n");
$TAG = "th";
while(<FILE>){
  if(/^\s*$/ || /^\#/){ next; }
  print "<tr>";
  while(/^([^,]*),(.*)$/){
    $CONT = $1;    $_ = $2;
    &jcode::convert(*CONT, "jis");
    print "<$TAG>$CONT";
  }
  $CONT = $_;
  &jcode::convert(*CONT, "jis");
  print "<$TAG>$CONT\n";
  $TAG = "td";
}
print "</table>\n";

print<<EofFtr;
<HR>
<a href="/~tsumura/foot.map"><img src="/~tsumura/pic/but2.gif"
border=0 alt="[Jump Menu]" ISMAP></a>
<ADDRESS>
<img src="/~tsumura/pic/tsumura.gif" ALIGN=MIDDLE alt="">
tsumura\@kuis.kyoto-u.ac.jp</ADDRESS>
</BODY>
</HTML>
EofFtr
