-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexz.c
158 lines (148 loc) · 2.41 KB
/
exz.c
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
#include "ex.h"
#include "ex_tty.h"
/*
* Ex - a text editor
* Bill Joy UCB June 1977
*/
static void zop2(int, int);
static void splitit(void);
char znoclear, zhadpr, zweight;
void
zop(char hadpr)
{
register int c, lines, op;
zhadpr = hadpr;
notempty();
znoclear = 0;
zweight = 0;
switch(c = op = ex_getchar()) {
case '^':
zweight = 1;
case '-':
case '+':
while (peekchar() == op) {
ex_getchar();
zweight++;
}
case '=':
case '.':
c = ex_getchar();
break;
case EOF:
znoclear++;
break;
default:
op = 0;
break;
}
if (digit(c)) {
lines = c - '0';
for(;;) {
c = ex_getchar();
if (!digit(c))
break;
lines *= 10;
lines += c - '0';
}
if (lines < value(WINDOW))
znoclear++;
if (op == '=')
lines += 2;
} else
lines = op == EOF ? value(SCROLL) : value(WINDOW);
if (c != EOF) {
ungetchar(c);
ex_newline();
}
addr1 = addr2;
setdot();
zop2(lines, op);
}
static void
zop2(int lines, int op)
{
register int *split;
split = NIL;
switch(op) {
case EOF:
if (addr2 == dol)
error("\nAt EOF");
case '+':
if (addr2 == dol)
error("At EOF");
addr2 += lines * zweight;
if (addr2 > dol)
error("Hit BOTTOM");
addr2++;
default:
addr1 = addr2;
addr2 += lines-1;
dot = addr2;
break;
case '=':
case '.':
lines--;
lines >>= 1;
if (op == '=')
lines--;
addr1 = addr2-lines;
if (op == '=')
dot = split = addr2;
addr2 += lines;
if (op == '.') {
markDOT();
dot = addr2;
}
break;
case '^':
case '-':
addr2 -= lines * zweight;
if (addr2 < one)
error("Hit TOP");
lines--;
addr1 = addr2 - lines;
dot = addr2;
break;
}
if (addr1 <= zero)
addr1 = one;
if (addr2 > dol)
addr2 = dol;
if (dot > dol)
dot = dol;
if (addr1 > addr2)
return;
if (addr2 - addr1 > 1 /* && really wanna do this */)
pstart();
if (op == EOF && zhadpr) {
ex_getline(*addr1);
ex_putchar('\r' | QUOTE);
shudclob = 1;
} else if (znoclear == 0 && CLEAR)
ex_putchar('\032' | QUOTE);
if (split) {
plines(addr1, split - 1, 0);
splitit();
plines(split, split, 0);
splitit();
addr1 = split + 1;
}
plines(addr1, addr2, 0);
}
static void
splitit(void)
{
register int l;
register char *lp;
for (l = COLUMNS == 1000 ? 72 : COLUMNS, lp = linebuf; l > 0; l--)
*lp++ = '-';
*lp = 0;
ex_printf("%s\n", linebuf);
}
void
zeq(int cnt)
{
znoclear = 0;
zop2(cnt, '=');
putNFL();
}