[comp.unix.xenix] Printing directly to the printer.

david@actsn.fay.ar.us (David Summers) (02/21/90)

I have a question regarding the way the print spooler works on Xenix:
Mainly, I need to print directly to the printer (if nothing else is printing
to it at the time).  Therefore, I need to find out the procedure for locking
the print spooler.  In my programs, I will write a small subroutine that will
try to attempt a lock on the printer and if it can't obtain the lock then it
will print to the printer spooler instead of directly to the printer.  Could
anyone advise me as to how this could be done?  Right now, any time I need to
print a large file, it takes up a lot more disk space because I have to spool
it to the printer rather than just print directly.  If I could do it my way
then that would save a lot of disk space (normally). 

I asked this question a few months ago and got the response from several people
that there was no need to do what I was suggesting.  I think that saving disk
space is an adequate need.

   Any help would be greatly appreciated.

    Thanks!
   - David Summers

-- 
David Summers                "Be Original! Drink Dr. Pepper like everyone else!"
(David.Summers@actsn.fay.ar.us)

scott@bbxsda.UUCP (Scott Amspoker) (02/21/90)

In article <178@actsn.fay.ar.us> david@actsn.fay.ar.us (David Summers) writes:
>I have a question regarding the way the print spooler works on Xenix:
>Mainly, I need to print directly to the printer (if nothing else is printing
>to it at the time).  Therefore, I need to find out the procedure for locking
>the print spooler.

You will have to modify the spooler interface scripts.  These may be 
found in the directory '/usr/spool/lp/interface'.  There is an
interface script for each printer you have set up.  The basic
idea is to modify the script to create a lock file at the beginning
and remove the lock file at the end.  However, this is not quite
as straight forward as it sounds.  You must guarantee that a
'test-and-set' type of operation is performed without interruption.
This can be accomplished with the following shell code:

----------------
# umask is used to force r--r--r-- permissions on the create
umask 333

# must use sub-shell to redirect error message
( until >$LOCKFILE
    do
	:
    done ) 2>/dev/null;
---------------

The above code will create a lock file with r--r--r-- permissions
or loop until an existing lockfile is removed.

In addition to the above code you will also need to place the following
command immediately after it:

            trap "rm $LOCKFILE; exit 0" 0 15 2 9

This will cause the lockfile to be removed whenever the script
terminates (either normally or by the 'cancel' command).

>I asked this question a few months ago and got the response from several people
>that there was no need to do what I was suggesting.  I think that saving disk
>space is an adequate need.

Obviously these people have never tried to do printer output to pre-printed
forms either.  I called SCO once about the spooler lockfile problem and
they couldn't imagine why I would ever try to write directly to the
printer.  I mentioned that it is diffcult for an operator to interact
with a test pattern being printed on invoice forms when using a spooler.
Their response was, "oh".  

-- 
Scott Amspoker
Basis International, Albuquerque, NM
(505) 345-5232
unmvax.cs.unm.edu!bbx!bbxsda!scott