1 /***********************************************************
3 * $Header: /usr/src/local/lwall/perl5/RCS/pp.c, v 4.1 92/08/07 18:26:21 lwall Exp Locker: lwall $
11 * Mon Jun 15 16:45:59 1992
14 * Larry Wall <lwall@netlabs.com>
17 * Revision 4.1 92/08/07 18:26:21 lwall
20 **********************************************************/
26 # include <sys/socket.h>
30 # include <net/errno.h>
38 #include <sys/select.h>
51 struct passwd *getpwnam P((char *));
52 struct passwd *getpwuid P((Uid_t));
54 struct passwd *getpwent();
61 struct group *getgrnam P((char *));
62 struct group *getgrgid P((Gid_t));
64 struct group *getgrent();
78 # define getpgrp getpgrp2
82 # define setpgrp setpgrp2
86 # define getpgrp getpgrp2
90 # define setpgrp setpgrp2
94 # define getpgrp getpgrp2
98 # define setpgrp setpgrp2
101 static I32 dopoptosub P((I32 startingblock));
113 if (GIMME != G_ARRAY) {
128 if (++markstack_ptr == markstack_max) {
129 I32 oldmax = markstack_max - markstack;
130 I32 newmax = oldmax * 3 / 2;
132 Renew(markstack, newmax, I32);
133 markstack_ptr = markstack + oldmax;
134 markstack_max = markstack + newmax;
136 *markstack_ptr = stack_sp - stack_base;
146 cxix = dopoptosub(cxstack_ix);
150 if (cxstack[cxix].blk_gimme == G_ARRAY)
159 XPUSHs(cSVOP->op_sv);
189 DIE("panic: pp_interp");
196 if (op->op_flags & OPf_INTRO)
197 PUSHs(save_scalar(cGVOP->op_gv));
199 PUSHs(GvSV(cGVOP->op_gv));
206 XPUSHs((SV*)cGVOP->op_gv);
214 if (op->op_flags & OPf_INTRO)
215 SAVECLEARSV(curpad[op->op_targ]);
222 if (op->op_flags & OPf_INTRO)
223 SAVECLEARSV(curpad[op->op_targ]);
225 if (op->op_flags & OPf_LVAL) {
229 if (GIMME == G_ARRAY) {
230 I32 maxarg = AvFILL((AV*)TARG) + 1;
232 Copy(AvARRAY((AV*)TARG), SP+1, maxarg, SV*);
236 SV* sv = sv_newmortal();
237 I32 maxarg = AvFILL((AV*)TARG) + 1;
238 sv_setiv(sv, maxarg);
248 if (op->op_flags & OPf_INTRO)
249 SAVECLEARSV(curpad[op->op_targ]);
250 if (op->op_flags & OPf_LVAL)
252 if (GIMME == G_ARRAY) { /* array wanted */
256 SV* sv = sv_newmortal();
257 if (HvFILL((HV*)TARG)) {
258 sprintf(buf, "%d/%d", HvFILL((HV*)TARG), HvMAX((HV*)TARG)+1);
270 DIE("NOT IMPL LINE %d",__LINE__);
287 if (SvTYPE(sv) != SVt_PVGV)
288 DIE("Not a symbol reference");
291 if (SvTYPE(sv) != SVt_PVGV) {
293 DIE(no_usym, "a symbol");
294 if (op->op_private & HINT_STRICT_REFS)
295 DIE(no_hardref, "a symbol");
296 sv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE, SVt_PVGV);
299 if (op->op_flags & OPf_INTRO) {
307 if (op->op_flags & OPf_SPECIAL)
308 GvGP(sv)->gp_refcnt++; /* will soon be assigned */
314 GvSV(sv) = NEWSV(72,0);
315 GvLINE(sv) = curcop->cop_line;
337 switch (SvTYPE(sv)) {
341 DIE("Not a scalar reference");
346 if (SvTYPE(gv) != SVt_PVGV) {
348 DIE(no_usym, "a scalar");
349 if (op->op_private & HINT_STRICT_REFS)
350 DIE(no_hardref, "a scalar");
351 gv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE, SVt_PV);
354 if (op->op_private & (OPpDEREF_AV|OPpDEREF_HV)) {
355 if (op->op_private & OPpDEREF_HV &&
356 (!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV)) {
357 if (op->op_private & HINT_STRICT_REFS && !SvROK(sv) && SvOK(sv))
358 DIE(no_hardref, "a hash");
361 sv_upgrade(sv, SVt_RV);
362 SvRV(sv) = SvREFCNT_inc(newHV());
367 else if (op->op_private & OPpDEREF_AV &&
368 (!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV)) {
369 if (op->op_private & HINT_STRICT_REFS && !SvROK(sv) && SvOK(sv))
370 DIE(no_hardref, "an array");
373 sv_upgrade(sv, SVt_RV);
374 SvRV(sv) = SvREFCNT_inc(newAV());
381 if (op->op_flags & OPf_INTRO)
382 SETs(save_scalar((GV*)TOPs));
392 SV *sv = AvARYLEN(av);
394 AvARYLEN(av) = sv = NEWSV(0,0);
395 sv_upgrade(sv, SVt_IV);
396 sv_magic(sv, (SV*)av, '#', Nullch, 0);
409 /* We always try to add a non-existent subroutine in case of AUTOLOAD. */
410 CV *cv = sv_2cv(TOPs, &stash, &gv, TRUE);
423 sv_upgrade(rv, SVt_RV);
424 SvRV(rv) = SvREFCNT_inc(sv);
448 pv = HvNAME(SvSTASH(sv));
450 switch (SvTYPE(sv)) {
465 case SVt_PVLV: pv = "LVALUE"; break;
466 case SVt_PVAV: pv = "ARRAY"; break;
467 case SVt_PVHV: pv = "HASH"; break;
468 case SVt_PVCV: pv = "CODE"; break;
469 case SVt_PVGV: pv = "GLOB"; break;
470 case SVt_PVFM: pv = "FORMLINE"; break;
471 default: pv = "UNKNOWN"; break;
474 PUSHp(pv, strlen(pv));
486 stash = curcop->cop_stash;
488 stash = fetch_stash(POPs, TRUE);
492 DIE("Can't bless non-reference value");
495 SvUPGRADE(ref, SVt_PVMG);
496 SvSTASH(ref) = (HV*)SvREFCNT_inc(stash);
508 fp = my_popen(tmps, "r");
510 sv_setpv(TARG, ""); /* note that this preserves previous buffer */
511 if (GIMME == G_SCALAR) {
512 while (sv_gets(TARG, fp, SvCUR(TARG)) != Nullch)
522 if (sv_gets(sv, fp, 0) == Nullch) {
526 XPUSHs(sv_2mortal(sv));
527 if (SvLEN(sv) - SvCUR(sv) > 20) {
528 SvLEN_set(sv, SvCUR(sv)+1);
529 Renew(SvPVX(sv), SvLEN(sv), char);
533 statusvalue = my_pclose(fp);
537 if (GIMME == G_SCALAR)
552 register IO *io = GvIO(last_in_gv);
553 register I32 type = op->op_type;
559 if (IoFLAGS(io) & IOf_ARGV) {
560 if (IoFLAGS(io) & IOf_START) {
561 IoFLAGS(io) &= ~IOf_START;
563 if (av_len(GvAVn(last_in_gv)) < 0) {
564 SV *tmpstr = newSVpv("-", 1); /* assume stdin */
565 (void)av_push(GvAVn(last_in_gv), tmpstr);
568 fp = nextargv(last_in_gv);
569 if (!fp) { /* Note: fp != IoIFP(io) */
570 (void)do_close(last_in_gv, FALSE); /* now it does*/
571 IoFLAGS(io) |= IOf_START;
574 else if (type == OP_GLOB) {
575 SV *tmpcmd = NEWSV(55, 0);
580 sv_setpv(tmpcmd, "perlglob ");
581 sv_catsv(tmpcmd, tmpglob);
582 sv_catpv(tmpcmd, " |");
585 sv_setpvn(tmpcmd, cshname, cshlen);
586 sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
587 sv_catsv(tmpcmd, tmpglob);
588 sv_catpv(tmpcmd, "'|");
590 sv_setpv(tmpcmd, "echo ");
591 sv_catsv(tmpcmd, tmpglob);
592 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
595 (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd));
600 else if (type == OP_GLOB)
605 warn("Read on closed filehandle <%s>", GvENAME(last_in_gv));
606 if (GIMME == G_SCALAR)
610 if (GIMME == G_ARRAY) {
611 sv = sv_2mortal(NEWSV(57, 80));
616 SvUPGRADE(sv, SVt_PV);
617 tmplen = SvLEN(sv); /* remember if already alloced */
619 Sv_Grow(sv, 80); /* try short-buffering it */
620 if (type == OP_RCATLINE)
626 if (!sv_gets(sv, fp, offset)) {
628 if (IoFLAGS(io) & IOf_ARGV) {
629 fp = nextargv(last_in_gv);
632 (void)do_close(last_in_gv, FALSE);
633 IoFLAGS(io) |= IOf_START;
635 else if (type == OP_GLOB) {
636 (void)do_close(last_in_gv, FALSE);
638 if (GIMME == G_SCALAR)
646 SvTAINT(sv); /* Anything from the outside world...*/
648 if (type == OP_GLOB) {
653 if (*SvEND(sv) == rschar)
657 for (tmps = SvPVX(sv); *tmps; tmps++)
658 if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
659 strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
661 if (*tmps && stat(SvPVX(sv), &statbuf) < 0) {
662 POPs; /* Unmatched wildcard? Chuck it... */
666 if (GIMME == G_ARRAY) {
667 if (SvLEN(sv) - SvCUR(sv) > 20) {
668 SvLEN_set(sv, SvCUR(sv)+1);
669 Renew(SvPVX(sv), SvLEN(sv), char);
671 sv = sv_2mortal(NEWSV(58, 80));
674 else if (!tmplen && SvLEN(sv) - SvCUR(sv) > 80) {
675 /* try to reclaim a bit of scalar space (only on 1st alloc) */
679 SvLEN_set(sv, SvCUR(sv)+40); /* allow some slop */
680 Renew(SvPVX(sv), SvLEN(sv), char);
693 SAVESPTR(last_in_gv); /* We don't want this to be permanent. */
694 last_in_gv = (GV*)*stack_sp--;
706 result = do_readline();
713 last_in_gv = (GV*)(*stack_sp--);
714 return do_readline();
719 last_in_gv = gv_fetchpv(SvPVx(GvSV((GV*)(*stack_sp--)), na), TRUE,SVt_PVIO);
720 return do_readline();
725 last_in_gv = cGVOP->op_gv;
726 return do_readline();
736 register PMOP *pm = (PMOP*)cLOGOP->op_other;
742 t = SvPV(tmpstr, len);
744 if (pm->op_pmregexp) {
745 regfree(pm->op_pmregexp);
746 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
749 pm->op_pmregexp = regcomp(t, t + len, pm->op_pmflags & PMf_FOLD);
751 if (!pm->op_pmregexp->prelen && curpm)
753 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
754 pm->op_pmflags |= PMf_WHITE;
756 if (pm->op_pmflags & PMf_KEEP) {
757 if (!(pm->op_pmflags & PMf_FOLD))
758 scan_prefix(pm, pm->op_pmregexp->precomp,
759 pm->op_pmregexp->prelen);
760 pm->op_pmflags &= ~PMf_RUNTIME; /* no point compiling again */
762 cLOGOP->op_first->op_next = op->op_next;
763 /* XXX delete push code? */
771 register PMOP *pm = cPMOP;
779 register REGEXP *rx = pm->op_pmregexp;
783 if (op->op_flags & OPf_STACKED)
792 DIE("panic: do_match");
794 if (pm->op_pmflags & PMf_USED) {
795 if (gimme == G_ARRAY)
800 if (!rx->prelen && curpm) {
802 rx = pm->op_pmregexp;
805 if (global = pm->op_pmflags & PMf_GLOBAL) {
807 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
808 MAGIC* mg = mg_find(TARG, 'g');
809 if (mg && mg->mg_ptr) {
810 rx->startp[0] = mg->mg_ptr;
811 rx->endp[0] = mg->mg_ptr + mg->mg_len;
815 safebase = (gimme == G_ARRAY) || global;
818 if (global && rx->startp[0]) {
820 if (s == rx->startp[0])
825 if (pm->op_pmshort) {
826 if (pm->op_pmflags & PMf_SCANFIRST) {
827 if (SvSCREAM(TARG)) {
828 if (screamfirst[BmRARE(pm->op_pmshort)] < 0)
830 else if (!(s = screaminstr(TARG, pm->op_pmshort)))
832 else if (pm->op_pmflags & PMf_ALL)
835 else if (!(s = fbm_instr((unsigned char*)s,
836 (unsigned char*)strend, pm->op_pmshort)))
838 else if (pm->op_pmflags & PMf_ALL)
840 if (s && rx->regback >= 0) {
841 ++BmUSEFUL(pm->op_pmshort);
849 else if (!multiline) {
850 if (*SvPVX(pm->op_pmshort) != *s ||
851 bcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) ) {
852 if (pm->op_pmflags & PMf_FOLD) {
853 if (ibcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) )
860 if (--BmUSEFUL(pm->op_pmshort) < 0) {
861 SvREFCNT_dec(pm->op_pmshort);
862 pm->op_pmshort = Nullsv; /* opt is being useless */
865 if (!rx->nparens && !global) {
866 gimme = G_SCALAR; /* accidental array context? */
869 if (regexec(rx, s, strend, truebase, 0,
870 SvSCREAM(TARG) ? TARG : Nullsv,
873 if (pm->op_pmflags & PMf_ONCE)
874 pm->op_pmflags |= PMf_USED;
882 if (gimme == G_ARRAY) {
886 if (global && !iters)
890 EXTEND(SP, iters + i);
891 for (i = !i; i <= iters; i++) {
892 PUSHs(sv_newmortal());
894 if (s = rx->startp[i]) {
895 len = rx->endp[i] - s;
897 sv_setpvn(*SP, s, len);
901 truebase = rx->subbeg;
909 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
910 mg = mg_find(TARG, 'g');
912 sv_magic(TARG, (SV*)0, 'g', Nullch, 0);
913 mg = mg_find(TARG, 'g');
915 mg->mg_ptr = rx->startp[0];
916 mg->mg_len = rx->endp[0] - rx->startp[0];
922 ++BmUSEFUL(pm->op_pmshort);
924 if (pm->op_pmflags & PMf_ONCE)
925 pm->op_pmflags |= PMf_USED;
927 rx->subbeg = truebase;
930 rx->endp[0] = s + SvCUR(pm->op_pmshort);
937 Safefree(rx->subbase);
938 tmps = rx->subbase = nsavestr(t, strend-t);
940 rx->subend = tmps + (strend-t);
941 tmps = rx->startp[0] = tmps + (s - t);
942 rx->endp[0] = tmps + SvCUR(pm->op_pmshort);
948 ++BmUSEFUL(pm->op_pmshort);
952 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
953 MAGIC* mg = mg_find(TARG, 'g');
960 if (gimme == G_ARRAY)
968 register PMOP *pm = cPMOP;
983 register REGEXP *rx = pm->op_pmregexp;
986 if (pm->op_pmflags & PMf_CONST) /* known replacement string? */
988 if (op->op_flags & OPf_STACKED)
996 DIE("panic: do_subst");
999 maxiters = (strend - s) + 10;
1001 if (!rx->prelen && curpm) {
1003 rx = pm->op_pmregexp;
1005 safebase = ((!rx || !rx->nparens) && !sawampersand);
1007 if (pm->op_pmshort) {
1008 if (pm->op_pmflags & PMf_SCANFIRST) {
1009 if (SvSCREAM(TARG)) {
1010 if (screamfirst[BmRARE(pm->op_pmshort)] < 0)
1012 else if (!(s = screaminstr(TARG, pm->op_pmshort)))
1015 else if (!(s = fbm_instr((unsigned char*)s, (unsigned char*)strend,
1018 if (s && rx->regback >= 0) {
1019 ++BmUSEFUL(pm->op_pmshort);
1027 else if (!multiline) {
1028 if (*SvPVX(pm->op_pmshort) != *s ||
1029 bcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) ) {
1030 if (pm->op_pmflags & PMf_FOLD) {
1031 if (ibcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) )
1038 if (--BmUSEFUL(pm->op_pmshort) < 0) {
1039 SvREFCNT_dec(pm->op_pmshort);
1040 pm->op_pmshort = Nullsv; /* opt is being useless */
1043 once = !(rpm->op_pmflags & PMf_GLOBAL);
1044 if (rpm->op_pmflags & PMf_CONST) { /* known replacement string? */
1045 c = SvPV(dstr, clen);
1046 if (clen <= rx->minlen) {
1047 /* can do inplace substitution */
1048 if (regexec(rx, s, strend, orig, 0,
1049 SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
1050 if (rx->subbase) /* oops, no we can't */
1054 SvSCREAM_off(TARG); /* disable possible screamer */
1059 if (m - s > strend - d) { /* faster to shorten from end */
1061 Copy(c, m, clen, char);
1066 Move(d, m, i, char);
1070 SvCUR_set(TARG, m - s);
1077 else if (i = m - s) { /* faster from front */
1085 Copy(c, m, clen, char);
1094 Copy(c, d, clen, char);
1110 if (iters++ > maxiters)
1111 DIE("Substitution loop");
1116 Move(s, d, i, char);
1120 Copy(c, d, clen, char);
1124 } while (regexec(rx, s, strend, orig, s == m,
1125 Nullsv, TRUE)); /* (don't match same null twice) */
1128 SvCUR_set(TARG, d - SvPVX(TARG) + i);
1129 Move(s, d, i+1, char); /* include the Null */
1133 PUSHs(sv_2mortal(newSViv((I32)iters)));
1142 if (regexec(rx, s, strend, orig, 0,
1143 SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
1145 dstr = NEWSV(25, sv_len(TARG));
1146 sv_setpvn(dstr, m, s-m);
1149 register CONTEXT *cx;
1151 RETURNOP(cPMOP->op_pmreplroot);
1154 if (iters++ > maxiters)
1155 DIE("Substitution loop");
1156 if (rx->subbase && rx->subbase != orig) {
1161 strend = s + (strend - m);
1164 sv_catpvn(dstr, s, m-s);
1167 sv_catpvn(dstr, c, clen);
1170 } while (regexec(rx, s, strend, orig, s == m, Nullsv,
1172 sv_catpvn(dstr, s, strend - s);
1173 sv_replace(TARG, dstr);
1176 PUSHs(sv_2mortal(newSViv((I32)iters)));
1183 ++BmUSEFUL(pm->op_pmshort);
1191 register PMOP *pm = (PMOP*) cLOGOP->op_other;
1192 register CONTEXT *cx = &cxstack[cxstack_ix];
1193 register SV *dstr = cx->sb_dstr;
1194 register char *s = cx->sb_s;
1195 register char *m = cx->sb_m;
1196 char *orig = cx->sb_orig;
1197 register REGEXP *rx = pm->op_pmregexp;
1199 if (cx->sb_iters++) {
1200 if (cx->sb_iters > cx->sb_maxiters)
1201 DIE("Substitution loop");
1203 sv_catsv(dstr, POPs);
1205 Safefree(rx->subbase);
1206 rx->subbase = cx->sb_subbase;
1209 if (cx->sb_once || !regexec(rx, s, cx->sb_strend, orig,
1210 s == m, Nullsv, cx->sb_safebase))
1212 SV *targ = cx->sb_targ;
1213 sv_catpvn(dstr, s, cx->sb_strend - s);
1214 sv_replace(targ, dstr);
1217 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
1219 RETURNOP(pm->op_next);
1222 if (rx->subbase && rx->subbase != orig) {
1225 cx->sb_orig = orig = rx->subbase;
1227 cx->sb_strend = s + (cx->sb_strend - m);
1229 cx->sb_m = m = rx->startp[0];
1230 sv_catpvn(dstr, s, m-s);
1231 cx->sb_s = rx->endp[0];
1232 cx->sb_subbase = rx->subbase;
1234 rx->subbase = Nullch; /* so recursion works */
1235 RETURNOP(pm->op_pmreplstart);
1243 if (op->op_flags & OPf_STACKED)
1250 PUSHi(do_trans(sv, op));
1254 /* Lvalue operators. */
1259 if (tainting && tainted && (!SvRMAGICAL(lstr) || !mg_find(lstr, 't'))) {
1262 SvSetSV(rstr, lstr);
1271 SV **lastlelem = stack_sp;
1272 SV **lastrelem = stack_base + POPMARK;
1273 SV **firstrelem = stack_base + POPMARK + 1;
1274 SV **firstlelem = lastrelem + 1;
1276 register SV **relem;
1277 register SV **lelem;
1286 delaymagic = DM_DELAY; /* catch simultaneous items */
1288 /* If there's a common identifier on both sides we have to take
1289 * special care that assigning the identifier on the left doesn't
1290 * clobber a value on the right that's used later in the list.
1292 if (op->op_private & OPpASSIGN_COMMON) {
1293 for (relem = firstrelem; relem <= lastrelem; relem++) {
1296 *relem = sv_mortalcopy(sv);
1304 while (lelem <= lastlelem) {
1306 switch (SvTYPE(sv)) {
1309 magic = SvSMAGICAL(ary) != 0;
1313 while (relem <= lastrelem) { /* gobble up all the rest */
1316 sv_setsv(sv,*relem);
1318 (void)av_store(ary,i++,sv);
1328 magic = SvSMAGICAL(hash) != 0;
1331 while (relem < lastrelem) { /* gobble up all the rest */
1336 sv = &sv_no, relem++;
1337 tmps = SvPV(sv, len);
1338 tmpstr = NEWSV(29,0);
1340 sv_setsv(tmpstr,*relem); /* value */
1341 *(relem++) = tmpstr;
1342 (void)hv_store(hash,tmps,len,tmpstr,0);
1349 if (SvTHINKFIRST(sv)) {
1350 if (SvREADONLY(sv) && curcop != &compiling) {
1351 if (sv != &sv_undef && sv != &sv_yes && sv != &sv_no)
1353 if (relem <= lastrelem)
1360 if (relem <= lastrelem) {
1361 sv_setsv(sv, *relem);
1365 sv_setsv(sv, &sv_undef);
1370 if (delaymagic & ~DM_DELAY) {
1371 if (delaymagic & DM_UID) {
1372 #ifdef HAS_SETRESUID
1373 (void)setresuid(uid,euid,(Uid_t)-1);
1374 #else /* not HAS_SETRESUID */
1376 (void)setreuid(uid,euid);
1377 #else /* not HAS_SETREUID */
1379 if ((delaymagic & DM_UID) == DM_RUID) {
1381 delaymagic =~ DM_RUID;
1383 #endif /* HAS_SETRUID */
1384 #endif /* HAS_SETRESUID */
1386 if ((delaymagic & DM_UID) == DM_EUID) {
1388 delaymagic =~ DM_EUID;
1390 #endif /* HAS_SETEUID */
1391 if (delaymagic & DM_UID) {
1393 DIE("No setreuid available");
1396 #endif /* not HAS_SETREUID */
1397 uid = (int)getuid();
1398 euid = (int)geteuid();
1400 if (delaymagic & DM_GID) {
1401 #ifdef HAS_SETRESGID
1402 (void)setresgid(gid,egid,(Gid_t)-1);
1403 #else /* not HAS_SETREGID */
1405 (void)setregid(gid,egid);
1406 #else /* not HAS_SETREGID */
1407 #endif /* not HAS_SETRESGID */
1409 if ((delaymagic & DM_GID) == DM_RGID) {
1411 delaymagic =~ DM_RGID;
1413 #endif /* HAS_SETRGID */
1414 #ifdef HAS_SETRESGID
1415 (void)setresgid(gid,egid,(Gid_t)-1);
1416 #else /* not HAS_SETREGID */
1418 if ((delaymagic & DM_GID) == DM_EGID) {
1420 delaymagic =~ DM_EGID;
1422 #endif /* HAS_SETEGID */
1423 if (delaymagic & DM_GID) {
1425 DIE("No setregid available");
1428 #endif /* not HAS_SETRESGID */
1429 #endif /* not HAS_SETREGID */
1430 gid = (int)getgid();
1431 egid = (int)getegid();
1433 tainting |= (euid != uid || egid != gid);
1436 if (GIMME == G_ARRAY) {
1440 SP = firstrelem + (lastlelem - firstlelem);
1446 SETi(lastrelem - firstrelem + 1);
1467 dSP; dMARK; dTARGET;
1469 do_chop(TARG, POPs);
1485 if (!sv || !SvANY(sv))
1487 switch (SvTYPE(sv)) {
1512 if (!op->op_private)
1519 if (SvTHINKFIRST(sv)) {
1526 switch (SvTYPE(sv)) {
1540 if (sv != GvSV(defgv)) {
1541 if (SvPOK(sv) && SvLEN(sv)) {
1543 Safefree(SvPVX(sv));
1544 SvPV_set(sv, Nullch);
1558 register unsigned char *s;
1561 register I32 *sfirst;
1562 register I32 *snext;
1566 s = (unsigned char*)(SvPV(TARG, len));
1569 SvSCREAM_off(lastscream);
1575 if (pos > maxscream) {
1576 if (maxscream < 0) {
1577 maxscream = pos + 80;
1578 New(301, screamfirst, 256, I32);
1579 New(302, screamnext, maxscream, I32);
1582 maxscream = pos + pos / 4;
1583 Renew(screamnext, maxscream, I32);
1587 sfirst = screamfirst;
1590 if (!sfirst || !snext)
1591 DIE("do_study: out of memory");
1593 for (ch = 256; ch; --ch)
1597 while (--pos >= 0) {
1599 if (sfirst[ch] >= 0)
1600 snext[pos] = sfirst[ch] - pos;
1605 /* If there were any case insensitive searches, we must assume they
1606 * all are. This speeds up insensitive searches much more than
1607 * it slows down sensitive ones.
1610 sfirst[fold[ch]] = pos;
1616 XPUSHs(sv_2mortal(newSViv((I32)retval)));
1639 sv_setsv(TARG, TOPs);
1651 sv_setsv(TARG, TOPs);
1658 /* Ordinary operators. */
1662 dSP; dATARGET; dPOPTOPnnrl;
1663 SETn( pow( left, right) );
1669 dSP; dATARGET; dPOPTOPnnrl;
1670 SETn( left * right );
1676 dSP; dATARGET; dPOPnv;
1678 DIE("Illegal division by zero");
1680 /* insure that 20./5. == 4. */
1685 if ((double)(I32)x == x &&
1686 (double)(I32)value == value &&
1687 (k = (I32)x/(I32)value)*(I32)value == (I32)x) {
1694 value = POPn / value;
1703 register unsigned long tmpulong;
1704 register long tmplong;
1707 tmpulong = (unsigned long) POPn;
1709 DIE("Illegal modulus zero");
1712 value = (I32)(((unsigned long)value) % tmpulong);
1714 tmplong = (long)value;
1715 value = (I32)(tmpulong - ((-tmplong - 1) % tmpulong)) - 1;
1724 register I32 count = POPi;
1725 if (GIMME == G_ARRAY && op->op_private & OPpREPEAT_DOLIST) {
1727 I32 items = SP - MARK;
1730 max = items * count;
1739 repeatcpy((char*)(MARK + items), (char*)MARK,
1740 items * sizeof(SV*), count - 1);
1744 else { /* Note: mark already snarfed by pp_list */
1749 if (TARG == tmpstr && SvTHINKFIRST(tmpstr)) {
1750 if (SvREADONLY(tmpstr) && curcop != &compiling)
1751 DIE("Can't x= to readonly value");
1755 SvSetSV(TARG, tmpstr);
1759 tmpstr = NEWSV(50, 0);
1760 tmps = SvPV(TARG, len);
1761 sv_setpvn(tmpstr, tmps, len);
1762 tmps = SvPV(tmpstr, tlen); /* force to be string */
1763 SvGROW(TARG, (count * len) + 1);
1764 repeatcpy((char*)SvPVX(TARG), tmps, tlen, count);
1765 SvCUR(TARG) *= count;
1766 *SvEND(TARG) = '\0';
1768 SvREFCNT_dec(tmpstr);
1771 sv_setsv(TARG, &sv_no);
1779 dSP; dATARGET; dPOPTOPnnrl;
1780 SETn( left + right );
1786 dSP; dATARGET; dPOPTOPnnrl;
1787 SETn( left - right );
1793 dSP; dATARGET; dPOPTOPssrl;
1798 sv_setpvn(TARG,s,len);
1801 sv_catpvn(TARG,s,len);
1808 dSP; dATARGET; dPOPTOPiirl;
1809 SETi( left << right );
1815 dSP; dATARGET; dPOPTOPiirl;
1816 SETi( left >> right );
1823 SETs((TOPn < value) ? &sv_yes : &sv_no);
1830 SETs((TOPn > value) ? &sv_yes : &sv_no);
1837 SETs((TOPn <= value) ? &sv_yes : &sv_no);
1844 SETs((TOPn >= value) ? &sv_yes : &sv_no);
1851 SETs((TOPn == value) ? &sv_yes : &sv_no);
1858 SETs((TOPn != value) ? &sv_yes : &sv_no);
1864 dSP; dTARGET; dPOPTOPnnrl;
1869 else if (left < right)
1880 SETs( sv_cmp(lstr, rstr) < 0 ? &sv_yes : &sv_no );
1887 SETs( sv_cmp(lstr, rstr) > 0 ? &sv_yes : &sv_no );
1894 SETs( sv_cmp(lstr, rstr) <= 0 ? &sv_yes : &sv_no );
1901 SETs( sv_cmp(lstr, rstr) >= 0 ? &sv_yes : &sv_no );
1908 SETs( sv_eq(lstr, rstr) ? &sv_yes : &sv_no );
1915 SETs( !sv_eq(lstr, rstr) ? &sv_yes : &sv_no );
1923 SETi( sv_cmp(lstr, rstr) );
1928 dSP; dATARGET; dPOPTOPssrl;
1929 if (SvNIOK(lstr) || SvNIOK(rstr)) {
1930 unsigned long value = U_L(SvNV(lstr));
1931 value = value & U_L(SvNV(rstr));
1932 SETn((double)value);
1935 do_vop(op->op_type, TARG, lstr, rstr);
1943 dSP; dATARGET; dPOPTOPssrl;
1944 if (SvNIOK(lstr) || SvNIOK(rstr)) {
1945 unsigned long value = U_L(SvNV(lstr));
1946 value = value ^ U_L(SvNV(rstr));
1947 SETn((double)value);
1950 do_vop(op->op_type, TARG, lstr, rstr);
1958 dSP; dATARGET; dPOPTOPssrl;
1959 if (SvNIOK(lstr) || SvNIOK(rstr)) {
1960 unsigned long value = U_L(SvNV(lstr));
1961 value = value | U_L(SvNV(rstr));
1962 SETn((double)value);
1965 do_vop(op->op_type, TARG, lstr, rstr);
1980 *stack_sp = SvTRUE(*stack_sp) ? &sv_no : &sv_yes;
1986 dSP; dTARGET; dTOPss;
1993 register char *tmps;
1994 register long *tmpl;
1998 tmps = SvPV(TARG, len);
2001 for ( ; anum && (unsigned long)tmps % sizeof(long); anum--, tmps++)
2004 for ( ; anum >= sizeof(long); anum -= sizeof(long), tmpl++)
2008 for ( ; anum > 0; anum--, tmps++)
2016 /* integer versions of some of the above */
2021 sv_setiv(TOPs, value + 1);
2029 sv_setiv(TOPs, value - 1);
2037 sv_setsv(TARG, TOPs);
2038 sv_setiv(TOPs, SvIV(TOPs) + 1);
2049 sv_setsv(TARG, TOPs);
2050 sv_setiv(TOPs, SvIV(TOPs) - 1);
2058 dSP; dATARGET; dPOPTOPiirl;
2059 SETi( left * right );
2065 dSP; dATARGET; dPOPiv;
2067 DIE("Illegal division by zero");
2068 value = POPi / value;
2075 dSP; dATARGET; dPOPTOPiirl;
2076 SETi( left % right );
2082 dSP; dATARGET; dPOPTOPiirl;
2083 SETi( left + right );
2089 dSP; dATARGET; dPOPTOPiirl;
2090 SETi( left - right );
2097 SETs((left < right) ? &sv_yes : &sv_no);
2104 SETs((left > right) ? &sv_yes : &sv_no);
2111 SETs((left <= right) ? &sv_yes : &sv_no);
2118 SETs((left >= right) ? &sv_yes : &sv_no);
2125 SETs((left == right) ? &sv_yes : &sv_no);
2132 SETs((left != right) ? &sv_yes : &sv_no);
2138 dSP; dTARGET; dPOPTOPiirl;
2143 else if (left < right)
2158 /* High falutin' math. */
2162 dSP; dTARGET; dPOPTOPnnrl;
2163 SETn(atan2(left, right));
2172 value = SvNVx(GvSV(defgv));
2185 value = SvNVx(GvSV(defgv));
2204 value = rand() * value / 2147483648.0;
2207 value = rand() * value / 65536.0;
2210 value = rand() * value / 32768.0;
2212 value = rand() * value / (double)(((unsigned long)1) << RANDBITS);
2242 value = SvNVx(GvSV(defgv));
2255 value = SvNVx(GvSV(defgv));
2259 DIE("Can't take log of %g", value);
2270 value = SvNVx(GvSV(defgv));
2274 DIE("Can't take sqrt of %g", value);
2275 value = sqrt(value);
2285 value = SvNVx(GvSV(defgv));
2289 (void)modf(value, &value);
2291 (void)modf(-value, &value);
2303 value = SvNVx(GvSV(defgv));
2321 tmps = SvPVx(GvSV(defgv), na);
2324 XPUSHi( scan_hex(tmps, 99, &argtype) );
2336 tmps = SvPVx(GvSV(defgv), na);
2339 while (*tmps && (isSPACE(*tmps) || *tmps == '0'))
2342 value = (I32)scan_hex(++tmps, 99, &argtype);
2344 value = (I32)scan_oct(tmps, 99, &argtype);
2355 XPUSHi( sv_len(GvSV(defgv)) );
2358 SETi( sv_len(TOPs) );
2370 I32 lvalue = op->op_flags & OPf_LVAL;
2375 pos = POPi - arybase;
2377 tmps = SvPV(sv, curlen); /* force conversion to string */
2379 pos += curlen + arybase;
2380 if (pos < 0 || pos > curlen) {
2382 warn("substr outside of string");
2391 rem = curlen - pos; /* rem=how many bytes left*/
2394 sv_setpvn(TARG, tmps, rem);
2395 if (lvalue) { /* it's an lvalue! */
2396 if (SvTHINKFIRST(sv)) {
2397 if (SvREADONLY(sv) && curcop != &compiling)
2400 DIE("Can't modify substr of a reference");
2404 LvTARGOFF(TARG) = tmps - SvPV(sv, na);
2405 LvTARGLEN(TARG) = rem;
2408 PUSHs(TARG); /* avoid SvSETMAGIC here */
2415 register I32 size = POPi;
2416 register I32 offset = POPi;
2417 register SV *src = POPs;
2418 I32 lvalue = op->op_flags & OPf_LVAL;
2420 unsigned char *s = (unsigned char*)SvPV(src, srclen);
2421 unsigned long retnum;
2424 offset *= size; /* turn into bit offset */
2425 len = (offset + size + 7) / 8;
2426 if (offset < 0 || size < 1)
2428 else if (!lvalue && len > srclen)
2433 (void)memzero(SvPVX(src) + srclen, len - srclen);
2434 SvCUR_set(src, len);
2436 s = (unsigned char*)SvPV(src, na);
2438 retnum = (s[offset >> 3] >> (offset & 7)) & ((1 << size) - 1);
2443 else if (size == 16)
2444 retnum = ((unsigned long) s[offset] << 8) + s[offset+1];
2445 else if (size == 32)
2446 retnum = ((unsigned long) s[offset] << 24) +
2447 ((unsigned long) s[offset + 1] << 16) +
2448 (s[offset + 2] << 8) + s[offset+3];
2451 if (lvalue) { /* it's an lvalue! */
2452 if (SvTHINKFIRST(src)) {
2453 if (SvREADONLY(src) && curcop != &compiling)
2456 DIE("Can't modify vec of a reference");
2460 LvTARGOFF(TARG) = offset;
2461 LvTARGLEN(TARG) = size;
2465 sv_setiv(TARG, (I32)retnum);
2484 offset = POPi - arybase;
2487 tmps = SvPV(big, biglen);
2490 else if (offset > biglen)
2492 if (!(tmps2 = fbm_instr((unsigned char*)tmps + offset,
2493 (unsigned char*)tmps + biglen, little)))
2494 retval = -1 + arybase;
2496 retval = tmps2 - tmps + arybase;
2518 tmps2 = SvPV(little, llen);
2519 tmps = SvPV(big, blen);
2523 offset = SvIV(offstr) - arybase + llen;
2526 else if (offset > blen)
2528 if (!(tmps2 = rninstr(tmps, tmps + offset,
2529 tmps2, tmps2 + llen)))
2530 retval = -1 + arybase;
2532 retval = tmps2 - tmps + arybase;
2539 dSP; dMARK; dORIGMARK; dTARGET;
2540 do_sprintf(TARG, SP-MARK, MARK+1);
2551 register char *s = SvPV(sv, len);
2552 register char *send = s + len;
2553 register char *base;
2554 register I32 skipspaces = 0;
2557 bool postspace = FALSE;
2564 New(804, fops, send - s, U16); /* Almost certainly too long... */
2569 *fpc++ = FF_LINEMARK;
2570 noblank = repeat = FALSE;
2588 case ' ': case '\t':
2601 *fpc++ = FF_LITERAL;
2608 *fpc++ = skipspaces;
2612 *fpc++ = FF_NEWLINE;
2616 arg = fpc - linepc + 1;
2623 *fpc++ = FF_LINEMARK;
2624 noblank = repeat = FALSE;
2633 ischop = s[-1] == '^';
2639 arg = (s - base) - 1;
2641 *fpc++ = FF_LITERAL;
2650 *fpc++ = FF_LINEGLOB;
2652 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2653 arg = ischop ? 512 : 0;
2663 arg |= 256 + (s - f);
2665 *fpc++ = s - base; /* fieldsize for FETCH */
2666 *fpc++ = FF_DECIMAL;
2671 bool ismore = FALSE;
2674 while (*++s == '>') ;
2675 prespace = FF_SPACE;
2677 else if (*s == '|') {
2678 while (*++s == '|') ;
2679 prespace = FF_HALFSPACE;
2684 while (*++s == '<') ;
2687 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2691 *fpc++ = s - base; /* fieldsize for FETCH */
2693 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2711 SvGROW(sv, SvCUR(sv) + arg * sizeof(U16) + 4);
2713 s = SvPVX(sv) + SvCUR(sv);
2714 s += 2 + (SvCUR(sv) & 1);
2716 Copy(fops, s, arg, U16);
2722 dSP; dMARK; dORIGMARK;
2723 register SV *form = *++MARK;
2728 register char *send;
2735 bool chopspace = (strchr(chopset, ' ') != Nullch);
2744 if (!SvCOMPILED(form)) {
2745 SvREADONLY_off(form);
2749 SvUPGRADE(formtarget, SVt_PV);
2750 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
2751 t = SvPV(formtarget, len);
2753 f = SvPV(form, len);
2765 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
2766 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
2767 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
2768 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
2769 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
2771 case FF_CHECKNL: name = "CHECKNL"; break;
2772 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
2773 case FF_SPACE: name = "SPACE"; break;
2774 case FF_HALFSPACE: name = "HALFSPACE"; break;
2775 case FF_ITEM: name = "ITEM"; break;
2776 case FF_CHOP: name = "CHOP"; break;
2777 case FF_LINEGLOB: name = "LINEGLOB"; break;
2778 case FF_NEWLINE: name = "NEWLINE"; break;
2779 case FF_MORE: name = "MORE"; break;
2780 case FF_LINEMARK: name = "LINEMARK"; break;
2781 case FF_END: name = "END"; break;
2784 fprintf(stderr, "%-16s%d\n", name, arg);
2786 fprintf(stderr, "%-16s\n", name);
2817 warn("Not enough format arguments");
2822 item = s = SvPV(sv, len);
2824 if (itemsize > fieldsize)
2825 itemsize = fieldsize;
2826 send = chophere = s + itemsize;
2830 else if (*s == '\n')
2834 itemsize = s - item;
2838 item = s = SvPV(sv, len);
2840 if (itemsize <= fieldsize) {
2841 send = chophere = s + itemsize;
2844 itemsize = s - item;
2852 itemsize = fieldsize;
2853 send = chophere = s + itemsize;
2854 while (s < send || (s == send && isSPACE(*s))) {
2864 if (strchr(chopset, *s))
2869 itemsize = chophere - item;
2874 arg = fieldsize - itemsize;
2883 arg = fieldsize - itemsize;
2896 if ((*t++ = *s++) < ' ')
2904 while (*s && isSPACE(*s))
2911 item = s = SvPV(sv, len);
2915 send = s + itemsize;
2924 SvCUR_set(formtarget, t - SvPVX(formtarget));
2925 sv_catpvn(formtarget, item, itemsize);
2926 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
2927 t = SvPVX(formtarget) + SvCUR(formtarget);
2932 /* If the field is marked with ^ and the value is undefined,
2935 if ((arg & 512) && !SvOK(sv)) {
2944 sprintf(t, "%#*.*f", fieldsize, arg & 255, value);
2946 sprintf(t, "%*.0f", fieldsize, value);
2953 while (t-- > linemark && *t == ' ') ;
2961 if (arg) { /* repeat until fields exhausted? */
2967 if (strnEQ(linemark, linemark - arg, arg))
2968 DIE("Runaway format");
2970 arg = t - SvPVX(formtarget);
2972 (t - SvPVX(formtarget)) + (f - formmark) + 1);
2973 t = SvPVX(formtarget) + arg;
2984 arg = fieldsize - itemsize;
2991 if (strnEQ(s," ",3)) {
2992 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
3003 SvCUR_set(formtarget, t - SvPVX(formtarget));
3004 FmLINES(formtarget) += lines;
3019 tmps = SvPVx(GvSV(defgv), na);
3023 value = (I32) (*tmps & 255);
3026 value = (I32) (anum & 255);
3037 if (SvTYPE(TARG) == SVt_NULL) {
3038 sv_upgrade(TARG,SVt_PV);
3044 *tmps = SvIVx(GvSV(defgv));
3054 dSP; dTARGET; dPOPTOPssrl;
3056 char *tmps = SvPV(lstr, na);
3058 sv_setpv(TARG, fcrypt(tmps, SvPV(rstr, na)));
3060 sv_setpv(TARG, crypt(tmps, SvPV(rstr, na)));
3064 "The crypt() function is unimplemented due to excessive paranoia.");
3076 if (!SvPADTMP(sv)) {
3083 if (isascii(*s) && islower(*s))
3095 if (!SvPADTMP(sv)) {
3102 if (isascii(*s) && isupper(*s))
3114 register char *send;
3117 if (!SvPADTMP(sv)) {
3126 if (isascii(*s) && islower(*s))
3138 register char *send;
3141 if (!SvPADTMP(sv)) {
3150 if (isascii(*s) && isupper(*s))
3167 if (SvTYPE(av) != SVt_PVAV)
3168 DIE("Not an array reference");
3169 if (op->op_flags & OPf_LVAL) {
3170 if (op->op_flags & OPf_INTRO)
3171 av = (AV*)save_svref((SV**)sv);
3177 if (SvTYPE(sv) == SVt_PVAV) {
3179 if (op->op_flags & OPf_LVAL) {
3185 if (SvTYPE(sv) != SVt_PVGV) {
3187 DIE(no_usym, "an array");
3188 if (op->op_private & HINT_STRICT_REFS)
3189 DIE(no_hardref, "an array");
3190 sv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE, SVt_PVAV);
3193 if (op->op_flags & OPf_LVAL) {
3194 if (op->op_flags & OPf_INTRO)
3202 if (GIMME == G_ARRAY) {
3203 I32 maxarg = AvFILL(av) + 1;
3205 Copy(AvARRAY(av), SP+1, maxarg, SV*);
3210 I32 maxarg = AvFILL(av) + 1;
3219 AV *av = GvAV((GV*)cSVOP->op_sv);
3220 SV** svp = av_fetch(av, op->op_private - arybase, op->op_flags & OPf_LVAL);
3221 PUSHs(svp ? *svp : &sv_undef);
3229 I32 elem = POPi - arybase;
3232 if (op->op_flags & OPf_LVAL) {
3233 svp = av_fetch(av, elem, TRUE);
3234 if (!svp || *svp == &sv_undef)
3235 DIE(no_aelem, elem);
3236 if (op->op_flags & OPf_INTRO)
3238 else if (!SvOK(*svp)) {
3239 if (op->op_private & OPpDEREF_HV) {
3242 sv_upgrade(*svp, SVt_RV);
3243 SvRV(*svp) = SvREFCNT_inc(newHV());
3247 else if (op->op_private & OPpDEREF_AV) {
3250 sv_upgrade(*svp, SVt_RV);
3251 SvRV(*svp) = SvREFCNT_inc(newAV());
3258 svp = av_fetch(av, elem, FALSE);
3259 PUSHs(svp ? *svp : &sv_undef);
3265 dSP; dMARK; dORIGMARK;
3267 register AV* av = (AV*)POPs;
3268 register I32 lval = op->op_flags & OPf_LVAL;
3269 I32 is_something_there = lval;
3271 while (++MARK <= SP) {
3272 I32 elem = SvIVx(*MARK);
3275 svp = av_fetch(av, elem, TRUE);
3276 if (!svp || *svp == &sv_undef)
3277 DIE(no_aelem, elem);
3278 if (op->op_flags & OPf_INTRO)
3282 svp = av_fetch(av, elem, FALSE);
3283 if (!is_something_there && svp && SvOK(*svp))
3284 is_something_there = TRUE;
3286 *MARK = svp ? *svp : &sv_undef;
3288 if (!is_something_there)
3293 /* Associative arrays. */
3298 HV *hash = (HV*)POPs;
3299 HE *entry = hv_iternext(hash);
3305 tmps = hv_iterkey(entry, &i);
3308 PUSHs(sv_2mortal(newSVpv(tmps, i)));
3309 if (GIMME == G_ARRAY) {
3310 sv_setsv(TARG, hv_iterval(hash, entry));
3314 else if (GIMME == G_SCALAR)
3339 DIE("Not an associative array reference");
3341 tmps = SvPV(tmpsv, len);
3342 sv = hv_delete(hv, tmps, len);
3358 if (SvTYPE(hv) != SVt_PVHV)
3359 DIE("Not an associative array reference");
3360 if (op->op_flags & OPf_LVAL) {
3361 if (op->op_flags & OPf_INTRO)
3362 hv = (HV*)save_svref((SV**)sv);
3368 if (SvTYPE(sv) == SVt_PVHV) {
3370 if (op->op_flags & OPf_LVAL) {
3376 if (SvTYPE(sv) != SVt_PVGV) {
3378 DIE(no_usym, "a hash");
3379 if (op->op_private & HINT_STRICT_REFS)
3380 DIE(no_hardref, "a hash");
3381 sv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE, SVt_PVHV);
3384 if (op->op_flags & OPf_LVAL) {
3385 if (op->op_flags & OPf_INTRO)
3393 if (GIMME == G_ARRAY) { /* array wanted */
3394 *stack_sp = (SV*)hv;
3400 sprintf(buf, "%d/%d", HvFILL(hv), HvMAX(hv)+1);
3401 sv_setpv(TARG, buf);
3416 char *key = SvPV(keysv, keylen);
3419 if (op->op_flags & OPf_LVAL) {
3420 svp = hv_fetch(hv, key, keylen, TRUE);
3421 if (!svp || *svp == &sv_undef)
3423 if (op->op_flags & OPf_INTRO)
3425 else if (!SvOK(*svp)) {
3426 if (op->op_private & OPpDEREF_HV) {
3429 sv_upgrade(*svp, SVt_RV);
3430 SvRV(*svp) = SvREFCNT_inc(newHV());
3434 else if (op->op_private & OPpDEREF_AV) {
3437 sv_upgrade(*svp, SVt_RV);
3438 SvRV(*svp) = SvREFCNT_inc(newAV());
3445 svp = hv_fetch(hv, key, keylen, FALSE);
3446 PUSHs(svp ? *svp : &sv_undef);
3452 dSP; dMARK; dORIGMARK;
3454 register HV *hv = (HV*)POPs;
3455 register I32 lval = op->op_flags & OPf_LVAL;
3456 I32 is_something_there = lval;
3458 while (++MARK <= SP) {
3460 char *key = SvPV(*MARK, keylen);
3463 svp = hv_fetch(hv, key, keylen, TRUE);
3464 if (!svp || *svp == &sv_undef)
3466 if (op->op_flags & OPf_INTRO)
3470 svp = hv_fetch(hv, key, keylen, FALSE);
3471 if (!is_something_there && svp && SvOK(*svp))
3472 is_something_there = TRUE;
3474 *MARK = svp ? *svp : &sv_undef;
3476 if (!is_something_there)
3481 /* Explosives and implosives. */
3490 register char *pat = SvPV(lstr, llen);
3491 register char *s = SvPV(rstr, rlen);
3492 char *strend = s + rlen;
3494 register char *patend = pat + llen;
3499 /* These must not be in registers: */
3510 unsigned quad auquad;
3516 register U32 culong;
3518 static char* bitcount = 0;
3520 if (GIMME != G_ARRAY) { /* arrange to do first one only */
3522 for (patend = pat; !isALPHA(*patend) || *patend == 'x'; patend++) ;
3523 if (strchr("aAbBhH", *patend) || *pat == '%') {
3525 while (isDIGIT(*patend) || *patend == '*')
3531 while (pat < patend) {
3536 else if (*pat == '*') {
3537 len = strend - strbeg; /* long enough */
3540 else if (isDIGIT(*pat)) {
3542 while (isDIGIT(*pat))
3543 len = (len * 10) + (*pat++ - '0');
3546 len = (datumtype != '@');
3551 if (len == 1 && pat[-1] != '1')
3560 if (len > strend - strbeg)
3561 DIE("@ outside of string");
3565 if (len > s - strbeg)
3566 DIE("X outside of string");
3570 if (len > strend - s)
3571 DIE("x outside of string");
3576 if (len > strend - s)
3579 goto uchar_checksum;
3580 sv = NEWSV(35, len);
3581 sv_setpvn(sv, s, len);
3583 if (datumtype == 'A') {
3584 aptr = s; /* borrow register */
3585 s = SvPVX(sv) + len - 1;
3586 while (s >= SvPVX(sv) && (!*s || isSPACE(*s)))
3589 SvCUR_set(sv, s - SvPVX(sv));
3590 s = aptr; /* unborrow register */
3592 XPUSHs(sv_2mortal(sv));
3596 if (pat[-1] == '*' || len > (strend - s) * 8)
3597 len = (strend - s) * 8;
3600 Newz(601, bitcount, 256, char);
3601 for (bits = 1; bits < 256; bits++) {
3602 if (bits & 1) bitcount[bits]++;
3603 if (bits & 2) bitcount[bits]++;
3604 if (bits & 4) bitcount[bits]++;
3605 if (bits & 8) bitcount[bits]++;
3606 if (bits & 16) bitcount[bits]++;
3607 if (bits & 32) bitcount[bits]++;
3608 if (bits & 64) bitcount[bits]++;
3609 if (bits & 128) bitcount[bits]++;
3613 culong += bitcount[*(unsigned char*)s++];
3618 if (datumtype == 'b') {
3620 if (bits & 1) culong++;
3626 if (bits & 128) culong++;
3633 sv = NEWSV(35, len + 1);
3636 aptr = pat; /* borrow register */
3638 if (datumtype == 'b') {
3640 for (len = 0; len < aint; len++) {
3641 if (len & 7) /*SUPPRESS 595*/
3645 *pat++ = '0' + (bits & 1);
3650 for (len = 0; len < aint; len++) {
3655 *pat++ = '0' + ((bits & 128) != 0);
3659 pat = aptr; /* unborrow register */
3660 XPUSHs(sv_2mortal(sv));
3664 if (pat[-1] == '*' || len > (strend - s) * 2)
3665 len = (strend - s) * 2;
3666 sv = NEWSV(35, len + 1);
3669 aptr = pat; /* borrow register */
3671 if (datumtype == 'h') {
3673 for (len = 0; len < aint; len++) {
3678 *pat++ = hexdigit[bits & 15];
3683 for (len = 0; len < aint; len++) {
3688 *pat++ = hexdigit[(bits >> 4) & 15];
3692 pat = aptr; /* unborrow register */
3693 XPUSHs(sv_2mortal(sv));
3696 if (len > strend - s)
3701 if (aint >= 128) /* fake up signed chars */
3710 if (aint >= 128) /* fake up signed chars */
3713 sv_setiv(sv, (I32)aint);
3714 PUSHs(sv_2mortal(sv));
3719 if (len > strend - s)
3733 sv_setiv(sv, (I32)auint);
3734 PUSHs(sv_2mortal(sv));
3739 along = (strend - s) / sizeof(I16);
3744 Copy(s, &ashort, 1, I16);
3752 Copy(s, &ashort, 1, I16);
3755 sv_setiv(sv, (I32)ashort);
3756 PUSHs(sv_2mortal(sv));
3763 along = (strend - s) / sizeof(U16);
3768 Copy(s, &aushort, 1, U16);
3771 if (datumtype == 'n')
3772 aushort = ntohs(aushort);
3775 if (datumtype == 'v')
3776 aushort = vtohs(aushort);
3784 Copy(s, &aushort, 1, U16);
3788 if (datumtype == 'n')
3789 aushort = ntohs(aushort);
3792 if (datumtype == 'v')
3793 aushort = vtohs(aushort);
3795 sv_setiv(sv, (I32)aushort);
3796 PUSHs(sv_2mortal(sv));
3801 along = (strend - s) / sizeof(int);
3806 Copy(s, &aint, 1, int);
3809 cdouble += (double)aint;
3817 Copy(s, &aint, 1, int);
3820 sv_setiv(sv, (I32)aint);
3821 PUSHs(sv_2mortal(sv));
3826 along = (strend - s) / sizeof(unsigned int);
3831 Copy(s, &auint, 1, unsigned int);
3832 s += sizeof(unsigned int);
3834 cdouble += (double)auint;
3842 Copy(s, &auint, 1, unsigned int);
3843 s += sizeof(unsigned int);
3845 sv_setiv(sv, (I32)auint);
3846 PUSHs(sv_2mortal(sv));
3851 along = (strend - s) / sizeof(I32);
3856 Copy(s, &along, 1, I32);
3859 cdouble += (double)along;
3867 Copy(s, &along, 1, I32);
3870 sv_setiv(sv, (I32)along);
3871 PUSHs(sv_2mortal(sv));
3878 along = (strend - s) / sizeof(U32);
3883 Copy(s, &aulong, 1, U32);
3886 if (datumtype == 'N')
3887 aulong = ntohl(aulong);
3890 if (datumtype == 'V')
3891 aulong = vtohl(aulong);
3894 cdouble += (double)aulong;
3902 Copy(s, &aulong, 1, U32);
3906 if (datumtype == 'N')
3907 aulong = ntohl(aulong);
3910 if (datumtype == 'V')
3911 aulong = vtohl(aulong);
3913 sv_setnv(sv, (double)aulong);
3914 PUSHs(sv_2mortal(sv));
3919 along = (strend - s) / sizeof(char*);
3924 if (sizeof(char*) > strend - s)
3927 Copy(s, &aptr, 1, char*);
3933 PUSHs(sv_2mortal(sv));
3938 if (sizeof(char*) > strend - s)
3941 Copy(s, &aptr, 1, char*);
3946 sv_setpvn(sv, aptr, len);
3947 PUSHs(sv_2mortal(sv));
3953 if (s + sizeof(quad) > strend)
3956 Copy(s, &aquad, 1, quad);
3960 sv_setnv(sv, (double)aquad);
3961 PUSHs(sv_2mortal(sv));
3967 if (s + sizeof(unsigned quad) > strend)
3970 Copy(s, &auquad, 1, unsigned quad);
3971 s += sizeof(unsigned quad);
3974 sv_setnv(sv, (double)auquad);
3975 PUSHs(sv_2mortal(sv));
3979 /* float and double added gnb@melba.bby.oz.au 22/11/89 */
3982 along = (strend - s) / sizeof(float);
3987 Copy(s, &afloat, 1, float);
3995 Copy(s, &afloat, 1, float);
3998 sv_setnv(sv, (double)afloat);
3999 PUSHs(sv_2mortal(sv));
4005 along = (strend - s) / sizeof(double);
4010 Copy(s, &adouble, 1, double);
4011 s += sizeof(double);
4018 Copy(s, &adouble, 1, double);
4019 s += sizeof(double);
4021 sv_setnv(sv, (double)adouble);
4022 PUSHs(sv_2mortal(sv));
4027 along = (strend - s) * 3 / 4;
4028 sv = NEWSV(42, along);
4029 while (s < strend && *s > ' ' && *s < 'a') {
4034 len = (*s++ - ' ') & 077;
4036 if (s < strend && *s >= ' ')
4037 a = (*s++ - ' ') & 077;
4040 if (s < strend && *s >= ' ')
4041 b = (*s++ - ' ') & 077;
4044 if (s < strend && *s >= ' ')
4045 c = (*s++ - ' ') & 077;
4048 if (s < strend && *s >= ' ')
4049 d = (*s++ - ' ') & 077;
4052 hunk[0] = a << 2 | b >> 4;
4053 hunk[1] = b << 4 | c >> 2;
4054 hunk[2] = c << 6 | d;
4055 sv_catpvn(sv, hunk, len > 3 ? 3 : len);
4060 else if (s[1] == '\n') /* possible checksum byte */
4063 XPUSHs(sv_2mortal(sv));
4068 if (strchr("fFdD", datumtype) ||
4069 (checksum > 32 && strchr("iIlLN", datumtype)) ) {
4074 while (checksum >= 16) {
4078 while (checksum >= 4) {
4084 along = (1 << checksum) - 1;
4085 while (cdouble < 0.0)
4087 cdouble = modf(cdouble / adouble, &trouble) * adouble;
4088 sv_setnv(sv, cdouble);
4091 if (checksum < 32) {
4092 along = (1 << checksum) - 1;
4093 culong &= (U32)along;
4095 sv_setnv(sv, (double)culong);
4097 XPUSHs(sv_2mortal(sv));
4105 doencodes(sv, s, len)
4113 sv_catpvn(sv, hunk, 1);
4116 hunk[0] = ' ' + (077 & (*s >> 2));
4117 hunk[1] = ' ' + (077 & ((*s << 4) & 060 | (s[1] >> 4) & 017));
4118 hunk[2] = ' ' + (077 & ((s[1] << 2) & 074 | (s[2] >> 6) & 03));
4119 hunk[3] = ' ' + (077 & (s[2] & 077));
4120 sv_catpvn(sv, hunk, 4);
4124 for (s = SvPVX(sv); *s; s++) {
4128 sv_catpvn(sv, "\n", 1);
4133 dSP; dMARK; dORIGMARK; dTARGET;
4134 register SV *cat = TARG;
4137 register char *pat = SvPVx(*++MARK, fromlen);
4138 register char *patend = pat + fromlen;
4143 static char null10[] = {0,0,0,0,0,0,0,0,0,0};
4144 static char *space10 = " ";
4146 /* These must not be in registers: */
4155 unsigned quad auquad;
4163 sv_setpvn(cat, "", 0);
4164 while (pat < patend) {
4165 #define NEXTFROM (items-- > 0 ? *MARK++ : &sv_no)
4168 len = strchr("@Xxu", datumtype) ? 0 : items;
4171 else if (isDIGIT(*pat)) {
4173 while (isDIGIT(*pat))
4174 len = (len * 10) + (*pat++ - '0');
4182 DIE("%% may only be used in unpack");
4193 if (SvCUR(cat) < len)
4194 DIE("X outside of string");
4201 sv_catpvn(cat, null10, 10);
4204 sv_catpvn(cat, null10, len);
4209 aptr = SvPV(fromstr, fromlen);
4213 sv_catpvn(cat, aptr, len);
4215 sv_catpvn(cat, aptr, fromlen);
4217 if (datumtype == 'A') {
4219 sv_catpvn(cat, space10, 10);
4222 sv_catpvn(cat, space10, len);
4226 sv_catpvn(cat, null10, 10);
4229 sv_catpvn(cat, null10, len);
4236 char *savepat = pat;
4241 aptr = SvPV(fromstr, fromlen);
4246 SvCUR(cat) += (len+7)/8;
4247 SvGROW(cat, SvCUR(cat) + 1);
4248 aptr = SvPVX(cat) + aint;
4253 if (datumtype == 'B') {
4254 for (len = 0; len++ < aint;) {
4255 items |= *pat++ & 1;
4259 *aptr++ = items & 0xff;
4265 for (len = 0; len++ < aint;) {
4271 *aptr++ = items & 0xff;
4277 if (datumtype == 'B')
4278 items <<= 7 - (aint & 7);
4280 items >>= 7 - (aint & 7);
4281 *aptr++ = items & 0xff;
4283 pat = SvPVX(cat) + SvCUR(cat);
4294 char *savepat = pat;
4299 aptr = SvPV(fromstr, fromlen);
4304 SvCUR(cat) += (len+1)/2;
4305 SvGROW(cat, SvCUR(cat) + 1);
4306 aptr = SvPVX(cat) + aint;
4311 if (datumtype == 'H') {
4312 for (len = 0; len++ < aint;) {
4314 items |= ((*pat++ & 15) + 9) & 15;
4316 items |= *pat++ & 15;
4320 *aptr++ = items & 0xff;
4326 for (len = 0; len++ < aint;) {
4328 items |= (((*pat++ & 15) + 9) & 15) << 4;
4330 items |= (*pat++ & 15) << 4;
4334 *aptr++ = items & 0xff;
4340 *aptr++ = items & 0xff;
4341 pat = SvPVX(cat) + SvCUR(cat);
4353 aint = SvIV(fromstr);
4355 sv_catpvn(cat, &achar, sizeof(char));
4358 /* Float and double added by gnb@melba.bby.oz.au 22/11/89 */
4363 afloat = (float)SvNV(fromstr);
4364 sv_catpvn(cat, (char *)&afloat, sizeof (float));
4371 adouble = (double)SvNV(fromstr);
4372 sv_catpvn(cat, (char *)&adouble, sizeof (double));
4378 ashort = (I16)SvIV(fromstr);
4380 ashort = htons(ashort);
4382 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
4388 ashort = (I16)SvIV(fromstr);
4390 ashort = htovs(ashort);
4392 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
4399 ashort = (I16)SvIV(fromstr);
4400 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
4406 auint = U_I(SvNV(fromstr));
4407 sv_catpvn(cat, (char*)&auint, sizeof(unsigned int));
4413 aint = SvIV(fromstr);
4414 sv_catpvn(cat, (char*)&aint, sizeof(int));
4420 aulong = U_L(SvNV(fromstr));
4422 aulong = htonl(aulong);
4424 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
4430 aulong = U_L(SvNV(fromstr));
4432 aulong = htovl(aulong);
4434 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
4440 aulong = U_L(SvNV(fromstr));
4441 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
4447 along = SvIV(fromstr);
4448 sv_catpvn(cat, (char*)&along, sizeof(I32));
4455 auquad = (unsigned quad)SvNV(fromstr);
4456 sv_catpvn(cat, (char*)&auquad, sizeof(unsigned quad));
4462 aquad = (quad)SvNV(fromstr);
4463 sv_catpvn(cat, (char*)&aquad, sizeof(quad));
4468 len = 1; /* assume SV is correct length */
4473 aptr = SvPV(fromstr, na);
4474 sv_catpvn(cat, (char*)&aptr, sizeof(char*));
4479 aptr = SvPV(fromstr, fromlen);
4480 SvGROW(cat, fromlen * 4 / 3);
4485 while (fromlen > 0) {
4492 doencodes(cat, aptr, todo);
4510 register I32 limit = POPi; /* note, negative is forever */
4513 register char *s = SvPV(sv, len);
4514 char *strend = s + len;
4515 register PMOP *pm = (PMOP*)POPs;
4519 I32 maxiters = (strend - s) + 10;
4522 I32 origlimit = limit;
4526 register REGEXP *rx = pm->op_pmregexp;
4530 DIE("panic: do_split");
4531 if (pm->op_pmreplroot)
4532 ary = GvAVn((GV*)pm->op_pmreplroot);
4533 else if (gimme != G_ARRAY)
4537 if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) {
4541 for (i = AvFILL(ary); i >= 0; i--)
4542 AvARRAY(ary)[i] = Nullsv; /* don't free mere refs */
4544 av_fill(ary,0); /* force allocation */
4546 /* temporarily switch stacks */
4548 SWITCHSTACK(stack, ary);
4550 base = SP - stack_base;
4552 if (pm->op_pmflags & PMf_SKIPWHITE) {
4557 limit = maxiters + 2;
4558 if (pm->op_pmflags & PMf_WHITE) {
4561 for (m = s; m < strend && !isSPACE(*m); m++) ;
4564 dstr = NEWSV(30, m-s);
4565 sv_setpvn(dstr, s, m-s);
4570 for (s = m + 1; s < strend && isSPACE(*s); s++) ;
4573 else if (strEQ("^", rx->precomp)) {
4576 for (m = s; m < strend && *m != '\n'; m++) ;
4580 dstr = NEWSV(30, m-s);
4581 sv_setpvn(dstr, s, m-s);
4588 else if (pm->op_pmshort) {
4589 i = SvCUR(pm->op_pmshort);
4591 I32 fold = (pm->op_pmflags & PMf_FOLD);
4592 i = *SvPVX(pm->op_pmshort);
4593 if (fold && isUPPER(i))
4598 m < strend && *m != i &&
4599 (!isUPPER(*m) || tolower(*m) != i);
4600 m++) /*SUPPRESS 530*/
4603 else /*SUPPRESS 530*/
4604 for (m = s; m < strend && *m != i; m++) ;
4607 dstr = NEWSV(30, m-s);
4608 sv_setpvn(dstr, s, m-s);
4617 while (s < strend && --limit &&
4618 (m=fbm_instr((unsigned char*)s, (unsigned char*)strend,
4622 dstr = NEWSV(31, m-s);
4623 sv_setpvn(dstr, s, m-s);
4632 maxiters += (strend - s) * rx->nparens;
4633 while (s < strend && --limit &&
4634 regexec(rx, s, strend, orig, 1, Nullsv, TRUE) ) {
4636 && rx->subbase != orig) {
4641 strend = s + (strend - m);
4644 dstr = NEWSV(32, m-s);
4645 sv_setpvn(dstr, s, m-s);
4650 for (i = 1; i <= rx->nparens; i++) {
4653 dstr = NEWSV(33, m-s);
4654 sv_setpvn(dstr, s, m-s);
4663 iters = (SP - stack_base) - base;
4664 if (iters > maxiters)
4666 if (s < strend || origlimit) { /* keep field after final delim? */
4667 dstr = NEWSV(34, strend-s);
4668 sv_setpvn(dstr, s, strend-s);
4675 while (iters > 0 && SvCUR(TOPs) == 0)
4679 SWITCHSTACK(ary, oldstack);
4680 if (gimme == G_ARRAY) {
4682 Copy(AvARRAY(ary), SP + 1, iters, SV*);
4688 if (gimme == G_ARRAY)
4698 dSP; dMARK; dTARGET;
4700 do_join(TARG, *MARK, MARK, SP);
4706 /* List operators. */
4711 if (GIMME != G_ARRAY) {
4713 *MARK = *SP; /* unwanted list, return last item */
4724 SV **lastrelem = stack_sp;
4725 SV **lastlelem = stack_base + POPMARK;
4726 SV **firstlelem = stack_base + POPMARK + 1;
4727 register SV **firstrelem = lastlelem + 1;
4728 I32 lval = op->op_flags & OPf_LVAL;
4729 I32 is_something_there = lval;
4731 register I32 max = lastrelem - lastlelem;
4732 register SV **lelem;
4735 if (GIMME != G_ARRAY) {
4736 ix = SvIVx(*lastlelem) - arybase;
4737 if (ix < 0 || ix >= max)
4738 *firstlelem = &sv_undef;
4740 *firstlelem = firstrelem[ix];
4746 SP = firstlelem - 1;
4750 for (lelem = firstlelem; lelem <= lastlelem; lelem++) {
4751 ix = SvIVx(*lelem) - arybase;
4756 else if (!(*lelem = firstrelem[ix]))
4759 else if (ix >= max || !(*lelem = firstrelem[ix]))
4761 if (!is_something_there && SvOK(*lelem))
4762 is_something_there = TRUE;
4764 if (is_something_there)
4767 SP = firstlelem - 1;
4774 I32 items = SP - MARK;
4776 XPUSHs((SV*)av_make(items, MARK+1));
4782 dSP; dMARK; dORIGMARK;
4790 SV *val = NEWSV(46, 0);
4792 sv_setsv(val, *++MARK);
4793 tmps = SvPV(key,len);
4794 (void)hv_store(hv,tmps,len,val,0);
4804 dSP; dMARK; dORIGMARK;
4805 register AV *ary = (AV*)*++MARK;
4809 register I32 offset;
4810 register I32 length;
4819 offset = SvIVx(*MARK);
4821 offset += AvFILL(ary) + 1;
4825 length = SvIVx(*MARK++);
4830 length = AvMAX(ary) + 1; /* close enough to infinity */
4834 length = AvMAX(ary) + 1;
4842 if (offset > AvFILL(ary) + 1)
4843 offset = AvFILL(ary) + 1;
4844 after = AvFILL(ary) + 1 - (offset + length);
4845 if (after < 0) { /* not that much array */
4846 length += after; /* offset+length now in array */
4848 if (!AvALLOC(ary)) {
4854 /* At this point, MARK .. SP-1 is our new LIST */
4857 diff = newlen - length;
4859 if (diff < 0) { /* shrinking the area */
4861 New(451, tmparyval, newlen, SV*); /* so remember insertion */
4862 Copy(MARK, tmparyval, newlen, SV*);
4865 MARK = ORIGMARK + 1;
4866 if (GIMME == G_ARRAY) { /* copy return vals to stack */
4867 MEXTEND(MARK, length);
4868 Copy(AvARRAY(ary)+offset, MARK, length, SV*);
4870 for (i = length, dst = MARK; i; i--)
4871 sv_2mortal(*dst++); /* free them eventualy */
4876 *MARK = AvARRAY(ary)[offset+length-1];
4879 for (i = length - 1, dst = &AvARRAY(ary)[offset]; i > 0; i--)
4880 SvREFCNT_dec(*dst++); /* free them now */
4883 AvFILL(ary) += diff;
4885 /* pull up or down? */
4887 if (offset < after) { /* easier to pull up */
4888 if (offset) { /* esp. if nothing to pull */
4889 src = &AvARRAY(ary)[offset-1];
4890 dst = src - diff; /* diff is negative */
4891 for (i = offset; i > 0; i--) /* can't trust Copy */
4894 Zero(AvARRAY(ary), -diff, SV*);
4895 SvPVX(ary) = (char*)(AvARRAY(ary) - diff); /* diff is negative */
4899 if (after) { /* anything to pull down? */
4900 src = AvARRAY(ary) + offset + length;
4901 dst = src + diff; /* diff is negative */
4902 Move(src, dst, after, SV*);
4904 Zero(&AvARRAY(ary)[AvFILL(ary)+1], -diff, SV*);
4905 /* avoid later double free */
4908 for (src = tmparyval, dst = AvARRAY(ary) + offset;
4910 *dst = NEWSV(46, 0);
4911 sv_setsv(*dst++, *src++);
4913 Safefree(tmparyval);
4916 else { /* no, expanding (or same) */
4918 New(452, tmparyval, length, SV*); /* so remember deletion */
4919 Copy(AvARRAY(ary)+offset, tmparyval, length, SV*);
4922 if (diff > 0) { /* expanding */
4924 /* push up or down? */
4926 if (offset < after && diff <= AvARRAY(ary) - AvALLOC(ary)) {
4930 Move(src, dst, offset, SV*);
4932 SvPVX(ary) = (char*)(AvARRAY(ary) - diff);/* diff is positive */
4934 AvFILL(ary) += diff;
4937 if (AvFILL(ary) + diff >= AvMAX(ary)) /* oh, well */
4938 av_store(ary, AvFILL(ary) + diff, Nullsv);
4940 AvFILL(ary) += diff;
4941 dst = AvARRAY(ary) + AvFILL(ary);
4942 for (i = diff; i > 0; i--) {
4943 if (*dst) /* stuff was hanging around */
4944 SvREFCNT_dec(*dst); /* after $#foo */
4948 dst = AvARRAY(ary) + AvFILL(ary);
4950 for (i = after; i; i--) {
4957 for (src = MARK, dst = AvARRAY(ary) + offset; newlen; newlen--) {
4958 *dst = NEWSV(46, 0);
4959 sv_setsv(*dst++, *src++);
4961 MARK = ORIGMARK + 1;
4962 if (GIMME == G_ARRAY) { /* copy return vals to stack */
4964 Copy(tmparyval, MARK, length, SV*);
4966 for (i = length, dst = MARK; i; i--)
4967 sv_2mortal(*dst++); /* free them eventualy */
4969 Safefree(tmparyval);
4973 else if (length--) {
4974 *MARK = tmparyval[length];
4977 while (length-- > 0)
4978 SvREFCNT_dec(tmparyval[length]);
4980 Safefree(tmparyval);
4991 dSP; dMARK; dORIGMARK; dTARGET;
4992 register AV *ary = (AV*)*++MARK;
4993 register SV *sv = &sv_undef;
4995 for (++MARK; MARK <= SP; MARK++) {
4998 sv_setsv(sv, *MARK);
4999 (void)av_push(ary, sv);
5002 PUSHi( AvFILL(ary) + 1 );
5010 SV *sv = av_pop(av);
5014 (void)sv_2mortal(sv);
5023 SV *sv = av_shift(av);
5028 (void)sv_2mortal(sv);
5035 dSP; dMARK; dORIGMARK; dTARGET;
5036 register AV *ary = (AV*)*++MARK;
5040 av_unshift(ary, SP - MARK);
5043 sv_setsv(sv, *++MARK);
5044 (void)av_store(ary, i++, sv);
5048 PUSHi( AvFILL(ary) + 1 );
5057 if (stack_base + *markstack_ptr == sp) {
5059 RETURNOP(op->op_next->op_next);
5061 stack_sp = stack_base + *markstack_ptr + 1;
5062 pp_pushmark(); /* push dst */
5063 pp_pushmark(); /* push src */
5064 ENTER; /* enter outer scope */
5067 SAVESPTR(GvSV(defgv));
5069 ENTER; /* enter inner scope */
5072 if (src = stack_base[*markstack_ptr]) {
5077 GvSV(defgv) = sv_newmortal();
5079 RETURNOP(((LOGOP*)op->op_next)->op_other);
5087 stack_base[markstack_ptr[-1]++] = stack_base[*markstack_ptr];
5089 LEAVE; /* exit inner scope */
5092 if (stack_base + *markstack_ptr > sp) {
5095 LEAVE; /* exit outer scope */
5096 POPMARK; /* pop src */
5097 items = --*markstack_ptr - markstack_ptr[-1];
5098 POPMARK; /* pop dst */
5099 SP = stack_base + POPMARK; /* pop original mark */
5100 if (GIMME != G_ARRAY) {
5111 ENTER; /* enter inner scope */
5114 if (src = stack_base[*markstack_ptr]) {
5119 GvSV(defgv) = sv_newmortal();
5121 RETURNOP(cLOGOP->op_other);
5125 static int sortcmp();
5126 static int sortcv();
5130 dSP; dMARK; dORIGMARK;
5132 SV **myorigmark = ORIGMARK;
5140 if (GIMME != G_ARRAY) {
5145 if (op->op_flags & OPf_STACKED) {
5147 if (op->op_flags & OPf_SPECIAL) {
5148 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
5149 kid = kUNOP->op_first; /* pass rv2gv */
5150 kid = kUNOP->op_first; /* pass leave */
5151 sortcop = kid->op_next;
5152 stash = curcop->cop_stash;
5155 cv = sv_2cv(*++MARK, &stash, &gv, 0);
5156 if (!(cv && CvROOT(cv))) {
5158 SV *tmpstr = sv_newmortal();
5159 gv_efullname(tmpstr, gv);
5161 DIE("Usersub \"%s\" called in sort", SvPVX(tmpstr));
5162 DIE("Undefined sort subroutine \"%s\" called",
5167 DIE("Usersub called in sort");
5168 DIE("Undefined subroutine in sort");
5170 DIE("Not a subroutine reference in sort");
5172 sortcop = CvSTART(cv);
5173 SAVESPTR(CvROOT(cv)->op_ppaddr);
5174 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
5177 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
5182 stash = curcop->cop_stash;
5185 up = myorigmark + 1;
5186 while (MARK < SP) { /* This may or may not shift down one here. */
5188 if (*up = *++MARK) { /* Weed out nulls. */
5190 (void)sv_2pv(*up, &na);
5196 max = --up - myorigmark;
5206 sortstack = newAV();
5207 av_store(sortstack, 32, Nullsv);
5208 av_clear(sortstack);
5209 AvREAL_off(sortstack);
5211 SWITCHSTACK(stack, sortstack);
5212 if (sortstash != stash) {
5213 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
5214 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
5218 SAVESPTR(GvSV(firstgv));
5219 SAVESPTR(GvSV(secondgv));
5221 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
5223 SWITCHSTACK(sortstack, oldstack);
5228 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
5229 qsort((char*)(ORIGMARK+1), max, sizeof(SV*), sortcmp);
5232 SP = ORIGMARK + max;
5242 if (GIMME == G_ARRAY) {
5253 register char *down;
5259 do_join(TARG, &sv_no, MARK, SP);
5261 sv_setsv(TARG, *SP);
5262 up = SvPV(TARG, len);
5264 down = SvPVX(TARG) + len - 1;
5282 if (GIMME == G_ARRAY)
5283 return cCONDOP->op_true;
5284 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
5291 if (GIMME == G_ARRAY) {
5292 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
5296 SV *targ = PAD_SV(op->op_targ);
5298 if ((op->op_private & OPpFLIP_LINENUM)
5299 ? last_in_gv && SvIV(sv) == IoLINES(GvIO(last_in_gv))
5301 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
5302 if (op->op_flags & OPf_SPECIAL) {
5309 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
5322 if (GIMME == G_ARRAY) {
5328 if (SvNIOK(lstr) || !SvPOK(lstr) ||
5329 (looks_like_number(lstr) && *SvPVX(lstr) != '0') ) {
5333 EXTEND(SP, max - i + 1);
5335 sv = sv_mortalcopy(&sv_no);
5341 SV *final = sv_mortalcopy(rstr);
5343 char *tmps = SvPV(final, len);
5345 sv = sv_mortalcopy(lstr);
5346 while (!SvNIOK(sv) && SvCUR(sv) <= len &&
5347 strNE(SvPVX(sv),tmps) ) {
5349 sv = sv_2mortal(newSVsv(sv));
5352 if (strEQ(SvPVX(sv),tmps))
5358 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
5360 if ((op->op_private & OPpFLIP_LINENUM)
5361 ? last_in_gv && SvIV(sv) == IoLINES(GvIO(last_in_gv))
5363 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
5364 sv_catpv(targ, "E0");
5379 register CONTEXT *cx;
5381 for (i = cxstack_ix; i >= 0; i--) {
5383 switch (cx->cx_type) {
5386 warn("Exiting substitution via %s", op_name[op->op_type]);
5390 warn("Exiting subroutine via %s", op_name[op->op_type]);
5394 warn("Exiting eval via %s", op_name[op->op_type]);
5397 if (!cx->blk_loop.label ||
5398 strNE(label, cx->blk_loop.label) ) {
5399 DEBUG_l(deb("(Skipping label #%d %s)\n",
5400 i, cx->blk_loop.label));
5403 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
5410 dopoptosub(startingblock)
5414 register CONTEXT *cx;
5415 for (i = startingblock; i >= 0; i--) {
5417 switch (cx->cx_type) {
5422 DEBUG_l( deb("(Found sub #%d)\n", i));
5430 dopoptoeval(startingblock)
5434 register CONTEXT *cx;
5435 for (i = startingblock; i >= 0; i--) {
5437 switch (cx->cx_type) {
5441 DEBUG_l( deb("(Found eval #%d)\n", i));
5449 dopoptoloop(startingblock)
5453 register CONTEXT *cx;
5454 for (i = startingblock; i >= 0; i--) {
5456 switch (cx->cx_type) {
5459 warn("Exiting substitition via %s", op_name[op->op_type]);
5463 warn("Exiting subroutine via %s", op_name[op->op_type]);
5467 warn("Exiting eval via %s", op_name[op->op_type]);
5470 DEBUG_l( deb("(Found loop #%d)\n", i));
5481 register CONTEXT *cx;
5485 while (cxstack_ix > cxix) {
5486 cx = &cxstack[cxstack_ix--];
5487 DEBUG_l(fprintf(stderr, "Unwinding block %d, type %s\n", cxstack_ix+1,
5488 block_type[cx->cx_type]));
5489 /* Note: we don't need to restore the base context info till the end. */
5490 switch (cx->cx_type) {
5523 va_start(args, pat);
5527 message = mess(pat, &args);
5529 restartop = die_where(message);
5530 if (stack != mainstack)
5531 longjmp(top_env, 3);
5541 register CONTEXT *cx;
5545 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),message);
5546 cxix = dopoptoeval(cxstack_ix);
5550 if (cxix < cxstack_ix)
5554 if (cx->cx_type != CXt_EVAL) {
5555 fprintf(stderr, "panic: die %s", message);
5560 if (gimme == G_SCALAR)
5561 *++newsp = &sv_undef;
5565 if (optype == OP_REQUIRE)
5566 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
5567 return pop_return();
5570 fputs(message, stderr);
5571 (void)fflush(stderr);
5573 (void)UNLINK(e_tmpname);
5575 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
5586 RETURNOP(cLOGOP->op_other);
5597 RETURNOP(cLOGOP->op_other);
5605 RETURNOP(cCONDOP->op_true);
5607 RETURNOP(cCONDOP->op_false);
5616 RETURNOP(cLOGOP->op_other);
5625 RETURNOP(cLOGOP->op_other);
5644 !(iogv = gv_fetchpv(SvPVX(sv), FALSE, SVt_PVIO)) ||
5645 !(ob=(SV*)GvIO(iogv)))
5647 char *name = SvPVX(((SVOP*)cLOGOP->op_other)->op_sv);
5649 char* packname = SvPV(sv, na);
5651 if (!isALPHA(*packname))
5652 DIE("Can't call method \"%s\" without a package or object reference", name);
5653 if (!(stash = fetch_stash(sv, FALSE)))
5654 DIE("Can't call method \"%s\" in empty package \"%s\"",
5656 gv = gv_fetchmethod(stash,name);
5658 DIE("Can't locate object method \"%s\" via package \"%s\"",
5666 if (!ob || !SvOBJECT(ob)) {
5667 char *name = SvPVX(((SVOP*)cLOGOP->op_other)->op_sv);
5668 DIE("Can't call method \"%s\" on unblessed reference", name);
5671 if (!gv) { /* nothing cached */
5672 char *name = SvPVX(((SVOP*)cLOGOP->op_other)->op_sv);
5673 gv = gv_fetchmethod(SvSTASH(ob),name);
5675 DIE("Can't locate object method \"%s\" via package \"%s\"",
5676 name, HvNAME(SvSTASH(ob)));
5691 register I32 items = SP - MARK;
5692 I32 hasargs = (op->op_flags & OPf_STACKED) != 0;
5693 register CONTEXT *cx;
5696 DIE("Not a subroutine reference");
5697 switch (SvTYPE(sv)) {
5701 DIE(no_usym, "a subroutine");
5702 if (op->op_private & HINT_STRICT_REFS)
5703 DIE(no_hardref, "a subroutine");
5704 gv = gv_fetchpv(SvPV(sv, na), FALSE, SVt_PVCV);
5714 if (SvTYPE(cv) == SVt_PVCV)
5719 DIE("Not a subroutine reference");
5724 if (!(cv = GvCV((GV*)sv)))
5725 cv = sv_2cv(sv, &stash, &gv, TRUE);
5734 DIE("Not a subroutine reference");
5736 if (!CvROOT(cv) && !CvUSERSUB(cv)) {
5737 if (gv = CvGV(cv)) {
5738 SV *tmpstr = sv_newmortal();
5740 gv_efullname(tmpstr, gv);
5741 ngv = gv_fetchmethod(GvESTASH(gv), "AUTOLOAD");
5742 if (ngv && ngv != gv && (cv = GvCV(ngv))) { /* One more chance... */
5744 sv_setsv(GvSV(gv), tmpstr);
5748 DIE("Undefined subroutine &%s called",SvPVX(tmpstr));
5750 DIE("Undefined subroutine called");
5753 if ((op->op_private & OPpDEREF_DB) && !CvUSERSUB(cv)) {
5757 gv_efullname(sv,gv);
5760 DIE("No DBsub routine");
5763 if (CvUSERSUB(cv)) {
5764 items = (*CvUSERSUB(cv))(CvUSERINDEX(cv), MARK - stack_base, items);
5765 sp = stack_base + items;
5771 AV* padlist = CvPADLIST(cv);
5772 SV** svp = AvARRAY(padlist);
5773 push_return(op->op_next);
5774 PUSHBLOCK(cx, CXt_SUB, MARK - 1);
5777 if (CvDEPTH(cv) >= 2) { /* save temporaries on recursion? */
5778 if (CvDEPTH(cv) == 100 && dowarn)
5779 warn("Deep recursion on subroutine \"%s\"",GvENAME(CvGV(cv)));
5780 if (CvDEPTH(cv) > AvFILL(padlist)) {
5781 AV *newpad = newAV();
5782 I32 ix = AvFILL((AV*)svp[1]);
5783 svp = AvARRAY(svp[0]);
5786 char *name = SvPVX(svp[ix]); /* XXX */
5788 av_store(newpad, ix--, (SV*)newAV());
5789 else if (*name == '%')
5790 av_store(newpad, ix--, (SV*)newHV());
5792 av_store(newpad, ix--, NEWSV(0,0));
5795 av_store(newpad, ix--, NEWSV(0,0));
5799 av_store(av, 0, Nullsv);
5800 av_store(newpad, 0, (SV*)av);
5804 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
5805 AvFILL(padlist) = CvDEPTH(cv);
5806 svp = AvARRAY(padlist);
5810 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
5812 AV* av = (AV*)curpad[0];
5815 cx->blk_sub.savearray = GvAV(defgv);
5816 cx->blk_sub.argarray = av;
5817 GvAV(defgv) = cx->blk_sub.argarray;
5820 if (items >= AvMAX(av)) {
5822 if (AvARRAY(av) != ary) {
5823 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
5824 SvPVX(av) = (char*)ary;
5826 if (items >= AvMAX(av)) {
5827 AvMAX(av) = items - 1;
5828 Renew(ary,items+1,SV*);
5830 SvPVX(av) = (char*)ary;
5833 Copy(MARK,AvARRAY(av),items,SV*);
5834 AvFILL(av) = items - 1;
5841 RETURNOP(CvSTART(cv));
5851 register CONTEXT *cx;
5856 if (gimme == G_SCALAR) {
5859 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
5862 *MARK = sv_mortalcopy(TOPs);
5870 for (mark = newsp + 1; mark <= SP; mark++)
5871 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP)))
5872 *mark = sv_mortalcopy(*mark);
5873 /* in case LEAVE wipes old return values */
5878 return pop_return();
5883 return pop_return();
5889 register I32 cxix = dopoptosub(cxstack_ix);
5891 register CONTEXT *cx;
5900 if (GIMME != G_ARRAY)
5904 nextcxix = dopoptosub(cxix - 1);
5905 if (DBsub && nextcxix >= 0 &&
5906 cxstack[nextcxix].blk_sub.cv == GvCV(DBsub))
5912 cx = &cxstack[cxix];
5913 if (GIMME != G_ARRAY) {
5916 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
5921 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
5922 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
5923 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
5926 if (cx->cx_type == CXt_SUB) {
5928 gv_efullname(sv, CvGV(cx->blk_sub.cv));
5929 PUSHs(sv_2mortal(sv));
5930 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
5933 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
5934 PUSHs(sv_2mortal(newSViv(0)));
5936 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
5937 if (cx->blk_sub.hasargs && curstash == debstash) {
5938 AV *ary = cx->blk_sub.argarray;
5942 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
5947 if (AvMAX(dbargs) < AvFILL(ary))
5948 av_store(dbargs, AvFILL(ary), Nullsv);
5949 Copy(AvARRAY(ary), AvARRAY(dbargs), AvFILL(ary)+1, SV*);
5950 AvFILL(dbargs) = AvFILL(ary);
5960 I32 oldscopeix = scopestack_ix;
5962 GvSV(firstgv) = *str1;
5963 GvSV(secondgv) = *str2;
5964 stack_sp = stack_base;
5967 result = SvIVx(AvARRAY(stack)[1]);
5968 while (scopestack_ix > oldscopeix) {
5975 sortcmp(strp1, strp2)
5979 register SV *str1 = *strp1;
5980 register SV *str2 = *strp2;
5983 if (SvCUR(str1) < SvCUR(str2)) {
5985 if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str1)))
5991 else if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str2)))
5993 else if (SvCUR(str1) == SvCUR(str2))
6003 if (SP - MARK != 1) {
6005 do_join(TARG, &sv_no, MARK, SP);
6006 tmps = SvPV(TARG, na);
6010 tmps = SvPV(TOPs, na);
6012 if (!tmps || !*tmps) {
6013 SV *error = GvSV(gv_fetchpv("@", TRUE, SVt_PV));
6014 SvUPGRADE(error, SVt_PV);
6015 if (SvPOK(error) && SvCUR(error))
6016 sv_catpv(error, "\t...caught");
6017 tmps = SvPV(error, na);
6019 if (!tmps || !*tmps)
6020 tmps = "Warning: something's wrong";
6029 if (SP - MARK != 1) {
6031 do_join(TARG, &sv_no, MARK, SP);
6032 tmps = SvPV(TARG, na);
6036 tmps = SvPV(TOPs, na);
6038 if (!tmps || !*tmps) {
6039 SV *error = GvSV(gv_fetchpv("@", TRUE, SVt_PV));
6040 SvUPGRADE(error, SVt_PV);
6041 if (SvPOK(error) && SvCUR(error))
6042 sv_catpv(error, "\t...propagated");
6043 tmps = SvPV(error, na);
6045 if (!tmps || !*tmps)
6060 sv_reset(tmps, curcop->cop_stash);
6073 TAINT_NOT; /* Each statement is presumed innocent */
6074 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
6082 TAINT_NOT; /* Each statement is presumed innocent */
6083 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
6086 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
6090 register CONTEXT *cx;
6107 DIE("No DB::DB routine defined");
6109 if (CvDEPTH(cv) >= 1) /* don't do recursive DB::DB call */
6111 push_return(op->op_next);
6112 PUSHBLOCK(cx, CXt_SUB, sp - 1);
6116 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
6117 RETURNOP(CvSTART(cv));
6126 TAINT_NOT; /* Each statement is presumed innocent */
6127 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
6129 oldsave = scopestack[scopestack_ix - 1];
6130 LEAVE_SCOPE(oldsave);
6137 register CONTEXT *cx;
6141 * We don't just use the GIMME macro here because it assumes there's
6142 * already a context, which ain't necessarily so at initial startup.
6145 if (op->op_flags & OPf_KNOW)
6146 gimme = op->op_flags & OPf_LIST;
6147 else if (cxstack_ix >= 0)
6148 gimme = cxstack[cxstack_ix].blk_gimme;
6155 PUSHBLOCK(cx, CXt_BLOCK, sp);
6163 register CONTEXT *cx;
6170 if (op->op_flags & OPf_KNOW)
6171 gimme = op->op_flags & OPf_LIST;
6172 else if (cxstack_ix >= 0)
6173 gimme = cxstack[cxstack_ix].blk_gimme;
6177 if (gimme == G_SCALAR) {
6180 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
6183 *MARK = sv_mortalcopy(TOPs);
6191 for (mark = newsp + 1; mark <= SP; mark++)
6192 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP)))
6193 *mark = sv_mortalcopy(*mark);
6194 /* in case LEAVE wipes old return values */
6210 register CONTEXT *cx;
6215 svp = &curpad[op->op_targ]; /* "my" variable */
6217 svp = &GvSV((GV*)POPs); /* symbol table variable */
6223 PUSHBLOCK(cx, CXt_LOOP, SP);
6224 PUSHLOOP(cx, svp, MARK);
6225 cx->blk_loop.iterary = stack;
6226 cx->blk_loop.iterix = MARK - stack_base;
6234 register CONTEXT *cx;
6238 cx = &cxstack[cxstack_ix];
6239 if (cx->cx_type != CXt_LOOP)
6240 DIE("panic: pp_iter");
6242 if (cx->blk_loop.iterix >= cx->blk_oldsp)
6245 if (sv = AvARRAY(cx->blk_loop.iterary)[++cx->blk_loop.iterix]) {
6247 *cx->blk_loop.itervar = sv;
6250 *cx->blk_loop.itervar = &sv_undef;
6258 register CONTEXT *cx;
6265 PUSHBLOCK(cx, CXt_LOOP, SP);
6266 PUSHLOOP(cx, 0, SP);
6274 register CONTEXT *cx;
6282 if (gimme == G_SCALAR) {
6284 *++newsp = sv_mortalcopy(*SP);
6286 *++newsp = &sv_undef;
6290 *++newsp = sv_mortalcopy(*++mark);
6303 register CONTEXT *cx;
6308 if (stack == sortstack) {
6309 AvARRAY(stack)[1] = *SP;
6313 cxix = dopoptosub(cxstack_ix);
6315 DIE("Can't return outside a subroutine");
6316 if (cxix < cxstack_ix)
6320 switch (cx->cx_type) {
6328 DIE("panic: return");
6332 if (gimme == G_SCALAR) {
6334 *++newsp = sv_mortalcopy(*SP);
6336 *++newsp = &sv_undef;
6337 if (optype == OP_REQUIRE && !SvTRUE(*newsp))
6338 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
6341 if (optype == OP_REQUIRE && MARK == SP)
6342 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
6344 *++newsp = sv_mortalcopy(*++MARK);
6349 return pop_return();
6356 register CONTEXT *cx;
6361 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
6362 /* XXX The sp is probably not right yet... */
6364 if (op->op_flags & OPf_SPECIAL) {
6365 cxix = dopoptoloop(cxstack_ix);
6367 DIE("Can't \"last\" outside a block");
6370 cxix = dopoptolabel(cPVOP->op_pv);
6372 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
6374 if (cxix < cxstack_ix)
6378 switch (cx->cx_type) {
6381 nextop = cx->blk_loop.last_op->op_next;
6386 nextop = pop_return();
6390 nextop = pop_return();
6397 if (gimme == G_SCALAR) {
6399 *++newsp = sv_mortalcopy(*SP);
6401 *++newsp = &sv_undef;
6405 *++newsp = sv_mortalcopy(*++mark);
6417 register CONTEXT *cx;
6420 if (op->op_flags & OPf_SPECIAL) {
6421 cxix = dopoptoloop(cxstack_ix);
6423 DIE("Can't \"next\" outside a block");
6426 cxix = dopoptolabel(cPVOP->op_pv);
6428 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
6430 if (cxix < cxstack_ix)
6434 oldsave = scopestack[scopestack_ix - 1];
6435 LEAVE_SCOPE(oldsave);
6436 return cx->blk_loop.next_op;
6443 register CONTEXT *cx;
6446 if (op->op_flags & OPf_SPECIAL) {
6447 cxix = dopoptoloop(cxstack_ix);
6449 DIE("Can't \"redo\" outside a block");
6452 cxix = dopoptolabel(cPVOP->op_pv);
6454 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
6456 if (cxix < cxstack_ix)
6460 oldsave = scopestack[scopestack_ix - 1];
6461 LEAVE_SCOPE(oldsave);
6462 return cx->blk_loop.redo_op;
6465 static OP* lastgotoprobe;
6468 dofindlabel(op,label,opstack)
6476 if (op->op_type == OP_LEAVE ||
6477 op->op_type == OP_SCOPE ||
6478 op->op_type == OP_LEAVELOOP ||
6479 op->op_type == OP_LEAVETRY)
6480 *ops++ = cUNOP->op_first;
6482 if (op->op_flags & OPf_KIDS) {
6483 /* First try all the kids at this level, since that's likeliest. */
6484 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
6485 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
6486 kCOP->cop_label && strEQ(kCOP->cop_label, label))
6489 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
6490 if (kid == lastgotoprobe)
6492 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
6493 if (ops > opstack &&
6494 (ops[-1]->op_type == OP_NEXTSTATE ||
6495 ops[-1]->op_type == OP_DBSTATE))
6500 if (op = dofindlabel(kid,label,ops))
6510 return pp_goto(ARGS);
6519 register CONTEXT *cx;
6525 if (op->op_flags & OPf_STACKED) {
6528 /* This egregious kludge implements goto &subroutine */
6529 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
6531 register CONTEXT *cx;
6532 CV* cv = (CV*)SvRV(sv);
6537 /* First do some returnish stuff. */
6538 cxix = dopoptosub(cxstack_ix);
6540 DIE("Can't goto subroutine outside a subroutine");
6541 if (cxix < cxstack_ix)
6545 *stack_sp = (SV*)cv;
6546 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
6547 items = AvFILL(cx->blk_sub.argarray) + 1;
6548 Copy(AvARRAY(cx->blk_sub.argarray), ++stack_sp, items, SV*);
6550 GvAV(defgv) = cx->blk_sub.savearray;
6552 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth)) {
6553 if (CvDELETED(cx->blk_sub.cv))
6554 SvREFCNT_dec(cx->blk_sub.cv);
6556 oldsave = scopestack[scopestack_ix - 1];
6557 LEAVE_SCOPE(oldsave);
6559 /* Now do some callish stuff. */
6560 if (CvUSERSUB(cv)) {
6561 items = (*CvUSERSUB(cv))(CvUSERINDEX(cv),
6562 mark - stack_base, items);
6563 sp = stack_base + items;
6565 return pop_return();
6568 AV* padlist = CvPADLIST(cv);
6569 SV** svp = AvARRAY(padlist);
6570 cx->blk_sub.cv = cv;
6571 cx->blk_sub.olddepth = CvDEPTH(cv);
6573 if (CvDEPTH(cv) >= 2) { /* save temporaries on recursion? */
6574 if (CvDEPTH(cv) == 100 && dowarn)
6575 warn("Deep recursion on subroutine \"%s\"",
6577 if (CvDEPTH(cv) > AvFILL(padlist)) {
6578 AV *newpad = newAV();
6579 I32 ix = AvFILL((AV*)svp[1]);
6580 svp = AvARRAY(svp[0]);
6583 char *name = SvPVX(svp[ix]); /* XXX */
6585 av_store(newpad, ix--, (SV*)newAV());
6586 else if (*name == '%')
6587 av_store(newpad, ix--, (SV*)newHV());
6589 av_store(newpad, ix--, NEWSV(0,0));
6592 av_store(newpad, ix--, NEWSV(0,0));
6594 if (cx->blk_sub.hasargs) {
6596 av_store(av, 0, Nullsv);
6597 av_store(newpad, 0, (SV*)av);
6601 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
6602 AvFILL(padlist) = CvDEPTH(cv);
6603 svp = AvARRAY(padlist);
6607 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
6608 if (cx->blk_sub.hasargs) {
6609 AV* av = (AV*)curpad[0];
6612 cx->blk_sub.savearray = GvAV(defgv);
6613 cx->blk_sub.argarray = av;
6614 GvAV(defgv) = cx->blk_sub.argarray;
6617 if (items >= AvMAX(av)) {
6619 if (AvARRAY(av) != ary) {
6620 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
6621 SvPVX(av) = (char*)ary;
6623 if (items >= AvMAX(av)) {
6624 AvMAX(av) = items - 1;
6625 Renew(ary,items+1,SV*);
6627 SvPVX(av) = (char*)ary;
6630 Copy(mark,AvARRAY(av),items,SV*);
6631 AvFILL(av) = items - 1;
6638 RETURNOP(CvSTART(cv));
6642 label = SvPV(sv,na);
6644 else if (op->op_flags & OPf_SPECIAL) {
6645 if (op->op_type != OP_DUMP)
6646 DIE("goto must have label");
6649 label = cPVOP->op_pv;
6651 if (label && *label) {
6658 for (ix = cxstack_ix; ix >= 0; ix--) {
6660 switch (cx->cx_type) {
6662 gotoprobe = CvROOT(cx->blk_sub.cv);
6665 gotoprobe = eval_root; /* XXX not good for nested eval */
6668 gotoprobe = cx->blk_oldcop->op_sibling;
6674 gotoprobe = cx->blk_oldcop->op_sibling;
6676 gotoprobe = main_root;
6682 gotoprobe = main_root;
6685 retop = dofindlabel(gotoprobe, label, enterops);
6688 lastgotoprobe = gotoprobe;
6691 DIE("Can't find label %s", label);
6693 /* pop unwanted frames */
6695 if (ix < cxstack_ix) {
6702 oldsave = scopestack[scopestack_ix - 1];
6703 LEAVE_SCOPE(oldsave);
6706 /* push wanted frames */
6710 for (ix = 0 + (gotoprobe == main_root); enterops[ix]; ix++) {
6718 if (op->op_type == OP_DUMP) {
6724 restartop = 0; /* hmm, must be GNU unexec().. */
6748 double value = SvNVx(GvSV(cCOP->cop_gv));
6749 register I32 match = (I32)value;
6752 if (((double)match) > value)
6753 --match; /* was fractional--truncate other way */
6755 match -= cCOP->uop.scop.scop_offset;
6758 else if (match > cCOP->uop.scop.scop_max)
6759 match = cCOP->uop.scop.scop_max;
6760 op = cCOP->uop.scop.scop_next[match];
6770 op = op->op_next; /* can't assume anything */
6772 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
6773 match -= cCOP->uop.scop.scop_offset;
6776 else if (match > cCOP->uop.scop.scop_max)
6777 match = cCOP->uop.scop.scop_max;
6778 op = cCOP->uop.scop.scop_next[match];
6798 tmps = SvPV(sv, len);
6799 if (do_open(gv, tmps, len)) {
6800 IoLINES(GvIO(gv)) = 0;
6801 PUSHi( (I32)forkprocess );
6803 else if (forkprocess == 0) /* we are a new child */
6820 PUSHs( do_close(gv, TRUE) ? &sv_yes : &sv_no );
6844 do_close(rgv, FALSE);
6846 do_close(wgv, FALSE);
6851 IoIFP(rstio) = fdopen(fd[0], "r");
6852 IoOFP(wstio) = fdopen(fd[1], "w");
6853 IoIFP(wstio) = IoOFP(wstio);
6854 IoTYPE(rstio) = '<';
6855 IoTYPE(wstio) = '>';
6857 if (!IoIFP(rstio) || !IoOFP(wstio)) {
6858 if (IoIFP(rstio)) fclose(IoIFP(rstio));
6860 if (IoOFP(wstio)) fclose(IoOFP(wstio));
6870 DIE(no_func, "pipe");
6883 if (!gv || !(io = GvIO(gv)) || !(fp = IoIFP(io)))
6901 TAINT_PROPER("umask");
6904 DIE(no_func, "Unsupported function umask");
6922 if (!gv || !(io = GvIO(gv)) || !(fp = IoIFP(io)))
6927 if (!fflush(fp) && (fp->_flag |= _IOBIN))
6932 if (setmode(fileno(fp), OP_BINARY) != -1)
6950 SV **mark = stack_base + *markstack_ptr + 1; /* reuse in entersubr */
6954 stash = fetch_stash(mark[1], FALSE);
6955 if (!stash || !(gv = gv_fetchmethod(stash, "new")) || !GvCV(gv))
6956 DIE("Can't tie to package %s", SvPV(mark[1],na));
6958 Zero(&myop, 1, BINOP);
6959 myop.op_last = (OP *) &myop;
6960 myop.op_next = Nullop;
6961 myop.op_flags = OPf_STACKED;
6970 if (op = pp_entersubr())
6974 if (!sv_isobject(TOPs))
6975 DIE("new didn't return an object");
6977 if (SvTYPE(varsv) == SVt_PVHV || SvTYPE(varsv) == SVt_PVAV)
6978 sv_magic(varsv, sv, 'P', 0, 0);
6980 sv_magic(varsv, sv, 'p', 0, -1);
6989 if (SvTYPE(TOPs) == SVt_PVHV || SvTYPE(TOPs) == SVt_PVAV)
6990 sv_unmagic(TOPs, 'P');
6992 sv_unmagic(TOPs, 'p');
7008 sv = sv_mortalcopy(&sv_no);
7009 sv_setpv(sv, "Any_DBM_File");
7010 stash = fetch_stash(sv, FALSE);
7011 if (!stash || !(gv = gv_fetchmethod(stash, "new")) || !GvCV(gv))
7012 DIE("No dbm on this machine");
7014 Zero(&myop, 1, BINOP);
7015 myop.op_last = (OP *) &myop;
7016 myop.op_next = Nullop;
7017 myop.op_flags = OPf_STACKED;
7030 PUSHs(sv_2mortal(newSViv(O_RDWR|O_CREAT)));
7032 PUSHs(sv_2mortal(newSViv(O_RDWR)));
7036 if (op = pp_entersubr())
7042 sv_magic((SV*)hv, sv, 'P', 0, 0);
7048 return pp_untie(ARGS);
7062 struct timeval timebuf;
7063 struct timeval *tbuf = &timebuf;
7066 #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
7071 # if BYTEORDER & 0xf0000
7072 # define ORDERBYTE (0x88888888 - BYTEORDER)
7074 # define ORDERBYTE (0x4444 - BYTEORDER)
7080 for (i = 1; i <= 3; i++) {
7088 #if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
7089 growsize = maxlen; /* little endians can use vecs directly */
7097 masksize = NFDBITS / NBBY;
7099 masksize = sizeof(long); /* documented int, everyone seems to use long */
7101 growsize = maxlen + (masksize - (maxlen % masksize));
7102 Zero(&fd_sets[0], 4, char*);
7110 timebuf.tv_sec = (long)value;
7111 value -= (double)timebuf.tv_sec;
7112 timebuf.tv_usec = (long)(value * 1000000.0);
7115 tbuf = Null(struct timeval*);
7117 for (i = 1; i <= 3; i++) {
7125 Sv_Grow(sv, growsize);
7126 s = SvPV(sv, na) + j;
7127 while (++j <= growsize) {
7131 #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
7133 New(403, fd_sets[i], growsize, char);
7134 for (offset = 0; offset < growsize; offset += masksize) {
7135 for (j = 0, k=ORDERBYTE; j < masksize; j++, (k >>= 4))
7136 fd_sets[i][j+offset] = s[(k % masksize) + offset];
7139 fd_sets[i] = SvPVX(sv);
7149 #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
7150 for (i = 1; i <= 3; i++) {
7154 for (offset = 0; offset < growsize; offset += masksize) {
7155 for (j = 0, k=ORDERBYTE; j < masksize; j++, (k >>= 4))
7156 s[(k % masksize) + offset] = fd_sets[i][j+offset];
7158 Safefree(fd_sets[i]);
7164 if (GIMME == G_ARRAY && tbuf) {
7165 value = (double)(timebuf.tv_sec) +
7166 (double)(timebuf.tv_usec) / 1000000.0;
7167 PUSHs(sv = sv_mortalcopy(&sv_no));
7168 sv_setnv(sv, value);
7172 DIE("select not implemented");
7179 GV *oldgv = defoutgv;
7180 if (op->op_private > 0) {
7181 defoutgv = (GV*)POPs;
7182 if (!GvIO(defoutgv))
7183 GvIO(defoutgv) = newIO();
7184 curoutgv = defoutgv;
7186 gv_efullname(TARG, oldgv);
7202 if (!gv || do_eof(gv)) /* make sure we have fp with something */
7205 sv_setpv(TARG, " ");
7206 *SvPVX(TARG) = getc(IoIFP(GvIO(gv))); /* should never be EOF */
7213 return pp_sysread(ARGS);
7222 register CONTEXT *cx;
7228 PUSHBLOCK(cx, CXt_SUB, stack_sp);
7230 defoutgv = gv; /* locally select filehandle so $% et al work */
7265 SV *tmpstr = sv_newmortal();
7266 gv_efullname(tmpstr, gv);
7267 DIE("Undefined format \"%s\" called",SvPVX(tmpstr));
7269 DIE("Not a format reference");
7272 return doform(cv,gv,op->op_next);
7278 GV *gv = cxstack[cxstack_ix].blk_sub.gv;
7279 register IO *io = GvIO(gv);
7280 FILE *ofp = IoOFP(io);
7285 register CONTEXT *cx;
7287 DEBUG_f(fprintf(stderr,"left=%ld, todo=%ld\n",
7288 (long)IoLINES_LEFT(io), (long)FmLINES(formtarget)));
7289 if (IoLINES_LEFT(io) < FmLINES(formtarget) &&
7290 formtarget != toptarget)
7292 if (!IoTOP_GV(io)) {
7296 if (!IoTOP_NAME(io)) {
7297 if (!IoFMT_NAME(io))
7298 IoFMT_NAME(io) = savestr(GvNAME(gv));
7299 sprintf(tmpbuf, "%s_TOP", IoFMT_NAME(io));
7300 topgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVFM);
7301 if (topgv && GvFORM(topgv))
7302 IoTOP_NAME(io) = savestr(tmpbuf);
7304 IoTOP_NAME(io) = savestr("top");
7306 topgv = gv_fetchpv(IoTOP_NAME(io),FALSE, SVt_PVFM);
7307 if (!topgv || !GvFORM(topgv)) {
7308 IoLINES_LEFT(io) = 100000000;
7311 IoTOP_GV(io) = topgv;
7313 if (IoLINES_LEFT(io) >= 0 && IoPAGE(io) > 0)
7314 fwrite(SvPVX(formfeed), SvCUR(formfeed), 1, ofp);
7315 IoLINES_LEFT(io) = IoPAGE_LEN(io);
7317 formtarget = toptarget;
7318 return doform(GvFORM(IoTOP_GV(io)),gv,op);
7330 warn("Filehandle only opened for input");
7332 warn("Write on closed filehandle");
7337 if ((IoLINES_LEFT(io) -= FmLINES(formtarget)) < 0) {
7339 warn("page overflow");
7341 if (!fwrite(SvPVX(formtarget), 1, SvCUR(formtarget), ofp) ||
7345 FmLINES(formtarget) = 0;
7346 SvCUR_set(formtarget, 0);
7347 if (IoFLAGS(io) & IOf_FLUSH)
7352 formtarget = bodytarget;
7354 return pop_return();
7359 dSP; dMARK; dORIGMARK;
7363 SV *sv = NEWSV(0,0);
7365 if (op->op_flags & OPf_STACKED)
7369 if (!(io = GvIO(gv))) {
7371 warn("Filehandle %s never opened", GvNAME(gv));
7375 else if (!(fp = IoOFP(io))) {
7378 warn("Filehandle %s opened only for input", GvNAME(gv));
7380 warn("printf on closed filehandle %s", GvNAME(gv));
7386 do_sprintf(sv, SP - MARK, MARK + 1);
7387 if (!do_print(sv, fp))
7390 if (IoFLAGS(io) & IOf_FLUSH)
7391 if (fflush(fp) == EOF)
7408 dSP; dMARK; dORIGMARK;
7413 if (op->op_flags & OPf_STACKED)
7417 if (!(io = GvIO(gv))) {
7419 warn("Filehandle %s never opened", GvNAME(gv));
7423 else if (!(fp = IoOFP(io))) {
7426 warn("Filehandle %s opened only for input", GvNAME(gv));
7428 warn("print on closed filehandle %s", GvNAME(gv));
7436 while (MARK <= SP) {
7437 if (!do_print(*MARK, fp))
7441 if (fwrite(ofs, 1, ofslen, fp) == 0 || ferror(fp)) {
7449 while (MARK <= SP) {
7450 if (!do_print(*MARK, fp))
7459 if (fwrite(ors, 1, orslen, fp) == 0 || ferror(fp))
7462 if (IoFLAGS(io) & IOf_FLUSH)
7463 if (fflush(fp) == EOF)
7479 dSP; dMARK; dORIGMARK; dTARGET;
7493 buffer = SvPV(bufstr, blen);
7494 length = SvIVx(*++MARK);
7495 if (SvTHINKFIRST(bufstr)) {
7496 if (SvREADONLY(bufstr) && curcop != &compiling)
7503 offset = SvIVx(*++MARK);
7507 warn("Too many args on read");
7509 if (!io || !IoIFP(io))
7512 if (op->op_type == OP_RECV) {
7513 bufsize = sizeof buf;
7514 SvGROW(bufstr, length+1), (buffer = SvPV(bufstr, blen)); /* sneaky */
7515 length = recvfrom(fileno(IoIFP(io)), buffer, length, offset,
7516 (struct sockaddr *)buf, &bufsize);
7519 SvCUR_set(bufstr, length);
7520 *SvEND(bufstr) = '\0';
7523 sv_magic(bufstr, 0, 't', 0, 0);
7525 sv_setpvn(TARG, buf, bufsize);
7530 if (op->op_type == OP_RECV)
7531 DIE(no_sock_func, "recv");
7533 SvGROW(bufstr, length+offset+1), (buffer = SvPV(bufstr, blen)); /* sneaky */
7534 if (op->op_type == OP_SYSREAD) {
7535 length = read(fileno(IoIFP(io)), buffer+offset, length);
7539 if (IoTYPE(io) == 's') {
7540 bufsize = sizeof buf;
7541 length = recvfrom(fileno(IoIFP(io)), buffer+offset, length, 0,
7542 (struct sockaddr *)buf, &bufsize);
7546 length = fread(buffer+offset, 1, length, IoIFP(io));
7549 SvCUR_set(bufstr, length+offset);
7550 *SvEND(bufstr) = '\0';
7553 sv_magic(bufstr, 0, 't', 0, 0);
7565 return pp_send(ARGS);
7570 dSP; dMARK; dORIGMARK; dTARGET;
7583 buffer = SvPV(bufstr, blen);
7584 length = SvIVx(*++MARK);
7587 if (!io || !IoIFP(io)) {
7590 if (op->op_type == OP_SYSWRITE)
7591 warn("Syswrite on closed filehandle");
7593 warn("Send on closed socket");
7596 else if (op->op_type == OP_SYSWRITE) {
7598 offset = SvIVx(*++MARK);
7602 warn("Too many args on syswrite");
7603 length = write(fileno(IoIFP(io)), buffer+offset, length);
7606 else if (SP >= MARK) {
7609 warn("Too many args on send");
7610 buffer = SvPVx(*++MARK, mlen);
7611 length = sendto(fileno(IoIFP(io)), buffer, blen, length,
7612 (struct sockaddr *)buffer, mlen);
7615 length = send(fileno(IoIFP(io)), buffer, blen, length);
7618 DIE(no_sock_func, "send");
7633 return pp_sysread(ARGS);
7644 gv = last_in_gv = (GV*)POPs;
7645 PUSHs(!gv || do_eof(gv) ? &sv_yes : &sv_no);
7657 gv = last_in_gv = (GV*)POPs;
7658 PUSHi( do_tell(gv) );
7669 gv = last_in_gv = (GV*)POPs;
7670 PUSHs( do_seek(gv, offset, whence) ? &sv_yes : &sv_no );
7677 Off_t len = (Off_t)POPn;
7682 #if defined(HAS_TRUNCATE) || defined(HAS_CHSIZE)
7684 if (op->op_flags & OPf_SPECIAL) {
7685 tmpgv = gv_fetchpv(POPp,FALSE, SVt_PVIO);
7686 if (!tmpgv || !GvIO(tmpgv) || !IoIFP(GvIO(tmpgv)) ||
7687 ftruncate(fileno(IoIFP(GvIO(tmpgv))), len) < 0)
7690 else if (truncate(POPp, len) < 0)
7693 if (op->op_flags & OPf_SPECIAL) {
7694 tmpgv = gv_fetchpv(POPp,FALSE, SVt_PVIO);
7695 if (!tmpgv || !GvIO(tmpgv) || !IoIFP(GvIO(tmpgv)) ||
7696 chsize(fileno(IoIFP(GvIO(tmpgv))), len) < 0)
7702 if ((tmpfd = open(POPp, 0)) < 0)
7705 if (chsize(tmpfd, len) < 0)
7718 DIE("truncate not implemented");
7724 return pp_ioctl(ARGS);
7731 unsigned int func = U_I(POPn);
7732 int optype = op->op_type;
7738 if (!io || !argstr || !IoIFP(io)) {
7739 errno = EBADF; /* well, sort of... */
7743 if (SvPOK(argstr) || !SvNIOK(argstr)) {
7746 s = SvPV(argstr, len);
7747 retval = IOCPARM_LEN(func);
7749 Sv_Grow(argstr, retval+1);
7750 SvCUR_set(argstr, retval);
7754 s[SvCUR(argstr)] = 17; /* a little sanity check here */
7757 retval = SvIV(argstr);
7759 s = (char*)(long)retval; /* ouch */
7761 s = (char*)retval; /* ouch */
7765 TAINT_PROPER(optype == OP_IOCTL ? "ioctl" : "fcntl");
7767 if (optype == OP_IOCTL)
7768 retval = ioctl(fileno(IoIFP(io)), func, s);
7771 DIE("fcntl is not implemented");
7774 retval = fcntl(fileno(IoIFP(io)), func, s);
7776 DIE("fcntl is not implemented");
7780 if (SvPOK(argstr)) {
7781 if (s[SvCUR(argstr)] != 17)
7782 DIE("Possible memory corruption: %s overflowed 3rd argument",
7784 s[SvCUR(argstr)] = 0; /* put our null back */
7793 PUSHp("0 but true", 10);
7812 fp = IoIFP(GvIO(gv));
7816 value = (I32)(flock(fileno(fp), argtype) >= 0);
7823 DIE(no_func, "flock()");
7835 int protocol = POPi;
7849 do_close(gv, FALSE);
7851 TAINT_PROPER("socket");
7852 fd = socket(domain, type, protocol);
7855 IoIFP(io) = fdopen(fd, "r"); /* stdio gets confused about sockets */
7856 IoOFP(io) = fdopen(fd, "w");
7858 if (!IoIFP(io) || !IoOFP(io)) {
7859 if (IoIFP(io)) fclose(IoIFP(io));
7860 if (IoOFP(io)) fclose(IoOFP(io));
7861 if (!IoIFP(io) && !IoOFP(io)) close(fd);
7867 DIE(no_sock_func, "socket");
7874 #ifdef HAS_SOCKETPAIR
7879 int protocol = POPi;
7892 do_close(gv1, FALSE);
7894 do_close(gv2, FALSE);
7896 TAINT_PROPER("socketpair");
7897 if (socketpair(domain, type, protocol, fd) < 0)
7899 IoIFP(io1) = fdopen(fd[0], "r");
7900 IoOFP(io1) = fdopen(fd[0], "w");
7902 IoIFP(io2) = fdopen(fd[1], "r");
7903 IoOFP(io2) = fdopen(fd[1], "w");
7905 if (!IoIFP(io1) || !IoOFP(io1) || !IoIFP(io2) || !IoOFP(io2)) {
7906 if (IoIFP(io1)) fclose(IoIFP(io1));
7907 if (IoOFP(io1)) fclose(IoOFP(io1));
7908 if (!IoIFP(io1) && !IoOFP(io1)) close(fd[0]);
7909 if (IoIFP(io2)) fclose(IoIFP(io2));
7910 if (IoOFP(io2)) fclose(IoOFP(io2));
7911 if (!IoIFP(io2) && !IoOFP(io2)) close(fd[1]);
7917 DIE(no_sock_func, "socketpair");
7928 register IO *io = GvIOn(gv);
7931 if (!io || !IoIFP(io))
7934 addr = SvPV(addrstr, len);
7935 TAINT_PROPER("bind");
7936 if (bind(fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
7943 warn("bind() on closed fd");
7947 DIE(no_sock_func, "bind");
7958 register IO *io = GvIOn(gv);
7961 if (!io || !IoIFP(io))
7964 addr = SvPV(addrstr, len);
7965 TAINT_PROPER("connect");
7966 if (connect(fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
7973 warn("connect() on closed fd");
7977 DIE(no_sock_func, "connect");
7987 register IO *io = GvIOn(gv);
7989 if (!io || !IoIFP(io))
7992 if (listen(fileno(IoIFP(io)), backlog) >= 0)
7999 warn("listen() on closed fd");
8003 DIE(no_sock_func, "listen");
8015 int len = sizeof buf;
8027 if (!gstio || !IoIFP(gstio))
8032 do_close(ngv, FALSE);
8034 fd = accept(fileno(IoIFP(gstio)), (struct sockaddr *)buf, &len);
8037 IoIFP(nstio) = fdopen(fd, "r");
8038 IoOFP(nstio) = fdopen(fd, "w");
8039 IoTYPE(nstio) = 's';
8040 if (!IoIFP(nstio) || !IoOFP(nstio)) {
8041 if (IoIFP(nstio)) fclose(IoIFP(nstio));
8042 if (IoOFP(nstio)) fclose(IoOFP(nstio));
8043 if (!IoIFP(nstio) && !IoOFP(nstio)) close(fd);
8052 warn("accept() on closed fd");
8059 DIE(no_sock_func, "accept");
8069 register IO *io = GvIOn(gv);
8071 if (!io || !IoIFP(io))
8074 PUSHi( shutdown(fileno(IoIFP(io)), how) >= 0 );
8079 warn("shutdown() on closed fd");
8083 DIE(no_sock_func, "shutdown");
8090 return pp_ssockopt(ARGS);
8092 DIE(no_sock_func, "getsockopt");
8100 int optype = op->op_type;
8103 unsigned int optname;
8108 if (optype == OP_GSOCKOPT)
8109 sv = sv_2mortal(NEWSV(22, 257));
8112 optname = (unsigned int) POPi;
8113 lvl = (unsigned int) POPi;
8117 if (!io || !IoIFP(io))
8120 fd = fileno(IoIFP(io));
8125 if (getsockopt(fd, lvl, optname, SvPVX(sv), (int*)&SvCUR(sv)) < 0)
8130 if (setsockopt(fd, lvl, optname, SvPVX(sv), SvCUR(sv)) < 0)
8139 warn("[gs]etsockopt() on closed fd");
8145 DIE(no_sock_func, "setsockopt");
8152 return pp_getpeername(ARGS);
8154 DIE(no_sock_func, "getsockname");
8162 int optype = op->op_type;
8166 register IO *io = GvIOn(gv);
8168 if (!io || !IoIFP(io))
8171 sv = sv_2mortal(NEWSV(22, 257));
8174 fd = fileno(IoIFP(io));
8176 case OP_GETSOCKNAME:
8177 if (getsockname(fd, (struct sockaddr *)SvPVX(sv), (int*)&SvCUR(sv)) < 0)
8180 case OP_GETPEERNAME:
8181 if (getpeername(fd, (struct sockaddr *)SvPVX(sv), (int*)&SvCUR(sv)) < 0)
8190 warn("get{sock, peer}name() on closed fd");
8196 DIE(no_sock_func, "getpeername");
8204 return pp_stat(ARGS);
8213 if (op->op_flags & OPf_SPECIAL) {
8214 tmpgv = cGVOP->op_gv;
8215 if (tmpgv != defgv) {
8216 laststype = OP_STAT;
8218 sv_setpv(statname, "");
8219 if (!GvIO(tmpgv) || !IoIFP(GvIO(tmpgv)) ||
8220 fstat(fileno(IoIFP(GvIO(tmpgv))), &statcache) < 0) {
8225 else if (laststatval < 0)
8229 sv_setpv(statname, POPp);
8232 laststype = op->op_type;
8233 if (op->op_type == OP_LSTAT)
8234 laststatval = lstat(SvPV(statname, na), &statcache);
8237 laststatval = stat(SvPV(statname, na), &statcache);
8238 if (laststatval < 0) {
8239 if (dowarn && strchr(SvPV(statname, na), '\n'))
8240 warn(warn_nl, "stat");
8246 if (GIMME != G_ARRAY) {
8253 PUSHs(sv_2mortal(newSViv((I32)statcache.st_dev)));
8254 PUSHs(sv_2mortal(newSViv((I32)statcache.st_ino)));
8255 PUSHs(sv_2mortal(newSViv((I32)statcache.st_mode)));
8256 PUSHs(sv_2mortal(newSViv((I32)statcache.st_nlink)));
8257 PUSHs(sv_2mortal(newSViv((I32)statcache.st_uid)));
8258 PUSHs(sv_2mortal(newSViv((I32)statcache.st_gid)));
8259 PUSHs(sv_2mortal(newSViv((I32)statcache.st_rdev)));
8260 PUSHs(sv_2mortal(newSViv((I32)statcache.st_size)));
8261 PUSHs(sv_2mortal(newSViv((I32)statcache.st_atime)));
8262 PUSHs(sv_2mortal(newSViv((I32)statcache.st_mtime)));
8263 PUSHs(sv_2mortal(newSViv((I32)statcache.st_ctime)));
8264 #ifdef USE_STAT_BLOCKS
8265 PUSHs(sv_2mortal(newSViv((I32)statcache.st_blksize)));
8266 PUSHs(sv_2mortal(newSViv((I32)statcache.st_blocks)));
8268 PUSHs(sv_2mortal(newSVpv("", 0)));
8269 PUSHs(sv_2mortal(newSVpv("", 0)));
8277 I32 result = my_stat(ARGS);
8281 if (cando(S_IRUSR, 0, &statcache))
8288 I32 result = my_stat(ARGS);
8292 if (cando(S_IWUSR, 0, &statcache))
8299 I32 result = my_stat(ARGS);
8303 if (cando(S_IXUSR, 0, &statcache))
8310 I32 result = my_stat(ARGS);
8314 if (cando(S_IRUSR, 1, &statcache))
8321 I32 result = my_stat(ARGS);
8325 if (cando(S_IWUSR, 1, &statcache))
8332 I32 result = my_stat(ARGS);
8336 if (cando(S_IXUSR, 1, &statcache))
8343 I32 result = my_stat(ARGS);
8352 return pp_ftrowned(ARGS);
8357 I32 result = my_stat(ARGS);
8361 if (statcache.st_uid == (op->op_type == OP_FTEOWNED ? euid : uid) )
8368 I32 result = my_stat(ARGS);
8372 if (!statcache.st_size)
8379 I32 result = my_stat(ARGS);
8383 PUSHi(statcache.st_size);
8389 I32 result = my_stat(ARGS);
8393 PUSHn( (basetime - statcache.st_mtime) / 86400.0 );
8399 I32 result = my_stat(ARGS);
8403 PUSHn( (basetime - statcache.st_atime) / 86400.0 );
8409 I32 result = my_stat(ARGS);
8413 PUSHn( (basetime - statcache.st_ctime) / 86400.0 );
8419 I32 result = my_stat(ARGS);
8423 if (S_ISSOCK(statcache.st_mode))
8430 I32 result = my_stat(ARGS);
8434 if (S_ISCHR(statcache.st_mode))
8441 I32 result = my_stat(ARGS);
8445 if (S_ISBLK(statcache.st_mode))
8452 I32 result = my_stat(ARGS);
8456 if (S_ISREG(statcache.st_mode))
8463 I32 result = my_stat(ARGS);
8467 if (S_ISDIR(statcache.st_mode))
8474 I32 result = my_stat(ARGS);
8478 if (S_ISFIFO(statcache.st_mode))
8485 I32 result = my_lstat(ARGS);
8489 if (S_ISLNK(statcache.st_mode))
8498 I32 result = my_stat(ARGS);
8502 if (statcache.st_mode & S_ISUID)
8512 I32 result = my_stat(ARGS);
8516 if (statcache.st_mode & S_ISGID)
8526 I32 result = my_stat(ARGS);
8530 if (statcache.st_mode & S_ISVTX)
8542 if (op->op_flags & OPf_SPECIAL) {
8547 gv = gv_fetchpv(tmps = POPp, FALSE, SVt_PVIO);
8548 if (gv && GvIO(gv) && IoIFP(GvIO(gv)))
8549 fd = fileno(IoIFP(GvIO(gv)));
8550 else if (isDIGIT(*tmps))
8566 register STDCHAR *s;
8570 if (op->op_flags & OPf_SPECIAL) {
8572 if (cGVOP->op_gv == defgv) {
8577 goto really_filename;
8581 statgv = cGVOP->op_gv;
8582 sv_setpv(statname, "");
8585 if (io && IoIFP(io)) {
8586 #if defined(USE_STD_STDIO) || defined(atarist) /* this will work with atariST */
8587 fstat(fileno(IoIFP(io)), &statcache);
8588 if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */
8589 if (op->op_type == OP_FTTEXT)
8593 if (IoIFP(io)->_cnt <= 0) {
8594 i = getc(IoIFP(io));
8596 (void)ungetc(i, IoIFP(io));
8598 if (IoIFP(io)->_cnt <= 0) /* null file is anything */
8600 len = IoIFP(io)->_cnt + (IoIFP(io)->_ptr - IoIFP(io)->_base);
8601 s = IoIFP(io)->_base;
8603 DIE("-T and -B not implemented on filehandles");
8608 warn("Test on unopened file <%s>",
8609 GvENAME(cGVOP->op_gv));
8617 sv_setpv(statname, SvPV(sv, na));
8619 i = open(SvPV(sv, na), 0);
8621 if (dowarn && strchr(SvPV(sv, na), '\n'))
8622 warn(warn_nl, "open");
8625 fstat(i, &statcache);
8626 len = read(i, tbuf, 512);
8629 if (S_ISDIR(statcache.st_mode) && op->op_type == OP_FTTEXT)
8630 RETPUSHNO; /* special case NFS directories */
8631 RETPUSHYES; /* null file is anything */
8636 /* now scan s to look for textiness */
8638 for (i = 0; i < len; i++, s++) {
8639 if (!*s) { /* null never allowed in text */
8646 *s != '\n' && *s != '\r' && *s != '\b' &&
8647 *s != '\t' && *s != '\f' && *s != 27)
8651 if ((odd * 10 > len) == (op->op_type == OP_FTTEXT)) /* allow 10% odd */
8659 return pp_fttext(ARGS);
8675 if (!tmps || !*tmps) {
8676 svp = hv_fetch(GvHVn(envgv), "HOME", 4, FALSE);
8678 tmps = SvPV(*svp, na);
8680 if (!tmps || !*tmps) {
8681 svp = hv_fetch(GvHVn(envgv), "LOGDIR", 6, FALSE);
8683 tmps = SvPV(*svp, na);
8685 TAINT_PROPER("chdir");
8686 PUSHi( chdir(tmps) >= 0 );
8692 dSP; dMARK; dTARGET;
8695 value = (I32)apply(op->op_type, MARK, SP);
8700 DIE(no_func, "Unsupported function chown");
8710 tmps = SvPVx(GvSV(defgv), na);
8713 TAINT_PROPER("chroot");
8714 PUSHi( chroot(tmps) >= 0 );
8717 DIE(no_func, "chroot");
8723 dSP; dMARK; dTARGET;
8725 value = (I32)apply(op->op_type, MARK, SP);
8733 dSP; dMARK; dTARGET;
8735 value = (I32)apply(op->op_type, MARK, SP);
8743 dSP; dMARK; dTARGET;
8745 value = (I32)apply(op->op_type, MARK, SP);
8757 char *tmps = SvPV(TOPs, na);
8758 TAINT_PROPER("rename");
8760 anum = rename(tmps, tmps2);
8762 if (same_dirent(tmps2, tmps)) /* can always rename to same name */
8765 if (euid || stat(tmps2, &statbuf) < 0 || !S_ISDIR(statbuf.st_mode))
8766 (void)UNLINK(tmps2);
8767 if (!(anum = link(tmps, tmps2)))
8768 anum = UNLINK(tmps);
8780 char *tmps = SvPV(TOPs, na);
8781 TAINT_PROPER("link");
8782 SETi( link(tmps, tmps2) >= 0 );
8784 DIE(no_func, "Unsupported function link");
8794 char *tmps = SvPV(TOPs, na);
8795 TAINT_PROPER("symlink");
8796 SETi( symlink(tmps, tmps2) >= 0 );
8799 DIE(no_func, "symlink");
8810 tmps = SvPVx(GvSV(defgv), na);
8813 len = readlink(tmps, buf, sizeof buf);
8821 RETSETUNDEF; /* just pretend it's a normal file */
8825 #if !defined(HAS_MKDIR) || !defined(HAS_RMDIR)
8827 dooneliner(cmd, filename)
8838 for (s = mybuf+strlen(mybuf); *filename; ) {
8843 myfp = my_popen(mybuf, "r");
8846 s = fgets(mybuf, sizeof mybuf, myfp);
8847 (void)my_pclose(myfp);
8849 for (errno = 1; errno < sys_nerr; errno++) {
8850 if (instr(mybuf, sys_errlist[errno])) /* you don't see this */
8855 #define EACCES EPERM
8857 if (instr(mybuf, "cannot make"))
8859 else if (instr(mybuf, "existing file"))
8861 else if (instr(mybuf, "ile exists"))
8863 else if (instr(mybuf, "non-exist"))
8865 else if (instr(mybuf, "does not exist"))
8867 else if (instr(mybuf, "not empty"))
8869 else if (instr(mybuf, "cannot access"))
8875 else { /* some mkdirs return no failure indication */
8876 tmps = SvPVx(st[1], na);
8877 anum = (stat(tmps, &statbuf) >= 0);
8878 if (op->op_type == OP_RMDIR)
8883 errno = EACCES; /* a guess */
8897 char *tmps = SvPV(TOPs, na);
8899 TAINT_PROPER("mkdir");
8901 SETi( mkdir(tmps, mode) >= 0 );
8903 SETi( dooneliner("mkdir", tmps) );
8906 chmod(tmps, (mode & ~oldumask) & 0777);
8917 tmps = SvPVx(GvSV(defgv), na);
8920 TAINT_PROPER("rmdir");
8922 XPUSHi( rmdir(tmps) >= 0 );
8924 XPUSHi( dooneliner("rmdir", tmps) );
8929 /* Directory calls. */
8934 #if defined(DIRENT) && defined(HAS_READDIR)
8935 char *dirname = POPp;
8937 register IO *io = GvIOn(gv);
8943 closedir(IoDIRP(io));
8944 if (!(IoDIRP(io) = opendir(dirname)))
8953 DIE(no_dir_func, "opendir");
8960 #if defined(DIRENT) && defined(HAS_READDIR)
8962 struct DIRENT *readdir P((DIR *)); /* XXX is this *ever* needed? */
8964 register struct DIRENT *dp;
8966 register IO *io = GvIOn(gv);
8968 if (!io || !IoDIRP(io))
8971 if (GIMME == G_ARRAY) {
8973 while (dp = (struct DIRENT *)readdir(IoDIRP(io))) {
8975 XPUSHs(sv_2mortal(newSVpv(dp->d_name, dp->d_namlen)));
8977 XPUSHs(sv_2mortal(newSVpv(dp->d_name, 0)));
8982 if (!(dp = (struct DIRENT *)readdir(IoDIRP(io))))
8985 XPUSHs(sv_2mortal(newSVpv(dp->d_name, dp->d_namlen)));
8987 XPUSHs(sv_2mortal(newSVpv(dp->d_name, 0)));
8995 if (GIMME == G_ARRAY)
9000 DIE(no_dir_func, "readdir");
9007 #if defined(HAS_TELLDIR) || defined(telldir)
9012 register IO *io = GvIOn(gv);
9014 if (!io || !IoDIRP(io))
9017 PUSHi( telldir(IoDIRP(io)) );
9024 DIE(no_dir_func, "telldir");
9031 #if defined(HAS_SEEKDIR) || defined(seekdir)
9034 register IO *io = GvIOn(gv);
9036 if (!io || !IoDIRP(io))
9039 (void)seekdir(IoDIRP(io), along);
9047 DIE(no_dir_func, "seekdir");
9054 #if defined(HAS_REWINDDIR) || defined(rewinddir)
9056 register IO *io = GvIOn(gv);
9058 if (!io || !IoDIRP(io))
9061 (void)rewinddir(IoDIRP(io));
9068 DIE(no_dir_func, "rewinddir");
9075 #if defined(DIRENT) && defined(HAS_READDIR)
9077 register IO *io = GvIOn(gv);
9079 if (!io || !IoDIRP(io))
9082 if (closedir(IoDIRP(io)) < 0)
9092 DIE(no_dir_func, "closedir");
9096 /* Process control. */
9111 if (tmpgv = gv_fetchpv("$", TRUE, SVt_PV))
9112 sv_setiv(GvSV(tmpgv), (I32)getpid());
9113 hv_clear(pidstatus); /* no kids, so don't wait for 'em */
9118 DIE(no_func, "Unsupported function fork");
9131 childpid = wait(&argflags);
9133 pidgone(childpid, argflags);
9134 value = (I32)childpid;
9135 statusvalue = (U16)argflags;
9139 DIE(no_func, "Unsupported function wait");
9154 childpid = wait4pid(childpid, &argflags, optype);
9155 value = (I32)childpid;
9156 statusvalue = (U16)argflags;
9160 DIE(no_func, "Unsupported function wait");
9166 dSP; dMARK; dORIGMARK; dTARGET;
9171 VOIDRET (*ihand)(); /* place to save signal during system() */
9172 VOIDRET (*qhand)(); /* place to save signal during system() */
9175 if (SP - MARK == 1) {
9177 char *junk = SvPV(TOPs, na);
9179 TAINT_PROPER("system");
9182 while ((childpid = vfork()) == -1) {
9183 if (errno != EAGAIN) {
9192 ihand = signal(SIGINT, SIG_IGN);
9193 qhand = signal(SIGQUIT, SIG_IGN);
9194 result = wait4pid(childpid, &status, 0);
9195 (void)signal(SIGINT, ihand);
9196 (void)signal(SIGQUIT, qhand);
9197 statusvalue = (U16)status;
9201 value = (I32)((unsigned int)status & 0xffff);
9203 do_execfree(); /* free any memory child malloced on vfork */
9208 if (op->op_flags & OPf_STACKED) {
9209 SV *really = *++MARK;
9210 value = (I32)do_aexec(really, MARK, SP);
9212 else if (SP - MARK != 1)
9213 value = (I32)do_aexec(Nullsv, MARK, SP);
9215 value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
9219 if ((op[1].op_type & A_MASK) == A_GV)
9220 value = (I32)do_aspawn(st[1], arglast);
9221 else if (arglast[2] - arglast[1] != 1)
9222 value = (I32)do_aspawn(Nullsv, arglast);
9224 value = (I32)do_spawn(SvPVx(sv_mortalcopy(st[2]), na));
9233 dSP; dMARK; dORIGMARK; dTARGET;
9236 if (op->op_flags & OPf_STACKED) {
9237 SV *really = *++MARK;
9238 value = (I32)do_aexec(really, MARK, SP);
9240 else if (SP - MARK != 1)
9241 value = (I32)do_aexec(Nullsv, MARK, SP);
9244 char *junk = SvPV(*SP, na);
9246 TAINT_PROPER("exec");
9248 value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
9257 dSP; dMARK; dTARGET;
9260 value = (I32)apply(op->op_type, MARK, SP);
9265 DIE(no_func, "Unsupported function kill");
9273 XPUSHi( getppid() );
9276 DIE(no_func, "getppid");
9291 #ifdef _POSIX_SOURCE
9293 DIE("POSIX getpgrp can't take an argument");
9294 value = (I32)getpgrp();
9296 value = (I32)getpgrp(pid);
9301 DIE(no_func, "getpgrp()");
9312 TAINT_PROPER("setpgrp");
9313 SETi( setpgrp(pid, pgrp) >= 0 );
9316 DIE(no_func, "setpgrp()");
9325 #ifdef HAS_GETPRIORITY
9328 SETi( getpriority(which, who) );
9331 DIE(no_func, "getpriority()");
9341 #ifdef HAS_SETPRIORITY
9345 TAINT_PROPER("setpriority");
9346 SETi( setpriority(which, who, niceval) >= 0 );
9349 DIE(no_func, "setpriority()");
9358 XPUSHi( time(Null(Time_t*)) );
9370 #if defined(MSDOS) || !defined(HAS_TIMES)
9371 DIE("times not implemented");
9375 (void)times(×buf);
9377 PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_utime)/HZ)));
9378 if (GIMME == G_ARRAY) {
9379 PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_stime)/HZ)));
9380 PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_cutime)/HZ)));
9381 PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_cstime)/HZ)));
9389 return pp_gmtime(ARGS);
9397 static char *dayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
9398 static char *monname[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
9399 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
9404 when = (Time_t)SvIVx(POPs);
9406 if (op->op_type == OP_LOCALTIME)
9407 tmbuf = localtime(&when);
9409 tmbuf = gmtime(&when);
9412 if (GIMME != G_ARRAY) {
9417 sprintf(mybuf, "%s %s %2d %02d:%02d:%02d %d",
9418 dayname[tmbuf->tm_wday],
9419 monname[tmbuf->tm_mon],
9424 tmbuf->tm_year + 1900);
9425 PUSHp(mybuf, strlen(mybuf));
9428 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_sec)));
9429 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_min)));
9430 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_hour)));
9431 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_mday)));
9432 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_mon)));
9433 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_year)));
9434 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_wday)));
9435 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_yday)));
9436 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_isdst)));
9447 anum = SvIVx(GvSV(defgv));
9450 anum = alarm((unsigned int)anum);
9457 DIE(no_func, "Unsupported function alarm");
9470 (void)time(&lasttime);
9475 sleep((unsigned int)duration);
9478 XPUSHi(when - lasttime);
9482 /* Shared memory. */
9486 return pp_semget(ARGS);
9491 return pp_semctl(ARGS);
9496 return pp_shmwrite(ARGS);
9501 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9502 dSP; dMARK; dTARGET;
9503 I32 value = (I32)(do_shmio(op->op_type, MARK, SP) >= 0);
9512 /* Message passing. */
9516 return pp_semget(ARGS);
9521 return pp_semctl(ARGS);
9526 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9527 dSP; dMARK; dTARGET;
9528 I32 value = (I32)(do_msgsnd(MARK, SP) >= 0);
9539 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9540 dSP; dMARK; dTARGET;
9541 I32 value = (I32)(do_msgrcv(MARK, SP) >= 0);
9554 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9555 dSP; dMARK; dTARGET;
9556 int anum = do_ipcget(op->op_type, MARK, SP);
9563 DIE("System V IPC is not implemented on this machine");
9569 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9570 dSP; dMARK; dTARGET;
9571 int anum = do_ipcctl(op->op_type, MARK, SP);
9579 PUSHp("0 but true",10);
9589 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9590 dSP; dMARK; dTARGET;
9591 I32 value = (I32)(do_semop(MARK, SP) >= 0);
9603 save_lines(array, sv)
9607 register char *s = SvPVX(sv);
9608 register char *send = SvPVX(sv) + SvCUR(sv);
9610 register I32 line = 1;
9612 while (s && s < send) {
9613 SV *tmpstr = NEWSV(85,0);
9615 sv_upgrade(tmpstr, SVt_PVMG);
9616 t = strchr(s, '\n');
9622 sv_setpvn(tmpstr, s, t - s);
9623 av_store(array, line++, tmpstr);
9637 /* set up a scratch pad */
9642 SAVESPTR(comppad_name);
9643 SAVEINT(comppad_name_fill);
9644 SAVEINT(min_intro_pending);
9645 SAVEINT(max_intro_pending);
9647 comppad_name = newAV();
9648 comppad_name_fill = 0;
9649 min_intro_pending = 0;
9650 av_push(comppad, Nullsv);
9651 curpad = AvARRAY(comppad);
9654 /* make sure we compile in the right package */
9656 newstash = curcop->cop_stash;
9657 if (curstash != newstash) {
9659 curstash = newstash;
9664 /* try to compile it */
9668 curcop = &compiling;
9673 if (yyparse() || error_count || !eval_root) {
9689 if (optype == OP_REQUIRE)
9690 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
9694 rspara = (nrslen == 2);
9700 rspara = (nrslen == 2);
9701 compiling.cop_line = 0;
9702 SAVEFREESV(comppad_name);
9703 SAVEFREESV(comppad);
9704 SAVEFREEOP(eval_root);
9706 DEBUG_x(dump_eval());
9708 /* compiled okay, so do it */
9710 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
9711 RETURNOP(eval_start);
9717 register CONTEXT *cx;
9722 I32 gimme = G_SCALAR;
9731 if (SvNIOK(sv) && !SvPOKp(sv)) {
9732 if (SvNV(sv) > atof(patchlevel) + 0.000999)
9733 DIE("Perl %3.3f required--this is only version %s, stopped",
9734 SvNV(sv),patchlevel);
9737 name = SvPV(sv, na);
9738 if (op->op_type == OP_REQUIRE &&
9739 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
9743 /* prepare to compile file */
9745 tmpname = savestr(name);
9746 if (*tmpname == '/' ||
9748 (tmpname[1] == '/' ||
9749 (tmpname[1] == '.' && tmpname[2] == '/'))))
9751 tryrsfp = fopen(tmpname,"r");
9754 AV *ar = GvAVn(incgv);
9757 for (i = 0; i <= AvFILL(ar); i++) {
9758 (void)sprintf(buf, "%s/%s",
9759 SvPVx(*av_fetch(ar, i, TRUE), na), name);
9760 tryrsfp = fopen(buf, "r");
9764 if (*s == '.' && s[1] == '/')
9767 tmpname = savestr(s);
9772 compiling.cop_filegv = gv_fetchfile(tmpname);
9776 if (op->op_type == OP_REQUIRE) {
9777 sprintf(tokenbuf,"Can't locate %s in @INC", name);
9778 if (instr(tokenbuf,".h "))
9779 strcat(tokenbuf," (change .h to .ph maybe?)");
9780 if (instr(tokenbuf,".ph "))
9781 strcat(tokenbuf," (did you run h2ph?)");
9788 /* Assume success here to prevent recursive requirement. */
9789 (void)hv_store(GvHVn(incgv), name, strlen(name),
9790 newSVsv(GvSV(compiling.cop_filegv)), 0 );
9794 lex_start(sv_2mortal(newSVpv("",0)));
9796 name = savestr(name);
9799 /* switch to eval mode */
9801 push_return(op->op_next);
9802 PUSHBLOCK(cx, CXt_EVAL, SP);
9803 PUSHEVAL(cx, name, compiling.cop_filegv);
9805 compiling.cop_line = 0;
9813 return pp_require(ARGS);
9819 register CONTEXT *cx;
9828 /* switch to eval mode */
9830 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
9831 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
9832 compiling.cop_line = 1;
9833 SAVEDELETE(defstash, savestr(tmpbuf), strlen(tmpbuf));
9835 push_return(op->op_next);
9836 PUSHBLOCK(cx, CXt_EVAL, SP);
9837 PUSHEVAL(cx, 0, compiling.cop_filegv);
9839 /* prepare to compile string */
9841 if (perldb && curstash != debstash)
9842 save_lines(GvAV(compiling.cop_filegv), linestr);
9853 register CONTEXT *cx;
9856 OP *eroot = eval_root;
9860 retop = pop_return();
9862 if (gimme == G_SCALAR) {
9865 if (SvFLAGS(TOPs) & SVs_TEMP)
9868 *MARK = sv_mortalcopy(TOPs);
9877 for (mark = newsp + 1; mark <= SP; mark++)
9878 if (!(SvFLAGS(TOPs) & SVs_TEMP))
9879 *mark = sv_mortalcopy(*mark);
9880 /* in case LEAVE wipes old return values */
9883 if (optype != OP_ENTEREVAL) {
9884 char *name = cx->blk_eval.old_name;
9886 if (!(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
9887 /* Unassume the success we assumed earlier. */
9888 (void)hv_delete(GvHVn(incgv), name, strlen(name));
9890 if (optype == OP_REQUIRE)
9891 retop = die("%s did not return a true value", name);
9897 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
9906 SP = do_eval(st[1], OP_EVAL, curcop->cop_stash, TRUE,
9909 SvREFCNT_dec(cSVOP->op_sv);
9910 op[1].arg_ptr.arg_cmd = eval_root;
9911 op[1].op_type = (A_CMD|A_DONT);
9912 op[0].op_type = OP_TRY;
9923 register CONTEXT *cx;
9929 push_return(cLOGOP->op_other->op_next);
9930 PUSHBLOCK(cx, CXt_EVAL, SP);
9932 eval_root = op; /* Only needed so that goto works right. */
9935 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
9945 register CONTEXT *cx;
9952 if (gimme == G_SCALAR) {
9955 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
9958 *MARK = sv_mortalcopy(TOPs);
9967 for (mark = newsp + 1; mark <= SP; mark++)
9968 if (!(SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP)))
9969 *mark = sv_mortalcopy(*mark);
9970 /* in case LEAVE wipes old return values */
9974 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
9978 /* Get system info. */
9983 return pp_ghostent(ARGS);
9985 DIE(no_sock_func, "gethostbyname");
9992 return pp_ghostent(ARGS);
9994 DIE(no_sock_func, "gethostbyaddr");
10002 I32 which = op->op_type;
10003 register char **elem;
10005 struct hostent *gethostbyname();
10006 struct hostent *gethostbyaddr();
10007 #ifdef HAS_GETHOSTENT
10008 struct hostent *gethostent();
10010 struct hostent *hent;
10014 if (which == OP_GHBYNAME) {
10015 hent = gethostbyname(POPp);
10017 else if (which == OP_GHBYADDR) {
10018 int addrtype = POPi;
10019 SV *addrstr = POPs;
10020 char *addr = SvPV(addrstr, na);
10022 hent = gethostbyaddr(addr, SvCUR(addrstr), addrtype);
10025 #ifdef HAS_GETHOSTENT
10026 hent = gethostent();
10028 DIE("gethostent not implemented");
10031 #ifdef HOST_NOT_FOUND
10033 statusvalue = (U16)h_errno & 0xffff;
10036 if (GIMME != G_ARRAY) {
10037 PUSHs(sv = sv_newmortal());
10039 if (which == OP_GHBYNAME) {
10040 sv_setpvn(sv, hent->h_addr, hent->h_length);
10043 sv_setpv(sv, hent->h_name);
10049 PUSHs(sv = sv_mortalcopy(&sv_no));
10050 sv_setpv(sv, hent->h_name);
10051 PUSHs(sv = sv_mortalcopy(&sv_no));
10052 for (elem = hent->h_aliases; *elem; elem++) {
10053 sv_catpv(sv, *elem);
10055 sv_catpvn(sv, " ", 1);
10057 PUSHs(sv = sv_mortalcopy(&sv_no));
10058 sv_setiv(sv, (I32)hent->h_addrtype);
10059 PUSHs(sv = sv_mortalcopy(&sv_no));
10060 len = hent->h_length;
10061 sv_setiv(sv, (I32)len);
10063 for (elem = hent->h_addr_list; *elem; elem++) {
10064 XPUSHs(sv = sv_mortalcopy(&sv_no));
10065 sv_setpvn(sv, *elem, len);
10068 PUSHs(sv = sv_mortalcopy(&sv_no));
10069 sv_setpvn(sv, hent->h_addr, len);
10070 #endif /* h_addr */
10074 DIE(no_sock_func, "gethostent");
10081 return pp_gnetent(ARGS);
10083 DIE(no_sock_func, "getnetbyname");
10090 return pp_gnetent(ARGS);
10092 DIE(no_sock_func, "getnetbyaddr");
10100 I32 which = op->op_type;
10101 register char **elem;
10103 struct netent *getnetbyname();
10104 struct netent *getnetbyaddr();
10105 struct netent *getnetent();
10106 struct netent *nent;
10108 if (which == OP_GNBYNAME)
10109 nent = getnetbyname(POPp);
10110 else if (which == OP_GNBYADDR) {
10111 int addrtype = POPi;
10112 unsigned long addr = U_L(POPn);
10113 nent = getnetbyaddr((long)addr, addrtype);
10116 nent = getnetent();
10119 if (GIMME != G_ARRAY) {
10120 PUSHs(sv = sv_newmortal());
10122 if (which == OP_GNBYNAME)
10123 sv_setiv(sv, (I32)nent->n_net);
10125 sv_setpv(sv, nent->n_name);
10131 PUSHs(sv = sv_mortalcopy(&sv_no));
10132 sv_setpv(sv, nent->n_name);
10133 PUSHs(sv = sv_mortalcopy(&sv_no));
10134 for (elem = nent->n_aliases; *elem; elem++) {
10135 sv_catpv(sv, *elem);
10137 sv_catpvn(sv, " ", 1);
10139 PUSHs(sv = sv_mortalcopy(&sv_no));
10140 sv_setiv(sv, (I32)nent->n_addrtype);
10141 PUSHs(sv = sv_mortalcopy(&sv_no));
10142 sv_setiv(sv, (I32)nent->n_net);
10147 DIE(no_sock_func, "getnetent");
10154 return pp_gprotoent(ARGS);
10156 DIE(no_sock_func, "getprotobyname");
10163 return pp_gprotoent(ARGS);
10165 DIE(no_sock_func, "getprotobynumber");
10173 I32 which = op->op_type;
10174 register char **elem;
10176 struct protoent *getprotobyname();
10177 struct protoent *getprotobynumber();
10178 struct protoent *getprotoent();
10179 struct protoent *pent;
10181 if (which == OP_GPBYNAME)
10182 pent = getprotobyname(POPp);
10183 else if (which == OP_GPBYNUMBER)
10184 pent = getprotobynumber(POPi);
10186 pent = getprotoent();
10189 if (GIMME != G_ARRAY) {
10190 PUSHs(sv = sv_newmortal());
10192 if (which == OP_GPBYNAME)
10193 sv_setiv(sv, (I32)pent->p_proto);
10195 sv_setpv(sv, pent->p_name);
10201 PUSHs(sv = sv_mortalcopy(&sv_no));
10202 sv_setpv(sv, pent->p_name);
10203 PUSHs(sv = sv_mortalcopy(&sv_no));
10204 for (elem = pent->p_aliases; *elem; elem++) {
10205 sv_catpv(sv, *elem);
10207 sv_catpvn(sv, " ", 1);
10209 PUSHs(sv = sv_mortalcopy(&sv_no));
10210 sv_setiv(sv, (I32)pent->p_proto);
10215 DIE(no_sock_func, "getprotoent");
10222 return pp_gservent(ARGS);
10224 DIE(no_sock_func, "getservbyname");
10231 return pp_gservent(ARGS);
10233 DIE(no_sock_func, "getservbyport");
10241 I32 which = op->op_type;
10242 register char **elem;
10244 struct servent *getservbyname();
10245 struct servent *getservbynumber();
10246 struct servent *getservent();
10247 struct servent *sent;
10249 if (which == OP_GSBYNAME) {
10250 char *proto = POPp;
10253 if (proto && !*proto)
10256 sent = getservbyname(name, proto);
10258 else if (which == OP_GSBYPORT) {
10259 char *proto = POPp;
10262 sent = getservbyport(port, proto);
10265 sent = getservent();
10268 if (GIMME != G_ARRAY) {
10269 PUSHs(sv = sv_newmortal());
10271 if (which == OP_GSBYNAME) {
10273 sv_setiv(sv, (I32)ntohs(sent->s_port));
10275 sv_setiv(sv, (I32)(sent->s_port));
10279 sv_setpv(sv, sent->s_name);
10285 PUSHs(sv = sv_mortalcopy(&sv_no));
10286 sv_setpv(sv, sent->s_name);
10287 PUSHs(sv = sv_mortalcopy(&sv_no));
10288 for (elem = sent->s_aliases; *elem; elem++) {
10289 sv_catpv(sv, *elem);
10291 sv_catpvn(sv, " ", 1);
10293 PUSHs(sv = sv_mortalcopy(&sv_no));
10295 sv_setiv(sv, (I32)ntohs(sent->s_port));
10297 sv_setiv(sv, (I32)(sent->s_port));
10299 PUSHs(sv = sv_mortalcopy(&sv_no));
10300 sv_setpv(sv, sent->s_proto);
10305 DIE(no_sock_func, "getservent");
10316 DIE(no_sock_func, "sethostent");
10327 DIE(no_sock_func, "setnetent");
10338 DIE(no_sock_func, "setprotoent");
10349 DIE(no_sock_func, "setservent");
10361 DIE(no_sock_func, "endhostent");
10373 DIE(no_sock_func, "endnetent");
10385 DIE(no_sock_func, "endprotoent");
10397 DIE(no_sock_func, "endservent");
10404 return pp_gpwent(ARGS);
10406 DIE(no_func, "getpwnam");
10413 return pp_gpwent(ARGS);
10415 DIE(no_func, "getpwuid");
10423 I32 which = op->op_type;
10424 register AV *ary = stack;
10426 struct passwd *pwent;
10428 if (which == OP_GPWNAM)
10429 pwent = getpwnam(POPp);
10430 else if (which == OP_GPWUID)
10431 pwent = getpwuid(POPi);
10433 pwent = (struct passwd *)getpwent();
10436 if (GIMME != G_ARRAY) {
10437 PUSHs(sv = sv_newmortal());
10439 if (which == OP_GPWNAM)
10440 sv_setiv(sv, (I32)pwent->pw_uid);
10442 sv_setpv(sv, pwent->pw_name);
10448 PUSHs(sv = sv_mortalcopy(&sv_no));
10449 sv_setpv(sv, pwent->pw_name);
10450 PUSHs(sv = sv_mortalcopy(&sv_no));
10451 sv_setpv(sv, pwent->pw_passwd);
10452 PUSHs(sv = sv_mortalcopy(&sv_no));
10453 sv_setiv(sv, (I32)pwent->pw_uid);
10454 PUSHs(sv = sv_mortalcopy(&sv_no));
10455 sv_setiv(sv, (I32)pwent->pw_gid);
10456 PUSHs(sv = sv_mortalcopy(&sv_no));
10458 sv_setiv(sv, (I32)pwent->pw_change);
10461 sv_setiv(sv, (I32)pwent->pw_quota);
10464 sv_setpv(sv, pwent->pw_age);
10468 PUSHs(sv = sv_mortalcopy(&sv_no));
10470 sv_setpv(sv, pwent->pw_class);
10473 sv_setpv(sv, pwent->pw_comment);
10476 PUSHs(sv = sv_mortalcopy(&sv_no));
10477 sv_setpv(sv, pwent->pw_gecos);
10478 PUSHs(sv = sv_mortalcopy(&sv_no));
10479 sv_setpv(sv, pwent->pw_dir);
10480 PUSHs(sv = sv_mortalcopy(&sv_no));
10481 sv_setpv(sv, pwent->pw_shell);
10483 PUSHs(sv = sv_mortalcopy(&sv_no));
10484 sv_setiv(sv, (I32)pwent->pw_expire);
10489 DIE(no_func, "getpwent");
10500 DIE(no_func, "setpwent");
10511 DIE(no_func, "endpwent");
10518 return pp_ggrent(ARGS);
10520 DIE(no_func, "getgrnam");
10527 return pp_ggrent(ARGS);
10529 DIE(no_func, "getgrgid");
10537 I32 which = op->op_type;
10538 register char **elem;
10540 struct group *grent;
10542 if (which == OP_GGRNAM)
10543 grent = getgrnam(POPp);
10544 else if (which == OP_GGRGID)
10545 grent = getgrgid(POPi);
10547 grent = (struct group *)getgrent();
10550 if (GIMME != G_ARRAY) {
10551 PUSHs(sv = sv_newmortal());
10553 if (which == OP_GGRNAM)
10554 sv_setiv(sv, (I32)grent->gr_gid);
10556 sv_setpv(sv, grent->gr_name);
10562 PUSHs(sv = sv_mortalcopy(&sv_no));
10563 sv_setpv(sv, grent->gr_name);
10564 PUSHs(sv = sv_mortalcopy(&sv_no));
10565 sv_setpv(sv, grent->gr_passwd);
10566 PUSHs(sv = sv_mortalcopy(&sv_no));
10567 sv_setiv(sv, (I32)grent->gr_gid);
10568 PUSHs(sv = sv_mortalcopy(&sv_no));
10569 for (elem = grent->gr_mem; *elem; elem++) {
10570 sv_catpv(sv, *elem);
10572 sv_catpvn(sv, " ", 1);
10578 DIE(no_func, "getgrent");
10589 DIE(no_func, "setgrent");
10600 DIE(no_func, "endgrent");
10607 #ifdef HAS_GETLOGIN
10610 if (!(tmps = getlogin()))
10612 PUSHp(tmps, strlen(tmps));
10615 DIE(no_func, "getlogin");
10619 /* Miscellaneous. */
10624 dSP; dMARK; dORIGMARK; dTARGET;
10625 register I32 items = SP - MARK;
10626 unsigned long a[20];
10627 register I32 i = 0;
10631 while (++MARK <= SP) {
10632 if (SvRMAGICAL(*MARK) && mg_find(*MARK, 't'))
10636 TAINT_PROPER("syscall");
10639 /* This probably won't work on machines where sizeof(long) != sizeof(int)
10640 * or where sizeof(long) != sizeof(char*). But such machines will
10641 * not likely have syscall implemented either, so who cares?
10643 while (++MARK <= SP) {
10644 if (SvNIOK(*MARK) || !i)
10645 a[i++] = SvIV(*MARK);
10647 a[i++] = (unsigned long)SvPVX(*MARK);
10653 DIE("Too many args to syscall");
10655 DIE("Too few args to syscall");
10657 retval = syscall(a[0]);
10660 retval = syscall(a[0],a[1]);
10663 retval = syscall(a[0],a[1],a[2]);
10666 retval = syscall(a[0],a[1],a[2],a[3]);
10669 retval = syscall(a[0],a[1],a[2],a[3],a[4]);
10672 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5]);
10675 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6]);
10678 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
10682 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]);
10685 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]);
10688 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],
10692 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],
10696 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],
10697 a[10],a[11],a[12]);
10700 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],
10701 a[10],a[11],a[12],a[13]);
10703 #endif /* atarist */
10709 DIE(no_func, "syscall");