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 223 224 225 226 227 228 229 230 231 232
|
include <clset.h>
include <ctotok.h>
# SYSHOST -- If a task which calls this routine is executed from the host
# command line (i.e. not through a CL) set any parameters not set on the
# command line (e.g. with keyword=value or @file arguments). The application
# provides three files to search in order. The first two are keyword=value
# files and the last is a parameter file. The parameter file may be encoded
# as a compiled procedure (see txtcompile). For this reason xt_txtopen is
# used which transparently handles disk text files and text encoding
# procedures.
#
# The process type is the return value.
# The show_pset argument is the name of a boolean parameter to query
# for showing the default parameter set. The value of this is returned
# for show_val. If the parameter is not used (a null string) or was
# not specified by the user the return value is false.
int procedure syshost (keyfile1, keyfile2, parfile, show_pset, show_val)
char keyfile1[ARB] #I Keyword file
char keyfile2[ARB] #I Keyword file
char parfile[ARB] #I Parameter file
char show_pset[ARB] #I Parameter for requestiong show
bool show_val #O Result of show request
int stat #R Return value
char line[SZ_LINE], param[SZ_FNAME], value[SZ_LINE]
int i, ip, fd, tok
bool clgetb(), streq()
int clstati(), access(), fscan(), ctotok(), strncmp(), xt_txtopen()
pointer clc_find()
errchk xt_getpars, xt_txtopen
begin
# Check if the task is called from the host.
stat = clstati (CL_PRTYPE)
if (stat != PR_HOST)
return (stat)
# Read user keyword=value files.
if (keyfile1[1] != EOS && access(keyfile1,0,0) == YES)
call xt_getpars (keyfile1)
if (keyfile2[1] != EOS && access(keyfile2,0,0) == YES)
call xt_getpars (keyfile2)
# Read parameter file.
if (parfile[1] != EOS &&
(access(parfile,0,0)==YES || strncmp (parfile, "proc:", 5)==0)) {
# Open parameter file.
fd = NULL
fd = xt_txtopen (parfile)
# Check for request to show default parameters.
if (show_pset[1] != EOS && clc_find(show_pset,param,SZ_FNAME)>0)
show_val = clgetb (show_pset)
else
show_val = false
# Scan parameter file lines and parse them.
while (fscan (fd) != EOF) {
call gargstr (line, SZ_LINE)
ip = 1
if (ctotok (line, ip, param, SZ_FNAME) != TOK_IDENTIFIER)
next
if (streq (param, "mode"))
next
for (i=0; i<3 && ctotok(line,ip,value,SZ_LINE)!=TOK_EOS;) {
if (value[1] == ',')
i = i + 1
}
tok = ctotok (line, ip, value, SZ_LINE)
switch (tok) {
case TOK_NUMBER, TOK_STRING, TOK_IDENTIFIER:
;
default:
value[1] = EOS
}
# Enter in clcache if not already defined.
if (clc_find (param, line, SZ_LINE) == NULL)
call clc_enter (param, value)
# Show parameter if desired.
if (show_val) {
switch (tok) {
case TOK_STRING:
call printf ("%s = ""%s""\n")
call pargstr (param)
call pargstr (value)
default:
call printf ("%s = %s\n")
call pargstr (param)
call pargstr (value)
}
}
}
# Close parameter file.
call xt_txtclose (fd)
}
return (stat)
end
# The following are copies of sys_getpars and sys_paramset with the
# following changes.
# - Return an error rather than a warning for a bad syntax
# - Enter parameter in CL cache only if not previously set
include <ctype.h>
define SZ_VALSTR 1024
define SZ_CMDBUF (SZ_COMMAND+1024)
# XT_GETPARS -- Read a sequence of param=value parameter assignments from
# the named file and enter them into the CLIO cache for the task.
procedure xt_getpars (fname)
char fname # pset file
bool skip
int lineno, fd
pointer sp, lbuf, err, ip
int open(), getlline()
errchk open, getlline
begin
call smark (sp)
call salloc (lbuf, SZ_CMDBUF, TY_CHAR)
fd = open (fname, READ_ONLY, TEXT_FILE)
# Skip whitespace for param = value args in a par file.
skip = true
lineno = 0
while (getlline (fd, Memc[lbuf], SZ_CMDBUF) != EOF) {
lineno = lineno + 1
for (ip=lbuf; IS_WHITE (Memc[ip]); ip=ip+1)
;
if (Memc[ip] == '#' || Memc[ip] == '\n')
next
iferr (call xt_paramset (Memc, ip, skip)) {
for (; Memc[ip] != EOS && Memc[ip] != '\n'; ip=ip+1)
;
Memc[ip] = EOS
call salloc (err, SZ_LINE, TY_CHAR)
call sprintf (Memc[err], SZ_LINE,
"Bad param assignment, line %d: `%s'\n")
call pargi (lineno)
call pargstr (Memc[lbuf])
call close (fd)
call error (1, Memc[err])
}
}
call close (fd)
call sfree (sp)
end
# XT_PARAMSET -- Extract the param and value substrings from a param=value
# or switch argument and enter them into the CL parameter cache. (see also
# clio.clcache).
procedure xt_paramset (args, ip, skip)
char args[ARB] # argument list
int ip # pointer to first char of argument
bool skip # skip whitespace within "param=value" args
pointer sp, param, value, op, clc_find()
int stridx()
begin
call smark (sp)
call salloc (param, SZ_FNAME, TY_CHAR)
call salloc (value, SZ_VALSTR, TY_CHAR)
# Extract the param field.
op = param
while (IS_ALNUM (args[ip]) || stridx (args[ip], "_.$") > 0) {
Memc[op] = args[ip]
op = op + 1
ip = ip + 1
}
Memc[op] = EOS
# Advance to the switch character or assignment operator.
while (IS_WHITE (args[ip]))
ip = ip + 1
switch (args[ip]) {
case '+':
# Boolean switch "yes".
ip = ip + 1
call strcpy ("yes", Memc[value], SZ_VALSTR)
case '-':
# Boolean switch "no".
ip = ip + 1
call strcpy ("no", Memc[value], SZ_VALSTR)
case '=':
# Extract the value field. This is either a quoted string or a
# string delimited by any of the metacharacters listed below.
ip = ip + 1
if (skip) {
while (IS_WHITE (args[ip]))
ip = ip + 1
}
call sys_gstrarg (args, ip, Memc[value], SZ_VALSTR)
default:
call error (1, "IRAF Main: command syntax error")
}
# Enter the param=value pair into the CL parameter cache.
if (clc_find (Memc[param], Memc[param], SZ_FNAME) == NULL)
call clc_enter (Memc[param], Memc[value])
call sfree (sp)
end
|