994
|
1 /* maksub.c */
|
|
2 #include <stdio.h>
|
|
3 #include "tools.h"
|
|
4 #include "ed.h"
|
|
5
|
|
6 char *
|
|
7 maksub(sub, subsz)
|
|
8 char *sub;
|
|
9 int subsz;
|
|
10 {
|
|
11 int size;
|
|
12 char delim, *cp;
|
|
13
|
|
14 size = 0;
|
|
15 cp = sub;
|
|
16
|
|
17 delim = *inptr++;
|
|
18 for (size = 0; *inptr != delim && *inptr != NL && size < subsz; size++) {
|
|
19 if (*inptr == '&') {
|
|
20 *cp++ = DITTO;
|
|
21 inptr++;
|
|
22 } else if ((*cp++ = *inptr++) == ESCAPE) {
|
|
23 if (size >= subsz) return(NULL);
|
|
24
|
|
25 switch (toupper(*inptr)) {
|
|
26 case NL: *cp++ = ESCAPE; break;
|
|
27 break;
|
|
28 case 'S':
|
|
29 *cp++ = SP;
|
|
30 inptr++;
|
|
31 break;
|
|
32 case 'N':
|
|
33 *cp++ = NL;
|
|
34 inptr++;
|
|
35 break;
|
|
36 case 'T':
|
|
37 *cp++ = HT;
|
|
38 inptr++;
|
|
39 break;
|
|
40 case 'B':
|
|
41 *cp++ = BS;
|
|
42 inptr++;
|
|
43 break;
|
|
44 case 'R':
|
|
45 *cp++ = CR;
|
|
46 inptr++;
|
|
47 break;
|
|
48 case '0':{
|
|
49 int i = 3;
|
|
50 *cp = 0;
|
|
51 do {
|
|
52 if (*++inptr < '0' || *inptr > '7')
|
|
53 break;
|
|
54
|
|
55 *cp = (*cp << 3) | (*inptr - '0');
|
|
56 } while (--i != 0);
|
|
57 cp++;
|
|
58 } break;
|
|
59 default: *cp++ = *inptr++; break;
|
|
60 }
|
|
61 }
|
|
62 }
|
|
63 if (size >= subsz) return(NULL);
|
|
64
|
|
65 *cp = EOS;
|
|
66 return(sub);
|
|
67 }
|
|
68
|