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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <error.h>
include <imhdr.h>
include <ctype.h>
# IMGETS -- Get the value of an image header parameter as a character string.
# The value is returned as a CL parameter of type string; the type coercion
# facilities of the CL may be used to convert to a different datatype if
# desired.
procedure t_imgets()
pointer sp, im
pointer image, param, value
pointer immap()
int ip, op, stridxs()
begin
call smark (sp)
call salloc (image, SZ_FNAME, TY_CHAR)
call salloc (param, SZ_LINE, TY_CHAR)
call salloc (value, SZ_LINE, TY_CHAR)
call clgstr ("image", Memc[image], SZ_FNAME)
call clgstr ("param", Memc[param], SZ_LINE)
im = immap (Memc[image], READ_ONLY, 0)
iferr (call imgstr (im, Memc[param], Memc[value], SZ_LINE)) {
call erract (EA_WARN)
call clpstr ("value", "0")
} else {
# Check for special case of string with double quotes.
if (stridxs ("\"", Memc[value]) != 0) {
op = param
for (ip=value; Memc[ip]!=EOS; ip=ip+1) {
if (Memc[ip] == '"') {
Memc[op] = '\\'
op = op + 1
}
Memc[op] = Memc[ip]
op = op + 1
}
Memc[op] = EOS
call clpstr ("value", Memc[param])
} else
call clpstr ("value", Memc[value])
}
call imunmap (im)
call sfree (sp)
end
|