MacPaint File Printing

Authors

Publication

Pub Details

Date

Pages

See all articles from QL Hacker's Journal 12

Don Walterman has sent a program that reads a MacPaint file and prints to an HP Deskjet printer. Don claims that this is his first C program. If so, it’s very ambitious.

Don did not send an article describing his program, so I’ll present it as is.

For formatting reasons, comments are below the lines that they apply to. I’ve inserted ^’s to emphasize the point.

/* Print_Mac305_c
Author: Don Walterman
*/

char _PROG_NAME[] = "Print Mac";

#include <stdio_h>
#include <qlib_h>

#define ESC 27
#define FF 12

char macfile_name[50],answer,i;
unsigned short int bits,repeat_count,single_count,byte;
unsigned short int dot_column,single_byte,line_count;
long tty_wait = 0;

FILE *mac_file, *printer;

main()
{
if((tty_wait = isatty( fileno( stdout ))) &&
!isnoclose( fileno(stdout )))
{
struct QLRECT rect;

rect.q_width = 512;
rect.q_height =200;
rect.q_x = rect.q_y = 0;
tty_wait = getchid( fileno(stdout) );
sd_wdef( tty_wait, -1, RED_M4, 1, &rect);
sd_clear( tty_wait, -1);
}

printf("Enter the readmac file to print \n(including the
device name). ");
scanf("%s" , macfile_name);

if ((mac_file = fopen(macfile_name,"r")) == NULL) {
puts("\ncan't find file...please check disk and
try again\n ");
printf("System error returned..... %d %s", _oserr,"
\n");
if(tty_wait) {
printf("Press any key to continue\n");
io_fbyte( tty_wait, -1, &i);
}
main();
}
fseek(mac_file,640,SEEK_SET);
/* ^ set file pointer to start of picture data */

printer = fopen("SER1","w");
/* ^ open SER1_ for printing */
fprintf(printer,"%c%s", ESC, "*b0M");
/* ^ select full graphics mode */
fprintf(printer,"%c%s", ESC,"*t75R");
/* ^ select 75 dpi resolution */
fprintf(printer,"%c%s", ESC,"&a0C");
/* ^ set printer's cursor to leftmost position */
fprintf(printer,"%c%s", ESC,"&a+112H");
/* ^ center the image on the page */
fprintf(printer,"%c%s", ESC,"*r1A");
/* ^ start printing at current printer(cursor)
position */

dot_column = 0;
line_count = 0;

fprintf(printer,"%c%s", ESC,"*b72W");
/* ^ print 576 dots per line (standard Mac screen
width) */
/* 72 dot_columns x 8 bits per dot_column */
do {
byte = fgetc(mac_file);
if (byte > 184 && byte < 256)
{
repeat_count = 257 - byte;
byte = fgetc(mac_file);
do {
fputc(byte , printer);
/* ^ this routine prints out the repeating data
bytes */
dot_column++;
/* ^ the first byte tells how many times to
repeat the */
if(dot_column > 71)
/* ^ next byte */
{
fprintf(printer,"%c%s", ESC,"*b72W");
dot_column = 0;
line_count++;
update();
}
--repeat_count;
} while (repeat_count > 0);
}
else {
/* ^ this routine prints out the non-repeating */
if (byte < 128)
/* ^ graphics bytes. the first byte tells how many */
{ /* non-repeating bytes follow */
single_count = 0;
do {
single_byte = fgetc(mac_file);
fputc(single_byte , printer);
dot_column++;
if(dot_column > 71)
{
fprintf(printer,"%c%s", ESC,"*b72W");
dot_column = 0;
line_count++;
update();
}
single_count++;
} while(single_count < (byte+1));
}
}

} while(!feof(mac_file) && (line_count < 720));
/* ^ jump out at end of file */
/* the screen is 720 lines so skip the garbage */
if(dot_column < 72)
/* ^ the file may have appended from the file transfer */
{
do {
/* ^ this routine finishes off whatever graphics */
byte = 0;
/* ^ line is started so that the next two commands */
fputc(byte , printer);
/* ^ are not mistaken for graphics data */
dot_column++;
} while(dot_column < 72);
}

fprintf(printer,"%c%s", ESC,"*rB");
/* ^ tell DeskJet end of graphics data */
fprintf(printer,"%c", FF);

fclose(printer);
fclose(mac_file);

printf("\nPrint another Readmac file ? ");
if(getchar() == 89 | getchar() == 121)
/* ^ if 'y' or 'Y' start over */
{
main();
}
}
update()
{
sd_pixp( tty_wait, -1,10,20);
printf("printing line %d %s", line_count, "of 720
lines....\n");
}

Products

 

Downloadable Media

 
Scroll to Top