home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / PRNSPOOL.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  3KB  |  154 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /* prnspool.c 12-22-91 Robert Mashlan, public domain */
  4. /* DOS print spooler interface functions             */
  5.  
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include "prnspool.h"
  9.  
  10. int printspool_errno = 0;
  11.  
  12. char *printspool_errlist[] = {
  13.       "No error",
  14.       "Function Invalid",
  15.       "File not found",
  16.       "Path not found",
  17.       "Too many open files",
  18.       "Access denied",
  19.       "",
  20.       "",
  21.       "Queue full",
  22.       "Spooler busy",
  23.       "",
  24.       "",
  25.       "Name too long",
  26.       "",
  27.       "Drive invalid"
  28.       };
  29.  
  30. /* returns -1 if printspooler installed */
  31. /* 0 otherwise                          */
  32.  
  33. int printspool_installed(void)
  34. {
  35.       union REGS r;
  36.  
  37.       r.x.ax = 0x0100;
  38.       int86(0x2f, &r, &r);
  39.       if(r.h.al==0xff)
  40.       {
  41.             printspool_errno=0;
  42.             return -1;
  43.       }
  44.       else
  45.       {
  46.             printspool_errno=1;
  47.             return 0;
  48.       }
  49. }
  50.  
  51. /* submits a file name to be printed */
  52. /* returns error code                */
  53.  
  54. int printspool_submit( const char *pathname )
  55. {
  56.       struct PACKET packet;
  57.       union REGS r;
  58.       struct SREGS s;
  59.  
  60.       packet.level = 0;
  61.       packet.pathname = (char FAR *)pathname;
  62.       s.ds   = FP_SEG(&packet);
  63.       r.x.dx = FP_OFF(&packet);
  64.       r.x.ax = 0x0101;
  65.       int86x(0x2f, &r, &r, &s);
  66.       if(!r.x.cflag)
  67.             return printspool_errno = 0;
  68.       else  return printspool_errno = r.x.ax;
  69. }
  70.  
  71. /* removes a file from the print queue */
  72.  
  73. int printspool_remove( const char FAR *fname )
  74. {
  75.       union REGS r;
  76.       struct SREGS s;
  77.  
  78.       s.ds   = FP_SEG(fname);
  79.       r.x.dx = FP_OFF(fname);
  80.       r.x.ax = 0x0102;
  81.       int86x(0x2f, &r, &r, &s);
  82.       if(!r.x.cflag)
  83.             return printspool_errno = 0;
  84.       else  return printspool_errno=r.x.ax;
  85. }
  86.  
  87. /* cancels all files in the print queue */
  88.  
  89. int printspool_cancel(void)
  90. {
  91.       union REGS r;
  92.  
  93.       r.x.ax = 0x0103;
  94.       int86(0x2f, &r, &r);
  95.       if(!r.x.cflag)
  96.             return printspool_errno = 0;
  97.       else  return printspool_errno = r.x.ax;
  98. }
  99.  
  100. /* ends hold state after a call to printspool_getqueue */
  101. /* or printspool_errorcount                            */
  102.  
  103. void printspool_endhold(void)
  104. {
  105.       union REGS r;
  106.  
  107.       r.x.ax = 0x0105;
  108.       int86(0x2f, &r, &r);
  109. }
  110.  
  111. /* returns a far pointer to the printspooler queue, */
  112. /* an array of 64 char asciiz strings               */
  113.  
  114. char FAR *printspool_getqueue(void)
  115. {
  116.       char FAR *result;
  117.       union REGS r;
  118.       struct SREGS s;
  119.  
  120.       r.x.ax = 0x0104;
  121.       int86x(0x2f, &r, &r, &s);
  122.       result = MK_FP(s.ds,r.x.si);
  123.       if (!r.x.cflag)
  124.       {
  125.             printspool_errno = 0;
  126.             return result;
  127.       }
  128.       else
  129.       {
  130.             printspool_errno = r.x.ax;
  131.             return NULL;
  132.       }
  133. }
  134.  
  135. /* returns the error count from the printspooler */
  136.  
  137. int printspool_errorcount(void)
  138. {
  139.       union REGS r;
  140.  
  141.       r.x.ax = 0x0104;
  142.       int86(0x2f, &r, &r);
  143.       if (!r.x.cflag)
  144.       {
  145.             printspool_errno = 0;
  146.             return r.x.dx;          /* return the number of errors */
  147.       }
  148.       else
  149.       {
  150.             printspool_errno = r.x.ax;
  151.             return r.x.dx;
  152.       }
  153. }
  154.