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.2 89/11/11 04:33:05 lwall Locked $
7 * $Log: evalargs.xc,v $
8 * Revision 3.0.1.2 89/11/11 04:33:05 lwall
9 * patch2: Configure now locates csh
11 * Revision 3.0.1.1 89/10/26 23:12:55 lwall
12 * patch1: glob didn't free a temporary string
14 * Revision 3.0 89/10/18 15:17:16 lwall
19 for (anum = 1; anum <= maxarg; anum++) {
20 argflags = arg[anum].arg_flags;
21 argtype = arg[anum].arg_type;
22 argptr = arg[anum].arg_ptr;
26 st[++sp] = &str_undef;
35 deb("%d.EXPR =>\n",anum);
38 sp = eval(argptr.arg_arg,
39 (argflags & AF_ARYOK) ? G_ARRAY : G_SCALAR, sp);
40 if (sp + (maxarg - anum) > stack->ary_max)
41 astore(stack, sp + (maxarg - anum), Nullstr);
42 st = stack->ary_array; /* possibly reallocated */
48 deb("%d.CMD (%lx) =>\n",anum,argptr.arg_cmd);
51 sp = cmd_exec(argptr.arg_cmd, gimme, sp);
52 if (sp + (maxarg - anum) > stack->ary_max)
53 astore(stack, sp + (maxarg - anum), Nullstr);
54 st = stack->ary_array; /* possibly reallocated */
58 str = afetch(stab_array(argptr.arg_stab),
59 arg[anum].arg_len - arybase, TRUE);
62 (void)sprintf(buf,"LARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
69 st[++sp] = afetch(stab_array(argptr.arg_stab),
70 arg[anum].arg_len - arybase, FALSE);
75 (void)sprintf(buf,"ARYSTAB $%s[%d]",stab_name(argptr.arg_stab),
82 st[++sp] = (STR*)argptr.arg_stab;
85 (void)sprintf(buf,"STAR *%s",stab_name(argptr.arg_stab));
91 str = st[++sp] = (STR*)argptr.arg_stab;
94 (void)sprintf(buf,"LSTAR *%s",stab_name(argptr.arg_stab));
100 st[++sp] = STAB_STR(argptr.arg_stab);
103 (void)sprintf(buf,"STAB $%s",stab_name(argptr.arg_stab));
112 deb("%d.LEXPR =>\n",anum);
115 if (argflags & AF_ARYOK) {
116 sp = eval(argptr.arg_arg, G_ARRAY, sp);
117 if (sp + (maxarg - anum) > stack->ary_max)
118 astore(stack, sp + (maxarg - anum), Nullstr);
119 st = stack->ary_array; /* possibly reallocated */
122 sp = eval(argptr.arg_arg, G_SCALAR, sp);
123 st = stack->ary_array; /* possibly reallocated */
131 (void)sprintf(buf,"LVAL $%s",stab_name(argptr.arg_stab));
136 str = STAB_STR(argptr.arg_stab);
138 fatal("panic: A_LVAL");
141 if (argflags & AF_PRE) {
142 if (argflags & AF_UP)
148 str = arg->arg_ptr.arg_str;
150 else if (argflags & AF_POST) {
151 st[sp] = str_static(str);
152 if (argflags & AF_UP)
157 str = arg->arg_ptr.arg_str;
164 stab = argptr.arg_stab;
165 str = stab_array(argptr.arg_stab)->ary_magic;
166 if (argflags & (AF_PRE|AF_POST))
167 str_numset(str,(double)(stab_array(stab)->ary_fill+arybase));
172 fatal("panic: A_LEXPR");
175 stab = argptr.arg_stab;
176 st[++sp] = stab_array(stab)->ary_magic;
177 str_numset(st[sp],(double)(stab_array(stab)->ary_fill+arybase));
183 st[++sp] = argptr.arg_str;
189 (void) interp(str,argptr.arg_str,sp);
190 st = stack->ary_array;
197 tmps = str_get(interp(str,argptr.arg_str,sp));
198 st = stack->ary_array;
200 taintproper("Insecure dependency in ``");
202 fp = mypopen(tmps,"r");
205 while (str_gets(str,fp,str->str_cur) != Nullch)
207 statusvalue = mypclose(fp);
219 extern int wantarray;
221 if (wantarray == G_ARRAY)
231 last_in_stab = stabent(str_get(STAB_STR(argptr.arg_stab)),TRUE);
232 old_record_separator = record_separator;
235 argflags |= AF_POST; /* enable newline chopping */
236 last_in_stab = argptr.arg_stab;
237 old_record_separator = record_separator;
239 record_separator = 0;
241 record_separator = '\n';
245 last_in_stab = argptr.arg_stab;
246 old_record_separator = record_separator;
248 if (anum > 1) /* assign to scalar */
249 gimme = G_SCALAR; /* force context to scalar */
252 if (stab_io(last_in_stab)) {
253 fp = stab_io(last_in_stab)->ifp;
255 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
256 if (stab_io(last_in_stab)->flags & IOF_START) {
257 stab_io(last_in_stab)->flags &= ~IOF_START;
258 stab_io(last_in_stab)->lines = 0;
259 if (alen(stab_array(last_in_stab)) < 0) {
260 tmpstr = str_make("-",1); /* assume stdin */
261 (void)apush(stab_array(last_in_stab), tmpstr);
264 fp = nextargv(last_in_stab);
265 if (!fp) { /* Note: fp != stab_io(last_in_stab)->ifp */
266 (void)do_close(last_in_stab,FALSE); /* now it does*/
267 stab_io(last_in_stab)->flags |= IOF_START;
270 else if (argtype == A_GLOB) {
271 (void) interp(str,stab_val(last_in_stab),sp);
272 st = stack->ary_array;
273 tmpstr = Str_new(55,0);
275 str_nset(tmpstr,cshname,cshlen);
276 str_cat(tmpstr," -cf 'set nonomatch; glob ");
277 str_scat(tmpstr,str);
278 str_cat(tmpstr,"'|");
280 str_set(tmpstr, "echo ");
281 str_scat(tmpstr,str);
283 "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
285 (void)do_open(last_in_stab,tmpstr->str_ptr);
286 fp = stab_io(last_in_stab)->ifp;
292 warn("Read on closed filehandle <%s>",stab_name(last_in_stab));
296 else if (!str_gets(str,fp, optype == O_RCAT ? str->str_cur : 0)) {
298 if (stab_io(last_in_stab)->flags & IOF_ARGV) {
299 fp = nextargv(last_in_stab);
302 (void)do_close(last_in_stab,FALSE);
303 stab_io(last_in_stab)->flags |= IOF_START;
305 else if (argflags & AF_POST) {
306 (void)do_close(last_in_stab,FALSE);
309 record_separator = old_record_separator;
310 if (gimme == G_ARRAY) {
317 stab_io(last_in_stab)->lines++;
320 str->str_tainted = 1; /* Anything from the outside world...*/
322 if (argflags & AF_POST) {
323 if (str->str_cur > 0)
325 if (str->str_ptr[str->str_cur] == record_separator)
326 str->str_ptr[str->str_cur] = '\0';
329 for (tmps = str->str_ptr; *tmps; tmps++)
330 if (!isalpha(*tmps) && !isdigit(*tmps) &&
331 index("$&*(){}[]'\";\\|?<>~`",*tmps))
333 if (*tmps && stat(str->str_ptr,&statbuf) < 0)
334 goto keepgoing; /* unmatched wildcard? */
336 if (gimme == G_ARRAY) {
337 st[sp] = str_static(st[sp]);
338 if (++sp > stack->ary_max) {
339 astore(stack, sp, Nullstr);
340 st = stack->ary_array;
345 record_separator = old_record_separator;
353 deb("%d.%s = '%s'\n",anum,tmps,str_peek(st[sp]));