#!/bin/sh

INFILE="PapierbandenCWI.csv"
SUBDIR="../"
OUTFILE=${SUBDIR}"/index.html"
SEPARATOR="#"

cat - > ${OUTFILE} <<\EOF
<html>
<head>
<title>PPT / Archive of PaPerTapes</title>
</head>
<body>
<center>
<h2>PPT / Archive of PaPerTapes</h2>
</center>
<hr>
<ul>
<li>There are a few programs used. You find them here: <a HREF="sources/index.html">SOURCES</a>
<li>You will find some useful documents here: <a HREF="docs/index.html">DOCUMENTS</a>
</ul>
EOF

echo '<p><center> timestamp ' >> ${OUTFILE}
date >> ${OUTFILE}
echo '</center><p><hr>' >> ${OUTFILE}

sed '1d' < $INFILE |
	sed '1,$s/#"/#/' |
	sed '1,$s/"#/#/' |
	awk -F${SEPARATOR} '{
		if($1 != "")
		{
			printf("<table border=0 width=\"100%%\">\n");
			printf("<tr>\n");
				printf("<td rowspan=2 width=\"8%%\">\n");
				printf("<font size=5>%d </font>", $1);
				printf("<font size=6 align=\"right\">|</font>");
				printf("</td>\n");

				printf("<td colspan=5>\n");
				printf("<center><b>%s</b></center>", $5);
				printf("</td>\n");
			printf("</tr>\n");
			printf("<tr>\n");
				printf("<td width=\"15%%\">\n");
				if($2 != "")
					printf("%s", $2);
				printf("</td>\n");

				printf("<td width=\"10%%\">| %s hole ppt</td>\n",$3);

				if($4 == "L")
					printf("<td width=\"25%%\">| %s = readable text (flexowriter)</td>\n",$4);
				else
				
				if($4 == "B")
					printf("<td width=\"25%%\">| %s = binary</td>\n",$4);
				else
				if($4 == "Z")
					printf("<td width=\"25%%\">| %s = Zebra code</td>\n",$4);
				else
				if($4 == "X")
					printf("<td width=\"25%%\">| %s = X1 handcode assembler</td>\n",$4);
				else
				if($4 == "A")
					printf("<td width=\"25%%\">| %s = Algol 60 source</td>\n",$4);
				else
				if($4 == "n")
					printf("<td width=\"25%%\">| %s =Not processed</td>\n",$4);
				else
					printf("<td width=\"25%%\">| %s</td>\n",$4);

				if($6 != "")
					printf("<td width=\"25%%\">| Note: <i>%s</i></td>\n",$6);
				else
					printf("<td width=\"25%%\">| --</td>\n");

				if($4 != "n")
					printf("<td width=\"15%%\">| <a HREF=\"b%d/index.html\">Files -></a></td>\n",$1);
				else
					printf("<td width=\"15%%\">| no files</td>\n");
			printf("</tr>\n");
			printf("</table>\n");
			printf("<hr>\n");
		}
	}' >> $OUTFILE

cat - >> ${OUTFILE} <<\EOF
</center>
</body>
</html>
EOF
