summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/pointRuler/ps2eps
blob: 2362ebf00baca0a95a6a24ebd62db3e3a58323eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' # -*-perl-*-
        if 0;
# The expression in the previous line replaces the unix specific line 
# {#!/usr/bin/perl}.   
# ps2eps - convert PostScript to EPS (Encapsulated PostScript) files
# -------------------------------------------------------------------
# (C)opyright 1999-2002 Roland Bless
#
# This program is free software; you can redistribute it and/or modify     
# it under the terms of the GNU General Public License as published by     
# the Free Software Foundation; either version 2 of the License, or        
# (at your option) any later version.                                      
#                                                                          
# This program is distributed in the hope that it will be useful,          
# but WITHOUT ANY WARRANTY; without even the implied warranty of           
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
# GNU General Public License for more details.                             
#                                                                          
# You should have received a copy of the GNU General Public License        
# along with this program; if not, write to the Free Software              
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Author: Roland Bless
# Send bug reports to roland@bless.de
# -------------------------------------------------------------------
# Additional filtering is done when Windows generated PostScript files
# are processed. Some instructions will otherwise lead to bad output
# if EPS-file gets embedded into other PostScript files.
# Requirements:
# + perl
# + gs   (ghostscript supporting pbm output)
# + bbox (a little C program [ANSI-C - should work on every platform]
#         for calculation of the actual BoundingBox)
# -------------------------------------------------------
# $Id: ps2eps,v 1.39 2002/07/10 09:50:28 bless Exp $
# -------------------------------------------------------
$prgname= "ps2eps";
$ghostscriptname= "gs";
$bboxname= "bbox";
$version= '$Id: ps2eps,v 1.39 2002/07/10 09:50:28 bless Exp $'; #'
$insertPScode= 1;     # Insert surrounding Postscript code
$infhandle = STDIN;   # Standard input is the default input file
$outfhandle = STDOUT; # Standard output is default output if STDIN is input
$infname= '-';
$outfname= '-';
$forceoverwrite= 0;   # do not overwrite existing files
$ignoreBB= 0;         # ignore existing Bounding Box comment
$removeDSC= 1;        # remove Adobe document structure comments
$removeADO= 1;        # remove Adobe printer Driver console Output [Page: ...]
$ignoreEOFDSC= 0;     # ignore %%EOF DSC hint
$removePreview= 0;    # remove preview
$quiet= 0;            # write progress to stdout
$resolution= 144;     # resolution for bounding box calculation is 2x72 dpi
$trytofixps= 1;       # try to fix postscript code
$forcefixps= 0;       # fix postscript code unconditionally if eq 1
$clip=0;              # do not clip
$inch=2.54;           # one inch is 2.54cm
$fullcolors= 1;       # use ppm format (24-bit full color)
$trailerseen= 0;      # Trailer comment seen?
$PSversion="2.0";     # default Postscript Version
$PSDSCversion="2.0";  # default Postscript DSC Version
$gpar="";
$trigger= 0;

#$debug=1; # Turn this on if you want to see the gs call

@ver= split(/ /,$version);

# filename for temporary files
if (defined($ENV{'TMP'}))
    { 
      $tmpdir= $ENV{'TMP'};
      $filesep= ($tmpdir =~ /^?\:\\/) ? '\\' : '/';
      if ($tmpdir =~ /$filesep$/)  
        { $tmpfname= $tmpdir . "$prgname.$$"; }
      else 
        { $tmpfname= $tmpdir . "$filesep$prgname.$$"; }
    }
else #assume we're on a UNIXBOX
    { $tmpfname= "/tmp/" . "$prgname.$$"; }

$licensetxt= "\
    This program is free software; you can redistribute it and/or modify\
    it under the terms of the GNU General Public License as published by\
    the Free Software Foundation; either version 2 of the License, or\
    (at your option) any later version.\
\
    This program is distributed in the hope that it will be useful,\
    but WITHOUT ANY WARRANTY; without even the implied warranty of\
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
    GNU General Public License for more details.\
\
    You should have received a copy of the GNU General Public License\
    along with this program; if not, write to the Free Software\
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n";

@prgidtxt= ( "$prgname - convert PostScript to EPS (Encapsulated PostScript) files\n",
	     "(C)opyright 1998-2002 Roland Bless\n\n" );

@helptxt= ("Version: @ver[2]\n",
          "Operation:\n",
          " Without any argument, $prgname reads from standard input\n",
          " and writes to standard output.\n",
          " If filenames are given as arguments they are processed\n",
          " one by one and output files are written to filenames\n",
          " with extension '.eps'. If input filenames have the extension\n",
          " '.ps' or '.prn', this extension is replaced with '.eps'.\n",
          " In all other cases '.eps' is appended to the input filename.\n",
          " Please note that PostScript files for input should contain\n",
          " only one single page.\n\n");

