changeset 5:22d1a53d5d17

Also generate ASCII version
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Apr 2006 10:58:11 +0000
parents 380f99b42900
children 781f97b31175
files Makefile.gen mkbcmap.c
diffstat 2 files changed, 144 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.gen	Fri Apr 28 08:08:10 2006 +0000
+++ b/Makefile.gen	Fri Apr 28 10:58:11 2006 +0000
@@ -16,7 +16,7 @@
 COLORMAP_BIN=$(BINPATH)colormap$(EXEEXT)
 MAKEBCMAP_BIN=$(BINPATH)mkbcmap$(EXEEXT)
 
-TARGETS=$(MKMAP_BIN) $(COLORMAP_BIN) $(MAKEBCMAP_BIN) votk.html batcity.html lanzia.html
+TARGETS=$(MKMAP_BIN) $(COLORMAP_BIN) $(MAKEBCMAP_BIN) votk.html batcity.html batcity.txt lanzia.html
 
 #
 # Target rules
@@ -44,6 +44,10 @@
 batcity.html: $(MAKEBCMAP_BIN) batcity2.cmap batcity.cnam tooltip.js
 	$(MAKEBCMAP_BIN) "New BatCity map (as of `date +"%d.%m.%Y %R"`) by Ggr Pupunen" batcity2.cmap batcity.cnam > $@
 
+batcity.txt: $(MAKEBCMAP_BIN) batcity2.cmap batcity.cnam
+	$(MAKEBCMAP_BIN) "New BatCity map (as of `date +"%d.%m.%Y %R"`) by Ggr Pupunen" batcity2.cmap batcity.cnam -ascii > $@
+
+
 votk.html: votk.map $(COLORMAP_BIN)
 	$(COLORMAP_BIN) "Valley of the Kings" < $< > $@
 
@@ -53,7 +57,7 @@
 #
 # Special targets
 #
-upload: batcity.html tooltip.js votk.html lanzia.html
+upload: batcity.html batcity.txt tooltip.js votk.html votk.map lanzia.html
 	scp $+ mhamalai@students.oamk.fi:public_html/bat/
 
 clean:
--- a/mkbcmap.c	Fri Apr 28 08:08:10 2006 +0000
+++ b/mkbcmap.c	Fri Apr 28 10:58:11 2006 +0000
@@ -188,7 +188,7 @@
 }
 
 
-void processMap(FILE *inFile, FILE *outFile)
+void processMapHTML(FILE *outFile, FILE *inFile)
 {
 	DINT c, p;
 
@@ -211,56 +211,10 @@
 		
 		p = c;
 	}
-
 }
 
 
-DINT parseLocFile(char *pcFilename)
-{
-	FILE *inFile;
-	DCHAR s[4096];
-	size_t i, j, k;
-	
-	if ((inFile = fopen(pcFilename, "rb")) == NULL) {
-		fprintf(stderr, "Could not open file '%s' for reading.\n",
-			pcFilename);
-		return -1;
-	}
-	
-	while (!feof(inFile)) {
-		s[0] = 0;
-		fgets(s, sizeof(s), inFile);
-		
-		if (strlen(s) > 3) {
-			i = 1;
-			
-			th_findnext(s, &i);
-			j = i;
-			
-			while (s[i] && s[i] != '[' && !th_iscrlf(s[i])) i++;
-			
-			if (s[i] == '[') {
-				k = i;
-				
-				while (s[k] && s[k] != ']' && !th_iscrlf(s[k])) k++;
-				s[k] = 0;
-				s[i] = 0;
-				addLoc(s[0], &s[j], &s[i+1]);
-			} else {
-				s[i] = 0;
-				addLoc(s[0], &s[j], NULL);
-			}
-			
-		}
-	}
-	
-	fclose(inFile);
-	
-	return 0;
-}
-
-
-void printBlock(FILE *outFile, DINT nStart, DINT nEnd)
+void printBlockHTML(FILE *outFile, DINT nStart, DINT nEnd)
 {
 	DINT n;
 	
@@ -312,32 +266,10 @@
 }
 
 
