home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / perl / 7101 < prev    next >
Encoding:
Text File  |  1992-11-23  |  1.8 KB  |  57 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!brunix!brunix!jgm
  3. From: jgm@cs.brown.edu (Jonathan Monsarrat)
  4. Subject: Re: perl and Post Script
  5. Message-ID: <1992Nov23.130915.19496@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown University Department of Computer Science
  8. References: <1992Nov22.163612.15510@r-node.gts.org>
  9. Date: Mon, 23 Nov 1992 13:09:15 GMT
  10. Lines: 45
  11.  
  12. > Could someone suggest a script which converts Post Script files into
  13. > simple ASCII format, stripping the formatting characters and the
  14. > brackets?
  15.  
  16. Doubtless some Perl God can write this with one line of /%$\/#Q$%#3'!/.
  17. Here's it is with 23!  :)
  18.  
  19. Let me know if you want a PS->ASCII converter that retains positional
  20. information. I have one written in PostScript. In general, because
  21. ASCII "A" does not always print "A" on the printer (in some weirdo
  22. fonts like Symbol), translating to ASCII from strings perfectly is not
  23. possible. Some programs like TeX deliberately replace the double-quote
  24. character with a non-ASCII font encoding, etc, etc.
  25.  
  26. Handling the string  (foo\))  properly is left as an exercise to the reader.
  27.  
  28. -Jon
  29. %! Jon Monsarrat   jgm@cs.brown.edu   Brown University %! Obfuscated PostScript
  30. 0 0 moveto 15 setlinewidth(qlllll-??LHHL??llH?hH7t,7olCAHH@)1 setlinejoin{dup
  31. 10 mul rotate 80 lt{50 0 rlineto}{50 0 rmoveto}ifelse}forall stroke showpage
  32.  
  33. ------------------------------ cut here ----------------------------
  34. #! /usr/local/bin/perl -P
  35. ########################################################
  36. # ps2ascii: look through a PostScript file for ASCII strings
  37. #
  38. # Usage:
  39. #     ps2ascii <inputfile.ps>
  40. #
  41. ########################################################
  42.  
  43. $out = "";
  44. while(<>)
  45. {
  46.   $line = $_;
  47.   while($line =~/\((.*)\)(.*)/) {
  48.        $line = $2;
  49.        if(length($out)+length($1) > 76) {
  50.          print "$out\n";
  51.          $out="";
  52.        }
  53.        $out=$out." ".$1;
  54.   }
  55. }
  56. print "$out\n";
  57.