@usagetxt= ("Syntax:\n",
            " $prgname [-f] [-q] [-N] [-n] [-P] [-c] [-C] [-m] [-B] [-E] [-s<pagedim>] [-l] [-h|--help] [-L] [-V|--version] [--] [psfile1] [psfile2] [...]\n",
            "Options:\n",
            " -f     force overwriting existing files\n",
            " -q     quiet operation (no output while processing files)\n",
            " -N     do not insert any postscript code\n",
            " -n     do not try to fix postscript code\n",
            " -P     remove preview image (smaller file, but no preview)\n",
            " -F     fix postscript code unconditionally\n",
            " -c     preserve document structure comments\n",
	    " -C     insert postscript code for clipping\n",
            " -m     use black/white bitmap as base for calculation\n",
            " -s<pagedim> pagesize in cm (default) or in, format XxY[cm|in], where X and Y are numbers\n",
            " -l     expand the original bounding box by one point in each direction\n",
	    " -B     do not use existing bounding box as page size for rendering\n",
	    " -E     do not use %%EOF as hint for end of file\n",
            " --help, \n",
            " -h     help information\n",
            " -L     show licensing information\n",
            " --version,\n",
            " -V     show version information\n",
            " --     all following arguments are treated as files\n",
            "        (allows filenames starting with -)\n",
            "\n",
            "Arguments:\n",
            " One or more names of PostScript files for input\n");



# -- argument checking
$no_of_files= 0;
ARGCHECK:
while ($arg= shift) # process options
{
  if ( $arg =~ /^-/ ) #it is an option
  {
    if ( $arg =~ /^--$/ ) # after -- only filenames can follow
    {
      while ($arg= shift) { @filenames[$no_of_files]= $arg; $no_of_files++; };
      last ARGCHECK;
    }
    if ( $arg eq '-f' ) { $forceoverwrite= 1; next ARGCHECK; }
    if ( $arg eq '-q' ) { $quiet= 1; next ARGCHECK; }
    if ( $arg eq '-m' ) { $fullcolors= 0; next ARGCHECK; }
    if ( $arg eq '-n' ) { $trytofixps= 0; next ARGCHECK; }
    if ( $arg eq '-F' ) { $forcefixps= 1; $trytofixps= 1; next ARGCHECK; }
    if ( $arg eq '-N' ) { $insertPScode= 0; next ARGCHECK; }
    if ( $arg eq '-P' ) { $removePreview= 1; next ARGCHECK; }
    if ( $arg eq '-c' ) { $removeDSC= 0; next ARGCHECK; }
    if ( $arg eq '-C' ) { $clip= 1; next ARGCHECK; }
    if ( $arg eq '-l' ) { $looseBB= '-l'; next ARGCHECK; }
    if ( $arg eq '-B' ) { $ignoreBB= 1; next ARGCHECK; }
    if ( $arg eq '-E' ) { $ignoreEOFDSC= 1; next ARGCHECK; }
    if ( $arg =~ '^-s' )
    {
      # if explicit size is given, ignore existing BoundingBox always
      $ignoreBB= 1; 
      $pagedimension= substr($arg,2); # dimension follows -s directly
      ($x_dim, $x, $y_dim, $unit)= split(/(x|cm|in)/,$pagedimension);
      if ( $x_dim !~ /^\d*\.?\d*$/ ) 
         { die "$x_dim in $arg is not a valid number"; } 
      if ( $y_dim !~ /^\d*\.?\d*$/ ) 
         { die "$y_dim in $arg is not a valid number"; } 
      
      #print STDERR "xdim: $x_dim ydim: $y_dim unit:$unit\n" ;
      if ( $unit ne 'in' ) # assume centimeters
      { # calculate dimension in pixels (remember: resolution is in dpi)
        $xpixels= int(($x_dim * $resolution) / $inch)+1;
        $ypixels= int(($y_dim * $resolution) / $inch)+1;
        $gpar= "-g${xpixels}x${ypixels}";
      }
      else
      {
        $xpixels= int($x_dim * $resolution)+1;
        $ypixels= int($y_dim * $resolution)+1;
        $gpar= "-g${xpixels}x${ypixels}";
      }
      next ARGCHECK;
    }
    if ( $arg eq '-h' || $arg eq '--help' ) 
    { 
      die @prgidtxt,@helptxt,@usagetxt,
      "\nAuthor: Roland Bless (roland\@bless.de)\n\n"
    } #end -h
    if ( $arg eq '-L' ) 
    { 
      die @prgidtxt,$licensetxt,
      "\nAuthor: Roland Bless (roland\@bless.de)\n\n"
    } #end -L
    if ( $arg eq '-V' || $arg eq '--version') 
    { 
	die @prgidtxt,"Version: @ver[2]\n";
    } #end -V
    die "$prgname: unknown option $arg\n",@usagetxt;
  }
  else
  {
    # it is a filename
    @filenames[$no_of_files++]= $arg;
  }
} #end while ARGCHECK



