aboutsummaryrefslogtreecommitdiff
path: root/sys/imio/dbc/imgcom.x
blob: 504c0c55511dc0f8203bb535e97b072d027876ea (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<syserr.h>
include <ctype.h>
include	"idbc.h"

# IMGCOM -- Get the comment field for a keyword.

procedure imgcom (im, key, comment)

pointer	im			#I image descriptor
char	key[ARB]		#I parameter to be set
char	comment[ARB]		#O comment string

bool	string_valued
int	ch, i, n, j, ic, op
pointer	rp, ip, sp, buf
int	idb_findrecord(), ctowrd(), stridx(), idb_getstring()
errchk	syserrs

define  end_ 91
begin
	call smark (sp)
	call salloc (buf, SZ_LINE, TY_CHAR)

        # Special fields do not have comment.
        if (key[1] == 'i' && key[2] == '_') {  
	    comment[1] = EOS
	    return
        }

	# Find the record.
	if (idb_findrecord (im, key, rp) == 0)
	    call syserrs (SYS_IDBKEYNF, key)

        ip = IDB_STARTVALUE
        if (ctowrd (Memc[rp], ip, Memc[buf], SZ_LINE) <= 0) {
	    comment[1] = EOS
	    goto end_
        }
 
	# Look for '/'
        while (ip < IDB_RECLEN && (Memc[rp+ip] != '/'))
             ip = ip + 1
        if (ip == IDB_RECLEN) {
	   comment[1] = EOS
	   goto end_
        }
        op = rp+ip+1
        while (op < IDB_RECLEN+rp && (IS_WHITE(Memc[op]) || Memc[op] == '\n'))
             op = op + 1

        # Copy comment section
        for (i = 1; Memc[op] != '\n' && op < IDB_RECLEN+rp; op=op+1) {
            comment[i] = Memc[op]
            i = i + 1
        }
        # Trim
	i = i - 1
        while (i >= 1 && IS_WHITE(comment[i]))
	   i = i - 1

        comment[i+1] = EOS
end_
	call sfree (sp)
end