changeset 87:d422585c19b9

Bunch of improvements all around; Re-wrote colormap utility.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 16 Dec 2006 13:43:30 +0000
parents 2519990b273e
children 872a13e83a2d
files Makefile.gen colormap.c diffmap.c maputils.c maputils.h mkloc.c mkmap.c mkspecial.c
diffstat 8 files changed, 527 insertions(+), 155 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.gen	Sat Dec 16 12:16:50 2006 +0000
+++ b/Makefile.gen	Sat Dec 16 13:43:30 2006 +0000
@@ -15,13 +15,12 @@
 MKMAP_BIN=$(BINPATH)mkmap$(EXEEXT)
 MKSPECIAL_BIN=$(BINPATH)mkspecial$(EXEEXT)
 COLORMAP_BIN=$(BINPATH)colormap$(EXEEXT)
-COLORANSI_BIN=$(BINPATH)coloransi$(EXEEXT)
 MAKEBCMAP_BIN=$(BINPATH)mkbcmap$(EXEEXT)
 DIFFMAP_BIN=$(BINPATH)diffmap$(EXEEXT)
 MKLOC_BIN=$(BINPATH)mkloc$(EXEEXT)
 
-TARGETS=$(MKMAP_BIN) $(COLORMAP_BIN) $(MKSPECIAL_BIN)		\
-	$(MAKEBCMAP_BIN) $(DIFFMAP_BIN)	$(COLORANSI_BIN)	\
+TARGETS=$(MKMAP_BIN) $(COLORMAP_BIN) $(MKSPECIAL_BIN)	\
+	$(MAKEBCMAP_BIN) $(DIFFMAP_BIN)			\
 	$(MKLOC_BIN) votk.html lanzia.html
 
 MAPFILES=tooltip.js votk.html votk.map lanzia.html lanzia.map
@@ -44,10 +43,7 @@
 $(MKLOC_BIN): mkloc.c maputils.o th_args.o th_util.o th_string.o
 	$(COMP) -o $@ $+ $(LDFLAGS)
 
-$(COLORMAP_BIN): colormap.c maputils.o th_util.o
-	$(COMP) -o $@ $+ $(LDFLAGS)
-
-$(COLORANSI_BIN): coloransi.c maputils.o th_util.o
+$(COLORMAP_BIN): colormap.c maputils.o th_util.o th_args.o th_string.o
 	$(COMP) -o $@ $+ $(LDFLAGS)
 
 $(MAKEBCMAP_BIN): mkbcmap.c maputils.o th_util.o th_string.o
@@ -65,19 +61,11 @@
 
 
 votk.html: votk.map $(COLORMAP_BIN)
-	$(COLORMAP_BIN) "Valley of the Kings" < $< > $@
+	$(COLORMAP_BIN) -t "Valley of the Kings" -vaOC -f html -o $@ $<
 
 lanzia.html: lanzia.map $(COLORMAP_BIN)
-	$(COLORMAP_BIN) "The Isle of Lanzia" < $< > $@
+	$(COLORMAP_BIN) -t "The Isle of Lanzia" -vaOC -f html -o $@ $<
 
-laenor.txt: laenor.initial /home/ccr/tiny.log $(MKMAP_BIN)
-	$(MKMAP_BIN) -r 10 -w 31 -h 30 -m 62 -v				\
-	-s "You look into sky without seeing and say (wizard eye)"	\
-	-I $< /home/ccr/tiny.log -o $@
-
-laenor.html: laenor.txt $(COLORMAP_BIN)
-	$(COLORMAP_BIN) "Continent of Laenor @ BatMUD mapped by Ggr (I have no life :D)" < $< > $@
-	scp $@ mhamalai@students.oamk.fi:public_html/
 
 #
 # Special targets
--- a/colormap.c	Sat Dec 16 12:16:50 2006 +0000
+++ b/colormap.c	Sat Dec 16 13:43:30 2006 +0000
@@ -4,35 +4,223 @@
  * (C) Copyright 2006 Tecnic Software productions (TNSP)
  */
 #include "maputils.h"
