mirror of
https://expo.survex.com/repositories/expoweb/.git/
synced 2025-12-08 14:54:28 +00:00
[svn r5753] Comments improved
Usage message displayed Directory creation bug fixed
This commit is contained in:
@@ -1,29 +1,37 @@
|
|||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
use strict;
|
use strict;
|
||||||
|
use File::Path;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
|
||||||
# no file made for 1996-01 (e.g.) Fix it.
|
# no_info col is redundant. FIXME
|
||||||
# 136 ents are in 161. why?
|
# WTF is dl compact?
|
||||||
# no_info col is redundant
|
|
||||||
|
|
||||||
((my $progname = $0) =~ s/^.*(\/|\\)//ig); # basename $0
|
((my $progname = $0) =~ s/^.*(\/|\\)//ig); # basename $0
|
||||||
|
|
||||||
|
# Parse options
|
||||||
my $no_verbose_progress = 0;
|
my $no_verbose_progress = 0;
|
||||||
#if ($ARGV[1]) {
|
my $usage = 0;
|
||||||
# if ($ARGV[1] eq "-q") {
|
GetOptions('quiet' => \$no_verbose_progress, # be quiet
|
||||||
# $verbose_progress = undef;
|
'help|?' => \$usage # help!
|
||||||
# }
|
);
|
||||||
#}
|
|
||||||
GetOptions(q => \$no_verbose_progress);
|
# Print usage
|
||||||
|
if ($usage) {
|
||||||
|
print << "EOF";
|
||||||
|
USAGE: $progname [-options] <CSV file>
|
||||||
|
-q, --quiet Be quiet about progress
|
||||||
|
-h, --help Show this message
|
||||||
|
EOF
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
unless ($ARGV[0]) {
|
unless ($ARGV[0]) {
|
||||||
print "Specify a CSV file name as the first argument (e.g. CAVETAB2.CSV)\n";
|
print "Specify a CSV file name (e.g. CAVETAB2.CSV)\n";
|
||||||
die $!;
|
die $!;
|
||||||
}
|
}
|
||||||
|
|
||||||
open (CSV, "< $ARGV[0]");
|
open (CSV, "< $ARGV[0]");
|
||||||
|
|
||||||
|
|
||||||
# Start writing index file
|
# Start writing index file
|
||||||
open IDXALL, ">..\/indxal.htm" or die $!;
|
open IDXALL, ">..\/indxal.htm" or die $!;
|
||||||
print IDXALL << "END";
|
print IDXALL << "END";
|
||||||
@@ -59,6 +67,7 @@ while (<CSV>) {
|
|||||||
do_this_line($_, "cave");
|
do_this_line($_, "cave");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Finish writing index file
|
||||||
print IDXALL << "END";
|
print IDXALL << "END";
|
||||||
</table>
|
</table>
|
||||||
<!--</dl>-->
|
<!--</dl>-->
|
||||||
@@ -105,10 +114,17 @@ END
|
|||||||
close IDXALL;
|
close IDXALL;
|
||||||
print "Information: Done\n";
|
print "Information: Done\n";
|
||||||
|
|
||||||
|
# Process a line of the CSV file
|
||||||
|
# First argument is contents of line to process
|
||||||
|
# Second argument is "cave" or "entrance"
|
||||||
|
# 3rd arg is the Kataster number of the cave an entrance belongs to (optional)
|
||||||
|
# 4th arg is the Other number of the cave an entrance belongs to (optional)
|
||||||
|
# Returns nothing
|
||||||
sub do_this_line {
|
sub do_this_line {
|
||||||
# Split single line into all the fields
|
# Split single line into all the fields
|
||||||
my ($kat_num, $kat_status, $ents, $other_number, $mult_ents, $file, $linkfile, $name, $unofficial_name, $comment, $area, $no_info, $explorers, $u_description, $equipment, $qmlist, $katstatus, $references, $u_centre_line, $u_drawn_survey, $survex_file, $length, $depth, $extent, $header, $footer, $notes, $ent_name, $tag_punkt, $other_punkt, $desc_other_punkt, $exact_punkt, $fix_type, $gpspresa, $gpspostsa, $northing, $easting, $altitude, $bearings, $map, $location, $approach, $ent_desc, $ent_photo, $marking) = &parse_csv($_[0]);
|
my ($kat_num, $kat_status, $ents, $other_number, $mult_ents, $file, $linkfile, $name, $unofficial_name, $comment, $area, $no_info, $explorers, $u_description, $equipment, $qmlist, $katstatus, $references, $u_centre_line, $u_drawn_survey, $survex_file, $length, $depth, $extent, $header, $footer, $notes, $ent_name, $tag_punkt, $other_punkt, $desc_other_punkt, $exact_punkt, $fix_type, $gpspresa, $gpspostsa, $northing, $easting, $altitude, $bearings, $map, $location, $approach, $ent_desc, $ent_photo, $marking) = &parse_csv($_[0]);
|
||||||
|
|
||||||
|
# If we have been called to process an entrance, we may have been given the cave's Kataster number or Other number
|
||||||
if ($_[2] and ! $kat_num) {
|
if ($_[2] and ! $kat_num) {
|
||||||
$kat_num = $_[2];
|
$kat_num = $_[2];
|
||||||
}
|
}
|
||||||
@@ -134,6 +150,7 @@ sub do_this_line {
|
|||||||
}
|
}
|
||||||
$toroot =~ s/Q\///;
|
$toroot =~ s/Q\///;
|
||||||
|
|
||||||
|
# If it's a cave, then insert it in the index file
|
||||||
if ($_[1] eq "cave") {
|
if ($_[1] eq "cave") {
|
||||||
my $e = $ents;
|
my $e = $ents;
|
||||||
$e =~ s/ +/ /g;
|
$e =~ s/ +/ /g;
|
||||||
@@ -164,8 +181,10 @@ sub do_this_line {
|
|||||||
print IDXALL "</tr>\n";
|
print IDXALL "</tr>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If the cave does not have a filename allocated, but does have multiple entrances, keep going through the CSV file until we are at the last entrance, before we return
|
||||||
unless ($file) { # this IS necessary
|
unless ($file) { # this IS necessary
|
||||||
if ($mult_ents eq "yes") {
|
if ($mult_ents eq "yes") {
|
||||||
|
print "hello $kat_num $other_number\n";
|
||||||
my $e_mult_ents;
|
my $e_mult_ents;
|
||||||
do {
|
do {
|
||||||
my $e = <CSV>;
|
my $e = <CSV>;
|
||||||
@@ -177,14 +196,24 @@ sub do_this_line {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If command line option is set, then be quiet
|
||||||
unless ($no_verbose_progress) {
|
unless ($no_verbose_progress) {
|
||||||
print "Progress: $file\n";
|
print "Progress: $file\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Magic number processing
|
||||||
$number =~ s/\//-/g;
|
$number =~ s/\//-/g;
|
||||||
$number =~ s/\?/q/;
|
$number =~ s/\?/q/;
|
||||||
open FILE, "> $file" or die $!;
|
|
||||||
|
|
||||||
|
# Make the directory that the file is in, in case it doesn't exist yet
|
||||||
|
my $fn = $file;
|
||||||
|
$fn =~ s/^.*\///g;
|
||||||
|
my $path = $file;
|
||||||
|
$path =~ s/\/$fn//g;
|
||||||
|
mkpath($path);
|
||||||
|
|
||||||
|
# Open the file and start writing to it
|
||||||
|
open FILE, "> $file" or die $!;
|
||||||
print FILE << "END";
|
print FILE << "END";
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
||||||
<!-- *** This file is auto-generated by $progname - edit cavetab2.csv instead -->
|
<!-- *** This file is auto-generated by $progname - edit cavetab2.csv instead -->
|
||||||
@@ -258,6 +287,7 @@ END
|
|||||||
print FILE "<b>Entrance:</b>\n<br>\n";
|
print FILE "<b>Entrance:</b>\n<br>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# Process the location data for the entrance
|
||||||
do_ent($tag_punkt,$other_punkt,$exact_punkt,$gpspostsa,$gpspresa,$easting,$northing,$altitude,$ent_name,$fix_type,$desc_other_punkt);
|
do_ent($tag_punkt,$other_punkt,$exact_punkt,$gpspostsa,$gpspresa,$easting,$northing,$altitude,$ent_name,$fix_type,$desc_other_punkt);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -324,6 +354,7 @@ END
|
|||||||
print FILE "\n<p>$footer";
|
print FILE "\n<p>$footer";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Find the area the cave is in, and add appropriate links
|
||||||
if ($area =~ /(1a|1b|1c|1d)/) {
|
if ($area =~ /(1a|1b|1c|1d)/) {
|
||||||
print FILE "\n<img alt=\">\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
|
print FILE "\n<img alt=\">\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
|
||||||
print FILE "\n<a href=\"$toroot\/plateau\/index.htm#$number\">Plateau area index and description</a><br>";
|
print FILE "\n<a href=\"$toroot\/plateau\/index.htm#$number\">Plateau area index and description</a><br>";
|
||||||
@@ -371,9 +402,10 @@ END
|
|||||||
}
|
}
|
||||||
unless ($area) {
|
unless ($area) {
|
||||||
print FILE "\n<img alt=\">\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
|
print FILE "\n<img alt=\">\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
|
||||||
print FILE "\n<a href=\"javascript:history.back(1)\">Go Back (Javascript)</a><br>";
|
print FILE "\n<a href=\"javascript:history.back(1)\">Go Back (Javascript)</a><br>"; # ACCK! ACCK! Evil JavaScript!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Finish writing to file
|
||||||
print FILE << "END";
|
print FILE << "END";
|
||||||
<img alt=">" src="$toroot/../icons/lists/0.png">
|
<img alt=">" src="$toroot/../icons/lists/0.png">
|
||||||
<a href="$toroot/indxal.htm#$number">Full Index</a><br>
|
<a href="$toroot/indxal.htm#$number">Full Index</a><br>
|
||||||
@@ -389,6 +421,9 @@ END
|
|||||||
close FILE;
|
close FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Parse a line of CSV data
|
||||||
|
# Argument is the line of data to be processed
|
||||||
|
# Returns array of the separated variables
|
||||||
sub parse_csv {
|
sub parse_csv {
|
||||||
my $line = $_[0];
|
my $line = $_[0];
|
||||||
my @parsedline = ();
|
my @parsedline = ();
|
||||||
@@ -411,6 +446,8 @@ sub parse_csv {
|
|||||||
return(@parsedline);
|
return(@parsedline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Process the location data for the entrance
|
||||||
|
# Returns nothing
|
||||||
sub do_ent {
|
sub do_ent {
|
||||||
my $punkt;
|
my $punkt;
|
||||||
my $calc_easting;
|
my $calc_easting;
|
||||||
@@ -503,6 +540,12 @@ sub do_ent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Handle multiple entrances
|
||||||
|
# 1st arg is the file name of the cave to which the entrance belongs
|
||||||
|
# 2nd arg is the Kataster number of the cave
|
||||||
|
# 3rd arg is the Other number of the cave (which may have been put in brackets)
|
||||||
|
# 4th arg is the Other number of the cave without any brackets
|
||||||
|
# 5th arg is the path to return to the root from the cave
|
||||||
sub multi_ents {
|
sub multi_ents {
|
||||||
my $file = $_[0];
|
my $file = $_[0];
|
||||||
my $kat_num = $_[1];
|
my $kat_num = $_[1];
|
||||||
@@ -514,6 +557,7 @@ sub multi_ents {
|
|||||||
print FILE "\n<p><b>Entrances:</b>\n<br>";
|
print FILE "\n<p><b>Entrances:</b>\n<br>";
|
||||||
my $e_mult_ents;
|
my $e_mult_ents;
|
||||||
|
|
||||||
|
# Process each entrance
|
||||||
do {
|
do {
|
||||||
my $e = <CSV>;
|
my $e = <CSV>;
|
||||||
chomp;
|
chomp;
|
||||||
@@ -526,19 +570,20 @@ sub multi_ents {
|
|||||||
|
|
||||||
print FILE "\n\n<li>";
|
print FILE "\n\n<li>";
|
||||||
|
|
||||||
if ($elinkfile) {
|
if ($elinkfile) { # this is a link to another cave - add link to entrance into cave file but don't generate another file for the entrance
|
||||||
print FILE "<a href=\"$toroot\/$elinkfile\">$eents $eother_number</a> ";
|
print FILE "<a href=\"$toroot\/$elinkfile\">$eents $eother_number</a> ";
|
||||||
do_this_line($e, "entrance", $kat_num, $other_number_no_brackets);
|
do_this_line($e, "entrance", $kat_num, $other_number_no_brackets);
|
||||||
} elsif ($efile) {
|
} elsif ($efile) { # call ourselves recursively to create a file for the entrance
|
||||||
print FILE "<a href=\"$toroot\/$efile\">$eents $eother_number</a> ";
|
print FILE "<a href=\"$toroot\/$efile\">$eents $eother_number</a> ";
|
||||||
close FILE; # perl filehandles are not recursively safe (when hacking at 4 in the morning). thus do this.
|
close FILE; # perl filehandles are not recursively safe (when hacking at 4 in the morning). thus do this.
|
||||||
|
|
||||||
do_this_line($e, "entrance", $kat_num, $other_number_no_brackets);
|
do_this_line($e, "entrance", $kat_num, $other_number_no_brackets);
|
||||||
open FILE, ">> $file" or die $!;
|
open FILE, ">> $file" or die $!;
|
||||||
} else {
|
} else { # no entrance file needed, and no link to another cave
|
||||||
print FILE "$eents $eother_number";
|
print FILE "$eents $eother_number";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Process the location data for the entrance
|
||||||
do_ent($etag_punkt,$eother_punkt,$eexact_punkt,$egpspostsa,$egpspresa,$eeasting,$enorthing,$ealtitude,$eent_name,$efix_type,$edesc_other_punkt);
|
do_ent($etag_punkt,$eother_punkt,$eexact_punkt,$egpspostsa,$egpspresa,$eeasting,$enorthing,$ealtitude,$eent_name,$efix_type,$edesc_other_punkt);
|
||||||
$e_mult_ents = $emult_ents;
|
$e_mult_ents = $emult_ents;
|
||||||
} while ($e_mult_ents ne "last entrance");
|
} while ($e_mult_ents ne "last entrance");
|
||||||
|
|||||||
Reference in New Issue
Block a user