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
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
flush
defined in line
119; used 10 times
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
Defined variables
ob
defined in line
114; used 5 times
obuf
defined in line
113; used 7 times