home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 344_01 / print.c < prev    next >
Text File  |  1991-02-11  |  7KB  |  235 lines

  1. /* HEADER:      PRINT.C
  2.  * TITLE:       Functions to access resident portion of PRINT.COM.
  3.  * VERSION:     1.00
  4.  *
  5.  * DESCRIPTION: The following functions are implemented:
  6.  *
  7.  *               unsigned prn_installed(void);
  8.  *                Checks for installation of PRINT.COM
  9.  *                Input:  nothing
  10.  *                Output: 0x0000     PRINT NOT installed
  11.  *                0xFFFF             PRINT is installed
  12.  *
  13.  *               unsigned prn_submit(char *file_name);
  14.  *                Submits file to print queue for printing
  15.  *                Input:  char *file pointer to file to be printed
  16.  *                Output: 0x0000     file successfully submitted
  17.  *                0xFFFF             PRINT not resident
  18.  *                else               error code of PRINT
  19.  *
  20.  *               unsigned prn_cancel_file(char *file_name);
  21.  *                Cancels file in print queue
  22.  *                Input:  char *file pointer to file to be cancelled
  23.  *                Output: 0x0000     file successfully cancelled
  24.  *                0xFFFF             PRINT not resident
  25.  *                else               error code of PRINT
  26.  *
  27.  *               unsigned prn_cancel_all(void);
  28.  *                Cancels all files currently in print queue
  29.  *                Input:  nothing
  30.  *                Output: 0x0000     print queue successfully cancelled
  31.  *                0xFFFF             PRINT not resident
  32.  *                else               error code of PRINT
  33.  *
  34.  *               unsigned prn_stop(void);
  35.  *                Stops print queue from printing
  36.  *                Input:  nothing
  37.  *                Output: 0x0000     print queue successfully stopped
  38.  *                0xFFFF             PRINT not resident
  39.  *                else               error code of PRINT
  40.  *
  41.  *               unsigned prn_resume(void);
  42.  *                Resumes printing
  43.  *                Input:  nothing
  44.  *                Output: 0x0000     printing successfully resumed
  45.  *                0xFFFF             PRINT not resident
  46.  *                else               error code of PRINT
  47.  *
  48.  *               unsigned prn_active(void);
  49.  *                Checks for print queue status
  50.  *                Input:  nothing
  51.  *                Output: 0x0000     print queue is empty
  52.  *                0xFFFF             PRINT is active
  53.  *
  54.  *              Error codes:
  55.  *                0x0001  invalid function
  56.  *                0x0002  file not found
  57.  *                0x0003  invalid path
  58.  *                0x0004  too many open files
  59.  *                0x0005  access denied
  60.  *                0x0008  print queue full
  61.  *                0x0009  print queue busy
  62.  *                0x000C  filename too long
  63.  *                0x000F  invalid drive
  64.  *
  65.  * KEYWORDS:    Printing
  66.  * SYSTEM:      MS- /PC-DOS Version 3.xx
  67.  * FILENAME:    PRINT.C
  68.  * AUTHOR:      Michael Wiedmann, December 1990
  69.  * COMPILERS:   Microsoft QuickC 1.0 + 2.0, MS C 5.1 + 6.0
  70.  */
  71.  
  72. #include <stdio.h>
  73. #include <dos.h>
  74.  
  75.  
  76. /* Macros                       */
  77.  
  78. #define INT_2F()        int86(0x2F, &r, &r)
  79. #define INT_2FX()       int86x(0x2F, &r, &r, &sr)
  80.  
  81.  
  82. /* typedef for request packet   */
  83.  
  84. typedef struct _REQ_PACKET
  85. {
  86.  unsigned char  prio;
  87.  unsigned       off;
  88.  unsigned       seg;
  89. } REQ_PACKET;
  90.  
  91.  
  92.  
  93. unsigned prn_installed(void)
  94. {
  95.  union REGS     r;
  96.  
  97.  r.x.ax = 0x0100;       /* check for installation state of PRINT        */
  98.  INT_2F();              /* call int 2fh                                 */
  99.  return ((r.h.al == 0xFF) ? 0xFFFF : 0x0000);
  100. }
  101.  
  102.  
  103.  
  104. unsigned prn_submit(char *file)
  105. {
  106.  union REGS     r;
  107.  struct SREGS   sr;
  108.  REQ_PACKET     req_packet;
  109.  
  110.  /* check for installation of PRINT first                       */
  111.  if (!prn_installed())
  112.     return 0xFFFF;
  113.  
  114.  /* fill request packet with offset and segment of file         */
  115.  req_packet.prio = 0x00;
  116.  req_packet.off  = FP_OFF(file);
  117.  req_packet.seg  = FP_SEG(file);
  118.  
  119.  /* fill register variables with appropriate values             */
  120.  sr.ds  = FP_SEG(req_packet);
  121.  r.x.dx = FP_OFF(req_packet);
  122.  r.x.ax = 0x0101;       /* submit file function of int 2fh      */
  123.  INT_2FX();             /* call int 2fh                         */
  124.  if (r.x.cflag)         /* error ?                              */
  125.     return (r.x.ax);    /* yes, return error code               */
  126.  else
  127.     return 0x0000;      /* no, return success                   */
  128. }
  129.  
  130.  
  131.  
  132. unsigned prn_cancel_file(char *file)
  133. {
  134.  union REGS     r;
  135.  struct SREGS   sr;
  136.  
  137.  /* check for installation fo PRINT first                       */
  138.  if (!prn_installed())
  139.     return 0xFFFF;
  140.  
  141.  /* fill in register variables                                  */
  142.  sr.ds    = FP_SEG(file);
  143.  r.x.dx   = FP_OFF(file);
  144.  r.x.ax   = 0x0102;     /* cancel file function of int 2fh      */
  145.  INT_2FX();             /* call int 2fh                         */
  146.  if (r.x.cflag)         /* error ?                              */
  147.     return (r.x.ax);    /* return error code                    */
  148.  else
  149.     return 0x0000;      /* no, return success                   */
  150. }
  151.  
  152.  
  153.  
  154. unsigned prn_cancel_all(void)
  155. {
  156.  union REGS r;
  157.  
  158.  /* check for installation of PRINT first                       */
  159.  if (!prn_installed())
  160.     return 0xFFFF;
  161.  
  162.  r.x.ax = 0x0103;       /* cancel all function of PRINT         */
  163.  INT_2F();              /* call int 2fh                         */
  164.  if (r.x.cflag)         /* error ?                              */
  165.     return (r.x.ax);    /* return error code                    */
  166.  else
  167.     return 0x0000;      /* no, return success                   */
  168. }
  169.  
  170.  
  171.  
  172. unsigned prn_stop(void)
  173. {
  174.   union REGS r;
  175.  
  176.   /* check for installation of PRINT first                      */
  177.   if (!prn_installed())
  178.      return 0xFFFF;
  179.  
  180.   r.x.ax = 0x0104;      /* get status function of PRINT         */
  181.   INT_2F();             /* call int 2fh                         */
  182.   if (r.x.cflag)        /* error ?                              */
  183.      return (r.x.ax);   /* yes, return error code               */
  184.   else
  185.      return 0x0000;     /* no, return success                   */
  186. }
  187.  
  188.  
  189.  
  190. unsigned prn_resume(void)
  191. {
  192.  union REGS r;
  193.  
  194.  /* check for installation of PRINT first                      */
  195.  if (!prn_installed())
  196.     return 0xFFFF;
  197.  
  198.  r.x.ax = 0x0105;       /* end of status function of PRINT      */
  199.  INT_2F();              /* call int 2fh                         */
  200.  if (r.x.cflag)         /* error ?                              */
  201.     return (r.x.ax);    /* yes, return error code               */
  202.  else
  203.     return 0x0000;      /* no, return success                   */
  204. }
  205.  
  206.  
  207.  
  208. unsigned prn_active(void)
  209. {
  210.  union REGS     r;
  211.  struct SREGS   sr;
  212.  unsigned char far *fptr;
  213.  
  214.  /* check for installation of PRINT first                      */
  215.  if (!prn_installed())
  216.     return 0xFFFF;
  217.  
  218.  r.x.ax = 0x0104;       /* status function of PRINT             */
  219.  INT_2FX();             /* call int 2fh                         */
  220.  
  221.  FP_SEG(fptr) = sr.ds;
  222.  FP_OFF(fptr) = r.x.si;
  223.  
  224.  r.x.ax = 0x0105;       /* end of status function of PRINT      */
  225.  INT_2F();
  226.  
  227.  if (*fptr)             /* print queue empty ?                  */
  228.     return 0xFFFF;      /* no                                   */
  229.  else
  230.     return 0x0000;      /* yes                                  */
  231. }
  232.  
  233.  
  234.  
  235.