home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / PRGETQ.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.6 KB  |  147 lines

  1. /**
  2. *
  3. * Name        PRGETQ -- Get the name of the Nth file in the print
  4. *              spooler's queue, as well number of items
  5. *              present.
  6. *
  7. * Synopsis    ret = prgetq (n, psize, pfile);
  8. *
  9. *        int ret     Return code -- 0 (PR_OK) if no error
  10. *
  11. *        int n        The queue item # to be returned in
  12. *                pfile.    0 for the spooler active file
  13. *                (file being printed), 1 for the next
  14. *                in line, etc.
  15. *
  16. *        int *psize    Pointer to the size of the queue
  17. *                (returned).
  18. *
  19. *        char *pfile    Name of the nth file in the queue
  20. *                (returned).  The length of the
  21. *                filename returned is 0 if the Nth
  22. *                item does not exist for whatever
  23. *                reason (n > size of current
  24. *                queue, spooler not installed, etc).
  25. *
  26. *                Note: You MUST reserve at least 65
  27. *                bytes for this string!
  28. *
  29. * Description    This function gets the pathname of the nth item in the
  30. *        DOS print queue.  If the return code is non-zero, psize
  31. *        is guaranteed to be 0, and *pfile is guaranteed to be
  32. *        NUL.
  33. *
  34. * Special    If the DOS the machine is running is older than 3.00,
  35. * Cases     or the print spooler has not been installed, the
  36. *        size returned is guaranteed to be 0.
  37. *
  38. * Returns    ret            0 (PR_OK) if no error, otherwise
  39. *                    one of the following values:
  40. *
  41. *            0 (PR_OK)        Item sucessfully returned.
  42. *
  43. *            1 (PR_INSTAL)   Spooler not installed (or)
  44. *                    DOS older than 3.00.
  45. *
  46. *            6 (PR_EMPTY)    The spooler queue is empty.
  47. *
  48. *            7 (PR_RANGE)    Requested item (n) out of range.
  49. *
  50. *            9 (PR_BUSY)     Spooler busy; unable to get
  51. *                    attention.    Try again later.
  52. *
  53. * Version    6.00  (C)Copyright Blaise Computing Inc. 1987,1989
  54. *
  55. **/
  56.  
  57.  
  58. #include <dos.h>
  59.  
  60. #include <bprint.h>
  61. #include <butil.h>
  62.  
  63. #define PR_QPATH_SIZE 64    /* the size of a path name in the        */
  64.                 /* printer queue.                */
  65.  
  66. #define NUL '\0'
  67.  
  68.  
  69. int prgetq (n, psize, pfile)
  70. int n;
  71. int *psize;
  72. char *pfile;
  73. {
  74.     char far     *pqueue;
  75.     int       err;
  76.     struct SREGS  sregs;
  77.     union  REGS   regs;
  78.  
  79.     err      = PR_OK;
  80.     pfile[0] = NUL;
  81.     *psize   = 0;
  82.  
  83.     if (! prinstld ())
  84.     return (PR_INSTAL);
  85.  
  86.     /* We get the address of the spooler queue, which freezes the   */
  87.     /* queue until we thaw it.    This is so that data in the queue   */
  88.     /* does not move around while we are reading it.            */
  89.     regs.x.ax     = 0x0104;  /* device 1 (spool), request 4 (queue   */
  90.                 /* address)                 */
  91.  
  92.     int86x (PR_DOS_INT, ®s, ®s, &sregs);
  93.  
  94.     if (regs.x.cflag)
  95.     err = regs.x.ax;
  96.  
  97.     else
  98.     {
  99.         /* Get a char * to the queue items.            */
  100.     pqueue = uttofar (sregs.ds, regs.x.si, char);
  101.  
  102.         /* Normalize to inhibit wrap-around.            */
  103.     pqueue = utnorm (pqueue, char);
  104.  
  105.         /* Count the number of queue items.            */
  106.     for (;    (*pqueue != NUL);  (*psize)++, pqueue += PR_QPATH_SIZE)
  107.         ;
  108.  
  109.     if (*psize == 0)
  110.         err = PR_EMPTY;
  111.  
  112.     else if ((*psize < (n + 1)) || (n < 0))
  113.         err = PR_RANGE;
  114.  
  115.     /* When we get to here, pqueue is pointing past the last    */
  116.     /* queue item.    We have to back it up to point at the item  */
  117.     /* requested                            */
  118.  
  119.     else
  120.     {
  121.         for (;  (n < *psize);  pqueue -= PR_QPATH_SIZE, n++)
  122.         ;
  123.  
  124.        /* Copy the string.    Can't use strcpy because pqueue and */
  125.        /* path are in different memory models.            */
  126.  
  127.         for (;  (*pfile = *pqueue) != NUL;    pfile++, pqueue++)
  128.         ;
  129.  
  130.         *pfile = NUL;
  131.     }
  132.     }
  133.  
  134.     regs.x.ax     = 0x0105;  /* device 1 (spool), request 5 (thaw    */
  135.                 /* the queue).                */
  136.  
  137.     int86 (PR_DOS_INT, ®s, ®s);
  138.  
  139.     if (err != 0)
  140.     {
  141.     *psize      = 0;
  142.     pfile[0] = NUL;
  143.     }
  144.  
  145.     return (err);
  146. }
  147.