if ($no_of_files == 0) # no file arguments, use STDIN as input
{
  @filenames[0]= '-';
}

if (!$quiet) { print STDERR "Input files: @filenames\n"; }

$device= $fullcolors ? "ppmraw" : "pbmraw";

PROCESSFILE:
while ($infname= (shift @filenames))
{
  # reset filter definitions for each file
  undef $linefilter; 
  undef $rangefilter_begin;
  undef $rangefilter_end;
  $fixthisps= $trytofixps;
  $fixmsgprinted= 0;

  if (!$quiet) { print STDERR "Processing: $infname\n"; }
  unless (open($infhandle,"<$infname"))
  { # skip over this file 
    print STDERR "$prgname: Can't open $infname: $!\n";
    next PROCESSFILE;
  }
 
  # buffer input from stdin into temporary file, because it has to be read twice
  # one for ghostscript, the other for generating output
  if ($infname eq '-') # input is stdin
  {
    $tmpfhandle='';
    open($tmpfhandle,">$tmpfname") or 
       die "Cannot open temporary file $tmpfname for writing: $!\n";
  }
  else # input is not stdin
  {
    undef $tmpfhandle;
    #if filename ends with .ps or .prn, replace the extension with .eps
    if ($infname =~ /\.(ps|prn)$/i) 
    { 
      $outfname= $infname; $outfname =~ s/\.(ps|prn)$/.eps/i; 
    }
    else # otherwise simply append the extension .eps
    {
        $outfname= $infname . ".eps";
    }
    if (!$forceoverwrite and -s "$outfname") 
      { 
        die "$prgname: Sorry, file named $outfname already exists,",
            " will not overwrite it.\n",
            " You will have to use the -f option, delete it or rename it",
            " before running $prgname again.\n";   
      }
    else
    {
      open($outfhandle,">$outfname") or die "Can't open file $outfname for writing: $!\n";
    }
  } #end else input is not stdin
  
  $linefilter= '^$'; # filter empty lines by default
  while (<$infhandle>)
  {
    if (/%!PS-Adobe-(\S+).*EPSF-(\S+)/)
    {
      $PSversion=$1;
      $PSDSCversion=$2;
      if (! ($PSversion =~ /\d+\.\d+/))
      {
        $PSDSCversion="2.0";
      }
      if (! ($PSDSCversion =~ /\d+\.\d+/))
      {
        $PSDSCversion="2.0";
      }
    }
    if (!$ignoreBB)
    {
      if ( /^%%\s*BoundingBox:\s*(.*)/ && !defined($eBBllx) )
      {
        ($eBBllx,$eBBlly,$eBBurx,$eBBury,$rest)= split /\s/,$1;
        # print STDERR "$eBBllx,$eBBlly,$eBBurx,$eBBury\n";
        $xpixels= int(($eBBurx * $resolution)/72)+1;
        $ypixels= int(($eBBury * $resolution)/72)+1;
        $gpar= "-g${xpixels}x${ypixels}";
        # check for meaningful values
        if (($xpixels <= 1) || ($ypixels <= 1))
        {
	    $gpar=""; undef $eBBllx;
        }
	else
	{
	    if (!$quiet) 
	    {
		print STDERR "Rendering with existing $_";
	    }
	}
      }
    }
    if ($fixthisps) # try to fix bad postscript code
    {
      # check for Windows 3.x output
      if ( /^Win.*Dict/ )
      { 
        if (!$quiet && !$fixmsgprinted) 
           { print STDERR "Windows 3.5 generated Postscript file detected, fixing\n"; }
        $linefilter= '^(EJ|RS)';
        $rangefilter_begin= '^statusdict';
        $rangefilter_end= 'cvx\ settransfer$';  #'
        $fixmsgprinted= 1; # stop printing message
      }
      else
      {
        if ( /^%%Creator:\s*Wind.U\s*Xprinter/ )
        { 
	    if (!$quiet && !$fixmsgprinted) 
	    { print STDERR "StarOffice generated Postscript file detected, fixing\n"; }
	    $linefilter= '^rs';
	    $fixmsgprinted= 1; # stop printing message
	}
      else
      {
        if ( $forcefixps || 
             /^\/NTPS/ || 
             /Creator:\s*(AdobePS|Pscript|.*Windows)/i ) #check for NT generated output
        {
          if (!$quiet && !$fixmsgprinted) 
          { 
            print STDERR "Windows generated Postscript file detected, fixing\n"; 
	  }
	  $rangefilter_begin= '^(\[\{|featurebegin\{)$'; #'
	  $rangefilter_end= '^(\} stopped cleartomark|\}featurecleanup)';
	  $triggered_rangefilter_begin= '^(1 1 1 SC)$'; #'
	  $triggered_rangefilter_end= '^(AF)$';
	  $fixmsgprinted= 1; # stop printing message
        } # end if NTPS
      } #end else
    }
    } #end if trytofixps

    if (defined($tmpfhandle))
    { 
      print $tmpfhandle $_ or die "$prgname: Failure during writing to temporary file $tmpfname";
    }

    if (/^%%EOF\s*$/) 
    {
	$totalEOFDSC++
    }
  } #end while <$infhandle>
  
  if (defined($tmpfhandle)) 
    { close($tmpfhandle); }
  else
    { 
      $tmpfhandle= $infhandle;
      $tmpfname= $infname; 
    }
  

  # calculate the bounding box
  if (!$quiet) { print STDERR "Calculating Bounding Box..."; }
  $cmdline="$ghostscriptname -dNOPAUSE -q $gpar -r$resolution -sDEVICE=$device -sOutputFile=- $tmpfname -c showpage -c quit | $bboxname $looseBB -r $resolution";
  if ($debug) { print STDERR "\ncalling: $cmdline\n"; }

  $boundingbox=`$cmdline`;
    
  #check result
  if ($boundingbox !~ /^%%BoundingBox/)
  {
    print STDERR "Error: Could not determine bounding box!\n",
    "I suppose $ghostscriptname had some trouble interpreting the ps-file\n",
    "or $bboxname is not in your search path of executables\n";
  }
  if ($clip)
  {
    # extend clipping box by 1 point
    $boundingbox =~ /^%%.*BoundingBox:\s*(.*)/;
    ($cBBllx,$cBBlly,$cBBurx,$cBBury,$rest)= split(/\s/,$1);
    if ($cBBllx > 0) { $cBBllx--; }
    if ($cBBlly > 0) { $cBBlly--; }
    $cBBurx++; $cBBury++;
    $boundingbox = "%%BoundingBox: $cBBllx $cBBlly $cBBurx $cBBury\n";
  }

  if (!$quiet) { print STDERR "ready. $boundingbox" };
  
  $before_startps= 1;
  $inserted_prolog= 0;
  $prolog_passed= 0;
  
  if (!$quiet) { print STDERR "Creating output file $outfname..."; }
  
  open($tmpfhandle,"<$tmpfname") or die "Cannot open file $tmpfname for reading";
  CREATEOUTPUT: 
  while (<$tmpfhandle>) 
  {
    $binarysection=/^(%%BeginBinary)|(beginimage)$/ ... /^(%%EndBinary)|^(endimage)/;
    if ( !$binarysection )
    {
      s/\r?\n?$//;       # remove CR and/or LF at end of line
    }
    if ($before_startps)
    {
      if ( /%!PS-Adobe.*/ ) { $before_startps= 0; }
        next CREATEOUTPUT;
    }
    else # we are in regular postscript code
    {
      if ( /^%%EOF\s*$/ )
      {
	$seenEOF++
      }
            
      if (! $inserted_prolog)
      {
        print $outfhandle "%!PS-Adobe-$PSversion EPSF-$PSDSCversion\n";
        print $outfhandle $boundingbox;
        print $outfhandle "% EPSF created by ps2eps @ver[2]\n";
        $inserted_prolog= 1;
        redo CREATEOUTPUT;
      }
      else #inserted_prolog
      {
        if (! $prolog_passed)
        {   
          #ignore the following lines in the prolog
          if ( /^%%BoundingBox/ ||
               /^%%Pages/       ||
               /^%%BeginProlog/ ||
               /^%%EndProlog/   ||
               ($removeDSC && /^%%.*: \(atend\)/) ||
	       ($removePreview && (/^%%BeginPreview/ ... /^%%EndPreview/)) ) 
          { next CREATEOUTPUT; }
          else
          {
            if ( /^[^%].*/ ||
                 /^%%EndComments/ ) # line is not a comment
            { 
              #output postscript code for proper EPS file
              if ($insertPScode) 
              { print $outfhandle "%%EndComments\n", 
                                  "%%BeginProlog\n";
              }
              if ($clip)
              {
                 printf $outfhandle "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath clip\n",$cBBllx,$cBBlly,$cBBurx,$cBBlly,$cBBurx,$cBBury,$cBBllx,$cBBury
              }
              if ($insertPScode) 
              {              
                print $outfhandle  "save\n",
                                   "countdictstack\n",
                                   "mark\n",
                                   "newpath\n",
                                   "/showpage {} def\n",
		                   "/setpagedevice {pop} def",
                         	   "%%EndProlog\n",
                                   "%%Page 1 1\n";
              }
              $prolog_passed= 1;
              if (/^%%EndComments/) { next CREATEOUTPUT; }
            }
          }
        } 
        else # main part of postscript file
        {
          #end of postscript file reached?
	  #Usually the DSC %%EOF signifies the end
          if ( eof($tmpfhandle) || 
	       ($ignoreEOFDSC == 0 && /^%%EOF\s*$/ && $seenEOF == $totalEOFDSC)
               || ( $trailerseen && /^II\*\000.*/ )	       
             ) 
          { 
	    #do not forget to print last line if not terminated by LF
	    if ( eof($tmpfhandle) && !/^$/ && !/^%%EOF\s*$/ ) # do not insert %%EOF twice
	    {
		print $outfhandle $_,"\n";
	    }
            #add appropriate trailer
            if ($insertPScode) 
	    {              
		print $outfhandle "%%Trailer\n",
		                  "cleartomark\n", 
		                  "countdictstack\n", 
                                  "exch sub { end } repeat\n",
		                  "restore\n",
		                  "%%EOF\n"; 
	    }
            last CREATEOUTPUT; 
          } # stop output

	  if ( /^%%Trailer\s*$/ )
	  {
	    $trailerseen=1;
	  }
	  else
	  {
	    if (!/^/s*$/)
	    {
		$trailerseen=0;
	    }
	  }
          # check for trigger
          if (/^eoclip$/)
          {
            $trigger= 1;
          };
          # remove the following lines
          if ( !$binarysection # only when not in binary section
	       &&
	       (
	       ($removePreview && (/^%%BeginPreview/ ... /^%%EndPreview/))
	       ||                        # no preview
               (defined($rangefilter_begin) && 
                 (/$rangefilter_begin/ ... /$rangefilter_end/)
               ) 
               ||
               (defined($triggered_rangefilter_begin) && 
                $trigger &&
                (/$triggered_rangefilter_begin/ ... /$triggered_rangefilter_end/)
               ) 
	       ||
               /$linefilter/             # lines by linefilter
	       ||
	       ($removeDSC && (/^%( |!)(\w )+/ || /^%%/)) # any type of structured comment
	       ||
	       ($removeADO && 
		(/^statusdict begin.*ProductName.*print product print.*flush end\r?\n?$/ ||
                 /^\(%%\[\s*(Page:.*|LastPage)\s*\]%%\)\s*=\s*\r?\n?/ ))
	       ||                    
	       /^$/                       # empty lines
               )
             )
          { 
	      next CREATEOUTPUT; 
	  }
  
          # sanity check
          if ( /clear|erasepage|initmatrix|initclip|initgraphics|startjob|\
                cleardictstack|setmatrix|setpagedevice|copypage|grestoreall|\
                exitserver|quit/ )
             { $notsane= 1; }
          else
             { $notsane= 0; }
        } # end else (this is main part) 

        # Output the postscript line
        print $outfhandle $_;
	if (!$binarysection)
	{
	    print $outfhandle "\n"; 
	}
      } # end else prolog_passed 
    } # end else inserted_prolog
  } # end while CREATEOUTPUT

  close($tmpfhandle);

  if ($tmpfname ne $infname) { unlink "$tmpfname"; } #remove temporary file

  close ($outfhandle);
  if (!$quiet) { print STDERR "ready.\n"; }
  if ($notsane and !$quiet)
  { 
    print STDERR "Warning: EPS-output for $infname is not sane, at least one\n",
                 "of the following commands was still present:\n",
                 "clear erasepage initmatrix initclip initgraphics startjob\n",
                 "cleardictstack setmatrix setpagedevice copypage grestoreall\n",
                 "exitserver quit\n";
  }
} #end while PROCESSFILE

# ---- end of perl-script -------