-#include <string.h>
+#include "th_args.h"
+#include "th_string.h"
+
+/*
+TODO:
+- analysoi mikä on se väri, mihin eniten vaihdetaan
+	(ei eniten käytetty, vaan mihin vaihdetaan useimmiten)
+	ja käytä sitä defaulttivärinä -> ei tarvi uutta tagia
+	väriin vaihtamiseksi, vain edellisen sulkemisen
+*/
+typedef struct {
+	char *fmtName;
+	char *fmtDescription;
+	void (*putTagStart) (FILE *, int);
+	void (*putTagEnd) (FILE *);
+	void (*putTagEOL) (FILE *);
+	void (*putFileStart) (FILE *);
+	void (*putFileEnd) (FILE *);
+} outfmt_t;
+
+
+char	*srcFilename = NULL,
+	*destFilename = NULL;
+
+char	*optHTMLTagName = "i",
+	*optMapTitle = NULL;
+	
+BOOL	optPerformAnalysis = FALSE,
+	optInputIsDiff = FALSE,
+	optUseOldFormat = FALSE,
+	optCheatMode = FALSE;
+
+int	optOutputFormat = 0;
 
-/* If defined, the code will be compiled with following
- * "optimizations", which make the HTML output smaller, at
- * cost of strict spec-compatibility
- *
- * - Omit '' from class='' arguments	(non-spec)
+	
+/* Arguments
+ */
+optarg_t optList[] = {
+	{ 0, '?', "help",	"Show this help", OPT_NONE },
+	{ 1, 'v', "verbose",	"Be more verbose", OPT_NONE },
+	{ 2, 'q', "quiet",	"Be quiet", OPT_NONE },
+	{ 3, 'T', "html-tag",	"HTML tag used for map", OPT_ARGREQ },
+	{ 4, 'a', "analysis",	"Perform statistical analysis", OPT_NONE },
+	{ 5, 'd', "input-diff",	"Input is a diff", OPT_NONE },
+	{ 6, 'O', "old-format",	"Input using old symbols/colors", OPT_NONE },
+	{ 7, 'o', "output",	"Output filename", OPT_ARGREQ },
+	{ 8, 'f', "format",	"Specify output format", OPT_ARGREQ },
+	{ 9, 't', "title",	"Map title", OPT_ARGREQ },
+	{ 10,'C', "cheat-mode",	"Use cheating in HTML", OPT_NONE },
+};
+
+const int optListN = (sizeof(optList) / sizeof(optarg_t));
+
+
+/*
+ * ANSI output format functions
  */
