home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
cspool.arj
/
SPOOLER.C
Wrap
C/C++ Source or Header
|
1992-05-15
|
6KB
|
271 lines
/* Author Paul Mckenzie -Public Domain- */
/* This module must be compiled with BYTE alignment ON */
/* Here are some C routines that accesses PRINT.COM.
PRINT.COM is accessed by issuing calls to interrupt 0x2F.
The print spooler must be installed by issuing a PRINT
command from the command line before these functions will
work properly. Also, you must use DOS 3.0 or higher */
/* These functions are compatible with any DOS C compiler that
supports the int86...() family of functions and supports
byte alignment compilation. This includes Turbo/Borland,
Microsoft, Zortech, Watcom, Lattice, JPI, and others not
mentioned. */
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define NEXTFILE 64
/* changes pointers to offset segment pair */
#define GET_SEGMENT(x) \
((unsigned) ((long)(char far *)(x) >> 16))
#define GET_OFFSET(x) \
((unsigned) ((long)(char far *)(x) & 0x0000FFFF))
#define MAKE_FAR_POINTER(a,b) ((char far *)(((unsigned long)(a) << 16)+(b)))
int spool_install(void);
int spool_print(char *);
int spool_status(char far **);
int spool_status_end(void);
static int _spool_error;
typedef struct packet /* packet needed for print spooler functions */
{
char level;
char far *ptr;
} packet;
/* check if print spooler is installed. The following return codes are as
follows:
if AL contains 0xFF, PRINT.COM is installed.
if AL contains 0, PRINT.COM is not installed, but can
be installed.
if AL contains 1, PRINT.COM is not installed and cannot be
installed. */
int spool_install()
{
union REGS regs;
regs.x.ax = 0x0100;
/* DOS must be at least 3.0 */
if (_osmajor < 3)
{
_spool_error = 1;
return FALSE;
}
/* call multiplex function to test for installed print spooler */
int86(0x2F,®s,®s);
if (regs.x.ax & 0x00FF == 0x00FF)
return TRUE;
/* return what AL has */
_spool_error = regs.h.al;
return FALSE;
}
/* spool_print() places a file in the print queue */
int spool_print(char *filename)
{
union REGS regs;
struct SREGS sregs;
/* define packet to submit */
packet p;
/* set level to 0 */
p.level = 0;
/* let packet ptr point to filename */
p.ptr = filename;
/* set AX to 0x0101 - this is the 'submit file to print' command */
regs.x.ax = 0x0101;
segread(&sregs);
/* move packet pointer to DS:DX */
regs.x.dx = GET_OFFSET(&p);
sregs.ds = GET_SEGMENT(&p);
/* place file in queue by calling multiplex function */
int86x(0x2F,®s,®s,&sregs);
/* return error condition */
if (regs.x.cflag & 0x0001)
{
_spool_error = regs.x.ax;
return FALSE;
}
/* OK */
return TRUE;
}
/* cancel a job from the print spooler - wildcards are allowed here */
int spool_cancel(char *dosname)
{
struct SREGS sregs;
union REGS regs;
_spool_error = 0;
/* move 'cancel job(s) command to AX' */
regs.x.ax = 0x0102;
segread(&sregs);
/* move dosname to DS:DX */
regs.x.dx = GET_OFFSET(dosname);
sregs.ds = GET_SEGMENT(dosname);
/* call multiplex interrupt */
int86x(0x2F,®s,®s,&sregs);
/* return if error */
if (regs.x.cflag & 0x0001)
{
_spool_error = regs.x.ax;
return FALSE;
}
/* return OK */
return TRUE;
}
/* cancel all jobs */
int spool_cancel_all()
{
union REGS regs;
_spool_error = 0;
/* move 'cancel all' constant to AX */
regs.x.ax = 0x0103;
/* call multiplex interrupt */
int86(0x2F,®s,®s);
/* return if error */
if (regs.x.cflag & 0x0001)
{
_spool_error = regs.x.ax;
return FALSE;
}
/* return OK */
return TRUE;
}
/* reads status of print queue - returns file names in print queue.
Each file name is terminated by a 0 character. Terminating file is
always NULL. This function pauses the printer. You must call
spool_status_end() to continue printing. */
int spool_status(char far **filenames)
{
union REGS regs;
struct SREGS sregs;
_spool_error = 0;
segread(&sregs);
/* move 'get file names' constant to AX */
regs.x.ax = 0x0104;
int86x(0x2F,®s,®s,&sregs);
*filenames = MAKE_FAR_POINTER(sregs.ds,regs.x.si);
/* return if error */
if (regs.x.cflag & 0x0001)
{
_spool_error = regs.x.ax;
return FALSE;
}
/* return OK */
return TRUE;
}
/* continue printing after spoll_status() */
int spool_status_end()
{
union REGS regs;
_spool_error = 0;
/* move 'get file names' constant to AX */
regs.x.ax = 0x0105;
int86(0x2F,®s,®s);
/* return if error */
if (regs.x.cflag & 0x0001)
{
_spool_error = regs.x.ax;
return FALSE;
}
/* return OK */
return TRUE;
}
/* Example */
main()
{
char far *filename;
int status;
int i;
/* check if spooler installed */
if (!spool_install())
{
printf("PRINT.COM not installed.");
exit(0);
}
/* spool print a file */
status = spool_print("spooler.c");
/* get list of file names */
status = spool_status(&filename);
/* loop to print all file names in queue */
/* all file names are 64 bytes apart. Each name is NULL-terminated.
A null file name indicates the end of the list */
i = 1;
while (1)
{
if (!*filename)
break;
printf("File %d in print queue is %Fs\n",i,filename);
filename+=NEXTFILE;
i++;
}
spool_status_end();
}