-
Notifications
You must be signed in to change notification settings - Fork 3
/
exx.c
91 lines (85 loc) · 1.31 KB
/
exx.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
#include "ex.h"
/*
* Ex3a - a text editor
* Bill Joy UCB July 1977
*/
void
xop(void (*f)(), int c)
{
register int *dp;
nonzero();
if (!inglobal)
save12(), undkind = UNDCHANGE;
for (dp = addr1; dp <= addr2; dp++) {
dot = dp;
ex_getline(*dp);
strcpy(genbuf, linebuf);
(*f)(c);
if (!eq(linebuf, genbuf))
putmark(dp);
}
}
void
xpand(void)
{
register char *cp, *dp;
register int col;
col = 0;
for (dp = linebuf, cp = genbuf; *cp; cp++) {
if (*cp == '\t') {
do {
if (dp >= &linebuf[LBSIZE-2])
goto xovflo;
*dp++ = ' ';
col++;
} while (col & 07);
continue;
}
if (dp >= &linebuf[LBSIZE-2])
xovflo:
error("Line too long@after expansion of tabs");
*dp++ = *cp;
col++;
}
*dp++ = 0;
}
void
tabulate(char c)
{
register char *cp, *dp;
register int dcol;
int ocol;
ocol = 0;
dcol = 0;
cp = genbuf, dp = linebuf;
for (;;) {
switch (*cp) {
case ' ':
dcol++;
break;
case '\t':
dcol += 8;
dcol &= ~07;
break;
default:
while (((ocol + 8) &~ 07) <= dcol) {
if (ocol + 1 == dcol)
break;
*dp++ = '\t';
ocol += 8;
ocol &= ~07;
}
while (ocol < dcol) {
*dp++ = ' ';
ocol++;
}
if (*cp == 0 || c == 0) {
strcpy(dp, cp);
return;
}
*dp++ = *cp;
ocol++, dcol++;
}
cp++;
}
}