Open System Services Programmer's Guide
Example 54 Sending an OSS File Directly to a Printer Using the Guardian API
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tal.h>
#include <cextdecs.h(FILE_OPEN_,CONTROL,WRITEX,FILE_CLOSE_)>
short filenum; /* file code number */
short retcode; /* procedure call return code */
_cc_status CC; /* condition code */
char *printer; /* name of printer */
char *pathname; /* name of file to print */
char buffer[134]; /* buffer for print line */
FILE *infile; /* input file to be printed */
int main(int argc, char *argv[]) {
/* Get the Guardian printer filename and the name of the file to print.*/
if (argc > 1)
printer = argv[1];
else
printer = "$s.#default";
if (argc > 2)
pathname = argv[2];
else
pathname = "/usr/include/stdio.h";
if((infile = fopen(pathname, "r")) == 0) {
perror("Can't open file");
exit(1);
}
retcode = FILE_OPEN_(printer, /* name of Guardian printer */
(short)strlen(printer), /* printer name length */
&filenum, /* file number returned */
2, /* open for write access */
1, /* open for exclusive use */
);
/* Check if open was successful. */
if (retcode != 0) {
fprintf(stderr, "Can't open %s\n", printer);
fprintf(stderr, "retcode = %d\n", retcode);
exit(1);
}
/* Position the paper to top of form. */
CC = CONTROL(filenum, /* send control code to printer */
1, /* forms control mode */
0 /* top of form control code */
);
if (_status_ne(CC)) {
fprintf(stderr, "Illegal control code to printer: %s\n",\
printer);
exit(1);
}
/* Read the input file, one line at a time, and send it to printer. */
while(fgets(buffer, 132, infile)) { /* get line from input file */
CC = WRITEX(filenum, /* write buffer to printer */
buffer, /* printer buffer */
(short)strlen(buffer) /* size of text string */
);
/* Check for successful printer write operation. */
if (_status_ne(CC)) {
fprintf(stderr, "Write to printer failed: %s\n", printer);
exit(1);
}
232 Managing I/O










