Article View: comp.lang.postscript
Article #2681Re: PostScript page counter?
From: Saumen K Dutta
Date: Tue, 31 Jul 1990 20:11
Date: Tue, 31 Jul 1990 20:11
80 lines
2785 bytes
2785 bytes
In article <226@heaven.woodside.ca.us> glenn@heaven..... writes
>
>In reality, almost every PostScript driver defines some procedure in the
>prologue the file called "EndPage" or "EP" or "SP" or whatever, and
>there is one invocation of that procedure for each page printed. With
>a moderately simple parser, it should be possible to figure out the
>name of the procedure that contains "showpage" in it somewhere, then
>go looking for instances of that procedure name in the rest of the
>document. Example:
>
> /BP { /page_save save def } def % begin-page
> /EP { page_save restore showpage } def % end-page
> ...
> hn GilmoBP
> % lots of stuff
> EP
>
>Any volunteers to write the simple parser? If it can recognize the
>basic syntax
>
> /name { { stuff } }
>
>I suspect that you could find the procedure that contained "showpage"
>fairly easily. Any volunteers? Want to endear yourself to the
>PostScript community with a great page-counting program?
>
Based on the above idea I tried to write a simple scanner ( I won't
call it parser ) with well available "awk" script. I ran it in one or
two outputs and it works well. I request anybody interested to read it,
use it and criticize it! I am not responsible for any bugs though I
would like to know about them.
--------------- CUT HERE --------------------------
BEGIN {
found = 0; bracket = 0; procname = 0; Pages = 0}
{for (i = 1; i <= NF; i++) {
if ( substr($i,1,1) == "%" ) {next};
if (substr($1,1,1) == "/") {
if ((bracket == 0)&&(found == 0))
{procname = substr($1,2,length($1)-1)}
};
if ( substr($i,1,1) == "{" ) { bracket ++};
if ( substr($i,length($i),1) == "}" ) {bracket --};
if ($i == "showpage") {found = 1 };
if ((found == 1)&&($i == procname)) { Pages ++};
}
}
END {printf("Pages : %d\n",Pages)}
----------- CUT HERE ---------------------------------
to run it put it into a file and run the command
awk -f <program-file> <postscript-file>
--
_ ||Internet: skdutta@cssun.tamu.edu
( /_ _ / --/-/- _ ||Bitnet : skd8107@tamvenus.bitnet
__)_/(_____(_/_(_/_(_(__(_/_______ ||Uucp : uunet!cssun.tamu.edu!skdutta
.. ||Yellnet: (409) 846-8803
Technical Details
Message-ID:
<7015@helios.TAMU.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!cs.tamu.eduReferences:
<1990Jul26.173633.13911@msuinfo.cl.msu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!cs.tamu.edu From: skdutta@cs.tamu.edu (Saumen K Dutta) Newsgroups: comp.lang.postscript Subject: Re: PostScript page counter? Message-ID: <7015@helios.TAMU.EDU> Date: 31 Jul 90 20:11:01 GMT References: <1990Jul26.173633.13911@msuinfo.cl.msu.edu> Sender: usenet@helios.TAMU.EDU Organization: Computer Science Department, Texas A&M University Lines: 80