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
75
76
77
78
79
80
|
# TP_BREAK -- Break an image name into bracket delimeted substrings
#
# B.Simon 02-Jun-89 Original
procedure tp_break (imname, part, npart, maxch)
char imname[ARB] # i: Image name
char part[maxch,ARB] # o: Array of image name parts
int npart # i: Maximum number of parts
int maxch # i: Maximum length of part
#--
bool inside
char ch
int ic, jc, ipart
pointer sp, errmsg
string syntax "Syntax error in image name (%s)"
begin
# Allocate memory for error message
call smark (sp)
call salloc (errmsg, SZ_LINE, TY_CHAR)
# Initialize output to null string
do ipart = 1, npart
part[1,ipart] = EOS
# Break image name into bracket delimeted components
# The variable inside is used as a check that brackets are paired
jc = 1
ipart = 1
inside = false
for (ic = 1; ipart <= npart && imname[ic] != EOS; ic = ic + 1) {
ch = imname[ic]
if (ch == '\\') {
ic = ic + 1
} else if (ch == '[') {
if (inside) {
call sprintf (Memc[errmsg], SZ_LINE, syntax)
call pargstr (imname)
call error (1, Memc[errmsg])
}
part[jc,ipart] = EOS
ipart = ipart + 1
inside = true
jc = 1
} else if (ch == ']') {
if (! inside) {
call sprintf (Memc[errmsg], SZ_LINE, syntax)
call pargstr (imname)
call error (1, Memc[errmsg])
}
inside = false
} else if (ipart > 1 && ! inside) {
call sprintf (Memc[errmsg], SZ_LINE, syntax)
call pargstr (imname)
call error (1, Memc[errmsg])
}
part[jc,ipart] = imname[ic]
jc = jc + 1
if (jc > maxch) {
call sprintf (Memc[errmsg], SZ_LINE, syntax)
call pargstr (imname)
call error (1, Memc[errmsg])
}
}
part[jc,ipart] = EOS
call sfree (sp)
end
|