SUMMARY:Printer accounting with NeWSprint 1.0

From: Joseph F. Young (
Date: Wed Nov 13 1991 - 05:21:41 CST

There is indeed a way to get around the NeWSprint 1.0 deficiencies
regarding accounting, by modifying the engine_ctl program to do it
anyway. Solutions for engine_ctl_SPARCprinter are described below.
I installed the patches from and we are now
getting the accounting information we need.

[Summary of responses follows]
From: Bill Unruh <>

Changes to the Sparc printer driver to allow it to keep track of pages printed.
This is a naive set of changes, with no warrenty that it won't do something
bad. I don't know what- we have used it for 7 mo and 20000 pages with no
I assume that the base location of the NeWSprint software is in the file
/news. Substitute the true location.

Changing The Sparcprinter engine controler

Go to the directory /news/np/devkit/examples/SPARCprinter. There is a
file called engine_ctl_SPARCprinter.c
Copy this file to engine_ctl_SPARCpage.c say and edit this file as follows.

At the beginning, in the Globals section, include the lines

long pages_count=0;
FILE *pgfile;

In the routine presscan(dir, token, cmd_code)
at the end of the while(copy_count--) block (inside the end of the block) put

    { rewind pgfile);

I print out the value of pages_count each time a page is sent to the printer to
make sure that it gets out even if the print driver dies for some reason in
middle of a job, and to make sure that I get all possible ways that it could
terminate. This is not efficient, but I do not understand the code well enough
to ensure that I will get all possibilities.

Finally, at the beginning of the program main() include the lines
if((pgfile=fopen("./page_count","r+"))!=(FILE *)NULL)

Compile this program.To compile it, you need to tell it a number of
includes and libraries:

cc $FLAGS -I/usr/openwin/include -I/news/np/devkit/include engine_ctl_SPARCpage.c -L/usr/openwin/include -lcps -L/news/np/devkit/lib -lengine_ctl.a

($FLAGS are whatever flags you like for your C compilation, and you may have to
rename /news/np/devkit/lib/engine_ctl.a to /news/np/devkit/lib/libengine_ctl.a )
Note that the Sun preinstalled version of openwindows does not include the
libcps.a file in the /usr/openwin/lib directory. It is on the openwindows tape
however. You do seem to need it.

Finally, you have to move a.out to
 /news/printer_classes/SPARCprinter/bin/engine_ctl_SPARCprinter, after saving
the original file. Make sure you do this when the printer is off line and not
printing. Make sure you set up the ownership and permissions of this file
properly ( the same as the original).

Now set up a file page_count in your spool directory for the SPARCprinter.
and initialise it with whatever initial number you want(eg,0).

Accounting For Print Jobs

In the /news/lpd/lpd_script, (which is called for every print job)
the present script prints the job information only if the banner/seperator
 page is also printed. This is useless for accounting, since a user can avoid
payment simply by running lpr -h.
So I have changed the lpr_script file so that the lines

 if [ -r $JOBDATA ];then
             if [ "$acctfile" ] && [ -w $acctfile ]; then
                cat $JOBDATA >>$acctfile

are replaced by

if [ "$acctfile" ] && [ -w $acctfile ]; then
             echo " " >>$acctfile
            echo "Printer sparc" >> $acctfile
            echo "User $username">>$acctfile
            echo "Host $hostname">>$acctfile
            echo "Date `date`" >> $acctfile
        if [ -r $JOBDATA ];then

which ensures that the data is printed out even if the banner page is not
printed. Then towards the beginning of the file I have put

PAGEI="`cat ./page_count `"
{ PAGEF=`cat ./page_count `
 echo "Pages= `echo $PAGEF - $PAGEI |bc`" >>$acctfile
Finally before each section of the file with the lines

 if [ pl_result -gt 0 ]; then
            exit 2
            exit 0
I have inserted the line
This calculates the total page count for the job and inserts it into the
accounting file.

Again, use the above as hints to doing a better job. It has worked for me
 for over 20000 pages, but no guarentees.
From: blight@ee.UManitoba.CA

We have been able to implement printer accounting
for a sparcprinter using mods to the newsprint
software. The changes and instructions are available
by anonymous ftp from (
in directory ~ftp/pub/sparcprinter.

Dave Blight
From: (Liam R. E. Quin)

Inb general it's quite hard. You'd have to redefine copypage and showpage
for NeWS to write to a file, but only when invoked as newsprint or users'll
get charged for pages `printed' in the previewer!

Redefine showpage and copypage to append a line to a file in one of the
startup files, and make the .param file in the spool directory invoke the
appropriate PostScript file, I suppose.

Sorry I can't help more, I don't have newsprint working, only a little of
the docs.

From: rodgers@maxwell.mmwb.ucsf.EDU (R. P. C. Rodgers, M.D.)

>Does anyone know any way to convince newsprint to produce a pac(8)
>format file or something with the same information? We are trying to
>keep track of who is using our SPARCprinter and how much paper, but
>newsprint does not appear to say anything about how many pages each
>job takes.

This was a problem we noted almost immediately, as one of the first
sites with NeWSprint. This is an unremediable problem with 1.0
which is supposedly going to be fixed in a future release. We
are a beta site for 2.0 but have not yet installed it so can not confirm
if it has been fixed in that release. I agree that it is annoying!

Cheerio, Rick Rodgers

>Joe Young

The following shar file contains changes to engine_ctl_SPARCprinter to
generate accounting records. I didn't write it, and unfortunately I've
lost any record of who did, but we've been using it here for several
months with no problems. One thing to watch out for is that the lock
file in /usr/spool/lpd/sparc or wherever must be readable by daemon so
that do_acct.c can get the username from it.

Michael Gordon
Electrical Engineering
Edinburgh University.

[ shar file omitted -- it is the version found at ]
Thanks also for everyone else's response:

From: Mark Ferraretto <>
From: Arie Bikker <>
From: (Connie Peterman)
From: (Jon A. Tankersley)
From: (Dorgival O Guedes Neto
From: Mark J. McIntosh <mmcintos@sirius.UVic.CA>

Joe Young

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:06:17 CDT