Hi

It's a bug that occurs when you have type file.  I don't think that the type 
file has a sort order field (though I must check since I'd not considered that 
untilled just now).

I guess that it would be good if the file name could be printed when this 
happens.

I'll post a patch later

Patch attached which fixes this and will properly warn if the
TYP file has the wrong code page.

..Steve
Index: src/uk/me/parabola/mkgmap/combiners/GmapsuppBuilder.java
===================================================================
--- src/uk/me/parabola/mkgmap/combiners/GmapsuppBuilder.java	(revision 2309)
+++ src/uk/me/parabola/mkgmap/combiners/GmapsuppBuilder.java	(working copy)
@@ -114,15 +114,18 @@
 	/**
 	 * Add the sort file for the given family id.
 	 */
-	private void addSrtFile(int familyId, Sort sort) {
-		Sort s = sortMap.get(familyId);
-		if (s == null)
+	private void addSrtFile(int familyId, FileInfo info) {
+		Sort prevSort = sortMap.get(familyId);
+		Sort sort = info.getSort();
+		if (prevSort == null) {
 			sortMap.put(familyId, sort);
-		else {
-			if (s.getCodepage() != sort.getCodepage())
-				System.err.println("WARNING: input files have differing code pages");
-			if (s.getSortOrderId() != sort.getSortOrderId())
-				System.err.println("WARNING: input files have differing sort orders");
+		} else {
+			if (prevSort.getCodepage() != sort.getCodepage())
+				System.err.printf("WARNING: input file '%s' has a different code page (%d rather than %d)\n",
+						info.getFilename(), sort.getCodepage(), prevSort.getCodepage());
+			if (info.hasSortOrder() && prevSort.getSortOrderId() != sort.getSortOrderId())
+				System.err.printf("WARNING: input file '%s' has a different sort order (%x rather than %x\n",
+						info.getFilename(), sort.getSortOrderId(), prevSort.getSortOrderId());
 		}
 	}
 
@@ -141,7 +144,7 @@
 			mdrBuilder.onMapEnd(info);
 		}
 
-		addSrtFile(familyId, info.getSort());
+		addSrtFile(familyId, info);
 	}
 
 	/**
Index: src/uk/me/parabola/mkgmap/combiners/FileInfo.java
===================================================================
--- src/uk/me/parabola/mkgmap/combiners/FileInfo.java	(revision 2309)
+++ src/uk/me/parabola/mkgmap/combiners/FileInfo.java	(working copy)
@@ -26,6 +26,7 @@
 import uk.me.parabola.imgfmt.FileSystemParam;
 import uk.me.parabola.imgfmt.Utils;
 import uk.me.parabola.imgfmt.app.Area;
+import uk.me.parabola.imgfmt.app.BufferedImgFileReader;
 import uk.me.parabola.imgfmt.app.lbl.LBLFileReader;
 import uk.me.parabola.imgfmt.app.srt.Sort;
 import uk.me.parabola.imgfmt.app.trergn.TREFileReader;
@@ -33,6 +34,7 @@
 import uk.me.parabola.imgfmt.fs.DirectoryEntry;
 import uk.me.parabola.imgfmt.fs.FileSystem;
 import uk.me.parabola.imgfmt.fs.ImgChannel;
+import uk.me.parabola.imgfmt.sys.FileImgChannel;
 import uk.me.parabola.imgfmt.sys.ImgFS;
 import uk.me.parabola.log.Logger;
 import uk.me.parabola.mkgmap.CommandArgs;
@@ -172,13 +174,34 @@
 
 		// Get the size of the file.
 		File f = new File(inputName);
-		long length = f.length();
-		info.fileSizes.add((int) length);
+		info.fileSizes.add((int) f.length());
 
+		if (inputName.toLowerCase().endsWith(".lbl")) {
+			lblInfo(inputName, info);
+		} else if (inputName.toLowerCase().endsWith(".typ")) {
+			typInfo(inputName, info);
+		}
+
 		return info;
 	}
 
 	/**
+	 * Read information from the TYP file that we might need when combining it with other files.
+	 * @param filename The name of the file.
+	 * @param info The information will be stored here.
+	 */
+	private static void typInfo(String filename, FileInfo info) {
+		ImgChannel chan = new FileImgChannel(filename, "r");
+		try {
+			BufferedImgFileReader fr = new BufferedImgFileReader(chan);
+			fr.position(0x15);
+			info.setCodePage(fr.getChar());
+		} finally {
+			Utils.closeFile(chan);
+		}
+	}
+
+	/**
 	 * An IMG file, this involves real work. We have to read in the file and
 	 * extract several pieces of information from it.
 	 *
@@ -284,19 +307,26 @@
 	 * Obtain the information we need from a LBL file.
 	 */
 	private static void lblInfo(FileSystem imgFs, DirectoryEntry ent, FileInfo info) throws FileNotFoundException {
-		LBLFileReader lblFile = null;
+		ImgChannel chan = imgFs.open(ent.getFullName(), "r");
+		lblInfo(chan, info);
+	}
+
+	private static void lblInfo(String filename, FileInfo info) {
+		FileImgChannel r = new FileImgChannel(filename, "r");
 		try {
-			ImgChannel chan = imgFs.open(ent.getFullName(), "r");
-			lblFile = new LBLFileReader(chan);
-
-			info.setCodePage(lblFile.getCodePage());
-			info.setSortOrderId(lblFile.getSortOrderId());
-
+			lblInfo(r, info);
 		} finally {
-			Utils.closeFile(lblFile);
+			Utils.closeFile(r);
 		}
 	}
 
+	private static void lblInfo(ImgChannel chan, FileInfo info) {
+		LBLFileReader lblFile = new LBLFileReader(chan);
+
+		info.setCodePage(lblFile.getCodePage());
+		info.setSortOrderId(lblFile.getSortOrderId());
+	}
+
 	private void setBounds(Area area) {
 		this.bounds = area;
 	}
@@ -448,11 +478,11 @@
 		this.codePage = codePage;
 	}
 
-	public int getSortOrderId() {
-		return sortOrderId;
-	}
-
 	public void setSortOrderId(int sortOrderId) {
 		this.sortOrderId = sortOrderId;
 	}
+
+	public boolean hasSortOrder() {
+		return sortOrderId != 0;
+	}
 }
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to