-DINT main(DINT argc, DCHAR *argv[])
+void outputHTML(FILE *outFile, FILE *inFile, DCHAR *mapTitle)
 {
-	FILE *inFile, *outFile;
-	DCHAR *mapTitle, *mapFilename, *descFilename;
 	DINT n;
 	
-	if (argc != 4) {
-		fprintf(stderr,
-		"Usage: %s \"<title>\" mapfile descfile > outfile\n",
-		argv[0]);
-		return 0;
-	}
-	
-	outFile = stdout;
-	mapTitle = argv[1];
-	mapFilename = argv[2];
-	descFilename = argv[3];
-	
-	/* Parse desc file */
-	if (parseLocFile(descFilename) < 0) {
-		fprintf(stderr,
-		"Could not properly parse desc file '%s'\n",
-		descFilename);
-		return 3;
-	}
-	
 	/* Output XHTML header */
 	fprintf(outFile,
 	"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
@@ -383,20 +315,9 @@
 	);
 	
 	/* Process input, convert to map */
-	fprintf(stderr, "Processing map...\n");
-	if ((inFile = fopen(mapFilename, "rb")) == NULL) {
-		fprintf(stderr,
-		"Could not open mapfile '%s' for reading.\n",
-		mapFilename);
-		return 3;
-	}
-	
-	processMap(inFile, outFile);
-	
-	fclose(inFile);
+	processMapHTML(outFile, inFile);
 	
 	/* Another table */
-	fprintf(stderr, "Building descs...\n");
 	fprintf(outFile,
 	"   </pre>\n"
 	"  </td>\n"
@@ -404,9 +325,9 @@
 	"   <table>\n"
 	"    <tr>\n"
 	);
-	
-	printBlock(outFile, 0, nlocations/2 - 1);
-	printBlock(outFile, nlocations/2, nlocations - 1);
+
+	printBlockHTML(outFile, 0, nlocations/2 - 1);
+	printBlockHTML(outFile, nlocations/2, nlocations - 1);
 	
 	/* XHTML document end tags */
 	fprintf(outFile,
@@ -418,7 +339,138 @@
 	"</body>\n"
 	"</html>\n"
 	);
+}
+
+
+void outputASCII(FILE *outFile, FILE *inFile, DCHAR *mapTitle)
+{
+	DINT c, n, m;
+	DCHAR fmt[32];
+	 
+	/* Output title */
+	fprintf(outFile, "%s\n\n", mapTitle);
 	
+	/* Process input, convert to map */
+	while ((c = fgetc(inFile)) != EOF) {
+		fputc(c, outFile);
+	}
+	
+	fprintf(outFile, "\n");
+	
+	/* Find max width of location descs */
+	for (m = 0, n = 0; n < nlocations; n++) {
+		c = strlen(locations[n].desc);
+		if (c > m) m = c;
+	}
+	
+	sprintf(fmt, "%%c %%-%ds | ", m);
+	
+	/* Print location lists */
+	m = (nlocations / 2);
+	for (n = 0; n < m; n++) {
+		c = m + n;
+		fprintf(outFile, fmt,
+		locations[n].c, locations[n].desc);
+		
+		if (c < nlocations) {
+			fprintf(outFile, "%c %s",
+			locations[c].c, locations[c].desc);
+		}
+		
+		fprintf(outFile, "\n");
+	}
+
+	fprintf(outFile, "\n");
+}
+
+
+DINT parseLocFile(char *pcFilename)
+{
+	FILE *inFile;
+	DCHAR s[4096];
+	size_t i, j, k;
+	
+	if ((inFile = fopen(pcFilename, "rb")) == NULL) {
+		fprintf(stderr, "Could not open file '%s' for reading.\n",
+			pcFilename);
+		return -1;
+	}
+	
+	while (!feof(inFile)) {
+		s[0] = 0;
+		fgets(s, sizeof(s), inFile);
+		
+		if (strlen(s) > 3) {
+			i = 1;
+			
+			th_findnext(s, &i);
+			j = i;
+			
+			while (s[i] && s[i] != '[' && !th_iscrlf(s[i])) i++;
+			
+			if (s[i] == '[') {
+				k = i;
+				
+				while (s[k] && s[k] != ']' && !th_iscrlf(s[k])) k++;
+				s[k] = 0;
+				s[i] = 0;
+				addLoc(s[0], &s[j], &s[i+1]);
+			} else {
+				s[i] = 0;
+				addLoc(s[0], &s[j], NULL);
+			}
+			
+		}
+	}
+	
+	fclose(inFile);
+	
+	return 0;
+}
+
+
+DINT main(DINT argc, DCHAR *argv[])
+{
+	FILE *inFile, *outFile;
+	DCHAR *mapTitle, *mapFilename, *descFilename;
+	
+	if (argc < 4) {
+		fprintf(stderr,
+		"Usage: %s \"<title>\" mapfile descfile > outfile\n",
+		argv[0]);
+		return 0;
+	}
+	
+	outFile = stdout;
+	mapTitle = argv[1];
+	mapFilename = argv[2];
+	descFilename = argv[3];
+	
+	/* Parse desc file */
+	if (parseLocFile(descFilename) < 0) {
+		fprintf(stderr,
+		"Could not properly parse desc file '%s'\n",
+		descFilename);
+		return 3;
+	}
+
+	/* Open mapfile */
+	if ((inFile = fopen(mapFilename, "rb")) == NULL) {
+		fprintf(stderr,
+		"Could not open mapfile '%s' for reading.\n",
+		mapFilename);
+		return 3;
+	}
+	
+	/* Output data */
+	if ((argc > 4) && !strcmp(argv[4], "-ascii")) {
+		outputASCII(outFile, inFile, mapTitle);
+	} else {
+		outputHTML(outFile, inFile, mapTitle);
+	}
+	
+	/* Close input and output files */
+	fclose(inFile);
 	fclose(outFile);
 	
 	return 0;