/* This program sends raw binary data files to the parallel * printer port. It does not attempt to interpret any of the * characters it sends. The program can be aborted from the * keyboard with ^C. * * The default file extension is .dsk, for binary deskjet files. */ #include #include #include #include #include #define STD_INPUT 0 #define STD_OUTPUT 1 #define ISDIGIT(c) ( (c)>='0' && (c)<='9' ) main(argc, argv) int argc; char **argv; { int j, c, byte, status, tmp_copies, argc2, files; int i=0, epson=0, copies=1; char dskfile[128], copy_string[10], **argv2, *send_eject; char *eject = {"\033&l0H\0"}; /* eject esc sequence */ FILE *fp, *fopen(); struct sgttyb term; if (argc < 2){ puts("usage: bpr [-#] [-e] file1 [file2] ...\n"); exit(-1); } argc2 = argc; /* save the argument info. */ argv2 = argv; /* Go through the arguments, set flags for any options. */ for (j=1; --argc2 > 0 && (*++argv2)[0] == '-'; ++j) { while (c = *++argv2[0]) { switch (c) { case 'e': /* disable deskjet eject page */ epson = 1; break; case '0': case '1': /* put # of copies in string */ case '2': case '3': /* then convert it to an int */ case '4': case '5': case '6': case '7': case '8': case '9': if (i != 0) { puts("bpr: Option is not sensible!"); exit(-1); } copy_string[i++] = c; for (c = *++argv2[0]; ISDIGIT(c) ; c = *++argv2[0] ) { copy_string[i++] = c; } copy_string[i] = '\0'; --argv2[0]; copies = atoi(copy_string); break; default: printf("bpr: Illegal option! %c\n", c); exit(-1); } } } if ((argc - j) <= 0) { puts("usage: bpr [-#] [-e] file1 [file2] ...\n"); exit(-1); } /* set standard input to raw mode so ^C can be trapped */ ioctl(STD_INPUT, TIOCGETP, &term); term.sg_flags = RAW; ioctl(STD_INPUT, TIOCSETP, &term); for (i=j; argv[i] != NULL; i++) { /* for every file */ tmp_copies = copies; for (; tmp_copies > 0; --tmp_copies) { /* loop over copies */ send_eject = eject; if((fp = fopen(argv[i], "rb")) == NULL){ /* open the file */ strcpy(dskfile, argv[i]); if (epson) { strcat(dskfile, ".eps"); } else { strcat(dskfile, ".dsk"); } if((fp = fopen(dskfile, "rb")) == NULL){ printf("bpr: Could not open %s!\n", argv[i]); continue; } } while ((byte = getc(fp)) != EOF){ Cprnout(byte); /* send the data */ status = Cconis(); /* check for keyboard abort */ if (status != 0){ c = getchar(); if (c == '\003') break; } } fclose(fp); /* close the file */ if (!epson) { /* send an eject page unless -e is set */ for (; *send_eject != '\0'; ++send_eject) Cprnout(*send_eject); } } /* end of copies */ } /* end of files */ exit(0); }