aboutsummaryrefslogtreecommitdiff
path: root/pkg/cl/doc/pset.sys
blob: 143d3b2a4f7c41a27acb7897ca7adda38df7b065 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
1. Procedures

	  ltp = cmdsrch (path)
	ltp = ltasksrch (path)
	 pp = paramsrch (path, &field)

	pfp = pfilesrch (path)
	pfp = pfileload (ltp)
	    pfileupdate (pfp)
	     pfilemerge (pfp, oldpfile)
	pfp = pfileread (pfilename)
	     pfilewrite (pfp, pfilename)


2. Pseudocode


# PFILESRCH -- Given a pfile name or the name of an ltask which has a pfile,
# allocate a pfile descriptor and read the pfile into that descriptor.

pfp procedure pfilesrch (path)

begin
	if (path is a filename)
	    return (pfp = pfileread (fname))
	else {
	    ltp = ltasksrch (path)
	    return (pfp = pfileload (ltp))
	}
end


# PFILELOAD -- Load the pfile for an ltask, given its descriptor ltp.

pfp procedure pfileload (ltp)

begin
	pfp = NULL

	if (ltp references a pset task) {
	    Descend the control stack task-list and examine the pset of
	    each task to locate the most recently executed task which
	    references this pset task.  The value of the pset parameter
	    for that task determines which pfile to use.

	    if (pset_param_value is a filename (.par or .cl extn))
		return (pfp = pfileread (fname))
	    else if (pset_param_value is an ltaskname)
		ltp = ltask descriptor of that task
	    else
		do nothing - use pset of pset-task on ltp
	}

	make usr_pfile name = uparm$pkgltask.par
	if (pfileload already called for this task)
	    return (pfp = pfileread (usr_pfile))

	get finfo of usr_pfile
	get filename, finfo of pkg_pfile
	    (check for .par, and if not found, use .cl)

	if (usr pfile exists and has a nonzero extent) {
	    if (usr pfile is older than pkg_pfile) {
		# Merge old usr_pfile into pkg_pfile, update usr_pfile.
		pfp = pfileread (pkg_pfile)
		pfp->pfilename = usr_pfile
		pfilemerge (pfp, usr_pfile)
	    }
	} else if (uparm exists and learning is enabled) {
	    # Make user copy of pkg pfile.
	    pfp = pfileread (pkg_pfile)
	    pfp->pfilename = usr_pfile
	} else
	    return (pfileread (pkg_pfile))

	set bit in ltask descriptor so that we don't do this again
	    (must be cleared if pfile is unlearned)
end


# PFILEUPDATE -- Update a parameter set in the pfile from which it was
# originally read.

procedure pfileupdate (pfp)

begin
	if (fake pset or pset has not been modified)
	    return
	else if (pset is cl.par)
	    return

	call pfilewrite (pfp, pfp->pfilename)
end


# PFILEMERGE -- Merge the parameter values from the named pfile into the
# given parameter set.

procedure pfilemerge (pfp, pfile)

begin
	mark topd
	ofp = pfileread (pfile)

	for (each parameter in ofp) {
	    find associated parameter in pfp
	    if (param not found)
		warn user
	    else if (illegal datatype conversion)
		warn user
	    else
		set value of parameter in pfp version
	}

	restore topd
end


# PFILEREAD -- Allocate a pfile descriptor and read the named pfile into it.
# The input pfile may be either a parameter file or a CL procedure script.

pfp procedure pfileread (pfilename)

begin
	allocate pfile descriptor

	open pfile

	if (pfilename has a .cl extension)
	    parse pfile into pfile descriptor
	else
	    scan pfile into pfile descriptor

	close pfile
end


# PFILEWRITE -- Write the parameter set in the pfile descriptor to the
# named file.  Any existing file is overwritten.

procedure pfilewrite (pfp, pfilename)

begin
	if (pfilename does not have .par extension)
	    add or modify extension to .par

	delete old pfile
	disable interrupts

	open new pfile
	write parameters
	close pfile

	reenable interrupts
end


--------------
path procedure paramsrch (path, &param)

begin
	parse arg list

	# Get field name.
	if (argc > 1 && last arg is a p_field reference) {
	    map field name to field code
	    decrement arg count
	}

	# Get parameter name.
	if (argc < 1)
	    error
	else {
	    last arg is param name
	    decrement arg count
	}
	    
	if (no args left) {
	    search for the parameter via the usual param search path,
		i.e., task, package, cl.
	} else {
	    compose path to ltask
	    call ltasksrch to find task
	    readin pfile for task
	    search pfilelist for named parameter
	}

	return p_name field code
	return (pp)
end


ltask procedure ltasksrch (path)

begin
	parse arg list

	# Find defined task.
	search task list for first arg,
	    via circular search of the loaded packages
	while (arg is a package)
	    search pkg task list for next arg
	
	# Deal with pset task references.
	while (arg list is not exhausted) {
	    readin pfile for task
	    search pfilelist for next arg
	    if (param found and it is a pset parameter) {
		if (value is null)
		    search pkg list for task of the same name
		else if (value is a taskname)
		    search pkg list for named task
		else if (value is a pfilename) {
		    setup dummy ltask struct at topd
		    readin pfile, attach to ltask
		}
	    } else
		break
	}

	return (ltp pointer to ltask descriptor)
end