994
|
1 /* catsub.c */
|
|
2 #include <stdio.h>
|
|
3 #include "tools.h"
|
|
4 #include "ed.h"
|
|
5
|
|
6 extern char *paropen[9], *parclose[9];
|
|
7
|
|
8 char *catsub(from, to, sub, new, newend)
|
|
9 char *from, *to, *sub, *new, *newend;
|
|
10 {
|
|
11 char *cp, *cp2;
|
|
12
|
|
13 for (cp = new; *sub != EOS && cp < newend;) {
|
|
14 if (*sub == DITTO) for (cp2 = from; cp2 < to;) {
|
|
15 *cp++ = *cp2++;
|
|
16 if (cp >= newend) break;
|
|
17 }
|
|
18 else if (*sub == ESCAPE) {
|
|
19 sub++;
|
|
20 if ('1' <= *sub && *sub <= '9') {
|
|
21 char *parcl = parclose[*sub - '1'];
|
|
22
|
|
23 for (cp2 = paropen[*sub - '1']; cp2 < parcl;) {
|
|
24 *cp++ = *cp2++;
|
|
25 if (cp >= newend) break;
|
|
26 }
|
|
27 } else
|
|
28 *cp++ = *sub;
|
|
29 } else
|
|
30 *cp++ = *sub;
|
|
31
|
|
32 sub++;
|
|
33 }
|
|
34
|
|
35 return(cp);
|
|
36 }
|
|
37
|