1 /* This file is included by eval.c. It's separate from eval.c to keep
2 * kit sizes from getting too big.
5 /* $Header: evalargs.xc,v 3.0 89/10/18 15:17:16 lwall Locked $
7 * $Log: evalargs.xc,v $
8 * Revision 3.0 89/10/18 15:17:16 lwall
13 for (anum = 1; anum <= maxarg; anum++) {
14 argflags = arg[anum].arg_flags;
15 argtype = arg[anum].arg_type;
16 argptr = arg[anum].arg_ptr;
20 st[++sp] = &str_undef;
29 deb("%d.EXPR =>\n",anum);
32 sp = eval(argptr.arg_arg,
33 (argflags & AF_ARYOK) ? G_ARRAY : G_SCALAR, sp);
34 if (sp + (maxarg - anum) > stack->ary_max)
35 astore(stack, sp + (maxarg - anum), Nullstr);
36 st = stack->ary_array; /* possibly reallocated */
42 deb("%d.CMD (%lx) =>\n",anum,argptr.arg_cmd);
45 sp = cmd_exec(argptr.arg_cmd, gimme, sp);
46 if (sp + (maxarg - anum) > stack->ary_max)
47 astore(stack, sp + (maxarg - anum), Nullstr);
48 st = stack->ary_array; /* possibly reallocated */
52 str = afetch(stab_array(argptr.arg_stab),
53 arg[anum].arg_len - arybase, TRUE);
56 (void)sprintf(buf,"LARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
63 st[++sp] = afetch(stab_array(argptr.arg_stab),
64 arg[anum].arg_len - arybase, FALSE);
69 (void)sprintf(buf,"ARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
76 st[++sp] = (STR*)argptr.arg_stab;
79 (void)sprintf(buf,"STAR *%s",stab_name(argptr.arg_stab));
85 str = st[++sp] = (STR*)argptr.arg_stab;
88 (void)sprintf(buf,"LSTAR *%s",stab_name(argptr.arg_stab));
94 st[++sp] = STAB_STR(argptr.arg_stab);
97 (void)sprintf(buf,"STAB $%s",stab_name(argptr.arg_stab));
106 deb("%d.LEXPR =>\n",anum);
109 if (argflags & AF_ARYOK) {
110 sp = eval(argptr.arg_arg, G_ARRAY, sp);
111 if (sp + (maxarg - anum) > stack->ary_max)
112 astore(stack, sp + (maxarg - anum), Nullstr);
113 st = stack->ary_array; /* possibly reallocated */
116 sp = eval(argptr.arg_arg, G_SCALAR, sp);
117 st = stack->ary_array; /* possibly reallocated */
125 (void)sprintf(buf,"LVAL $%s",stab_name(argptr.arg_stab));
130 str = STAB_STR(argptr.arg_stab);
132 fatal("panic: A_LVAL");
135 if (argflags & AF_PRE) {
136 if (argflags & AF_UP)
142 str = arg->arg_ptr.arg_str;
144 else if (argflags & AF_POST) {
145 st[sp] = str_static(str);
146 if (argflags & AF_UP)
151 str = arg->arg_ptr.arg_str;
158 stab = argptr.arg_stab;
159 str = stab_array(argptr.arg_stab)->ary_magic;
160 if (argflags & (AF_PRE|AF_POST))
161 str_numset(str,(double)(stab_array(stab)->ary_fill+arybase));
166 fatal("panic: A_LEXPR");
169 stab = argptr.arg_stab;
170 st[++sp] = stab_array(stab)->ary_magic;
171 str_numset(st[sp],(double)(stab_array(stab)->ary_fill+arybase));
177 st[++sp] = argptr.arg_str;
183 (void) interp(str,argptr.arg_str,sp);
184 st = stack->ary_array;
191 tmps = str_get(interp(str,argptr.arg_str,sp));
192 st = stack->ary_array;
194 taintproper("Insecure dependency in ``");
196 fp = mypopen(tmps,"r");
199 while (str_gets(str,fp,str->str_cur) != Nullch)
201 statusvalue = mypclose(fp);
213 extern int wantarray;
215 if (wantarray == G_ARRAY)
225 last_in_stab = stabent(str_get(STAB_STR(argptr.arg_stab)),TRUE);
226 old_record_separator = record_separator;
229 argflags |= AF_POST; /* enable newline chopping */
230 last_in_stab = argptr.arg_stab;
231 old_record_separator = record_separator;
233 record_separator = 0;
235 record_separator = '\n';
238 last_in_stab = argptr.arg_stab;
239 old_record_separator = record_separator;
241 if (anum > 1) /* assign to scalar */
242 gimme = G_SCALAR; /* force context to scalar */
245 if (stab_io(last_in_stab)) {
246 fp = stab_io(last_in_stab)->ifp;
248 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
249 if (stab_io(last_in_stab)->flags & IOF_START) {
250 stab_io(last_in_stab)->flags &= ~IOF_START;
251 stab_io(last_in_stab)->lines = 0;
252 if (alen(stab_array(last_in_stab)) < 0) {
253 tmpstr = str_make("-",1); /* assume stdin */
254 (void)apush(stab_array(last_in_stab), tmpstr);
257 fp = nextargv(last_in_stab);
258 if (!fp) /* Note: fp != stab_io(last_in_stab)->ifp */
259 (void)do_close(last_in_stab,FALSE); /* now it does*/
261 else if (argtype == A_GLOB) {
262 (void) interp(str,stab_val(last_in_stab),sp);
263 st = stack->ary_array;
264 tmpstr = Str_new(55,0);
266 str_set(tmpstr,"/bin/csh -cf 'set nonomatch; glob ");
267 str_scat(tmpstr,str);
268 str_cat(tmpstr,"'|");
271 str_set(tmpstr, "echo ");
272 str_scat(tmpstr,str);
274 "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
276 (void)do_open(last_in_stab,tmpstr->str_ptr);
277 fp = stab_io(last_in_stab)->ifp;
282 warn("Read on closed filehandle <%s>",stab_name(last_in_stab));
286 else if (!str_gets(str,fp, optype == O_RCAT ? str->str_cur : 0)) {
288 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
289 fp = nextargv(last_in_stab);
292 (void)do_close(last_in_stab,FALSE);
293 stab_io(last_in_stab)->flags |= IOF_START;
295 else if (argflags & AF_POST) {
296 (void)do_close(last_in_stab,FALSE);
299 record_separator = old_record_separator;
300 if (gimme == G_ARRAY) {
307 stab_io(last_in_stab)->lines++;
310 str->str_tainted = 1; /* Anything from the outside world...*/
312 if (argflags & AF_POST) {
313 if (str->str_cur > 0)
315 if (str->str_ptr[str->str_cur] == record_separator)
316 str->str_ptr[str->str_cur] = '\0';
319 for (tmps = str->str_ptr; *tmps; tmps++)
320 if (!isalpha(*tmps) && !isdigit(*tmps) &&
321 index("$&*(){}[]'\";\\|?<>~`",*tmps))
323 if (*tmps && stat(str->str_ptr,&statbuf) < 0)
324 goto keepgoing; /* unmatched wildcard? */
326 if (gimme == G_ARRAY) {
327 st[sp] = str_static(st[sp]);
328 if (++sp > stack->ary_max) {
329 astore(stack, sp, Nullstr);
330 st = stack->ary_array;
335 record_separator = old_record_separator;
343 deb("%d.%s = '%s'\n",anum,tmps,str_peek(st[sp]));