-#define CHEATMODE
+void putTagStartANSI(FILE *outFile, int c)
+{
+	fputc(0x1b, outFile);
+
+	if (c < 0) {
+		fprintf(outFile, "[0;47;30m");
+	} else {
+		fprintf(outFile, "[%d;%dm",
+			mapColors[c].ansiAttr,
+			mapColors[c].ansi);
+	}
+}
+
+void putTagEndANSI(FILE *outFile)
+{
+	(void) outFile;
+}
+
+void putEOLANSI(FILE *outFile)
+{
+	fprintf(outFile, "\n");
+}
+
+void putFileStartANSI(FILE *outFile)
+{
+	fputc(0x1b, outFile);
+	fprintf(outFile, "[0m");
+
+	if (optMapTitle) {
+		fprintf(outFile, "%s\n", optMapTitle);
+	}
+}
+
+
+void putFileEndANSI(FILE *outFile)
+{
+	fputc(0x1b, outFile);
+	fprintf(outFile, "[0m");
+}
 
 
-void processNormal(FILE *inFile, FILE *outFile)
+/*
+ * ASCII output format functions
+ */
+void putTagStartText(FILE *outFile, int c)
+{
+	(void) outFile; (void) c;
+}
+
+void putTagEndText(FILE *outFile)
+{
+	(void) outFile;
+}
+
+void putEOLText(FILE *outFile)
+{
+	fprintf(outFile, "\n");
+}
+
+void putFileStartText(FILE *outFile)
+{
+	if (optMapTitle) {
+		fprintf(outFile, "%s\n", optMapTitle);
+	}
+}
+
+
+void putFileEndText(FILE *outFile)
+{
+	(void) outFile;
+}
+
+
+/*
+ * XHTML+CSS output format functions
+ */
+#define HTML_LOCTITLE_SPEC 'q'
+
+void putTagStartHTML(FILE *outFile, int c)
+{
+	int q;
+	
+	if (c < 0)
+		q = HTML_LOCTITLE_SPEC;
+	else
+		q = 'a'+c;
+	
+	if (optCheatMode)
+		fprintf(outFile, "<i class=%c>", q);
+	else
+		fprintf(outFile, "<i class='%c'>", q);
+}
+
+void putTagEndHTML(FILE *outFile)
+{
+	fprintf(outFile, "</i>");
+}
+
+void putEOLHTML(FILE *outFile)
+{
+	fprintf(outFile, "\n");
+}
+
+void putFileStartHTML(FILE *outFile)
+{
+	mcXHTMLhead(outFile, optMapTitle);
+	
+	fprintf(outFile,
+	" <style type=\"text/css\">\n"
+	"  body { background: black; color: white; }\n"
+	"  %s { text-decoration: none; font-style: normal; }\n"
+	"  %s.%c { background: white; color: black; }\n",
+	optHTMLTagName, optHTMLTagName, HTML_LOCTITLE_SPEC
+	);
+	
+	mcXHTMLcolors(outFile, optHTMLTagName);
+
+	fprintf(outFile,
+	" </style>\n"
+	"</head>\n"
+	"<body>\n"
+	);
+
+	if (optMapTitle)
+	fprintf(outFile, "<h2>%s</h2>\n", optMapTitle);
+
+	fprintf(outFile,
+	"<pre>\n"
+	);
+}
+
+void putFileEndHTML(FILE *outFile)
+{
+	/* XHTML document end tags */
+	fprintf(outFile,
+	"</pre>\n"
+	"</body>\n"
+	"</html>\n"
+	);
+}
+
+
+/* Process a normal format input
+ */
+void processNormal(FILE *inFile, FILE *outFile, outfmt_t *fmt)
 {
 	int k, c, p;
 
 	c = p = -1;
 	while ((k = fgetc(inFile)) != EOF) {
 		if (k == '\n') {
-			fprintf(outFile, "\n");
+			fmt->putTagEOL(outFile);
 		} else if (k == 0xff) {
 			/* Location title mode */
-			if (p != -1) fprintf(outFile, "</i>");
+			if (p != -1)
+				fmt->putTagEnd(outFile);
+
 			c = p = -2;
 			
-#ifdef CHEATMODE
-			fprintf(outFile, "<i class=q>");
-#else
-			fprintf(outFile, "<i class='q'>");
-#endif
+			fmt->putTagStart(outFile, -1);
 			
 			while ((k = fgetc(inFile)) != EOF) {
 				if (k == 0xfe)
@@ -42,126 +230,280 @@
 			}
 			
 		} else {
-			c = mcGetColor(k);
+			c = mcGetColor(k, optUseOldFormat);
 			if (c != p) {
-				if (p != -1) fprintf(outFile, "</i>");
+				if (p != -1) fmt->putTagEnd(outFile);
 	
 				if (k > 0) {
-#ifdef CHEATMODE
-					fprintf(outFile,
-					"<i class=%c>%c", 'a'+c, k);
-#else
-					fprintf(outFile,
-					"<i class='%c'>%c", 'a'+c, k);
-#endif
-				}
-			} else
-				fprintf(outFile, "%c", k);
-		}
-		
-		p = c;
-	}
-}
-
-
-void processDiff(FILE *inFile, FILE *outFile)
-{
-	int c, p;
-
-	c = p = -1;
-	while ((c = fgetc(inFile)) != EOF) {
-		if (c == 0xff) {
-			fprintf(outFile, "\n");
-		} else {
-			if (c != p) {
-				if (p != -1) {
-					fprintf(outFile, "</i>");
-				}
-	
-				if (c >= 0) {
-					int t = (c / 64), q = (c % 64);
-					if (t > 0) {
-						fprintf(outFile,
-						"<i style='color:%s;background:%s'>",
-						mapColors[mapPieces[q].col].css,
-						mapColors[t].css);
-					} else {
-#ifdef CHEATMODE
-						fprintf(outFile, "<i class=%c>",
-						'a'+mapPieces[q].col);
-#else
-						fprintf(outFile, "<i class='%c'>",
-						'a'+mapPieces[q].col);
-#endif
-					}
-					
-					fprintf(outFile, "%c", mapPieces[q].c);
+					fmt->putTagStart(outFile, c);
+					fprintf(outFile, "%c", k);
 				}
 			} else {
-				fprintf(outFile, "%c",
-				mapPieces[c % 64].c);
+				fprintf(outFile, "%c", k);
 			}
 		}
 		
 		p = c;
 	}
+	
+	if (p != -1) fmt->putTagEnd(outFile);
+}
+
+
+/* Get a symbol
+ */
+char getSymbol(int i, BOOL useOld)
+{
+	if (useOld)
+		return mapPieces[i].oldSymbol;
+	else
+		return mapPieces[i].symbol;
+}
+
+
+/* Process a diff
+ */
+BOOL processDiff(FILE *inFile, FILE *outFile, outfmt_t *fmt)
+{
+	int c, p;
+	size_t offs;
+
+	offs = 0;
+	c = p = -1;
+	while ((c = fgetc(inFile)) != EOF) {
+		if (c == 0xff) {
+			fmt->putTagEOL(outFile);
+		} else {
+			if (c != p) {
+				if (p != -1)
+					fmt->putTagEnd(outFile);
+	
+				if (c >= 0) {
+					int t = (c / 64),
+					q = mcGetColor(c % 64, optUseOldFormat);
+					
+					if (t > 0) {
+						/* FIXME FIXME TODO */
+						fprintf(outFile,
+						"<i style='background:%s;color:black'>",
+						mapColors[q].css);
+					} else
+						fmt->putTagStart(outFile, q);
+					
+					fprintf(outFile, "%c",
+						getSymbol(q, optUseOldFormat));
+				}
+			} else if (c >= 0) {
+				fprintf(outFile, "%c",
+					getSymbol(c % 64, optUseOldFormat));
+			} else {
+				THERR("Broken map diff input at offset %d.\n", offs);
+				exit(15);
+			}
+		}
+		
+		p = c;
+		offs++;
+	}
+
+	if (p != -1) fmt->putTagEnd(outFile);
+	
+	return TRUE;
 }
 
 
