#!/usr/bin/perl # # This program converts the weather-display 'taglist.txt' to a PHP page # keeping the same names for the variables. # # Author: Ken True, http://saratoga-weather.org/ # Date: 07-Apr-2006 # # This program may be freely used and copied. Use at your own risk. # # usage: gen-PHP-tagslist.pl # use Getopt::Std; use File::Basename; use vars qw/ $opt_d $opt_h $opt_v $opt_u/; my $PROGRAM = "gen-PHP-tagslist.pl"; my $version="$PROGRAM - Version 1.00 - 07-Apr-2006"; my $usage = "$PROGRAM [-d] [-h] [-v] .txt where: -h = help (this message) -v = version -d = debug This is the tagslist.txt file from weather-link Purpose: Convert the tagslist.txt file into a silent PHP page so all the variables are named as in Weather-Display and can be used in a page (when processed by Weather-Display upload) Outputs: tagslist.php - Converted file in PHP format "; getopts('dvh'); die "$version\n" if $opt_v; my $debug = 0; $debug = 1 if $opt_d; my $infile = $ARGV[0]; die "$version\n\n$usage\n" if $opt_h or !$infile; open (INFILE,"<$infile") or die "Unable to open $infile: $!\n"; my $inrec = ''; my @f = (); my ($fname,$path,$fext) = fileparse($infile,".txt"); my $outfile = $path . $fname . ".php"; print STDOUT <$outfile") or die "Unable to open $outfile: $!\n"; print OUTFILE <) { $inrec = $_; chomp($inrec); $recsin++; if ($inrec =~ m|^(\%\S+\%)|) { $tag = $1; $inrec =~ s|$tag\s*[\.]+||; # remove the tag and leading dots $tagname = $tag; $tagname =~ s|\%||g; # remove the % markers; $tagname =~ s|\-|_|g; # replace - with _ $tagname =~ s|\<|LT|g; # replace < with LT $tagname =~ s|\>|GT|g; # replace > with GT $tagname =~ s|\=||g; # remove = $tagname =~ s|/|_|g; # replace / with _ $tagname =~ s|\,|CM|g; # replace , with CM print OUTFILE "\$$tagname = \"$tag\";\t// $inrec\n"; $fixedup++; } else { print OUTFILE "// $inrec\n"; } } print OUTFILE < FINIS ; print STDERR <