BSD 2 development
[unix-history] / .ref-BSD-1 / ex-1.1 / ex_pack.c
CommitLineData
d43bb1bf
BJ
1#include "ex.h"
2#include "ex_re.h"
3/*
4 * Ex - a text editor
5 * Bill Joy UCB October, 1977
6 */
7
8/*
9 * Unpack into linebuf
10 */
11unpack(sp)
12 register char *sp;
13{
14 register char *lp;
15 register int c;
16 int i;
17
18 for (lp = linebuf; c = *sp++;) {
19 if ((c & 0200) != 0) {
20 c =& 0177;
21 switch (c) {
22
23 case 0:
24 c = ' ';
25gosh:
26 for (i = *sp++; i > 0; i--)
27 *lp++ = c;
28 continue;
29#ifdef UNIMP
30 case 012:
31 *lp++ = '\t';
32 *lp++ = '\t';
33 continue;
34#endif
35 case 015:
36 c = '\t';
37 goto gosh;
38 }
39 *lp++ = ' ';
40 }
41 *lp++ = c;
42 }
43 *lp = 0;
44 return (linebuf);
45}
46
47pack(sp)
48 register char *sp;
49{
50 register char *lp;
51 register int c;
52 int i;
53
54 for (lp = linebuf; c = *lp++;) {
55 if (c == '\n') {
56 linebp = lp;
57 break;
58 }
59 if (c != ' ' && c != '\t' || *lp == 0 || c == '\t' && *lp != '\t') {
60 *sp++ = c;
61 continue;
62 }
63 if (c == ' ' && *lp != ' ' && *lp != '\n') {
64 *sp++ = *lp++ | 0200;
65 continue;
66 }
67 for (i = 1; *lp == c && i < 127; lp++, i++)
68 continue;
69#ifdef UNIMP
70 if (c == '\t' && i == 2) {
71 *sp++ = 0212;
72 continue;
73 }
74#endif
75 *sp++ = c == '\t' ? 0215 : 0200;
76 *sp++ = i;
77 }
78 *sp = 0;
79}