1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include "imx.h"
# IMX_ESCAPE -- Return a pointer to the composed file name, escaping parts
# as needed.
pointer procedure imx_escape (in, index, extname, extver, ikparams,
section, expr, maxch)
char in[ARB] #I File image name (without kernel or image sec)
char index[ARB] #I Range list of extension indexes
char extname[ARB] #I Pattern for extension names
char extver[ARB] #I Range list of extension versions
char ikparams[ARB] #I Image kernel parameters
char section[ARB] #I Image section
char expr[ARB] #I Selection expression
int maxch #I Print errors?
pointer out, op
int i, len, level
char ch, peek, prev
bool init_esc
int strlen()
define output {Memc[op]=$1;op=op+1}
define escape {output('\\');output($1)}
begin
len = max (SZ_LINE, strlen (in))
call calloc (out, max (SZ_LINE, (4*len)), TY_CHAR)
op = out
level = 0
init_esc = false
for (i=1; i <= len; i=i+1) {
prev = in[max(1,i)]
ch = in[i]
peek = in[i+1]
if (ch == EOS)
break;
if (ch == '[') {
if (prev != ']' && !init_esc) {
output ('%')
output ('%')
output (CH_DELIM)
init_esc = true
}
escape (ch)
level = level + 1
} else if (ch == ']') {
output (ch)
if (peek != '[') # closing delim
output ('%')
level = level - 1
} else if (ch == ',') {
if (level > 0)
output('\\')
if (level == 0)
init_esc = false
output (ch)
} else if (ch == '*')
escape (ch)
else
output (ch)
}
output (EOS)
return (out)
end
|