# 2.11BSD#431 - /usr/src/local/less/output.c

##### Functions

    carat_char        X
    control_char      X
    dropout           X
    error             X
    error_width       X
    flush             X
    put_line          X
    putc              X
    puts              X

##### Variables

    errmsgs           X
    public            X

       1: /*
       2:  * High level routines dealing with the output to the screen.
       3:  */
       4:
       5: #include "less.h"
       6:
       7: public int errmsgs; /* Count of messages displayed by error() */
       8:
       9: extern int sigs;
      10: extern int sc_width, sc_height;
      11: extern int ul_width, ue_width;
      12: extern int so_width, se_width;
      13: extern int bo_width, be_width;
      14: extern int tabstop;
      15: extern int twiddle;
      16: extern int any_display;
      17: extern char *line;
      18: extern char *first_cmd;
      19:
      20: /*
      21:  * Display the line which is in the line buffer.
      22:  */
      23:     public void
      24: put_line()
      25: {
      26:     register char *p;
      27:     register int c;
      28:     register int column;
      29:     extern int auto_wrap, ignaw;
      30:
      31:     if (sigs)
      32:         /*
      33: 		 * Don't output if a signal is pending.
      34: 		 */
      35:         return;
      36:
      37:     if (line == NULL)
      38:         line = (twiddle) ? "~" : "";
      39:
      40:     column = 0;
      41:     for (p = line;  *p != '\0';  p++)
      42:     {
      43:         switch (c = *p)
      44:         {
      45:         case UL_CHAR:
      46:             ul_enter();
      47:             column += ul_width;
      48:             break;
      49:         case UE_CHAR:
      50:             ul_exit();
      51:             column += ue_width;
      52:             break;
      53:         case BO_CHAR:
      54:             bo_enter();
      55:             column += bo_width;
      56:             break;
      57:         case BE_CHAR:
      58:             bo_exit();
      59:             column += be_width;
      60:             break;
      61:         case '\t':
      62:             do
      63:             {
      64:                 putc(' ');
      65:                 column++;
      66:             } while ((column % tabstop) != 0);
      67:             break;
      68:         case '\b':
      69:             putbs();
      70:             column--;
      71:             break;
      72:         default:
      73:             if (c & 0200)
      74:             {
      75:                 putc('^');
      76:                 putc(c & 0177);
      77:                 column += 2;
      78:             } else
      79:             {
      80:                 putc(c);
      81:                 column++;
      82:             }
      83:         }
      84:     }
      85:     if (column < sc_width || !auto_wrap || ignaw)
      86:         putc('\n');
      87: }
      88:
      89: /*
      90:  * Is a given character a "control" character?
      91:  * {{ ASCII DEPENDENT }}
      92:  */
      93:     public int
      94: control_char(c)
      95:     int c;
      96: {
      97:     return (c < ' ' || c == '\177');
      98: }
      99:
     100: /*
     101:  * Return the printable character used to identify a control character
     102:  * (printed after a carat; e.g. '\3' => "^C").
     103:  * {{ ASCII DEPENDENT }}
     104:  */
     105:     public int
     106: carat_char(c)
     107:     int c;
     108: {
     109:     return ((c == '\177') ? '?' : (c | 0100));
     110: }
     111:
     112:
     113: static char obuf[1024];
     114: static char *ob = obuf;
     115:
     116: /*
     117:  * Flush buffered output.
     118:  */
     119:     public void
     120: flush()
     121: {
     122:     write(1, obuf, ob-obuf);
     123:     ob = obuf;
     124: }
     125:
     126: /*
     127:  * Discard buffered output.
     128:  */
     129:     public void
     130: dropout()
     131: {
     132:     ob = obuf;
     133: }
     134:
     135: /*
     136:  * Output a character.
     137:  */
     138:     public void
     139: putc(c)
     140:     int c;
     141: {
     142:     if (ob >= &obuf[sizeof(obuf)])
     143:         flush();
     144:     *ob++ = c;
     145: }
     146:
     147: /*
     148:  * Output a string.
     149:  */
     150:     public void
     151: puts(s)
     152:     register char *s;
     153: {
     154:     while (*s != '\0')
     155:         putc(*s++);
     156: }
     157:
     158: /*
     159:  * Output a message in the lower left corner of the screen
     160:  * and wait for carriage return.
     161:  */
     162:
     163: static char return_to_continue[] = "  (press RETURN)";
     164:
     165:     public void
     166: error(s)
     167:     char *s;
     168: {
     169:     register int c;
     170:     static char buf[2];
     171:
     172:     errmsgs++;
     173:     if (!any_display)
     174:     {
     175:         /*
     176: 		 * Nothing has been displayed yet.
     177: 		 * Output this message on error output (file
     178: 		 * descriptor 2) and don't wait for a keystroke
     179: 		 * to continue.
     180: 		 *
     181: 		 * This has the desirable effect of producing all
     182: 		 * error messages on error output if standard output
     183: 		 * is directed to a file.  It also does the same if
     184: 		 * we never produce any real output; for example, if
     185: 		 * the input file(s) cannot be opened.  If we do
     186: 		 * eventually produce output, code in edit() makes
     187: 		 * sure these messages can be seen before they are
     188: 		 * overwritten or scrolled away.
     189: 		 */
     190:         write(2, s, strlen(s));
     191:         write(2, "\n", 1);
     192:         return;
     193:     }
     194:
     195:     lower_left();
     196:     clear_eol();
     197:     so_enter();
     198:     puts(s);
     199:     puts(return_to_continue);
     200:     so_exit();
     201:
     202: #if ONLY_RETURN
     203:     while ((c = getc()) != '\n' && c != '\r')
     204:         bell();
     205: #else
     206:     c = getc();
     207:     if (c != '\n' && c != '\r' && c != ' ')
     208:     {
     209:         buf[0] = c;
     210:         first_cmd = buf;
     211:     }
     212: #endif
     213:
     214:     if (strlen(s) + sizeof(return_to_continue) +
     215:         so_width + se_width + 1 > sc_width)
     216:         /*
     217: 		 * Printing the message has probably scrolled the screen.
     218: 		 * {{ Unless the terminal doesn't have auto margins,
     219: 		 *    in which case we just hammered on the right margin. }}
     220: 		 */
     221:         repaint();
     222: }
     223:
     224: #ifdef notdef
     225:     public int
     226: error_width()
     227: {
     228:     /*
     229: 	 * Don't use the last position, because some terminals
     230: 	 * will scroll if you write in the last char of the last line.
     231: 	 */
     232:     return (sc_width -
     233:         (sizeof(return_to_continue) + so_width + se_width + 1));
     234: }
     235: #endif

