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.3 89/11/17 15:25:07 lwall Locked $
7 * $Log: evalargs.xc,v $
8 * Revision 3.0.1.3 89/11/17 15:25:07 lwall
9 * patch5: constant numeric subscripts disappeared in ?:
11 * Revision 3.0.1.2 89/11/11 04:33:05 lwall
12 * patch2: Configure now locates csh
14 * Revision 3.0.1.1 89/10/26 23:12:55 lwall
15 * patch1: glob didn't free a temporary string
17 * Revision 3.0 89/10/18 15:17:16 lwall
22 for (anum = 1; anum <= maxarg; anum++) {
23 argflags = arg[anum].arg_flags;
24 argtype = arg[anum].arg_type;
25 argptr = arg[anum].arg_ptr;
29 st[++sp] = &str_undef;
38 deb("%d.EXPR =>\n",anum);
41 sp = eval(argptr.arg_arg,
42 (argflags & AF_ARYOK) ? G_ARRAY : G_SCALAR, sp);
43 if (sp + (maxarg - anum) > stack->ary_max)
44 astore(stack, sp + (maxarg - anum), Nullstr);
45 st = stack->ary_array; /* possibly reallocated */
51 deb("%d.CMD (%lx) =>\n",anum,argptr.arg_cmd);
54 sp = cmd_exec(argptr.arg_cmd, gimme, sp);
55 if (sp + (maxarg - anum) > stack->ary_max)
56 astore(stack, sp + (maxarg - anum), Nullstr);
57 st = stack->ary_array; /* possibly reallocated */
62 case O_ITEM2: argtype = 2; break;
63 case O_ITEM3: argtype = 3; break;
64 default: argtype = anum; break;
66 str = afetch(stab_array(argptr.arg_stab),
67 arg[argtype].arg_len - arybase, TRUE);
70 (void)sprintf(buf,"LARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
71 arg[argtype].arg_len);
78 case O_ITEM2: argtype = 2; break;
79 case O_ITEM3: argtype = 3; break;
80 default: argtype = anum; break;
82 st[++sp] = afetch(stab_array(argptr.arg_stab),
83 arg[argtype].arg_len - arybase, FALSE);
88 (void)sprintf(buf,"ARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
89 arg[argtype].arg_len);
95 st[++sp] = (STR*)argptr.arg_stab;
98 (void)sprintf(buf,"STAR *%s",stab_name(argptr.arg_stab));
104 str = st[++sp] = (STR*)argptr.arg_stab;
107 (void)sprintf(buf,"LSTAR *%s",stab_name(argptr.arg_stab));
113 st[++sp] = STAB_STR(argptr.arg_stab);
116 (void)sprintf(buf,"STAB $%s",stab_name(argptr.arg_stab));
125 deb("%d.LEXPR =>\n",anum);
128 if (argflags & AF_ARYOK) {
129 sp = eval(argptr.arg_arg, G_ARRAY, sp);
130 if (sp + (maxarg - anum) > stack->ary_max)
131 astore(stack, sp + (maxarg - anum), Nullstr);
132 st = stack->ary_array; /* possibly reallocated */
135 sp = eval(argptr.arg_arg, G_SCALAR, sp);
136 st = stack->ary_array; /* possibly reallocated */
144 (void)sprintf(buf,"LVAL $%s",stab_name(argptr.arg_stab));
149 str = STAB_STR(argptr.arg_stab);
151 fatal("panic: A_LVAL");
154 if (argflags & AF_PRE) {
155 if (argflags & AF_UP)
161 str = arg->arg_ptr.arg_str;
163 else if (argflags & AF_POST) {
164 st[sp] = str_static(str);
165 if (argflags & AF_UP)
170 str = arg->arg_ptr.arg_str;
177 stab = argptr.arg_stab;
178 str = stab_array(argptr.arg_stab)->ary_magic;
179 if (argflags & (AF_PRE|AF_POST))
180 str_numset(str,(double)(stab_array(stab)->ary_fill+arybase));
185 fatal("panic: A_LEXPR");
188 stab = argptr.arg_stab;
189 st[++sp] = stab_array(stab)->ary_magic;
190 str_numset(st[sp],(double)(stab_array(stab)->ary_fill+arybase));
196 st[++sp] = argptr.arg_str;
202 (void) interp(str,argptr.arg_str,sp);
203 st = stack->ary_array;
210 tmps = str_get(interp(str,argptr.arg_str,sp));
211 st = stack->ary_array;
213 taintproper("Insecure dependency in ``");
215 fp = mypopen(tmps,"r");
218 while (str_gets(str,fp,str->str_cur) != Nullch)
220 statusvalue = mypclose(fp);
232 extern int wantarray;
234 if (wantarray == G_ARRAY)
244 last_in_stab = stabent(str_get(STAB_STR(argptr.arg_stab)),TRUE);
245 old_record_separator = record_separator;
248 argflags |= AF_POST; /* enable newline chopping */
249 last_in_stab = argptr.arg_stab;
250 old_record_separator = record_separator;
252 record_separator = 0;
254 record_separator = '\n';
258 last_in_stab = argptr.arg_stab;
259 old_record_separator = record_separator;
261 if (anum > 1) /* assign to scalar */
262 gimme = G_SCALAR; /* force context to scalar */
265 if (stab_io(last_in_stab)) {
266 fp = stab_io(last_in_stab)->ifp;
268 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
269 if (stab_io(last_in_stab)->flags & IOF_START) {
270 stab_io(last_in_stab)->flags &= ~IOF_START;
271 stab_io(last_in_stab)->lines = 0;
272 if (alen(stab_array(last_in_stab)) < 0) {
273 tmpstr = str_make("-",1); /* assume stdin */
274 (void)apush(stab_array(last_in_stab), tmpstr);
277 fp = nextargv(last_in_stab);
278 if (!fp) { /* Note: fp != stab_io(last_in_stab)->ifp */
279 (void)do_close(last_in_stab,FALSE); /* now it does*/
280 stab_io(last_in_stab)->flags |= IOF_START;
283 else if (argtype == A_GLOB) {
284 (void) interp(str,stab_val(last_in_stab),sp);
285 st = stack->ary_array;
286 tmpstr = Str_new(55,0);
288 str_nset(tmpstr,cshname,cshlen);
289 str_cat(tmpstr," -cf 'set nonomatch; glob ");
290 str_scat(tmpstr,str);
291 str_cat(tmpstr,"'|");
293 str_set(tmpstr, "echo ");
294 str_scat(tmpstr,str);
296 "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
298 (void)do_open(last_in_stab,tmpstr->str_ptr);
299 fp = stab_io(last_in_stab)->ifp;
305 warn("Read on closed filehandle <%s>",stab_name(last_in_stab));
309 else if (!str_gets(str,fp, optype == O_RCAT ? str->str_cur : 0)) {
311 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
312 fp = nextargv(last_in_stab);
315 (void)do_close(last_in_stab,FALSE);
316 stab_io(last_in_stab)->flags |= IOF_START;
318 else if (argflags & AF_POST) {
319 (void)do_close(last_in_stab,FALSE);
322 record_separator = old_record_separator;
323 if (gimme == G_ARRAY) {
330 stab_io(last_in_stab)->lines++;
333 str->str_tainted = 1; /* Anything from the outside world...*/
335 if (argflags & AF_POST) {
336 if (str->str_cur > 0)
338 if (str->str_ptr[str->str_cur] == record_separator)
339 str->str_ptr[str->str_cur] = '\0';
342 for (tmps = str->str_ptr; *tmps; tmps++)
343 if (!isalpha(*tmps) && !isdigit(*tmps) &&
344 index("$&*(){}[]'\";\\|?<>~`",*tmps))
346 if (*tmps && stat(str->str_ptr,&statbuf) < 0)
347 goto keepgoing; /* unmatched wildcard? */
349 if (gimme == G_ARRAY) {
350 st[sp] = str_static(st[sp]);
351 if (++sp > stack->ary_max) {
352 astore(stack, sp, Nullstr);
353 st = stack->ary_array;
358 record_separator = old_record_separator;
366 deb("%d.%s = '%s'\n",anum,tmps,str_peek(st[sp]));