home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name PRGETQ -- Get the name of the Nth file in the print
- * spooler's queue, as well number of items
- * present.
- *
- * Synopsis ret = prgetq (n, psize, pfile);
- *
- * int ret Return code -- 0 (PR_OK) if no error
- *
- * int n The queue item # to be returned in
- * pfile. 0 for the spooler active file
- * (file being printed), 1 for the next
- * in line, etc.
- *
- * int *psize Pointer to the size of the queue
- * (returned).
- *
- * char *pfile Name of the nth file in the queue
- * (returned). The length of the
- * filename returned is 0 if the Nth
- * item does not exist for whatever
- * reason (n > size of current
- * queue, spooler not installed, etc).
- *
- * Note: You MUST reserve at least 65
- * bytes for this string!
- *
- * Description This function gets the pathname of the nth item in the
- * DOS print queue. If the return code is non-zero, psize
- * is guaranteed to be 0, and *pfile is guaranteed to be
- * NUL.
- *
- * Special If the DOS the machine is running is older than 3.00,
- * Cases or the print spooler has not been installed, the
- * size returned is guaranteed to be 0.
- *
- * Returns ret 0 (PR_OK) if no error, otherwise
- * one of the following values:
- *
- * 0 (PR_OK) Item sucessfully returned.
- *
- * 1 (PR_INSTAL) Spooler not installed (or)
- * DOS older than 3.00.
- *
- * 6 (PR_EMPTY) The spooler queue is empty.
- *
- * 7 (PR_RANGE) Requested item (n) out of range.
- *
- * 9 (PR_BUSY) Spooler busy; unable to get
- * attention. Try again later.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1987,1989
- *
- **/
-
-
- #include <dos.h>
-
- #include <bprint.h>
- #include <butil.h>
-
- #define PR_QPATH_SIZE 64 /* the size of a path name in the */
- /* printer queue. */
-
- #define NUL '\0'
-
-
- int prgetq (n, psize, pfile)
- int n;
- int *psize;
- char *pfile;
- {
- char far *pqueue;
- int err;
- struct SREGS sregs;
- union REGS regs;
-
- err = PR_OK;
- pfile[0] = NUL;
- *psize = 0;
-
- if (! prinstld ())
- return (PR_INSTAL);
-
- /* We get the address of the spooler queue, which freezes the */
- /* queue until we thaw it. This is so that data in the queue */
- /* does not move around while we are reading it. */
- regs.x.ax = 0x0104; /* device 1 (spool), request 4 (queue */
- /* address) */
-
- int86x (PR_DOS_INT, ®s, ®s, &sregs);
-
- if (regs.x.cflag)
- err = regs.x.ax;
-
- else
- {
- /* Get a char * to the queue items. */
- pqueue = uttofar (sregs.ds, regs.x.si, char);
-
- /* Normalize to inhibit wrap-around. */
- pqueue = utnorm (pqueue, char);
-
- /* Count the number of queue items. */
- for (; (*pqueue != NUL); (*psize)++, pqueue += PR_QPATH_SIZE)
- ;
-
- if (*psize == 0)
- err = PR_EMPTY;
-
- else if ((*psize < (n + 1)) || (n < 0))
- err = PR_RANGE;
-
- /* When we get to here, pqueue is pointing past the last */
- /* queue item. We have to back it up to point at the item */
- /* requested */
-
- else
- {
- for (; (n < *psize); pqueue -= PR_QPATH_SIZE, n++)
- ;
-
- /* Copy the string. Can't use strcpy because pqueue and */
- /* path are in different memory models. */
-
- for (; (*pfile = *pqueue) != NUL; pfile++, pqueue++)
- ;
-
- *pfile = NUL;
- }
- }
-
- regs.x.ax = 0x0105; /* device 1 (spool), request 5 (thaw */
- /* the queue). */
-
- int86 (PR_DOS_INT, ®s, ®s);
-
- if (err != 0)
- {
- *psize = 0;
- pfile[0] = NUL;
- }
-
- return (err);
- }