#!/usr/bin/perl use strict; use warnings; #since first page gets treated like the end of a chapter #we start with end_chapter being true. my $end_chapter = 1; #flags #for title my $title_fixed = 0; #for media type removal my $media_killed = 0; #time is used as filename to reduce possibility of files being overwri +tten. my $time = time(); #line required to redirect output to postprocessor (ie perfectbinder) my $to_pp = "<</OutputType(postprocessor)>>setpagedevice \n"; #line to force chapterization my $chapter = "true [] /110pProcs /ProcSet findresource /setchapters g +et exec \n"; #file declarations #my $outfile = "/var/spool/drop_box/autoq/$time.print"; #my $outfile = "./outputfile"; my $outfile = "c:/Quint.out";#only used for testing. uncomment previou +s line for production #my $filearg = $ARGV[0];#only used for testing. in production file com +es on STDIN #alias $infile to STDIN - this line is used for production #my $infile = \*STDIN; open (OUT, ">".$outfile) or die "Can't create temp file!!!!!!!!! $!"; #open (my $infile, "<".$filearg); my $line; while ($line = <>){ #handle chapter endings - currently denoted by null OutputType $line = chapterize($line); #print "End Chapter Setting: $end_chapter\n"; if ($end_chapter) { printline($line); handleSeps(); } else { printline($line); } } sub del_KDKHost { #if this the KDKHost line, delete it my $line = shift; if ($line =~ m/^%KDKHost:/){ $line = ""; print "Killed KDKHost Line\n"; } return $line; } sub make_title { #take XRXtitle line and create standard PS Title comment my $line = shift; if ($line =~ m!^%XRXtitle:!){ my @parts = split (/: /, $line); my $title = pop (@parts); $title =~ s!(\r\n)!!; $line = "%%Title: ($title)\n"; } $title_fixed = 1; return $line; } sub chapterize { #if OutputType is null, this is the end of a book. #replace the OutputType line with the perfectbinder command my $line = shift; if ($line =~ m!^<</OutputType \(\)>>setpagedevice!) { $line = $chapter; $end_chapter = 1; } return $line; } sub handleSeps { #if we just made a chapter, or this is the beginning of the file #we have to make the next 2 pages come out of the top exit my $counter= 0; my $file = shift; my $line; #print "Entered HandleSeps routine \n"; #uncomment for debug while ($line = <>) { #if its the KDKHost line, delete it #we have to do it here because #it is always in the header #and the header is processed as part of the #chapterization process. $line = del_KDKHost($line); $line = make_title($line); #delete media calls. These will always be at top of file as we +ll unless ($media_killed){ $line = kill_media($line, "pinky", "UNIVERSALID"); } #if we have started a new page #increment page counter and if we are on the 3rd page #since chapter break, insert line for output to perfect binder if ($counter <= 3) { if ($line =~ m!%%BeginPageSetup!){ $counter++; if ($counter==3){ #print "Begin Chapter - $linecount \n"; $line .= "$to_pp"; $counter = 0; $end_chapter = 0; printline($line); return; } } #if it is the OutputType line for this page, change to top + output elsif ($line =~ m!<</OutputType\(Stacker\)>>setpagedevice! +){ #print "Stacker Line \n"; $line =~ s/Stacker/top/; } } printline($line); } } sub kill_media { #sub takes line and a list of paper types to remove #and kills unwanted media calls. #We do this because jobs come with DocumentMediaReuqired #set to all possible media types, even if they aren't #actually used in this document. my $line = shift; my $media; if ($line =~ m!^%%DocumentMedia:!){ $media_killed=1; printline($line); while ($line = <>){ foreach $media (@_) { if ($line =~ m!$media!){ $line = ""; print "Killed media type: $media\n"; last; } elsif ($line !~ m!^%%\+!){ print "Returning Line: $line\n"; return $line; } } printline($line); } } else { return $line; } } sub printline { my $out_line = shift; print OUT $out_line; #print "$out_line\n" }
In reply to Using null filehandle by digger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |