2004-04-06 03:08:25 +01:00
#!/usr/bin/perl -w
use strict ;
2004-04-20 00:37:35 +01:00
use File::Path ;
2004-04-18 19:57:30 +01:00
use Getopt::Long ;
2004-04-06 03:08:25 +01:00
2004-04-22 11:26:19 +01:00
# no_info col is currently unused
2004-04-27 14:47:29 +01:00
# also, header never has any info...
2004-04-06 03:08:25 +01:00
( ( my $ progname = $ 0 ) =~ s/^.*(\/|\\)//ig ) ; # basename $0
2004-04-20 00:37:35 +01:00
# Parse options
2004-04-18 19:57:30 +01:00
my $ no_verbose_progress = 0 ;
2004-04-20 00:37:35 +01:00
my $ usage = 0 ;
GetOptions ( 'quiet' = > \ $ no_verbose_progress , # be quiet
2004-04-20 01:11:21 +01:00
'help' = > \ $ usage # help!
2004-04-20 00:37:35 +01:00
) ;
# Print usage
if ( $ usage ) {
2004-04-20 01:11:21 +01:00
usage ( ) ;
2004-04-20 00:37:35 +01:00
}
2004-04-18 19:57:30 +01:00
2004-04-06 03:08:25 +01:00
unless ( $ ARGV [ 0 ] ) {
2004-04-22 11:26:19 +01:00
print STDERR "Specify a CSV file name as the program's argument(e.g. CAVETAB2.CSV)\n" ;
2004-04-20 01:11:21 +01:00
usage ( ) ;
2004-04-06 03:08:25 +01:00
}
open ( CSV , "< $ARGV[0]" ) ;
# Start writing index file
2004-04-21 14:18:29 +01:00
open INDXAL , ">..\/indxal.htm" or die $! ;
print INDXAL << "END" ;
2004-04-21 22:49:22 +01:00
< ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
2004-04-06 03:08:25 +01:00
< ! - - ** * This file is auto - generated by $ progname - edit cavetab2 . csv instead - - >
2004-04-27 14:47:29 +01:00
< html lang = "en" xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" >
2004-04-06 03:08:25 +01:00
<head>
2004-04-21 22:49:22 +01:00
< meta http - equiv = "Content-Type" content = "text/html; charset=iso-8859-1" / >
2004-04-06 03:08:25 +01:00
<title> Loser Plateau area : Cave description index </title>
2004-04-21 22:49:22 +01:00
< link rel = "stylesheet" type = "text/css" href = "css/main2.css" / >
2004-04-06 03:08:25 +01:00
</head>
<body>
2004-04-21 22:49:22 +01:00
<h1> Kataster Gruppe 1623 : < br />Loser Augst-Eck - INDEX</ h1 >
2004-04-06 03:08:25 +01:00
2004-04-21 14:18:29 +01:00
< table border = "0" frame = "void" >
2004-04-06 03:08:25 +01:00
END
<CSV> ; # starting to read in csv file, eat header line
# Read in pos file to @pos now rather than later so we don't repeat it n times
2004-04-22 11:26:19 +01:00
open INPUT2 , "< all.pos" or print STDERR "Could not find all.pos in the current directory\n" and die $! ;
2004-04-06 03:08:25 +01:00
my @ pos = <INPUT2> ;
close INPUT2 ;
# Go down a directory
chdir ".." ;
# While loop which reads in each line of csv file
while ( <CSV> ) {
chomp ;
do_this_line ( $ _ , "cave" ) ;
}
2004-04-20 00:37:35 +01:00
# Finish writing index file
2004-04-21 14:18:29 +01:00
print INDXAL << "END" ;
2004-04-06 03:08:25 +01:00
</table>
< ! - - LINKS - - >
2004-04-27 14:47:29 +01:00
< hr / > <ul>
2004-04-21 22:49:22 +01:00
<li> Back to < a href = "../index.htm" > CUCC Home page </a> </li>
<li> Back to < a href = "index.htm" > Expedition Intro page </a> </li>
<li>
<h3> Main Indices: </h3>
<ul> <li> < a href = "infodx.htm" > <b> Index </b> to Expo </a> information pages </li>
<li> < a href = "areas.htm" > Description of CUCC ' s area </a> and split to subareas </li>
<li> List of ( links to ) < a href = "pubs.htm" > published reports and logbooks </a> </li> </ul>
</li>
<li>
<h3> Pictures: </h3>
<ul> <li> < a href = "gall0.htm" > Text only Index </a> </li>
<li> < a href = "gallery/0.htm" > Index pages ( with thumbnails ) </a> </li> </ul>
</li>
<li>
<h3> Other info: </h3>
<ul> <li> Table of < a href = "folk/index.htm" > members of CUCC expeditions </a> 1976 - 99 </li>
<li> < a href = "others/index.htm" > Other groups </a> who have worked in the area . </li>
<li> < a href = "1626/index.htm" > Adjacent area 1626 </a> </li> </ul>
</li>
</ul>
2004-04-21 14:18:29 +01:00
< ! - - / LINKS - - >
2004-04-06 03:08:25 +01:00
</body>
</html>
END
2004-04-21 14:18:29 +01:00
close INDXAL ;
2004-04-06 03:08:25 +01:00
print "Information: Done\n" ;
2004-04-20 00:37:35 +01:00
# 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
2004-04-06 03:08:25 +01:00
sub do_this_line {
# 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 ] ) ;
2004-04-20 00:37:35 +01:00
# If we have been called to process an entrance, we may have been given the cave's Kataster number or Other number
2004-04-06 03:08:25 +01:00
if ( $ _ [ 2 ] and ! $ kat_num ) {
$ kat_num = $ _ [ 2 ] ;
}
if ( $ _ [ 3 ] and ! $ other_number ) {
$ other_number = $ _ [ 3 ] ;
}
2004-04-22 12:20:31 +01:00
# Generate $linkid which will be kataster no., or other no. if no kataster no. present. Per HTML4 (and XHTML etc.) ID and NAME tokens must begin with alpha characters - hence "id" prepend
my $ linkid = "id$kat_num" ;
2004-04-06 03:08:25 +01:00
my $ other_number_no_brackets = $ other_number ;
if ( $ kat_num and $ other_number ) {
$ other_number = "($other_number)" ; # wrap it in brackets, so it doesn't appear to be official
} elsif ( $ other_number and ! $ kat_num ) {
2004-04-22 12:20:31 +01:00
$ linkid = "id$other_number" ;
2004-04-06 03:08:25 +01:00
}
2004-04-21 16:24:24 +01:00
# Under XHTML 1.0, link ids must not have '(', '?', ' ', or '/'
$ linkid =~ s/\//-/g ;
$ linkid =~ s/\?/q/ ;
$ linkid =~ s/\(/:/ ;
$ linkid =~ s/\)/:/ ;
$ linkid =~ s/ /_/ ;
2004-04-29 18:43:49 +01:00
$ linkid = lc ( $ linkid ) ;
2004-04-06 03:08:25 +01:00
# Determine the number of directorys deep the caves main page is at in order to link to area descriptions and indxal
my $ toroot = 'Q' ; # hey; it's magic
my $ counter = ( $ file =~ tr /\// / ) ;
while ( $ counter ) {
$ toroot = join ( '' , $ toroot , "/.." ) ;
$ counter - - ;
}
$ toroot =~ s/Q\/// ;
2004-04-20 00:37:35 +01:00
# If it's a cave, then insert it in the index file
2004-04-06 03:08:25 +01:00
if ( $ _ [ 1 ] eq "cave" ) {
my $ e = $ ents ;
$ e =~ s/ +/ /g ;
2004-04-21 16:24:24 +01:00
print INDXAL "<tr><td><a name=\"$linkid\">$kat_num $other_number" ;
2004-04-06 03:08:25 +01:00
if ( $ e ) {
2004-04-21 14:18:29 +01:00
print INDXAL "<small> - $e</small>" ;
2004-04-06 03:08:25 +01:00
}
2004-04-21 14:18:29 +01:00
print INDXAL "</a></td><td>" ;
2004-04-06 03:08:25 +01:00
if ( $ file ) {
2004-04-21 14:18:29 +01:00
print INDXAL "<a href=\"$file\">" ;
2004-04-06 03:08:25 +01:00
} elsif ( $ linkfile ) {
2004-04-21 14:18:29 +01:00
print INDXAL "<a href=\"$linkfile\">" ;
2004-04-06 03:08:25 +01:00
}
if ( $ name ) {
2004-04-21 14:18:29 +01:00
print INDXAL $ name ;
2004-04-06 03:08:25 +01:00
} else {
2004-04-21 14:18:29 +01:00
print INDXAL "?" ;
2004-04-06 03:08:25 +01:00
}
if ( $ unofficial_name ) {
2004-04-21 14:18:29 +01:00
print INDXAL " ($unofficial_name)" ;
2004-04-06 03:08:25 +01:00
}
if ( $ file or $ linkfile ) {
2004-04-21 14:18:29 +01:00
print INDXAL "</a>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ comment ) {
2004-04-21 14:18:29 +01:00
print INDXAL " - $comment" ;
2004-04-06 03:08:25 +01:00
}
2004-04-21 14:18:29 +01:00
print INDXAL "</td></tr>\n" ;
2004-04-06 03:08:25 +01:00
}
2004-04-20 00:37:35 +01:00
# 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
2004-04-06 03:08:25 +01:00
unless ( $ file ) { # this IS necessary
if ( $ mult_ents eq "yes" ) {
my $ e_mult_ents ;
do {
my $ e = <CSV> ;
chomp ;
my ( undef , undef , undef , undef , $ emult_ents ) = & parse_csv ( $ e ) ;
$ e_mult_ents = $ emult_ents ;
} while ( $ e_mult_ents ne "last entrance" ) ;
}
return ;
}
2004-04-20 00:37:35 +01:00
# If command line option is set, then be quiet
2004-04-18 19:57:30 +01:00
unless ( $ no_verbose_progress ) {
2004-04-06 03:08:25 +01:00
print "Progress: $file\n" ;
}
2004-04-20 00:37:35 +01:00
# 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 $! ;
2004-04-06 03:08:25 +01:00
print FILE << "END" ;
2004-04-21 22:49:22 +01:00
< ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
2004-04-06 03:08:25 +01:00
< ! - - ** * This file is auto - generated by $ progname - edit cavetab2 . csv instead - - >
2004-04-27 14:47:29 +01:00
< html lang = "en" xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" >
2004-04-06 03:08:25 +01:00
<head>
2004-04-21 22:49:22 +01:00
< meta http - equiv = "Content-Type" content = "text/html; charset=iso-8859-1" / >
< link rel = "stylesheet" type = "text/css" href = "$toroot/css/main2.css" / >
2004-04-06 03:08:25 +01:00
END
if ( $ kat_num ) {
print FILE "<title>1623:$kat_num" ;
} else {
2004-04-21 16:24:24 +01:00
print FILE "<title>$other_number" ;
2004-04-06 03:08:25 +01:00
}
print FILE << "END" ;
</title>
</head>
<body>
END
if ( $ header ) {
2004-04-21 16:24:24 +01:00
print FILE "$header\n\n" ;
2004-04-06 03:08:25 +01:00
}
2004-04-21 22:49:22 +01:00
print FILE "<table id=\"cavepage\">\n" ;
print FILE "<tr><th id=\"kat_no\">" ;
2004-04-06 03:08:25 +01:00
if ( $ kat_num ) {
print FILE "$kat_num" ;
}
if ( $ ents ) {
print FILE " - $ents" ;
}
if ( $ other_number ) {
2004-04-22 11:26:19 +01:00
if ( $ kat_num ) {
print FILE "<br />" ;
}
print FILE " $other_number" ;
2004-04-06 03:08:25 +01:00
}
2004-04-21 22:49:22 +01:00
print FILE "</th><th id=\"name\">$name" ;
2004-04-06 03:08:25 +01:00
if ( $ unofficial_name ) {
2004-04-22 11:26:19 +01:00
if ( $ name ) {
print FILE "<br />" ;
}
print FILE " ($unofficial_name)" ;
2004-04-06 03:08:25 +01:00
}
2004-04-21 22:49:22 +01:00
print FILE "</th>" ;
2004-04-06 03:08:25 +01:00
if ( $ kat_status ) {
2004-04-21 22:49:22 +01:00
print FILE "<th id=\"status\">$kat_status</th>" ;
2004-04-06 03:08:25 +01:00
}
2004-04-21 22:49:22 +01:00
print FILE "</tr>\n</table>" ;
2004-04-06 03:08:25 +01:00
if ( $ length or $ depth or $ extent ) {
print FILE "\n\n<p>" ;
}
if ( $ length ) {
print FILE "<b>Length:</b> $length " ;
}
if ( $ depth ) {
print FILE "<b>Depth:</b> $depth " ;
}
if ( $ extent ) {
print FILE "<b>Extent:</b> $extent " ;
}
2004-04-21 16:24:24 +01:00
if ( $ length or $ depth or $ extent ) {
print FILE "</p>" ;
}
2004-04-06 03:08:25 +01:00
# Entrance specific bit
unless ( $ mult_ents eq "yes" ) {
2004-04-21 16:24:24 +01:00
# If there is only one entrance,
print FILE "\n\n<p>" ;
2004-04-27 14:47:29 +01:00
if ( $ tag_punkt || $ other_punkt || $ exact_punkt || $ gpspostsa || $ gpspresa || $ easting || $ northing || $ altitude || $ fix_type || $ desc_other_punkt && ! $ ent_name ) { # basically, if do_ent is going to do anything, print "Entrance:"
print FILE "<b>Entrance: </b>" ;
2004-04-06 03:08:25 +01:00
}
2004-04-20 00:37:35 +01:00
# Process the location data for the entrance
2004-04-06 03:08:25 +01:00
do_ent ( $ tag_punkt , $ other_punkt , $ exact_punkt , $ gpspostsa , $ gpspresa , $ easting , $ northing , $ altitude , $ ent_name , $ fix_type , $ desc_other_punkt ) ;
2004-04-21 16:24:24 +01:00
print FILE "</p>"
2004-04-06 03:08:25 +01:00
} else {
# If there are multiple entrances
multi_ents ( $ file , $ kat_num , $ other_number , $ other_number_no_brackets , $ toroot ) ;
}
# Cave general bit
if ( $ location ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Location:</b> $location</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ bearings ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Bearings:</b> $bearings</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ approach ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Approach:</b> $approach</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ map ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Map:</b> $map</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ ent_desc ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Entrance Description:</b> $ent_desc</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ ent_photo ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Entrance Photo:</b> $ent_photo</p>" ;
2004-04-06 03:08:25 +01:00
}
2004-04-21 00:45:21 +01:00
if ( $ marking and $ marking ne "\r" and $ marking ne "\r\n" and $ marking ne "\n" ) { # bodgelicious.
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Marking:</b> $marking</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ references ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>References:</b> $references</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ u_description ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Underground Description:</b> $u_description</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ equipment ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Equipment:</b> $equipment</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ qmlist ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>QM list:</b> $qmlist</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ u_drawn_survey ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Survey:</b> $u_drawn_survey</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ notes ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Notes:</b> $notes</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ explorers ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Explorers:</b> $explorers</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ katstatus ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Kataster Status:</b> $katstatus</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ u_centre_line ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Centre Line:</b> $u_centre_line</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ survex_file ) {
2004-04-21 16:24:24 +01:00
print FILE "\n\n<p><b>Survex file:</b> $survex_file</p>" ;
2004-04-06 03:08:25 +01:00
}
if ( $ footer ) {
2004-04-21 22:49:22 +01:00
print FILE "\n\n<p>$footer</p>" ;
2004-04-06 03:08:25 +01:00
}
2004-04-27 14:47:29 +01:00
print FILE "\n\n<!-- LINKS -->\n<hr /><ul>\n" ;
2004-04-21 22:49:22 +01:00
2004-04-27 14:47:29 +01:00
if ( $ _ [ 1 ] eq "entrance" ) {
print FILE "<li><a href=\"javascript:history.back(1)\">Go Back (Javascript)</a></li>\n" ; # ACCK! ACCK! Evil JavaScript! - this HAS to be done, for things like 78a, where the reader could have got there either via 78 OR 40 (and we have NO way of knowing
}
2004-04-20 00:37:35 +01:00
# Find the area the cave is in, and add appropriate links
2004-04-06 03:08:25 +01:00
if ( $ area =~ /(1a|1b|1c|1d)/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/plateau\/index.htm#$linkid\">Plateau area index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /(2a|2b)/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/smkridge\/index.htm#$linkid\">Schwarzmooskogel ridge area index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /3/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/br-alm\/index.htm#$linkid\">Bräuning Alm area index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /4/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/kratzer\/index.htm#$linkid\">Kratzer valley index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /5/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/wilden\/index.htm#$linkid\">Schwarzmoos-Wildensee area index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /6/ ) {
2004-04-29 18:43:49 +01:00
print FILE "<li><a href=\"$toroot\/remote\/index.htm#$linkid\">Far plateau area index and description</a></li>\n" ;
2004-05-02 04:30:30 +01:00
print FILE "<li><a href=\"$toroot\/1626\/index.htm\">Adjacent area 1626</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /7/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/egglgrub\/index.htm#$linkid\">Egglgrube area index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /(8a|8b|8c|8d)/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/loser\/index.htm#$linkid\">Loser/Augst See area index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /9/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/gschwand\/index.htm#$linkid\">Gschwandt area index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /10/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/aaussee\/index.htm#$linkid\">N & NE shore of Altauseer See</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
if ( $ area =~ /11/ ) {
2004-04-21 22:49:22 +01:00
print FILE "<li><a href=\"$toroot\/augstb\/index.htm#$linkid\">Augstbach area index and description</a></li>\n" ;
2004-04-06 03:08:25 +01:00
}
2004-04-20 00:37:35 +01:00
# Finish writing to file
2004-04-06 03:08:25 +01:00
print FILE << "END" ;
2004-04-21 22:49:22 +01:00
<li> < a href = "$toroot/indxal.htm#$linkid" > Full Index </a> </li>
<li> < a href = "$toroot/areas.htm" > Other Areas </a> </li>
<li> < a href = "$toroot/index.htm" > Back to Expedition Intro page </a> </li>
</ul>
2004-04-21 14:18:29 +01:00
< ! - - / LINKS - - >
2004-04-06 03:08:25 +01:00
</body>
</html>
END
close FILE ;
}
2004-04-20 00:37:35 +01:00
# Parse a line of CSV data
# Argument is the line of data to be processed
# Returns array of the separated variables
2004-04-06 03:08:25 +01:00
sub parse_csv {
my $ line = $ _ [ 0 ] ;
my @ parsedline = ( ) ;
my $ field = '' ;
while ( $ line =~ m { \ G (?:^|,)
( ? : "((?> [^" ] * ) ( ? > "" [ ^ "]*)*)" | ( [ ^ " , ] * ) ) } gx ) {
if ( $ 2 ) {
$ field = $ 2 ;
} elsif ( $ 1 ) {
$ field = $ 1 ;
$ field =~ s/""/"/g ;
} else {
$ field = '' ;
}
push ( @ parsedline , $ field ) ;
}
return ( @ parsedline ) ;
}
2004-04-20 00:37:35 +01:00
# Process the location data for the entrance
# Returns nothing
2004-04-06 03:08:25 +01:00
sub do_ent {
my $ punkt ;
my $ calc_easting ;
my $ calc_northing ;
my $ calc_altitude ;
my $ desc ;
my $ tag_punkt = $ _ [ 0 ] ;
my $ other_punkt = $ _ [ 1 ] ;
my $ exact_punkt = $ _ [ 2 ] ;
my $ gpspostsa = $ _ [ 3 ] ;
my $ gpspresa = $ _ [ 4 ] ;
my $ easting = $ _ [ 5 ] ;
my $ northing = $ _ [ 6 ] ;
my $ altitude = $ _ [ 7 ] ;
my $ ent_name = $ _ [ 8 ] ;
my $ fix_type = $ _ [ 9 ] ;
my $ desc_other_punkt = $ _ [ 10 ] ;
# Write out info for entrance
if ( $ ent_name ) {
2004-04-21 16:24:24 +01:00
print FILE "<b>Entrance Name:</b> $ent_name " ;
2004-04-06 03:08:25 +01:00
}
if ( $ altitude ) {
print FILE "<b>Recorded Alt:</b> $altitude " ;
}
if ( $ northing ) {
print FILE "<b>Recorded as N</b>$northing " ;
}
if ( $ easting ) {
print FILE "<b>Recorded as E</b>$easting " ;
}
if ( $ fix_type ) {
print FILE "<b>Fix type:</b> $fix_type " ;
}
if ( $ tag_punkt ) {
print FILE "<b>Tag point:</b> $tag_punkt " ;
}
if ( $ other_punkt ) {
print FILE "<b>Point:</b> $other_punkt " ;
if ( $ desc_other_punkt ) {
print FILE "<b>Point description:</b> $desc_other_punkt " ;
} else {
print FILE "<b>Point description:</b> none " ;
}
}
if ( $ exact_punkt ) {
print FILE "<b>Exact entrance:</b> $exact_punkt " ;
}
if ( $ gpspresa ) {
print FILE "<b>GPS pre sa:</b> $gpspresa " ;
}
if ( $ gpspostsa ) {
print FILE "<b>GPS post sa:</b> $gpspostsa " ;
}
# Decide which punkt to lookup
if ( $ tag_punkt ) {
$ punkt = $ tag_punkt ;
$ desc = "tag point" ;
} elsif ( $ other_punkt ) {
$ punkt = $ other_punkt ;
$ desc = "point" ;
} elsif ( $ exact_punkt ) {
$ punkt = $ exact_punkt ;
$ desc = "exact point" ;
} elsif ( $ gpspostsa ) {
$ punkt = $ gpspostsa ;
$ desc = "GPS (pre SA)" ;
} elsif ( $ gpspresa ) {
$ punkt = $ gpspresa ;
$ desc = "GPS (post SA)" ;
}
# Find the position of that punkt
if ( $ punkt ) {
for my $ surveypoint ( @ pos ) {
if ( $ surveypoint =~ m/\( *([0-9\.\-]*), *([0-9\.\-]*), *([0-9\.\-]*) \) $punkt(\r\n|\n|\r)/ ) {
$ calc_easting = $ 1 ;
$ calc_northing = $ 2 ;
$ calc_altitude = $ 3 ;
}
}
if ( $ calc_easting ) {
2004-04-21 22:49:22 +01:00
print FILE "<br />\nLookup values for $desc data: " ;
2004-04-06 03:08:25 +01:00
print FILE "<b>Alt:</b> $calc_altitude " ;
print FILE "<b>N</b>$calc_northing " ;
print FILE "<b>E</b>$calc_easting " ;
} else
2004-04-22 11:26:19 +01:00
{ print STDERR "Warning: Lookup point for $desc data not found: $punkt\n" ; }
2004-04-06 03:08:25 +01:00
}
}
2004-04-20 00:37:35 +01:00
# 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
2004-04-06 03:08:25 +01:00
sub multi_ents {
my $ file = $ _ [ 0 ] ;
my $ kat_num = $ _ [ 1 ] ;
my $ other_number = $ _ [ 2 ] ;
my $ other_number_no_brackets = $ _ [ 3 ] ;
my $ toroot = $ _ [ 4 ] ;
2004-04-21 22:49:22 +01:00
print FILE "\n\n<p><b>Entrances:</b></p>\n\n<ul>" ;
2004-04-06 03:08:25 +01:00
my $ e_mult_ents ;
2004-04-20 00:37:35 +01:00
# Process each entrance
2004-04-06 03:08:25 +01:00
do {
my $ e = <CSV> ;
chomp ;
my ( $ ekat_num , undef , $ eents , $ eother_number , $ emult_ents , $ efile , $ elinkfile , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , undef , $ eent_name , $ etag_punkt , $ eother_punkt , $ edesc_other_punkt , $ eexact_punkt , $ efix_type , $ egpspresa , $ egpspostsa , $ enorthing , $ eeasting , $ ealtitude ) = & parse_csv ( $ e ) ;
if ( $ eother_number ) {
$ eother_number = "($eother_number)" ; # wrap it in brackets, so it doesn't appear to be official
}
2004-04-21 14:18:29 +01:00
print FILE "\n<li>" ;
2004-04-06 03:08:25 +01:00
2004-04-20 00:37:35 +01:00
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
2004-04-06 03:08:25 +01:00
print FILE "<a href=\"$toroot\/$elinkfile\">$eents $eother_number</a> " ;
do_this_line ( $ e , "entrance" , $ kat_num , $ other_number_no_brackets ) ;
2004-04-20 00:37:35 +01:00
} elsif ( $ efile ) { # call ourselves recursively to create a file for the entrance
2004-04-06 03:08:25 +01:00
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.
do_this_line ( $ e , "entrance" , $ kat_num , $ other_number_no_brackets ) ;
open FILE , ">> $file" or die $! ;
2004-04-20 00:37:35 +01:00
} else { # no entrance file needed, and no link to another cave
2004-04-06 03:08:25 +01:00
print FILE "$eents $eother_number" ;
}
2004-04-20 00:37:35 +01:00
# Process the location data for the entrance
2004-04-06 03:08:25 +01:00
do_ent ( $ etag_punkt , $ eother_punkt , $ eexact_punkt , $ egpspostsa , $ egpspresa , $ eeasting , $ enorthing , $ ealtitude , $ eent_name , $ efix_type , $ edesc_other_punkt ) ;
2004-04-21 22:49:22 +01:00
print FILE "</li>" ;
2004-04-06 03:08:25 +01:00
$ e_mult_ents = $ emult_ents ;
} while ( $ e_mult_ents ne "last entrance" ) ;
2004-04-21 22:49:22 +01:00
print FILE "\n</ul>" ;
2004-04-06 03:08:25 +01:00
}
2004-04-20 01:11:21 +01:00
# Usage
sub usage {
print << "EOF" ;
USAGE: $ progname [ - options ] < CSV file >
- q , - - quiet Be quiet about progress
- h , - - help Show this message
EOF
exit ( 0 ) ;
}