Repository navigation
Expand file tree
/
Copy pathdisplay.c
More file actions
executable file
·547 lines (506 loc) · 10.8 KB
/
Copy pathdisplay.c
File metadata and controls
executable file
·547 lines (506 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/* Copyright (c) 1985 Ceriel J.H. Jacobs */
# ifndef lint
static char rcsid[] = "$Header$";
# endif
# define _DISPLAY_
# include "in_all.h"
# include "display.h"
# include "assert.h"
# include "machine.h"
# include "term.h"
# include "output.h"
# include "options.h"
# include "process.h"
# include "getline.h"
# include "main.h"
STATIC char * do_line();
/*
* Fill n lines of the screen, each with "str".
*/
STATIC VOID
fillscr(n,str) char *str; int n; {
while (n-- > 0) {
putline(str);
}
}
/*
* Skip "n" screenlines of line "p", and return what's left of it.
*/
STATIC char *
skiplines(p,n) char *p; int n; {
while (n-- > 0) {
p = do_line(p,0);
scr_info.currentpos--;
}
return p;
}
/*
* Redraw screen.
* "n" = 1 if it is a real redraw, 0 if one page must be displayed.
* It is also called when yap receives a stop signal.
*/
VOID
redraw(n) int n; {
register struct scr_info *p = &scr_info;
register int i;
i = pagesize;
if (n && p->currentpos) {
i = p->currentpos;
}
(VOID) display(p->firstline,p->nf,i,1);
}
/*
* Compute return value for the routines "display" and "scrollf".
* This return value indicates wether we are at the end of file
* or at the start, or both.
* "s" contains that part of the last line that was not displayed.
*/
STATIC int
compretval(s) char *s; {
register int i;
register struct scr_info *p = &scr_info;
i = 0;
if (!s || (!*s && !getline(p->lastline+1, 1))) {
i = EOFILE;
}
if (p->firstline == 1 && !p->nf) {
i |= START;
}
status = i;
return i;
}
/*
* Display nlines, starting at line n, not displaying the first
* nd screenlines of n.
* If reallydispl = 0, the actual displaying is not performed,
* only the computing associated with it is done.
*/
int
display(n,nd,nlines,reallydispl)
long n; int nd; register int nlines; int reallydispl; {
register struct scr_info *s = &scr_info;
register char *p; /* pointer to line to be displayed */
if (startcomm) { /* No displaying on a command from the
* yap command line. In this case, displaying
* will be done after executing the command,
* by a redraw.
*/
reallydispl = 0;
}
if (!n) {
n = 1L;
nd = 0;
}
if (reallydispl) { /* move cursor to starting point */
if (stupid) {
putline(currentfile);
putline(", line ");
prnum(n);
nlines--;
}
if (cflag) {
putline("\r\n");
}
else {
home();
clrscreen();
}
}
/*
* Now, do computations and display
*/
s->currentpos = 0;
s->nf = nd;
s->head = s->tail;
s->tail->cnt = 0;
s->tail->line = n;
p = skiplines(getline(n,1),nd);
while (nlines && p) {
/*
* While there is room,
* and there is something left to display ...
*/
(s->tail->cnt)++;
nlines--;
if (*(p = do_line(p,reallydispl)) == '\0') {
/*
* File-line finished, get next one ...
*/
p = getline(++n,1);
if (nlines && p) {
s->tail = s->tail->next;
s->tail->cnt = 0;
s->tail->line = n;
}
}
}
if (!stupid) {
s->currentpos += nlines;
if (reallydispl) {
fillscr(nlines, "~\r\n");
fillscr(maxpagesize - s->currentpos, "\r\n");
}
}
return compretval(p);
}
/*
* Scroll forwards n lines.
*/
int
scrollf(n,reallydispl) int n; int reallydispl; {
register struct scr_info *s = &scr_info;
register char *p;
register long ll;
register int i;
/*
* First, find out how many screenlines of the last line were already
* on the screen, and possibly above it.
*/
if (n <= 0 || (status & EOFILE)) return status;
if (startcomm) reallydispl = 0;
/*
* Find out where to begin displaying
*/
i = s->tail->cnt;
if ((ll = s->lastline) == s->firstline) i += s->nf;
p = skiplines(getline(ll, 1), i);
/*
* Now, place the cursor at the first free line
*/
if (reallydispl && !stupid) {
clrbline();
mgoto(s->currentpos);
}
/*
* Now display lines, keeping track of which lines are on the screen.
*/
while (n-- > 0) { /* There are still rows to be displayed */
if (!*p) { /* End of line, get next one */
if (!(p = getline(++ll, 1))) {
/*
* No lines left. At end of file
*/
break;
}
s->tail = s->tail->next;
s->tail->cnt = 0;
s->tail->line = ll;
}
if (s->currentpos >= maxpagesize) {
/*
* No room, delete first screen-line
*/
s->currentpos--;
s->nf++;
if (--(s->head->cnt) == 0) {
/*
* The first file-line on the screen is wiped
* out completely; update administration
* accordingly.
*/
s->nf = 0;
s->head = s->head->next;
assert(s->head->cnt > 0);
}
}
s->tail->cnt++;
p = do_line(p, reallydispl);
}
return compretval(p);
}
/*
* Scroll back n lines
*/
int
scrollb(n, reallydispl) int n, reallydispl; {
register struct scr_info *s = &scr_info;
register char *p; /* Holds string to be displayed */
register int i;
register int count;
register long ln; /* a line number */
register int nodispl;
int cannotscroll; /* stupid or no insert-line */
/*
* First, find out where to start
*/
if ((count = n) <= 0 || (status & START)) return status;
if (startcomm) reallydispl = 0;
cannotscroll = stupid || (!*AL && !*SR);
ln = s->firstline;
nodispl = s->nf;
while (count) { /* While scrolling back ... */
if (i = nodispl) {
/*
* There were screen-lines of s->firstline that were not
* displayed.
* We can use them now, but only "count" of them.
*/
if (i > count) i = count;
s->currentpos += i;
nodispl -= i;
count -= i;
}
else { /* Get previous line */
if (ln == 1) break; /* isn't there ... */
p = getline(--ln, 1);
/*
* Make it the first line of the screen and compute
* how many screenlines it takes. These lines are not
* displayed, but nodispl is set to this count, so
* that it will be nonzero next time around
*/
nodispl = 0;
do { /* Find out how many screenlines */
nodispl++;
p = skiplines(p, 1);
} while (*p);
}
}
n -= count;
if ((i = s->currentpos) > maxpagesize) i = maxpagesize;
if (reallydispl && hardcopy) i = n;
/*
* Now that we know where to start, we can use "display" to do the
* rest of the computing for us, and maybe even the displaying ...
*/
i = display(ln,
nodispl,
i,
reallydispl && cannotscroll);
if (cannotscroll || !reallydispl) {
/*
* Yes, "display" did the displaying, or we did'nt have to
* display at all.
* I like it, but the user obviously does not.
* Let him buy another (smarter) terminal ...
*/
return i;
}
/*
* Now, all we have to do is the displaying. And we are dealing with
* a smart terminal (it can insert lines or scroll back).
*/
home();
/*
* Insert lines all at once
*/
for (i = n; i; i--) {
if (DB && *CE) {
/*
* Grumble..., terminal retains lines below, so we have
* to clear the lines that we push off the screen
*/
clrbline();
home();
}
if (*SR) {
scrollreverse();
}
else {
# ifdef VT100_PATCH
insert_line(0);
# else
insert_line();
# endif
}
}
p = skiplines(getline(ln = s->firstline, 1), s->nf);
for (i = 0; i < n; i++) {
p = do_line(p,1);
s->currentpos--;
if (!*p) {
p = getline(++ln, 1);
}
}
return count;
}
/*
* Process a line.
* If reallydispl > 0 then display it.
*/
STATIC char *
do_line(str, reallydispl) register char *str; int reallydispl; {
char buf[1024];
register char *p = buf;
register int pos = COLS;
register int c;
register int c1;
register int do_ul = 0, do_hl = 0;
int lastmode = 0, lasthlmode = 0;
int c2;
while (*str && pos > 0) {
if (*str < ' ' && (c1 = match(str,&c2,sppat)) > 0) {
/*
* We found a string that matches, and thus must be
* echoed literally
*/
if ((pos - c2) <= 0) {
/*
* It did not fit
*/
break;
}
pos -= c2;
str += c1;
if (reallydispl) {
c = *str;
*p = *str = 0;
cputline(p = buf);
putline(str - c1);
*str = c;
}
continue;
}
c = *s
8000
tr++;
do_hl = 0;
if (*str == '\b' && *(str+1) != 0
&& (c != '_' || *(str+2) == '\b')) {
while (*str == '\b' && *(str+1) != 0) {
str++;
c = *str++;
do_hl = 1;
}
}
do_ul = 1;
/*
* Find underline sequences ...
*/
if (c == '_' && *str == '\b') {
str++;
c = *str++;
}
else {
if (*str == '\b' && *(str+1) == '_') {
str += 2;
}
else do_ul = 0;
}
if (reallydispl && do_hl != lasthlmode) {
*p = 0;
cputline(p = buf);
if (do_hl) bold();
else end_bold();
}
lasthlmode = do_hl;
if (reallydispl && do_ul != lastmode) {
*p = 0;
cputline(p = buf);
if (do_ul) underline();
else end_underline();
}
lastmode = do_ul;
*p++ = c;
if (c >= ' ' && c < 0177) {
pos--;
if (reallydispl && do_ul && *UC && pos > 0) {
/*
* Underlining apparently is done one
* character at a time.
*/
*p = 0;
cputline(p = buf);
backspace();
underchar();
}
continue;
}
if (c == '\t') {
p--;
c1 = 8 - ((COLS - pos) & 07);
/*
* Actually, if COLS is a multiple of 8, this can be
* simplified to
* c1 = pos & 07;
* But of course, we don't know that for sure.
*/
if (pos - c1 < 0) break;
pos -= c1;
if (reallydispl) {
if (expandtabs) {
/*
* Expand tabs. We cannot let the
* kernel take care of this
* for two reasons:
* 1. There can be tabs in cursor
* addressing strings,
* 2. We probably do it better.
*/
while (c1-- > 0) {
*p++ = ' ';
}
}
else {
*p = 0;
cputline(p = buf);
givetab();
}
}
continue;
}
/*
* Now we have a control character, which takes two positions
*/
if (pos <= 1) {
p--;
break;
}
pos -= 2;
}
if (reallydispl) {
*p = 0;
cputline(buf);
if (pos > 0 || (pos <= 0 && (!AM || XN))) {
putline("\r\n");
}
/*
* The next should be here! I.e. it may not be before printing
* the newline. This has to do with XN. We don't know exactly
* WHEN the terminal will stop ignoring the newline.
* I have for example a terminal (Ampex a230) that will
* continue to ignore the newline after a clear to end of line
* sequence, but not after an end_underline sequence.
*/
if (do_ul) {
end_underline();
}
if (do_hl) {
standend();
}
}
scr_info.currentpos++;
return str;
}
/* ARGSUSED */
int
setmark(cnt) long cnt; { /* Set a mark on the current page */
register struct scr_info *p = &scr_info;
p->savfirst = p->firstline;
p->savnf = p->nf;
}
/* ARGSUSED */
int
tomark(cnt) long cnt; { /* Go to the mark */
register struct scr_info *p = &scr_info;
(VOID) display(p->savfirst,p->savnf,pagesize,1);
<
4645
/div>}
/* ARGSUSED */
int
exgmark(cnt) long cnt; { /* Exchange mark and current page */
register struct scr_info *p = &scr_info;
register long svfirst;
register int svnf;
svfirst = p->firstline;
svnf = p->nf;
tomark(0L);
p->savfirst = svfirst;
p->savnf = svnf;
}
VOID
d_clean() { /* Clean up */
register struct scr_info *p = &scr_info;
p->savnf = 0;
p->savfirst = 0;
p->head = p->tail;
p->head->line = 0;
p->currentpos = 0;
}