home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / PSUTILS / INCLUDER.CMD < prev    next >
OS/2 REXX Batch file  |  1994-01-14  |  1KB  |  49 lines

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