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.1 89/10/26 23:12:55 lwall Locked $
7 * $Log: evalargs.xc,v $
8 * Revision 3.0.1.1 89/10/26 23:12:55 lwall
9 * patch1: glob didn't free a temporary string
11 * Revision 3.0 89/10/18 15:17:16 lwall
16 for (anum = 1; anum <= maxarg; anum++) {
17 argflags = arg[anum].arg_flags;
18 argtype = arg[anum].arg_type;
19 argptr = arg[anum].arg_ptr;
23 st[++sp] = &str_undef;
32 deb("%d.EXPR =>\n",anum);
35 sp = eval(argptr.arg_arg,
36 (argflags & AF_ARYOK) ? G_ARRAY : G_SCALAR, sp);
37 if (sp + (maxarg - anum) > stack->ary_max)
38 astore(stack, sp + (maxarg - anum), Nullstr);
39 st = stack->ary_array; /* possibly reallocated */
45 deb("%d.CMD (%lx) =>\n",anum,argptr.arg_cmd);
48 sp = cmd_exec(argptr.arg_cmd, gimme, sp);
49 if (sp + (maxarg - anum) > stack->ary_max)
50 astore(stack, sp + (maxarg - anum), Nullstr);
51 st = stack->ary_array; /* possibly reallocated */
55 str = afetch(stab_array(argptr.arg_stab),
56 arg[anum].arg_len - arybase, TRUE);
59 (void)sprintf(buf,"LARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
66 st[++sp] = afetch(stab_array(argptr.arg_stab),
67 arg[anum].arg_len - arybase, FALSE);
72 (void)sprintf(buf,"ARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
79 st[++sp] = (STR*)argptr.arg_stab;
82 (void)sprintf(buf,"STAR *%s",stab_name(argptr.arg_stab));
88 str = st[++sp] = (STR*)argptr.arg_stab;
91 (void)sprintf(buf,"LSTAR *%s",stab_name(argptr.arg_stab));
97 st[++sp] = STAB_STR(argptr.arg_stab);
100 (void)sprintf(buf,"STAB $%s",stab_name(argptr.arg_stab));
109 deb("%d.LEXPR =>\n",anum);
112 if (argflags & AF_ARYOK) {
113 sp = eval(argptr.arg_arg, G_ARRAY, sp);
114 if (sp + (maxarg - anum) > stack->ary_max)
115 astore(stack, sp + (maxarg - anum), Nullstr);
116 st = stack->ary_array; /* possibly reallocated */
119 sp = eval(argptr.arg_arg, G_SCALAR, sp);
120 st = stack->ary_array; /* possibly reallocated */
128 (void)sprintf(buf,"LVAL $%s",stab_name(argptr.arg_stab));
133 str = STAB_STR(argptr.arg_stab);
135 fatal("panic: A_LVAL");
138 if (argflags & AF_PRE) {
139 if (argflags & AF_UP)
145 str = arg->arg_ptr.arg_str;
147 else if (argflags & AF_POST) {
148 st[sp] = str_static(str);
149 if (argflags & AF_UP)
154 str = arg->arg_ptr.arg_str;
161 stab = argptr.arg_stab;
162 str = stab_array(argptr.arg_stab)->ary_magic;
163 if (argflags & (AF_PRE|AF_POST))
164 str_numset(str,(double)(stab_array(stab)->ary_fill+arybase));
169 fatal("panic: A_LEXPR");
172 stab = argptr.arg_stab;
173 st[++sp] = stab_array(stab)->ary_magic;
174 str_numset(st[sp],(double)(stab_array(stab)->ary_fill+arybase));
180 st[++sp] = argptr.arg_str;
186 (void) interp(str,argptr.arg_str,sp);
187 st = stack->ary_array;
194 tmps = str_get(interp(str,argptr.arg_str,sp));
195 st = stack->ary_array;
197 taintproper("Insecure dependency in ``");
199 fp = mypopen(tmps,"r");
202 while (str_gets(str,fp,str->str_cur) != Nullch)
204 statusvalue = mypclose(fp);
216 extern int wantarray;
218 if (wantarray == G_ARRAY)
228 last_in_stab = stabent(str_get(STAB_STR(argptr.arg_stab)),TRUE);
229 old_record_separator = record_separator;
232 argflags |= AF_POST; /* enable newline chopping */
233 last_in_stab = argptr.arg_stab;
234 old_record_separator = record_separator;
236 record_separator = 0;
238 record_separator = '\n';
241 last_in_stab = argptr.arg_stab;
242 old_record_separator = record_separator;
244 if (anum > 1) /* assign to scalar */
245 gimme = G_SCALAR; /* force context to scalar */
248 if (stab_io(last_in_stab)) {
249 fp = stab_io(last_in_stab)->ifp;
251 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
252 if (stab_io(last_in_stab)->flags & IOF_START) {
253 stab_io(last_in_stab)->flags &= ~IOF_START;
254 stab_io(last_in_stab)->lines = 0;
255 if (alen(stab_array(last_in_stab)) < 0) {
256 tmpstr = str_make("-",1); /* assume stdin */
257 (void)apush(stab_array(last_in_stab), tmpstr);
260 fp = nextargv(last_in_stab);
261 if (!fp) /* Note: fp != stab_io(last_in_stab)->ifp */
262 (void)do_close(last_in_stab,FALSE); /* now it does*/
264 else if (argtype == A_GLOB) {
265 (void) interp(str,stab_val(last_in_stab),sp);
266 st = stack->ary_array;
267 tmpstr = Str_new(55,0);
269 str_set(tmpstr,"/bin/csh -cf 'set nonomatch; glob ");
270 str_scat(tmpstr,str);
271 str_cat(tmpstr,"'|");
274 str_set(tmpstr, "echo ");
275 str_scat(tmpstr,str);
277 "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
279 (void)do_open(last_in_stab,tmpstr->str_ptr);
280 fp = stab_io(last_in_stab)->ifp;
286 warn("Read on closed filehandle <%s>",stab_name(last_in_stab));
290 else if (!str_gets(str,fp, optype == O_RCAT ? str->str_cur : 0)) {
292 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
293 fp = nextargv(last_in_stab);
296 (void)do_close(last_in_stab,FALSE);
297 stab_io(last_in_stab)->flags |= IOF_START;
299 else if (argflags & AF_POST) {
300 (void)do_close(last_in_stab,FALSE);
303 record_separator = old_record_separator;
304 if (gimme == G_ARRAY) {
311 stab_io(last_in_stab)->lines++;
314 str->str_tainted = 1; /* Anything from the outside world...*/
316 if (argflags & AF_POST) {
317 if (str->str_cur > 0)
319 if (str->str_ptr[str->str_cur] == record_separator)
320 str->str_ptr[str->str_cur] = '\0';
323 for (tmps = str->str_ptr; *tmps; tmps++)
324 if (!isalpha(*tmps) && !isdigit(*tmps) &&
325 index("$&*(){}[]'\";\\|?<>~`",*tmps))
327 if (*tmps && stat(str->str_ptr,&statbuf) < 0)
328 goto keepgoing; /* unmatched wildcard? */
330 if (gimme == G_ARRAY) {
331 st[sp] = str_static(st[sp]);
332 if (++sp > stack->ary_max) {
333 astore(stack, sp, Nullstr);
334 st = stack->ary_array;
339 record_separator = old_record_separator;
347 deb("%d.%s = '%s'\n",anum,tmps,str_peek(st[sp]));