-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathex_pack.c
80 lines (75 loc) · 1.11 KB
/
ex_pack.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
#include "ex.h"
#include "ex_re.h"
/*
* Ex - a text editor
* Bill Joy UCB October, 1977
*/
/*
* Unpack into linebuf
*/
char *
unpack(char *sp)
{
register char *lp;
register int c;
int i;
for (lp = linebuf; (c = *sp++);) {
if ((c & 0200) != 0) {
c &= 0177;
switch (c) {
case 0:
c = ' ';
gosh:
for (i = *sp++; i > 0; i--)
*lp++ = c;
continue;
#ifdef UNIMP
case 012:
*lp++ = '\t';
*lp++ = '\t';
continue;
#endif
case 015:
c = '\t';
goto gosh;
}
*lp++ = ' ';
}
*lp++ = c;
}
*lp = 0;
return (linebuf);
}
void
pack(char *sp)
{
register char *lp;
register int c;
int i;
for (lp = linebuf; (c = *lp++);) {
if (c == '\n') {
linebp = lp;
break;
}
if ((c != ' ' && c != '\t') || *lp == 0 || (c == '\t'
&& *lp != '\t')) {
*sp++ = c;
continue;
}
if (c == ' ' && *lp != ' ' && *lp != '\n') {
*sp++ = *lp++ | 0200;
continue;
}
for (i = 1; *lp == c && i < 127; lp++, i++)
continue;
#ifdef UNIMP
if (c == '\t' && i == 2) {
*sp++ = 0212;
continue;
}
#endif
*sp++ = c == '\t' ? 0215 : 0200;
*sp++ = i;
}
*sp = 0;
}