Rev 539 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2007 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* Author: Steve Ratcliffe
* Create date: Dec 16, 2007
*/
package test.display;
import java.util.List;
import uk.me.parabola.imgfmt.app.Label;
import uk.me.parabola.imgfmt.app.trergn.Subdivision;
import test.elements.Point;
/**
* Standalone program to display the NET file as it is worked out. Will start
* out with what is in imgdecode by John Mechalas.
*
* Can produce a massive file, so may take some time to write.
*
* @author Steve Ratcliffe
*/
public class LblDisplay
extends CommonDisplay
{
private Section cities
;
private Section regions
;
private Section countries
;
protected void print
() {
openLbl
();
openTre
();
openRgn
();
readCommonHeader
();
readHeader
();
printCities
();
printCountries
();
printRegions
();
}
private void readHeader
() {
Displayer d =
new Displayer
(reader
);
d.
setTitle("LBL header");
long start = reader.
position();
readSection
(d,
"LBL 1 (labels)",
1,
false,
false);
DisplayItem item = d.
item();
int offsetShift = item.
setBytes1(reader.
get1u());
item.
addText("Label offsets x%d",
1 << offsetShift
);
d.
byteValue("Label coding %d");
countries = readSection
(d,
"LBL 2 countries",
2,
true,
true);
regions = readSection
(d,
"LBL 3 regions",
3,
true,
true);
cities = readSection
(d,
"LBL 4 cities",
4,
true,
true);
readSection
(d,
"LBL 5 poi index",
5,
true,
true);
readSection
(d,
"LBL 6 poi properties",
6,
false,
false);
d.
byteValue("unk %d");
d.
byteValue("POI global properties %x");
d.
int3Value("unk %x");
readSection
(d,
"LBL 7 poi types",
7,
true,
true);
readSection
(d,
"LBL 8 zips",
8,
true,
true);
readSection
(d,
"LBL 9 highways",
9,
true,
true);
readSection
(d,
"LBL 10 exits",
10,
true,
true);
readSection
(d,
"LBL 11 highway data",
11,
true,
true);
d.
charValue("code page %d");
d.
intValue("unk");
readSection
(d,
"Sort descriptor",
12,
false,
false);
readSection
(d,
"LBL 12 unknown",
12,
false,
true);
if (getHeaderLen
() > 196) {
readSection
(d,
"LBL 13",
13,
false,
true);
readSection
(d,
"LBL 14",
14,
true,
true);
readSection
(d,
"LBL 15",
15,
true,
true);
}
if (getHeaderLen
() > 236) {
readSection
(d,
"LBL 16",
16,
true,
true);
readSection
(d,
"LBL 17",
17,
true,
true);
readSection
(d,
"LBL 18",
18,
true,
true);
readSection
(d,
"LBL 19",
19,
true,
true);
readSection
(d,
"LBL 20",
20,
true,
true);
readSection
(d,
"LBL 21",
21,
true,
true);
readSection
(d,
"LBL 22",
22,
true,
true);
readSection
(d,
"LBL 23",
23,
false,
true);
readSection
(d,
"LBL 24",
24,
true,
true);
readSection
(d,
"LBL 25",
25,
true,
true);
readSection
(d,
"LBL 26",
26,
true,
true);
readSection
(d,
"LBL 27",
27,
true,
true);
readSection
(d,
"LBL 28",
28,
false,
false);
}
int len = getHeaderLen
() - COMMON_HEADER_LEN
;
d.
rawValue((int) (len -
(reader.
position() - start
)));
d.
print(outStream
);
//analyze(outStream);
}
private void printCities
() {
Displayer d =
new Displayer
(reader
);
d.
setTitle("Cities");
int start =
(int) cities.
getStart();
reader.
position(start
);
int ncity =
1;
int end =
(int) cities.
getEnd();
while (reader.
position() < end
) {
DisplayItem cityItem = d.
int3Item();
DisplayItem regItem = d.
charItem();
int reg = regItem.
getValue();
if ((reg
& 0x8000
) ==
0) {
int off = cityItem.
getValue();
cityItem.
addText("City %d: label %x: %s", ncity, off, lbl.
fetchLabel(off
));
} else {
Subdivision
[] subdivisions = tre.
subdivForLevel(0);
int value = cityItem.
getValue();
int subdiv =
(value
>>> 8) & 0xffff
;
int point = value
& 0xff
;
int number = subdivisions
[0].
getNumber();
Subdivision subdivision = subdivisions
[subdiv - number
];
List<Point> points = rgn.
pointsForSubdiv(subdivision
);
Point p = points.
get(point-
1);
Label label = p.
getLabel();
cityItem.
addText("City %d: idx div/point=%d/%d %s", ncity, subdiv,
point, label.
getText());
}
if ((reg
& 0x4000
) ==
0) {
regItem.
addText("Region %d", reg
& 0x3fff
);
} else {
regItem.
addText("Country %d", reg
& 0x3fff
);
}
ncity++
;
d.
print(outStream
);
d.
setTitle(null);
}
d.
print(outStream
);
}
private void printRegions
() {
Displayer d =
new Displayer
(reader
);
d.
setTitle("Regions");
int start =
(int) regions.
getStart();
reader.
position(start
);
int nRegion =
1;
int end =
(int) regions.
getEnd();
while (reader.
position() < end
) {
DisplayItem countryItem = d.
charItem();
DisplayItem regionItem = d.
int3Item();
int off = regionItem.
getValue();
regionItem.
addText("Region %d: label %x: %s", nRegion, off, lbl.
fetchLabel(off
));
countryItem.
addText("Country %d", countryItem.
getValue());
nRegion++
;
d.
print(outStream
);
d.
setTitle(null);
}
d.
print(outStream
);
}
private void printCountries
() {
Displayer d =
new Displayer
(reader
);
d.
setTitle("Countries");
int start =
(int) countries.
getStart();
reader.
position(start
);
int nCountry =
1;
int end =
(int) countries.
getEnd();
while (reader.
position() < end
) {
DisplayItem countryItem = d.
int3Item();
int off = countryItem.
getValue();
countryItem.
addText("Country %d: label %x: %s", nCountry, off, lbl.
fetchLabel(off
));
nCountry++
;
d.
print(outStream
);
d.
setTitle(null);
}
d.
print(outStream
);
}
public static void main
(String[] args
) {
if (args.
length < 1) {
System.
err.
println("Usage: lbldisplay <filename>");
System.
exit(1);
}
String name = args
[0];
CommonDisplay nd =
new LblDisplay
();
nd.
display(name,
"LBL");
}
}