home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / bc / general / 293 < prev    next >
Encoding:
Text File  |  1992-09-11  |  3.6 KB  |  109 lines

  1. Newsgroups: 1b.help,bc.general
  2. Path: sparky!uunet!van-bc!ubc-cs!news.UVic.CA!sirius!Mark.McIntosh
  3. From: Mark.McIntosh@engr.UVic.CA (Mark  McIntosh)
  4. Subject: Re: How do I change postscript resumes into ASCII so I can print and kee
  5. In-Reply-To: jtrumbull@coast.almanac.bc.ca's message of Fri, 11 Sep 92 09:23:32 PDT
  6. Message-ID: <MARK.MCINTOSH.92Sep11105740@sombrio.UVic.CA>
  7. Lines: 94
  8. Sender: news@sol.UVic.CA
  9. Nntp-Posting-Host: sombrio.uvic.ca
  10. Organization: University of Victoria, Victoria, BC, Canada
  11. References: <XD4XqB1w164w@coast.almanac.bc.ca>
  12. Distribution: na
  13. Date: 11 Sep 92 18:57:40 GMT
  14.  
  15. On Fri, 11 Sep 92 09:23:32 PDT, jtrumbull@coast.almanac.bc.ca (Jim Trumbull    ) said:
  16. >The problem that we are having is that some of the resumes we receive
  17. >are in postsript format, and so far, are not usable.  Please let me
  18. >know what has to be done to convert these to ASCII - that is, if it
  19. >is at all possible.
  20.  
  21. It's not straightforward, but here are two UNIX based suggestions I've
  22. seen:
  23.  
  24. 1) A sed(1) macro, defined as a C-shell alias
  25.  
  26. alias unps \(sed \
  27.  \''s/%.*$//g;s/^[ \t]*[^()]*$//g;s/^[^(]*(//g;s/)[^(]*(/ /g;s/)[^)]*$//g;'\' \
  28.  \| tr '\\012' '\\040' \| tr -s '\\040' '\\040' \; echo \'\'\)
  29.  
  30. invoke as "unps < filename".  Will dump Postscript text strings found.
  31.  
  32. 2) A Perl program
  33.  
  34. #!/usr/unsupported/perl
  35. # We simulate a postscript interpreter (gack!)
  36. # Skip the leading glop
  37. #
  38. #From: rjc@onion.princeton.edu (Raymond Chen)
  39. #Date: 20 Mar 92 22:36:32 GMT
  40. #
  41. #Every twenty-five requests for a Postscript-To-Ascii filter I see,
  42. #I post this.  This was tailored for the Postscript that comes out of groff.
  43. #We actually simulate a (dumbed down) Postscript interpreter!
  44. #It's been so long, I can't remember if the code satisfactorily handles kerns.
  45. #
  46. #I used this script to de-Postscriptify a 1Meg postscript file.
  47. #
  48. #Unlike my previous dastardly perl script, this one actually has
  49. #comments!  (Not very useful ones, of course.)
  50.  
  51. while (<> !~ /^%%Page: 1 2/) { ; }
  52.  
  53. @stack = ();
  54. $y = 0;
  55.  
  56. main: while(<>){ chop;
  57. while (s/\\$//) { $_ .= <>; chop; }
  58. next if /^%/;
  59. s/\\\(/\\050/g;
  60. s/\\\)/\\051/g;
  61.   while ($_) {
  62.   s/^\s*//;#nuke leading whitespace
  63.   if (s/^([\d.-]+)//) { # a number
  64.   push(@stack, $1); }
  65.   elsif (s/^\/[@_a-zA-Z-]+//) { # a literal
  66.     push(@stack, ""); }
  67.   elsif (s/^\(([^)]*)\)//) { # a string
  68.     push(@stack, $1); }
  69.   elsif (s/^(\w+)//) { # a command
  70.     $c = $1;
  71.     if ($c eq "C") { print &spaceout($stack[2]); }
  72.     elsif ($c eq "E") { print "~" if $stack[1] > 0; print &fixup($stack[0]); }
  73.     elsif ($c eq "F") { print &fixup($stack[1]); }
  74.     elsif ($c eq "F2") { ; }
  75.     elsif ($c eq "G") { print &spaceout($stack[1]); }
  76.     elsif ($c eq "H") { print &fixup($stack[2]); }
  77.     elsif ($c eq "Q") { &moveshow; }
  78.     elsif ($c eq "R") { shift(@stack); &moveshow; }
  79.     elsif ($c eq "S") { shift(@stack); &spaceout($stack[0]); &moveshow; }
  80.     elsif ($c eq "T") { shift(@stack); shift(@stack); &moveshow; }
  81.     elsif ($c eq "BP") { }
  82.     elsif ($c eq "EP") { print "\n", "-" x 40, "\n"; }
  83.     elsif ($c eq "SF") { }
  84.     elsif ($c eq "end") { last main; }
  85.   else { print STDERR "\7", join(":", @stack), " <$c>?\n"; }
  86.   @stack = ();
  87.   }
  88.   elsif (s/^<(.*)>//) { # a hex string
  89.      $c = ""; $d = $1;
  90.      while ($d =~ s/(..)//) { $c .= sprintf("%c", hex($1)); }
  91.     push(@stack, $c); }
  92.   else { print STDERR "\7How to parse $_?\n"; }
  93.   }
  94.   }
  95.  
  96. sub moveshow {
  97.     if ($y != $stack[2]) { $y = $stack[2]; print "\n"; }
  98.     else { print "~"; }
  99.     print &fixup($stack[0]); 
  100. }
  101.  
  102. sub spaceout { @t = split(//, $_[0]); $_[0] = &fixup(join(" ", @t)); }
  103.  
  104. sub fixup { $_[0] =~ s/\.\.\.\.[.]*/\.\.\.\./; 
  105. $_[0] =~ s/\\(\d\d\d)/sprintf("%c",oct($1))/eg;
  106. $_[0] =~ s/\214/fi/g; $_[0] =~ s/\215/fl/g; 
  107. $_[0]; }
  108.  
  109.