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: #ifndef NRTC
  89: /*
  90:  * Return the printable character used to identify a control character
  91:  * (printed after a carat; e.g. '\3' => "^C").
  92:  * {{ ASCII DEPENDENT }}
  93:  */
  94:     public int
  95: carat_char(c)
  96:     int c;
  97: {
  98:     return ((c == '\177') ? '?' : (c | 0100));
  99: }
 100: #endif	NRTC
 101: 
 102: 
 103: static char obuf[1024];
 104: static char *ob = obuf;
 105: 
 106: /*
 107:  * Flush buffered output.
 108:  */
 109:     public void
 110: flush()
 111: {
 112:     write(1, obuf, ob-obuf);
 113:     ob = obuf;
 114: }
 115: 
 116: /*
 117:  * Discard buffered output.
 118:  */
 119:     public void
 120: dropout()
 121: {
 122:     ob = obuf;
 123: }
 124: 
 125: /*
 126:  * Output a character.
 127:  */
 128:     public void
 129: putc(c)
 130:     int c;
 131: {
 132:     if (ob >= &obuf[sizeof(obuf)])
 133:         flush();
 134:     *ob++ = c;
 135: }
 136: 
 137: /*
 138:  * Output a string.
 139:  */
 140:     public void
 141: puts(s)
 142:     register char *s;
 143: {
 144:     while (*s != '\0')
 145:         putc(*s++);
 146: }
 147: 
 148: /*
 149:  * Output a message in the lower left corner of the screen
 150:  * and wait for carriage return.
 151:  */
 152: 
 153: static char return_to_continue[] = "  (press RETURN)";
 154: 
 155:     public void
 156: error(s)
 157:     char *s;
 158: {
 159:     register int c;
 160:     static char buf[2];
 161: 
 162:     lower_left();
 163:     clear_eol();
 164:     so_enter();
 165:     puts(s);
 166:     puts(return_to_continue);
 167:     so_exit();
 168: 
 169: #if ONLY_RETURN
 170:     while ((c = getc()) != '\n' && c != '\r')
 171:         bell();
 172: #else
 173:     c = getc();
 174:     if (c != '\n' && c != '\r' && c != ' ')
 175:     {
 176:         buf[0] = c;
 177:         first_cmd = buf;
 178:     }
 179: #endif
 180: 
 181:     if (strlen(s) > sc_width)
 182:         repaint();
 183: }
 184: 
 185:     public int
 186: error_width()
 187: {
 188:     /*
 189: 	 * Don't use the last position, because some terminals
 190: 	 * will scroll if you write in the last char of the last line.
 191: 	 */
 192:     return (sc_width -
 193:         (sizeof(return_to_continue) + so_width + se_width + 1));
 194: }

Defined functions

carat_char defined in line 94; used 1 times

Defined variables

ob defined in line 104; used 5 times
obuf defined in line 103; used 7 times
public defined in line 128; never used
return_to_continue defined in line 153; used 2 times
Last modified: 1986-04-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1311
Valid CSS Valid XHTML 1.0 Strict