home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / PSUTILS / INCLUDER.PL < prev    next >
Perl Script  |  1993-11-19  |  1KB  |  48 lines

  1. #!@PERL@
  2. # includeres: include resources in PostScript file
  3. #
  4.  
  5. # feed this into perl
  6. eval 'exec perl -S $0 "$@"'
  7.    if $running_under_some_shell;
  8.  
  9. $prog = ($0 =~ s=.*/==);
  10.  
  11. %extn = ("font", ".pfa", "file", ".ps", "procset", ".ps", # resource extns
  12.      "pattern", ".pat", "form", ".frm", "encoding", ".enc");
  13. %type = ("%%BeginFile:", "file", "%%BeginProcSet:", "procset",
  14.      "%%BeginFont:", "font"); # resource types
  15.  
  16. sub filename {            # make filename for resource in @_
  17.    local($name);
  18.    foreach (@_) {        # sanitise name
  19.       s/[!()\$\#*&\\\|\`\'\"\~\{\}\[\]\<\>\?]//g;
  20.       $name .= $_;
  21.    }
  22.    $name =~ s@.*/@@;        # drop directories
  23.    die "Filename not found for resource ", join(" ", @_), "\n"
  24.       if $name =~ /^$/;
  25.    $name;
  26. }
  27.  
  28. while (<>) {
  29.    if (/^%%IncludeResource:/ || /^%%IncludeFont:/ || /^%%IncludeProcSet:/) {
  30.       local($comment, @res) = split(/\s+/);
  31.       local($type) = defined($type{$comment}) ? $type{$comment} : shift(@res);
  32.       local($name) = &filename(@res);
  33.       local($inc) = "@INCLUDE@"; # system include directory
  34.       if (open(RES, $name) || open(RES, "$name$extn{$type}") ||
  35.       open(RES, "$inc/$name") || open(RES, "$inc/$name$extn{$type}")) {
  36.      while (<RES>) {
  37.         print $_;
  38.      }
  39.      close(RES);
  40.       } else {
  41.      print "%%IncludeResource: ", join(" ", $type, @res), "\n";
  42.      print STDERR "Resource $name not found\n";
  43.       }
  44.    } else {
  45.       print $_;
  46.    }
  47. }
  48.