Commit | Line | Data |
---|---|---|
09a0104b BJ |
1 | #include "ex.h" |
2 | #include "ex_re.h" | |
3 | /* | |
4 | * Ex - a text editor | |
5 | * Bill Joy UCB June 1977 | |
6 | * | |
7 | * Should get a < n square algorithm here. | |
8 | */ | |
9 | ||
10 | #define GBSIZE 256 | |
11 | ||
12 | global(k) | |
13 | int k; | |
14 | { | |
15 | register char *gp; | |
16 | register c; | |
17 | register int *a1; | |
18 | char globuf[GBSIZE], *Cwas; | |
19 | int i; | |
20 | ||
21 | i = dol - zero; | |
22 | Cwas = Command; | |
23 | if (inglobal) | |
24 | error("Global within global@not allowed"); | |
25 | markDOT(); | |
26 | setall(); | |
27 | nonzero(); | |
28 | skipwh(); | |
29 | c = getchar(); | |
30 | if (endcmd(c)) | |
31 | error("Global needs re|Missing regular expression for global"); | |
32 | compile(c, 0); | |
33 | savere(&scanre); | |
34 | gp = globuf; | |
35 | while ((c = getchar()) != '\n') { | |
36 | switch (c) { | |
37 | case EOF: | |
38 | error("EOF reading global"); | |
39 | case '\\': | |
40 | c = getchar(); | |
41 | switch (c) { | |
42 | case '\\': | |
43 | ungetchar(c); | |
44 | break; | |
45 | case '\n': | |
46 | break; | |
47 | default: | |
48 | *gp++ = '\\'; | |
49 | break; | |
50 | } | |
51 | break; | |
52 | } | |
53 | *gp++ = c; | |
54 | if (gp >= &globuf[GBSIZE - 2]) | |
55 | error("Global command too long@- limit 254 characters"); | |
56 | } | |
57 | ungetchar(c); | |
58 | newline(); | |
59 | *gp++ = c; | |
60 | *gp++ = 0; | |
61 | inglobal = 1; | |
62 | for (a1 = one; a1 <= dol; a1++) { | |
63 | *a1 =& ~01; | |
64 | if (a1 >= addr1 && a1 <= addr2 && execute(0, a1) == k) | |
65 | *a1 =| 01; | |
66 | } | |
67 | saveall(); | |
68 | for (a1 = one; a1 <= dol; a1++) { | |
69 | if (*a1 & 01) { | |
70 | *a1 =& ~01; | |
71 | dot = a1; | |
72 | globp = globuf; | |
73 | commands(1, 1); | |
74 | a1 = zero; | |
75 | } | |
76 | } | |
77 | inglobal = 0; | |
78 | endline = 1; | |
79 | Command = Cwas; | |
80 | netchHAD(i); | |
81 | setlastchar(EOF); | |
82 | } | |
83 | ||
84 | save(a1, a2) | |
85 | int *a1; | |
86 | register int *a2; | |
87 | { | |
88 | register int *addr, *dest; | |
89 | struct { int integer; }; | |
90 | ||
91 | undkind = UNDNONE; | |
92 | undadot = dot; | |
93 | for (dest = dol + 1, addr = a1; addr <= a2; *dest++ = *addr++) | |
94 | if (dest >= endcore) { | |
95 | if (sbrk(1024) == -1) | |
96 | error("Out of memory@saving lines for undo - try using ed or re)"); | |
97 | endcore.integer =+ 1024; | |
98 | } | |
99 | undkind = UNDALL; | |
100 | unddel = a1 - 1; | |
101 | undap1 = a1; | |
102 | undap2 = a2 + 1; | |
103 | unddol = dest - 1; | |
104 | } | |
105 | ||
106 | save12() | |
107 | { | |
108 | ||
109 | save(addr1, addr2); | |
110 | } | |
111 | ||
112 | saveall() | |
113 | { | |
114 | ||
115 | save(one, dol); | |
116 | } |