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

1.1       root        1: /*
                      2:  * lpr/print.c
                      3:  */
                      4: 
                      5: #include       <stdio.h>
                      6: 
                      7: #define        LINESIZ 512
                      8: 
                      9: #define        lputc(c)        putc((c), lp)
                     10: 
                     11: static         col,                    /* current print position */
                     12:                endcol;                 /* leftmost unused position */
                     13: static char    line0[LINESIZ],
                     14:                line1[LINESIZ];
                     15: 
                     16: extern int     printing;
                     17: extern FILE    *lp;
                     18: 
                     19: print( file)
                     20: char   *file;
                     21: {
                     22:        register FILE   *f;
                     23:        register        c;
                     24: 
                     25:        f = fopen( file, "r");
                     26:        if (f == NULL)
                     27:                return (1);
                     28: 
                     29:        while ((c=getline( f)) && printing>0) {
                     30:                putline( line1);
                     31:                putline( line0);
                     32:                lputc( c);
                     33:        }
                     34: 
                     35:        fclose( f);
                     36:        return (0);
                     37: }
                     38: 
                     39: 
                     40: 
                     41: getline( f)
                     42: register FILE  *f;
                     43: {
                     44:        register        c;
                     45: 
                     46:        col = 0;
                     47:        endcol = 0;
                     48: 
                     49:        while ((c=getc( f)) != EOF)
                     50:                switch (c) {
                     51:                case '\n':
                     52:                case '\f':
                     53:                        line0[col] = '\0';
                     54:                        line1[col] = '\0';
                     55:                        return (c);
                     56:                case '\b':
                     57:                        if (col)
                     58:                                --col;
                     59:                        break;
                     60:                case '\r':
                     61:                        col = 0;
                     62:                        break;
                     63:                case '\t':
                     64:                        do {
                     65:                                store( ' ');
                     66:                        } while (col & 7);
                     67:                        break;
                     68:                default:
                     69:                        store( c);
                     70:                }
                     71: 
                     72:        return (0);
                     73: }
                     74: 
                     75: store( c)
                     76: {
                     77: 
                     78:        if (col < LINESIZ-1)
                     79:                if (col >= endcol) {
                     80:                        line0[col] = c;
                     81:                        line1[col] = ' ';
                     82:                        ++endcol;
                     83:                }
                     84:                else
                     85:                        line1[col] = c;
                     86:        ++col;
                     87: }
                     88: 
                     89: putline( linep)
                     90: register char  *linep;
                     91: {
                     92:        register        c,
                     93:                        xcol;
                     94: 
                     95:        col = 0;
                     96:        xcol = 0;
                     97: 
                     98:        for (; ; )
                     99:                switch (c = *linep++) {
                    100:                case '\0':
                    101:                        if (col)
                    102:                                lputc( '\r');
                    103:                        return;
                    104:                default:
                    105:                        while (col < xcol) {
                    106:                                ++col;
                    107:                                lputc( ' ');
                    108:                        }
                    109:                        lputc( c);
                    110:                        ++col;
                    111:                case ' ':
                    112:                        ++xcol;
                    113:                }
                    114: }
                    115: 
                    116: /* end of lpr/print.c */

unix.superglobalmegacorp.com

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