#This is a simple program that coordinates the conversion from the old #techrep format to the new format. # # EXAMPLE, PARAMETERS: # # proper calling format is: # old2new # # # This will typically look like: # # #perl cmd \ # ftp://ftp.cs.virginia.edu/pub/techreports \ # /var/ftp/pub/techreports/DOCIDS \ # "Department of Computer Science, University of Virginia" # < ~techrep/lib/oldtechrep.bib > ~techrep/lib/report.bib # # #-------------------------------------------------------------------------- # if ((!$ARGV[0]) || (!$ARGV[1]) || (!$ARGV[2])) { print "Usage: old2new ReportUrl Mapfile Organization\n"; die; } $reportUrl=@ARGV[0]; $mapFilename=@ARGV[1]; $organization=@ARGV[2]; # read the mapping file (usually DOCIDS) open (mapfile, $mapFilename); while () { ($trNumber, $file) = split(/ /, $_); chop $file; $mapping{$trNumber} = $file; } close (mapfile); # # reads only from STDIN, so that the program can take parameters # the default action is <> which reads from each name specified # on the command line # $currentGMTime = &cgmtime; while ($_ = ) { if (/^$/) { #assumes a blank line follows every record, INCLUDING THE LAST ONE #adds the following lines to each record $file = $mapping{$DOC}; if ($file) { #so now doc exists by definition # print STDERR "$DOC exists \n"; print "%U ", $reportUrl, "/", $file, "\n"; } else { # print STDERR "$DOC does not exist on-line. Citation only.\n"; } print "%I $organization\n"; print "%Z ", $currentGMTime, "\n"; print "\n"; } elsif (/^%F (.*)/) { $DOC = $1; print "%R $DOC\n"; } elsif (/^%c (.*)/) { $categories = $1; print "%Y $categories\n"; } elsif (/^%Z/) { # Old %Z not used, is now bib entry modification date } else { print; } } # returns an rfc1123 date string based on Greenwich Mean Time sub cgmtime{ @gmtime = gmtime; $mon = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[@gmtime[4]]; $sec = @gmtime[0]; if ($sec < 10) { $sec= "0".$sec; } $min = @gmtime[1]; if ($min < 10) { $min= "0".$min; } $hour = @gmtime[2]; if ($hour < 10) { $hour= "0".$hour; } $mday = @gmtime[3]; $mon = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[@gmtime[4]]; $year = @gmtime[5]; if ($year > 70) { $year+=1900; } else { $year+=2000; } $wday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[@gmtime[6]]; $isdst = @gmtime[7]; $wday.", ".$mday." ".$mon." ".$year." ".$hour.":".$min.":".$sec." GMT"; } # returns an rfc1123 date string based on local time sub clocaltime{ @loctime = localtime; $sec = @loctime[0]; if ($sec < 10) { $sec= "0".$sec; } $min = @loctime[1]; if ($min < 10) { $min= "0".$min; } $hour = @loctime[2]; if ($hour < 10) { $hour= "0".$hour; } $mday = @loctime[3]; $mon = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[@loctime[4]]; $year = @loctime[5]; if ($year > 70) { $year+=1900; } else { $year+=2000; } $wday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[@loctime[6]]; $isdst = @loctime[7]; $wday.", ".$mday." ".$mon." ".$year." ".$hour.":".$min.":".$sec; }