#!/usr/bin/perl -w use strict; use Getopt::Long; # sort algorithm on png entries should be improved. but then, shouldn't they always. ((my $progname = $0) =~ s/^.*(\/|\\)//ig); # basename $0 # Parse options my $no_verbose_progress = 0; my $usage = 0; GetOptions('quiet' => \$no_verbose_progress, # be quiet 'help|?' => \$usage # help! ); # Print usage if ($usage) { usage(); } unless ($ARGV[0]) { print "Specify a CSV file name as the program's argument (e.g. Surveys.csv)\n"; usage(); } # Read in list of names - this seems not to be used #open (NAMES, "< $ARGV[0]"); #my @names; #while () { # chomp; # push(@names,$_); #} open (CSV, "< $ARGV[0]"); # Start writing table file, and write table header open TABLE, "> surtabnam.html" or die $!; print TABLE << "END"; Unfinished surveys by person

Unfinished surveys by person

END ; # starting to read in csv file, eat header line my ($year, $surveyno, $date, $cave_surf, $caveno, $cave_name, $location, $svx_file, $instruments, $tape, $notes, $photos, $comments, $finished, $sketch_wo_CL); my ($newsurveyno, @dir, @plans, @notesimg, @elev, @misc); print "Progress: *"; # While loop which reads in each line of csv file #@lines stores the lines for sorting later my @lines; while () { chomp; # Split single line into all the fields ($year, $surveyno, $date, $cave_surf, $caveno, $cave_name, $location, $svx_file, $instruments, $tape, $notes, $photos, $comments, $finished, $sketch_wo_CL) = &parse_csv($_); if ($year ne "2007") { next } # Last field of CSV file can have weird form-feeds etc. Kill them $sketch_wo_CL =~ s/\r//; # Make survey number pure numeric. Pad numbers less than 10 with a zero # $surveyno =~ s/[a-zA-Z]//g; $newsurveyno = $surveyno; if ($surveyno < 10) { $newsurveyno = join("", "0", $surveyno); } # Get the directory contents, do a numeric sort on the files if (opendir(DIR, "${year}/${year}#$newsurveyno")) { @dir = sort numericsort grep(!/CVS/ && !/^\./, readdir(DIR)); # HTMLize the files foreach ($_, @dir) { my $href = ""; $href =~ s/#/%23/g; $_ = join('', $href, "$_<\/a>
"); } # Split the files into their respective categories @plans = grep(/plan/i, @dir); @notesimg = grep(/notes/i, @dir); @elev = grep(/elev/i || /extend/i, @dir); @misc = grep(!/plan/i && !/notes/i && !/extend/i && !/elev/i, @dir); closedir(DIR); } else { # Directory for this survey does not exist unless ($no_verbose_progress) { print "\nWarning: ${year}/${year}#$newsurveyno does not exist "; } (@plans, @notesimg, @elev, @misc) = undef; ($plans[0], $notesimg[0], $elev[0], $misc[0]) = ("Survey", "directory", "does not", "exist"); } # Write line out to table unless ($finished =~ m\[yY]es\){ push(@lines,"$notes
\n"); } print "*"; } my @sortedlines = sort(@lines); #$n allows the title of the table to be displayed every 10 lines my $n=0; #$name allows each person to have their own section my $name = "Initialisation"; foreach my $line (@sortedlines) { if ($line =~ /(.*)(\\n"; if ($1 eq ""){ print TABLE "

Notes person not known

\n"; } else{ print TABLE "

$1

\n"; } print TABLE "
$year$newsurveyno$date$cave_surf$caveno$cave_name$location$svx_file$instruments$tape$notes$photos$comments$finished$sketch_wo_CL@plans@notesimg@elev@misc
\n"; print TABLE "\n"; print TABLE "$2\n"; } } } print TABLE << "END";
YearSurvey NumberDateCave/SurfaceCave NumberCave NameLocationSurvex fileInstrumentsTapeNotesPhotosCommentsFinishedSketches without centre linesPlansNotes*elev* and *extendAnything else
END close TABLE; print "\nInformation: Done\n"; # Parse the CSV file sub parse_csv { my $line = $_[0]; my @parsedline = (); my $field = ''; while ($line =~ m{ \G(?:^|[,\t]) (?: "((?> [^"]*) (?> "" [^"]*)*)" | ([^"\t,]*)) }gx) { if ($2) { $field = $2; } elsif ($1) { $field = $1; $field =~ s/""/"/g; } else { $field = ''; } push(@parsedline, $field); } return(@parsedline); } # A singularly crap numeric sort sub numericsort { my ($moda, $modb); $moda = $a; $modb = $b; # remove alpha characters, ".", "#" "_" and "-" to enable filenames to be purely numeric (hopefully) $moda =~ s/[a-zA-Z\.\\_#-]//g; $modb =~ s/[a-zA-Z\.\\_#-]//g; if ($moda and $modb) { $moda <=> $modb; } else { # No characters left (no numerics chars in filename. Who cares where it ends up in search order. 0; } } # Usage sub usage { print << "EOF"; USAGE: $progname [-options] -q, --quiet Be quiet about progress -h, --help Show this message EOF exit(0); }