summaryrefslogtreecommitdiff
path: root/navit/script
diff options
context:
space:
mode:
authorlains <lains@caramail.com>2018-11-18 22:59:14 +0100
committerPierre GRANDIN <pgrandin@users.noreply.github.com>2018-11-18 13:59:14 -0800
commite70a28963ff9754d3257361fad93aebf59edee08 (patch)
tree07a97ee212611ff4d1156baf87b8744f5d2b9ba4 /navit/script
parentb0773218ab67e00e1aa7303829f342dce87c46c0 (diff)
downloadnavit-e70a28963ff9754d3257361fad93aebf59edee08.tar.gz
Refactoring:Xmlconfig:Moving layout definition in their own .xml file (makes main navit.xml file lighter) (#559)
Layouts contain quite heavy xml code, and there are many layouts available for navit. They are all inserted inside the main navit.xml, which makes it hard to edit because of its size, even if changes or customizations by users are very rarely on the layout code. I have thus moved the layout code away from navit.xml, each layout having its own xml definition file, called navit_layout_*.xml These files are inserted inside the main navit.xml file by using the already existing xi:include mechanism, this also allow for backwards compatibility (old monolithic navit.xml files are still valid and can be used). The other advantage for this is that f the user wants to have his/her own customized navit.xml, he/she can still include the shipped layout files, making their xml lighter. This also allow to enable/disable specific layouts easily by including or not each layout file. It is also easier to perform side-by-side comparison between two layout files.
Diffstat (limited to 'navit/script')
-rwxr-xr-xnavit/script/check_itemdef42
-rwxr-xr-xnavit/script/itemgra.pl92
2 files changed, 78 insertions, 56 deletions
diff --git a/navit/script/check_itemdef b/navit/script/check_itemdef
deleted file mode 100755
index 61ea1cb29..000000000
--- a/navit/script/check_itemdef
+++ /dev/null
@@ -1,42 +0,0 @@
-#! /bin/sh
-function check_item_def
-{
- grep -q "[(,]$1)" ../item_def.h || echo "$1 missing"
-}
-
-function check_item_xml
-{
- grep -q "^$1\$" check.$$ || echo "$1 will not be rendered"
-}
-
-
-awk '/<layout name="Car"/,/<\/layout/ { if (/<itemgra/) {print $0} }' < ../navit.xml | sed 's/.*item_types="\([^"]*\)".*/\1/' | tr "," "\012" | sort -u >check.$$
-echo item_def.h
-grep "^ITEM" ../item_def.h | sed -e "s/ITEM(\(.*\))/\1/" -e "s/ITEM2([^,]*,\(.*\))/\1/" |
-while read -r x
-do
- check_item_xml "$x"
-done
-
-rm -f check.$$
-echo maptool.c
-egrep '^ "[nw] +[^ ]+ +[^ ]+' ../maptool.c | sed "s/.* //" | sort -u |
-while read -r x
-do
- check_item_def "${x%%\\n\"}"
-done
-
-echo "navit.xml"
-grep '<itemgra item_types="' <../navit.xml | cut -d \" -f 2 | tr "," "\012" |
-while read -r x
-do
- check_item_def "$x"
-done
-
-echo "garmintypes.txt"
-grep "^[0-9]" ../map/garmin/garmintypes.txt | sed -e 's/[A-Z][A-Z]*, //' -e 's/.*= \([^,]*\),.*/\1/' | sort -u |
-while read -r x
-do
- check_item_def "$x"
-done
-
diff --git a/navit/script/itemgra.pl b/navit/script/itemgra.pl
index bbe02b000..54a08225c 100755
--- a/navit/script/itemgra.pl
+++ b/navit/script/itemgra.pl
@@ -1,25 +1,69 @@
#! /usr/bin/perl
+
+# This script parses the XML config file and checks if known itemgra elements are defined or not in each layout
+# Run ./itemgra.pl 2>/dev/null to get only the result without parsing information messages
my $layout;
my $type,$types;
+my $garmintypes;
my $order,$orders,@orders;
my @layouts;
-open(IN,"../navit.xml");
-while (<IN>) {
- if (/<layout name="([^"]*)"/) {
- $layout=$1;
- push(@layouts,$layout);
- }
- if (/<itemgra item_types="([^"]*)"/) {
- $types=$1;
- if (/order="([^"]*)"/) {
- $order=$1;
- foreach $type (split(",",$types)) {
- $result->{$type}->{$layout}->{$order}=1;
+my $input_stream;
+my @input_stream_stack;
+my $current_filename = "../navit_shipped.xml";
+if (!open($input_stream,$current_filename)) {
+ print(STDERR "Failed to open \"" . $current_filename . "\"\n");
+ exit(1);
+}
+while(defined($input_stream)) {
+ #printf("%d input streams in file recursion stack. Current input stream is " . $input_stream . "\n", $#input_stream_stack+1);
+ while (<$input_stream>) {
+ #print($_);
+ if (/<layout name="([^"]*)"/) {
+ $layout=$1;
+ push(@layouts,$layout);
+ }
+ if (/<xi:include href="([^"]*)"/) {
+ my $xml_include_file;
+ $xml_include_file=$1;
+ if ($xml_include_file =~ /^[\/\$]/) { # PATH is absolute or starts with a variable... do not modify PATH
+ }
+ $xml_include_file =~ s@^@../@; # Make PATH relative to ../ (navit XML config is in parent
+ if ($xml_include_file =~ /.*maps\/\*\.xml$/) { # Skip mapsets that use wildcards
+ }
+ else {
+ push(@input_stream_stack, $input_stream);
+ $input_stream = undef;
+ print(STDERR "Opening included file \"" . $xml_include_file . "\"\n");
+ if (!open($input_stream, $xml_include_file)) {
+ $xml_include_file =~ s/\.xml$/_shipped.xml/; # If file does not exist, try suffixing the filename with _shipped
+ print(SDTERR "Opening included file \"" . $xml_include_file . "\"\n");
+ if (!open($input_stream, $xml_include_file)) {
+ print(STDERR "Failed to open \"" . $xml_include_file . "\"\n");
+ exit(1);
+ }
+ }
+ $current_filename = $xml_include_file;
+ #printf("%d input streams in file recursion stack. Current input stream is " . $input_stream . "\n", $#input_stream_stack+1);
+ next;
+ }
+ }
+ if (/<itemgra item_types="([^"]*)"/) {
+ $types=$1;
+ if (/order="([^"]*)"/) {
+ $order=$1;
+ print(STDERR "Order $order found in \"" . $current_filename . "\"\n");
+ foreach $type (split(",",$types)) {
+ $result->{$type}->{$layout}->{$order}=1;
+ }
}
}
}
+ close($input_stream);
+ $input_stream = pop(@input_stream_stack);
+ #print("Popped input stream " . $input_stream . "\n");
}
-close(IN);
+print(STDERR "Finished parsing navit XML config\n");
+print(STDERR "Parsing item_def.h\n");
open(IN,"../item_def.h");
while (<IN>) {
if (/^ITEM2\([^,]*,(.*)\)/) {
@@ -32,13 +76,26 @@ while (<IN>) {
}
}
close(IN);
+print(STDERR "Parsing ../map/garmin/garmintypes.txt\n");
+open(IN,"../map/garmin/garmintypes.txt");
+while (<IN>) {
+ if (/^[0-9][^=]*=\s*([^,]*),.*$/) {
+ $type=$1;
+ print("Garmintype: " . $type . "\n");
+ $garmintypes->{$type}->{"none"}=1;
+ }
+}
+close(IN);
+
+print(STDERR "Outputting results\n");
my $typefmt="%-30s";
my $layoutfmt="%10s";
printf($typefmt,"");
foreach $layout (@layouts) {
printf($layoutfmt,$layout);
}
-printf("\n");
+print("\n");
+# Check which map items defined in ../item_def.h are actually handled by each layout
foreach $type (sort keys %$result) {
$marker="";
if (!$result->{$type}->{"none"}) {
@@ -55,3 +112,10 @@ foreach $type (sort keys %$result) {
}
printf("\n");
}
+
+print("Analysis on ../map/garmin/garmintypes.txt:\n");
+foreach $type (sort keys %$garmintypes) {
+ if (!$result->{$type}->{"none"}) {
+ print($type . " exists in garmintypes.txt and missing in itemdef.h\n");
+ }
+} \ No newline at end of file