|
|
1.1 ! root 1: /* ! 2: * epson.c ! 3: * 11/8/90 ! 4: * Epson MX-80 printer driver. ! 5: * Usage: epson [ - cdfrw8 ] [ -b banner ] [ -in ] [ -o ofile ] [ -sn ] [ file ... ] ! 6: */ ! 7: ! 8: #include <stdio.h> ! 9: ! 10: #define VERSION "1.8" /* Version number. */ ! 11: #define ESC "\033" /* ASCII escape */ ! 12: #define USAGE "Usage: epson [ -cdfrw8 ] [ -b banner] [ -in ] [ -o ofile ] [ -sn ] [ file ... ]\n" ! 13: ! 14: /* Epson special characters. */ ! 15: #define COMPON '\017' ! 16: #define COMPOFF '\222' ! 17: #define FORMFD '\014' ! 18: #define SELECT '\021' ! 19: #define WIDEON '\016' ! 20: #define WIDEOFF '\224' ! 21: ! 22: /* Default output device. */ ! 23: #ifdef COHERENT ! 24: #define OUTFILE "/dev/lp" /* COHERENT */ ! 25: #else ! 26: #define OUTFILE "prn:" /* MS-DOS */ ! 27: #endif ! 28: ! 29: /* Forward. */ ! 30: void fatal(); ! 31: void indent(); ! 32: void process(); ! 33: void usage(); ! 34: ! 35: /* Globals. */ ! 36: char *banner; /* banner */ ! 37: int cflag; /* compressed */ ! 38: int dflag; /* double struck (default: emphasized) */ ! 39: int eightflag; /* eight lines per inch */ ! 40: int fflag; /* suppress formfeed */ ! 41: int nindent; /* indent */ ! 42: char *ofile = OUTFILE; /* output file */ ! 43: FILE *ofp; /* output FILE */ ! 44: int rflag; /* Roman (default: italic) */ ! 45: int spaces = 1; /* vertical spaces */ ! 46: int wflag; /* double width */ ! 47: ! 48: main(argc, argv) int argc; char *argv[]; ! 49: { ! 50: register int i; ! 51: ! 52: /* Process option flags. */ ! 53: while (--argc > 0 && **++argv == '-') { ! 54: switch (*++*argv) { ! 55: case 'b': ! 56: if (--argc == 0) ! 57: usage(); ! 58: banner = *++argv; ! 59: break; ! 60: case 'c': ++cflag; break; ! 61: case 'd': ++dflag; break; ! 62: case 'f': ++fflag; break; ! 63: case 'i': ! 64: nindent = atoi(++*argv); ! 65: if (nindent < 0) ! 66: fatal("bad -i arg %d", nindent); ! 67: break; ! 68: case 'o': ! 69: if (--argc == 0) ! 70: usage(); ! 71: ofile = *++argv; ! 72: break; ! 73: case 'r': ++rflag; break; ! 74: case 's': ! 75: spaces = atoi(++*argv); ! 76: if (spaces <1 || spaces > 3) ! 77: fatal("bad -s arg %d", spaces); ! 78: break; ! 79: case 'w': ++wflag; break; ! 80: case 'V': ! 81: fprintf(stderr, "epson: V%s\n", VERSION); ! 82: break; ! 83: case '8': ++eightflag; break; ! 84: default: usage(); break; ! 85: } ! 86: } ! 87: ! 88: /* Open output file and initialize Epson. */ ! 89: if ((ofp = fopen(ofile, "w")) == NULL) ! 90: fatal("cannot open file \"%s\"", ofile); ! 91: fputs(ESC "@", ofp); ! 92: ! 93: /* Print banner if given. */ ! 94: if (banner != NULL) { ! 95: i = (wflag ? nindent * 2 : cflag ? nindent / 2 : nindent); ! 96: while (i-- > 0) ! 97: fputc(' ', ofp); ! 98: fputc(WIDEON, ofp); ! 99: fputs(banner, ofp); ! 100: fputc(WIDEOFF, ofp); ! 101: fputc('\n', ofp); ! 102: } ! 103: if (cflag) ! 104: fputc(COMPON, ofp); ! 105: if (eightflag) ! 106: fputs(ESC "0" ESC "CX", ofp); ! 107: ! 108: /* Process input files. */ ! 109: if (argc == 0) ! 110: process(NULL); /* NULL means stdin */ ! 111: else ! 112: while (argc-- > 0) ! 113: process(*argv++); ! 114: ! 115: /* Cleanup and close output file. */ ! 116: if (cflag) ! 117: fputc(COMPOFF, ofp); ! 118: if (eightflag) ! 119: fputs(ESC "2" ESC "CB", ofp); ! 120: if (wflag) ! 121: fputc(WIDEOFF, ofp); ! 122: fputs(ESC "@", ofp); ! 123: if (fclose(ofp) == EOF) ! 124: fatal("cannot close file \"%s\"", ofile); ! 125: exit(0); ! 126: } ! 127: ! 128: /* Print fatal error message and exit. */ ! 129: /* VARARGS */ ! 130: void ! 131: fatal(s) char *s; ! 132: { ! 133: fprintf(stderr, "epson: %r\n", &s); ! 134: exit(1); ! 135: } ! 136: ! 137: /* Perform indentation. */ ! 138: void ! 139: indent() ! 140: { ! 141: register int i; ! 142: ! 143: if (wflag) ! 144: fputc(WIDEON, ofp); ! 145: for (i = nindent; i-- > 0; ) ! 146: fputc(' ', ofp); ! 147: } ! 148: ! 149: /* Process input file ifp. */ ! 150: void ! 151: process(fname) char *fname; ! 152: { ! 153: register FILE *ifp; ! 154: register int this, next, i; ! 155: ! 156: if (fname == NULL) ! 157: ifp = stdin; ! 158: else if ((ifp = fopen(fname, "r")) == NULL) ! 159: fatal("cannot open file \"%s\"", fname); ! 160: indent(); ! 161: while ((this = fgetc(ifp)) != EOF) { ! 162: if (this == '\n') { /* newline */ ! 163: for (i = spaces; i-- > 0; ) ! 164: fputc(this, ofp); ! 165: indent(); ! 166: } else if (this == FORMFD) { /* formfeed */ ! 167: fputc(this, ofp); ! 168: indent(); ! 169: } else if ((next = fgetc(ifp)) != '\b') { ! 170: fputc(this, ofp); ! 171: ungetc(next, ifp); ! 172: } else { ! 173: /* Next char is backspace, could mean bold or italic. */ ! 174: if (this == '_' && !rflag) { ! 175: /* "_\bx" means italic x. */ ! 176: fputc(fgetc(ifp) + 0200, ofp); ! 177: } else if (!dflag) { ! 178: if ((next = fgetc(ifp)) == this) { ! 179: /* "x\bx" means bold x. */ ! 180: fputs(ESC "E", ofp); ! 181: fputc(this, ofp); ! 182: fputs(ESC "F", ofp); ! 183: } else { ! 184: /* "x\by", print as is. */ ! 185: fputc(this, ofp); ! 186: fputc('\b', ofp); ! 187: ungetc(next, ifp); ! 188: } ! 189: } else { ! 190: /* Just print as is... */ ! 191: fputc(this, ofp); ! 192: ungetc(next, ifp); ! 193: } ! 194: } ! 195: } ! 196: if (!fflag) ! 197: fputc(FORMFD, ofp); ! 198: if (fname != NULL) ! 199: fclose(ifp); ! 200: } ! 201: ! 202: /* Print usage message and exit. */ ! 203: void ! 204: usage() ! 205: { ! 206: fprintf(stderr, "Usage: epson [ -cdfrw8 ] [ -b banner] [ -in ] [ -o ofile ] [ -sn ] [ file ... ]\n"); ! 207: exit(1); ! 208: } ! 209: ! 210: /* end of epson.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.