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.1.4 90/02/28 17:38:37 lwall Locked $
7 * $Log: evalargs.xc,v $
8 * Revision 3.0.1.4 90/02/28 17:38:37 lwall
9 * patch9: $#foo -= 2 didn't work
11 * Revision 3.0.1.3 89/11/17 15:25:07 lwall
12 * patch5: constant numeric subscripts disappeared in ?:
14 * Revision 3.0.1.2 89/11/11 04:33:05 lwall
15 * patch2: Configure now locates csh
17 * Revision 3.0.1.1 89/10/26 23:12:55 lwall
18 * patch1: glob didn't free a temporary string
20 * Revision 3.0 89/10/18 15:17:16 lwall
25 for (anum = 1; anum <= maxarg; anum++) {
26 argflags = arg[anum].arg_flags;
27 argtype = arg[anum].arg_type;
28 argptr = arg[anum].arg_ptr;
32 st[++sp] = &str_undef;
41 deb("%d.EXPR =>\n",anum);
44 sp = eval(argptr.arg_arg,
45 (argflags & AF_ARYOK) ? G_ARRAY : G_SCALAR, sp);
46 if (sp + (maxarg - anum) > stack->ary_max)
47 astore(stack, sp + (maxarg - anum), Nullstr);
48 st = stack->ary_array; /* possibly reallocated */
54 deb("%d.CMD (%lx) =>\n",anum,argptr.arg_cmd);
57 sp = cmd_exec(argptr.arg_cmd, gimme, sp);
58 if (sp + (maxarg - anum) > stack->ary_max)
59 astore(stack, sp + (maxarg - anum), Nullstr);
60 st = stack->ary_array; /* possibly reallocated */
65 case O_ITEM2: argtype = 2; break;
66 case O_ITEM3: argtype = 3; break;
67 default: argtype = anum; break;
69 str = afetch(stab_array(argptr.arg_stab),
70 arg[argtype].arg_len - arybase, TRUE);
73 (void)sprintf(buf,"LARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
74 arg[argtype].arg_len);
81 case O_ITEM2: argtype = 2; break;
82 case O_ITEM3: argtype = 3; break;
83 default: argtype = anum; break;
85 st[++sp] = afetch(stab_array(argptr.arg_stab),
86 arg[argtype].arg_len - arybase, FALSE);
91 (void)sprintf(buf,"ARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
92 arg[argtype].arg_len);
98 st[++sp] = (STR*)argptr.arg_stab;
101 (void)sprintf(buf,"STAR *%s",stab_name(argptr.arg_stab));
107 str = st[++sp] = (STR*)argptr.arg_stab;
110 (void)sprintf(buf,"LSTAR *%s",stab_name(argptr.arg_stab));
116 st[++sp] = STAB_STR(argptr.arg_stab);
119 (void)sprintf(buf,"STAB $%s",stab_name(argptr.arg_stab));
128 deb("%d.LEXPR =>\n",anum);
131 if (argflags & AF_ARYOK) {
132 sp = eval(argptr.arg_arg, G_ARRAY, sp);
133 if (sp + (maxarg - anum) > stack->ary_max)
134 astore(stack, sp + (maxarg - anum), Nullstr);
135 st = stack->ary_array; /* possibly reallocated */
138 sp = eval(argptr.arg_arg, G_SCALAR, sp);
139 st = stack->ary_array; /* possibly reallocated */
147 (void)sprintf(buf,"LVAL $%s",stab_name(argptr.arg_stab));
152 str = STAB_STR(argptr.arg_stab);
154 fatal("panic: A_LVAL");
157 if (argflags & AF_PRE) {
158 if (argflags & AF_UP)
164 str = arg->arg_ptr.arg_str;
166 else if (argflags & AF_POST) {
167 st[sp] = str_static(str);
168 if (argflags & AF_UP)
173 str = arg->arg_ptr.arg_str;
180 stab = argptr.arg_stab;
181 str = stab_array(argptr.arg_stab)->ary_magic;
182 if (optype != O_SASSIGN || argflags & (AF_PRE|AF_POST))
183 str_numset(str,(double)(stab_array(stab)->ary_fill+arybase));
188 fatal("panic: A_LEXPR");
191 stab = argptr.arg_stab;
192 st[++sp] = stab_array(stab)->ary_magic;
193 str_numset(st[sp],(double)(stab_array(stab)->ary_fill+arybase));
199 st[++sp] = argptr.arg_str;
205 (void) interp(str,argptr.arg_str,sp);
206 st = stack->ary_array;
213 tmps = str_get(interp(str,argptr.arg_str,sp));
214 st = stack->ary_array;
216 taintproper("Insecure dependency in ``");
218 fp = mypopen(tmps,"r");
221 while (str_gets(str,fp,str->str_cur) != Nullch)
223 statusvalue = mypclose(fp);
235 if (wantarray == G_ARRAY)
245 last_in_stab = stabent(str_get(STAB_STR(argptr.arg_stab)),TRUE);
246 old_record_separator = record_separator;
249 argflags |= AF_POST; /* enable newline chopping */
250 last_in_stab = argptr.arg_stab;
251 old_record_separator = record_separator;
253 record_separator = 0;
255 record_separator = '\n';
259 last_in_stab = argptr.arg_stab;
260 old_record_separator = record_separator;
262 if (anum > 1) /* assign to scalar */
263 gimme = G_SCALAR; /* force context to scalar */
266 if (stab_io(last_in_stab)) {
267 fp = stab_io(last_in_stab)->ifp;
269 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
270 if (stab_io(last_in_stab)->flags & IOF_START) {
271 stab_io(last_in_stab)->flags &= ~IOF_START;
272 stab_io(last_in_stab)->lines = 0;
273 if (alen(stab_array(last_in_stab)) < 0) {
274 tmpstr = str_make("-",1); /* assume stdin */
275 (void)apush(stab_array(last_in_stab), tmpstr);
278 fp = nextargv(last_in_stab);
279 if (!fp) { /* Note: fp != stab_io(last_in_stab)->ifp */
280 (void)do_close(last_in_stab,FALSE); /* now it does*/
281 stab_io(last_in_stab)->flags |= IOF_START;
284 else if (argtype == A_GLOB) {
285 (void) interp(str,stab_val(last_in_stab),sp);
286 st = stack->ary_array;
287 tmpstr = Str_new(55,0);
289 str_nset(tmpstr,cshname,cshlen);
290 str_cat(tmpstr," -cf 'set nonomatch; glob ");
291 str_scat(tmpstr,str);
292 str_cat(tmpstr,"'|");
294 str_set(tmpstr, "echo ");
295 str_scat(tmpstr,str);
297 "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
299 (void)do_open(last_in_stab,tmpstr->str_ptr,
301 fp = stab_io(last_in_stab)->ifp;
307 warn("Read on closed filehandle <%s>",stab_name(last_in_stab));
311 else if (!str_gets(str,fp, optype == O_RCAT ? str->str_cur : 0)) {
313 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
314 fp = nextargv(last_in_stab);
317 (void)do_close(last_in_stab,FALSE);
318 stab_io(last_in_stab)->flags |= IOF_START;
320 else if (argflags & AF_POST) {
321 (void)do_close(last_in_stab,FALSE);
324 record_separator = old_record_separator;
325 if (gimme == G_ARRAY) {
332 stab_io(last_in_stab)->lines++;
335 str->str_tainted = 1; /* Anything from the outside world...*/
337 if (argflags & AF_POST) {
338 if (str->str_cur > 0)
340 if (str->str_ptr[str->str_cur] == record_separator)
341 str->str_ptr[str->str_cur] = '\0';
344 for (tmps = str->str_ptr; *tmps; tmps++)
345 if (!isalpha(*tmps) && !isdigit(*tmps) &&
346 index("$&*(){}[]'\";\\|?<>~`",*tmps))
348 if (*tmps && stat(str->str_ptr,&statbuf) < 0)
349 goto keepgoing; /* unmatched wildcard? */
351 if (gimme == G_ARRAY) {
352 st[sp] = str_static(st[sp]);
353 if (++sp > stack->ary_max) {
354 astore(stack, sp, Nullstr);
355 st = stack->ary_array;
360 record_separator = old_record_separator;
368 deb("%d.%s = '%s'\n",anum,tmps,str_peek(st[sp]));