: eval 'exec perl -S $0 ${1+"$@"}' if $running_under_some_shell; # # wml1to2 -- Upgrade input files from WML 1.x to WML 2.x # Copyright 2000 Denis Barbier. All rights reserved. # This program is free software released under the GNU General # Public License v2. # # This tool updates input files to make them suitable with WML 2.x # Transformation is made in place, so making backups before running # this script is a wise idea. # # Documentation can be viewed with # perldoc wml1to2 # sub usage { print STDERR "Usage: wml1to2 file1 file2 ...\n\n"; print STDERR " Warning: files are written in place, so make sure you\n"; print STDERR " performed backups before running this script\n\n"; } $warn = 0; sub WarnIfPresent { my ($pattern, $string) = @_; if ($string =~ m|\b$pattern\b|s) { print STDERR "Warning: $pattern found\n"; $warn = 1; } } if ($#ARGV == -1) { &usage; exit(1); } foreach (@ARGV) { if (m/^-/) { &usage; exit(1); } elsif (! -f) { print STDERR "File " . $_ . " not found: skipped\n"; next; } # Okay, processing can take place my ($infile, $outfile) = ($_, $_ . ".".$$); if (-e $outfile) { print STDERR "File " . $outfile . " does already exist, so input file " . $infile . " is skipped\n"; } # Read input file local($/) = undef; open(IN, "< $infile") or die "Unable to read file " . $infile;; my ($text) = ; close(IN); $_ = $text; # Perform substitution. See README.mp4h for details # Macro definitions s|]+)|]+)|>|{#$1#}|g; s|\.\.(\!?[a-zA-Z][a-zA-Z0-9_]*\!?)>>|{#$1#:|g; s|<<\.\.|:##}|g; s|<<(\!?[a-zA-Z][a-zA-Z0-9_]*\!?)\.\.|:#$1#}|g; s|({#\!?[a-zA-Z][a-zA-Z0-9_]*\!?):|$1#:|g; s|:#}|:##}|g; s|:(\!?[a-zA-Z][a-zA-Z0-9_]*\!?#})|:#$1|g; # Detect possible cause of problems &WarnIfPresent('define-container', $_); &WarnIfPresent(' $outfile") or die "Unable to write to file " . $outfile; print OUT $text; close(OUT); rename($outfile, $infile) or die "Unable to write to file " . $infile; } if ($warn) { print STDERR "Check previous warnings carefully and make sure there is no trouble with them.\n"; } 1; ##EOF## __END__ =head1 NAME wml1to2 - Make WML input files ready for WML 2.x =head1 SYNOPSIS B I [I] ... To apply this script recursively on all files of a directory, call find my_path -type f -exec wml1to2 {} \; It is also possible to process only WML input files, e.g. find my_path -name \*.wml -exec wml1to2 {} \; See the find(1) manpage for details. =head1 DESCRIPTION This program transforms files to make them suitable for WML 2.x. As transformations are performed in place, you should always backup your datas before applying this program. You have been warned. This paragraph explains which operations are performed to input text. For more details on incompatibilities between WML 1.x and WML 2.x, read the C file shipped with the distribution. =over 4 =item Macro Functions The Cdefine-tagE> command replaces CdefsubstE>, Cdefine-containerE> and CdefmacroE>. On the other hand, Cdefine-functionE>, CdefunE> and CdefweakmacroE> have no equivalent and should be rewritten. Special sequences C<%qbody> and C<%xbody> are replaced by C<%body>. =item Group Functions The CgroupE> command replaces CprogE> and CconcatE>. =item Arithmetic Functions This was necessary because CdivE> is a valid HTML tag, so division is now performed with CdivideE>. But it is not an easy task to determine if a CdivE> tag has to be replaced by CdivideE>, so a warning is raised and no transformations are performed. Other mathematical functions also use a longer name: CmulE> is replaced by CmultiplyE>, CsubE> by CsubstractE> and CmodE> by CmoduloE>. =item Diversion Tags In WML 1.x, casual diversion commands are CENAMEEE>, C<..NAMEEE> and CENAME..>, but strange results may occur if these names have been defined by wml_p2_mp4h. For this reason, these forms have been deprecated since WML 1.7.3 in favor of C<{#NAME#}>, C<{#NAME:> and C<:NAME#}>. This caused some performance problems, and eventually WML 2.x use C<{#NAME#}>, C<{#NAME#:> and C<:#NAME#}>. =back =head1 AUTHOR Denis Barbier barbier@engelschall.com =cut