Annotation of 43BSD/contrib/mh/miscellany/less/:output.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * High level routines dealing with the output to the screen.
                      3:  */
                      4: 
                      5: #include "less.h"
                      6: 
                      7: extern int sigs;
                      8: extern int sc_width, sc_height;
                      9: extern int ul_width, ue_width;
                     10: extern int so_width, se_width;
                     11: extern int tabstop;
                     12: extern int twiddle;
                     13: extern char *line;
                     14: extern char *first_cmd;
                     15: 
                     16: /*
                     17:  * Display the line which is in the line buffer.
                     18:  */
                     19:        public void
                     20: put_line()
                     21: {
                     22:        register char *p;
                     23:        register int c;
                     24:        register int column;
                     25:        extern int auto_wrap, ignaw;
                     26: 
                     27:        if (sigs)
                     28:                /*
                     29:                 * Don't output if a signal is pending.
                     30:                 */
                     31:                return;
                     32: 
                     33:        if (line == NULL)
                     34:                line = (twiddle) ? "~" : "";
                     35: 
                     36:        column = 0;
                     37:        for (p = line;  *p != '\0';  p++)
                     38:        {
                     39:                switch (c = *p)
                     40:                {
                     41:                case UL_CHAR:
                     42:                        ul_enter();
                     43:                        column += ul_width;
                     44:                        break;
                     45:                case UE_CHAR:
                     46:                        ul_exit();
                     47:                        column += ue_width;
                     48:                        break;
                     49:                case '\t':
                     50:                        do
                     51:                        {
                     52:                                putc(' ');
                     53:                                column++;
                     54:                        } while ((column % tabstop) != 0);
                     55:                        break;
                     56:                case '\b':
                     57:                        putbs();
                     58:                        column--;
                     59:                        break;
                     60:                default:
                     61:                        if (c & 0200)
                     62:                        {
                     63:                                putc('^');
                     64:                                putc(c & 0177);
                     65:                                column += 2;
                     66:                        } else
                     67:                        {
                     68:                                putc(c);
                     69:                                column++;
                     70:                        }
                     71:                }
                     72:        }
                     73:        if (column < sc_width || !auto_wrap || ignaw)
                     74:                putc('\n');
                     75: }
                     76: 
                     77: /*
                     78:  * Is a given character a "control" character?
                     79:  * {{ ASCII DEPENDENT }}
                     80:  */
                     81:        public int
                     82: control_char(c)
                     83:        int c;
                     84: {
                     85:        return (c < ' ' || c == '\177');
                     86: }
                     87: 
                     88: /*
                     89:  * Return the printable character used to identify a control character
                     90:  * (printed after a carat; e.g. '\3' => "^C").
                     91:  * {{ ASCII DEPENDENT }}
                     92:  */
                     93:        public int
                     94: carat_char(c)
                     95:        int c;
                     96: {
                     97:        return ((c == '\177') ? '?' : (c | 0100));
                     98: }
                     99: 
                    100: 
                    101: static char obuf[1024];
                    102: static char *ob = obuf;
                    103: 
                    104: /*
                    105:  * Flush buffered output.
                    106:  */
                    107:        public void
                    108: flush()
                    109: {
                    110:        write(1, obuf, ob-obuf);
                    111:        ob = obuf;
                    112: }
                    113: 
                    114: /*
                    115:  * Discard buffered output.
                    116:  */
                    117:        public void
                    118: dropout()
                    119: {
                    120:        ob = obuf;
                    121: }
                    122: 
                    123: /*
                    124:  * Output a character.
                    125:  */
                    126:        public void
                    127: putc(c)
                    128:        int c;
                    129: {
                    130:        if (ob >= &obuf[sizeof(obuf)])
                    131:                flush();
                    132:        *ob++ = c;
                    133: }
                    134: 
                    135: /*
                    136:  * Output a string.
                    137:  */
                    138:        public void
                    139: puts(s)
                    140:        register char *s;
                    141: {
                    142:        while (*s != '\0')
                    143:                putc(*s++);
                    144: }
                    145: 
                    146: /*
                    147:  * Output a message in the lower left corner of the screen
                    148:  * and wait for carriage return.
                    149:  */
                    150: 
                    151: static char return_to_continue[] = "  (press RETURN)";
                    152: 
                    153:        public void
                    154: error(s)
                    155:        char *s;
                    156: {
                    157:        register int c;
                    158:        static char buf[2];
                    159: 
                    160:        lower_left();
                    161:        clear_eol();
                    162:        so_enter();
                    163:        puts(s);
                    164:        puts(return_to_continue);
                    165:        so_exit();
                    166: 
                    167: #if ONLY_RETURN
                    168:        while ((c = getc()) != '\n' && c != '\r')
                    169:                bell();
                    170: #else
                    171:        c = getc();
                    172:        if (c != '\n' && c != '\r' && c != ' ')
                    173:        {
                    174:                buf[0] = c;
                    175:                first_cmd = buf;
                    176:        }
                    177: #endif
                    178: 
                    179:        if (strlen(s) > sc_width)
                    180:                repaint();
                    181: }
                    182: 
                    183:        public int
                    184: error_width()
                    185: {
                    186:        /*
                    187:         * Don't use the last position, because some terminals
                    188:         * will scroll if you write in the last char of the last line.
                    189:         */
                    190:        return (sc_width - 
                    191:                (sizeof(return_to_continue) + so_width + se_width + 1));
                    192: }

unix.superglobalmegacorp.com

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