aboutsummaryrefslogtreecommitdiff
path: root/sys/qpoe/qpgpsym.x
blob: b18199e21b8a568d14db3d3a0c8ef17e2109cc72 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<syserr.h>
include	"qpoe.h"

# QP_GPSYM -- Lookup the named parameter in the symbol table and return
# a pointer to the symstruct describing the parameter as the function value.
# NULL is returned if the parameter is not defined, or if the named symbol is
# not a parameter.  Global parameter aliases are recursively expanded.
# Local macros are not expanded at this level, since local macros are stored
# as parameters themselves.

pointer procedure qp_gpsym (qp, param)

pointer	qp			#I QPOE descriptor
char	param[ARB]		#I parameter name

int	n
pointer	sp, pname, sym, st, sm
pointer	stfind(), strefsbuf(), qm_symtab()
errchk	syserrs

#pointer	ip
#int	fd, nchars
#int	fm_getfd(), read()
#errchk	fm_getfd, read, seek

begin
	call smark (sp)
	call salloc (pname, SZ_FNAME, TY_CHAR)

	st = QP_ST(qp)
	sm = qm_symtab (QP_QM(qp))
	call strcpy (param, Memc[pname], SZ_FNAME)

	# First expand any aliases in the global macro symbol table.
	sym = stfind (sm, param)
	for (n=1;  sym != NULL;  n=n+1) {
	    if (and (S_FLAGS(sym), SF_DELETED) != 0)
		break
	    call strcpy (strefsbuf(sm,S_OFFSET(sym)), Memc[pname], SZ_FNAME)
	    sym = stfind (sm, Memc[pname])
	    if (n > MAX_INDIR)
		call syserrs (SYS_QPMRECUR, param)
	}

	# Lookup the symbol in the datafile local symbol table.  Datafile
	# local macros cannot be expanded in parameter references, since
	# the macros are themselves stored as parameters (if macro parameters
	# were expanded in parameter references, there would be no simple
	# way to access the macro parameters themselves).

	sym = stfind (st, Memc[pname])

#	Disable expansion of datafile-local macro defines.
#	if (sym != NULL) {
#	    for (n=0;  S_DTYPE(sym) == TY_MACRO;  n=n+1) {
#		if (and (S_FLAGS(sym), SF_DELETED) != 0) {
#		    break
#
#		} else if (S_LFILE(sym) > 0) {
#		    # Macro value stored as data.
#		    fd = fm_getfd (QP_FM(qp), S_LFILE(sym), READ_ONLY, 0)
#
#		    call seek (fd, S_OFFSET(sym))
#		    nchars = max (0, read (fd, Memc[pname], S_NELEM(sym)))
#		    Memc[pname+nchars] = EOS
#		    ip = pname
#
#		    call fm_retfd (QP_FM(qp), S_LFILE(sym))
#
#		} else {
#		    # Macro value stored in symbol table.
#		    ip = strefsbuf (st, S_OFFSET(sym))
#		}
#
#		# Macro recursion.
#		if (n > MAX_INDIR)
#		    call syserrs (SYS_QPMRECUR, param)
#	    }
#	}

	# Don't "find" the symbol if it has been deleted.
	if (sym != NULL)
	    if (and (S_FLAGS(sym), SF_DELETED) != 0)
		sym = NULL

	call sfree (sp)
	return (sym)
end