Annotation of coherent/d/bin/lpr/hpprint.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * hpprint.c
                      3:  * 12/13/90
                      4:  * Print a file for the hp daemon.
                      5:  * This is nontrivial for two reasons.
                      6:  * First, the device might be a serial line,
                      7:  * so this needs to worry about getting the mode bits right.
                      8:  * Second, "hpr foo" should expand tabs in foo,
                      9:  * but "hpr -f 1 font" should not muck with the binary font bits.
                     10:  * This routine therefore knows some gory details about HP PCL.
                     11:  */
                     12: 
                     13: #include       <stdio.h>
                     14: #include       <sgtty.h>
                     15: 
                     16: extern int     printing;
                     17: extern FILE    *lp;
                     18: 
                     19: char ebuf[64];
                     20: 
                     21: /*
                     22:  * Print the given file.
                     23:  * If fontnum is not -1, the file contains a soft font;
                     24:  * precede and follow it with PCL commands to load it as font fontnum.
                     25:  */
                     26: print(file, fontnum) char *file; int fontnum;
                     27: {
                     28:        register FILE   *f;
                     29:        register int c;
                     30:        register int nraw = 0;
                     31:        int col = 0;
                     32:        struct sgttyb sg;
                     33: 
                     34:        f = fopen( file, "r");
                     35:        if (f == NULL)
                     36:                return (1);
                     37:        ioctl(fileno(lp), TIOCGETP, &sg);
                     38:        c = sg.sg_flags;
                     39:        sg.sg_flags &= ~(XTABS|CRMOD);
                     40:        ioctl(fileno(lp), TIOCSETP, &sg);
                     41:        sg.sg_flags = c;
                     42:        if (fontnum != -1)
                     43:                fprintf(lp, "\033*c%dD", fontnum);      /* assign font # */
                     44:        while ((c=getc(f)) != EOF && printing > 0) {
                     45:                if (nraw) {
                     46:                        putc(c, lp);
                     47:                        --nraw;
                     48:                        continue;
                     49:                }
                     50:                switch (c) {
                     51:                case 033:
                     52:                        c = escape(f);
                     53:                        /* PCL commands followed by binary data. */
                     54:                        if ((c == 'W' && ebuf[1] == '*' && ebuf[2] == 'b')
                     55:                         || (c == 'W' && ebuf[1] == '(' && ebuf[2] == 's')
                     56:                         || (c == 'W' && ebuf[1] == ')' && ebuf[2] == 's')
                     57:                         || (c == 'X' && ebuf[1] == '&' && ebuf[2] == 'p'))
                     58:                                nraw = atoi(ebuf+3);            /* data count */
                     59:                        continue;
                     60:                case '\n':
                     61:                        putc('\r', lp);
                     62:                        col = 0;
                     63:                        putc(c, lp);
                     64:                        continue;
                     65:                case '\r':
                     66:                        col = 0;
                     67:                        putc(c, lp);
                     68:                        continue;
                     69:                case '\t':
                     70:                        do putc(' ', lp); while ((++col%8) != 0);
                     71:                        continue;
                     72:                case '\b':
                     73:                        if (col)
                     74:                                col -= 1;
                     75:                        putc(c, lp);
                     76:                        continue;
                     77:                default:
                     78:                        if (c >= ' ' && c < 0177)
                     79:                                ++col;
                     80:                        putc(c, lp);
                     81:                        continue;
                     82:                }
                     83:        }
                     84:        if (fontnum != -1)
                     85:                fprintf(lp, "\033*c5F");        /* make font permanent */
                     86:        ioctl(fileno(lp), TIOCSETP, &sg);
                     87:        fclose( f);
                     88:        return (0);
                     89: }
                     90: 
                     91: /*
                     92:  * Copy a PCL command (escape sequence) to the printer,
                     93:  * but save a copy in the buffer for later examination.
                     94:  */
                     95: escape(fp) register FILE *fp;
                     96: {
                     97:        register char *p;
                     98:        register int c;
                     99: 
                    100:        p = ebuf;
                    101:        *p++ = 033;
                    102:        putc(033, lp);
                    103:        if ((c = getc(fp)) != EOF && printing > 0) {
                    104:                putc(c, lp);
                    105:                *p++ = c;
                    106:                *p = 0;
                    107:                if (c == 'E' || c == '=' || c == '9' || c == 'Y' || c == 'Z')
                    108:                        return c;
                    109:                while ((c = getc(fp)) != EOF && printing > 0) {
                    110:                        putc(c, lp);
                    111:                        *p++ = c;
                    112:                        *p = 0;
                    113:                        if (c >= '@' && c <= 'Z')
                    114:                                return c;       /* read until UPPERCASE char */
                    115:                }
                    116:        }
                    117:        return 0;
                    118: }
                    119: 
                    120: /* end of hpprint.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.