1 /* $Header: eval.c,v 3.0.1.9 90/10/15 16:46:13 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.9 90/10/15 16:46:13 lwall
10 * patch29: added caller
11 * patch29: added scalar
12 * patch29: added cmp and <=>
13 * patch29: added sysread and syswrite
14 * patch29: added -M, -A and -C
15 * patch29: index and substr now have optional 3rd args
16 * patch29: you can now read into the middle string
17 * patch29: ~ now works on vector string
18 * patch29: non-existent array values no longer cause core dumps
19 * patch29: eof; core dumped
20 * patch29: oct and hex now produce unsigned result
21 * patch29: unshift did not return the documented value
23 * Revision 3.0.1.8 90/08/13 22:17:14 lwall
24 * patch28: the NSIG hack didn't work right on Xenix
25 * patch28: defined(@array) and defined(%array) didn't work right
26 * patch28: rename was busted on systems without rename system call
28 * Revision 3.0.1.7 90/08/09 03:33:44 lwall
29 * patch19: made ~ do vector operation on strings like &, | and ^
30 * patch19: dbmopen(%name...) didn't work right
31 * patch19: dbmopen(name, 'filename', undef) now refrains from creating
32 * patch19: empty %array now returns 0 in scalar context
33 * patch19: die with no arguments no longer exits unconditionally
34 * patch19: return outside a subroutine now returns a reasonable message
35 * patch19: rename done with unlink()/link()/unlink() now checks for clobbering
36 * patch19: -s now returns size of file
38 * Revision 3.0.1.6 90/03/27 15:53:51 lwall
39 * patch16: MSDOS support
40 * patch16: support for machines that can't cast negative floats to unsigned ints
41 * patch16: ioctl didn't return values correctly
43 * Revision 3.0.1.5 90/03/12 16:37:40 lwall
44 * patch13: undef $/ didn't work as advertised
45 * patch13: added list slice operator (LIST)[LIST]
46 * patch13: added splice operator: @oldelems = splice(@array,$offset,$len,LIST)
48 * Revision 3.0.1.4 90/02/28 17:36:59 lwall
49 * patch9: added pipe function
50 * patch9: a return in scalar context wouldn't return array
51 * patch9: !~ now always returns scalar even in array context
52 * patch9: some machines can't cast float to long with high bit set
53 * patch9: piped opens returned undef in child
54 * patch9: @array in scalar context now returns length of array
55 * patch9: chdir; coredumped
56 * patch9: wait no longer ignores signals
57 * patch9: mkdir now handles odd versions of /bin/mkdir
58 * patch9: -l FILEHANDLE now disallowed
60 * Revision 3.0.1.3 89/12/21 20:03:05 lwall
61 * patch7: errno may now be a macro with an lvalue
62 * patch7: ANSI strerror() is now supported
63 * patch7: send() didn't allow a TO argument
64 * patch7: ord() now always returns positive even on signed char machines
66 * Revision 3.0.1.2 89/11/17 15:19:34 lwall
67 * patch5: constant numeric subscripts get lost inside ?:
69 * Revision 3.0.1.1 89/11/11 04:31:51 lwall
70 * patch2: mkdir and rmdir needed to quote argument when passed to shell
71 * patch2: mkdir and rmdir now return better error codes
72 * patch2: fileno, seekdir, rewinddir and closedir now disallow defaults
74 * Revision 3.0 89/10/18 15:17:04 lwall
82 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
94 static void (*ihand)();
95 static void (*qhand)();
97 static int (*ihand)();
98 static int (*qhand)();
105 static struct lstring *lstr;
106 static int old_record_separator;
108 double sin(), cos(), atan2(), pow();
129 int arglast[8]; /* highest sp for arg--valid only for non-O_LIST args */
130 unsigned long tmplong;
137 bool assigning = FALSE;
138 double exp(), log(), sqrt(), modf();
139 char *crypt(), *getenv();
140 extern void grow_dlevel();
144 optype = arg->arg_type;
145 maxarg = arg->arg_len;
147 str = arg->arg_ptr.arg_str;
148 if (sp + maxarg > stack->ary_max)
149 astore(stack, sp + maxarg, Nullstr);
150 st = stack->ary_array;
155 deb("%s (%lx) %d args:\n",opname[optype],arg,maxarg);
157 debname[dlevel] = opname[optype][0];
158 debdelim[dlevel] = ':';
159 if (++dlevel >= dlmax)
164 #include "evalargs.xc"
172 if (gimme == G_ARRAY)
180 if (gimme == G_ARRAY)
183 STR_SSET(str,st[arglast[anum]-arglast[0]]);
187 if (gimme == G_ARRAY)
190 STR_SSET(str,st[arglast[anum]-arglast[0]]);
200 anum = (int)str_gnum(st[2]);
202 tmpstr = Str_new(50, 0);
203 str_sset(tmpstr,str);
204 tmps = str_get(tmpstr); /* force to be string */
205 STR_GROW(str, (anum * str->str_cur) + 1);
206 repeatcpy(str->str_ptr, tmps, tmpstr->str_cur, anum);
207 str->str_cur *= anum;
208 str->str_ptr[str->str_cur] = '\0';
211 str_sset(str,&str_no);
215 sp = do_match(str,arg,
217 if (gimme == G_ARRAY)
222 sp = do_match(str,arg,
224 str_sset(str, str_true(str) ? &str_no : &str_yes);
228 sp = do_subst(str,arg,arglast[0]);
231 sp = do_subst(str,arg,arglast[0]);
232 str = arg->arg_ptr.arg_str;
233 str_set(str, str_true(str) ? No : Yes);
236 if (arg[1].arg_flags & AF_ARYOK) {
237 if (arg->arg_len == 1) {
238 arg->arg_type = O_LOCAL;
242 arg->arg_type = O_AASSIGN;
247 arg->arg_type = O_SASSIGN;
252 arglast[2] = arglast[1]; /* push a null array */
261 STR_SSET(str, st[2]);
266 str = arg->arg_ptr.arg_str;
267 for (sp = arglast[0] + 1; sp <= arglast[1]; sp++)
272 if (arg[1].arg_type & A_DONT) {
273 sp = do_defined(str,arg,
277 else if (str->str_pok || str->str_nok)
281 if (arg[1].arg_type & A_DONT) {
282 sp = do_undef(str,arg,
286 else if (str != stab_val(defstab)) {
287 str->str_pok = str->str_nok = 0;
292 sp = do_study(str,arg,
296 value = str_gnum(st[1]);
297 value = pow(value,str_gnum(st[2]));
300 value = str_gnum(st[1]);
301 value *= str_gnum(st[2]);
304 if ((value = str_gnum(st[2])) == 0.0)
305 fatal("Illegal division by zero");
306 value = str_gnum(st[1]) / value;
309 tmplong = (long) str_gnum(st[2]);
311 fatal("Illegal modulus zero");
312 when = (long)str_gnum(st[1]);
315 value = (double)(when % tmplong);
317 value = (double)(tmplong - ((-when - 1) % tmplong)) - 1;
321 value = str_gnum(st[1]);
322 value += str_gnum(st[2]);
325 value = str_gnum(st[1]);
326 value -= str_gnum(st[2]);
329 value = str_gnum(st[1]);
330 anum = (int)str_gnum(st[2]);
332 value = (double)(U_L(value) << anum);
336 value = str_gnum(st[1]);
337 anum = (int)str_gnum(st[2]);
339 value = (double)(U_L(value) >> anum);
343 value = str_gnum(st[1]);
344 value = (value < str_gnum(st[2])) ? 1.0 : 0.0;
347 value = str_gnum(st[1]);
348 value = (value > str_gnum(st[2])) ? 1.0 : 0.0;
351 value = str_gnum(st[1]);
352 value = (value <= str_gnum(st[2])) ? 1.0 : 0.0;
355 value = str_gnum(st[1]);
356 value = (value >= str_gnum(st[2])) ? 1.0 : 0.0;
360 if ((!st[1]->str_nok && !looks_like_number(st[1])) ||
361 (!st[2]->str_nok && !looks_like_number(st[2])) )
362 warn("Possible use of == on string value");
364 value = str_gnum(st[1]);
365 value = (value == str_gnum(st[2])) ? 1.0 : 0.0;
368 value = str_gnum(st[1]);
369 value = (value != str_gnum(st[2])) ? 1.0 : 0.0;
372 value = str_gnum(st[1]);
373 value -= str_gnum(st[2]);
376 else if (value < 0.0)
380 if (!sawvec || st[1]->str_nok || st[2]->str_nok) {
381 value = str_gnum(st[1]);
383 value = (double)(U_L(value) & U_L(str_gnum(st[2])));
388 do_vop(optype,str,st[1],st[2]);
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]);
412 /* use register in evaluating str_true() */
414 if (str_true(st[1])) {
417 argflags = arg[anum].arg_flags;
418 if (gimme == G_ARRAY)
419 argflags |= AF_ARYOK;
420 argtype = arg[anum].arg_type & A_MASK;
421 argptr = arg[anum].arg_ptr;
429 str_sset(str, st[1]);
437 if (str_true(st[1])) {
439 str_sset(str, st[1]);
449 argflags = arg[anum].arg_flags;
450 if (gimme == G_ARRAY)
451 argflags |= AF_ARYOK;
452 argtype = arg[anum].arg_type & A_MASK;
453 argptr = arg[anum].arg_ptr;
460 anum = (str_true(st[1]) ? 2 : 3);
461 optype = (anum == 2 ? O_ITEM2 : O_ITEM3);
462 argflags = arg[anum].arg_flags;
463 if (gimme == G_ARRAY)
464 argflags |= AF_ARYOK;
465 argtype = arg[anum].arg_type & A_MASK;
466 argptr = arg[anum].arg_ptr;
472 if (gimme == G_ARRAY)
477 value = -str_gnum(st[1]);
480 value = (double) !str_true(st[1]);
483 if (!sawvec || st[1]->str_nok) {
485 value = (double) ~U_L(str_gnum(st[1]));
492 for (anum = str->str_cur; anum; anum--, tmps++)
497 stab_fullname(str,defoutstab);
499 if ((arg[1].arg_type & A_MASK) == A_WORD)
500 defoutstab = arg[1].arg_ptr.arg_stab;
502 defoutstab = stabent(str_get(st[1]),TRUE);
503 if (!stab_io(defoutstab))
504 stab_io(defoutstab) = stio_new();
505 curoutstab = defoutstab;
512 else if ((arg[1].arg_type & A_MASK) == A_WORD) {
513 if (!(stab = arg[1].arg_ptr.arg_stab))
517 stab = stabent(str_get(st[1]),TRUE);
518 if (!stab_io(stab)) {
524 fp = stab_io(stab)->ofp;
526 if (stab_io(stab)->fmt_stab)
527 form = stab_form(stab_io(stab)->fmt_stab);
529 form = stab_form(stab);
533 warn("No format for filehandle");
535 if (stab_io(stab)->ifp)
536 warn("Filehandle only opened for input");
538 warn("Write on closed filehandle");
545 format(&outrec,form,sp);
546 do_write(&outrec,stab_io(stab),sp);
547 if (stab_io(stab)->flags & IOF_FLUSH)
554 stab = arg[1].arg_ptr.arg_stab;
555 if (st[3]->str_nok || st[3]->str_pok)
556 anum = (int)str_gnum(st[3]);
559 value = (double)hdbmopen(stab_hash(stab),str_get(st[2]),anum);
562 fatal("No dbm or ndbm on this machine");
566 stab = arg[1].arg_ptr.arg_stab;
567 hdbmclose(stab_hash(stab));
570 fatal("No dbm or ndbm on this machine");
573 if ((arg[1].arg_type & A_MASK) == A_WORD)
574 stab = arg[1].arg_ptr.arg_stab;
576 stab = stabent(str_get(st[1]),TRUE);
577 tmps = str_get(st[2]);
578 if (do_open(stab,tmps,st[2]->str_cur)) {
579 value = (double)forkprocess;
580 stab_io(stab)->lines = 0;
583 else if (forkprocess == 0) /* we are a new child */
589 value = (double) do_trans(str,arg);
590 str = arg->arg_ptr.arg_str;
593 str_set(arg->arg_ptr.arg_str, do_trans(str,arg) == 0 ? Yes : No);
594 str = arg->arg_ptr.arg_str;
599 else if ((arg[1].arg_type & A_MASK) == A_WORD)
600 stab = arg[1].arg_ptr.arg_stab;
602 stab = stabent(str_get(st[1]),TRUE);
603 str_set(str, do_close(stab,TRUE) ? Yes : No );
607 sp = do_each(str,stab_hash(arg[1].arg_ptr.arg_stab),
612 sp = do_kv(str,stab_hash(arg[1].arg_ptr.arg_stab), optype,
616 str->str_nok = str->str_pok = 0;
617 str->str_u.str_stab = arg[1].arg_ptr.arg_stab;
618 str->str_state = SS_ARY;
621 ary = stab_array(arg[1].arg_ptr.arg_stab);
622 maxarg = ary->ary_fill + 1;
623 if (gimme == G_ARRAY) { /* array wanted */
626 if (maxarg > 0 && sp + maxarg > stack->ary_max) {
627 astore(stack,sp + maxarg, Nullstr);
628 st = stack->ary_array;
631 Copy(ary->ary_array, &st[1], maxarg, STR*);
636 value = (double)maxarg;
640 anum = ((int)str_gnum(st[2])) - arybase;
641 str = afetch(stab_array(arg[1].arg_ptr.arg_stab),anum,FALSE);
644 tmpstab = arg[1].arg_ptr.arg_stab;
645 tmps = str_get(st[2]);
646 str = hdelete(stab_hash(tmpstab),tmps,st[2]->str_cur);
647 if (tmpstab == envstab)
653 str->str_nok = str->str_pok = 0;
654 str->str_u.str_stab = arg[1].arg_ptr.arg_stab;
655 str->str_state = SS_HASH;
658 if (gimme == G_ARRAY) { /* array wanted */
659 sp = do_kv(str,stab_hash(arg[1].arg_ptr.arg_stab), optype,
664 tmpstab = arg[1].arg_ptr.arg_stab;
665 if (!stab_hash(tmpstab)->tbl_fill)
667 sprintf(buf,"%d/%d",stab_hash(tmpstab)->tbl_fill,
668 stab_hash(tmpstab)->tbl_max+1);
673 tmpstab = arg[1].arg_ptr.arg_stab;
674 tmps = str_get(st[2]);
675 str = hfetch(stab_hash(tmpstab),tmps,st[2]->str_cur,FALSE);
678 anum = ((int)str_gnum(st[2])) - arybase;
679 str = afetch(stab_array(arg[1].arg_ptr.arg_stab),anum,TRUE);
680 if (!str || str == &str_undef)
681 fatal("Assignment to non-creatable value, subscript %d",anum);
684 tmpstab = arg[1].arg_ptr.arg_stab;
685 tmps = str_get(st[2]);
686 anum = st[2]->str_cur;
687 str = hfetch(stab_hash(tmpstab),tmps,anum,TRUE);
688 if (!str || str == &str_undef)
689 fatal("Assignment to non-creatable value, subscript \"%s\"",tmps);
690 if (tmpstab == envstab) /* heavy wizardry going on here */
691 str_magic(str, tmpstab, 'E', tmps, anum); /* str is now magic */
692 /* he threw the brick up into the air */
693 else if (tmpstab == sigstab)
694 str_magic(str, tmpstab, 'S', tmps, anum);
696 else if (stab_hash(tmpstab)->tbl_dbm)
697 str_magic(str, tmpstab, 'D', tmps, anum);
699 else if (perldb && tmpstab == DBline)
700 str_magic(str, tmpstab, 'L', tmps, anum);
705 goto do_slice_already;
709 goto do_slice_already;
713 goto do_slice_already;
717 goto do_slice_already;
722 sp = do_slice(arg[1].arg_ptr.arg_stab,str,anum,argtype,
726 sp = do_splice(stab_array(arg[1].arg_ptr.arg_stab),gimme,arglast);
729 if (arglast[2] - arglast[1] != 1)
730 str = do_push(stab_array(arg[1].arg_ptr.arg_stab),arglast);
732 str = Str_new(51,0); /* must copy the STR */
734 (void)apush(stab_array(arg[1].arg_ptr.arg_stab),str);
738 str = apop(ary = stab_array(arg[1].arg_ptr.arg_stab));
739 goto staticalization;
741 str = ashift(ary = stab_array(arg[1].arg_ptr.arg_stab));
745 if (ary->ary_flags & ARF_REAL)
746 (void)str_2static(str);
749 sp = do_unpack(str,gimme,arglast);
752 value = str_gnum(st[3]);
753 sp = do_split(str, arg[2].arg_ptr.arg_spat, (int)value,
758 value = (double)str_len(stab_val(defstab));
760 value = (double)str_len(st[1]);
763 do_sprintf(str, sp-arglast[0], st+1);
766 anum = ((int)str_gnum(st[2])) - arybase; /* anum=where to start*/
767 tmps = str_get(st[1]); /* force conversion to string */
768 if (argtype = (str == st[1]))
769 str = arg->arg_ptr.arg_str;
771 anum += st[1]->str_cur + arybase;
772 if (anum < 0 || anum > st[1]->str_cur)
775 optype = maxarg < 3 ? st[1]->str_cur : (int)str_gnum(st[3]);
779 anum = st[1]->str_cur - anum; /* anum=how many bytes left*/
782 str_nset(str, tmps, anum);
783 if (argtype) { /* it's an lvalue! */
784 lstr = (struct lstring*)str;
785 str->str_magic = st[1];
786 st[1]->str_rare = 's';
787 lstr->lstr_offset = tmps - str_get(st[1]);
788 lstr->lstr_len = anum;
793 (void)do_pack(str,arglast);
796 sp = do_grep(arg,str,gimme,arglast);
799 do_join(str,arglast);
802 tmps = str_get(st[1]);
803 value = (double) (str_cmp(st[1],st[2]) < 0);
806 tmps = str_get(st[1]);
807 value = (double) (str_cmp(st[1],st[2]) > 0);
810 tmps = str_get(st[1]);
811 value = (double) (str_cmp(st[1],st[2]) <= 0);
814 tmps = str_get(st[1]);
815 value = (double) (str_cmp(st[1],st[2]) >= 0);
818 tmps = str_get(st[1]);
819 value = (double) str_eq(st[1],st[2]);
822 tmps = str_get(st[1]);
823 value = (double) !str_eq(st[1],st[2]);
826 tmps = str_get(st[1]);
827 value = (double) str_cmp(st[1],st[2]);
830 sp = do_subr(arg,gimme,arglast);
831 st = stack->ary_array + arglast[0]; /* maybe realloced */
834 sp = do_subr(arg,gimme,arglast);
835 st = stack->ary_array + arglast[0]; /* maybe realloced */
838 sp = do_caller(arg,maxarg,gimme,arglast);
839 st = stack->ary_array + arglast[0]; /* maybe realloced */
842 if ((arg[1].arg_type & A_MASK) == A_WORD)
843 stab = arg[1].arg_ptr.arg_stab;
845 stab = stabent(str_get(st[1]),TRUE);
846 sp = do_sort(str,stab,
850 if (gimme == G_ARRAY)
854 sp = do_sreverse(str,
858 if (arglast[2] - arglast[1] != 1) {
859 do_join(str,arglast);
860 tmps = str_get(st[1]);
864 tmps = str_get(st[2]);
867 tmps = "Warning: something's wrong";
871 if (arglast[2] - arglast[1] != 1) {
872 do_join(str,arglast);
873 tmps = str_get(st[1]);
877 tmps = str_get(st[2]);
885 if ((arg[1].arg_type & A_MASK) == A_WORD)
886 stab = arg[1].arg_ptr.arg_stab;
888 stab = stabent(str_get(st[1]),TRUE);
891 if (!stab_io(stab)) {
893 warn("Filehandle never opened");
896 if (!(fp = stab_io(stab)->ofp)) {
898 if (stab_io(stab)->ifp)
899 warn("Filehandle opened only for input");
901 warn("Print on closed filehandle");
906 if (optype == O_PRTF || arglast[2] - arglast[1] != 1)
907 value = (double)do_aprint(arg,fp,arglast);
909 value = (double)do_print(st[2],fp);
910 if (orslen && optype == O_PRINT)
911 if (fwrite(ors, 1, orslen, fp) == 0)
914 if (stab_io(stab)->flags & IOF_FLUSH)
915 if (fflush(fp) == EOF)
923 tmps = str_get(st[1]);
924 if (!tmps || !*tmps) {
925 tmpstr = hfetch(stab_hash(envstab),"HOME",4,FALSE);
926 tmps = str_get(tmpstr);
928 if (!tmps || !*tmps) {
929 tmpstr = hfetch(stab_hash(envstab),"LOGDIR",6,FALSE);
930 tmps = str_get(tmpstr);
933 taintproper("Insecure dependency in chdir");
935 value = (double)(chdir(tmps) >= 0);
941 anum = (int)str_gnum(st[1]);
948 tmps = str_get(st[1]);
949 str_reset(tmps,curcmd->c_stash);
953 if (gimme == G_ARRAY)
956 str = st[sp - arglast[0]]; /* unwanted list, return last item */
963 else if ((arg[1].arg_type & A_MASK) == A_WORD)
964 stab = arg[1].arg_ptr.arg_stab;
966 stab = stabent(str_get(st[1]),TRUE);
967 str_set(str, do_eof(stab) ? Yes : No);
973 else if ((arg[1].arg_type & A_MASK) == A_WORD)
974 stab = arg[1].arg_ptr.arg_stab;
976 stab = stabent(str_get(st[1]),TRUE);
979 if (!stab || do_eof(stab)) /* make sure we have fp with something */
986 *str->str_ptr = getc(stab_io(stab)->ifp); /* should never be EOF */
993 else if ((arg[1].arg_type & A_MASK) == A_WORD)
994 stab = arg[1].arg_ptr.arg_stab;
996 stab = stabent(str_get(st[1]),TRUE);
998 value = (double)do_tell(stab);
1000 (void)do_tell(stab);
1006 if ((arg[1].arg_type & A_MASK) == A_WORD)
1007 stab = arg[1].arg_ptr.arg_stab;
1009 stab = stabent(str_get(st[1]),TRUE);
1010 tmps = str_get(st[2]);
1011 anum = (int)str_gnum(st[3]);
1013 maxarg = sp - arglast[0];
1015 warn("Too many args on read");
1017 maxarg = (int)str_gnum(st[4]);
1020 if (!stab_io(stab) || !stab_io(stab)->ifp)
1023 if (optype == O_RECV) {
1024 argtype = sizeof buf;
1025 anum = recvfrom(fileno(stab_io(stab)->ifp), tmps, anum, maxarg,
1028 st[2]->str_cur = anum;
1029 st[2]->str_ptr[anum] = '\0';
1030 str_nset(str,buf,argtype);
1033 str_sset(str,&str_undef);
1037 if (optype == O_RECV)
1040 STR_GROW(st[2], anum+maxarg+1), (tmps = str_get(st[2])); /* sneaky */
1042 if (stab_io(stab)->type == 's') {
1043 argtype = sizeof buf;
1044 anum = recvfrom(fileno(stab_io(stab)->ifp), tmps+maxarg, anum, 0,
1049 if (optype == O_SYSREAD) {
1050 anum = read(fileno(stab_io(stab)->ifp), tmps+maxarg, anum);
1053 anum = fread(tmps+maxarg, 1, anum, stab_io(stab)->ifp);
1056 st[2]->str_cur = anum+maxarg;
1057 st[2]->str_ptr[anum+maxarg] = '\0';
1058 value = (double)anum;
1062 if ((arg[1].arg_type & A_MASK) == A_WORD)
1063 stab = arg[1].arg_ptr.arg_stab;
1065 stab = stabent(str_get(st[1]),TRUE);
1066 tmps = str_get(st[2]);
1067 anum = (int)str_gnum(st[3]);
1069 stio = stab_io(stab);
1070 maxarg = sp - arglast[0];
1071 if (!stio || !stio->ifp) {
1074 if (optype == O_SYSWRITE)
1075 warn("Syswrite on closed filehandle");
1077 warn("Send on closed socket");
1080 else if (optype == O_SYSWRITE) {
1082 warn("Too many args on syswrite");
1084 optype = (int)str_gnum(st[4]);
1087 anum = write(fileno(stab_io(stab)->ifp), tmps+optype, anum);
1090 else if (maxarg >= 4) {
1092 warn("Too many args on send");
1093 tmps2 = str_get(st[4]);
1094 anum = sendto(fileno(stab_io(stab)->ifp), tmps, st[2]->str_cur,
1095 anum, tmps2, st[4]->str_cur);
1098 anum = send(fileno(stab_io(stab)->ifp), tmps, st[2]->str_cur, anum);
1105 value = (double)anum;
1108 if ((arg[1].arg_type & A_MASK) == A_WORD)
1109 stab = arg[1].arg_ptr.arg_stab;
1111 stab = stabent(str_get(st[1]),TRUE);
1112 value = str_gnum(st[2]);
1113 str_set(str, do_seek(stab,
1114 (long)value, (int)str_gnum(st[3]) ) ? Yes : No);
1118 tmps = "_SUB_"; /* just fake up a "last _SUB_" */
1120 if (curcsv->wantarray == G_ARRAY) {
1121 lastretstr = Nullstr;
1122 lastspbase = arglast[1];
1123 lastsize = arglast[2] - arglast[1];
1126 lastretstr = str_static(st[arglast[2] - arglast[0]]);
1132 tmps = str_get(arg[1].arg_ptr.arg_str);
1134 while (loop_ptr >= 0 && (!loop_stack[loop_ptr].loop_label ||
1135 strNE(tmps,loop_stack[loop_ptr].loop_label) )) {
1138 deb("(Skipping label #%d %s)\n",loop_ptr,
1139 loop_stack[loop_ptr].loop_label);
1146 deb("(Found label #%d %s)\n",loop_ptr,
1147 loop_stack[loop_ptr].loop_label);
1152 if (tmps && strEQ(tmps, "_SUB_"))
1153 fatal("Can't return outside a subroutine");
1154 fatal("Bad label: %s", maxarg > 0 ? tmps : "<null>");
1156 if (!lastretstr && optype == O_LAST && lastsize) {
1158 st += lastspbase + 1;
1159 optype = loop_stack[loop_ptr].loop_sp - lastspbase; /* negative */
1161 for (anum = lastsize; anum > 0; anum--,st++)
1162 st[optype] = str_static(st[0]);
1164 longjmp(loop_stack[loop_ptr].loop_env, O_LAST);
1166 longjmp(loop_stack[loop_ptr].loop_env, optype);
1168 case O_GOTO:/* shudder */
1169 goto_targ = str_get(arg[1].arg_ptr.arg_str);
1171 goto_targ = Nullch; /* just restart from top */
1172 if (optype == O_DUMP) {
1176 longjmp(top_env, 1);
1178 tmps = str_get(st[1]);
1182 anum = (int) str_gnum(st[3]) - arybase;
1185 else if (anum > st[1]->str_cur)
1186 anum = st[1]->str_cur;
1189 if (!(tmps2 = fbminstr((unsigned char*)tmps + anum,
1190 (unsigned char*)tmps + st[1]->str_cur, st[2])))
1192 if (tmps2 = fbminstr(Null(unsigned char*),Null(unsigned char*),Nullstr))
1194 value = (double)(-1 + arybase);
1196 value = (double)(tmps2 - tmps + arybase);
1199 tmps = str_get(st[1]);
1200 tmps2 = str_get(st[2]);
1202 anum = st[1]->str_cur;
1204 anum = (int) str_gnum(st[3]) - arybase + st[2]->str_cur;
1207 else if (anum > st[1]->str_cur)
1208 anum = st[1]->str_cur;
1211 if (!(tmps2 = rninstr(tmps, tmps + anum,
1212 tmps2, tmps2 + st[2]->str_cur)))
1214 if (tmps2 = rninstr(Nullch,Nullch,Nullch,Nullch))
1216 value = (double)(-1 + arybase);
1218 value = (double)(tmps2 - tmps + arybase);
1222 value = (double) time(Null(long*));
1226 sp = do_tms(str,gimme,arglast);
1232 when = (long)str_gnum(st[1]);
1233 sp = do_time(str,localtime(&when),
1240 when = (long)str_gnum(st[1]);
1241 sp = do_time(str,gmtime(&when),
1245 sp = do_truncate(str,arg,
1250 sp = do_stat(str,arg,
1255 tmps = str_get(st[1]);
1257 str_set(str,fcrypt(tmps,str_get(st[2])));
1259 str_set(str,crypt(tmps,str_get(st[2])));
1263 "The crypt() function is unimplemented due to excessive paranoia.");
1267 value = str_gnum(st[1]);
1268 value = atan2(value,str_gnum(st[2]));
1272 value = str_gnum(stab_val(defstab));
1274 value = str_gnum(st[1]);
1279 value = str_gnum(stab_val(defstab));
1281 value = str_gnum(st[1]);
1288 value = str_gnum(st[1]);
1292 value = rand() * value / 2147483648.0;
1295 value = rand() * value / 65536.0;
1298 value = rand() * value / 32768.0;
1300 value = rand() * value / (double)(((unsigned long)1) << RANDBITS);
1311 anum = (int)str_gnum(st[1]);
1316 value = str_gnum(stab_val(defstab));
1318 value = str_gnum(st[1]);
1323 value = str_gnum(stab_val(defstab));
1325 value = str_gnum(st[1]);
1330 value = str_gnum(stab_val(defstab));
1332 value = str_gnum(st[1]);
1333 value = sqrt(value);
1337 value = str_gnum(stab_val(defstab));
1339 value = str_gnum(st[1]);
1341 (void)modf(value,&value);
1343 (void)modf(-value,&value);
1349 tmps = str_get(stab_val(defstab));
1351 tmps = str_get(st[1]);
1353 value = (double) (*tmps & 255);
1356 value = (double) (anum & 255);
1363 tmps = str_get(st[1]);
1365 if (!tmps || !*tmps)
1366 sleep((32767<<16)+32767);
1368 sleep((unsigned int)atoi(tmps));
1370 value = (double)when;
1372 value = ((double)when) - value;
1376 sp = do_range(gimme,arglast);
1379 if (gimme == G_ARRAY) { /* it's a range */
1380 /* can we optimize to constant array? */
1381 if ((arg[1].arg_type & A_MASK) == A_SINGLE &&
1382 (arg[2].arg_type & A_MASK) == A_SINGLE) {
1383 st[2] = arg[2].arg_ptr.arg_str;
1384 sp = do_range(gimme,arglast);
1385 st = stack->ary_array;
1386 maxarg = sp - arglast[0];
1387 str_free(arg[1].arg_ptr.arg_str);
1388 str_free(arg[2].arg_ptr.arg_str);
1389 arg->arg_type = O_ARRAY;
1390 arg[1].arg_type = A_STAB|A_DONT;
1392 stab = arg[1].arg_ptr.arg_stab = aadd(genstab());
1393 ary = stab_array(stab);
1394 afill(ary,maxarg - 1);
1396 while (maxarg-- > 0)
1397 ary->ary_array[maxarg] = str_smake(st[maxarg]);
1400 arg->arg_type = optype = O_RANGE;
1401 maxarg = arg->arg_len = 2;
1403 arg[anum].arg_flags &= ~AF_ARYOK;
1404 argflags = arg[anum].arg_flags;
1405 argtype = arg[anum].arg_type & A_MASK;
1406 arg[anum].arg_type = argtype;
1407 argptr = arg[anum].arg_ptr;
1413 arg->arg_type = O_FLIP;
1416 if ((arg[1].arg_type & A_MASK) == A_SINGLE ?
1417 last_in_stab && (int)str_gnum(st[1]) == stab_io(last_in_stab)->lines
1420 str_numset(str,0.0);
1422 arg->arg_type = optype = O_FLOP;
1423 arg[2].arg_type &= ~A_DONT;
1424 arg[1].arg_type |= A_DONT;
1425 argflags = arg[2].arg_flags;
1426 argtype = arg[2].arg_type & A_MASK;
1427 argptr = arg[2].arg_ptr;
1436 if ((arg[2].arg_type & A_MASK) == A_SINGLE ?
1437 last_in_stab && (int)str_gnum(st[2]) == stab_io(last_in_stab)->lines
1440 arg->arg_type = O_FLIP;
1441 arg[1].arg_type &= ~A_DONT;
1442 arg[2].arg_type |= A_DONT;
1450 if (tmpstab = stabent("$",allstabs))
1451 str_numset(STAB_STR(tmpstab),(double)getpid());
1452 hclear(pidstatus); /* no kids, so don't wait for 'em */
1454 value = (double)anum;
1457 fatal("Unsupported function fork");
1463 anum = wait(&argflags);
1465 pidgone(anum,argflags);
1466 value = (double)anum;
1468 statusvalue = (unsigned short)argflags;
1471 fatal("Unsupported function wait");
1477 anum = (int)str_gnum(st[1]);
1478 optype = (int)str_gnum(st[2]);
1479 anum = wait4pid(anum, &argflags,optype);
1480 value = (double)anum;
1482 statusvalue = (unsigned short)argflags;
1485 fatal("Unsupported function wait");
1491 if (arglast[2] - arglast[1] == 1) {
1493 tainted |= st[2]->str_tainted;
1494 taintproper("Insecure dependency in system");
1497 while ((anum = vfork()) == -1) {
1498 if (errno != EAGAIN) {
1506 ihand = signal(SIGINT, SIG_IGN);
1507 qhand = signal(SIGQUIT, SIG_IGN);
1508 argtype = wait4pid(anum, &argflags, 0);
1512 (void)signal(SIGINT, ihand);
1513 (void)signal(SIGQUIT, qhand);
1514 statusvalue = (unsigned short)argflags;
1518 value = (double)((unsigned int)argflags & 0xffff);
1520 do_execfree(); /* free any memory child malloced on vfork */
1523 if ((arg[1].arg_type & A_MASK) == A_STAB)
1524 value = (double)do_aexec(st[1],arglast);
1525 else if (arglast[2] - arglast[1] != 1)
1526 value = (double)do_aexec(Nullstr,arglast);
1528 value = (double)do_exec(str_get(str_static(st[2])));
1532 if ((arg[1].arg_type & A_MASK) == A_STAB)
1533 value = (double)do_aspawn(st[1],arglast);
1534 else if (arglast[2] - arglast[1] != 1)
1535 value = (double)do_aspawn(Nullstr,arglast);
1537 value = (double)do_spawn(str_get(str_static(st[2])));
1542 if ((arg[1].arg_type & A_MASK) == A_STAB)
1543 value = (double)do_aexec(st[1],arglast);
1544 else if (arglast[2] - arglast[1] != 1)
1545 value = (double)do_aexec(Nullstr,arglast);
1547 value = (double)do_exec(str_get(str_static(st[2])));
1560 tmps = str_get(stab_val(defstab));
1562 tmps = str_get(st[1]);
1571 case '0': case '1': case '2': case '3': case '4':
1572 case '5': case '6': case '7':
1573 tmplong <<= argtype;
1574 tmplong += *tmps++ & 15;
1576 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
1577 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
1581 tmplong += (*tmps++ & 7) + 9;
1590 value = (double)tmplong;
1594 value = (double)apply(optype,arglast);
1597 fatal("Unsupported function chown");
1602 value = (double)apply(optype,arglast);
1605 fatal("Unsupported function kill");
1611 value = (double)apply(optype,arglast);
1620 anum = umask((int)str_gnum(st[1]));
1621 value = (double)anum;
1623 taintproper("Insecure dependency in umask");
1627 fatal("Unsupported function umask");
1634 if ((anum = do_ipcget(optype, arglast)) == -1)
1636 value = (double)anum;
1641 anum = do_ipcctl(optype, arglast);
1645 value = (double)anum;
1648 str_set(str,"0 but true");
1652 value = (double)(do_msgsnd(arglast) >= 0);
1655 value = (double)(do_msgrcv(arglast) >= 0);
1658 value = (double)(do_semop(arglast) >= 0);
1662 value = (double)(do_shmio(optype, arglast) >= 0);
1664 #else /* not SYSVIPC */
1676 fatal("System V IPC is not implemented on this machine");
1677 #endif /* not SYSVIPC */
1679 tmps = str_get(st[1]);
1680 tmps2 = str_get(st[2]);
1682 taintproper("Insecure dependency in rename");
1685 value = (double)(rename(tmps,tmps2) >= 0);
1687 if (same_dirent(tmps2, tmps)) /* can always rename to same name */
1690 if (euid || stat(tmps2,&statbuf) < 0 ||
1691 (statbuf.st_mode & S_IFMT) != S_IFDIR )
1692 (void)UNLINK(tmps2);
1693 if (!(anum = link(tmps,tmps2)))
1694 anum = UNLINK(tmps);
1696 value = (double)(anum >= 0);
1701 tmps = str_get(st[1]);
1702 tmps2 = str_get(st[2]);
1704 taintproper("Insecure dependency in link");
1706 value = (double)(link(tmps,tmps2) >= 0);
1709 fatal("Unsupported function link");
1713 tmps = str_get(st[1]);
1714 anum = (int)str_gnum(st[2]);
1716 taintproper("Insecure dependency in mkdir");
1719 value = (double)(mkdir(tmps,anum) >= 0);
1722 (void)strcpy(buf,"mkdir ");
1724 #if !defined(MKDIR) || !defined(RMDIR)
1726 for (tmps2 = buf+6; *tmps; ) {
1730 (void)strcpy(tmps2," 2>&1");
1731 rsfp = mypopen(buf,"r");
1734 tmps2 = fgets(buf,sizeof buf,rsfp);
1735 (void)mypclose(rsfp);
1736 if (tmps2 != Nullch) {
1737 for (errno = 1; errno < sys_nerr; errno++) {
1738 if (instr(buf,sys_errlist[errno])) /* you don't see this */
1743 #define EACCES EPERM
1745 if (instr(buf,"cannot make"))
1747 else if (instr(buf,"existing file"))
1749 else if (instr(buf,"ile exists"))
1751 else if (instr(buf,"non-exist"))
1753 else if (instr(buf,"does not exist"))
1755 else if (instr(buf,"not empty"))
1757 else if (instr(buf,"cannot access"))
1763 else { /* some mkdirs return no failure indication */
1764 tmps = str_get(st[1]);
1765 anum = (stat(tmps,&statbuf) >= 0);
1766 if (optype == O_RMDIR)
1771 errno = EACCES; /* a guess */
1772 value = (double)anum;
1781 tmps = str_get(stab_val(defstab));
1783 tmps = str_get(st[1]);
1785 taintproper("Insecure dependency in rmdir");
1788 value = (double)(rmdir(tmps) >= 0);
1791 (void)strcpy(buf,"rmdir ");
1792 goto one_liner; /* see above in MKDIR */
1796 value = (double)getppid();
1799 fatal("Unsupported function getppid");
1807 anum = (int)str_gnum(st[1]);
1808 value = (double)getpgrp(anum);
1811 fatal("The getpgrp() function is unimplemented on this machine");
1816 argtype = (int)str_gnum(st[1]);
1817 anum = (int)str_gnum(st[2]);
1819 taintproper("Insecure dependency in setpgrp");
1821 value = (double)(setpgrp(argtype,anum) >= 0);
1824 fatal("The setpgrp() function is unimplemented on this machine");
1829 argtype = (int)str_gnum(st[1]);
1830 anum = (int)str_gnum(st[2]);
1831 value = (double)getpriority(argtype,anum);
1834 fatal("The getpriority() function is unimplemented on this machine");
1839 argtype = (int)str_gnum(st[1]);
1840 anum = (int)str_gnum(st[2]);
1841 optype = (int)str_gnum(st[3]);
1843 taintproper("Insecure dependency in setpriority");
1845 value = (double)(setpriority(argtype,anum,optype) >= 0);
1848 fatal("The setpriority() function is unimplemented on this machine");
1854 tmps = str_get(stab_val(defstab));
1856 tmps = str_get(st[1]);
1858 taintproper("Insecure dependency in chroot");
1860 value = (double)(chroot(tmps) >= 0);
1863 fatal("Unsupported function chroot");
1869 stab = last_in_stab;
1870 else if ((arg[1].arg_type & A_MASK) == A_WORD)
1871 stab = arg[1].arg_ptr.arg_stab;
1873 stab = stabent(str_get(st[1]),TRUE);
1874 argtype = U_I(str_gnum(st[2]));
1876 taintproper("Insecure dependency in ioctl");
1878 anum = do_ctl(optype,stab,argtype,st[3]);
1882 value = (double)anum;
1885 str_set(str,"0 but true");
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 if (stab && stab_io(stab))
1897 fp = stab_io(stab)->ifp;
1901 argtype = (int)str_gnum(st[2]);
1902 value = (double)(flock(fileno(fp),argtype) >= 0);
1908 fatal("The flock() function is unimplemented on this machine");
1912 ary = stab_array(arg[1].arg_ptr.arg_stab);
1913 if (arglast[2] - arglast[1] != 1)
1914 do_unshift(ary,arglast);
1916 STR *tmpstr = Str_new(52,0); /* must copy the STR */
1917 str_sset(tmpstr,st[2]);
1919 (void)astore(ary,0,tmpstr);
1921 value = (double)(ary->ary_fill + 1);
1928 tmpstr = stab_val(defstab);
1931 (arg[1].arg_type & A_MASK) != A_NULL ? st[1] : stab_val(defstab);
1933 tainted |= tmpstr->str_tainted;
1934 taintproper("Insecure dependency in eval");
1936 sp = do_eval(tmpstr, optype, curcmd->c_stash,
1964 if (mystat(arg,st[1]) < 0)
1966 if (cando(anum,argtype,&statcache))
1971 if (mystat(arg,st[1]) < 0)
1976 if (mystat(arg,st[1]) < 0)
1978 if (statcache.st_uid == (optype == O_FTEOWNED ? euid : uid) )
1982 if (mystat(arg,st[1]) < 0)
1984 if (!statcache.st_size)
1988 if (mystat(arg,st[1]) < 0)
1990 value = (double)statcache.st_size;
1994 if (mystat(arg,st[1]) < 0)
1996 value = (double)(basetime - statcache.st_mtime) / 86400.0;
1999 if (mystat(arg,st[1]) < 0)
2001 value = (double)(basetime - statcache.st_atime) / 86400.0;
2004 if (mystat(arg,st[1]) < 0)
2006 value = (double)(basetime - statcache.st_ctime) / 86400.0;
2012 goto check_file_type;
2018 goto check_file_type;
2022 goto check_file_type;
2028 goto check_file_type;
2032 if (mystat(arg,st[1]) < 0)
2034 if ((statcache.st_mode & S_IFMT) == anum )
2040 goto check_file_type;
2045 if (arg[1].arg_type & A_DONT)
2046 fatal("You must supply explicit filename with -l");
2048 if (lstat(str_get(st[1]),&statcache) < 0)
2050 if ((statcache.st_mode & S_IFMT) == S_IFLNK )
2056 tmps = str_get(st[1]);
2057 tmps2 = str_get(st[2]);
2059 taintproper("Insecure dependency in symlink");
2061 value = (double)(symlink(tmps,tmps2) >= 0);
2064 fatal("Unsupported function symlink");
2069 tmps = str_get(stab_val(defstab));
2071 tmps = str_get(st[1]);
2072 anum = readlink(tmps,buf,sizeof buf);
2075 str_nset(str,buf,anum);
2078 fatal("Unsupported function readlink");
2101 if (mystat(arg,st[1]) < 0)
2103 if (statcache.st_mode & anum)
2107 if (arg[1].arg_type & A_DONT) {
2108 stab = arg[1].arg_ptr.arg_stab;
2112 stab = stabent(tmps = str_get(st[1]),FALSE);
2113 if (stab && stab_io(stab) && stab_io(stab)->ifp)
2114 anum = fileno(stab_io(stab)->ifp);
2115 else if (isdigit(*tmps))
2124 str = do_fttext(arg,st[1]);
2128 if ((arg[1].arg_type & A_MASK) == A_WORD)
2129 stab = arg[1].arg_ptr.arg_stab;
2131 stab = stabent(str_get(st[1]),TRUE);
2133 value = (double)do_socket(stab,arglast);
2135 (void)do_socket(stab,arglast);
2139 if ((arg[1].arg_type & A_MASK) == A_WORD)
2140 stab = arg[1].arg_ptr.arg_stab;
2142 stab = stabent(str_get(st[1]),TRUE);
2144 value = (double)do_bind(stab,arglast);
2146 (void)do_bind(stab,arglast);
2150 if ((arg[1].arg_type & A_MASK) == A_WORD)
2151 stab = arg[1].arg_ptr.arg_stab;
2153 stab = stabent(str_get(st[1]),TRUE);
2155 value = (double)do_connect(stab,arglast);
2157 (void)do_connect(stab,arglast);
2161 if ((arg[1].arg_type & A_MASK) == A_WORD)
2162 stab = arg[1].arg_ptr.arg_stab;
2164 stab = stabent(str_get(st[1]),TRUE);
2166 value = (double)do_listen(stab,arglast);
2168 (void)do_listen(stab,arglast);
2172 if ((arg[1].arg_type & A_MASK) == A_WORD)
2173 stab = arg[1].arg_ptr.arg_stab;
2175 stab = stabent(str_get(st[1]),TRUE);
2176 if ((arg[2].arg_type & A_MASK) == A_WORD)
2177 stab2 = arg[2].arg_ptr.arg_stab;
2179 stab2 = stabent(str_get(st[2]),TRUE);
2180 do_accept(str,stab,stab2);
2188 sp = do_ghent(optype,
2196 sp = do_gnent(optype,
2204 sp = do_gpent(optype,
2212 sp = do_gsent(optype,
2216 value = (double) sethostent((int)str_gnum(st[1]));
2219 value = (double) setnetent((int)str_gnum(st[1]));
2222 value = (double) setprotoent((int)str_gnum(st[1]));
2225 value = (double) setservent((int)str_gnum(st[1]));
2228 value = (double) endhostent();
2231 value = (double) endnetent();
2234 value = (double) endprotoent();
2237 value = (double) endservent();
2240 if ((arg[1].arg_type & A_MASK) == A_WORD)
2241 stab = arg[1].arg_ptr.arg_stab;
2243 stab = stabent(str_get(st[1]),TRUE);
2244 if ((arg[2].arg_type & A_MASK) == A_WORD)
2245 stab2 = arg[2].arg_ptr.arg_stab;
2247 stab2 = stabent(str_get(st[2]),TRUE);
2249 value = (double)do_spair(stab,stab2,arglast);
2251 (void)do_spair(stab,stab2,arglast);
2255 if ((arg[1].arg_type & A_MASK) == A_WORD)
2256 stab = arg[1].arg_ptr.arg_stab;
2258 stab = stabent(str_get(st[1]),TRUE);
2260 value = (double)do_shutdown(stab,arglast);
2262 (void)do_shutdown(stab,arglast);
2267 if ((arg[1].arg_type & A_MASK) == A_WORD)
2268 stab = arg[1].arg_ptr.arg_stab;
2270 stab = stabent(str_get(st[1]),TRUE);
2271 sp = do_sopt(optype,stab,arglast);
2275 if ((arg[1].arg_type & A_MASK) == A_WORD)
2276 stab = arg[1].arg_ptr.arg_stab;
2278 stab = stabent(str_get(st[1]),TRUE);
2281 sp = do_getsockname(optype,stab,arglast);
2284 #else /* SOCKET not defined */
2317 fatal("Unsupported socket function");
2321 sp = do_select(gimme,arglast);
2324 fatal("select not implemented");
2329 if ((arg[1].arg_type & A_MASK) == A_WORD)
2330 stab = arg[1].arg_ptr.arg_stab;
2332 stab = stabent(str_get(st[1]),TRUE);
2333 if (!stab || !(stio = stab_io(stab)) || !(fp = stio->ifp))
2340 if ((arg[1].arg_type & A_MASK) == A_WORD)
2341 stab = arg[1].arg_ptr.arg_stab;
2343 stab = stabent(str_get(st[1]),TRUE);
2344 if (!stab || !(stio = stab_io(stab)) || !(fp = stio->ifp))
2347 str_set(str, (setmode(fileno(fp), O_BINARY) != -1) ? Yes : No);
2354 sp = do_vec(str == st[1], arg->arg_ptr.arg_str, arglast);
2360 sp = do_gpwent(optype,
2364 value = (double) setpwent();
2367 value = (double) endpwent();
2372 fatal("Unsupported password function");
2379 sp = do_ggrent(optype,
2383 value = (double) setgrent();
2386 value = (double) endgrent();
2391 fatal("Unsupported group function");
2396 if (!(tmps = getlogin()))
2400 fatal("Unsupported function getlogin");
2411 if ((arg[1].arg_type & A_MASK) == A_WORD)
2412 stab = arg[1].arg_ptr.arg_stab;
2414 stab = stabent(str_get(st[1]),TRUE);
2417 sp = do_dirop(optype,stab,gimme,arglast);
2420 value = (double)do_syscall(arglast);
2424 if ((arg[1].arg_type & A_MASK) == A_WORD)
2425 stab = arg[1].arg_ptr.arg_stab;
2427 stab = stabent(str_get(st[1]),TRUE);
2428 if ((arg[2].arg_type & A_MASK) == A_WORD)
2429 stab2 = arg[2].arg_ptr.arg_stab;
2431 stab2 = stabent(str_get(st[2]),TRUE);
2432 do_pipe(str,stab,stab2);
2435 fatal("Unsupported function pipe");
2446 deb("%s RETURNS \"%s\"\n",opname[optype],str_get(str));
2449 return arglast[0] + 1;
2456 anum = sp - arglast[0];
2459 deb("%s RETURNS ()\n",opname[optype]);
2462 deb("%s RETURNS (\"%s\")\n",opname[optype],str_get(st[1]));
2465 tmps = str_get(st[1]);
2466 deb("%s RETURNS %d ARGS (\"%s\",%s\"%s\")\n",opname[optype],
2467 anum,tmps,anum==2?"":"...,",str_get(st[anum]));
2492 str_numset(str,value);
2499 deb("%s RETURNS \"%f\"\n",opname[optype],value);
2502 return arglast[0] + 1;