#### Defined functions

carat_char defined in line 105; used 4 times

- in /usr/src/local/less/command.c line 108
- in /usr/src/local/less/funcs.h line 39
- in /usr/src/local/less/line.c line 377
- in /usr/src/local/less/option.c line 242

control_char defined in line 93; used 5 times

- in /usr/src/local/less/command.c line 52, 104
- in /usr/src/local/less/funcs.h line 38
- in /usr/src/local/less/line.c line 364
- in /usr/src/local/less/option.c line 241

dropout defined in line 129; used 2 times

- in /usr/src/local/less/funcs.h line 41
- in /usr/src/local/less/signal.c line 89

error defined in line 165; used 41 times

- in /usr/src/local/less/ch.c line 108, 125, 383, 395
- in /usr/src/local/less/command.c line 302, 476, 483, 553, 561, 570
- in /usr/src/local/less/funcs.h line 44
- in /usr/src/local/less/help.c line 21
- in /usr/src/local/less/main.c line 56, 68, 78, 90, 121, 157, 192, 212, 225
- in /usr/src/local/less/option.c line 195, 230, 237, 247, 367, 389
- in /usr/src/local/less/prim.c line 285, 319, 334, 360, 428, 464, 505, 547, 563, 574, 592, 645, 685
- in /usr/src/local/less/screen.c line 165

error_width defined in line 225; used 1 times

- in /usr/src/local/less/funcs.h line 45

flush defined in line 119; used 10 times

- in line 143
- in /usr/src/local/less/ch.c line 195
- in /usr/src/local/less/command.c line 138
- in /usr/src/local/less/funcs.h line 40
- in /usr/src/local/less/main.c line 149, 241, 366
- in /usr/src/local/less/signal.c line 102, 172
- in /usr/src/local/less/ttyin.c line 40

put_line defined in line 23; used 3 times

- in /usr/src/local/less/funcs.h line 37
- in /usr/src/local/less/prim.c line 139, 193

putc defined in line 138; used 26 times

- in line 64, 75-80(3), 86, 155
- in /usr/src/local/less/command.c line 74, 106-110(2), 172
- in /usr/src/local/less/funcs.h line 42
- in /usr/src/local/less/main.c line 240
- in /usr/src/local/less/screen.c line 428, 439, 448, 458, 467, 476, 486, 495, 504, 513, 526-528(3), 537

puts defined in line 150; used 15 times

- in line 198-199(2)
- in /usr/src/local/less/ch.c line 193
- in /usr/src/local/less/command.c line 176, 526, 538, 618, 631
- in /usr/src/local/less/funcs.h line 43
- in /usr/src/local/less/main.c line 146-148(2)
- in /usr/src/local/less/prim.c line 108
- in /usr/src/local/less/signal.c line 163-165(3)

#### Defined variables

errmsgs defined in line 7; used 2 times

- in line 172
- in /usr/src/local/less/main.c line 184

ob defined in line 114; used 5 times

- in line 122-123(2), 132, 142-144(2)

obuf defined in line 113; used 7 times

- in line 114, 122-123(3), 132, 142(2)

public defined in line 138; never used
return_to_continue defined in line 163; used 3 times

- in line 199, 214, 233

Last modified: 1990-07-10 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 816 |