1 /* $Header: eval.c,v 3.0.1.11 91/01/11 17:58:30 lwall Locked $
3 * Copyright (c) 1989, Larry Wall
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
9 * Revision 3.0.1.11 91/01/11 17:58:30 lwall
10 * patch42: ANSIfied the stat mode checking
11 * patch42: perl -D14 crashed on ..
12 * patch42: waitpid() emulation was useless because of #ifdef WAITPID
14 * Revision 3.0.1.10 90/11/10 01:33:22 lwall
15 * patch38: random cleanup
16 * patch38: couldn't return from sort routine
17 * patch38: added hooks for unexec()
18 * patch38: added alarm function
20 * Revision 3.0.1.9 90/10/15 16:46:13 lwall
21 * patch29: added caller
22 * patch29: added scalar
23 * patch29: added cmp and <=>
24 * patch29: added sysread and syswrite
25 * patch29: added -M, -A and -C
26 * patch29: index and substr now have optional 3rd args
27 * patch29: you can now read into the middle string
28 * patch29: ~ now works on vector string
29 * patch29: non-existent array values no longer cause core dumps
30 * patch29: eof; core dumped
31 * patch29: oct and hex now produce unsigned result
32 * patch29: unshift did not return the documented value
34 * Revision 3.0.1.8 90/08/13 22:17:14 lwall
35 * patch28: the NSIG hack didn't work right on Xenix
36 * patch28: defined(@array) and defined(%array) didn't work right
37 * patch28: rename was busted on systems without rename system call
39 * Revision 3.0.1.7 90/08/09 03:33:44 lwall
40 * patch19: made ~ do vector operation on strings like &, | and ^
41 * patch19: dbmopen(%name...) didn't work right
42 * patch19: dbmopen(name, 'filename', undef) now refrains from creating
43 * patch19: empty %array now returns 0 in scalar context
44 * patch19: die with no arguments no longer exits unconditionally
45 * patch19: return outside a subroutine now returns a reasonable message
46 * patch19: rename done with unlink()/link()/unlink() now checks for clobbering
47 * patch19: -s now returns size of file
49 * Revision 3.0.1.6 90/03/27 15:53:51 lwall
50 * patch16: MSDOS support
51 * patch16: support for machines that can't cast negative floats to unsigned ints
52 * patch16: ioctl didn't return values correctly
54 * Revision 3.0.1.5 90/03/12 16:37:40 lwall
55 * patch13: undef $/ didn't work as advertised
56 * patch13: added list slice operator (LIST)[LIST]
57 * patch13: added splice operator: @oldelems = splice(@array,$offset,$len,LIST)
59 * Revision 3.0.1.4 90/02/28 17:36:59 lwall
60 * patch9: added pipe function
61 * patch9: a return in scalar context wouldn't return array
62 * patch9: !~ now always returns scalar even in array context
63 * patch9: some machines can't cast float to long with high bit set
64 * patch9: piped opens returned undef in child
65 * patch9: @array in scalar context now returns length of array
66 * patch9: chdir; coredumped
67 * patch9: wait no longer ignores signals
68 * patch9: mkdir now handles odd versions of /bin/mkdir
69 * patch9: -l FILEHANDLE now disallowed
71 * Revision 3.0.1.3 89/12/21 20:03:05 lwall
72 * patch7: errno may now be a macro with an lvalue
73 * patch7: ANSI strerror() is now supported
74 * patch7: send() didn't allow a TO argument
75 * patch7: ord() now always returns positive even on signed char machines
77 * Revision 3.0.1.2 89/11/17 15:19:34 lwall
78 * patch5: constant numeric subscripts get lost inside ?:
80 * Revision 3.0.1.1 89/11/11 04:31:51 lwall
81 * patch2: mkdir and rmdir needed to quote argument when passed to shell
82 * patch2: mkdir and rmdir now return better error codes
83 * patch2: fileno, seekdir, rewinddir and closedir now disallow defaults
85 * Revision 3.0 89/10/18 15:17:04 lwall
93 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
105 static void (*ihand)();
106 static void (*qhand)();
108 static int (*ihand)();
109 static int (*qhand)();
116 static struct lstring *lstr;
117 static int old_record_separator;
119 double sin(), cos(), atan2(), pow();
140 int arglast[8]; /* highest sp for arg--valid only for non-O_LIST args */
141 unsigned long tmplong;
148 bool assigning = FALSE;
149 double exp(), log(), sqrt(), modf();
150 char *crypt(), *getenv();
151 extern void grow_dlevel();
155 optype = arg->arg_type;
156 maxarg = arg->arg_len;
158 str = arg->arg_ptr.arg_str;
159 if (sp + maxarg > stack->ary_max)
160 astore(stack, sp + maxarg, Nullstr);
161 st = stack->ary_array;
166 deb("%s (%lx) %d args:\n",opname[optype],arg,maxarg);
168 debname[dlevel] = opname[optype][0];
169 debdelim[dlevel] = ':';
170 if (++dlevel >= dlmax)
175 #include "evalargs.xc"
183 if (gimme == G_ARRAY)
191 if (gimme == G_ARRAY)
194 STR_SSET(str,st[arglast[anum]-arglast[0]]);
198 if (gimme == G_ARRAY)
201 STR_SSET(str,st[arglast[anum]-arglast[0]]);
211 anum = (int)str_gnum(st[2]);
213 tmpstr = Str_new(50, 0);
214 str_sset(tmpstr,str);
215 tmps = str_get(tmpstr); /* force to be string */
216 STR_GROW(str, (anum * str->str_cur) + 1);
217 repeatcpy(str->str_ptr, tmps, tmpstr->str_cur, anum);
218 str->str_cur *= anum;
219 str->str_ptr[str->str_cur] = '\0';
222 str_sset(str,&str_no);
226 sp = do_match(str,arg,
228 if (gimme == G_ARRAY)
233 sp = do_match(str,arg,
235 str_sset(str, str_true(str) ? &str_no : &str_yes);
239 sp = do_subst(str,arg,arglast[0]);
242 sp = do_subst(str,arg,arglast[0]);
243 str = arg->arg_ptr.arg_str;
244 str_set(str, str_true(str) ? No : Yes);
247 if (arg[1].arg_flags & AF_ARYOK) {
248 if (arg->arg_len == 1) {
249 arg->arg_type = O_LOCAL;
253 arg->arg_type = O_AASSIGN;
258 arg->arg_type = O_SASSIGN;
263 arglast[2] = arglast[1]; /* push a null array */
272 STR_SSET(str, st[2]);
277 str = arg->arg_ptr.arg_str;
278 for (sp = arglast[0] + 1; sp <= arglast[1]; sp++)
283 if (arg[1].arg_type & A_DONT) {
284 sp = do_defined(str,arg,
288 else if (str->str_pok || str->str_nok)
292 if (arg[1].arg_type & A_DONT) {
293 sp = do_undef(str,arg,
297 else if (str != stab_val(defstab)) {
298 str->str_pok = str->str_nok = 0;
303 sp = do_study(str,arg,
307 value = str_gnum(st[1]);
308 value = pow(value,str_gnum(st[2]));
311 value = str_gnum(st[1]);
312 value *= str_gnum(st[2]);
315 if ((value = str_gnum(st[2])) == 0.0)
316 fatal("Illegal division by zero");
317 value = str_gnum(st[1]) / value;
320 tmplong = (long) str_gnum(st[2]);
322 fatal("Illegal modulus zero");
323 when = (long)str_gnum(st[1]);
326 value = (double)(when % tmplong);
328 value = (double)(tmplong - ((-when - 1) % tmplong)) - 1;
332 value = str_gnum(st[1]);
333 value += str_gnum(st[2]);
336 value = str_gnum(st[1]);
337 value -= str_gnum(st[2]);
340 value = str_gnum(st[1]);
341 anum = (int)str_gnum(st[2]);
343 value = (double)(U_L(value) << anum);
347 value = str_gnum(st[1]);
348 anum = (int)str_gnum(st[2]);
350 value = (double)(U_L(value) >> anum);
354 value = str_gnum(st[1]);
355 value = (value < str_gnum(st[2])) ? 1.0 : 0.0;
358 value = str_gnum(st[1]);
359 value = (value > str_gnum(st[2])) ? 1.0 : 0.0;
362 value = str_gnum(st[1]);
363 value = (value <= str_gnum(st[2])) ? 1.0 : 0.0;
366 value = str_gnum(st[1]);
367 value = (value >= str_gnum(st[2])) ? 1.0 : 0.0;
371 if ((!st[1]->str_nok && !looks_like_number(st[1])) ||
372 (!st[2]->str_nok && !looks_like_number(st[2])) )
373 warn("Possible use of == on string value");
375 value = str_gnum(st[1]);
376 value = (value == str_gnum(st[2])) ? 1.0 : 0.0;
379 value = str_gnum(st[1]);
380 value = (value != str_gnum(st[2])) ? 1.0 : 0.0;
383 value = str_gnum(st[1]);
384 value -= str_gnum(st[2]);
387 else if (value < 0.0)
391 if (!sawvec || st[1]->str_nok || st[2]->str_nok) {
392 value = str_gnum(st[1]);
394 value = (double)(U_L(value) & U_L(str_gnum(st[2])));
399 do_vop(optype,str,st[1],st[2]);
402 if (!sawvec || st[1]->str_nok || st[2]->str_nok) {
403 value = str_gnum(st[1]);
405 value = (double)(U_L(value) ^ U_L(str_gnum(st[2])));
410 do_vop(optype,str,st[1],st[2]);
413 if (!sawvec || st[1]->str_nok || st[2]->str_nok) {
414 value = str_gnum(st[1]);
416 value = (double)(U_L(value) | U_L(str_gnum(st[2])));
421 do_vop(optype,str,st[1],st[2]);
423 /* use register in evaluating str_true() */
425 if (str_true(st[1])) {
428 argflags = arg[anum].arg_flags;
429 if (gimme == G_ARRAY)
430 argflags |= AF_ARYOK;
431 argtype = arg[anum].arg_type & A_MASK;
432 argptr = arg[anum].arg_ptr;
440 str_sset(str, st[1]);
448 if (str_true(st[1])) {
450 str_sset(str, st[1]);
460 argflags = arg[anum].arg_flags;
461 if (gimme == G_ARRAY)
462 argflags |= AF_ARYOK;
463 argtype = arg[anum].arg_type & A_MASK;
464 argptr = arg[anum].arg_ptr;
471 anum = (str_true(st[1]) ? 2 : 3);
472 optype = (anum == 2 ? O_ITEM2 : O_ITEM3);
473 argflags = arg[anum].arg_flags;
474 if (gimme == G_ARRAY)
475 argflags |= AF_ARYOK;
476 argtype = arg[anum].arg_type & A_MASK;
477 argptr = arg[anum].arg_ptr;
483 if (gimme == G_ARRAY)
488 value = -str_gnum(st[1]);
491 value = (double) !str_true(st[1]);
494 if (!sawvec || st[1]->str_nok) {
496 value = (double) ~U_L(str_gnum(st[1]));
503 for (anum = str->str_cur; anum; anum--, tmps++)
508 stab_fullname(str,defoutstab);
510 if ((arg[1].arg_type & A_MASK) == A_WORD)
511 defoutstab = arg[1].arg_ptr.arg_stab;
513 defoutstab = stabent(str_get(st[1]),TRUE);
514 if (!stab_io(defoutstab))
515 stab_io(defoutstab) = stio_new();
516 curoutstab = defoutstab;
523 else if ((arg[1].arg_type & A_MASK) == A_WORD) {
524 if (!(stab = arg[1].arg_ptr.arg_stab))
528 stab = stabent(str_get(st[1]),TRUE);
529 if (!stab_io(stab)) {
535 fp = stab_io(stab)->ofp;
537 if (stab_io(stab)->fmt_stab)
538 form = stab_form(stab_io(stab)->fmt_stab);
540 form = stab_form(stab);
544 warn("No format for filehandle");
546 if (stab_io(stab)->ifp)
547 warn("Filehandle only opened for input");
549 warn("Write on closed filehandle");
556 format(&outrec,form,sp);
557 do_write(&outrec,stab_io(stab),sp);
558 if (stab_io(stab)->flags & IOF_FLUSH)
565 stab = arg[1].arg_ptr.arg_stab;
566 if (st[3]->str_nok || st[3]->str_pok)
567 anum = (int)str_gnum(st[3]);
570 value = (double)hdbmopen(stab_hash(stab),str_get(st[2]),anum);
573 fatal("No dbm or ndbm on this machine");
577 stab = arg[1].arg_ptr.arg_stab;
578 hdbmclose(stab_hash(stab));
581 fatal("No dbm or ndbm on this machine");
584 if ((arg[1].arg_type & A_MASK) == A_WORD)
585 stab = arg[1].arg_ptr.arg_stab;
587 stab = stabent(str_get(st[1]),TRUE);
588 tmps = str_get(st[2]);
589 if (do_open(stab,tmps,st[2]->str_cur)) {
590 value = (double)forkprocess;
591 stab_io(stab)->lines = 0;
594 else if (forkprocess == 0) /* we are a new child */
600 value = (double) do_trans(str,arg);
601 str = arg->arg_ptr.arg_str;
604 str_set(arg->arg_ptr.arg_str, do_trans(str,arg) == 0 ? Yes : No);
605 str = arg->arg_ptr.arg_str;
610 else if ((arg[1].arg_type & A_MASK) == A_WORD)
611 stab = arg[1].arg_ptr.arg_stab;
613 stab = stabent(str_get(st[1]),TRUE);
614 str_set(str, do_close(stab,TRUE) ? Yes : No );
618 sp = do_each(str,stab_hash(arg[1].arg_ptr.arg_stab),
623 sp = do_kv(str,stab_hash(arg[1].arg_ptr.arg_stab), optype,
627 str->str_nok = str->str_pok = 0;
628 str->str_u.str_stab = arg[1].arg_ptr.arg_stab;
629 str->str_state = SS_ARY;
632 ary = stab_array(arg[1].arg_ptr.arg_stab);
633 maxarg = ary->ary_fill + 1;
634 if (gimme == G_ARRAY) { /* array wanted */
637 if (maxarg > 0 && sp + maxarg > stack->ary_max) {
638 astore(stack,sp + maxarg, Nullstr);
639 st = stack->ary_array;
642 Copy(ary->ary_array, &st[1], maxarg, STR*);
647 value = (double)maxarg;
651 anum = ((int)str_gnum(st[2])) - arybase;
652 str = afetch(stab_array(arg[1].arg_ptr.arg_stab),anum,FALSE);
655 tmpstab = arg[1].arg_ptr.arg_stab;
656 tmps = str_get(st[2]);
657 str = hdelete(stab_hash(tmpstab),tmps,st[2]->str_cur);
658 if (tmpstab == envstab)
664 str->str_nok = str->str_pok = 0;
665 str->str_u.str_stab = arg[1].arg_ptr.arg_stab;
666 str->str_state = SS_HASH;
669 if (gimme == G_ARRAY) { /* array wanted */
670 sp = do_kv(str,stab_hash(arg[1].arg_ptr.arg_stab), optype,
675 tmpstab = arg[1].arg_ptr.arg_stab;
676 if (!stab_hash(tmpstab)->tbl_fill)
678 sprintf(buf,"%d/%d",stab_hash(tmpstab)->tbl_fill,
679 stab_hash(tmpstab)->tbl_max+1);
684 tmpstab = arg[1].arg_ptr.arg_stab;
685 tmps = str_get(st[2]);
686 str = hfetch(stab_hash(tmpstab),tmps,st[2]->str_cur,FALSE);
689 anum = ((int)str_gnum(st[2])) - arybase;
690 str = afetch(stab_array(arg[1].arg_ptr.arg_stab),anum,TRUE);
691 if (!str || str == &str_undef)
692 fatal("Assignment to non-creatable value, subscript %d",anum);
695 tmpstab = arg[1].arg_ptr.arg_stab;
696 tmps = str_get(st[2]);
697 anum = st[2]->str_cur;
698 str = hfetch(stab_hash(tmpstab),tmps,anum,TRUE);
699 if (!str || str == &str_undef)
700 fatal("Assignment to non-creatable value, subscript \"%s\"",tmps);
701 if (tmpstab == envstab) /* heavy wizardry going on here */
702 str_magic(str, tmpstab, 'E', tmps, anum); /* str is now magic */
703 /* he threw the brick up into the air */
704 else if (tmpstab == sigstab)
705 str_magic(str, tmpstab, 'S', tmps, anum);
707 else if (stab_hash(tmpstab)->tbl_dbm)
708 str_magic(str, tmpstab, 'D', tmps, anum);
710 else if (perldb && tmpstab == DBline)
711 str_magic(str, tmpstab, 'L', tmps, anum);
716 goto do_slice_already;
720 goto do_slice_already;
724 goto do_slice_already;
728 goto do_slice_already;
733 sp = do_slice(arg[1].arg_ptr.arg_stab,str,anum,argtype,
737 sp = do_splice(stab_array(arg[1].arg_ptr.arg_stab),gimme,arglast);
740 if (arglast[2] - arglast[1] != 1)
741 str = do_push(stab_array(arg[1].arg_ptr.arg_stab),arglast);
743 str = Str_new(51,0); /* must copy the STR */
745 (void)apush(stab_array(arg[1].arg_ptr.arg_stab),str);
749 str = apop(ary = stab_array(arg[1].arg_ptr.arg_stab));
750 goto staticalization;
752 str = ashift(ary = stab_array(arg[1].arg_ptr.arg_stab));
756 if (ary->ary_flags & ARF_REAL)
757 (void)str_2static(str);
760 sp = do_unpack(str,gimme,arglast);
763 value = str_gnum(st[3]);
764 sp = do_split(str, arg[2].arg_ptr.arg_spat, (int)value,
769 value = (double)str_len(stab_val(defstab));
771 value = (double)str_len(st[1]);
774 do_sprintf(str, sp-arglast[0], st+1);
777 anum = ((int)str_gnum(st[2])) - arybase; /* anum=where to start*/
778 tmps = str_get(st[1]); /* force conversion to string */
779 if (argtype = (str == st[1]))
780 str = arg->arg_ptr.arg_str;
782 anum += st[1]->str_cur + arybase;
783 if (anum < 0 || anum > st[1]->str_cur)
786 optype = maxarg < 3 ? st[1]->str_cur : (int)str_gnum(st[3]);
790 anum = st[1]->str_cur - anum; /* anum=how many bytes left*/
793 str_nset(str, tmps, anum);
794 if (argtype) { /* it's an lvalue! */
795 lstr = (struct lstring*)str;
796 str->str_magic = st[1];
797 st[1]->str_rare = 's';
798 lstr->lstr_offset = tmps - str_get(st[1]);
799 lstr->lstr_len = anum;
804 (void)do_pack(str,arglast);
807 sp = do_grep(arg,str,gimme,arglast);
810 do_join(str,arglast);
813 tmps = str_get(st[1]);
814 value = (double) (str_cmp(st[1],st[2]) < 0);
817 tmps = str_get(st[1]);
818 value = (double) (str_cmp(st[1],st[2]) > 0);
821 tmps = str_get(st[1]);
822 value = (double) (str_cmp(st[1],st[2]) <= 0);
825 tmps = str_get(st[1]);
826 value = (double) (str_cmp(st[1],st[2]) >= 0);
829 tmps = str_get(st[1]);
830 value = (double) str_eq(st[1],st[2]);
833 tmps = str_get(st[1]);
834 value = (double) !str_eq(st[1],st[2]);
837 tmps = str_get(st[1]);
838 value = (double) str_cmp(st[1],st[2]);
841 sp = do_subr(arg,gimme,arglast);
842 st = stack->ary_array + arglast[0]; /* maybe realloced */
845 sp = do_subr(arg,gimme,arglast);
846 st = stack->ary_array + arglast[0]; /* maybe realloced */
849 sp = do_caller(arg,maxarg,gimme,arglast);
850 st = stack->ary_array + arglast[0]; /* maybe realloced */
853 if ((arg[1].arg_type & A_MASK) == A_WORD)
854 stab = arg[1].arg_ptr.arg_stab;
856 stab = stabent(str_get(st[1]),TRUE);
857 sp = do_sort(str,stab,
861 if (gimme == G_ARRAY)
862 sp = do_reverse(arglast);
864 sp = do_sreverse(str, arglast);
867 if (arglast[2] - arglast[1] != 1) {
868 do_join(str,arglast);
869 tmps = str_get(st[1]);
873 tmps = str_get(st[2]);
876 tmps = "Warning: something's wrong";
880 if (arglast[2] - arglast[1] != 1) {
881 do_join(str,arglast);
882 tmps = str_get(st[1]);
886 tmps = str_get(st[2]);
894 if ((arg[1].arg_type & A_MASK) == A_WORD)
895 stab = arg[1].arg_ptr.arg_stab;
897 stab = stabent(str_get(st[1]),TRUE);
900 if (!stab_io(stab)) {
902 warn("Filehandle never opened");
905 if (!(fp = stab_io(stab)->ofp)) {
907 if (stab_io(stab)->ifp)
908 warn("Filehandle opened only for input");
910 warn("Print on closed filehandle");
915 if (optype == O_PRTF || arglast[2] - arglast[1] != 1)
916 value = (double)do_aprint(arg,fp,arglast);
918 value = (double)do_print(st[2],fp);
919 if (orslen && optype == O_PRINT)
920 if (fwrite(ors, 1, orslen, fp) == 0)
923 if (stab_io(stab)->flags & IOF_FLUSH)
924 if (fflush(fp) == EOF)
932 tmps = str_get(st[1]);
933 if (!tmps || !*tmps) {
934 tmpstr = hfetch(stab_hash(envstab),"HOME",4,FALSE);
935 tmps = str_get(tmpstr);
937 if (!tmps || !*tmps) {
938 tmpstr = hfetch(stab_hash(envstab),"LOGDIR",6,FALSE);
939 tmps = str_get(tmpstr);
942 taintproper("Insecure dependency in chdir");
944 value = (double)(chdir(tmps) >= 0);
950 anum = (int)str_gnum(st[1]);
957 tmps = str_get(st[1]);
958 str_reset(tmps,curcmd->c_stash);
962 if (gimme == G_ARRAY)
965 str = st[sp - arglast[0]]; /* unwanted list, return last item */
972 else if ((arg[1].arg_type & A_MASK) == A_WORD)
973 stab = arg[1].arg_ptr.arg_stab;
975 stab = stabent(str_get(st[1]),TRUE);
976 str_set(str, do_eof(stab) ? Yes : No);
982 else if ((arg[1].arg_type & A_MASK) == A_WORD)
983 stab = arg[1].arg_ptr.arg_stab;
985 stab = stabent(str_get(st[1]),TRUE);
988 if (!stab || do_eof(stab)) /* make sure we have fp with something */
995 *str->str_ptr = getc(stab_io(stab)->ifp); /* should never be EOF */
1001 stab = last_in_stab;
1002 else if ((arg[1].arg_type & A_MASK) == A_WORD)
1003 stab = arg[1].arg_ptr.arg_stab;
1005 stab = stabent(str_get(st[1]),TRUE);
1007 value = (double)do_tell(stab);
1009 (void)do_tell(stab);
1015 if ((arg[1].arg_type & A_MASK) == A_WORD)
1016 stab = arg[1].arg_ptr.arg_stab;
1018 stab = stabent(str_get(st[1]),TRUE);
1019 tmps = str_get(st[2]);
1020 anum = (int)str_gnum(st[3]);
1022 maxarg = sp - arglast[0];
1024 warn("Too many args on read");
1026 maxarg = (int)str_gnum(st[4]);
1029 if (!stab_io(stab) || !stab_io(stab)->ifp)
1032 if (optype == O_RECV) {
1033 argtype = sizeof buf;
1034 anum = recvfrom(fileno(stab_io(stab)->ifp), tmps, anum, maxarg,
1037 st[2]->str_cur = anum;
1038 st[2]->str_ptr[anum] = '\0';
1039 str_nset(str,buf,argtype);
1042 str_sset(str,&str_undef);
1046 if (optype == O_RECV)
1049 STR_GROW(st[2], anum+maxarg+1), (tmps = str_get(st[2])); /* sneaky */
1051 if (stab_io(stab)->type == 's') {
1052 argtype = sizeof buf;
1053 anum = recvfrom(fileno(stab_io(stab)->ifp), tmps+maxarg, anum, 0,
1058 if (optype == O_SYSREAD) {
1059 anum = read(fileno(stab_io(stab)->ifp), tmps+maxarg, anum);
1062 anum = fread(tmps+maxarg, 1, anum, stab_io(stab)->ifp);
1065 st[2]->str_cur = anum+maxarg;
1066 st[2]->str_ptr[anum+maxarg] = '\0';
1067 value = (double)anum;
1071 if ((arg[1].arg_type & A_MASK) == A_WORD)
1072 stab = arg[1].arg_ptr.arg_stab;
1074 stab = stabent(str_get(st[1]),TRUE);
1075 tmps = str_get(st[2]);
1076 anum = (int)str_gnum(st[3]);
1078 stio = stab_io(stab);
1079 maxarg = sp - arglast[0];
1080 if (!stio || !stio->ifp) {
1083 if (optype == O_SYSWRITE)
1084 warn("Syswrite on closed filehandle");
1086 warn("Send on closed socket");
1089 else if (optype == O_SYSWRITE) {
1091 warn("Too many args on syswrite");
1093 optype = (int)str_gnum(st[4]);
1096 anum = write(fileno(stab_io(stab)->ifp), tmps+optype, anum);
1099 else if (maxarg >= 4) {
1101 warn("Too many args on send");
1102 tmps2 = str_get(st[4]);
1103 anum = sendto(fileno(stab_io(stab)->ifp), tmps, st[2]->str_cur,
1104 anum, tmps2, st[4]->str_cur);
1107 anum = send(fileno(stab_io(stab)->ifp), tmps, st[2]->str_cur, anum);
1114 value = (double)anum;
1117 if ((arg[1].arg_type & A_MASK) == A_WORD)
1118 stab = arg[1].arg_ptr.arg_stab;
1120 stab = stabent(str_get(st[1]),TRUE);
1121 value = str_gnum(st[2]);
1122 str_set(str, do_seek(stab,
1123 (long)value, (int)str_gnum(st[3]) ) ? Yes : No);
1127 tmps = "_SUB_"; /* just fake up a "last _SUB_" */
1129 if (curcsv && curcsv->wantarray == G_ARRAY) {
1130 lastretstr = Nullstr;
1131 lastspbase = arglast[1];
1132 lastsize = arglast[2] - arglast[1];
1135 lastretstr = str_static(st[arglast[2] - arglast[0]]);
1141 tmps = str_get(arg[1].arg_ptr.arg_str);
1143 while (loop_ptr >= 0 && (!loop_stack[loop_ptr].loop_label ||
1144 strNE(tmps,loop_stack[loop_ptr].loop_label) )) {
1147 deb("(Skipping label #%d %s)\n",loop_ptr,
1148 loop_stack[loop_ptr].loop_label);
1155 deb("(Found label #%d %s)\n",loop_ptr,
1156 loop_stack[loop_ptr].loop_label);
1161 if (tmps && strEQ(tmps, "_SUB_"))
1162 fatal("Can't return outside a subroutine");
1163 fatal("Bad label: %s", maxarg > 0 ? tmps : "<null>");
1165 if (!lastretstr && optype == O_LAST && lastsize) {
1167 st += lastspbase + 1;
1168 optype = loop_stack[loop_ptr].loop_sp - lastspbase; /* negative */
1170 for (anum = lastsize; anum > 0; anum--,st++)
1171 st[optype] = str_static(st[0]);
1173 longjmp(loop_stack[loop_ptr].loop_env, O_LAST);
1175 longjmp(loop_stack[loop_ptr].loop_env, optype);
1177 case O_GOTO:/* shudder */
1178 goto_targ = str_get(arg[1].arg_ptr.arg_str);
1180 goto_targ = Nullch; /* just restart from top */
1181 if (optype == O_DUMP) {
1185 longjmp(top_env, 1);
1187 tmps = str_get(st[1]);
1191 anum = (int) str_gnum(st[3]) - arybase;
1194 else if (anum > st[1]->str_cur)
1195 anum = st[1]->str_cur;
1198 if (!(tmps2 = fbminstr((unsigned char*)tmps + anum,
1199 (unsigned char*)tmps + st[1]->str_cur, st[2])))
1201 if (tmps2 = fbminstr(Null(unsigned char*),Null(unsigned char*),Nullstr))
1203 value = (double)(-1 + arybase);
1205 value = (double)(tmps2 - tmps + arybase);
1208 tmps = str_get(st[1]);
1209 tmps2 = str_get(st[2]);
1211 anum = st[1]->str_cur;
1213 anum = (int) str_gnum(st[3]) - arybase + st[2]->str_cur;
1216 else if (anum > st[1]->str_cur)
1217 anum = st[1]->str_cur;
1220 if (!(tmps2 = rninstr(tmps, tmps + anum,
1221 tmps2, tmps2 + st[2]->str_cur)))
1223 if (tmps2 = rninstr(Nullch,Nullch,Nullch,Nullch))
1225 value = (double)(-1 + arybase);
1227 value = (double)(tmps2 - tmps + arybase);
1231 value = (double) time(Null(long*));
1235 sp = do_tms(str,gimme,arglast);
1241 when = (long)str_gnum(st[1]);
1242 sp = do_time(str,localtime(&when),
1249 when = (long)str_gnum(st[1]);
1250 sp = do_time(str,gmtime(&when),
1254 sp = do_truncate(str,arg,
1259 sp = do_stat(str,arg,
1264 tmps = str_get(st[1]);
1266 str_set(str,fcrypt(tmps,str_get(st[2])));
1268 str_set(str,crypt(tmps,str_get(st[2])));
1272 "The crypt() function is unimplemented due to excessive paranoia.");
1276 value = str_gnum(st[1]);
1277 value = atan2(value,str_gnum(st[2]));
1281 value = str_gnum(stab_val(defstab));
1283 value = str_gnum(st[1]);
1288 value = str_gnum(stab_val(defstab));
1290 value = str_gnum(st[1]);
1297 value = str_gnum(st[1]);
1301 value = rand() * value / 2147483648.0;
1304 value = rand() * value / 65536.0;
1307 value = rand() * value / 32768.0;
1309 value = rand() * value / (double)(((unsigned long)1) << RANDBITS);
1320 anum = (int)str_gnum(st[1]);
1325 value = str_gnum(stab_val(defstab));
1327 value = str_gnum(st[1]);
1332 value = str_gnum(stab_val(defstab));
1334 value = str_gnum(st[1]);
1339 value = str_gnum(stab_val(defstab));
1341 value = str_gnum(st[1]);
1342 value = sqrt(value);
1346 value = str_gnum(stab_val(defstab));
1348 value = str_gnum(st[1]);
1350 (void)modf(value,&value);
1352 (void)modf(-value,&value);
1358 tmps = str_get(stab_val(defstab));
1360 tmps = str_get(st[1]);
1362 value = (double) (*tmps & 255);
1365 value = (double) (anum & 255);
1370 tmps = str_get(stab_val(defstab));
1372 tmps = str_get(st[1]);
1375 anum = alarm((unsigned int)atoi(tmps));
1378 value = (double)anum;
1384 tmps = str_get(st[1]);
1386 if (!tmps || !*tmps)
1387 sleep((32767<<16)+32767);
1389 sleep((unsigned int)atoi(tmps));
1391 value = (double)when;
1393 value = ((double)when) - value;
1397 sp = do_range(gimme,arglast);
1400 if (gimme == G_ARRAY) { /* it's a range */
1401 /* can we optimize to constant array? */
1402 if ((arg[1].arg_type & A_MASK) == A_SINGLE &&
1403 (arg[2].arg_type & A_MASK) == A_SINGLE) {
1404 st[2] = arg[2].arg_ptr.arg_str;
1405 sp = do_range(gimme,arglast);
1406 st = stack->ary_array;
1407 maxarg = sp - arglast[0];
1408 str_free(arg[1].arg_ptr.arg_str);
1409 str_free(arg[2].arg_ptr.arg_str);
1410 arg->arg_type = O_ARRAY;
1411 arg[1].arg_type = A_STAB|A_DONT;
1413 stab = arg[1].arg_ptr.arg_stab = aadd(genstab());
1414 ary = stab_array(stab);
1415 afill(ary,maxarg - 1);
1418 while (maxarg-- > 0)
1419 ary->ary_array[maxarg] = str_smake(st[maxarg]);
1423 arg->arg_type = optype = O_RANGE;
1424 maxarg = arg->arg_len = 2;
1426 arg[anum].arg_flags &= ~AF_ARYOK;
1427 argflags = arg[anum].arg_flags;
1428 argtype = arg[anum].arg_type & A_MASK;
1429 arg[anum].arg_type = argtype;
1430 argptr = arg[anum].arg_ptr;
1436 arg->arg_type = O_FLIP;
1439 if ((arg[1].arg_type & A_MASK) == A_SINGLE ?
1440 last_in_stab && (int)str_gnum(st[1]) == stab_io(last_in_stab)->lines
1443 str_numset(str,0.0);
1445 arg->arg_type = optype = O_FLOP;
1446 arg[2].arg_type &= ~A_DONT;
1447 arg[1].arg_type |= A_DONT;
1448 argflags = arg[2].arg_flags;
1449 argtype = arg[2].arg_type & A_MASK;
1450 argptr = arg[2].arg_ptr;
1459 if ((arg[2].arg_type & A_MASK) == A_SINGLE ?
1460 last_in_stab && (int)str_gnum(st[2]) == stab_io(last_in_stab)->lines
1463 arg->arg_type = O_FLIP;
1464 arg[1].arg_type &= ~A_DONT;
1465 arg[2].arg_type |= A_DONT;
1473 if (tmpstab = stabent("$",allstabs))
1474 str_numset(STAB_STR(tmpstab),(double)getpid());
1475 hclear(pidstatus); /* no kids, so don't wait for 'em */
1477 value = (double)anum;
1480 fatal("Unsupported function fork");
1486 anum = wait(&argflags);
1488 pidgone(anum,argflags);
1489 value = (double)anum;
1491 statusvalue = (unsigned short)argflags;
1494 fatal("Unsupported function wait");
1500 anum = (int)str_gnum(st[1]);
1501 optype = (int)str_gnum(st[2]);
1502 anum = wait4pid(anum, &argflags,optype);
1503 value = (double)anum;
1505 statusvalue = (unsigned short)argflags;
1508 fatal("Unsupported function wait");
1514 if (arglast[2] - arglast[1] == 1) {
1516 tainted |= st[2]->str_tainted;
1517 taintproper("Insecure dependency in system");
1520 while ((anum = vfork()) == -1) {
1521 if (errno != EAGAIN) {
1529 ihand = signal(SIGINT, SIG_IGN);
1530 qhand = signal(SIGQUIT, SIG_IGN);
1531 argtype = wait4pid(anum, &argflags, 0);
1535 (void)signal(SIGINT, ihand);
1536 (void)signal(SIGQUIT, qhand);
1537 statusvalue = (unsigned short)argflags;
1541 value = (double)((unsigned int)argflags & 0xffff);
1543 do_execfree(); /* free any memory child malloced on vfork */
1546 if ((arg[1].arg_type & A_MASK) == A_STAB)
1547 value = (double)do_aexec(st[1],arglast);
1548 else if (arglast[2] - arglast[1] != 1)
1549 value = (double)do_aexec(Nullstr,arglast);
1551 value = (double)do_exec(str_get(str_static(st[2])));
1555 if ((arg[1].arg_type & A_MASK) == A_STAB)
1556 value = (double)do_aspawn(st[1],arglast);
1557 else if (arglast[2] - arglast[1] != 1)
1558 value = (double)do_aspawn(Nullstr,arglast);
1560 value = (double)do_spawn(str_get(str_static(st[2])));
1565 if ((arg[1].arg_type & A_MASK) == A_STAB)
1566 value = (double)do_aexec(st[1],arglast);
1567 else if (arglast[2] - arglast[1] != 1)
1568 value = (double)do_aexec(Nullstr,arglast);
1570 value = (double)do_exec(str_get(str_static(st[2])));
1583 tmps = str_get(stab_val(defstab));
1585 tmps = str_get(st[1]);
1594 case '0': case '1': case '2': case '3': case '4':
1595 case '5': case '6': case '7':
1596 tmplong <<= argtype;
1597 tmplong += *tmps++ & 15;
1599 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
1600 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
1604 tmplong += (*tmps++ & 7) + 9;
1613 value = (double)tmplong;
1617 value = (double)apply(optype,arglast);
1620 fatal("Unsupported function chown");
1625 value = (double)apply(optype,arglast);
1628 fatal("Unsupported function kill");
1634 value = (double)apply(optype,arglast);
1643 anum = umask((int)str_gnum(st[1]));
1644 value = (double)anum;
1646 taintproper("Insecure dependency in umask");
1650 fatal("Unsupported function umask");
1657 if ((anum = do_ipcget(optype, arglast)) == -1)
1659 value = (double)anum;
1664 anum = do_ipcctl(optype, arglast);
1668 value = (double)anum;
1671 str_set(str,"0 but true");
1675 value = (double)(do_msgsnd(arglast) >= 0);
1678 value = (double)(do_msgrcv(arglast) >= 0);
1681 value = (double)(do_semop(arglast) >= 0);
1685 value = (double)(do_shmio(optype, arglast) >= 0);
1687 #else /* not SYSVIPC */
1699 fatal("System V IPC is not implemented on this machine");
1700 #endif /* not SYSVIPC */
1702 tmps = str_get(st[1]);
1703 tmps2 = str_get(st[2]);
1705 taintproper("Insecure dependency in rename");
1708 value = (double)(rename(tmps,tmps2) >= 0);
1710 if (same_dirent(tmps2, tmps)) /* can always rename to same name */
1713 if (euid || stat(tmps2,&statbuf) < 0 || !S_ISDIR(statbuf.st_mode))
1714 (void)UNLINK(tmps2);
1715 if (!(anum = link(tmps,tmps2)))
1716 anum = UNLINK(tmps);
1718 value = (double)(anum >= 0);
1723 tmps = str_get(st[1]);
1724 tmps2 = str_get(st[2]);
1726 taintproper("Insecure dependency in link");
1728 value = (double)(link(tmps,tmps2) >= 0);
1731 fatal("Unsupported function link");
1735 tmps = str_get(st[1]);
1736 anum = (int)str_gnum(st[2]);
1738 taintproper("Insecure dependency in mkdir");
1741 value = (double)(mkdir(tmps,anum) >= 0);
1744 (void)strcpy(buf,"mkdir ");
1746 #if !defined(MKDIR) || !defined(RMDIR)
1748 for (tmps2 = buf+6; *tmps; ) {
1752 (void)strcpy(tmps2," 2>&1");
1753 rsfp = mypopen(buf,"r");
1756 tmps2 = fgets(buf,sizeof buf,rsfp);
1757 (void)mypclose(rsfp);
1758 if (tmps2 != Nullch) {
1759 for (errno = 1; errno < sys_nerr; errno++) {
1760 if (instr(buf,sys_errlist[errno])) /* you don't see this */
1765 #define EACCES EPERM
1767 if (instr(buf,"cannot make"))
1769 else if (instr(buf,"existing file"))
1771 else if (instr(buf,"ile exists"))
1773 else if (instr(buf,"non-exist"))
1775 else if (instr(buf,"does not exist"))
1777 else if (instr(buf,"not empty"))
1779 else if (instr(buf,"cannot access"))
1785 else { /* some mkdirs return no failure indication */
1786 tmps = str_get(st[1]);
1787 anum = (stat(tmps,&statbuf) >= 0);
1788 if (optype == O_RMDIR)
1793 errno = EACCES; /* a guess */
1794 value = (double)anum;
1803 tmps = str_get(stab_val(defstab));
1805 tmps = str_get(st[1]);
1807 taintproper("Insecure dependency in rmdir");
1810 value = (double)(rmdir(tmps) >= 0);
1813 (void)strcpy(buf,"rmdir ");
1814 goto one_liner; /* see above in MKDIR */
1818 value = (double)getppid();
1821 fatal("Unsupported function getppid");
1829 anum = (int)str_gnum(st[1]);
1830 value = (double)getpgrp(anum);
1833 fatal("The getpgrp() function is unimplemented on this machine");
1838 argtype = (int)str_gnum(st[1]);
1839 anum = (int)str_gnum(st[2]);
1841 taintproper("Insecure dependency in setpgrp");
1843 value = (double)(setpgrp(argtype,anum) >= 0);
1846 fatal("The setpgrp() function is unimplemented on this machine");
1851 argtype = (int)str_gnum(st[1]);
1852 anum = (int)str_gnum(st[2]);
1853 value = (double)getpriority(argtype,anum);
1856 fatal("The getpriority() function is unimplemented on this machine");
1861 argtype = (int)str_gnum(st[1]);
1862 anum = (int)str_gnum(st[2]);
1863 optype = (int)str_gnum(st[3]);
1865 taintproper("Insecure dependency in setpriority");
1867 value = (double)(setpriority(argtype,anum,optype) >= 0);
1870 fatal("The setpriority() function is unimplemented on this machine");
1876 tmps = str_get(stab_val(defstab));
1878 tmps = str_get(st[1]);
1880 taintproper("Insecure dependency in chroot");
1882 value = (double)(chroot(tmps) >= 0);
1885 fatal("Unsupported function chroot");
1891 stab = last_in_stab;
1892 else if ((arg[1].arg_type & A_MASK) == A_WORD)
1893 stab = arg[1].arg_ptr.arg_stab;
1895 stab = stabent(str_get(st[1]),TRUE);
1896 argtype = U_I(str_gnum(st[2]));
1898 taintproper("Insecure dependency in ioctl");
1900 anum = do_ctl(optype,stab,argtype,st[3]);
1904 value = (double)anum;
1907 str_set(str,"0 but true");
1913 stab = last_in_stab;
1914 else if ((arg[1].arg_type & A_MASK) == A_WORD)
1915 stab = arg[1].arg_ptr.arg_stab;
1917 stab = stabent(str_get(st[1]),TRUE);
1918 if (stab && stab_io(stab))
1919 fp = stab_io(stab)->ifp;
1923 argtype = (int)str_gnum(st[2]);
1924 value = (double)(flock(fileno(fp),argtype) >= 0);
1930 fatal("The flock() function is unimplemented on this machine");
1934 ary = stab_array(arg[1].arg_ptr.arg_stab);
1935 if (arglast[2] - arglast[1] != 1)
1936 do_unshift(ary,arglast);
1938 STR *tmpstr = Str_new(52,0); /* must copy the STR */
1939 str_sset(tmpstr,st[2]);
1941 (void)astore(ary,0,tmpstr);
1943 value = (double)(ary->ary_fill + 1);
1950 tmpstr = stab_val(defstab);
1953 (arg[1].arg_type & A_MASK) != A_NULL ? st[1] : stab_val(defstab);
1955 tainted |= tmpstr->str_tainted;
1956 taintproper("Insecure dependency in eval");
1958 sp = do_eval(tmpstr, optype, curcmd->c_stash,
1986 if (mystat(arg,st[1]) < 0)
1988 if (cando(anum,argtype,&statcache))
1993 if (mystat(arg,st[1]) < 0)
1998 if (mystat(arg,st[1]) < 0)
2000 if (statcache.st_uid == (optype == O_FTEOWNED ? euid : uid) )
2004 if (mystat(arg,st[1]) < 0)
2006 if (!statcache.st_size)
2010 if (mystat(arg,st[1]) < 0)
2012 value = (double)statcache.st_size;
2016 if (mystat(arg,st[1]) < 0)
2018 value = (double)(basetime - statcache.st_mtime) / 86400.0;
2021 if (mystat(arg,st[1]) < 0)
2023 value = (double)(basetime - statcache.st_atime) / 86400.0;
2026 if (mystat(arg,st[1]) < 0)
2028 value = (double)(basetime - statcache.st_ctime) / 86400.0;
2032 if (mystat(arg,st[1]) < 0)
2034 if (S_ISSOCK(statcache.st_mode))
2038 if (mystat(arg,st[1]) < 0)
2040 if (S_ISCHR(statcache.st_mode))
2044 if (mystat(arg,st[1]) < 0)
2046 if (S_ISBLK(statcache.st_mode))
2050 if (mystat(arg,st[1]) < 0)
2052 if (S_ISREG(statcache.st_mode))
2056 if (mystat(arg,st[1]) < 0)
2058 if (S_ISDIR(statcache.st_mode))
2062 if (mystat(arg,st[1]) < 0)
2064 if (S_ISFIFO(statcache.st_mode))
2068 if (mylstat(arg,st[1]) < 0)
2070 if (S_ISLNK(statcache.st_mode))
2075 tmps = str_get(st[1]);
2076 tmps2 = str_get(st[2]);
2078 taintproper("Insecure dependency in symlink");
2080 value = (double)(symlink(tmps,tmps2) >= 0);
2083 fatal("Unsupported function symlink");
2088 tmps = str_get(stab_val(defstab));
2090 tmps = str_get(st[1]);
2091 anum = readlink(tmps,buf,sizeof buf);
2094 str_nset(str,buf,anum);
2097 fatal("Unsupported function readlink");
2120 if (mystat(arg,st[1]) < 0)
2122 if (statcache.st_mode & anum)
2126 if (arg[1].arg_type & A_DONT) {
2127 stab = arg[1].arg_ptr.arg_stab;
2131 stab = stabent(tmps = str_get(st[1]),FALSE);
2132 if (stab && stab_io(stab) && stab_io(stab)->ifp)
2133 anum = fileno(stab_io(stab)->ifp);
2134 else if (isdigit(*tmps))
2143 str = do_fttext(arg,st[1]);
2147 if ((arg[1].arg_type & A_MASK) == A_WORD)
2148 stab = arg[1].arg_ptr.arg_stab;
2150 stab = stabent(str_get(st[1]),TRUE);
2152 value = (double)do_socket(stab,arglast);
2154 (void)do_socket(stab,arglast);
2158 if ((arg[1].arg_type & A_MASK) == A_WORD)
2159 stab = arg[1].arg_ptr.arg_stab;
2161 stab = stabent(str_get(st[1]),TRUE);
2163 value = (double)do_bind(stab,arglast);
2165 (void)do_bind(stab,arglast);
2169 if ((arg[1].arg_type & A_MASK) == A_WORD)
2170 stab = arg[1].arg_ptr.arg_stab;
2172 stab = stabent(str_get(st[1]),TRUE);
2174 value = (double)do_connect(stab,arglast);
2176 (void)do_connect(stab,arglast);
2180 if ((arg[1].arg_type & A_MASK) == A_WORD)
2181 stab = arg[1].arg_ptr.arg_stab;
2183 stab = stabent(str_get(st[1]),TRUE);
2185 value = (double)do_listen(stab,arglast);
2187 (void)do_listen(stab,arglast);
2191 if ((arg[1].arg_type & A_MASK) == A_WORD)
2192 stab = arg[1].arg_ptr.arg_stab;
2194 stab = stabent(str_get(st[1]),TRUE);
2195 if ((arg[2].arg_type & A_MASK) == A_WORD)
2196 stab2 = arg[2].arg_ptr.arg_stab;
2198 stab2 = stabent(str_get(st[2]),TRUE);
2199 do_accept(str,stab,stab2);
2207 sp = do_ghent(optype,
2215 sp = do_gnent(optype,
2223 sp = do_gpent(optype,
2231 sp = do_gsent(optype,
2235 value = (double) sethostent((int)str_gnum(st[1]));
2238 value = (double) setnetent((int)str_gnum(st[1]));
2241 value = (double) setprotoent((int)str_gnum(st[1]));
2244 value = (double) setservent((int)str_gnum(st[1]));
2247 value = (double) endhostent();
2250 value = (double) endnetent();
2253 value = (double) endprotoent();
2256 value = (double) endservent();
2259 if ((arg[1].arg_type & A_MASK) == A_WORD)
2260 stab = arg[1].arg_ptr.arg_stab;
2262 stab = stabent(str_get(st[1]),TRUE);
2263 if ((arg[2].arg_type & A_MASK) == A_WORD)
2264 stab2 = arg[2].arg_ptr.arg_stab;
2266 stab2 = stabent(str_get(st[2]),TRUE);
2268 value = (double)do_spair(stab,stab2,arglast);
2270 (void)do_spair(stab,stab2,arglast);
2274 if ((arg[1].arg_type & A_MASK) == A_WORD)
2275 stab = arg[1].arg_ptr.arg_stab;
2277 stab = stabent(str_get(st[1]),TRUE);
2279 value = (double)do_shutdown(stab,arglast);
2281 (void)do_shutdown(stab,arglast);
2286 if ((arg[1].arg_type & A_MASK) == A_WORD)
2287 stab = arg[1].arg_ptr.arg_stab;
2289 stab = stabent(str_get(st[1]),TRUE);
2290 sp = do_sopt(optype,stab,arglast);
2294 if ((arg[1].arg_type & A_MASK) == A_WORD)
2295 stab = arg[1].arg_ptr.arg_stab;
2297 stab = stabent(str_get(st[1]),TRUE);
2300 sp = do_getsockname(optype,stab,arglast);
2303 #else /* SOCKET not defined */
2336 fatal("Unsupported socket function");
2340 sp = do_select(gimme,arglast);
2343 fatal("select not implemented");
2348 if ((arg[1].arg_type & A_MASK) == A_WORD)
2349 stab = arg[1].arg_ptr.arg_stab;
2351 stab = stabent(str_get(st[1]),TRUE);
2352 if (!stab || !(stio = stab_io(stab)) || !(fp = stio->ifp))
2359 if ((arg[1].arg_type & A_MASK) == A_WORD)
2360 stab = arg[1].arg_ptr.arg_stab;
2362 stab = stabent(str_get(st[1]),TRUE);
2363 if (!stab || !(stio = stab_io(stab)) || !(fp = stio->ifp))
2366 str_set(str, (setmode(fileno(fp), O_BINARY) != -1) ? Yes : No);
2373 sp = do_vec(str == st[1], arg->arg_ptr.arg_str, arglast);
2379 sp = do_gpwent(optype,
2383 value = (double) setpwent();
2386 value = (double) endpwent();
2391 fatal("Unsupported password function");
2398 sp = do_ggrent(optype,
2402 value = (double) setgrent();
2405 value = (double) endgrent();
2410 fatal("Unsupported group function");
2415 if (!(tmps = getlogin()))
2419 fatal("Unsupported function getlogin");
2430 if ((arg[1].arg_type & A_MASK) == A_WORD)
2431 stab = arg[1].arg_ptr.arg_stab;
2433 stab = stabent(str_get(st[1]),TRUE);
2436 sp = do_dirop(optype,stab,gimme,arglast);
2439 value = (double)do_syscall(arglast);
2443 if ((arg[1].arg_type & A_MASK) == A_WORD)
2444 stab = arg[1].arg_ptr.arg_stab;
2446 stab = stabent(str_get(st[1]),TRUE);
2447 if ((arg[2].arg_type & A_MASK) == A_WORD)
2448 stab2 = arg[2].arg_ptr.arg_stab;
2450 stab2 = stabent(str_get(st[2]),TRUE);
2451 do_pipe(str,stab,stab2);
2454 fatal("Unsupported function pipe");
2465 deb("%s RETURNS \"%s\"\n",opname[optype],str_get(str));
2468 return arglast[0] + 1;
2475 anum = sp - arglast[0];
2478 deb("%s RETURNS ()\n",opname[optype]);
2481 deb("%s RETURNS (\"%s\")\n",opname[optype],str_get(st[1]));
2484 tmps = str_get(st[1]);
2485 deb("%s RETURNS %d ARGS (\"%s\",%s\"%s\")\n",opname[optype],
2486 anum,tmps,anum==2?"":"...,",str_get(st[anum]));
2511 str_numset(str,value);
2518 deb("%s RETURNS \"%f\"\n",opname[optype],value);
2521 return arglast[0] + 1;