[comp.sys.ibm.pc] Laserjet download/DOS answers

mikey@shuksan.UUCP (Mike Fields) (11/22/89)

Some time ago, I posted a question regarding downloading fonts to 
a laserjet and "help" from dos trashing the data.  

Thanks to the people who responded.  I thought I would post two solutions
to the problem - it is possible to talk either in the low level mode
(open, write) or the high level stream mode (fopen, fprintf etc).

Sample code follows:

        ************* sample **************

FILE *outfile;	/* high level stream output to printer */
int pr_handle, pr_stat; /* low level file handle and status for ioctl */

              ..... skip some stuff ....

if((pr_handle=open("PRN",O_BINARY|O_WRONLY) /* open binary for write */
    {
	perror("Low level file open error");
	exit(-1);   /* unable to open file - exit */
	}
pr_stat=ioctl(pr_handle,0,0,0);  /* get status of file handle */
ioctl(pr_handle,1,(pr_stat|0x20),0); /* set to raw mode */

	/* at this point, the low level file is available for writing to
	with write commands (assign your own buffers etc).  This works
	quite well. I prefer to use a stream for output and let the
	'system' handle my buffering (some people say I am a slow
	learner!!).  The following code opens the stream for your 
	use.
	*/

if((outfile=fdopen(pr_handle,"wb")) == NULL) /* attach stream to handle */
	{
	perror("Stream open error for output");
	exit(-1);
	}


At this point, the stream 'outfile' is available to write to with fprint()
etc.  It seems to work well.  The trick is to make sure you set the low
level file handle to 'raw' mode first! I know the book sez that the PRN
is already open for your use in the binary mode.

When you are done, you need to close the files and reset the ioctl bits:

fclose(outfile);
ioctl(pr_handle,1,pr_status,0);
fclose(pr_handle);

I hope this helps others who are trying to do sim. things with messydos!!

thanks to everyone who replied and sent email! (John Mauzey, James Krause
and John Miller and others!!)


-- 
Mikey (yes "he likes it!")
=======================================================   Mike Fields
uw-beaver!ssc-vax!shuksan!mikey  (206) 393-3768 [work]    12022 NE 138th Pl.
                                 (206) 821-3492 [home]    Kirkland, Wa. 98034