Annotation of coherent/d/bin/nroff/tty.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * tty.c
                      3:  * Nroff.
                      4:  * nroff output writer, aka TTY driver.
                      5:  */
                      6: 
                      7: #include <ctype.h>
                      8: #include "roff.h"
                      9: 
                     10: /* Font indices. */
                     11: #define        FONTR   0                       /* Roman                        */
                     12: #define        FONTB   1                       /* Bold                         */
                     13: #define        FONTI   2                       /* Italic                       */
                     14: 
                     15: /* Special escape sequences. */
                     16: #define        RLF     "\0337"                 /* Reverse line feed            */
                     17: #define        HRLF    "\0338"                 /* Half reverse line feed       */
                     18: #define        HLF     "\0339"                 /* Half line feed               */
                     19: #define        LF      "\033B"                 /* Line feed                    */
                     20: 
                     21: /*
                     22:  * Device parameters.
                     23:  */
                     24: int    ntroff  =       NROFF;          /* Programme is NROFF type      */
                     25: long   semmul  =       3;              /* Multiplier for em space      */
                     26: long   semdiv  =       5;              /* Divisor for em space         */
                     27: long   senmul  =       3;              /* Multiplier for en space      */
                     28: long   sendiv  =       5;              /* Divisor for en space         */
                     29: long   shrmul  =       12;             /* Horizontal resolution (mul)  */
                     30: long   shrdiv  =       1;              /* Horizontal resolution (div)  */
                     31: long   sinmul  =       120;            /* Multiplier for inch          */
                     32: long   sindiv  =       1;              /* Divisor for inch             */
                     33: long   snrmul  =       0;              /* Narrow space (mul)           */
                     34: long   snrdiv  =       1;              /* Narrow space (div)           */
                     35: long   svrmul  =       20;             /* Vertical resolution (mul)    */
                     36: long   svrdiv  =       1;              /* Vertical resolution (div)    */
                     37: 
                     38: /*
                     39:  * Map user fontnames to font numbers.
                     40:  */
                     41: FTB fontab[NFNAMES] ={
                     42:        { 'R',  '\0', FONTR },
                     43:        { 'B',  '\0', FONTB },
                     44:        { 'I',  '\0', FONTI }
                     45: };
                     46: static char    *font_names[NFNAMES] = { "Roman", "Bold", "Italic" };
                     47: 
                     48: /*
                     49:  * Initialize nroff-specific parameters.
                     50:  */
                     51: dev_init()
                     52: {
                     53:        swdmul  = 1;                    /* multiplier for width table */
                     54:        swddiv  = 20;                   /* divisor for width table */
                     55:        vls = psz = unit(SMINCH, 6*SDINCH);
                     56: 
                     57:        /* Sanity check: width() below assumes swdmul*psz == swddiv. */
                     58:        if (swdmul * psz != swddiv)
                     59:                panic("botch: swdmul=%d psz=%d swddiv=%d", swdmul, psz, swddiv);
                     60: }
                     61: 
                     62: /*
                     63:  * Compute the scaled width of a character:
                     64:  *     width(c) == unit(swdmul*fonwidt[c]*psz, swddiv).
                     65:  * For nroff, swdmul*psz == swddiv and fonwidt[i] is constant, so it's trivial.
                     66:  */
                     67: int
                     68: width(c) register int c;
                     69: {
                     70:        return (c < NWIDTH) ? 12 : 0;
                     71: }
                     72: 
                     73: /*
                     74:  * Given a font number, change to the given font.
                     75:  */
                     76: dev_font(n) register int n;
                     77: {
                     78:        addidir(DFONT, curfont = n);
                     79: }
                     80: 
                     81: /*
                     82:  * Given a pointer to a buffer containing stream directives
                     83:  * and a pointer to the end of the buffer, print the buffer
                     84:  * out.
                     85:  */
                     86: flushl(buffer, bufend) CODE *buffer; CODE *bufend;
                     87: {
                     88:        static int hpos, hres, vres, font;
                     89:        register CODE *cp;
                     90:        register int i, n;
                     91:        char *tp;
                     92: 
                     93: #if    (DDEBUG & DBGFUNC)
                     94:        printd(DBGFUNC, "flushl: hpos=%d, hres=%d, vres=%d, font=%d\n",
                     95:                hpos, hres, vres, font);
                     96: #endif
                     97:        for (cp = buffer; cp < bufend; cp++) {
                     98:                i = cp->l_arg.c_iarg;
                     99: #if    (DDEBUG & DBGCODE)
                    100:                codebug(cp->l_arg.c_code, i);
                    101: #endif
                    102: #if    0
                    103:                fprintf(stderr, "output: %d arg=%d\n", cp->l_arg.c_code, i);
                    104: #endif
                    105:                switch (cp->l_arg.c_code) {
                    106:                case DNULL:
                    107:                case DHYPH:
                    108:                        continue;
                    109:                case DHMOV:
                    110:                case DPADC:
                    111:                        hres += i;
                    112:                        if ((hpos += i) < 0) {
                    113:                                hres -= hpos;
                    114:                                hpos = 0;
                    115:                        }
                    116:                        continue;
                    117:                case DVMOV:
                    118:                        vres += i;
                    119:                        continue;
                    120:                case DFONT:
                    121:                        font = i;
                    122:                        continue;
                    123:                case DPSZE:
                    124:                        continue;
                    125:                case DSPAR:
                    126:                        hpos = hres = 0;
                    127:                        vres += i;
                    128:                        if (vres >= 0) {
                    129:                                n = (vres+10) / 20;
                    130:                                vres -= n*20;
                    131:                                while (n--)
                    132:                                        putchar('\n');
                    133:                        } else {
                    134:                                putchar('\r');
                    135:                                n = (-vres+9)/20;
                    136:                                vres += n*20;
                    137:                                while (n--)
                    138:                                        printf(RLF);
                    139:                        }
                    140:                        continue;
                    141:                case DTRAB:                     /* transparent line */
                    142:                        tp = cp->b_arg.c_bufp;
                    143:                        while (*tp)
                    144:                                putchar(*tp++);
                    145:                        free(cp->b_arg.c_bufp);
                    146:                        continue;
                    147:                default:
                    148:                        if (vres >= 0) {
                    149:                                vres += 5;
                    150:                                n = (vres) / 20;
                    151:                                while (n--)
                    152:                                        printf(LF);
                    153:                                if (vres%20/10)
                    154:                                        printf(HLF);
                    155:                        } else {
                    156:                                vres -= 5;
                    157:                                n = (-vres)/20;
                    158:                                while (n--)
                    159:                                        printf(RLF);
                    160:                                if (-vres%20/10)
                    161:                                        printf(HRLF);
                    162:                        }
                    163:                        vres = 0;
                    164:                        if (hres >= 0) {
                    165:                                n = (hres+6) / 12;
                    166:                                hres -= n*12;
                    167:                                while (n--)
                    168:                                        putchar(' ');
                    169:                        } else {
                    170:                                n = (-hres+5)/12;
                    171:                                hres += n*12;
                    172:                                while (n--)
                    173:                                        putchar('\b');
                    174:                        }
                    175:                        if (cp->l_arg.c_code==DHYPC)
                    176:                                n = '-';
                    177:                        else
                    178:                                n = cp->l_arg.c_code;
                    179:                        if (n < 0 || n >= NWIDTH)
                    180:                                panic("bad directive %d", n);
                    181:                        if ((font != FONTR)
                    182:                        &&  (isascii(n))
                    183:                        &&  (isupper(n) || islower(n) || isdigit(n)))
                    184:                                switch (font) {
                    185:                                case FONTB:
                    186:                                        printf("%c\b", n);
                    187:                                        break;
                    188:                                case FONTI:
                    189: #if    1
                    190:                                        printf("_\b");
                    191: #else
                    192:                                        n |= 0x80;
                    193: #endif
                    194:                                        break;
                    195: #if    0
                    196:                                case HELV:
                    197:                                        printf("_\b");
                    198:                                        break;
                    199: #endif
                    200:                                default:
                    201:                                        panic("bad font %d", font);
                    202:                                }
                    203:                        putchar(n);
                    204:                        hres += cp->c_arg.c_move-12;
                    205:                        hpos += cp->c_arg.c_move;
                    206:                }
                    207:        }
                    208: }
                    209: 
                    210: /*
                    211:  * Display available fonts.
                    212:  */
                    213: void
                    214: font_display()
                    215: {
                    216:        register FTB *p;
                    217:        register int a, b;
                    218: 
                    219:        fprintf(stderr, "Fonts available in this version:\n");
                    220:        for (p = fontab; p < &fontab[NFNAMES]; p++) {
                    221:                if ((a = p->f_name[0]) == 0)
                    222:                        break;
                    223:                if ((b = p->f_name[1]) == 0)
                    224:                        b = ' ';
                    225:                fprintf(stderr," %c%c %s\n", a, b, font_names[p->f_font]);
                    226:        }
                    227:        fprintf(stderr, "Fonts may be renamed with the .rf request.\n");
                    228: }
                    229: 
                    230: /*
                    231:  * The following troff functions are nops for nroff.
                    232:  */
                    233: #if    ZKLUDGE
                    234: dev_close(){}
                    235: #endif
                    236: dev_cs(){}
                    237: dev_fz(){}
                    238: dev_ps(){}             /* psz initialized in devinit() */
                    239: newpsze(){}
                    240: load_font(){}
                    241: 
                    242: 
                    243: /* end of tty.c */

unix.superglobalmegacorp.com

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