home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / dvips583.zip / contrib.zip / dvips / contrib / MakeTeXPK.pl < prev    next >
Perl Script  |  1998-11-03  |  6KB  |  199 lines

  1. #!/usr/local/bin/perl
  2. #
  3. #   MakeTeXPK.pl
  4. #
  5. #   v1.0 - modified by John Stoffel (john@wpi.wpi.edu) from the original
  6. #          shell script written by Tomas Rokicki (rokicki@cs.stanford.edu).
  7. #          please feel free to make any modifications you would like to this
  8. #          script, but please acknowledge myself and tom when you make 
  9. #          changes.
  10. #
  11. #        - This was orignally modified to write the fonts to a seperate 
  12. #          directory because the fonts were stored on a read-only NFS
  13. #          server.  New fonts were then stored in a second location that
  14. #          was world writeable, so fonts could be created automatically.  
  15. #          
  16. #          1. checks both directories before hand for the font's existence.
  17. #          2. creates the font, then moves it to the writeable directory.
  18. #          3. changes the ownership and protection so users can't write
  19. #             the font directly.
  20. #
  21. #        - this script should NOT be used directly, but run through
  22. #          suidscript.pl first and then used as directed.
  23. #
  24. #   todo:
  25. #        - add automagic support for write-white and write-black printers.
  26. #          now I have two seperate version of the same program.  This would
  27. #          mean adding in either a new parameter, or possibly a -w or -b
  28. #          switch.  Default could be customizable.  What do you think tom?  
  29. #      
  30. #        - cleanup the code a little more and write it in better perl.
  31. #
  32. # ------------------------------------------------------------------------
  33. #
  34. #   This script file makes a new TeX PK font, because one wasn't
  35. #   found.  Parameters are:
  36. #
  37. #   name dpi bdpi magnification [[mode] subdir]
  38. #
  39. #   `name' is the name of the font, such as `cmr10'.  `dpi' is
  40. #   the resolution the font is needed at.  `bdpi' is the base
  41. #   resolution, useful for figuring out the mode to make the font
  42. #   in.  `magnification' is a string to pass to MF as the
  43. #   magnification.  `mode', if supplied, is the mode to use.
  44. #
  45. #   Note that this file must execute Metafont, and then gftopk,
  46. #   and place the result in the correct location for the PostScript
  47. #   driver to find it subsequently.  If this doesn't work, it will
  48. #   be evident because MF will be invoked over and over again.
  49. #
  50. #   Of course, it needs to be set up for your site.
  51. #
  52. # -------------------------------------------------------------------------
  53.  
  54. # setup the environment variables before hand.
  55.  
  56. $ENV{'PATH'} = '/bin:/usr/bin:/usr/ucb:/usr/local/bin';
  57. $ENV{'SHELL'} = '/bin/sh' if $ENV{'SHELL'} ne '';
  58. $ENV{'IFS'} = '' if $ENV{'IFS'} ne '';
  59. $path = $ENV{'PATH'};
  60. umask(0022);
  61.  
  62. # set who the owner and group of the created fonts will be.
  63.  
  64. $OWNER = "root.tex";
  65.  
  66. # check number of arguements.
  67.  
  68. die "Not enough arguments!\n" if ($#ARGV < 3);
  69.  
  70. # make sure the user doesn't try to give us any control characters as
  71. # as arguements.
  72.  
  73. $NAME=&untaint($ARGV[0]);
  74. $DPI=&untaint($ARGV[1]);
  75. $BDPI=&untaint($ARGV[2]);
  76. $MAG=&untaint($ARGV[3]);
  77. $MODE=&untaint($ARGV[4]) if (defined($ARGV[4]));
  78. $PK=&untaint($ARGV[5]) if (defined($ARGV[5]));
  79.  
  80. # texdir and local dir can be the same if $TEXDIR is world writeable, or 
  81. # different if $TEXDIR is read-only and $LOCALDIR is read-write.
  82.  
  83. $TEXDIR="/usr/local/lib/tex";
  84. $LOCALDIR="/shared/tex/fonts";
  85. $DESTDIR="$LOCALDIR/white/pk";
  86.  
  87. # TEMPDIR needs to be unique for each process because of the possibility
  88. # of simultaneous processes running this script.
  89.  
  90. if ($TMPDIR eq '') {
  91.     $TEMPDIR="/tmp/mtpk.$$";
  92.    }
  93. else {
  94.     $TEMPDIR="$TMPDIR/mtpk.$$";
  95.    }
  96.  
  97. if ($MODE eq "") {
  98.     if ($BDPI eq "300") { $MODE='imagen'; }
  99.     elsif ($BDPI eq "200") { $MODE='FAX'; }
  100.     elsif ($BDPI eq "360") { $MODE='nextII'; }
  101.     elsif ($BDPI eq "400") { $MODE='nexthi'; } 
  102.     elsif ($BDPI eq "100") { $MODE='nextscreen'; }
  103.     elsif ($BDPI eq "635") { $MODE='linolo'; }
  104.     elsif ($BDPI eq "1270") { $MODE='linohi'; }
  105.     elsif ($BDPI eq "2540") { $MODE='linosuper'; }
  106.     else {
  107.       die "I don't know the $MODE for $BDPI\nHave your system admin update MakeTeXPK.pl\n"
  108.       }
  109. }
  110.  
  111. #  Something like the following is useful at some sites.
  112. # DESTDIR=/usr/local/lib/tex/fonts/pk.$MODE
  113.  
  114. $GFNAME="$NAME.$DPI"."gf";
  115. $PKNAME="$NAME.$DPI"."pk";
  116.  
  117. # Clean up on normal or abnormal exit
  118.  
  119. chdir("/") || die "Couldn't cd to /: $!\n";
  120.  
  121. if (-d $TEMPDIR) {
  122.     rmdir($TEMPDIR) || die "Couldn't remove $TEMPDIR: $!\n";
  123. }
  124. if (-e "$DESTDIR/pktmp.$$") {
  125.     unlink("$DESTDIR/pktmp.$$") || die "Couldn't rm $DESTDIR/pktmp.$$: $!\n";
  126. }
  127.  
  128. if (! -d $DESTDIR) {
  129.     mkdir($DESTDIR,0755) || die "Couldn't make $DESTDIR: $!\n";
  130. }
  131.  
  132. if ($PK ne '') {
  133.     $DESTDIR = $DESTDIR . $PK;
  134.     if (! -d $DESTDIR) {
  135.     mkdir($DESTDIR,0755) || die "Couldn't make $DESTDIR: $!\n";
  136.     }
  137. }                   
  138.  
  139. mkdir($TEMPDIR,0755) || die "Couldn't make $TEMPDIR: $!\n";
  140.  
  141. chdir($TEMPDIR) || die "Couldn't cd to $TEMPDIR: $!\n";
  142.  
  143. if (-e "$DESTDIR/$PKNAME") {
  144.     die "$DESTDIR/$PKNAME already exists!\n";
  145. }
  146.  
  147. # check also in the standard place
  148.  
  149. if ($PK eq '') {
  150.     if (-e "$TEXDIR/fonts/white/pk/$PKNAME") {
  151.     die "$TEXDIR/fonts/white/pk/$PKNAME already exists!\n";
  152.     }
  153.     elsif (-e "$TEXDIR/fonts/white/pk/$PK$PKNAME") {
  154.     die "$TEXDIR/fonts/white/pk/$PK$PKNAME already exists!\n";
  155.     }
  156. }
  157.  
  158. # print out the command string we will use, then actually do the command,
  159. # printing it's results.
  160.  
  161. print "mf \"\\mode:=$MODE; mag:=$MAG; scrollmode; input $NAME\" </dev/null\n";
  162. system("mf \"\\mode:=$MODE; mag:=$MAG; scrollmode; input $NAME\" </dev/null");
  163.  
  164. # check that $GFNAME was created correctly.
  165.  
  166. if (! -e $GFNAME ) { die "Metafont failed for some reason on $GFNAME\n";}
  167.  
  168. print `gftopk -v ./$GFNAME ./$PKNAME`;
  169.  
  170. # Install the PK file carefully, since others may be doing the same
  171. # as us simultaneously.
  172.  
  173. `mv $PKNAME $DESTDIR/pktmp.$$`;
  174. chdir($DESTDIR) || die "Couldn't cd to $DESTDIR: $!\n";
  175. `mv pktmp.$$ $PKNAME`;
  176.  
  177. # now we want to make sure only proper people can change this new font.
  178.  
  179. `/etc/chown $OWNER $PKNAME`;
  180. `/bin/chmod 664 $PKNAME`;
  181.  
  182. # this subroutine makes sure there are no funny control characters in 
  183. # the arguements that have been passed to the program.
  184.  
  185. sub untaint {
  186.     local($temp) = @_;
  187.     $temp =~ /^([-\/\(\)\.\w]*)$/ || die "Invalid arguement: $temp\n";
  188.     $temp = $1;
  189.     return($temp);
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. 
  199.