annotate 3rdparty/packages/ed/maksub.c @ 994:bef1844de0dc

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