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>
29 #include <net/errno.h>
36 #include <sys/select.h>
61 static I32 dopoptosub P((I32 startingblock));
73 if (GIMME != G_ARRAY) {
88 if (++markstack_ptr == markstack_max) {
89 I32 oldmax = markstack_max - markstack;
90 I32 newmax = oldmax * 3 / 2;
92 Renew(markstack, newmax, I32);
93 markstack_ptr = markstack + oldmax;
94 markstack_max = markstack + newmax;
96 *markstack_ptr = stack_sp - stack_base;
106 cxix = dopoptosub(cxstack_ix);
110 if (cxstack[cxix].blk_gimme == G_ARRAY)
119 XPUSHs(cSVOP->op_sv);
149 DIE("panic: pp_interp");
156 if (op->op_flags & OPf_INTRO)
157 PUSHs(save_scalar(cGVOP->op_gv));
159 PUSHs(GvSV(cGVOP->op_gv));
166 XPUSHs((SV*)cGVOP->op_gv);
174 if (op->op_flags & OPf_INTRO)
175 SAVECLEARSV(curpad[op->op_targ]);
183 if (op->op_flags & OPf_INTRO)
184 SAVECLEARSV(curpad[op->op_targ]);
185 if (op->op_flags & OPf_LVAL)
195 if (op->op_flags & OPf_INTRO)
196 SAVECLEARSV(curpad[op->op_targ]);
197 if (op->op_flags & OPf_LVAL)
205 DIE("NOT IMPL LINE %d",__LINE__);
222 if (SvTYPE(sv) != SVt_PVGV)
223 DIE("Not a glob reference");
226 if (SvTYPE(sv) != SVt_PVGV) {
228 DIE(no_usym, "a glob");
229 sv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE);
232 if (op->op_flags & OPf_INTRO) {
240 if (op->op_flags & OPf_SPECIAL)
241 GvGP(sv)->gp_refcnt++; /* will soon be assigned */
247 GvSV(sv) = NEWSV(72,0);
248 GvLINE(sv) = curcop->cop_line;
270 switch (SvTYPE(sv)) {
274 DIE("Not a scalar reference");
279 if (SvTYPE(gv) != SVt_PVGV) {
281 DIE(no_usym, "a scalar");
282 gv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE);
285 if (op->op_private == OP_RV2HV &&
286 (!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV)) {
289 sv_upgrade(sv, SVt_RV);
290 SvRV(sv) = SvREFCNT_inc(newHV());
295 else if (op->op_private == OP_RV2AV &&
296 (!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV)) {
299 sv_upgrade(sv, SVt_RV);
300 SvRV(sv) = SvREFCNT_inc(newAV());
306 if (op->op_flags & OPf_INTRO)
307 SETs(save_scalar((GV*)TOPs));
317 SV *sv = AvARYLEN(av);
319 AvARYLEN(av) = sv = NEWSV(0,0);
320 sv_upgrade(sv, SVt_IV);
321 sv_magic(sv, (SV*)av, '#', Nullch, 0);
334 /* We always try to add a non-existent subroutine in case of AUTOLOAD. */
335 CV *cv = sv_2cv(TOPs, &stash, &gv, TRUE);
348 sv_upgrade(rv, SVt_RV);
349 SvRV(rv) = SvREFCNT_inc(sv);
373 pv = HvNAME(SvSTASH(sv));
375 switch (SvTYPE(sv)) {
390 case SVt_PVLV: pv = "LVALUE"; break;
391 case SVt_PVAV: pv = "ARRAY"; break;
392 case SVt_PVHV: pv = "HASH"; break;
393 case SVt_PVCV: pv = "CODE"; break;
394 case SVt_PVGV: pv = "GLOB"; break;
395 case SVt_PVFM: pv = "FORMLINE"; break;
396 default: pv = "UNKNOWN"; break;
399 PUSHp(pv, strlen(pv));
411 stash = curcop->cop_stash;
413 stash = fetch_stash(POPs, TRUE);
417 DIE("Can't bless non-reference value");
420 SvUPGRADE(ref, SVt_PVMG);
421 SvSTASH(ref) = (HV*)SvREFCNT_inc(stash);
433 fp = my_popen(tmps, "r");
435 sv_setpv(TARG, ""); /* note that this preserves previous buffer */
436 if (GIMME == G_SCALAR) {
437 while (sv_gets(TARG, fp, SvCUR(TARG)) != Nullch)
447 if (sv_gets(sv, fp, 0) == Nullch) {
451 XPUSHs(sv_2mortal(sv));
452 if (SvLEN(sv) - SvCUR(sv) > 20) {
453 SvLEN_set(sv, SvCUR(sv)+1);
454 Renew(SvPVX(sv), SvLEN(sv), char);
458 statusvalue = my_pclose(fp);
462 if (GIMME == G_SCALAR)
477 register IO *io = GvIO(last_in_gv);
478 register I32 type = op->op_type;
484 if (IoFLAGS(io) & IOf_ARGV) {
485 if (IoFLAGS(io) & IOf_START) {
486 IoFLAGS(io) &= ~IOf_START;
488 if (av_len(GvAVn(last_in_gv)) < 0) {
489 SV *tmpstr = newSVpv("-", 1); /* assume stdin */
490 (void)av_push(GvAVn(last_in_gv), tmpstr);
493 fp = nextargv(last_in_gv);
494 if (!fp) { /* Note: fp != IoIFP(io) */
495 (void)do_close(last_in_gv, FALSE); /* now it does*/
496 IoFLAGS(io) |= IOf_START;
499 else if (type == OP_GLOB) {
500 SV *tmpcmd = NEWSV(55, 0);
505 sv_setpv(tmpcmd, "perlglob ");
506 sv_catsv(tmpcmd, tmpglob);
507 sv_catpv(tmpcmd, " |");
510 sv_setpvn(tmpcmd, cshname, cshlen);
511 sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
512 sv_catsv(tmpcmd, tmpglob);
513 sv_catpv(tmpcmd, "'|");
515 sv_setpv(tmpcmd, "echo ");
516 sv_catsv(tmpcmd, tmpglob);
517 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
520 (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd));
525 else if (type == OP_GLOB)
530 warn("Read on closed filehandle <%s>", GvENAME(last_in_gv));
531 if (GIMME == G_SCALAR)
535 if (GIMME == G_ARRAY) {
536 sv = sv_2mortal(NEWSV(57, 80));
541 SvUPGRADE(sv, SVt_PV);
542 tmplen = SvLEN(sv); /* remember if already alloced */
544 Sv_Grow(sv, 80); /* try short-buffering it */
545 if (type == OP_RCATLINE)
551 if (!sv_gets(sv, fp, offset)) {
553 if (IoFLAGS(io) & IOf_ARGV) {
554 fp = nextargv(last_in_gv);
557 (void)do_close(last_in_gv, FALSE);
558 IoFLAGS(io) |= IOf_START;
560 else if (type == OP_GLOB) {
561 (void)do_close(last_in_gv, FALSE);
563 if (GIMME == G_SCALAR)
571 SvTAINT(sv); /* Anything from the outside world...*/
573 if (type == OP_GLOB) {
578 if (*SvEND(sv) == rschar)
582 for (tmps = SvPVX(sv); *tmps; tmps++)
583 if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
584 strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
586 if (*tmps && stat(SvPVX(sv), &statbuf) < 0) {
587 POPs; /* Unmatched wildcard? Chuck it... */
591 if (GIMME == G_ARRAY) {
592 if (SvLEN(sv) - SvCUR(sv) > 20) {
593 SvLEN_set(sv, SvCUR(sv)+1);
594 Renew(SvPVX(sv), SvLEN(sv), char);
596 sv = sv_2mortal(NEWSV(58, 80));
599 else if (!tmplen && SvLEN(sv) - SvCUR(sv) > 80) {
600 /* try to reclaim a bit of scalar space (only on 1st alloc) */
604 SvLEN_set(sv, SvCUR(sv)+40); /* allow some slop */
605 Renew(SvPVX(sv), SvLEN(sv), char);
618 SAVESPTR(last_in_gv); /* We don't want this to be permanent. */
619 last_in_gv = (GV*)*stack_sp--;
631 result = do_readline();
638 last_in_gv = (GV*)(*stack_sp--);
639 return do_readline();
644 last_in_gv = gv_fetchpv(SvPVx(GvSV((GV*)(*stack_sp--)), na), TRUE);
645 return do_readline();
650 last_in_gv = cGVOP->op_gv;
651 return do_readline();
661 register PMOP *pm = (PMOP*)cLOGOP->op_other;
665 register REGEXP *rx = pm->op_pmregexp;
668 global = pm->op_pmflags & PMf_GLOBAL;
670 t = SvPV(tmpstr, len);
673 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
674 pm->op_pmregexp = regcomp(t, t + len,
675 pm->op_pmflags & PMf_FOLD);
676 if (!pm->op_pmregexp->prelen && curpm)
678 if (pm->op_pmflags & PMf_KEEP) {
679 if (!(pm->op_pmflags & PMf_FOLD))
680 scan_prefix(pm, pm->op_pmregexp->precomp,
681 pm->op_pmregexp->prelen);
682 pm->op_pmflags &= ~PMf_RUNTIME; /* no point compiling again */
684 cLOGOP->op_first->op_next = op->op_next;
685 /* XXX delete push code */
693 register PMOP *pm = cPMOP;
701 register REGEXP *rx = pm->op_pmregexp;
705 if (op->op_flags & OPf_STACKED)
714 DIE("panic: do_match");
716 if (pm->op_pmflags & PMf_USED) {
717 if (gimme == G_ARRAY)
722 if (!rx->prelen && curpm) {
724 rx = pm->op_pmregexp;
727 if (global = pm->op_pmflags & PMf_GLOBAL) {
729 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
730 MAGIC* mg = mg_find(TARG, 'g');
731 if (mg && mg->mg_ptr) {
732 rx->startp[0] = mg->mg_ptr;
733 rx->endp[0] = mg->mg_ptr + mg->mg_len;
737 safebase = (gimme == G_ARRAY) || global;
740 if (global && rx->startp[0]) {
742 if (s == rx->startp[0])
747 if (pm->op_pmshort) {
748 if (pm->op_pmflags & PMf_SCANFIRST) {
749 if (SvSCREAM(TARG)) {
750 if (screamfirst[BmRARE(pm->op_pmshort)] < 0)
752 else if (!(s = screaminstr(TARG, pm->op_pmshort)))
754 else if (pm->op_pmflags & PMf_ALL)
757 else if (!(s = fbm_instr((unsigned char*)s,
758 (unsigned char*)strend, pm->op_pmshort)))
760 else if (pm->op_pmflags & PMf_ALL)
762 if (s && rx->regback >= 0) {
763 ++BmUSEFUL(pm->op_pmshort);
771 else if (!multiline) {
772 if (*SvPVX(pm->op_pmshort) != *s ||
773 bcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) ) {
774 if (pm->op_pmflags & PMf_FOLD) {
775 if (ibcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) )
782 if (--BmUSEFUL(pm->op_pmshort) < 0) {
783 SvREFCNT_dec(pm->op_pmshort);
784 pm->op_pmshort = Nullsv; /* opt is being useless */
787 if (!rx->nparens && !global) {
788 gimme = G_SCALAR; /* accidental array context? */
791 if (regexec(rx, s, strend, truebase, 0,
792 SvSCREAM(TARG) ? TARG : Nullsv,
795 if (pm->op_pmflags & PMf_ONCE)
796 pm->op_pmflags |= PMf_USED;
804 if (gimme == G_ARRAY) {
808 if (global && !iters)
812 EXTEND(SP, iters + i);
813 for (i = !i; i <= iters; i++) {
814 PUSHs(sv_newmortal());
816 if (s = rx->startp[i]) {
817 len = rx->endp[i] - s;
819 sv_setpvn(*SP, s, len);
823 truebase = rx->subbeg;
831 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
832 mg = mg_find(TARG, 'g');
834 sv_magic(TARG, (SV*)0, 'g', Nullch, 0);
835 mg = mg_find(TARG, 'g');
837 mg->mg_ptr = rx->startp[0];
838 mg->mg_len = rx->endp[0] - rx->startp[0];
844 ++BmUSEFUL(pm->op_pmshort);
846 if (pm->op_pmflags & PMf_ONCE)
847 pm->op_pmflags |= PMf_USED;
849 rx->subbeg = truebase;
852 rx->endp[0] = s + SvCUR(pm->op_pmshort);
859 Safefree(rx->subbase);
860 tmps = rx->subbase = nsavestr(t, strend-t);
862 rx->subend = tmps + (strend-t);
863 tmps = rx->startp[0] = tmps + (s - t);
864 rx->endp[0] = tmps + SvCUR(pm->op_pmshort);
870 ++BmUSEFUL(pm->op_pmshort);
874 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
875 MAGIC* mg = mg_find(TARG, 'g');
882 if (gimme == G_ARRAY)
890 register PMOP *pm = cPMOP;
905 register REGEXP *rx = pm->op_pmregexp;
908 if (pm->op_pmflags & PMf_CONST) /* known replacement string? */
910 if (op->op_flags & OPf_STACKED)
918 DIE("panic: do_subst");
921 maxiters = (strend - s) + 10;
923 if (!rx->prelen && curpm) {
925 rx = pm->op_pmregexp;
927 safebase = ((!rx || !rx->nparens) && !sawampersand);
929 if (pm->op_pmshort) {
930 if (pm->op_pmflags & PMf_SCANFIRST) {
931 if (SvSCREAM(TARG)) {
932 if (screamfirst[BmRARE(pm->op_pmshort)] < 0)
934 else if (!(s = screaminstr(TARG, pm->op_pmshort)))
937 else if (!(s = fbm_instr((unsigned char*)s, (unsigned char*)strend,
940 if (s && rx->regback >= 0) {
941 ++BmUSEFUL(pm->op_pmshort);
949 else if (!multiline) {
950 if (*SvPVX(pm->op_pmshort) != *s ||
951 bcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) ) {
952 if (pm->op_pmflags & PMf_FOLD) {
953 if (ibcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) )
960 if (--BmUSEFUL(pm->op_pmshort) < 0) {
961 SvREFCNT_dec(pm->op_pmshort);
962 pm->op_pmshort = Nullsv; /* opt is being useless */
965 once = !(rpm->op_pmflags & PMf_GLOBAL);
966 if (rpm->op_pmflags & PMf_CONST) { /* known replacement string? */
967 c = SvPV(dstr, clen);
968 if (clen <= rx->minlen) {
969 /* can do inplace substitution */
970 if (regexec(rx, s, strend, orig, 0,
971 SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
972 if (rx->subbase) /* oops, no we can't */
976 SvSCREAM_off(TARG); /* disable possible screamer */
981 if (m - s > strend - d) { /* faster to shorten from end */
983 Copy(c, m, clen, char);
992 SvCUR_set(TARG, m - s);
999 else if (i = m - s) { /* faster from front */
1007 Copy(c, m, clen, char);
1016 Copy(c, d, clen, char);
1032 if (iters++ > maxiters)
1033 DIE("Substitution loop");
1038 Move(s, d, i, char);
1042 Copy(c, d, clen, char);
1046 } while (regexec(rx, s, strend, orig, s == m,
1047 Nullsv, TRUE)); /* (don't match same null twice) */
1050 SvCUR_set(TARG, d - SvPVX(TARG) + i);
1051 Move(s, d, i+1, char); /* include the Null */
1055 PUSHs(sv_2mortal(newSViv((I32)iters)));
1064 if (regexec(rx, s, strend, orig, 0,
1065 SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
1067 dstr = NEWSV(25, sv_len(TARG));
1068 sv_setpvn(dstr, m, s-m);
1071 register CONTEXT *cx;
1073 RETURNOP(cPMOP->op_pmreplroot);
1076 if (iters++ > maxiters)
1077 DIE("Substitution loop");
1078 if (rx->subbase && rx->subbase != orig) {
1083 strend = s + (strend - m);
1086 sv_catpvn(dstr, s, m-s);
1089 sv_catpvn(dstr, c, clen);
1092 } while (regexec(rx, s, strend, orig, s == m, Nullsv,
1094 sv_catpvn(dstr, s, strend - s);
1095 sv_replace(TARG, dstr);
1098 PUSHs(sv_2mortal(newSViv((I32)iters)));
1105 ++BmUSEFUL(pm->op_pmshort);
1113 register PMOP *pm = (PMOP*) cLOGOP->op_other;
1114 register CONTEXT *cx = &cxstack[cxstack_ix];
1115 register SV *dstr = cx->sb_dstr;
1116 register char *s = cx->sb_s;
1117 register char *m = cx->sb_m;
1118 char *orig = cx->sb_orig;
1119 register REGEXP *rx = pm->op_pmregexp;
1121 if (cx->sb_iters++) {
1122 if (cx->sb_iters > cx->sb_maxiters)
1123 DIE("Substitution loop");
1125 sv_catsv(dstr, POPs);
1127 Safefree(rx->subbase);
1128 rx->subbase = cx->sb_subbase;
1131 if (cx->sb_once || !regexec(rx, s, cx->sb_strend, orig,
1132 s == m, Nullsv, cx->sb_safebase))
1134 SV *targ = cx->sb_targ;
1135 sv_catpvn(dstr, s, cx->sb_strend - s);
1136 sv_replace(targ, dstr);
1139 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
1141 RETURNOP(pm->op_next);
1144 if (rx->subbase && rx->subbase != orig) {
1147 cx->sb_orig = orig = rx->subbase;
1149 cx->sb_strend = s + (cx->sb_strend - m);
1151 cx->sb_m = m = rx->startp[0];
1152 sv_catpvn(dstr, s, m-s);
1153 cx->sb_s = rx->endp[0];
1154 cx->sb_subbase = rx->subbase;
1156 rx->subbase = Nullch; /* so recursion works */
1157 RETURNOP(pm->op_pmreplstart);
1165 if (op->op_flags & OPf_STACKED)
1172 PUSHi(do_trans(sv, op));
1176 /* Lvalue operators. */
1181 if (tainting && tainted && (!SvRMAGICAL(lstr) || !mg_find(lstr, 't'))) {
1184 SvSetSV(rstr, lstr);
1193 SV **lastlelem = stack_sp;
1194 SV **lastrelem = stack_base + POPMARK;
1195 SV **firstrelem = stack_base + POPMARK + 1;
1196 SV **firstlelem = lastrelem + 1;
1198 register SV **relem;
1199 register SV **lelem;
1208 delaymagic = DM_DELAY; /* catch simultaneous items */
1210 /* If there's a common identifier on both sides we have to take
1211 * special care that assigning the identifier on the left doesn't
1212 * clobber a value on the right that's used later in the list.
1214 if (op->op_private & OPpASSIGN_COMMON) {
1215 for (relem = firstrelem; relem <= lastrelem; relem++) {
1218 *relem = sv_mortalcopy(sv);
1226 while (lelem <= lastlelem) {
1228 switch (SvTYPE(sv)) {
1231 magic = SvSMAGICAL(ary) != 0;
1235 while (relem <= lastrelem) { /* gobble up all the rest */
1238 sv_setsv(sv,*relem);
1240 (void)av_store(ary,i++,sv);
1250 magic = SvSMAGICAL(hash) != 0;
1253 while (relem < lastrelem) { /* gobble up all the rest */
1258 sv = &sv_no, relem++;
1259 tmps = SvPV(sv, len);
1260 tmpstr = NEWSV(29,0);
1262 sv_setsv(tmpstr,*relem); /* value */
1263 *(relem++) = tmpstr;
1264 (void)hv_store(hash,tmps,len,tmpstr,0);
1271 if (SvTHINKFIRST(sv)) {
1272 if (SvREADONLY(sv) && curcop != &compiling) {
1273 if (sv != &sv_undef && sv != &sv_yes && sv != &sv_no)
1275 if (relem <= lastrelem)
1282 if (relem <= lastrelem) {
1283 sv_setsv(sv, *relem);
1287 sv_setsv(sv, &sv_undef);
1292 if (delaymagic & ~DM_DELAY) {
1293 if (delaymagic & DM_UID) {
1295 (void)setreuid(uid,euid);
1296 #else /* not HAS_SETREUID */
1298 if ((delaymagic & DM_UID) == DM_RUID) {
1300 delaymagic =~ DM_RUID;
1302 #endif /* HAS_SETRUID */
1304 if ((delaymagic & DM_UID) == DM_EUID) {
1306 delaymagic =~ DM_EUID;
1308 #endif /* HAS_SETEUID */
1309 if (delaymagic & DM_UID) {
1311 DIE("No setreuid available");
1314 #endif /* not HAS_SETREUID */
1315 uid = (int)getuid();
1316 euid = (int)geteuid();
1318 if (delaymagic & DM_GID) {
1320 (void)setregid(gid,egid);
1321 #else /* not HAS_SETREGID */
1323 if ((delaymagic & DM_GID) == DM_RGID) {
1325 delaymagic =~ DM_RGID;
1327 #endif /* HAS_SETRGID */
1329 if ((delaymagic & DM_GID) == DM_EGID) {
1331 delaymagic =~ DM_EGID;
1333 #endif /* HAS_SETEGID */
1334 if (delaymagic & DM_GID) {
1336 DIE("No setregid available");
1339 #endif /* not HAS_SETREGID */
1340 gid = (int)getgid();
1341 egid = (int)getegid();
1343 tainting |= (euid != uid || egid != gid);
1346 if (GIMME == G_ARRAY) {
1350 SP = firstrelem + (lastlelem - firstlelem);
1356 SETi(lastrelem - firstrelem + 1);
1377 dSP; dMARK; dTARGET;
1379 do_chop(TARG, POPs);
1395 if (!sv || !SvANY(sv))
1397 switch (SvTYPE(sv)) {
1422 if (!op->op_private)
1429 if (SvTHINKFIRST(sv)) {
1436 switch (SvTYPE(sv)) {
1450 if (sv != GvSV(defgv)) {
1451 if (SvPOK(sv) && SvLEN(sv)) {
1453 Safefree(SvPVX(sv));
1454 SvPV_set(sv, Nullch);
1468 register unsigned char *s;
1471 register I32 *sfirst;
1472 register I32 *snext;
1476 s = (unsigned char*)(SvPV(TARG, len));
1479 SvSCREAM_off(lastscream);
1485 if (pos > maxscream) {
1486 if (maxscream < 0) {
1487 maxscream = pos + 80;
1488 New(301, screamfirst, 256, I32);
1489 New(302, screamnext, maxscream, I32);
1492 maxscream = pos + pos / 4;
1493 Renew(screamnext, maxscream, I32);
1497 sfirst = screamfirst;
1500 if (!sfirst || !snext)
1501 DIE("do_study: out of memory");
1503 for (ch = 256; ch; --ch)
1507 while (--pos >= 0) {
1509 if (sfirst[ch] >= 0)
1510 snext[pos] = sfirst[ch] - pos;
1515 /* If there were any case insensitive searches, we must assume they
1516 * all are. This speeds up insensitive searches much more than
1517 * it slows down sensitive ones.
1520 sfirst[fold[ch]] = pos;
1526 XPUSHs(sv_2mortal(newSViv((I32)retval)));
1549 sv_setsv(TARG, TOPs);
1561 sv_setsv(TARG, TOPs);
1568 /* Ordinary operators. */
1572 dSP; dATARGET; dPOPTOPnnrl;
1573 SETn( pow( left, right) );
1579 dSP; dATARGET; dPOPTOPnnrl;
1580 SETn( left * right );
1586 dSP; dATARGET; dPOPnv;
1588 DIE("Illegal division by zero");
1590 /* insure that 20./5. == 4. */
1595 if ((double)(I32)x == x &&
1596 (double)(I32)value == value &&
1597 (k = (I32)x/(I32)value)*(I32)value == (I32)x) {
1604 value = POPn / value;
1613 register unsigned long tmpulong;
1614 register long tmplong;
1617 tmpulong = (unsigned long) POPn;
1619 DIE("Illegal modulus zero");
1622 value = (I32)(((unsigned long)value) % tmpulong);
1624 tmplong = (long)value;
1625 value = (I32)(tmpulong - ((-tmplong - 1) % tmpulong)) - 1;
1634 register I32 count = POPi;
1635 if (GIMME == G_ARRAY && op->op_private & OPpREPEAT_DOLIST) {
1637 I32 items = SP - MARK;
1640 max = items * count;
1649 repeatcpy((char*)(MARK + items), (char*)MARK,
1650 items * sizeof(SV*), count - 1);
1654 else { /* Note: mark already snarfed by pp_list */
1659 if (TARG == tmpstr && SvTHINKFIRST(tmpstr)) {
1660 if (SvREADONLY(tmpstr) && curcop != &compiling)
1661 DIE("Can't x= to readonly value");
1665 SvSetSV(TARG, tmpstr);
1669 tmpstr = NEWSV(50, 0);
1670 tmps = SvPV(TARG, len);
1671 sv_setpvn(tmpstr, tmps, len);
1672 tmps = SvPV(tmpstr, tlen); /* force to be string */
1673 SvGROW(TARG, (count * len) + 1);
1674 repeatcpy((char*)SvPVX(TARG), tmps, tlen, count);
1675 SvCUR(TARG) *= count;
1676 *SvEND(TARG) = '\0';
1678 SvREFCNT_dec(tmpstr);
1681 sv_setsv(TARG, &sv_no);
1689 dSP; dATARGET; dPOPTOPnnrl;
1690 SETn( left + right );
1696 dSP; dATARGET; dPOPTOPiirl;
1697 SETi( left + right );
1703 dSP; dATARGET; dPOPTOPnnrl;
1704 SETn( left - right );
1710 dSP; dATARGET; dPOPTOPssrl;
1711 SvSetSV(TARG, lstr);
1712 sv_catsv(TARG, rstr);
1721 double value = TOPn;
1722 SETi( U_L(value) << anum );
1730 double value = TOPn;
1731 SETi( U_L(value) >> anum );
1738 SETs((TOPn < value) ? &sv_yes : &sv_no);
1745 SETs((TOPn > value) ? &sv_yes : &sv_no);
1752 SETs((TOPn <= value) ? &sv_yes : &sv_no);
1759 SETs((TOPn >= value) ? &sv_yes : &sv_no);
1766 SETs((TOPn == value) ? &sv_yes : &sv_no);
1773 SETs((TOPn != value) ? &sv_yes : &sv_no);
1779 dSP; dTARGET; dPOPTOPnnrl;
1784 else if (left < right)
1795 SETs( sv_cmp(lstr, rstr) < 0 ? &sv_yes : &sv_no );
1802 SETs( sv_cmp(lstr, rstr) > 0 ? &sv_yes : &sv_no );
1809 SETs( sv_cmp(lstr, rstr) <= 0 ? &sv_yes : &sv_no );
1816 SETs( sv_cmp(lstr, rstr) >= 0 ? &sv_yes : &sv_no );
1823 SETs( sv_eq(lstr, rstr) ? &sv_yes : &sv_no );
1830 SETs( !sv_eq(lstr, rstr) ? &sv_yes : &sv_no );
1838 SETi( sv_cmp(lstr, rstr) );
1844 dSP; dATARGET; dPOPTOPssrl;
1845 if (SvNIOK(lstr) || SvNIOK(rstr)) {
1846 I32 value = SvIV(lstr);
1847 value = value & SvIV(rstr);
1851 do_vop(op->op_type, TARG, lstr, rstr);
1859 dSP; dATARGET; dPOPTOPssrl;
1860 if (SvNIOK(lstr) || SvNIOK(rstr)) {
1861 I32 value = SvIV(lstr);
1862 value = value ^ SvIV(rstr);
1866 do_vop(op->op_type, TARG, lstr, rstr);
1874 dSP; dATARGET; dPOPTOPssrl;
1875 if (SvNIOK(lstr) || SvNIOK(rstr)) {
1876 I32 value = SvIV(lstr);
1877 value = value | SvIV(rstr);
1881 do_vop(op->op_type, TARG, lstr, rstr);
1896 *stack_sp = SvTRUE(*stack_sp) ? &sv_no : &sv_yes;
1902 dSP; dTARGET; dTOPss;
1909 register char *tmps;
1910 register long *tmpl;
1914 tmps = SvPV(TARG, len);
1917 for ( ; anum && (unsigned long)tmps % sizeof(long); anum--, tmps++)
1920 for ( ; anum >= sizeof(long); anum -= sizeof(long), tmpl++)
1924 for ( ; anum > 0; anum--, tmps++)
1932 /* High falutin' math. */
1936 dSP; dTARGET; dPOPTOPnnrl;
1937 SETn(atan2(left, right));
1946 value = SvNVx(GvSV(defgv));
1959 value = SvNVx(GvSV(defgv));
1978 value = rand() * value / 2147483648.0;
1981 value = rand() * value / 65536.0;
1984 value = rand() * value / 32768.0;
1986 value = rand() * value / (double)(((unsigned long)1) << RANDBITS);
2016 value = SvNVx(GvSV(defgv));
2029 value = SvNVx(GvSV(defgv));
2033 DIE("Can't take log of %g", value);
2044 value = SvNVx(GvSV(defgv));
2048 DIE("Can't take sqrt of %g", value);
2049 value = sqrt(value);
2059 value = SvNVx(GvSV(defgv));
2063 (void)modf(value, &value);
2065 (void)modf(-value, &value);
2077 value = SvNVx(GvSV(defgv));
2095 tmps = SvPVx(GvSV(defgv), na);
2098 XPUSHi( scan_hex(tmps, 99, &argtype) );
2110 tmps = SvPVx(GvSV(defgv), na);
2113 while (*tmps && (isSPACE(*tmps) || *tmps == '0'))
2116 value = (I32)scan_hex(++tmps, 99, &argtype);
2118 value = (I32)scan_oct(tmps, 99, &argtype);
2129 XPUSHi( sv_len(GvSV(defgv)) );
2132 SETi( sv_len(TOPs) );
2144 I32 lvalue = op->op_flags & OPf_LVAL;
2149 pos = POPi - arybase;
2151 tmps = SvPV(sv, curlen); /* force conversion to string */
2153 pos += curlen + arybase;
2154 if (pos < 0 || pos > curlen) {
2156 warn("substr outside of string");
2165 rem = curlen - pos; /* rem=how many bytes left*/
2168 sv_setpvn(TARG, tmps, rem);
2169 if (lvalue) { /* it's an lvalue! */
2170 if (SvTHINKFIRST(sv)) {
2171 if (SvREADONLY(sv) && curcop != &compiling)
2178 LvTARGOFF(TARG) = tmps - SvPV(sv, na);
2179 LvTARGLEN(TARG) = rem;
2182 PUSHs(TARG); /* avoid SvSETMAGIC here */
2189 register I32 size = POPi;
2190 register I32 offset = POPi;
2191 register SV *src = POPs;
2192 I32 lvalue = op->op_flags & OPf_LVAL;
2194 unsigned char *s = (unsigned char*)SvPV(src, srclen);
2195 unsigned long retnum;
2198 offset *= size; /* turn into bit offset */
2199 len = (offset + size + 7) / 8;
2200 if (offset < 0 || size < 1)
2202 else if (!lvalue && len > srclen)
2207 (void)memzero(SvPVX(src) + srclen, len - srclen);
2208 SvCUR_set(src, len);
2210 s = (unsigned char*)SvPV(src, na);
2212 retnum = (s[offset >> 3] >> (offset & 7)) & ((1 << size) - 1);
2217 else if (size == 16)
2218 retnum = ((unsigned long) s[offset] << 8) + s[offset+1];
2219 else if (size == 32)
2220 retnum = ((unsigned long) s[offset] << 24) +
2221 ((unsigned long) s[offset + 1] << 16) +
2222 (s[offset + 2] << 8) + s[offset+3];
2225 if (lvalue) { /* it's an lvalue! */
2226 if (SvTHINKFIRST(src)) {
2227 if (SvREADONLY(src) && curcop != &compiling)
2234 LvTARGOFF(TARG) = offset;
2235 LvTARGLEN(TARG) = size;
2239 sv_setiv(TARG, (I32)retnum);
2258 offset = POPi - arybase;
2261 tmps = SvPV(big, biglen);
2264 else if (offset > biglen)
2266 if (!(tmps2 = fbm_instr((unsigned char*)tmps + offset,
2267 (unsigned char*)tmps + biglen, little)))
2268 retval = -1 + arybase;
2270 retval = tmps2 - tmps + arybase;
2292 tmps2 = SvPV(little, llen);
2293 tmps = SvPV(big, blen);
2297 offset = SvIV(offstr) - arybase + llen;
2300 else if (offset > blen)
2302 if (!(tmps2 = rninstr(tmps, tmps + offset,
2303 tmps2, tmps2 + llen)))
2304 retval = -1 + arybase;
2306 retval = tmps2 - tmps + arybase;
2313 dSP; dMARK; dORIGMARK; dTARGET;
2314 do_sprintf(TARG, SP-MARK, MARK+1);
2325 register char *s = SvPV(sv, len);
2326 register char *send = s + len;
2327 register char *base;
2328 register I32 skipspaces = 0;
2331 bool postspace = FALSE;
2338 New(804, fops, send - s, U16); /* Almost certainly too long... */
2343 *fpc++ = FF_LINEMARK;
2344 noblank = repeat = FALSE;
2362 case ' ': case '\t':
2375 *fpc++ = FF_LITERAL;
2382 *fpc++ = skipspaces;
2386 *fpc++ = FF_NEWLINE;
2390 arg = fpc - linepc + 1;
2397 *fpc++ = FF_LINEMARK;
2398 noblank = repeat = FALSE;
2407 ischop = s[-1] == '^';
2413 arg = (s - base) - 1;
2415 *fpc++ = FF_LITERAL;
2424 *fpc++ = FF_LINEGLOB;
2426 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2427 arg = ischop ? 512 : 0;
2437 arg |= 256 + (s - f);
2439 *fpc++ = s - base; /* fieldsize for FETCH */
2440 *fpc++ = FF_DECIMAL;
2445 bool ismore = FALSE;
2448 while (*++s == '>') ;
2449 prespace = FF_SPACE;
2451 else if (*s == '|') {
2452 while (*++s == '|') ;
2453 prespace = FF_HALFSPACE;
2458 while (*++s == '<') ;
2461 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2465 *fpc++ = s - base; /* fieldsize for FETCH */
2467 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2485 SvGROW(sv, SvCUR(sv) + arg * sizeof(U16) + 4);
2487 s = SvPVX(sv) + SvCUR(sv);
2488 s += 2 + (SvCUR(sv) & 1);
2490 Copy(fops, s, arg, U16);
2496 dSP; dMARK; dORIGMARK;
2497 register SV *form = *++MARK;
2502 register char *send;
2508 bool chopspace = (strchr(chopset, ' ') != Nullch);
2517 if (!SvCOMPILED(form)) {
2518 SvREADONLY_off(form);
2522 SvUPGRADE(formtarget, SVt_PV);
2523 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
2524 t = SvPV(formtarget, len);
2526 f = SvPV(form, len);
2538 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
2539 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
2540 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
2541 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
2542 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
2544 case FF_CHECKNL: name = "CHECKNL"; break;
2545 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
2546 case FF_SPACE: name = "SPACE"; break;
2547 case FF_HALFSPACE: name = "HALFSPACE"; break;
2548 case FF_ITEM: name = "ITEM"; break;
2549 case FF_CHOP: name = "CHOP"; break;
2550 case FF_LINEGLOB: name = "LINEGLOB"; break;
2551 case FF_NEWLINE: name = "NEWLINE"; break;
2552 case FF_MORE: name = "MORE"; break;
2553 case FF_LINEMARK: name = "LINEMARK"; break;
2554 case FF_END: name = "END"; break;
2557 fprintf(stderr, "%-16s%d\n", name, arg);
2559 fprintf(stderr, "%-16s\n", name);
2590 warn("Not enough format arguments");
2597 if (itemsize > fieldsize)
2598 itemsize = fieldsize;
2599 send = chophere = s + itemsize;
2603 else if (*s == '\n')
2607 itemsize = s - SvPVX(sv);
2613 if (itemsize <= fieldsize) {
2614 send = chophere = s + itemsize;
2617 itemsize = s - SvPVX(sv);
2625 itemsize = fieldsize;
2626 send = chophere = s + itemsize;
2627 while (s < send || (s == send && isSPACE(*s))) {
2637 if (strchr(chopset, *s))
2642 itemsize = chophere - SvPVX(sv);
2647 arg = fieldsize - itemsize;
2656 arg = fieldsize - itemsize;
2669 if ((*t++ = *s++) < ' ')
2677 while (*s && isSPACE(*s))
2688 send = s + itemsize;
2697 SvCUR_set(formtarget, t - SvPVX(formtarget));
2698 sv_catpvn(formtarget, SvPVX(sv), itemsize);
2699 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
2700 t = SvPVX(formtarget) + SvCUR(formtarget);
2705 /* If the field is marked with ^ and the value is undefined,
2708 if ((arg & 512) && !SvOK(sv)) {
2717 sprintf(t, "%#*.*f", fieldsize, arg & 255, value);
2719 sprintf(t, "%*.0f", fieldsize, value);
2726 while (t-- > linemark && *t == ' ') ;
2734 if (arg) { /* repeat until fields exhausted? */
2740 if (strnEQ(linemark, linemark - arg, arg))
2741 DIE("Runaway format");
2743 arg = t - SvPVX(formtarget);
2745 (t - SvPVX(formtarget)) + (f - formmark) + 1);
2746 t = SvPVX(formtarget) + arg;
2757 arg = fieldsize - itemsize;
2764 if (strnEQ(s," ",3)) {
2765 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
2776 SvCUR_set(formtarget, t - SvPVX(formtarget));
2777 FmLINES(formtarget) += lines;
2792 tmps = SvPVx(GvSV(defgv), na);
2796 value = (I32) (*tmps & 255);
2799 value = (I32) (anum & 255);
2810 if (SvTYPE(TARG) == SVt_NULL) {
2811 sv_upgrade(TARG,SVt_PV);
2817 *tmps = SvIVx(GvSV(defgv));
2827 dSP; dTARGET; dPOPTOPssrl;
2829 char *tmps = SvPV(lstr, na);
2831 sv_setpv(TARG, fcrypt(tmps, SvPV(rstr, na)));
2833 sv_setpv(TARG, crypt(tmps, SvPV(rstr, na)));
2837 "The crypt() function is unimplemented due to excessive paranoia.");
2849 if (!SvPADTMP(sv)) {
2856 if (isascii(*s) && islower(*s))
2868 if (!SvPADTMP(sv)) {
2875 if (isascii(*s) && isupper(*s))
2887 register char *send;
2890 if (!SvPADTMP(sv)) {
2899 if (isascii(*s) && islower(*s))
2911 register char *send;
2914 if (!SvPADTMP(sv)) {
2923 if (isascii(*s) && isupper(*s))
2940 if (SvTYPE(av) != SVt_PVAV)
2941 DIE("Not an array reference");
2942 if (op->op_flags & OPf_LVAL) {
2943 if (op->op_flags & OPf_INTRO)
2944 av = (AV*)save_svref((SV**)sv);
2950 if (SvTYPE(sv) == SVt_PVAV) {
2952 if (op->op_flags & OPf_LVAL) {
2958 if (SvTYPE(sv) != SVt_PVGV) {
2960 DIE(no_usym, "an array");
2961 sv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE);
2964 if (op->op_flags & OPf_LVAL) {
2965 if (op->op_flags & OPf_INTRO)
2973 if (GIMME == G_ARRAY) {
2974 I32 maxarg = AvFILL(av) + 1;
2976 Copy(AvARRAY(av), SP+1, maxarg, SV*);
2981 I32 maxarg = AvFILL(av) + 1;
2990 AV *av = GvAV((GV*)cSVOP->op_sv);
2991 SV** svp = av_fetch(av, op->op_private - arybase, op->op_flags & OPf_LVAL);
2992 PUSHs(svp ? *svp : &sv_undef);
3000 I32 elem = POPi - arybase;
3003 if (op->op_flags & OPf_LVAL) {
3004 svp = av_fetch(av, elem, TRUE);
3005 if (!svp || *svp == &sv_undef)
3006 DIE(no_aelem, elem);
3007 if (op->op_flags & OPf_INTRO)
3009 else if (!SvOK(*svp)) {
3010 if (op->op_private == OP_RV2HV) {
3013 sv_upgrade(*svp, SVt_RV);
3014 SvRV(*svp) = SvREFCNT_inc(newHV());
3018 else if (op->op_private == OP_RV2AV) {
3021 sv_upgrade(*svp, SVt_RV);
3022 SvRV(*svp) = SvREFCNT_inc(newAV());
3029 svp = av_fetch(av, elem, FALSE);
3030 PUSHs(svp ? *svp : &sv_undef);
3036 dSP; dMARK; dORIGMARK;
3038 register AV* av = (AV*)POPs;
3039 register I32 lval = op->op_flags & OPf_LVAL;
3040 I32 is_something_there = lval;
3042 while (++MARK <= SP) {
3043 I32 elem = SvIVx(*MARK);
3046 svp = av_fetch(av, elem, TRUE);
3047 if (!svp || *svp == &sv_undef)
3048 DIE(no_aelem, elem);
3049 if (op->op_flags & OPf_INTRO)
3053 svp = av_fetch(av, elem, FALSE);
3054 if (!is_something_there && svp && SvOK(*svp))
3055 is_something_there = TRUE;
3057 *MARK = svp ? *svp : &sv_undef;
3059 if (!is_something_there)
3064 /* Associative arrays. */
3069 HV *hash = (HV*)POPs;
3070 HE *entry = hv_iternext(hash);
3076 tmps = hv_iterkey(entry, &i);
3079 PUSHs(sv_2mortal(newSVpv(tmps, i)));
3080 if (GIMME == G_ARRAY) {
3081 sv_setsv(TARG, hv_iterval(hash, entry));
3085 else if (GIMME == G_SCALAR)
3110 DIE("Not an associative array reference");
3112 tmps = SvPV(tmpsv, len);
3113 sv = hv_delete(hv, tmps, len);
3127 if (SvTYPE(sv) == SVt_RV) {
3129 if (SvTYPE(hv) != SVt_PVHV)
3130 DIE("Not an associative array reference");
3131 if (op->op_flags & OPf_LVAL) {
3132 if (op->op_flags & OPf_INTRO)
3133 hv = (HV*)save_svref((SV**)sv);
3139 if (SvTYPE(sv) == SVt_PVHV) {
3141 if (op->op_flags & OPf_LVAL) {
3147 if (SvTYPE(sv) != SVt_PVGV) {
3149 DIE(no_usym, "a hash");
3150 sv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE);
3153 if (op->op_flags & OPf_LVAL) {
3154 if (op->op_flags & OPf_INTRO)
3162 if (GIMME == G_ARRAY) { /* array wanted */
3163 *stack_sp = (SV*)hv;
3169 sprintf(buf, "%d/%d", HvFILL(hv), HvMAX(hv)+1);
3170 sv_setpv(TARG, buf);
3185 char *key = SvPV(keysv, keylen);
3188 if (op->op_flags & OPf_LVAL) {
3189 svp = hv_fetch(hv, key, keylen, TRUE);
3190 if (!svp || *svp == &sv_undef)
3192 if (op->op_flags & OPf_INTRO)
3194 else if (!SvOK(*svp)) {
3195 if (op->op_private == OP_RV2HV) {
3198 sv_upgrade(*svp, SVt_RV);
3199 SvRV(*svp) = SvREFCNT_inc(newHV());
3203 else if (op->op_private == OP_RV2AV) {
3206 sv_upgrade(*svp, SVt_RV);
3207 SvRV(*svp) = SvREFCNT_inc(newAV());
3214 svp = hv_fetch(hv, key, keylen, FALSE);
3215 PUSHs(svp ? *svp : &sv_undef);
3221 dSP; dMARK; dORIGMARK;
3223 register HV *hv = (HV*)POPs;
3224 register I32 lval = op->op_flags & OPf_LVAL;
3225 I32 is_something_there = lval;
3227 while (++MARK <= SP) {
3229 char *key = SvPV(*MARK, keylen);
3232 svp = hv_fetch(hv, key, keylen, TRUE);
3233 if (!svp || *svp == &sv_undef)
3235 if (op->op_flags & OPf_INTRO)
3239 svp = hv_fetch(hv, key, keylen, FALSE);
3240 if (!is_something_there && svp && SvOK(*svp))
3241 is_something_there = TRUE;
3243 *MARK = svp ? *svp : &sv_undef;
3245 if (!is_something_there)
3250 /* Explosives and implosives. */
3259 register char *pat = SvPV(lstr, llen);
3260 register char *s = SvPV(rstr, rlen);
3261 char *strend = s + rlen;
3263 register char *patend = pat + llen;
3268 /* These must not be in registers: */
3279 unsigned quad auquad;
3285 register U32 culong;
3287 static char* bitcount = 0;
3289 if (GIMME != G_ARRAY) { /* arrange to do first one only */
3291 for (patend = pat; !isALPHA(*patend) || *patend == 'x'; patend++) ;
3292 if (strchr("aAbBhH", *patend) || *pat == '%') {
3294 while (isDIGIT(*patend) || *patend == '*')
3300 while (pat < patend) {
3305 else if (*pat == '*') {
3306 len = strend - strbeg; /* long enough */
3309 else if (isDIGIT(*pat)) {
3311 while (isDIGIT(*pat))
3312 len = (len * 10) + (*pat++ - '0');
3315 len = (datumtype != '@');
3320 if (len == 1 && pat[-1] != '1')
3329 if (len > strend - strbeg)
3330 DIE("@ outside of string");
3334 if (len > s - strbeg)
3335 DIE("X outside of string");
3339 if (len > strend - s)
3340 DIE("x outside of string");
3345 if (len > strend - s)
3348 goto uchar_checksum;
3349 sv = NEWSV(35, len);
3350 sv_setpvn(sv, s, len);
3352 if (datumtype == 'A') {
3353 aptr = s; /* borrow register */
3354 s = SvPVX(sv) + len - 1;
3355 while (s >= SvPVX(sv) && (!*s || isSPACE(*s)))
3358 SvCUR_set(sv, s - SvPVX(sv));
3359 s = aptr; /* unborrow register */
3361 XPUSHs(sv_2mortal(sv));
3365 if (pat[-1] == '*' || len > (strend - s) * 8)
3366 len = (strend - s) * 8;
3369 Newz(601, bitcount, 256, char);
3370 for (bits = 1; bits < 256; bits++) {
3371 if (bits & 1) bitcount[bits]++;
3372 if (bits & 2) bitcount[bits]++;
3373 if (bits & 4) bitcount[bits]++;
3374 if (bits & 8) bitcount[bits]++;
3375 if (bits & 16) bitcount[bits]++;
3376 if (bits & 32) bitcount[bits]++;
3377 if (bits & 64) bitcount[bits]++;
3378 if (bits & 128) bitcount[bits]++;
3382 culong += bitcount[*(unsigned char*)s++];
3387 if (datumtype == 'b') {
3389 if (bits & 1) culong++;
3395 if (bits & 128) culong++;
3402 sv = NEWSV(35, len + 1);
3405 aptr = pat; /* borrow register */
3407 if (datumtype == 'b') {
3409 for (len = 0; len < aint; len++) {
3410 if (len & 7) /*SUPPRESS 595*/
3414 *pat++ = '0' + (bits & 1);
3419 for (len = 0; len < aint; len++) {
3424 *pat++ = '0' + ((bits & 128) != 0);
3428 pat = aptr; /* unborrow register */
3429 XPUSHs(sv_2mortal(sv));
3433 if (pat[-1] == '*' || len > (strend - s) * 2)
3434 len = (strend - s) * 2;
3435 sv = NEWSV(35, len + 1);
3438 aptr = pat; /* borrow register */
3440 if (datumtype == 'h') {
3442 for (len = 0; len < aint; len++) {
3447 *pat++ = hexdigit[bits & 15];
3452 for (len = 0; len < aint; len++) {
3457 *pat++ = hexdigit[(bits >> 4) & 15];
3461 pat = aptr; /* unborrow register */
3462 XPUSHs(sv_2mortal(sv));
3465 if (len > strend - s)
3470 if (aint >= 128) /* fake up signed chars */
3479 if (aint >= 128) /* fake up signed chars */
3482 sv_setiv(sv, (I32)aint);
3483 PUSHs(sv_2mortal(sv));
3488 if (len > strend - s)
3502 sv_setiv(sv, (I32)auint);
3503 PUSHs(sv_2mortal(sv));
3508 along = (strend - s) / sizeof(I16);
3513 Copy(s, &ashort, 1, I16);
3521 Copy(s, &ashort, 1, I16);
3524 sv_setiv(sv, (I32)ashort);
3525 PUSHs(sv_2mortal(sv));
3532 along = (strend - s) / sizeof(U16);
3537 Copy(s, &aushort, 1, U16);
3540 if (datumtype == 'n')
3541 aushort = ntohs(aushort);
3544 if (datumtype == 'v')
3545 aushort = vtohs(aushort);
3553 Copy(s, &aushort, 1, U16);
3557 if (datumtype == 'n')
3558 aushort = ntohs(aushort);
3561 if (datumtype == 'v')
3562 aushort = vtohs(aushort);
3564 sv_setiv(sv, (I32)aushort);
3565 PUSHs(sv_2mortal(sv));
3570 along = (strend - s) / sizeof(int);
3575 Copy(s, &aint, 1, int);
3578 cdouble += (double)aint;
3586 Copy(s, &aint, 1, int);
3589 sv_setiv(sv, (I32)aint);
3590 PUSHs(sv_2mortal(sv));
3595 along = (strend - s) / sizeof(unsigned int);
3600 Copy(s, &auint, 1, unsigned int);
3601 s += sizeof(unsigned int);
3603 cdouble += (double)auint;
3611 Copy(s, &auint, 1, unsigned int);
3612 s += sizeof(unsigned int);
3614 sv_setiv(sv, (I32)auint);
3615 PUSHs(sv_2mortal(sv));
3620 along = (strend - s) / sizeof(I32);
3625 Copy(s, &along, 1, I32);
3628 cdouble += (double)along;
3636 Copy(s, &along, 1, I32);
3639 sv_setiv(sv, (I32)along);
3640 PUSHs(sv_2mortal(sv));
3647 along = (strend - s) / sizeof(U32);
3652 Copy(s, &aulong, 1, U32);
3655 if (datumtype == 'N')
3656 aulong = ntohl(aulong);
3659 if (datumtype == 'V')
3660 aulong = vtohl(aulong);
3663 cdouble += (double)aulong;
3671 Copy(s, &aulong, 1, U32);
3675 if (datumtype == 'N')
3676 aulong = ntohl(aulong);
3679 if (datumtype == 'V')
3680 aulong = vtohl(aulong);
3682 sv_setnv(sv, (double)aulong);
3683 PUSHs(sv_2mortal(sv));
3688 along = (strend - s) / sizeof(char*);
3693 if (sizeof(char*) > strend - s)
3696 Copy(s, &aptr, 1, char*);
3702 PUSHs(sv_2mortal(sv));
3707 if (sizeof(char*) > strend - s)
3710 Copy(s, &aptr, 1, char*);
3715 sv_setpvn(sv, aptr, len);
3716 PUSHs(sv_2mortal(sv));
3722 if (s + sizeof(quad) > strend)
3725 Copy(s, &aquad, 1, quad);
3729 sv_setnv(sv, (double)aquad);
3730 PUSHs(sv_2mortal(sv));
3736 if (s + sizeof(unsigned quad) > strend)
3739 Copy(s, &auquad, 1, unsigned quad);
3740 s += sizeof(unsigned quad);
3743 sv_setnv(sv, (double)auquad);
3744 PUSHs(sv_2mortal(sv));
3748 /* float and double added gnb@melba.bby.oz.au 22/11/89 */
3751 along = (strend - s) / sizeof(float);
3756 Copy(s, &afloat, 1, float);
3764 Copy(s, &afloat, 1, float);
3767 sv_setnv(sv, (double)afloat);
3768 PUSHs(sv_2mortal(sv));
3774 along = (strend - s) / sizeof(double);
3779 Copy(s, &adouble, 1, double);
3780 s += sizeof(double);
3787 Copy(s, &adouble, 1, double);
3788 s += sizeof(double);
3790 sv_setnv(sv, (double)adouble);
3791 PUSHs(sv_2mortal(sv));
3796 along = (strend - s) * 3 / 4;
3797 sv = NEWSV(42, along);
3798 while (s < strend && *s > ' ' && *s < 'a') {
3803 len = (*s++ - ' ') & 077;
3805 if (s < strend && *s >= ' ')
3806 a = (*s++ - ' ') & 077;
3809 if (s < strend && *s >= ' ')
3810 b = (*s++ - ' ') & 077;
3813 if (s < strend && *s >= ' ')
3814 c = (*s++ - ' ') & 077;
3817 if (s < strend && *s >= ' ')
3818 d = (*s++ - ' ') & 077;
3821 hunk[0] = a << 2 | b >> 4;
3822 hunk[1] = b << 4 | c >> 2;
3823 hunk[2] = c << 6 | d;
3824 sv_catpvn(sv, hunk, len > 3 ? 3 : len);
3829 else if (s[1] == '\n') /* possible checksum byte */
3832 XPUSHs(sv_2mortal(sv));
3837 if (strchr("fFdD", datumtype) ||
3838 (checksum > 32 && strchr("iIlLN", datumtype)) ) {
3843 while (checksum >= 16) {
3847 while (checksum >= 4) {
3853 along = (1 << checksum) - 1;
3854 while (cdouble < 0.0)
3856 cdouble = modf(cdouble / adouble, &trouble) * adouble;
3857 sv_setnv(sv, cdouble);
3860 if (checksum < 32) {
3861 along = (1 << checksum) - 1;
3862 culong &= (U32)along;
3864 sv_setnv(sv, (double)culong);
3866 XPUSHs(sv_2mortal(sv));
3874 doencodes(sv, s, len)
3882 sv_catpvn(sv, hunk, 1);
3885 hunk[0] = ' ' + (077 & (*s >> 2));
3886 hunk[1] = ' ' + (077 & ((*s << 4) & 060 | (s[1] >> 4) & 017));
3887 hunk[2] = ' ' + (077 & ((s[1] << 2) & 074 | (s[2] >> 6) & 03));
3888 hunk[3] = ' ' + (077 & (s[2] & 077));
3889 sv_catpvn(sv, hunk, 4);
3893 for (s = SvPVX(sv); *s; s++) {
3897 sv_catpvn(sv, "\n", 1);
3902 dSP; dMARK; dORIGMARK; dTARGET;
3903 register SV *cat = TARG;
3906 register char *pat = SvPVx(*++MARK, fromlen);
3907 register char *patend = pat + fromlen;
3912 static char null10[] = {0,0,0,0,0,0,0,0,0,0};
3913 static char *space10 = " ";
3915 /* These must not be in registers: */
3924 unsigned quad auquad;
3932 sv_setpvn(cat, "", 0);
3933 while (pat < patend) {
3934 #define NEXTFROM (items-- > 0 ? *MARK++ : &sv_no)
3937 len = strchr("@Xxu", datumtype) ? 0 : items;
3940 else if (isDIGIT(*pat)) {
3942 while (isDIGIT(*pat))
3943 len = (len * 10) + (*pat++ - '0');
3951 DIE("%% may only be used in unpack");
3962 if (SvCUR(cat) < len)
3963 DIE("X outside of string");
3970 sv_catpvn(cat, null10, 10);
3973 sv_catpvn(cat, null10, len);
3978 aptr = SvPV(fromstr, fromlen);
3982 sv_catpvn(cat, aptr, len);
3984 sv_catpvn(cat, aptr, fromlen);
3986 if (datumtype == 'A') {
3988 sv_catpvn(cat, space10, 10);
3991 sv_catpvn(cat, space10, len);
3995 sv_catpvn(cat, null10, 10);
3998 sv_catpvn(cat, null10, len);
4005 char *savepat = pat;
4010 aptr = SvPV(fromstr, fromlen);
4015 SvCUR(cat) += (len+7)/8;
4016 SvGROW(cat, SvCUR(cat) + 1);
4017 aptr = SvPVX(cat) + aint;
4022 if (datumtype == 'B') {
4023 for (len = 0; len++ < aint;) {
4024 items |= *pat++ & 1;
4028 *aptr++ = items & 0xff;
4034 for (len = 0; len++ < aint;) {
4040 *aptr++ = items & 0xff;
4046 if (datumtype == 'B')
4047 items <<= 7 - (aint & 7);
4049 items >>= 7 - (aint & 7);
4050 *aptr++ = items & 0xff;
4052 pat = SvPVX(cat) + SvCUR(cat);
4063 char *savepat = pat;
4068 aptr = SvPV(fromstr, fromlen);
4073 SvCUR(cat) += (len+1)/2;
4074 SvGROW(cat, SvCUR(cat) + 1);
4075 aptr = SvPVX(cat) + aint;
4080 if (datumtype == 'H') {
4081 for (len = 0; len++ < aint;) {
4083 items |= ((*pat++ & 15) + 9) & 15;
4085 items |= *pat++ & 15;
4089 *aptr++ = items & 0xff;
4095 for (len = 0; len++ < aint;) {
4097 items |= (((*pat++ & 15) + 9) & 15) << 4;
4099 items |= (*pat++ & 15) << 4;
4103 *aptr++ = items & 0xff;
4109 *aptr++ = items & 0xff;
4110 pat = SvPVX(cat) + SvCUR(cat);
4122 aint = SvIV(fromstr);
4124 sv_catpvn(cat, &achar, sizeof(char));
4127 /* Float and double added by gnb@melba.bby.oz.au 22/11/89 */
4132 afloat = (float)SvNV(fromstr);
4133 sv_catpvn(cat, (char *)&afloat, sizeof (float));
4140 adouble = (double)SvNV(fromstr);
4141 sv_catpvn(cat, (char *)&adouble, sizeof (double));
4147 ashort = (I16)SvIV(fromstr);
4149 ashort = htons(ashort);
4151 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
4157 ashort = (I16)SvIV(fromstr);
4159 ashort = htovs(ashort);
4161 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
4168 ashort = (I16)SvIV(fromstr);
4169 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
4175 auint = U_I(SvNV(fromstr));
4176 sv_catpvn(cat, (char*)&auint, sizeof(unsigned int));
4182 aint = SvIV(fromstr);
4183 sv_catpvn(cat, (char*)&aint, sizeof(int));
4189 aulong = U_L(SvNV(fromstr));
4191 aulong = htonl(aulong);
4193 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
4199 aulong = U_L(SvNV(fromstr));
4201 aulong = htovl(aulong);
4203 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
4209 aulong = U_L(SvNV(fromstr));
4210 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
4216 along = SvIV(fromstr);
4217 sv_catpvn(cat, (char*)&along, sizeof(I32));
4224 auquad = (unsigned quad)SvNV(fromstr);
4225 sv_catpvn(cat, (char*)&auquad, sizeof(unsigned quad));
4231 aquad = (quad)SvNV(fromstr);
4232 sv_catpvn(cat, (char*)&aquad, sizeof(quad));
4237 len = 1; /* assume SV is correct length */
4242 aptr = SvPV(fromstr, na);
4243 sv_catpvn(cat, (char*)&aptr, sizeof(char*));
4248 aptr = SvPV(fromstr, fromlen);
4249 SvGROW(cat, fromlen * 4 / 3);
4254 while (fromlen > 0) {
4261 doencodes(cat, aptr, todo);
4279 register I32 limit = POPi; /* note, negative is forever */
4282 register char *s = SvPV(sv, len);
4283 char *strend = s + len;
4284 register PMOP *pm = (PMOP*)POPs;
4288 I32 maxiters = (strend - s) + 10;
4291 I32 origlimit = limit;
4295 register REGEXP *rx = pm->op_pmregexp;
4299 DIE("panic: do_split");
4300 if (pm->op_pmreplroot)
4301 ary = GvAVn((GV*)pm->op_pmreplroot);
4302 else if (gimme != G_ARRAY)
4306 if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) {
4310 for (i = AvFILL(ary); i >= 0; i--)
4311 AvARRAY(ary)[i] = Nullsv; /* don't free mere refs */
4313 av_fill(ary,0); /* force allocation */
4315 /* temporarily switch stacks */
4317 SWITCHSTACK(stack, ary);
4319 base = SP - stack_base + 1;
4321 if (pm->op_pmflags & PMf_SKIPWHITE) {
4326 limit = maxiters + 2;
4327 if (strEQ("\\s+", rx->precomp)) {
4330 for (m = s; m < strend && !isSPACE(*m); m++) ;
4333 dstr = NEWSV(30, m-s);
4334 sv_setpvn(dstr, s, m-s);
4339 for (s = m + 1; s < strend && isSPACE(*s); s++) ;
4342 else if (strEQ("^", rx->precomp)) {
4345 for (m = s; m < strend && *m != '\n'; m++) ;
4349 dstr = NEWSV(30, m-s);
4350 sv_setpvn(dstr, s, m-s);
4357 else if (pm->op_pmshort) {
4358 i = SvCUR(pm->op_pmshort);
4360 I32 fold = (pm->op_pmflags & PMf_FOLD);
4361 i = *SvPVX(pm->op_pmshort);
4362 if (fold && isUPPER(i))
4367 m < strend && *m != i &&
4368 (!isUPPER(*m) || tolower(*m) != i);
4369 m++) /*SUPPRESS 530*/
4372 else /*SUPPRESS 530*/
4373 for (m = s; m < strend && *m != i; m++) ;
4376 dstr = NEWSV(30, m-s);
4377 sv_setpvn(dstr, s, m-s);
4386 while (s < strend && --limit &&
4387 (m=fbm_instr((unsigned char*)s, (unsigned char*)strend,
4391 dstr = NEWSV(31, m-s);
4392 sv_setpvn(dstr, s, m-s);
4401 maxiters += (strend - s) * rx->nparens;
4402 while (s < strend && --limit &&
4403 regexec(rx, s, strend, orig, 1, Nullsv, TRUE) ) {
4405 && rx->subbase != orig) {
4410 strend = s + (strend - m);
4413 dstr = NEWSV(32, m-s);
4414 sv_setpvn(dstr, s, m-s);
4419 for (i = 1; i <= rx->nparens; i++) {
4422 dstr = NEWSV(33, m-s);
4423 sv_setpvn(dstr, s, m-s);
4432 iters = (SP - stack_base) - base;
4433 if (iters > maxiters)
4435 if (s < strend || origlimit) { /* keep field after final delim? */
4436 dstr = NEWSV(34, strend-s);
4437 sv_setpvn(dstr, s, strend-s);
4444 while (iters > 0 && SvCUR(TOPs) == 0)
4448 SWITCHSTACK(ary, oldstack);
4449 if (gimme == G_ARRAY) {
4451 Copy(AvARRAY(ary), SP + 1, iters, SV*);
4457 if (gimme == G_ARRAY)
4460 SP = stack_base + base;
4468 dSP; dMARK; dTARGET;
4470 do_join(TARG, *MARK, MARK, SP);
4476 /* List operators. */
4481 if (GIMME != G_ARRAY) {
4483 *MARK = *SP; /* unwanted list, return last item */
4494 SV **lastrelem = stack_sp;
4495 SV **lastlelem = stack_base + POPMARK;
4496 SV **firstlelem = stack_base + POPMARK + 1;
4497 register SV **firstrelem = lastlelem + 1;
4498 I32 lval = op->op_flags & OPf_LVAL;
4499 I32 is_something_there = lval;
4501 register I32 max = lastrelem - lastlelem;
4502 register SV **lelem;
4505 if (GIMME != G_ARRAY) {
4506 ix = SvIVx(*lastlelem) - arybase;
4507 if (ix < 0 || ix >= max)
4508 *firstlelem = &sv_undef;
4510 *firstlelem = firstrelem[ix];
4516 SP = firstlelem - 1;
4520 for (lelem = firstlelem; lelem <= lastlelem; lelem++) {
4521 ix = SvIVx(*lelem) - arybase;
4526 else if (!(*lelem = firstrelem[ix]))
4529 else if (ix >= max || !(*lelem = firstrelem[ix]))
4531 if (!is_something_there && SvOK(*lelem))
4532 is_something_there = TRUE;
4534 if (is_something_there)
4537 SP = firstlelem - 1;
4544 I32 items = SP - MARK;
4546 XPUSHs((SV*)av_make(items, MARK+1));
4552 dSP; dMARK; dORIGMARK;
4558 SV *val = NEWSV(46, 0);
4560 sv_setsv(val, *++MARK);
4562 (void)hv_store(hv,tmps,SvCUROK(key),val,0);
4572 dSP; dMARK; dORIGMARK;
4573 register AV *ary = (AV*)*++MARK;
4577 register I32 offset;
4578 register I32 length;
4587 offset = SvIVx(*MARK);
4589 offset += AvFILL(ary) + 1;
4593 length = SvIVx(*MARK++);
4598 length = AvMAX(ary) + 1; /* close enough to infinity */
4602 length = AvMAX(ary) + 1;
4610 if (offset > AvFILL(ary) + 1)
4611 offset = AvFILL(ary) + 1;
4612 after = AvFILL(ary) + 1 - (offset + length);
4613 if (after < 0) { /* not that much array */
4614 length += after; /* offset+length now in array */
4616 if (!AvALLOC(ary)) {
4622 /* At this point, MARK .. SP-1 is our new LIST */
4625 diff = newlen - length;
4627 if (diff < 0) { /* shrinking the area */
4629 New(451, tmparyval, newlen, SV*); /* so remember insertion */
4630 Copy(MARK, tmparyval, newlen, SV*);
4633 MARK = ORIGMARK + 1;
4634 if (GIMME == G_ARRAY) { /* copy return vals to stack */
4635 MEXTEND(MARK, length);
4636 Copy(AvARRAY(ary)+offset, MARK, length, SV*);
4638 for (i = length, dst = MARK; i; i--)
4639 sv_2mortal(*dst++); /* free them eventualy */
4644 *MARK = AvARRAY(ary)[offset+length-1];
4647 for (i = length - 1, dst = &AvARRAY(ary)[offset]; i > 0; i--)
4648 SvREFCNT_dec(*dst++); /* free them now */
4651 AvFILL(ary) += diff;
4653 /* pull up or down? */
4655 if (offset < after) { /* easier to pull up */
4656 if (offset) { /* esp. if nothing to pull */
4657 src = &AvARRAY(ary)[offset-1];
4658 dst = src - diff; /* diff is negative */
4659 for (i = offset; i > 0; i--) /* can't trust Copy */
4662 Zero(AvARRAY(ary), -diff, SV*);
4663 SvPVX(ary) = (char*)(AvARRAY(ary) - diff); /* diff is negative */
4667 if (after) { /* anything to pull down? */
4668 src = AvARRAY(ary) + offset + length;
4669 dst = src + diff; /* diff is negative */
4670 Move(src, dst, after, SV*);
4672 Zero(&AvARRAY(ary)[AvFILL(ary)+1], -diff, SV*);
4673 /* avoid later double free */
4676 for (src = tmparyval, dst = AvARRAY(ary) + offset;
4678 *dst = NEWSV(46, 0);
4679 sv_setsv(*dst++, *src++);
4681 Safefree(tmparyval);
4684 else { /* no, expanding (or same) */
4686 New(452, tmparyval, length, SV*); /* so remember deletion */
4687 Copy(AvARRAY(ary)+offset, tmparyval, length, SV*);
4690 if (diff > 0) { /* expanding */
4692 /* push up or down? */
4694 if (offset < after && diff <= AvARRAY(ary) - AvALLOC(ary)) {
4698 Move(src, dst, offset, SV*);
4700 SvPVX(ary) = (char*)(AvARRAY(ary) - diff);/* diff is positive */
4702 AvFILL(ary) += diff;
4705 if (AvFILL(ary) + diff >= AvMAX(ary)) /* oh, well */
4706 av_store(ary, AvFILL(ary) + diff, Nullsv);
4708 AvFILL(ary) += diff;
4709 dst = AvARRAY(ary) + AvFILL(ary);
4710 for (i = diff; i > 0; i--) {
4711 if (*dst) /* stuff was hanging around */
4712 SvREFCNT_dec(*dst); /* after $#foo */
4716 dst = AvARRAY(ary) + AvFILL(ary);
4718 for (i = after; i; i--) {
4725 for (src = MARK, dst = AvARRAY(ary) + offset; newlen; newlen--) {
4726 *dst = NEWSV(46, 0);
4727 sv_setsv(*dst++, *src++);
4729 MARK = ORIGMARK + 1;
4730 if (GIMME == G_ARRAY) { /* copy return vals to stack */
4732 Copy(tmparyval, MARK, length, SV*);
4734 for (i = length, dst = MARK; i; i--)
4735 sv_2mortal(*dst++); /* free them eventualy */
4737 Safefree(tmparyval);
4741 else if (length--) {
4742 *MARK = tmparyval[length];
4745 while (length-- > 0)
4746 SvREFCNT_dec(tmparyval[length]);
4748 Safefree(tmparyval);
4759 dSP; dMARK; dORIGMARK; dTARGET;
4760 register AV *ary = (AV*)*++MARK;
4761 register SV *sv = &sv_undef;
4763 for (++MARK; MARK <= SP; MARK++) {
4766 sv_setsv(sv, *MARK);
4767 (void)av_push(ary, sv);
4770 PUSHi( AvFILL(ary) + 1 );
4778 SV *sv = av_pop(av);
4782 (void)sv_2mortal(sv);
4791 SV *sv = av_shift(av);
4796 (void)sv_2mortal(sv);
4803 dSP; dMARK; dORIGMARK; dTARGET;
4804 register AV *ary = (AV*)*++MARK;
4808 av_unshift(ary, SP - MARK);
4811 sv_setsv(sv, *++MARK);
4812 (void)av_store(ary, i++, sv);
4816 PUSHi( AvFILL(ary) + 1 );
4825 if (stack_base + *markstack_ptr == sp) {
4827 RETURNOP(op->op_next->op_next);
4829 stack_sp = stack_base + *markstack_ptr + 1;
4830 pp_pushmark(); /* push dst */
4831 pp_pushmark(); /* push src */
4832 ENTER; /* enter outer scope */
4835 SAVESPTR(GvSV(defgv));
4837 ENTER; /* enter inner scope */
4840 if (src = stack_base[*markstack_ptr]) {
4845 GvSV(defgv) = sv_newmortal();
4847 RETURNOP(((LOGOP*)op->op_next)->op_other);
4855 stack_base[markstack_ptr[-1]++] = stack_base[*markstack_ptr];
4857 LEAVE; /* exit inner scope */
4860 if (stack_base + *markstack_ptr > sp) {
4863 LEAVE; /* exit outer scope */
4864 POPMARK; /* pop src */
4865 items = --*markstack_ptr - markstack_ptr[-1];
4866 POPMARK; /* pop dst */
4867 SP = stack_base + POPMARK; /* pop original mark */
4868 if (GIMME != G_ARRAY) {
4879 ENTER; /* enter inner scope */
4882 if (src = stack_base[*markstack_ptr]) {
4887 GvSV(defgv) = sv_newmortal();
4889 RETURNOP(cLOGOP->op_other);
4893 static int sortcmp();
4894 static int sortcv();
4898 dSP; dMARK; dORIGMARK;
4900 SV **myorigmark = ORIGMARK;
4908 if (GIMME != G_ARRAY) {
4913 if (op->op_flags & OPf_STACKED) {
4914 if (op->op_flags & OPf_SPECIAL) {
4915 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
4916 kid = kUNOP->op_first; /* pass rv2gv */
4917 kid = kUNOP->op_first; /* pass leave */
4918 sortcop = kid->op_next;
4919 stash = curcop->cop_stash;
4922 cv = sv_2cv(*++MARK, &stash, &gv, 0);
4923 if (!(cv && CvROOT(cv))) {
4925 SV *tmpstr = sv_newmortal();
4926 gv_efullname(tmpstr, gv);
4928 DIE("Usersub \"%s\" called in sort", SvPVX(tmpstr));
4929 DIE("Undefined sort subroutine \"%s\" called",
4934 DIE("Usersub called in sort");
4935 DIE("Undefined subroutine in sort");
4937 DIE("Not a subroutine reference in sort");
4939 sortcop = CvSTART(cv);
4940 SAVESPTR(CvROOT(cv)->op_ppaddr);
4941 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
4946 stash = curcop->cop_stash;
4949 up = myorigmark + 1;
4950 while (MARK < SP) { /* This may or may not shift down one here. */
4952 if (*up = *++MARK) { /* Weed out nulls. */
4954 (void)sv_2pv(*up, &na);
4960 max = --up - myorigmark;
4971 sortstack = newAV();
4972 av_store(sortstack, 32, Nullsv);
4973 av_clear(sortstack);
4974 AvREAL_off(sortstack);
4976 SWITCHSTACK(stack, sortstack);
4977 if (sortstash != stash) {
4978 firstgv = gv_fetchpv("a", TRUE);
4979 secondgv = gv_fetchpv("b", TRUE);
4983 SAVESPTR(GvSV(firstgv));
4984 SAVESPTR(GvSV(secondgv));
4986 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
4988 SWITCHSTACK(sortstack, oldstack);
4993 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
4994 qsort((char*)(ORIGMARK+1), max, sizeof(SV*), sortcmp);
4997 SP = ORIGMARK + max;
5007 if (GIMME == G_ARRAY) {
5018 register char *down;
5024 do_join(TARG, &sv_no, MARK, SP);
5026 sv_setsv(TARG, *SP);
5027 up = SvPV(TARG, len);
5029 down = SvPVX(TARG) + len - 1;
5047 if (GIMME == G_ARRAY)
5048 return cCONDOP->op_true;
5049 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
5056 if (GIMME == G_ARRAY) {
5057 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
5061 SV *targ = PAD_SV(op->op_targ);
5063 if ((op->op_private & OPpFLIP_LINENUM)
5064 ? last_in_gv && SvIV(sv) == IoLINES(GvIO(last_in_gv))
5066 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
5067 if (op->op_flags & OPf_SPECIAL) {
5074 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
5087 if (GIMME == G_ARRAY) {
5093 if (SvNIOK(lstr) || !SvPOK(lstr) ||
5094 (looks_like_number(lstr) && *SvPVX(lstr) != '0') ) {
5098 EXTEND(SP, max - i + 1);
5100 sv = sv_mortalcopy(&sv_no);
5106 SV *final = sv_mortalcopy(rstr);
5108 char *tmps = SvPV(final, len);
5110 sv = sv_mortalcopy(lstr);
5111 while (!SvNIOK(sv) && SvCUR(sv) <= len &&
5112 strNE(SvPVX(sv),tmps) ) {
5114 sv = sv_2mortal(newSVsv(sv));
5117 if (strEQ(SvPVX(sv),tmps))
5123 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
5125 if ((op->op_private & OPpFLIP_LINENUM)
5126 ? last_in_gv && SvIV(sv) == IoLINES(GvIO(last_in_gv))
5128 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
5129 sv_catpv(targ, "E0");
5144 register CONTEXT *cx;
5146 for (i = cxstack_ix; i >= 0; i--) {
5148 switch (cx->cx_type) {
5151 warn("Exiting substitution via %s", op_name[op->op_type]);
5155 warn("Exiting subroutine via %s", op_name[op->op_type]);
5159 warn("Exiting eval via %s", op_name[op->op_type]);
5162 if (!cx->blk_loop.label ||
5163 strNE(label, cx->blk_loop.label) ) {
5164 DEBUG_l(deb("(Skipping label #%d %s)\n",
5165 i, cx->blk_loop.label));
5168 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
5175 dopoptosub(startingblock)
5179 register CONTEXT *cx;
5180 for (i = startingblock; i >= 0; i--) {
5182 switch (cx->cx_type) {
5187 DEBUG_l( deb("(Found sub #%d)\n", i));
5195 dopoptoeval(startingblock)
5199 register CONTEXT *cx;
5200 for (i = startingblock; i >= 0; i--) {
5202 switch (cx->cx_type) {
5206 DEBUG_l( deb("(Found eval #%d)\n", i));
5214 dopoptoloop(startingblock)
5218 register CONTEXT *cx;
5219 for (i = startingblock; i >= 0; i--) {
5221 switch (cx->cx_type) {
5224 warn("Exiting substitition via %s", op_name[op->op_type]);
5228 warn("Exiting subroutine via %s", op_name[op->op_type]);
5232 warn("Exiting eval via %s", op_name[op->op_type]);
5235 DEBUG_l( deb("(Found loop #%d)\n", i));
5246 register CONTEXT *cx;
5250 while (cxstack_ix > cxix) {
5251 cx = &cxstack[cxstack_ix--];
5252 DEBUG_l(fprintf(stderr, "Unwinding block %d, type %s\n", cxstack_ix+1,
5253 block_type[cx->cx_type]));
5254 /* Note: we don't need to restore the base context info till the end. */
5255 switch (cx->cx_type) {
5288 va_start(args, pat);
5292 message = mess(pat, &args);
5294 restartop = die_where(message);
5295 if (stack != mainstack)
5296 longjmp(top_env, 3);
5306 register CONTEXT *cx;
5310 sv_setpv(GvSV(gv_fetchpv("@",TRUE)),message);
5311 cxix = dopoptoeval(cxstack_ix);
5315 if (cxix < cxstack_ix)
5319 if (cx->cx_type != CXt_EVAL) {
5320 fprintf(stderr, "panic: die %s", message);
5325 if (gimme == G_SCALAR)
5326 *++newsp = &sv_undef;
5330 if (optype == OP_REQUIRE)
5331 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE)), na));
5332 return pop_return();
5335 fputs(message, stderr);
5336 (void)fflush(stderr);
5338 (void)UNLINK(e_tmpname);
5340 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
5351 RETURNOP(cLOGOP->op_other);
5362 RETURNOP(cLOGOP->op_other);
5370 RETURNOP(cCONDOP->op_true);
5372 RETURNOP(cCONDOP->op_false);
5381 RETURNOP(cLOGOP->op_other);
5390 RETURNOP(cLOGOP->op_other);
5409 !(iogv = gv_fetchpv(SvPVX(sv), FALSE)) ||
5410 !(ob=(SV*)GvIO(iogv)))
5412 char *name = SvPVX(((SVOP*)cLOGOP->op_other)->op_sv);
5414 char* packname = SvPV(sv, na);
5416 if (!isALPHA(*packname))
5417 DIE("Can't call method \"%s\" without a package or object reference", name);
5418 if (!(stash = fetch_stash(sv, FALSE)))
5419 DIE("Can't call method \"%s\" in empty package \"%s\"",
5421 gv = gv_fetchmethod(stash,name);
5423 DIE("Can't locate object method \"%s\" via package \"%s\"",
5431 if (!ob || !SvOBJECT(ob)) {
5432 char *name = SvPVX(((SVOP*)cLOGOP->op_other)->op_sv);
5433 DIE("Can't call method \"%s\" on unblessed reference", name);
5436 if (!gv) { /* nothing cached */
5437 char *name = SvPVX(((SVOP*)cLOGOP->op_other)->op_sv);
5438 gv = gv_fetchmethod(SvSTASH(ob),name);
5440 DIE("Can't locate object method \"%s\" via package \"%s\"",
5441 name, HvNAME(SvSTASH(ob)));
5456 register I32 items = SP - MARK;
5457 I32 hasargs = (op->op_flags & OPf_STACKED) != 0;
5458 register CONTEXT *cx;
5461 DIE("Not a subroutine reference");
5462 switch (SvTYPE(sv)) {
5466 DIE(no_usym, "a subroutine");
5467 gv = gv_fetchpv(SvPV(sv, na), FALSE);
5477 if (SvTYPE(cv) == SVt_PVCV)
5482 DIE("Not a subroutine reference");
5487 if (!(cv = GvCV((GV*)sv)))
5488 cv = sv_2cv(sv, &stash, &gv, TRUE);
5497 DIE("Not a subroutine reference");
5499 if (!CvROOT(cv) && !CvUSERSUB(cv)) {
5500 if (gv = CvGV(cv)) {
5501 SV *tmpstr = sv_newmortal();
5503 gv_efullname(tmpstr, gv);
5504 ngv = gv_fetchmethod(GvESTASH(gv), "AUTOLOAD");
5505 if (ngv && ngv != gv && (cv = GvCV(ngv))) { /* One more chance... */
5507 sv_setsv(GvSV(gv), tmpstr);
5511 DIE("Undefined subroutine &%s called",SvPVX(tmpstr));
5513 DIE("Undefined subroutine called");
5516 if ((op->op_private & OPpSUBR_DB) && !CvUSERSUB(cv)) {
5520 gv_efullname(sv,gv);
5523 DIE("No DBsub routine");
5526 if (CvUSERSUB(cv)) {
5527 items = (*CvUSERSUB(cv))(CvUSERINDEX(cv), MARK - stack_base, items);
5528 sp = stack_base + items;
5534 AV* padlist = CvPADLIST(cv);
5535 SV** svp = AvARRAY(padlist);
5536 push_return(op->op_next);
5537 PUSHBLOCK(cx, CXt_SUB, MARK - 1);
5540 if (CvDEPTH(cv) >= 2) { /* save temporaries on recursion? */
5541 if (CvDEPTH(cv) == 100 && dowarn)
5542 warn("Deep recursion on subroutine \"%s\"",GvENAME(CvGV(cv)));
5543 if (CvDEPTH(cv) > AvFILL(padlist)) {
5544 AV *newpad = newAV();
5545 I32 ix = AvFILL((AV*)svp[1]);
5546 svp = AvARRAY(svp[0]);
5549 char *name = SvPVX(svp[ix]); /* XXX */
5551 av_store(newpad, ix--, (SV*)newAV());
5552 else if (*name == '%')
5553 av_store(newpad, ix--, (SV*)newHV());
5555 av_store(newpad, ix--, NEWSV(0,0));
5558 av_store(newpad, ix--, NEWSV(0,0));
5562 av_store(av, 0, Nullsv);
5563 av_store(newpad, 0, (SV*)av);
5567 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
5568 AvFILL(padlist) = CvDEPTH(cv);
5569 svp = AvARRAY(padlist);
5573 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
5575 AV* av = (AV*)curpad[0];
5578 cx->blk_sub.savearray = GvAV(defgv);
5579 cx->blk_sub.argarray = av;
5580 GvAV(defgv) = cx->blk_sub.argarray;
5583 if (items >= AvMAX(av)) {
5585 if (AvARRAY(av) != ary) {
5586 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
5587 SvPVX(av) = (char*)ary;
5589 if (items >= AvMAX(av)) {
5590 AvMAX(av) = items - 1;
5591 Renew(ary,items+1,SV*);
5593 SvPVX(av) = (char*)ary;
5596 Copy(MARK,AvARRAY(av),items,SV*);
5597 AvFILL(av) = items - 1;
5604 RETURNOP(CvSTART(cv));
5614 register CONTEXT *cx;
5619 if (gimme == G_SCALAR) {
5622 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
5625 *MARK = sv_mortalcopy(TOPs);
5633 for (mark = newsp + 1; mark <= SP; mark++)
5634 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP)))
5635 *mark = sv_mortalcopy(*mark);
5636 /* in case LEAVE wipes old return values */
5641 return pop_return();
5646 return pop_return();
5652 register I32 cxix = dopoptosub(cxstack_ix);
5654 register CONTEXT *cx;
5663 if (GIMME != G_ARRAY)
5667 nextcxix = dopoptosub(cxix - 1);
5668 if (DBsub && nextcxix >= 0 &&
5669 cxstack[nextcxix].blk_sub.cv == GvCV(DBsub))
5675 cx = &cxstack[cxix];
5676 if (GIMME != G_ARRAY) {
5679 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
5684 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
5685 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
5686 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
5689 if (cx->cx_type == CXt_SUB) {
5691 gv_efullname(sv, CvGV(cx->blk_sub.cv));
5692 PUSHs(sv_2mortal(sv));
5693 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
5696 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
5697 PUSHs(sv_2mortal(newSViv(0)));
5699 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
5700 if (cx->blk_sub.hasargs && curstash == debstash) {
5701 AV *ary = cx->blk_sub.argarray;
5705 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE)));
5709 if (AvMAX(dbargs) < AvFILL(ary))
5710 av_store(dbargs, AvFILL(ary), Nullsv);
5711 Copy(AvARRAY(ary), AvARRAY(dbargs), AvFILL(ary)+1, SV*);
5712 AvFILL(dbargs) = AvFILL(ary);
5722 I32 oldscopeix = scopestack_ix;
5724 GvSV(firstgv) = *str1;
5725 GvSV(secondgv) = *str2;
5726 stack_sp = stack_base;
5729 result = SvIVx(AvARRAY(stack)[1]);
5730 while (scopestack_ix > oldscopeix) {
5737 sortcmp(strp1, strp2)
5741 register SV *str1 = *strp1;
5742 register SV *str2 = *strp2;
5745 if (SvCUR(str1) < SvCUR(str2)) {
5747 if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str1)))
5753 else if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str2)))
5755 else if (SvCUR(str1) == SvCUR(str2))
5765 if (SP - MARK != 1) {
5767 do_join(TARG, &sv_no, MARK, SP);
5768 tmps = SvPV(TARG, na);
5772 tmps = SvPV(TOPs, na);
5774 if (!tmps || !*tmps) {
5775 SV *error = GvSV(gv_fetchpv("@", TRUE));
5776 SvUPGRADE(error, SVt_PV);
5777 if (SvPOK(error) && SvCUR(error))
5778 sv_catpv(error, "\t...caught");
5779 tmps = SvPV(error, na);
5781 if (!tmps || !*tmps)
5782 tmps = "Warning: something's wrong";
5791 if (SP - MARK != 1) {
5793 do_join(TARG, &sv_no, MARK, SP);
5794 tmps = SvPV(TARG, na);
5798 tmps = SvPV(TOPs, na);
5800 if (!tmps || !*tmps) {
5801 SV *error = GvSV(gv_fetchpv("@", TRUE));
5802 SvUPGRADE(error, SVt_PV);
5803 if (SvPOK(error) && SvCUR(error))
5804 sv_catpv(error, "\t...propagated");
5805 tmps = SvPV(error, na);
5807 if (!tmps || !*tmps)
5822 sv_reset(tmps, curcop->cop_stash);
5835 TAINT_NOT; /* Each statement is presumed innocent */
5836 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
5844 TAINT_NOT; /* Each statement is presumed innocent */
5845 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
5848 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
5852 register CONTEXT *cx;
5869 DIE("No DB::DB routine defined");
5871 if (CvDEPTH(cv) >= 1) /* don't do recursive DB::DB call */
5873 push_return(op->op_next);
5874 PUSHBLOCK(cx, CXt_SUB, sp - 1);
5878 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
5879 RETURNOP(CvSTART(cv));
5888 TAINT_NOT; /* Each statement is presumed innocent */
5889 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
5891 oldsave = scopestack[scopestack_ix - 1];
5892 LEAVE_SCOPE(oldsave);
5899 register CONTEXT *cx;
5904 PUSHBLOCK(cx, CXt_BLOCK, sp);
5912 register CONTEXT *cx;
5919 if (GIMME == G_SCALAR) {
5922 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
5925 *MARK = sv_mortalcopy(TOPs);
5933 for (mark = newsp + 1; mark <= SP; mark++)
5934 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP)))
5935 *mark = sv_mortalcopy(*mark);
5936 /* in case LEAVE wipes old return values */
5952 register CONTEXT *cx;
5953 SV **svp = &GvSV((GV*)POPs);
5960 PUSHBLOCK(cx, CXt_LOOP, SP);
5961 PUSHLOOP(cx, svp, MARK);
5962 cx->blk_loop.iterary = stack;
5963 cx->blk_loop.iterix = MARK - stack_base;
5971 register CONTEXT *cx;
5975 cx = &cxstack[cxstack_ix];
5976 if (cx->cx_type != CXt_LOOP)
5977 DIE("panic: pp_iter");
5979 if (cx->blk_loop.iterix >= cx->blk_oldsp)
5982 if (sv = AvARRAY(cx->blk_loop.iterary)[++cx->blk_loop.iterix]) {
5984 *cx->blk_loop.itervar = sv;
5987 *cx->blk_loop.itervar = &sv_undef;
5995 register CONTEXT *cx;
6002 PUSHBLOCK(cx, CXt_LOOP, SP);
6003 PUSHLOOP(cx, 0, SP);
6011 register CONTEXT *cx;
6019 if (gimme == G_SCALAR) {
6021 *++newsp = sv_mortalcopy(*SP);
6023 *++newsp = &sv_undef;
6027 *++newsp = sv_mortalcopy(*++mark);
6040 register CONTEXT *cx;
6045 if (stack == sortstack) {
6046 AvARRAY(stack)[1] = *SP;
6050 cxix = dopoptosub(cxstack_ix);
6052 DIE("Can't return outside a subroutine");
6053 if (cxix < cxstack_ix)
6057 switch (cx->cx_type) {
6065 DIE("panic: return");
6069 if (gimme == G_SCALAR) {
6071 *++newsp = sv_mortalcopy(*SP);
6073 *++newsp = &sv_undef;
6074 if (optype == OP_REQUIRE && !SvTRUE(*newsp))
6075 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE)), na));
6078 if (optype == OP_REQUIRE && MARK == SP)
6079 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE)), na));
6081 *++newsp = sv_mortalcopy(*++MARK);
6086 return pop_return();
6093 register CONTEXT *cx;
6098 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
6099 /* XXX The sp is probably not right yet... */
6101 if (op->op_flags & OPf_SPECIAL) {
6102 cxix = dopoptoloop(cxstack_ix);
6104 DIE("Can't \"last\" outside a block");
6107 cxix = dopoptolabel(cPVOP->op_pv);
6109 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
6111 if (cxix < cxstack_ix)
6115 switch (cx->cx_type) {
6118 nextop = cx->blk_loop.last_op->op_next;
6123 nextop = pop_return();
6127 nextop = pop_return();
6134 if (gimme == G_SCALAR) {
6136 *++newsp = sv_mortalcopy(*SP);
6138 *++newsp = &sv_undef;
6142 *++newsp = sv_mortalcopy(*++mark);
6154 register CONTEXT *cx;
6157 if (op->op_flags & OPf_SPECIAL) {
6158 cxix = dopoptoloop(cxstack_ix);
6160 DIE("Can't \"next\" outside a block");
6163 cxix = dopoptolabel(cPVOP->op_pv);
6165 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
6167 if (cxix < cxstack_ix)
6171 oldsave = scopestack[scopestack_ix - 1];
6172 LEAVE_SCOPE(oldsave);
6173 return cx->blk_loop.next_op;
6180 register CONTEXT *cx;
6183 if (op->op_flags & OPf_SPECIAL) {
6184 cxix = dopoptoloop(cxstack_ix);
6186 DIE("Can't \"redo\" outside a block");
6189 cxix = dopoptolabel(cPVOP->op_pv);
6191 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
6193 if (cxix < cxstack_ix)
6197 oldsave = scopestack[scopestack_ix - 1];
6198 LEAVE_SCOPE(oldsave);
6199 return cx->blk_loop.redo_op;
6202 static OP* lastgotoprobe;
6205 dofindlabel(op,label,opstack)
6213 if (op->op_type == OP_LEAVE ||
6214 op->op_type == OP_SCOPE ||
6215 op->op_type == OP_LEAVELOOP ||
6216 op->op_type == OP_LEAVETRY)
6217 *ops++ = cUNOP->op_first;
6219 if (op->op_flags & OPf_KIDS) {
6220 /* First try all the kids at this level, since that's likeliest. */
6221 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
6222 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
6223 kCOP->cop_label && strEQ(kCOP->cop_label, label))
6226 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
6227 if (kid == lastgotoprobe)
6229 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
6230 if (ops > opstack &&
6231 (ops[-1]->op_type == OP_NEXTSTATE ||
6232 ops[-1]->op_type == OP_DBSTATE))
6237 if (op = dofindlabel(kid,label,ops))
6247 return pp_goto(ARGS);
6256 register CONTEXT *cx;
6262 if (op->op_flags & OPf_STACKED) {
6265 /* This egregious kludge implements goto &subroutine */
6266 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
6268 register CONTEXT *cx;
6269 CV* cv = (CV*)SvRV(sv);
6274 /* First do some returnish stuff. */
6275 cxix = dopoptosub(cxstack_ix);
6277 DIE("Can't goto subroutine outside a subroutine");
6278 if (cxix < cxstack_ix)
6282 *stack_sp = (SV*)cv;
6283 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
6284 items = AvFILL(cx->blk_sub.argarray) + 1;
6285 Copy(AvARRAY(cx->blk_sub.argarray), ++stack_sp, items, SV*);
6287 GvAV(defgv) = cx->blk_sub.savearray;
6289 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth)) {
6290 if (CvDELETED(cx->blk_sub.cv))
6291 SvREFCNT_dec(cx->blk_sub.cv);
6293 oldsave = scopestack[scopestack_ix - 1];
6294 LEAVE_SCOPE(oldsave);
6296 /* Now do some callish stuff. */
6297 if (CvUSERSUB(cv)) {
6298 items = (*CvUSERSUB(cv))(CvUSERINDEX(cv),
6299 mark - stack_base, items);
6300 sp = stack_base + items;
6302 return pop_return();
6305 AV* padlist = CvPADLIST(cv);
6306 SV** svp = AvARRAY(padlist);
6307 cx->blk_sub.cv = cv;
6308 cx->blk_sub.olddepth = CvDEPTH(cv);
6310 if (CvDEPTH(cv) >= 2) { /* save temporaries on recursion? */
6311 if (CvDEPTH(cv) == 100 && dowarn)
6312 warn("Deep recursion on subroutine \"%s\"",
6314 if (CvDEPTH(cv) > AvFILL(padlist)) {
6315 AV *newpad = newAV();
6316 I32 ix = AvFILL((AV*)svp[1]);
6317 svp = AvARRAY(svp[0]);
6320 char *name = SvPVX(svp[ix]); /* XXX */
6322 av_store(newpad, ix--, (SV*)newAV());
6323 else if (*name == '%')
6324 av_store(newpad, ix--, (SV*)newHV());
6326 av_store(newpad, ix--, NEWSV(0,0));
6329 av_store(newpad, ix--, NEWSV(0,0));
6331 if (cx->blk_sub.hasargs) {
6333 av_store(av, 0, Nullsv);
6334 av_store(newpad, 0, (SV*)av);
6338 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
6339 AvFILL(padlist) = CvDEPTH(cv);
6340 svp = AvARRAY(padlist);
6344 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
6345 if (cx->blk_sub.hasargs) {
6346 AV* av = (AV*)curpad[0];
6349 cx->blk_sub.savearray = GvAV(defgv);
6350 cx->blk_sub.argarray = av;
6351 GvAV(defgv) = cx->blk_sub.argarray;
6354 if (items >= AvMAX(av)) {
6356 if (AvARRAY(av) != ary) {
6357 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
6358 SvPVX(av) = (char*)ary;
6360 if (items >= AvMAX(av)) {
6361 AvMAX(av) = items - 1;
6362 Renew(ary,items+1,SV*);
6364 SvPVX(av) = (char*)ary;
6367 Copy(mark,AvARRAY(av),items,SV*);
6368 AvFILL(av) = items - 1;
6375 RETURNOP(CvSTART(cv));
6379 label = SvPV(sv,na);
6381 else if (op->op_flags & OPf_SPECIAL) {
6382 if (op->op_type != OP_DUMP)
6383 DIE("goto must have label");
6386 label = cPVOP->op_pv;
6388 if (label && *label) {
6395 for (ix = cxstack_ix; ix >= 0; ix--) {
6397 switch (cx->cx_type) {
6399 gotoprobe = CvROOT(cx->blk_sub.cv);
6402 gotoprobe = eval_root; /* XXX not good for nested eval */
6405 gotoprobe = cx->blk_oldcop->op_sibling;
6411 gotoprobe = cx->blk_oldcop->op_sibling;
6413 gotoprobe = main_root;
6419 gotoprobe = main_root;
6422 retop = dofindlabel(gotoprobe, label, enterops);
6425 lastgotoprobe = gotoprobe;
6428 DIE("Can't find label %s", label);
6430 /* pop unwanted frames */
6432 if (ix < cxstack_ix) {
6439 oldsave = scopestack[scopestack_ix - 1];
6440 LEAVE_SCOPE(oldsave);
6443 /* push wanted frames */
6447 for (ix = 0 + (gotoprobe == main_root); enterops[ix]; ix++) {
6455 if (op->op_type == OP_DUMP) {
6461 restartop = 0; /* hmm, must be GNU unexec().. */
6485 double value = SvNVx(GvSV(cCOP->cop_gv));
6486 register I32 match = (I32)value;
6489 if (((double)match) > value)
6490 --match; /* was fractional--truncate other way */
6492 match -= cCOP->uop.scop.scop_offset;
6495 else if (match > cCOP->uop.scop.scop_max)
6496 match = cCOP->uop.scop.scop_max;
6497 op = cCOP->uop.scop.scop_next[match];
6507 op = op->op_next; /* can't assume anything */
6509 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
6510 match -= cCOP->uop.scop.scop_offset;
6513 else if (match > cCOP->uop.scop.scop_max)
6514 match = cCOP->uop.scop.scop_max;
6515 op = cCOP->uop.scop.scop_next[match];
6535 tmps = SvPV(sv, len);
6536 if (do_open(gv, tmps, len)) {
6537 IoLINES(GvIO(gv)) = 0;
6538 PUSHi( (I32)forkprocess );
6540 else if (forkprocess == 0) /* we are a new child */
6557 PUSHs( do_close(gv, TRUE) ? &sv_yes : &sv_no );
6581 do_close(rgv, FALSE);
6583 do_close(wgv, FALSE);
6588 IoIFP(rstio) = fdopen(fd[0], "r");
6589 IoOFP(wstio) = fdopen(fd[1], "w");
6590 IoIFP(wstio) = IoOFP(wstio);
6591 IoTYPE(rstio) = '<';
6592 IoTYPE(wstio) = '>';
6594 if (!IoIFP(rstio) || !IoOFP(wstio)) {
6595 if (IoIFP(rstio)) fclose(IoIFP(rstio));
6597 if (IoOFP(wstio)) fclose(IoOFP(wstio));
6607 DIE(no_func, "pipe");
6620 if (!gv || !(io = GvIO(gv)) || !(fp = IoIFP(io)))
6638 TAINT_PROPER("umask");
6641 DIE(no_func, "Unsupported function umask");
6659 if (!gv || !(io = GvIO(gv)) || !(fp = IoIFP(io)))
6664 if (!fflush(fp) && (fp->_flag |= _IOBIN))
6669 if (setmode(fileno(fp), OP_BINARY) != -1)
6687 SV **mark = stack_base + *markstack_ptr + 1; /* reuse in entersubr */
6691 stash = fetch_stash(mark[1], FALSE);
6692 if (!stash || !(gv = gv_fetchmethod(stash, "new")) || !GvCV(gv))
6693 DIE("Can't tie to package %s", SvPV(mark[1],na));
6695 Zero(&myop, 1, BINOP);
6696 myop.op_last = (OP *) &myop;
6697 myop.op_next = Nullop;
6698 myop.op_flags = OPf_STACKED;
6707 if (op = pp_entersubr())
6712 if (SvTYPE(varsv) == SVt_PVHV || SvTYPE(varsv) == SVt_PVAV)
6713 sv_magic(varsv, sv, 'P', 0, 0);
6715 sv_magic(varsv, sv, 'p', 0, -1);
6724 if (SvTYPE(TOPs) == SVt_PVHV || SvTYPE(TOPs) == SVt_PVAV)
6725 sv_unmagic(TOPs, 'P');
6727 sv_unmagic(TOPs, 'p');
6743 sv = sv_mortalcopy(&sv_no);
6744 sv_setpv(sv, "Any_DBM_File");
6745 stash = fetch_stash(sv, FALSE);
6746 if (!stash || !(gv = gv_fetchmethod(stash, "new")) || !GvCV(gv))
6747 DIE("No dbm on this machine");
6749 Zero(&myop, 1, BINOP);
6750 myop.op_last = (OP *) &myop;
6751 myop.op_next = Nullop;
6752 myop.op_flags = OPf_STACKED;
6765 PUSHs(sv_2mortal(newSViv(O_RDWR|O_CREAT)));
6767 PUSHs(sv_2mortal(newSViv(O_RDWR)));
6771 if (op = pp_entersubr())
6777 sv_magic((SV*)hv, sv, 'P', 0, 0);
6783 return pp_untie(ARGS);
6797 struct timeval timebuf;
6798 struct timeval *tbuf = &timebuf;
6801 #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
6806 # if BYTEORDER & 0xf0000
6807 # define ORDERBYTE (0x88888888 - BYTEORDER)
6809 # define ORDERBYTE (0x4444 - BYTEORDER)
6815 for (i = 1; i <= 3; i++) {
6823 #if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
6824 growsize = maxlen; /* little endians can use vecs directly */
6832 masksize = NFDBITS / NBBY;
6834 masksize = sizeof(long); /* documented int, everyone seems to use long */
6836 growsize = maxlen + (masksize - (maxlen % masksize));
6837 Zero(&fd_sets[0], 4, char*);
6845 timebuf.tv_sec = (long)value;
6846 value -= (double)timebuf.tv_sec;
6847 timebuf.tv_usec = (long)(value * 1000000.0);
6850 tbuf = Null(struct timeval*);
6852 for (i = 1; i <= 3; i++) {
6860 Sv_Grow(sv, growsize);
6861 s = SvPV(sv, na) + j;
6862 while (++j <= growsize) {
6866 #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
6868 New(403, fd_sets[i], growsize, char);
6869 for (offset = 0; offset < growsize; offset += masksize) {
6870 for (j = 0, k=ORDERBYTE; j < masksize; j++, (k >>= 4))
6871 fd_sets[i][j+offset] = s[(k % masksize) + offset];
6874 fd_sets[i] = SvPVX(sv);
6884 #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
6885 for (i = 1; i <= 3; i++) {
6889 for (offset = 0; offset < growsize; offset += masksize) {
6890 for (j = 0, k=ORDERBYTE; j < masksize; j++, (k >>= 4))
6891 s[(k % masksize) + offset] = fd_sets[i][j+offset];
6893 Safefree(fd_sets[i]);
6899 if (GIMME == G_ARRAY && tbuf) {
6900 value = (double)(timebuf.tv_sec) +
6901 (double)(timebuf.tv_usec) / 1000000.0;
6902 PUSHs(sv = sv_mortalcopy(&sv_no));
6903 sv_setnv(sv, value);
6907 DIE("select not implemented");
6914 GV *oldgv = defoutgv;
6915 if (op->op_private > 0) {
6916 defoutgv = (GV*)POPs;
6917 if (!GvIO(defoutgv))
6918 GvIO(defoutgv) = newIO();
6919 curoutgv = defoutgv;
6921 gv_efullname(TARG, oldgv);
6937 if (!gv || do_eof(gv)) /* make sure we have fp with something */
6940 sv_setpv(TARG, " ");
6941 *SvPVX(TARG) = getc(IoIFP(GvIO(gv))); /* should never be EOF */
6948 return pp_sysread(ARGS);
6957 register CONTEXT *cx;
6963 PUSHBLOCK(cx, CXt_SUB, stack_sp);
6965 defoutgv = gv; /* locally select filehandle so $% et al work */
7000 SV *tmpstr = sv_newmortal();
7001 gv_efullname(tmpstr, gv);
7002 DIE("Undefined format \"%s\" called",SvPVX(tmpstr));
7004 DIE("Not a format reference");
7007 return doform(cv,gv,op->op_next);
7013 GV *gv = cxstack[cxstack_ix].blk_sub.gv;
7014 register IO *io = GvIO(gv);
7015 FILE *ofp = IoOFP(io);
7020 register CONTEXT *cx;
7022 DEBUG_f(fprintf(stderr,"left=%ld, todo=%ld\n",
7023 (long)IoLINES_LEFT(io), (long)FmLINES(formtarget)));
7024 if (IoLINES_LEFT(io) < FmLINES(formtarget) &&
7025 formtarget != toptarget)
7027 if (!IoTOP_GV(io)) {
7031 if (!IoTOP_NAME(io)) {
7032 if (!IoFMT_NAME(io))
7033 IoFMT_NAME(io) = savestr(GvNAME(gv));
7034 sprintf(tmpbuf, "%s_TOP", IoFMT_NAME(io));
7035 topgv = gv_fetchpv(tmpbuf,FALSE);
7036 if (topgv && GvFORM(topgv))
7037 IoTOP_NAME(io) = savestr(tmpbuf);
7039 IoTOP_NAME(io) = savestr("top");
7041 topgv = gv_fetchpv(IoTOP_NAME(io),FALSE);
7042 if (!topgv || !GvFORM(topgv)) {
7043 IoLINES_LEFT(io) = 100000000;
7046 IoTOP_GV(io) = topgv;
7048 if (IoLINES_LEFT(io) >= 0 && IoPAGE(io) > 0)
7049 fwrite(SvPVX(formfeed), SvCUR(formfeed), 1, ofp);
7050 IoLINES_LEFT(io) = IoPAGE_LEN(io);
7052 formtarget = toptarget;
7053 return doform(GvFORM(IoTOP_GV(io)),gv,op);
7065 warn("Filehandle only opened for input");
7067 warn("Write on closed filehandle");
7072 if ((IoLINES_LEFT(io) -= FmLINES(formtarget)) < 0) {
7074 warn("page overflow");
7076 if (!fwrite(SvPVX(formtarget), 1, SvCUR(formtarget), ofp) ||
7080 FmLINES(formtarget) = 0;
7081 SvCUR_set(formtarget, 0);
7082 if (IoFLAGS(io) & IOf_FLUSH)
7087 formtarget = bodytarget;
7089 return pop_return();
7094 dSP; dMARK; dORIGMARK;
7098 SV *sv = NEWSV(0,0);
7100 if (op->op_flags & OPf_STACKED)
7104 if (!(io = GvIO(gv))) {
7106 warn("Filehandle never opened");
7110 else if (!(fp = IoOFP(io))) {
7113 warn("Filehandle opened only for input");
7115 warn("printf on closed filehandle");
7121 do_sprintf(sv, SP - MARK, MARK + 1);
7122 if (!do_print(sv, fp))
7125 if (IoFLAGS(io) & IOf_FLUSH)
7126 if (fflush(fp) == EOF)
7143 dSP; dMARK; dORIGMARK;
7148 if (op->op_flags & OPf_STACKED)
7152 if (!(io = GvIO(gv))) {
7154 warn("Filehandle never opened");
7158 else if (!(fp = IoOFP(io))) {
7161 warn("Filehandle opened only for input");
7163 warn("print on closed filehandle");
7171 while (MARK <= SP) {
7172 if (!do_print(*MARK, fp))
7176 if (fwrite(ofs, 1, ofslen, fp) == 0 || ferror(fp)) {
7184 while (MARK <= SP) {
7185 if (!do_print(*MARK, fp))
7194 if (fwrite(ors, 1, orslen, fp) == 0 || ferror(fp))
7197 if (IoFLAGS(io) & IOf_FLUSH)
7198 if (fflush(fp) == EOF)
7214 dSP; dMARK; dORIGMARK; dTARGET;
7228 buffer = SvPV(bufstr, blen);
7229 length = SvIVx(*++MARK);
7230 if (SvTHINKFIRST(bufstr)) {
7231 if (SvREADONLY(bufstr) && curcop != &compiling)
7238 offset = SvIVx(*++MARK);
7242 warn("Too many args on read");
7244 if (!io || !IoIFP(io))
7247 if (op->op_type == OP_RECV) {
7248 bufsize = sizeof buf;
7249 SvGROW(bufstr, length+1), (buffer = SvPV(bufstr, blen)); /* sneaky */
7250 length = recvfrom(fileno(IoIFP(io)), buffer, length, offset,
7254 SvCUR_set(bufstr, length);
7255 *SvEND(bufstr) = '\0';
7258 sv_setpvn(TARG, buf, bufsize);
7263 if (op->op_type == OP_RECV)
7264 DIE(no_sock_func, "recv");
7266 SvGROW(bufstr, length+offset+1), (buffer = SvPV(bufstr, blen)); /* sneaky */
7267 if (op->op_type == OP_SYSREAD) {
7268 length = read(fileno(IoIFP(io)), buffer+offset, length);
7272 if (IoTYPE(io) == 's') {
7273 bufsize = sizeof buf;
7274 length = recvfrom(fileno(IoIFP(io)), buffer+offset, length, 0,
7279 length = fread(buffer+offset, 1, length, IoIFP(io));
7282 SvCUR_set(bufstr, length+offset);
7283 *SvEND(bufstr) = '\0';
7296 return pp_send(ARGS);
7301 dSP; dMARK; dORIGMARK; dTARGET;
7314 buffer = SvPV(bufstr, blen);
7315 length = SvIVx(*++MARK);
7318 if (!io || !IoIFP(io)) {
7321 if (op->op_type == OP_SYSWRITE)
7322 warn("Syswrite on closed filehandle");
7324 warn("Send on closed socket");
7327 else if (op->op_type == OP_SYSWRITE) {
7329 offset = SvIVx(*++MARK);
7333 warn("Too many args on syswrite");
7334 length = write(fileno(IoIFP(io)), buffer+offset, length);
7337 else if (SP >= MARK) {
7340 warn("Too many args on send");
7341 buffer = SvPVx(*++MARK, mlen);
7342 length = sendto(fileno(IoIFP(io)), buffer, blen, length, buffer, mlen);
7345 length = send(fileno(IoIFP(io)), buffer, blen, length);
7348 DIE(no_sock_func, "send");
7363 return pp_sysread(ARGS);
7374 gv = last_in_gv = (GV*)POPs;
7375 PUSHs(!gv || do_eof(gv) ? &sv_yes : &sv_no);
7387 gv = last_in_gv = (GV*)POPs;
7388 PUSHi( do_tell(gv) );
7399 gv = last_in_gv = (GV*)POPs;
7400 PUSHs( do_seek(gv, offset, whence) ? &sv_yes : &sv_no );
7407 off_t len = (off_t)POPn;
7412 #if defined(HAS_TRUNCATE) || defined(HAS_CHSIZE)
7414 if (op->op_flags & OPf_SPECIAL) {
7415 tmpgv = gv_fetchpv(POPp,FALSE);
7416 if (!tmpgv || !GvIO(tmpgv) || !IoIFP(GvIO(tmpgv)) ||
7417 ftruncate(fileno(IoIFP(GvIO(tmpgv))), len) < 0)
7420 else if (truncate(POPp, len) < 0)
7423 if (op->op_flags & OPf_SPECIAL) {
7424 tmpgv = gv_fetchpv(POPp,FALSE);
7425 if (!tmpgv || !GvIO(tmpgv) || !IoIFP(GvIO(tmpgv)) ||
7426 chsize(fileno(IoIFP(GvIO(tmpgv))), len) < 0)
7432 if ((tmpfd = open(POPp, 0)) < 0)
7435 if (chsize(tmpfd, len) < 0)
7448 DIE("truncate not implemented");
7454 return pp_ioctl(ARGS);
7461 unsigned int func = U_I(POPn);
7462 int optype = op->op_type;
7468 if (!io || !argstr || !IoIFP(io)) {
7469 errno = EBADF; /* well, sort of... */
7473 if (SvPOK(argstr) || !SvNIOK(argstr)) {
7476 s = SvPV(argstr, len);
7477 retval = IOCPARM_LEN(func);
7479 Sv_Grow(argstr, retval+1);
7480 SvCUR_set(argstr, retval);
7484 s[SvCUR(argstr)] = 17; /* a little sanity check here */
7487 retval = SvIV(argstr);
7489 s = (char*)(long)retval; /* ouch */
7491 s = (char*)retval; /* ouch */
7495 TAINT_PROPER(optype == OP_IOCTL ? "ioctl" : "fcntl");
7497 if (optype == OP_IOCTL)
7498 retval = ioctl(fileno(IoIFP(io)), func, s);
7501 DIE("fcntl is not implemented");
7504 retval = fcntl(fileno(IoIFP(io)), func, s);
7506 DIE("fcntl is not implemented");
7510 if (SvPOK(argstr)) {
7511 if (s[SvCUR(argstr)] != 17)
7512 DIE("Possible memory corruption: %s overflowed 3rd argument",
7514 s[SvCUR(argstr)] = 0; /* put our null back */
7523 PUSHp("0 but true", 10);
7542 fp = IoIFP(GvIO(gv));
7546 value = (I32)(flock(fileno(fp), argtype) >= 0);
7553 DIE(no_func, "flock()");
7565 int protocol = POPi;
7579 do_close(gv, FALSE);
7581 TAINT_PROPER("socket");
7582 fd = socket(domain, type, protocol);
7585 IoIFP(io) = fdopen(fd, "r"); /* stdio gets confused about sockets */
7586 IoOFP(io) = fdopen(fd, "w");
7588 if (!IoIFP(io) || !IoOFP(io)) {
7589 if (IoIFP(io)) fclose(IoIFP(io));
7590 if (IoOFP(io)) fclose(IoOFP(io));
7591 if (!IoIFP(io) && !IoOFP(io)) close(fd);
7597 DIE(no_sock_func, "socket");
7604 #ifdef HAS_SOCKETPAIR
7609 int protocol = POPi;
7622 do_close(gv1, FALSE);
7624 do_close(gv2, FALSE);
7626 TAINT_PROPER("socketpair");
7627 if (socketpair(domain, type, protocol, fd) < 0)
7629 IoIFP(io1) = fdopen(fd[0], "r");
7630 IoOFP(io1) = fdopen(fd[0], "w");
7632 IoIFP(io2) = fdopen(fd[1], "r");
7633 IoOFP(io2) = fdopen(fd[1], "w");
7635 if (!IoIFP(io1) || !IoOFP(io1) || !IoIFP(io2) || !IoOFP(io2)) {
7636 if (IoIFP(io1)) fclose(IoIFP(io1));
7637 if (IoOFP(io1)) fclose(IoOFP(io1));
7638 if (!IoIFP(io1) && !IoOFP(io1)) close(fd[0]);
7639 if (IoIFP(io2)) fclose(IoIFP(io2));
7640 if (IoOFP(io2)) fclose(IoOFP(io2));
7641 if (!IoIFP(io2) && !IoOFP(io2)) close(fd[1]);
7647 DIE(no_sock_func, "socketpair");
7658 register IO *io = GvIOn(gv);
7661 if (!io || !IoIFP(io))
7664 addr = SvPV(addrstr, len);
7665 TAINT_PROPER("bind");
7666 if (bind(fileno(IoIFP(io)), addr, len) >= 0)
7673 warn("bind() on closed fd");
7677 DIE(no_sock_func, "bind");
7688 register IO *io = GvIOn(gv);
7691 if (!io || !IoIFP(io))
7694 addr = SvPV(addrstr, len);
7695 TAINT_PROPER("connect");
7696 if (connect(fileno(IoIFP(io)), addr, len) >= 0)
7703 warn("connect() on closed fd");
7707 DIE(no_sock_func, "connect");
7717 register IO *io = GvIOn(gv);
7719 if (!io || !IoIFP(io))
7722 if (listen(fileno(IoIFP(io)), backlog) >= 0)
7729 warn("listen() on closed fd");
7733 DIE(no_sock_func, "listen");
7745 int len = sizeof buf;
7757 if (!gstio || !IoIFP(gstio))
7762 do_close(ngv, FALSE);
7764 fd = accept(fileno(IoIFP(gstio)), (struct sockaddr *)buf, &len);
7767 IoIFP(nstio) = fdopen(fd, "r");
7768 IoOFP(nstio) = fdopen(fd, "w");
7769 IoTYPE(nstio) = 's';
7770 if (!IoIFP(nstio) || !IoOFP(nstio)) {
7771 if (IoIFP(nstio)) fclose(IoIFP(nstio));
7772 if (IoOFP(nstio)) fclose(IoOFP(nstio));
7773 if (!IoIFP(nstio) && !IoOFP(nstio)) close(fd);
7782 warn("accept() on closed fd");
7789 DIE(no_sock_func, "accept");
7799 register IO *io = GvIOn(gv);
7801 if (!io || !IoIFP(io))
7804 PUSHi( shutdown(fileno(IoIFP(io)), how) >= 0 );
7809 warn("shutdown() on closed fd");
7813 DIE(no_sock_func, "shutdown");
7820 return pp_ssockopt(ARGS);
7822 DIE(no_sock_func, "getsockopt");
7830 int optype = op->op_type;
7833 unsigned int optname;
7838 if (optype == OP_GSOCKOPT)
7839 sv = sv_2mortal(NEWSV(22, 257));
7842 optname = (unsigned int) POPi;
7843 lvl = (unsigned int) POPi;
7847 if (!io || !IoIFP(io))
7850 fd = fileno(IoIFP(io));
7855 if (getsockopt(fd, lvl, optname, SvPVX(sv), (int*)&SvCUR(sv)) < 0)
7860 if (setsockopt(fd, lvl, optname, SvPVX(sv), SvCUR(sv)) < 0)
7869 warn("[gs]etsockopt() on closed fd");
7875 DIE(no_sock_func, "setsockopt");
7882 return pp_getpeername(ARGS);
7884 DIE(no_sock_func, "getsockname");
7892 int optype = op->op_type;
7896 register IO *io = GvIOn(gv);
7898 if (!io || !IoIFP(io))
7901 sv = sv_2mortal(NEWSV(22, 257));
7904 fd = fileno(IoIFP(io));
7906 case OP_GETSOCKNAME:
7907 if (getsockname(fd, SvPVX(sv), (int*)&SvCUR(sv)) < 0)
7910 case OP_GETPEERNAME:
7911 if (getpeername(fd, SvPVX(sv), (int*)&SvCUR(sv)) < 0)
7920 warn("get{sock, peer}name() on closed fd");
7926 DIE(no_sock_func, "getpeername");
7934 return pp_stat(ARGS);
7943 if (op->op_flags & OPf_SPECIAL) {
7944 tmpgv = cGVOP->op_gv;
7945 if (tmpgv != defgv) {
7946 laststype = OP_STAT;
7948 sv_setpv(statname, "");
7949 if (!GvIO(tmpgv) || !IoIFP(GvIO(tmpgv)) ||
7950 fstat(fileno(IoIFP(GvIO(tmpgv))), &statcache) < 0) {
7955 else if (laststatval < 0)
7959 sv_setpv(statname, POPp);
7962 laststype = op->op_type;
7963 if (op->op_type == OP_LSTAT)
7964 laststatval = lstat(SvPV(statname, na), &statcache);
7967 laststatval = stat(SvPV(statname, na), &statcache);
7968 if (laststatval < 0) {
7969 if (dowarn && strchr(SvPV(statname, na), '\n'))
7970 warn(warn_nl, "stat");
7976 if (GIMME != G_ARRAY) {
7983 PUSHs(sv_2mortal(newSViv((I32)statcache.st_dev)));
7984 PUSHs(sv_2mortal(newSViv((I32)statcache.st_ino)));
7985 PUSHs(sv_2mortal(newSViv((I32)statcache.st_mode)));
7986 PUSHs(sv_2mortal(newSViv((I32)statcache.st_nlink)));
7987 PUSHs(sv_2mortal(newSViv((I32)statcache.st_uid)));
7988 PUSHs(sv_2mortal(newSViv((I32)statcache.st_gid)));
7989 PUSHs(sv_2mortal(newSViv((I32)statcache.st_rdev)));
7990 PUSHs(sv_2mortal(newSViv((I32)statcache.st_size)));
7991 PUSHs(sv_2mortal(newSViv((I32)statcache.st_atime)));
7992 PUSHs(sv_2mortal(newSViv((I32)statcache.st_mtime)));
7993 PUSHs(sv_2mortal(newSViv((I32)statcache.st_ctime)));
7995 PUSHs(sv_2mortal(newSViv((I32)statcache.st_blksize)));
7996 PUSHs(sv_2mortal(newSViv((I32)statcache.st_blocks)));
7998 PUSHs(sv_2mortal(newSVpv("", 0)));
7999 PUSHs(sv_2mortal(newSVpv("", 0)));
8007 I32 result = my_stat(ARGS);
8011 if (cando(S_IRUSR, 0, &statcache))
8018 I32 result = my_stat(ARGS);
8022 if (cando(S_IWUSR, 0, &statcache))
8029 I32 result = my_stat(ARGS);
8033 if (cando(S_IXUSR, 0, &statcache))
8040 I32 result = my_stat(ARGS);
8044 if (cando(S_IRUSR, 1, &statcache))
8051 I32 result = my_stat(ARGS);
8055 if (cando(S_IWUSR, 1, &statcache))
8062 I32 result = my_stat(ARGS);
8066 if (cando(S_IXUSR, 1, &statcache))
8073 I32 result = my_stat(ARGS);
8082 return pp_ftrowned(ARGS);
8087 I32 result = my_stat(ARGS);
8091 if (statcache.st_uid == (op->op_type == OP_FTEOWNED ? euid : uid) )
8098 I32 result = my_stat(ARGS);
8102 if (!statcache.st_size)
8109 I32 result = my_stat(ARGS);
8113 PUSHi(statcache.st_size);
8119 I32 result = my_stat(ARGS);
8123 PUSHn( (basetime - statcache.st_mtime) / 86400.0 );
8129 I32 result = my_stat(ARGS);
8133 PUSHn( (basetime - statcache.st_atime) / 86400.0 );
8139 I32 result = my_stat(ARGS);
8143 PUSHn( (basetime - statcache.st_ctime) / 86400.0 );
8149 I32 result = my_stat(ARGS);
8153 if (S_ISSOCK(statcache.st_mode))
8160 I32 result = my_stat(ARGS);
8164 if (S_ISCHR(statcache.st_mode))
8171 I32 result = my_stat(ARGS);
8175 if (S_ISBLK(statcache.st_mode))
8182 I32 result = my_stat(ARGS);
8186 if (S_ISREG(statcache.st_mode))
8193 I32 result = my_stat(ARGS);
8197 if (S_ISDIR(statcache.st_mode))
8204 I32 result = my_stat(ARGS);
8208 if (S_ISFIFO(statcache.st_mode))
8215 I32 result = my_lstat(ARGS);
8219 if (S_ISLNK(statcache.st_mode))
8228 I32 result = my_stat(ARGS);
8232 if (statcache.st_mode & S_ISUID)
8242 I32 result = my_stat(ARGS);
8246 if (statcache.st_mode & S_ISGID)
8256 I32 result = my_stat(ARGS);
8260 if (statcache.st_mode & S_ISVTX)
8272 if (op->op_flags & OPf_SPECIAL) {
8277 gv = gv_fetchpv(tmps = POPp, FALSE);
8278 if (gv && GvIO(gv) && IoIFP(GvIO(gv)))
8279 fd = fileno(IoIFP(GvIO(gv)));
8280 else if (isDIGIT(*tmps))
8296 register STDCHAR *s;
8300 if (op->op_flags & OPf_SPECIAL) {
8302 if (cGVOP->op_gv == defgv) {
8307 goto really_filename;
8311 statgv = cGVOP->op_gv;
8312 sv_setpv(statname, "");
8315 if (io && IoIFP(io)) {
8316 #if defined(STDSTDIO) || defined(atarist) /* this will work with atariST */
8317 fstat(fileno(IoIFP(io)), &statcache);
8318 if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */
8319 if (op->op_type == OP_FTTEXT)
8323 if (IoIFP(io)->_cnt <= 0) {
8324 i = getc(IoIFP(io));
8326 (void)ungetc(i, IoIFP(io));
8328 if (IoIFP(io)->_cnt <= 0) /* null file is anything */
8330 len = IoIFP(io)->_cnt + (IoIFP(io)->_ptr - IoIFP(io)->_base);
8331 s = IoIFP(io)->_base;
8333 DIE("-T and -B not implemented on filehandles");
8338 warn("Test on unopened file <%s>",
8339 GvENAME(cGVOP->op_gv));
8347 sv_setpv(statname, SvPV(sv, na));
8349 i = open(SvPV(sv, na), 0);
8351 if (dowarn && strchr(SvPV(sv, na), '\n'))
8352 warn(warn_nl, "open");
8355 fstat(i, &statcache);
8356 len = read(i, tbuf, 512);
8359 if (S_ISDIR(statcache.st_mode) && op->op_type == OP_FTTEXT)
8360 RETPUSHNO; /* special case NFS directories */
8361 RETPUSHYES; /* null file is anything */
8366 /* now scan s to look for textiness */
8368 for (i = 0; i < len; i++, s++) {
8369 if (!*s) { /* null never allowed in text */
8376 *s != '\n' && *s != '\r' && *s != '\b' &&
8377 *s != '\t' && *s != '\f' && *s != 27)
8381 if ((odd * 10 > len) == (op->op_type == OP_FTTEXT)) /* allow 10% odd */
8389 return pp_fttext(ARGS);
8405 if (!tmps || !*tmps) {
8406 svp = hv_fetch(GvHVn(envgv), "HOME", 4, FALSE);
8408 tmps = SvPV(*svp, na);
8410 if (!tmps || !*tmps) {
8411 svp = hv_fetch(GvHVn(envgv), "LOGDIR", 6, FALSE);
8413 tmps = SvPV(*svp, na);
8415 TAINT_PROPER("chdir");
8416 PUSHi( chdir(tmps) >= 0 );
8422 dSP; dMARK; dTARGET;
8425 value = (I32)apply(op->op_type, MARK, SP);
8430 DIE(no_func, "Unsupported function chown");
8440 tmps = SvPVx(GvSV(defgv), na);
8443 TAINT_PROPER("chroot");
8444 PUSHi( chroot(tmps) >= 0 );
8447 DIE(no_func, "chroot");
8453 dSP; dMARK; dTARGET;
8455 value = (I32)apply(op->op_type, MARK, SP);
8463 dSP; dMARK; dTARGET;
8465 value = (I32)apply(op->op_type, MARK, SP);
8473 dSP; dMARK; dTARGET;
8475 value = (I32)apply(op->op_type, MARK, SP);
8487 char *tmps = SvPV(TOPs, na);
8488 TAINT_PROPER("rename");
8490 anum = rename(tmps, tmps2);
8492 if (same_dirent(tmps2, tmps)) /* can always rename to same name */
8495 if (euid || stat(tmps2, &statbuf) < 0 || !S_ISDIR(statbuf.st_mode))
8496 (void)UNLINK(tmps2);
8497 if (!(anum = link(tmps, tmps2)))
8498 anum = UNLINK(tmps);
8510 char *tmps = SvPV(TOPs, na);
8511 TAINT_PROPER("link");
8512 SETi( link(tmps, tmps2) >= 0 );
8514 DIE(no_func, "Unsupported function link");
8524 char *tmps = SvPV(TOPs, na);
8525 TAINT_PROPER("symlink");
8526 SETi( symlink(tmps, tmps2) >= 0 );
8529 DIE(no_func, "symlink");
8540 tmps = SvPVx(GvSV(defgv), na);
8543 len = readlink(tmps, buf, sizeof buf);
8551 RETSETUNDEF; /* just pretend it's a normal file */
8555 #if !defined(HAS_MKDIR) || !defined(HAS_RMDIR)
8557 dooneliner(cmd, filename)
8568 for (s = mybuf+strlen(mybuf); *filename; ) {
8573 myfp = my_popen(mybuf, "r");
8576 s = fgets(mybuf, sizeof mybuf, myfp);
8577 (void)my_pclose(myfp);
8579 for (errno = 1; errno < sys_nerr; errno++) {
8580 if (instr(mybuf, sys_errlist[errno])) /* you don't see this */
8585 #define EACCES EPERM
8587 if (instr(mybuf, "cannot make"))
8589 else if (instr(mybuf, "existing file"))
8591 else if (instr(mybuf, "ile exists"))
8593 else if (instr(mybuf, "non-exist"))
8595 else if (instr(mybuf, "does not exist"))
8597 else if (instr(mybuf, "not empty"))
8599 else if (instr(mybuf, "cannot access"))
8605 else { /* some mkdirs return no failure indication */
8606 tmps = SvPVx(st[1], na);
8607 anum = (stat(tmps, &statbuf) >= 0);
8608 if (op->op_type == OP_RMDIR)
8613 errno = EACCES; /* a guess */
8627 char *tmps = SvPV(TOPs, na);
8629 TAINT_PROPER("mkdir");
8631 SETi( mkdir(tmps, mode) >= 0 );
8633 SETi( dooneliner("mkdir", tmps) );
8636 chmod(tmps, (mode & ~oldumask) & 0777);
8647 tmps = SvPVx(GvSV(defgv), na);
8650 TAINT_PROPER("rmdir");
8652 XPUSHi( rmdir(tmps) >= 0 );
8654 XPUSHi( dooneliner("rmdir", tmps) );
8659 /* Directory calls. */
8664 #if defined(DIRENT) && defined(HAS_READDIR)
8665 char *dirname = POPp;
8667 register IO *io = GvIOn(gv);
8673 closedir(IoDIRP(io));
8674 if (!(IoDIRP(io) = opendir(dirname)))
8683 DIE(no_dir_func, "opendir");
8690 #if defined(DIRENT) && defined(HAS_READDIR)
8692 struct DIRENT *readdir();
8694 register struct DIRENT *dp;
8696 register IO *io = GvIOn(gv);
8698 if (!io || !IoDIRP(io))
8701 if (GIMME == G_ARRAY) {
8703 while (dp = readdir(IoDIRP(io))) {
8705 XPUSHs(sv_2mortal(newSVpv(dp->d_name, dp->d_namlen)));
8707 XPUSHs(sv_2mortal(newSVpv(dp->d_name, 0)));
8712 if (!(dp = readdir(IoDIRP(io))))
8715 XPUSHs(sv_2mortal(newSVpv(dp->d_name, dp->d_namlen)));
8717 XPUSHs(sv_2mortal(newSVpv(dp->d_name, 0)));
8725 if (GIMME == G_ARRAY)
8730 DIE(no_dir_func, "readdir");
8737 #if defined(HAS_TELLDIR) || defined(telldir)
8742 register IO *io = GvIOn(gv);
8744 if (!io || !IoDIRP(io))
8747 PUSHi( telldir(IoDIRP(io)) );
8754 DIE(no_dir_func, "telldir");
8761 #if defined(HAS_SEEKDIR) || defined(seekdir)
8764 register IO *io = GvIOn(gv);
8766 if (!io || !IoDIRP(io))
8769 (void)seekdir(IoDIRP(io), along);
8777 DIE(no_dir_func, "seekdir");
8784 #if defined(HAS_REWINDDIR) || defined(rewinddir)
8786 register IO *io = GvIOn(gv);
8788 if (!io || !IoDIRP(io))
8791 (void)rewinddir(IoDIRP(io));
8798 DIE(no_dir_func, "rewinddir");
8805 #if defined(DIRENT) && defined(HAS_READDIR)
8807 register IO *io = GvIOn(gv);
8809 if (!io || !IoDIRP(io))
8812 if (closedir(IoDIRP(io)) < 0)
8822 DIE(no_dir_func, "closedir");
8826 /* Process control. */
8841 if (tmpgv = gv_fetchpv("$", TRUE))
8842 sv_setiv(GvSV(tmpgv), (I32)getpid());
8843 hv_clear(pidstatus); /* no kids, so don't wait for 'em */
8848 DIE(no_func, "Unsupported function fork");
8861 childpid = wait(&argflags);
8863 pidgone(childpid, argflags);
8864 value = (I32)childpid;
8865 statusvalue = (U16)argflags;
8869 DIE(no_func, "Unsupported function wait");
8884 childpid = wait4pid(childpid, &argflags, optype);
8885 value = (I32)childpid;
8886 statusvalue = (U16)argflags;
8890 DIE(no_func, "Unsupported function wait");
8896 dSP; dMARK; dORIGMARK; dTARGET;
8901 VOIDRET (*ihand)(); /* place to save signal during system() */
8902 VOIDRET (*qhand)(); /* place to save signal during system() */
8905 if (SP - MARK == 1) {
8907 char *junk = SvPV(TOPs, na);
8909 TAINT_PROPER("system");
8912 while ((childpid = vfork()) == -1) {
8913 if (errno != EAGAIN) {
8922 ihand = signal(SIGINT, SIG_IGN);
8923 qhand = signal(SIGQUIT, SIG_IGN);
8924 result = wait4pid(childpid, &status, 0);
8925 (void)signal(SIGINT, ihand);
8926 (void)signal(SIGQUIT, qhand);
8927 statusvalue = (U16)status;
8931 value = (I32)((unsigned int)status & 0xffff);
8933 do_execfree(); /* free any memory child malloced on vfork */
8938 if (op->op_flags & OPf_STACKED) {
8939 SV *really = *++MARK;
8940 value = (I32)do_aexec(really, MARK, SP);
8942 else if (SP - MARK != 1)
8943 value = (I32)do_aexec(Nullsv, MARK, SP);
8945 value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
8949 if ((op[1].op_type & A_MASK) == A_GV)
8950 value = (I32)do_aspawn(st[1], arglast);
8951 else if (arglast[2] - arglast[1] != 1)
8952 value = (I32)do_aspawn(Nullsv, arglast);
8954 value = (I32)do_spawn(SvPVx(sv_mortalcopy(st[2]), na));
8963 dSP; dMARK; dORIGMARK; dTARGET;
8966 if (op->op_flags & OPf_STACKED) {
8967 SV *really = *++MARK;
8968 value = (I32)do_aexec(really, MARK, SP);
8970 else if (SP - MARK != 1)
8971 value = (I32)do_aexec(Nullsv, MARK, SP);
8974 char *junk = SvPV(*SP, na);
8976 TAINT_PROPER("exec");
8978 value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
8987 dSP; dMARK; dTARGET;
8990 value = (I32)apply(op->op_type, MARK, SP);
8995 DIE(no_func, "Unsupported function kill");
9003 XPUSHi( getppid() );
9006 DIE(no_func, "getppid");
9021 #ifdef _POSIX_SOURCE
9023 DIE("POSIX getpgrp can't take an argument");
9024 value = (I32)getpgrp();
9026 value = (I32)getpgrp(pid);
9031 DIE(no_func, "getpgrp()");
9042 TAINT_PROPER("setpgrp");
9043 SETi( setpgrp(pid, pgrp) >= 0 );
9046 DIE(no_func, "setpgrp()");
9055 #ifdef HAS_GETPRIORITY
9058 SETi( getpriority(which, who) );
9061 DIE(no_func, "getpriority()");
9071 #ifdef HAS_SETPRIORITY
9075 TAINT_PROPER("setpriority");
9076 SETi( setpriority(which, who, niceval) >= 0 );
9079 DIE(no_func, "setpriority()");
9088 XPUSHi( time(Null(long*)) );
9101 DIE("times not implemented");
9105 (void)times(×buf);
9107 PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_utime)/HZ)));
9108 if (GIMME == G_ARRAY) {
9109 PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_stime)/HZ)));
9110 PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_cutime)/HZ)));
9111 PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_cstime)/HZ)));
9119 return pp_gmtime(ARGS);
9127 static char *dayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
9128 static char *monname[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
9129 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
9134 when = (time_t)SvIVx(POPs);
9136 if (op->op_type == OP_LOCALTIME)
9137 tmbuf = localtime(&when);
9139 tmbuf = gmtime(&when);
9142 if (GIMME != G_ARRAY) {
9147 sprintf(mybuf, "%s %s %2d %02d:%02d:%02d %d",
9148 dayname[tmbuf->tm_wday],
9149 monname[tmbuf->tm_mon],
9154 tmbuf->tm_year + 1900);
9155 PUSHp(mybuf, strlen(mybuf));
9158 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_sec)));
9159 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_min)));
9160 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_hour)));
9161 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_mday)));
9162 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_mon)));
9163 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_year)));
9164 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_wday)));
9165 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_yday)));
9166 PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_isdst)));
9177 anum = SvIVx(GvSV(defgv));
9180 anum = alarm((unsigned int)anum);
9187 DIE(no_func, "Unsupported function alarm");
9200 (void)time(&lasttime);
9205 sleep((unsigned int)duration);
9208 XPUSHi(when - lasttime);
9212 /* Shared memory. */
9216 return pp_semget(ARGS);
9221 return pp_semctl(ARGS);
9226 return pp_shmwrite(ARGS);
9231 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9232 dSP; dMARK; dTARGET;
9233 I32 value = (I32)(do_shmio(op->op_type, MARK, SP) >= 0);
9242 /* Message passing. */
9246 return pp_semget(ARGS);
9251 return pp_semctl(ARGS);
9256 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9257 dSP; dMARK; dTARGET;
9258 I32 value = (I32)(do_msgsnd(MARK, SP) >= 0);
9269 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9270 dSP; dMARK; dTARGET;
9271 I32 value = (I32)(do_msgrcv(MARK, SP) >= 0);
9284 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9285 dSP; dMARK; dTARGET;
9286 int anum = do_ipcget(op->op_type, MARK, SP);
9293 DIE("System V IPC is not implemented on this machine");
9299 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9300 dSP; dMARK; dTARGET;
9301 int anum = do_ipcctl(op->op_type, MARK, SP);
9309 PUSHp("0 but true",10);
9319 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
9320 dSP; dMARK; dTARGET;
9321 I32 value = (I32)(do_semop(MARK, SP) >= 0);
9333 save_lines(array, sv)
9337 register char *s = SvPVX(sv);
9338 register char *send = SvPVX(sv) + SvCUR(sv);
9340 register I32 line = 1;
9342 while (s && s < send) {
9343 SV *tmpstr = NEWSV(85,0);
9345 sv_upgrade(tmpstr, SVt_PVMG);
9346 t = strchr(s, '\n');
9352 sv_setpvn(tmpstr, s, t - s);
9353 av_store(array, line++, tmpstr);
9367 /* set up a scratch pad */
9372 SAVESPTR(comppad_name);
9373 SAVEINT(comppad_name_fill);
9374 SAVEINT(min_intro_pending);
9375 SAVEINT(max_intro_pending);
9377 comppad_name = newAV();
9378 comppad_name_fill = 0;
9379 min_intro_pending = 0;
9380 av_push(comppad, Nullsv);
9381 curpad = AvARRAY(comppad);
9384 /* make sure we compile in the right package */
9386 newstash = curcop->cop_stash;
9387 if (curstash != newstash) {
9389 curstash = newstash;
9394 /* try to compile it */
9398 curcop = &compiling;
9403 if (yyparse() || error_count || !eval_root) {
9419 if (optype == OP_REQUIRE)
9420 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE)), na));
9424 rspara = (nrslen == 2);
9430 rspara = (nrslen == 2);
9431 compiling.cop_line = 0;
9432 SAVEFREESV(comppad_name);
9433 SAVEFREESV(comppad);
9434 SAVEFREEOP(eval_root);
9436 DEBUG_x(dump_eval());
9438 /* compiled okay, so do it */
9440 sv_setpv(GvSV(gv_fetchpv("@",TRUE)),"");
9441 RETURNOP(eval_start);
9447 register CONTEXT *cx;
9452 I32 gimme = G_SCALAR;
9461 if (SvNIOK(sv) && !SvPOKp(sv)) {
9462 if (SvNV(sv) > atof(patchlevel) + 0.000999)
9463 DIE("Perl %3.3f required--this is only version %s, stopped",
9464 SvNV(sv),patchlevel);
9467 name = SvPV(sv, na);
9468 if (op->op_type == OP_REQUIRE &&
9469 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
9473 /* prepare to compile file */
9475 tmpname = savestr(name);
9476 if (*tmpname == '/' ||
9478 (tmpname[1] == '/' ||
9479 (tmpname[1] == '.' && tmpname[2] == '/'))))
9481 tryrsfp = fopen(tmpname,"r");
9484 AV *ar = GvAVn(incgv);
9487 for (i = 0; i <= AvFILL(ar); i++) {
9488 (void)sprintf(buf, "%s/%s",
9489 SvPVx(*av_fetch(ar, i, TRUE), na), name);
9490 tryrsfp = fopen(buf, "r");
9494 if (*s == '.' && s[1] == '/')
9497 tmpname = savestr(s);
9502 compiling.cop_filegv = gv_fetchfile(tmpname);
9506 if (op->op_type == OP_REQUIRE) {
9507 sprintf(tokenbuf,"Can't locate %s in @INC", name);
9508 if (instr(tokenbuf,".h "))
9509 strcat(tokenbuf," (change .h to .ph maybe?)");
9510 if (instr(tokenbuf,".ph "))
9511 strcat(tokenbuf," (did you run h2ph?)");
9520 lex_start(sv_2mortal(newSVpv("",0)));
9522 name = savestr(name);
9525 /* switch to eval mode */
9527 push_return(op->op_next);
9528 PUSHBLOCK(cx, CXt_EVAL, SP);
9529 PUSHEVAL(cx, name, compiling.cop_filegv);
9531 compiling.cop_line = 0;
9539 return pp_require(ARGS);
9545 register CONTEXT *cx;
9554 /* switch to eval mode */
9556 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
9557 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
9558 compiling.cop_line = 1;
9559 SAVEDELETE(defstash, savestr(tmpbuf), strlen(tmpbuf));
9561 push_return(op->op_next);
9562 PUSHBLOCK(cx, CXt_EVAL, SP);
9563 PUSHEVAL(cx, 0, compiling.cop_filegv);
9565 /* prepare to compile string */
9567 if (perldb && curstash != debstash)
9568 save_lines(GvAV(compiling.cop_filegv), linestr);
9579 register CONTEXT *cx;
9582 OP *eroot = eval_root;
9586 retop = pop_return();
9588 if (gimme == G_SCALAR) {
9591 if (SvFLAGS(TOPs) & SVs_TEMP)
9594 *MARK = sv_mortalcopy(TOPs);
9603 for (mark = newsp + 1; mark <= SP; mark++)
9604 if (!(SvFLAGS(TOPs) & SVs_TEMP))
9605 *mark = sv_mortalcopy(*mark);
9606 /* in case LEAVE wipes old return values */
9609 if (optype != OP_ENTEREVAL) {
9610 char *name = cx->blk_eval.old_name;
9612 if (gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp) {
9613 (void)hv_store(GvHVn(incgv), name,
9614 strlen(name), newSVsv(GvSV(curcop->cop_filegv)), 0 );
9616 else if (optype == OP_REQUIRE)
9617 retop = die("%s did not return a true value", name);
9622 sv_setpv(GvSV(gv_fetchpv("@",TRUE)),"");
9631 SP = do_eval(st[1], OP_EVAL, curcop->cop_stash, TRUE,
9634 SvREFCNT_dec(cSVOP->op_sv);
9635 op[1].arg_ptr.arg_cmd = eval_root;
9636 op[1].op_type = (A_CMD|A_DONT);
9637 op[0].op_type = OP_TRY;
9648 register CONTEXT *cx;
9654 push_return(cLOGOP->op_other->op_next);
9655 PUSHBLOCK(cx, CXt_EVAL, SP);
9657 eval_root = op; /* Only needed so that goto works right. */
9660 sv_setpv(GvSV(gv_fetchpv("@",TRUE)),"");
9670 register CONTEXT *cx;
9677 if (gimme == G_SCALAR) {
9680 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
9683 *MARK = sv_mortalcopy(TOPs);
9692 for (mark = newsp + 1; mark <= SP; mark++)
9693 if (!(SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP)))
9694 *mark = sv_mortalcopy(*mark);
9695 /* in case LEAVE wipes old return values */
9699 sv_setpv(GvSV(gv_fetchpv("@",TRUE)),"");
9703 /* Get system info. */
9708 return pp_ghostent(ARGS);
9710 DIE(no_sock_func, "gethostbyname");
9717 return pp_ghostent(ARGS);
9719 DIE(no_sock_func, "gethostbyaddr");
9727 I32 which = op->op_type;
9728 register char **elem;
9730 struct hostent *gethostbyname();
9731 struct hostent *gethostbyaddr();
9732 #ifdef HAS_GETHOSTENT
9733 struct hostent *gethostent();
9735 struct hostent *hent;
9739 if (which == OP_GHBYNAME) {
9740 hent = gethostbyname(POPp);
9742 else if (which == OP_GHBYADDR) {
9743 int addrtype = POPi;
9745 char *addr = SvPV(addrstr, na);
9747 hent = gethostbyaddr(addr, SvCUR(addrstr), addrtype);
9750 #ifdef HAS_GETHOSTENT
9751 hent = gethostent();
9753 DIE("gethostent not implemented");
9756 #ifdef HOST_NOT_FOUND
9758 statusvalue = (U16)h_errno & 0xffff;
9761 if (GIMME != G_ARRAY) {
9762 PUSHs(sv = sv_newmortal());
9764 if (which == OP_GHBYNAME) {
9765 sv_setpvn(sv, hent->h_addr, hent->h_length);
9768 sv_setpv(sv, hent->h_name);
9774 PUSHs(sv = sv_mortalcopy(&sv_no));
9775 sv_setpv(sv, hent->h_name);
9776 PUSHs(sv = sv_mortalcopy(&sv_no));
9777 for (elem = hent->h_aliases; *elem; elem++) {
9778 sv_catpv(sv, *elem);
9780 sv_catpvn(sv, " ", 1);
9782 PUSHs(sv = sv_mortalcopy(&sv_no));
9783 sv_setiv(sv, (I32)hent->h_addrtype);
9784 PUSHs(sv = sv_mortalcopy(&sv_no));
9785 len = hent->h_length;
9786 sv_setiv(sv, (I32)len);
9788 for (elem = hent->h_addr_list; *elem; elem++) {
9789 XPUSHs(sv = sv_mortalcopy(&sv_no));
9790 sv_setpvn(sv, *elem, len);
9793 PUSHs(sv = sv_mortalcopy(&sv_no));
9794 sv_setpvn(sv, hent->h_addr, len);
9799 DIE(no_sock_func, "gethostent");
9806 return pp_gnetent(ARGS);
9808 DIE(no_sock_func, "getnetbyname");
9815 return pp_gnetent(ARGS);
9817 DIE(no_sock_func, "getnetbyaddr");
9825 I32 which = op->op_type;
9826 register char **elem;
9828 struct netent *getnetbyname();
9829 struct netent *getnetbyaddr();
9830 struct netent *getnetent();
9831 struct netent *nent;
9833 if (which == OP_GNBYNAME)
9834 nent = getnetbyname(POPp);
9835 else if (which == OP_GNBYADDR) {
9836 int addrtype = POPi;
9837 unsigned long addr = U_L(POPn);
9838 nent = getnetbyaddr((long)addr, addrtype);
9844 if (GIMME != G_ARRAY) {
9845 PUSHs(sv = sv_newmortal());
9847 if (which == OP_GNBYNAME)
9848 sv_setiv(sv, (I32)nent->n_net);
9850 sv_setpv(sv, nent->n_name);
9856 PUSHs(sv = sv_mortalcopy(&sv_no));
9857 sv_setpv(sv, nent->n_name);
9858 PUSHs(sv = sv_mortalcopy(&sv_no));
9859 for (elem = nent->n_aliases; *elem; elem++) {
9860 sv_catpv(sv, *elem);
9862 sv_catpvn(sv, " ", 1);
9864 PUSHs(sv = sv_mortalcopy(&sv_no));
9865 sv_setiv(sv, (I32)nent->n_addrtype);
9866 PUSHs(sv = sv_mortalcopy(&sv_no));
9867 sv_setiv(sv, (I32)nent->n_net);
9872 DIE(no_sock_func, "getnetent");
9879 return pp_gprotoent(ARGS);
9881 DIE(no_sock_func, "getprotobyname");
9888 return pp_gprotoent(ARGS);
9890 DIE(no_sock_func, "getprotobynumber");
9898 I32 which = op->op_type;
9899 register char **elem;
9901 struct protoent *getprotobyname();
9902 struct protoent *getprotobynumber();
9903 struct protoent *getprotoent();
9904 struct protoent *pent;
9906 if (which == OP_GPBYNAME)
9907 pent = getprotobyname(POPp);
9908 else if (which == OP_GPBYNUMBER)
9909 pent = getprotobynumber(POPi);
9911 pent = getprotoent();
9914 if (GIMME != G_ARRAY) {
9915 PUSHs(sv = sv_newmortal());
9917 if (which == OP_GPBYNAME)
9918 sv_setiv(sv, (I32)pent->p_proto);
9920 sv_setpv(sv, pent->p_name);
9926 PUSHs(sv = sv_mortalcopy(&sv_no));
9927 sv_setpv(sv, pent->p_name);
9928 PUSHs(sv = sv_mortalcopy(&sv_no));
9929 for (elem = pent->p_aliases; *elem; elem++) {
9930 sv_catpv(sv, *elem);
9932 sv_catpvn(sv, " ", 1);
9934 PUSHs(sv = sv_mortalcopy(&sv_no));
9935 sv_setiv(sv, (I32)pent->p_proto);
9940 DIE(no_sock_func, "getprotoent");
9947 return pp_gservent(ARGS);
9949 DIE(no_sock_func, "getservbyname");
9956 return pp_gservent(ARGS);
9958 DIE(no_sock_func, "getservbyport");
9966 I32 which = op->op_type;
9967 register char **elem;
9969 struct servent *getservbyname();
9970 struct servent *getservbynumber();
9971 struct servent *getservent();
9972 struct servent *sent;
9974 if (which == OP_GSBYNAME) {
9978 if (proto && !*proto)
9981 sent = getservbyname(name, proto);
9983 else if (which == OP_GSBYPORT) {
9987 sent = getservbyport(port, proto);
9990 sent = getservent();
9993 if (GIMME != G_ARRAY) {
9994 PUSHs(sv = sv_newmortal());
9996 if (which == OP_GSBYNAME) {
9998 sv_setiv(sv, (I32)ntohs(sent->s_port));
10000 sv_setiv(sv, (I32)(sent->s_port));
10004 sv_setpv(sv, sent->s_name);
10010 PUSHs(sv = sv_mortalcopy(&sv_no));
10011 sv_setpv(sv, sent->s_name);
10012 PUSHs(sv = sv_mortalcopy(&sv_no));
10013 for (elem = sent->s_aliases; *elem; elem++) {
10014 sv_catpv(sv, *elem);
10016 sv_catpvn(sv, " ", 1);
10018 PUSHs(sv = sv_mortalcopy(&sv_no));
10020 sv_setiv(sv, (I32)ntohs(sent->s_port));
10022 sv_setiv(sv, (I32)(sent->s_port));
10024 PUSHs(sv = sv_mortalcopy(&sv_no));
10025 sv_setpv(sv, sent->s_proto);
10030 DIE(no_sock_func, "getservent");
10041 DIE(no_sock_func, "sethostent");
10052 DIE(no_sock_func, "setnetent");
10063 DIE(no_sock_func, "setprotoent");
10074 DIE(no_sock_func, "setservent");
10086 DIE(no_sock_func, "endhostent");
10098 DIE(no_sock_func, "endnetent");
10110 DIE(no_sock_func, "endprotoent");
10122 DIE(no_sock_func, "endservent");
10129 return pp_gpwent(ARGS);
10131 DIE(no_func, "getpwnam");
10138 return pp_gpwent(ARGS);
10140 DIE(no_func, "getpwuid");
10148 I32 which = op->op_type;
10149 register AV *ary = stack;
10151 struct passwd *getpwnam();
10152 struct passwd *getpwuid();
10153 struct passwd *getpwent();
10154 struct passwd *pwent;
10156 if (which == OP_GPWNAM)
10157 pwent = getpwnam(POPp);
10158 else if (which == OP_GPWUID)
10159 pwent = getpwuid(POPi);
10161 pwent = getpwent();
10164 if (GIMME != G_ARRAY) {
10165 PUSHs(sv = sv_newmortal());
10167 if (which == OP_GPWNAM)
10168 sv_setiv(sv, (I32)pwent->pw_uid);
10170 sv_setpv(sv, pwent->pw_name);
10176 PUSHs(sv = sv_mortalcopy(&sv_no));
10177 sv_setpv(sv, pwent->pw_name);
10178 PUSHs(sv = sv_mortalcopy(&sv_no));
10179 sv_setpv(sv, pwent->pw_passwd);
10180 PUSHs(sv = sv_mortalcopy(&sv_no));
10181 sv_setiv(sv, (I32)pwent->pw_uid);
10182 PUSHs(sv = sv_mortalcopy(&sv_no));
10183 sv_setiv(sv, (I32)pwent->pw_gid);
10184 PUSHs(sv = sv_mortalcopy(&sv_no));
10186 sv_setiv(sv, (I32)pwent->pw_change);
10189 sv_setiv(sv, (I32)pwent->pw_quota);
10192 sv_setpv(sv, pwent->pw_age);
10196 PUSHs(sv = sv_mortalcopy(&sv_no));
10198 sv_setpv(sv, pwent->pw_class);
10201 sv_setpv(sv, pwent->pw_comment);
10204 PUSHs(sv = sv_mortalcopy(&sv_no));
10205 sv_setpv(sv, pwent->pw_gecos);
10206 PUSHs(sv = sv_mortalcopy(&sv_no));
10207 sv_setpv(sv, pwent->pw_dir);
10208 PUSHs(sv = sv_mortalcopy(&sv_no));
10209 sv_setpv(sv, pwent->pw_shell);
10211 PUSHs(sv = sv_mortalcopy(&sv_no));
10212 sv_setiv(sv, (I32)pwent->pw_expire);
10217 DIE(no_func, "getpwent");
10228 DIE(no_func, "setpwent");
10239 DIE(no_func, "endpwent");
10246 return pp_ggrent(ARGS);
10248 DIE(no_func, "getgrnam");
10255 return pp_ggrent(ARGS);
10257 DIE(no_func, "getgrgid");
10265 I32 which = op->op_type;
10266 register char **elem;
10268 struct group *getgrnam();
10269 struct group *getgrgid();
10270 struct group *getgrent();
10271 struct group *grent;
10273 if (which == OP_GGRNAM)
10274 grent = getgrnam(POPp);
10275 else if (which == OP_GGRGID)
10276 grent = getgrgid(POPi);
10278 grent = getgrent();
10281 if (GIMME != G_ARRAY) {
10282 PUSHs(sv = sv_newmortal());
10284 if (which == OP_GGRNAM)
10285 sv_setiv(sv, (I32)grent->gr_gid);
10287 sv_setpv(sv, grent->gr_name);
10293 PUSHs(sv = sv_mortalcopy(&sv_no));
10294 sv_setpv(sv, grent->gr_name);
10295 PUSHs(sv = sv_mortalcopy(&sv_no));
10296 sv_setpv(sv, grent->gr_passwd);
10297 PUSHs(sv = sv_mortalcopy(&sv_no));
10298 sv_setiv(sv, (I32)grent->gr_gid);
10299 PUSHs(sv = sv_mortalcopy(&sv_no));
10300 for (elem = grent->gr_mem; *elem; elem++) {
10301 sv_catpv(sv, *elem);
10303 sv_catpvn(sv, " ", 1);
10309 DIE(no_func, "getgrent");
10320 DIE(no_func, "setgrent");
10331 DIE(no_func, "endgrent");
10338 #ifdef HAS_GETLOGIN
10341 if (!(tmps = getlogin()))
10343 PUSHp(tmps, strlen(tmps));
10346 DIE(no_func, "getlogin");
10350 /* Miscellaneous. */
10355 dSP; dMARK; dORIGMARK; dTARGET;
10356 register I32 items = SP - MARK;
10357 unsigned long a[20];
10358 register I32 i = 0;
10362 while (++MARK <= SP) {
10363 if (SvRMAGICAL(*MARK) && mg_find(*MARK, 't'))
10367 TAINT_PROPER("syscall");
10370 /* This probably won't work on machines where sizeof(long) != sizeof(int)
10371 * or where sizeof(long) != sizeof(char*). But such machines will
10372 * not likely have syscall implemented either, so who cares?
10374 while (++MARK <= SP) {
10375 if (SvNIOK(*MARK) || !i)
10376 a[i++] = SvIV(*MARK);
10378 a[i++] = (unsigned long)SvPVX(*MARK);
10384 DIE("Too many args to syscall");
10386 DIE("Too few args to syscall");
10388 retval = syscall(a[0]);
10391 retval = syscall(a[0],a[1]);
10394 retval = syscall(a[0],a[1],a[2]);
10397 retval = syscall(a[0],a[1],a[2],a[3]);
10400 retval = syscall(a[0],a[1],a[2],a[3],a[4]);
10403 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5]);
10406 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6]);
10409 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
10413 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]);
10416 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]);
10419 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],
10423 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],
10427 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],
10428 a[10],a[11],a[12]);
10431 retval = syscall(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],
10432 a[10],a[11],a[12],a[13]);
10434 #endif /* atarist */
10440 DIE(no_func, "syscall");