+/* List of output formats
+ */
+outfmt_t outputFormats[] = {
+	{ "xhtml", "XHTML+CSS",
+	putTagStartHTML, putTagEndHTML, putEOLHTML,
+	putFileStartHTML, putFileEndHTML
+	},
+
+	{ "ansi", "ANSI text",
+	putTagStartANSI, putTagEndANSI, putEOLANSI,
+	putFileStartANSI, putFileEndANSI
+	},
+
+	{ "text", "Plain ASCII text",
+	putTagStartText, putTagEndText, putEOLText,
+	putFileStartText, putFileEndText
+	},
+};
+
+const int noutputFormats = (sizeof(outputFormats) / sizeof(outfmt_t));
+
+
+void argShowHelp(void)
+{
+	int i;
+	
+	th_args_help(stderr, optList, optListN, th_prog_name,
+	"[options] <input mapfile>");
+	
+	fprintf(stderr, "\nAvailable OUTPUT formats:\n");
+	for (i = 0; i < noutputFormats; i++) {
+		fprintf(stderr, "  %-8s - %s %s\n",
+		outputFormats[i].fmtName,
+		outputFormats[i].fmtDescription,
+		(i == optOutputFormat) ? "(default)" : ""
+		);
+	}
+
+	fprintf(stderr, "\n");
+}
+
+
+BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
+{
+	int i, n;
+	
+	switch (optN) {
+	case 0:
+		argShowHelp();
+		exit(0);
+		break;
+
+	case 1:
+		th_verbosityLevel++;
+		break;
+	
+	case 2:
+		th_verbosityLevel = -1;
+		break;
+	
+	case 3:
+		optHTMLTagName = optArg;
+		THMSG(2, "HTML tag set to '%s'\n", optHTMLTagName);
+		break;
+	
+	case 4:
+		optPerformAnalysis = TRUE;
+		THMSG(2, "Analysis enabled.\n");
+		break;
+	
+	case 5:
+		optInputIsDiff = TRUE;
+		THMSG(2, "Input is a 'diff', handling it as such.\n");
+		break;
+		
+	case 6:
+		optUseOldFormat = TRUE;
+		THMSG(2, "Input is using old map symbols/colors.\n");
+		break;
+	
+	case 7:
+		destFilename = optArg;
+		THMSG(2, "Output file set to '%s'.\n", destFilename);
+		break;
+	
+	case 8:
+		/* Get format */
+		for (i = 0, n = -1; (i < noutputFormats) && (n < 0); i++)
+			if (th_strcmp(optArg, outputFormats[i].fmtName) == 0)
+				n = i;
+		
+		if (n < 0) {
+			THERR("Invalid output format '%s'\n", optArg);
+			return FALSE;
+		}
+		
+		optOutputFormat = n;
+		THMSG(2, "Output format set to '%s'\n", optArg);
+		break;
+	
+	case 9:
+		optMapTitle = optArg;
+		THMSG(2, "Map title string set to '%s'.\n", optMapTitle);
+		break;
+	
+	case 10:
+		optCheatMode = TRUE;
+		THMSG(2, "HTML cheats mode enabled!\n");
+		break;
+
+	default:
+		THERR("Unknown option '%s'.\n", currArg);
+		return FALSE;
+	}
+	
+	return TRUE;
+}
+
+
+BOOL argHandleFile(char *currArg)
+{
+	if (!srcFilename)
+		srcFilename = currArg;
+	else {
+		THERR("Too many input map files specified!\n");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+
+/* Main program
+ */
 int main(int argc, char *argv[])
 {
 	FILE *inFile, *outFile;
-	BOOL optDiff;
-	
-	inFile = stdin;
-	outFile = stdout;
-	
-	/* Output XHTML header */
-	if (argc >= 2)
-		mcXHTMLhead(outFile, argv[1]);
-	else
-		mcXHTMLhead(outFile, NULL);
-	
-	if (argc >= 3 && !strcmp(argv[2], "-diff"))
-		optDiff = TRUE;
-	else
-		optDiff = FALSE;
-		
-	/* Output CSS style information */
-	fprintf(outFile,
-	" <style type=\"text/css\">\n"
-	"  body	{ background: black; color: white; }\n"
-	"  i { text-decoration: none; font-style: normal; }\n"
-	"  span.q { background: white; color: black; }\n"
-	);
-
-	mcXHTMLcolors(outFile, "i");
+	outfmt_t *fmt = NULL;
 
-	fprintf(outFile,
-	" </style>\n"
-	"</head>\n"
-	"<body>\n"
-	);
-
-	if (argc >= 2)
-		fprintf(outFile, "<h2>%s</h2>\n", argv[1]);
-
-	fprintf(outFile,
-	"<pre>\n"
-	);
+	/* Initialize */
+	th_init("colormap", "ASCII map colorizer", "0.1", NULL, NULL);
+	th_verbosityLevel = 1;
+	
+	/* Parse arguments */
+	if (!th_args_process(argc, argv, optList, optListN,
+		argHandleOpt, argHandleFile, TRUE))
+		exit(1);
+	
+	if (srcFilename == NULL) {
+		THERR("Nothing to do. (try --help)\n");
+		exit(0);
+	}
+	
+	/* Do statistical analysis, if needed */
+	if (optPerformAnalysis) {
+		THMSG(1, "Computing statistical analysis of mapdata ...\n");
+	}
+	
+	/* Open input file */
+	if ((inFile = fopen(srcFilename, "rb")) == NULL) {
+		THERR("Error opening input file '%s'!\n",
+			srcFilename);
+		exit(1);
+	}
 	
-	/* Process input, convert to map */
-	if (optDiff)
-		processDiff(inFile, outFile);
+	/* Open output file */
+	if (destFilename == NULL)
+		outFile = stdout;
+	else if ((outFile = fopen(destFilename, "wb")) == NULL) {
+		THERR("Error opening output file '%s'!\n",
+			destFilename);
+		exit(1);
+	}
+
+	/* Okay, let's process the shit */
+	fmt = &outputFormats[optOutputFormat];
+	THMSG(1, "Converting to '%s' ...\n", fmt->fmtName);
+
+	fmt->putFileStart(outFile);
+
+	if (optInputIsDiff)
+		processDiff(inFile, outFile, fmt);
 	else
-		processNormal(inFile, outFile);
+		processNormal(inFile, outFile, fmt);
+
+	fmt->putFileEnd(outFile);
+
+	fclose(outFile);
+	fclose(inFile);
 	
-	/* XHTML document end tags */
-	fprintf(outFile,
-	"</pre>\n"
-	"</body>\n"
-	"</html>\n"
-	);
+	THMSG(1, "Done.\n");
 	
+	exit(0);
 	return 0;
 }
--- a/diffmap.c	Sat Dec 16 12:16:50 2006 +0000
+++ b/diffmap.c	Sat Dec 16 13:43:30 2006 +0000
@@ -25,7 +25,7 @@
 }
 
 
-mapblock_t * diffBlocks(mapblock_t *map1, mapblock_t *map2)
+mapblock_t * diffBlocks(mapblock_t *map1, mapblock_t *map2, BOOL useOld)
 {
 	int x, y;
 	mapblock_t *res;
@@ -50,9 +50,9 @@
 	for (y = 0; y < map1->h; y++)
 	for (x = 0; x < map1->w; x++) {
 		if (*p1 != *p2)
-			*pd = mcGet(*p2) + 0x40;
+			*pd = mcGet(*p2, useOld) + 0x40;
 		else
-			*pd = mcGet(*p1);
+			*pd = mcGet(*p1, useOld);
 
 		p1++; p2++; pd++;
 	}
@@ -64,29 +64,36 @@
 int main(int argc, char *argv[])
 {
 	mapblock_t *map1, *map2, *res;
+	BOOL useOld;
 	
+	th_init("diffmap", "", "0.2", NULL, NULL);
+	th_verbosityLevel = 1;
+
 	if (argc < 3) {
 		fprintf(stderr,
-		"Usage: %s mapfile1 mapfile2 > outfile\n",
-		argv[0]);
+		"Usage: %s mapfile1 mapfile2 [-useold] > outfile\n"
+		"(-useold option is for maps using old map symbols)\n",
+		th_prog_name);
 		exit(1);
 	}
 	
+	if ((argc >= 4) && !strcmp(argv[3], "-useold"))
+		useOld = TRUE;
+	else
+		useOld = FALSE;
+
+	THMSG(1, "Using %s map symbols and colours.\n",
+		useOld ? "OLD" : "NEW");
+	
 	/* Read mapfiles */
-	if ((map1 = parseFile(argv[1])) == NULL) {
-		THERR("Could not parse input file #1: '%s'\n",
-			argv[1]);
+	if ((map1 = parseFile(argv[1])) == NULL)
 		exit(2);
-	}
 
-	if ((map2 = parseFile(argv[2])) == NULL) {
-		THERR("Could not parse input file #2: '%s'\n",
-			argv[2]);
+	if ((map2 = parseFile(argv[2])) == NULL)
 		exit(2);
-	}
 	
 	/* Compute and output data */
-	if ((res = diffBlocks(map1, map2)) == NULL) {
+	if ((res = diffBlocks(map1, map2, useOld)) == NULL) {
 		THERR("Could not create diff between inputs!\n");
 		exit(3);
 	}
--- a/maputils.c	Sat Dec 16 12:16:50 2006 +0000
+++ b/maputils.c	Sat Dec 16 13:43:30 2006 +0000
@@ -115,6 +115,36 @@
 }
 
 
+void mcXHTMLhead(FILE *outFile, char *title)
+{
+	assert(outFile);
+	
+	/* Output XHTML header */
+	fprintf(outFile,
+	"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
+	"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
+	"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"
+	"<head>\n");
+	
+	if (title)
+	fprintf(outFile, " <title>%s</title>\n", title);
+}
+
+
+void mcXHTMLcolors(FILE *outFile, char *tagName)
+{
+	int n;
+	
+	for (n = 0; n < nmapColors; n++) {
+		fprintf(outFile,
+		"  %s.%c { color: %s; }\n",
+		tagName, 'a'+n,
+		mapColors[n].css);
+	}
+
+}
+
+
 /* Map block handling
  */
 mapblock_t * allocBlock(int blockW, int blockH)
@@ -238,6 +268,8 @@
 {
 	char *c;
 	int x, y;
+	assert(f);
+	assert(map);
 
 	c = map->d;
 		
@@ -261,6 +293,8 @@
 int putBlockDo(mapblock_t *map, mapblock_t *b, int ox, int oy)
 {
 	int x, y;
+	assert(map);
+	assert(b);
 	
 	for (y = 0; y < b->h; y++)
 	for (x = 0; x < b->w; x++) {
@@ -287,6 +321,9 @@
 {
 	mapblock_t *tmp;
 	int x0, y0, x1, y1, mx, my;
+
+	assert(map);
+	assert(b);
 	
 	/* Determine new block size */
 	x0 = mx = y0 = my = 0;
@@ -331,6 +368,8 @@
 {
 	int x, y;
 	size_t o;
+	assert(map);
+	assert(symbols);
 	
 	o = 0;
 	for (y = 0; y < map->h; y++)
--- a/maputils.h	Sat Dec 16 12:16:50 2006 +0000
+++ b/maputils.h	Sat Dec 16 13:43:30 2006 +0000
@@ -72,6 +72,8 @@
  */
 int		mcGet(int, BOOL);
 int		mcGetColor(int, BOOL);
+void		mcXHTMLhead(FILE *, char *);
+void		mcXHTMLcolors(FILE *, char *);
 
 mapblock_t *	allocBlock(int, int);
 void		freeBlock(mapblock_t *);
--- a/mkloc.c	Sat Dec 16 12:16:50 2006 +0000
+++ b/mkloc.c	Sat Dec 16 13:43:30 2006 +0000
@@ -48,7 +48,6 @@
 
 /* Variables
  */
-char	*progName = NULL;
 char	*srcFile = NULL,
 	*destFile = NULL,
 	*locFile = NULL;
@@ -77,7 +76,7 @@
 
 void argShowHelp()
 {
-	th_args_help(stdout, optList, optListN, progName,
+	th_args_help(stdout, optList, optListN, th_prog_name,
 		"[options]");
 }
 
@@ -502,7 +501,6 @@
 	locations_t worldLocations;
 
 	/* Initialize */
-	progName = argv[0];
 	th_init("mkloc", "Add locations to ASCII map", "0.1", NULL, NULL);
 	th_verbosityLevel = 1;
 	
--- a/mkmap.c	Sat Dec 16 12:16:50 2006 +0000
+++ b/mkmap.c	Sat Dec 16 13:43:30 2006 +0000
@@ -17,7 +17,6 @@
 
 /* Variables
  */
-char	*progName = NULL;
 int	nsrcFiles = 0;
 char	*srcFiles[MAX_FILES],
 	*destFile = NULL;
@@ -56,7 +55,7 @@
 
 void argShowHelp()
 {
-	th_args_help(stdout, optList, optListN, progName,
+	th_args_help(stdout, optList, optListN, th_prog_name,
 		"[options] <inputfile> [inputfile#2..]");
 }
 
@@ -402,7 +401,6 @@
 	mapblock_t *worldMap = NULL, *tmp = NULL, *initialMap = NULL;
 	mapblock_t **mapBlocks = NULL;
 
-	progName = argv[0];
 	th_init("mkmap", "ASCII Map Auto-Stitcher", "0.3", NULL, NULL);
 	th_verbosityLevel = 1;
 	
--- a/mkspecial.c	Sat Dec 16 12:16:50 2006 +0000
+++ b/mkspecial.c	Sat Dec 16 13:43:30 2006 +0000
@@ -16,7 +16,6 @@
 
 /* Variables
  */
-char	*progName = NULL;
 int	nsrcFiles = 0;
 char	*srcFiles[MAX_FILES],
 	*destFile = NULL;
@@ -58,7 +57,7 @@
 
 void argShowHelp()
 {
-	th_args_help(stdout, optList, optListN, progName,
+	th_args_help(stdout, optList, optListN, th_prog_name,
 		"[options] <inputfile> [inputfile#2..]");
 }
 
@@ -331,7 +330,6 @@
 	mapblock_t *worldMap = NULL, *initialMap = NULL;
 	mapblock_t **mapBlocks = NULL;
 
-	progName = argv[0];
 	th_init("mkspecial", "Yet Another ASCII Map Auto-Stitcher", "0.1", NULL, NULL);
 	th_verbosityLevel = 1;