friedman@chekov.UU.NET (Barry Friedman) (09/18/90)
This program is used to translate the postscript version of Johan Vromans' Perl Reference Guide into troff. It is now able to produce troff for formatters which do not have a '2-up landscape option' (but can print plain landscape) # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Barry Friedman <friedman@kirk> on Tue Sep 18 12:22:30 1990 # # This archive contains: # tguide # unset LANG echo x - tguide cat >tguide <<'@EOF' #!/usr/local/bin/perl #----------------------------------------------------------------------- # tguide @ 3.0.28.1 # # translate J. Vromans ``Perl Reference Guide'' to troff # # Usage: tguide refguide.ps > refguide.t # # Output is raw troff (no macro package needed,) # tuned for a laserjet II using HP Softfonts AD & AF # with the Eroff formatter the guide could be printed using # the `2-up landscape' option. (change $hshift setting below) # # Author: Barry Friedman friedman%chekov@uunet.uunet # (...!uunet!chekov!friedman) # # Known bugs: Doesn't handle boxes or Alternate Symbol set # (Only used for copyright & pi in the guide) # # Use: Unlimited #----------------------------------------------------------------------- # # scale and page position factors # Based on 300 units per inch (change accordingly for other units) #$hshift=0; # if using 2-up landscape mode $hshift=1650; # left/right page shift for ordinary landscape made $hscale=3; #horizontal position multiplier $vscale=2.7; #vertical position multiplier $hcorr=250; #left margin offset $vcorr=120; #top margin offset # constants $em='-'; # em dash $dg='\\\\(dg'; # dagger #----------------------------------------------------------------------- # OUTPUT PREAMBLE # # Set the printer to double sided landscape mode # this sequence works with Eroff, don't know about other formatters # print q|\X'code="\e033&l2S"'\c|,"\n"; # laserjet 2000 control sequence #*********************************************************************** # COMMENT OUT THE ABOVE LINE IF NOT A LASERJET print ".po 0\n"; print ".in 0\n"; print ".ll 11i\n"; while (<>) { if ( /^%%EndDocumentSetup/..eof() ) { #------------------------------------------------- # Skip a lot of useless stuff #------------------------------------------------- if ( /^%%/ ) { # comments skipped next; } if ( / gr$/ ) { #? next; } if ( / lw$/ ) { #? next; } if ( / lin$/ ) { #? next; } if ( / setTxMode$/ ) { #? next; } if ( / pen$/ ) { #? next; } if ( /\)kp$/ ) { #frame ? next; } if ( / xl$/ ) { #frame ? next; } if ( / fr$/ ) { #frame ? next; } if ( /bu fc$/ ) { next; } if ( /fs$/ ) { next; } if ( /bn$/ ) { next; } #------------------------------------------------- # Now for some real work #------------------------------------------------- if ( /^move1$/ ) { # output page NOTE: Eroff 2-up landscape handles # this automatically - otherwise toggle a correction # factor to be added to horizontal position #move to left side of page if ($hshift) { print ".bp\n" if $not_first_bp; $not_first_bp = 1; $hshift_tmp = 0; } next; } if ( /^move2$/ ) { # output page #move to right side of page $hshift_tmp = $hshift; next; } if ( /^op$/ ) { # output page next if $hshift; print ".bp\n" if $not_first_bp; $not_first_bp = 1; next; } #------------------------------------------------- # Font Changes #------------------------------------------------- if ( /Helvetica fnt/ ) { print "'ft H\n"; next; } if ( /Times-Bold fnt/ ) { print ".ft B\n"; next; } if ( /Times-Italic fnt/ ) { print ".ft I\n"; next; } if ( /Times-Roman fnt/ ) { print ".ft R\n"; next; } #------------------------------------------------- # Size translations (from 2up guide #------------------------------------------------- if ( /(\d+) fz/ ) { $sz = $1; if ($sz == 24) { $sz = 18; } elsif ($sz == 18) { $sz = 12; } elsif ($sz == 14) { $sz = 10; } elsif ($sz == 12) { $sz = 8; } elsif ($sz == 10) { $sz = 8; } print ".ps $sz\n"; $vs = $sz+2; print ".vs $vs\n"; next; } #------------------------------------------------- # Positioning #------------------------------------------------- if ( /(-*\d+) (-*\d+) gm$/ ) { $v= $1; # vertical pos $h= $2; # horiz. pos if ($1 < 0 || $2 < 0 ) { next; } $sc_v = int($v * $vscale) - $vcorr; print ".br\n"; print ".sp |$sc_v","u\n"; $sc_h = int($h * $hscale) - $hcorr +$hshift_tmp; print "\\h\'|$sc_h","u\'\\c\n"; next; } #------------------------------------------------- # Text translations #------------------------------------------------- if ( /[(](.*)[)].*show$/ ) { $ln = $1; $ln =~ s/\\240/$dg/g; $ln =~ s/\\253/'/g; $ln =~ s/\\311/.../g; $ln =~ s/\\312/\\|/g; $ln =~ s/\\322/``/g; $ln =~ s/\\323/''/g; $ln =~ s/\\325/'/g; $ln =~ s/\\32./$em/g; $ln =~ s/\\\(/\(/g; $ln =~ s/\\\)/\)/g; # guard column 1 of output if ( $ln =~ /^[.'" ]/ ) { $ln = "\\&" . $ln; } print "$ln\n"; next; } #print STDERR "?: $_"; # Anything I missed }} @EOF chmod 777 tguide exit 0