3 * Copyright (c) 1991-1994, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "It's a big house this, and very peculiar. Always a bit more to discover,
12 * and no knowing what you'll find around a corner. And Elves, sir!" --Samwise
18 static void doencodes _((SV *sv, char *s, I32 len));
20 /* variations on pp_null */
25 if (GIMME != G_ARRAY) {
41 if (op->op_private & OPpLVAL_INTRO)
42 SAVECLEARSV(curpad[op->op_targ]);
44 if (op->op_flags & OPf_REF) {
48 if (GIMME == G_ARRAY) {
49 I32 maxarg = AvFILL((AV*)TARG) + 1;
51 Copy(AvARRAY((AV*)TARG), SP+1, maxarg, SV*);
55 SV* sv = sv_newmortal();
56 I32 maxarg = AvFILL((AV*)TARG) + 1;
67 if (op->op_private & OPpLVAL_INTRO)
68 SAVECLEARSV(curpad[op->op_targ]);
69 if (op->op_flags & OPf_REF)
71 if (GIMME == G_ARRAY) { /* array wanted */
72 RETURNOP(do_kv(ARGS));
75 SV* sv = sv_newmortal();
76 if (HvFILL((HV*)TARG)) {
77 sprintf(buf, "%d/%d", HvFILL((HV*)TARG), HvMAX((HV*)TARG)+1);
89 DIE("NOT IMPL LINE %d",__LINE__);
101 if (SvTYPE(sv) != SVt_PVGV)
102 DIE("Not a GLOB reference");
105 if (SvTYPE(sv) != SVt_PVGV) {
108 if (SvGMAGICAL(sv)) {
114 if (op->op_flags & OPf_REF ||
115 op->op_private & HINT_STRICT_REFS)
116 DIE(no_usym, "a symbol");
120 if (op->op_private & HINT_STRICT_REFS)
121 DIE(no_symref, sym, "a symbol");
122 sv = (SV*)gv_fetchpv(sym, TRUE, SVt_PVGV);
125 if (op->op_private & OPpLVAL_INTRO) {
129 SSPUSHPTR(SvREFCNT_inc(sv));
133 if (op->op_flags & OPf_SPECIAL) {
134 GvGP(sv)->gp_refcnt++; /* will soon be assigned */
142 GvSV(sv) = NEWSV(72,0);
143 GvLINE(sv) = curcop->cop_line;
158 switch (SvTYPE(sv)) {
162 DIE("Not a SCALAR reference");
169 if (SvTYPE(gv) != SVt_PVGV) {
170 if (SvGMAGICAL(sv)) {
176 if (op->op_flags & OPf_REF ||
177 op->op_private & HINT_STRICT_REFS)
178 DIE(no_usym, "a SCALAR");
182 if (op->op_private & HINT_STRICT_REFS)
183 DIE(no_symref, sym, "a SCALAR");
184 gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PV);
188 if (op->op_flags & OPf_MOD) {
189 if (op->op_private & OPpLVAL_INTRO)
190 sv = save_scalar((GV*)TOPs);
191 else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV))
202 SV *sv = AvARYLEN(av);
204 AvARYLEN(av) = sv = NEWSV(0,0);
205 sv_upgrade(sv, SVt_IV);
206 sv_magic(sv, (SV*)av, '#', Nullch, 0);
214 dSP; dTARGET; dPOPss;
216 if (op->op_flags & OPf_MOD) {
219 PUSHs(TARG); /* no SvSETMAGIC */
225 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
226 mg = mg_find(sv, 'g');
227 if (mg && mg->mg_len >= 0) {
228 PUSHi(mg->mg_len + curcop->cop_arybase);
242 /* We usually try to add a non-existent subroutine in case of AUTOLOAD. */
243 /* (But not in defined().) */
244 CV *cv = sv_2cv(TOPs, &stash, &gv, !(op->op_flags & OPf_SPECIAL));
261 cv = sv_2cv(TOPs, &stash, &gv, FALSE);
262 if (cv && SvPOK(cv)) {
264 ret = sv_2mortal(newSVpv(p ? p : "", SvLEN(cv)));
273 CV* cv = (CV*)cSVOP->op_sv;
277 cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
288 sv_upgrade(rv, SVt_RV);
293 (void)SvREFCNT_inc(sv);
306 if (GIMME != G_ARRAY) {
313 sv_upgrade(rv, SVt_RV);
318 (void)SvREFCNT_inc(sv);
335 if (sv && SvGMAGICAL(sv))
338 if (!sv || !SvROK(sv))
342 pv = sv_reftype(sv,TRUE);
343 PUSHp(pv, strlen(pv));
353 stash = curcop->cop_stash;
355 stash = gv_stashsv(POPs, TRUE);
357 (void)sv_bless(TOPs, stash);
361 /* Pattern matching */
366 register unsigned char *s;
369 register I32 *sfirst;
374 s = (unsigned char*)(SvPV(sv, len));
376 if (sv == lastscream)
380 SvSCREAM_off(lastscream);
381 SvREFCNT_dec(lastscream);
383 lastscream = SvREFCNT_inc(sv);
389 if (pos > maxscream) {
391 maxscream = pos + 80;
392 New(301, screamfirst, 256, I32);
393 New(302, screamnext, maxscream, I32);
396 maxscream = pos + pos / 4;
397 Renew(screamnext, maxscream, I32);
401 sfirst = screamfirst;
404 if (!sfirst || !snext)
405 DIE("do_study: out of memory");
407 for (ch = 256; ch; --ch)
414 snext[pos] = sfirst[ch] - pos;
419 /* If there were any case insensitive searches, we must assume they
420 * all are. This speeds up insensitive searches much more than
421 * it slows down sensitive ones.
424 sfirst[fold[ch]] = pos;
428 sv_magic(sv, Nullsv, 'g', Nullch, 0); /* piggyback on m//g magic */
431 XPUSHs(sv_2mortal(newSViv((I32)retval)));
440 if (op->op_flags & OPf_STACKED)
446 TARG = sv_newmortal();
447 PUSHi(do_trans(sv, op));
451 /* Lvalue operators. */
473 SETi(do_chomp(TOPs));
480 register I32 count = 0;
483 count += do_chomp(POPs);
494 if (!sv || !SvANY(sv))
496 switch (SvTYPE(sv)) {
498 if (AvMAX(sv) >= 0 || SvRMAGICAL(sv))
502 if (HvARRAY(sv) || SvRMAGICAL(sv))
506 if (CvROOT(sv) || CvXSUB(sv))
530 if (SvTHINKFIRST(sv)) {
537 switch (SvTYPE(sv)) {
552 sv_setsv(sv, &sv_undef);
556 if (SvPOK(sv) && SvLEN(sv)) {
559 SvPV_set(sv, Nullch);
574 SvFLAGS(TOPs) &= ~(SVf_NOK|SVf_POK|SVp_NOK|SVp_POK);
585 sv_setsv(TARG, TOPs);
588 SvFLAGS(TOPs) &= ~(SVf_NOK|SVf_POK|SVp_NOK|SVp_POK);
602 sv_setsv(TARG, TOPs);
605 SvFLAGS(TOPs) &= ~(SVf_NOK|SVf_POK|SVp_NOK|SVp_POK);
614 /* Ordinary operators. */
618 dSP; dATARGET; tryAMAGICbin(pow,opASSIGN);
621 SETn( pow( left, right) );
628 dSP; dATARGET; tryAMAGICbin(mult,opASSIGN);
631 SETn( left * right );
638 dSP; dATARGET; tryAMAGICbin(div,opASSIGN);
642 DIE("Illegal division by zero");
644 /* insure that 20./5. == 4. */
649 if ((double)I_32(x) == x &&
650 (double)I_32(value) == value &&
651 (k = I_32(x)/I_32(value))*I_32(value) == I_32(x)) {
658 value = POPn / value;
667 dSP; dATARGET; tryAMAGICbin(mod,opASSIGN);
669 register unsigned long tmpulong;
670 register long tmplong;
673 tmpulong = (unsigned long) POPn;
675 DIE("Illegal modulus zero");
678 value = (I32)(((unsigned long)value) % tmpulong);
680 tmplong = (long)value;
681 value = (I32)(tmpulong - ((-tmplong - 1) % tmpulong)) - 1;
690 dSP; dATARGET; tryAMAGICbin(repeat,opASSIGN);
692 register I32 count = POPi;
693 if (GIMME == G_ARRAY && op->op_private & OPpREPEAT_DOLIST) {
695 I32 items = SP - MARK;
707 repeatcpy((char*)(MARK + items), (char*)MARK,
708 items * sizeof(SV*), count - 1);
714 else { /* Note: mark already snarfed by pp_list */
719 if (TARG == tmpstr && SvTHINKFIRST(tmpstr)) {
720 if (SvREADONLY(tmpstr) && curcop != &compiling)
721 DIE("Can't x= to readonly value");
725 SvSetSV(TARG, tmpstr);
726 SvPV_force(TARG, len);
728 SvGROW(TARG, (count * len) + 1);
730 repeatcpy(SvPVX(TARG) + len, SvPVX(TARG), len, count - 1);
731 SvCUR(TARG) *= count;
733 (void)SvPOK_only(TARG);
736 sv_setsv(TARG, &sv_no);
745 dSP; dATARGET; tryAMAGICbin(subtr,opASSIGN);
748 SETn( left - right );
755 dSP; dATARGET; tryAMAGICbin(lshift,opASSIGN);
758 SETi( left << right );
765 dSP; dATARGET; tryAMAGICbin(rshift,opASSIGN);
768 SETi( left >> right );
775 dSP; tryAMAGICbinSET(lt,0);
778 SETs((TOPn < value) ? &sv_yes : &sv_no);
785 dSP; tryAMAGICbinSET(gt,0);
788 SETs((TOPn > value) ? &sv_yes : &sv_no);
795 dSP; tryAMAGICbinSET(le,0);
798 SETs((TOPn <= value) ? &sv_yes : &sv_no);
805 dSP; tryAMAGICbinSET(ge,0);
808 SETs((TOPn >= value) ? &sv_yes : &sv_no);
815 dSP; tryAMAGICbinSET(ne,0);
818 SETs((TOPn != value) ? &sv_yes : &sv_no);
825 dSP; dTARGET; tryAMAGICbin(ncmp,0);
832 else if (left < right)
843 dSP; tryAMAGICbinSET(slt,0);
846 SETs( sv_cmp(left, right) < 0 ? &sv_yes : &sv_no );
853 dSP; tryAMAGICbinSET(sgt,0);
856 SETs( sv_cmp(left, right) > 0 ? &sv_yes : &sv_no );
863 dSP; tryAMAGICbinSET(sle,0);
866 SETs( sv_cmp(left, right) <= 0 ? &sv_yes : &sv_no );
873 dSP; tryAMAGICbinSET(sge,0);
876 SETs( sv_cmp(left, right) >= 0 ? &sv_yes : &sv_no );
883 dSP; tryAMAGICbinSET(sne,0);
886 SETs( !sv_eq(left, right) ? &sv_yes : &sv_no );
893 dSP; dTARGET; tryAMAGICbin(scmp,0);
896 SETi( sv_cmp(left, right) );
902 dSP; dATARGET; tryAMAGICbin(band,opASSIGN);
905 if (SvNIOKp(left) || SvNIOKp(right)) {
906 unsigned long value = U_L(SvNV(left));
907 value = value & U_L(SvNV(right));
911 do_vop(op->op_type, TARG, left, right);
920 dSP; dATARGET; tryAMAGICbin(bxor,opASSIGN);
923 if (SvNIOKp(left) || SvNIOKp(right)) {
924 unsigned long value = U_L(SvNV(left));
925 value = value ^ U_L(SvNV(right));
929 do_vop(op->op_type, TARG, left, right);
938 dSP; dATARGET; tryAMAGICbin(bor,opASSIGN);
941 if (SvNIOKp(left) || SvNIOKp(right)) {
942 unsigned long value = U_L(SvNV(left));
943 value = value | U_L(SvNV(right));
947 do_vop(op->op_type, TARG, left, right);
956 dSP; dTARGET; tryAMAGICun(neg);
963 else if (SvPOKp(sv)) {
965 char *s = SvPV(sv, len);
966 if (isALPHA(*s) || *s == '_') {
967 sv_setpvn(TARG, "-", 1);
970 else if (*s == '+' || *s == '-') {
972 *SvPV_force(TARG, len) = *s == '-' ? '+' : '-';
975 sv_setnv(TARG, -SvNV(sv));
987 dSP; tryAMAGICunSET(not);
988 #endif /* OVERLOAD */
989 *stack_sp = SvTRUE(*stack_sp) ? &sv_no : &sv_yes;
995 dSP; dTARGET; tryAMAGICun(compl);
1003 SETn( (double) ~U_L(SvNV(sv)) );
1008 register char *tmps;
1009 register long *tmpl;
1013 tmps = SvPV_force(TARG, len);
1016 for ( ; anum && (unsigned long)tmps % sizeof(long); anum--, tmps++)
1019 for ( ; anum >= sizeof(long); anum -= sizeof(long), tmpl++)
1023 for ( ; anum > 0; anum--, tmps++)
1032 /* integer versions of some of the above */
1036 dSP; dATARGET; tryAMAGICbin(mult,opASSIGN);
1039 SETi( left * right );
1046 dSP; dATARGET; tryAMAGICbin(div,opASSIGN);
1050 DIE("Illegal division by zero");
1051 value = POPi / value;
1059 dSP; dATARGET; tryAMAGICbin(mod,opASSIGN);
1062 SETi( left % right );
1069 dSP; dATARGET; tryAMAGICbin(add,opASSIGN);
1072 SETi( left + right );
1079 dSP; dATARGET; tryAMAGICbin(subtr,opASSIGN);
1082 SETi( left - right );
1089 dSP; tryAMAGICbinSET(lt,0);
1092 SETs((left < right) ? &sv_yes : &sv_no);
1099 dSP; tryAMAGICbinSET(gt,0);
1102 SETs((left > right) ? &sv_yes : &sv_no);
1109 dSP; tryAMAGICbinSET(le,0);
1112 SETs((left <= right) ? &sv_yes : &sv_no);
1119 dSP; tryAMAGICbinSET(ge,0);
1122 SETs((left >= right) ? &sv_yes : &sv_no);
1129 dSP; tryAMAGICbinSET(eq,0);
1132 SETs((left == right) ? &sv_yes : &sv_no);
1139 dSP; tryAMAGICbinSET(ne,0);
1142 SETs((left != right) ? &sv_yes : &sv_no);
1149 dSP; dTARGET; tryAMAGICbin(ncmp,0);
1156 else if (left < right)
1167 dSP; dTARGET; tryAMAGICun(neg);
1172 /* High falutin' math. */
1176 dSP; dTARGET; tryAMAGICbin(atan2,0);
1179 SETn(atan2(left, right));
1186 dSP; dTARGET; tryAMAGICun(sin);
1198 dSP; dTARGET; tryAMAGICun(cos);
1219 value = rand() * value / 2147483648.0;
1222 value = rand() * value / 65536.0;
1225 value = rand() * value / 32768.0;
1227 value = rand() * value / (double)(((unsigned long)1) << RANDBITS);
1242 # include <starlet.h>
1243 unsigned int when[2];
1244 _ckvmssts(sys$gettim(when));
1245 anum = when[0] ^ when[1];
1247 # if defined(I_SYS_TIME) && !defined(PLAN9)
1248 struct timeval when;
1249 gettimeofday(&when,(struct timezone *) 0);
1250 anum = when.tv_sec ^ when.tv_usec;
1257 #if !defined(PLAN9) /* XXX Plan9 assembler chokes on this; fix coming soon */
1258 /* 17-Jul-1996 bailey@genetics.upenn.edu */
1259 /* What is a good hashing algorithm here? */
1260 anum ^= ( ( 269 * (U32)getpid())
1261 ^ (26107 * (U32)&when)
1262 ^ (73819 * (U32)stack_sp));
1274 dSP; dTARGET; tryAMAGICun(exp);
1286 dSP; dTARGET; tryAMAGICun(log);
1291 DIE("Can't take log of %g", value);
1300 dSP; dTARGET; tryAMAGICun(sqrt);
1305 DIE("Can't take sqrt of %g", value);
1306 value = sqrt(value);
1318 (void)modf(value, &value);
1320 (void)modf(-value, &value);
1329 dSP; dTARGET; tryAMAGICun(abs);
1346 unsigned long value;
1350 value = scan_hex(tmps, 99, &argtype);
1361 unsigned long value;
1366 while (*tmps && isSPACE(*tmps))
1371 value = scan_hex(++tmps, 99, &argtype);
1373 value = scan_oct(tmps, 99, &argtype);
1386 SETi( sv_len(TOPs) );
1398 I32 lvalue = op->op_flags & OPf_MOD;
1400 I32 arybase = curcop->cop_arybase;
1404 pos = POPi - arybase;
1406 tmps = SvPV(sv, curlen);
1408 pos += curlen + arybase;
1409 if (pos < 0 || pos > curlen) {
1410 if (dowarn || lvalue)
1411 warn("substr outside of string");
1418 len += curlen - pos;
1423 rem = curlen - pos; /* rem=how many bytes left*/
1426 sv_setpvn(TARG, tmps, rem);
1427 if (lvalue) { /* it's an lvalue! */
1428 if (!SvGMAGICAL(sv))
1429 (void)SvPOK_only(sv);
1430 if (SvTYPE(TARG) < SVt_PVLV) {
1431 sv_upgrade(TARG, SVt_PVLV);
1432 sv_magic(TARG, Nullsv, 'x', Nullch, 0);
1437 LvTARGOFF(TARG) = pos;
1438 LvTARGLEN(TARG) = rem;
1441 PUSHs(TARG); /* avoid SvSETMAGIC here */
1448 register I32 size = POPi;
1449 register I32 offset = POPi;
1450 register SV *src = POPs;
1451 I32 lvalue = op->op_flags & OPf_MOD;
1453 unsigned char *s = (unsigned char*)SvPV(src, srclen);
1454 unsigned long retnum;
1457 offset *= size; /* turn into bit offset */
1458 len = (offset + size + 7) / 8;
1459 if (offset < 0 || size < 1)
1462 if (lvalue) { /* it's an lvalue! */
1463 if (SvTYPE(TARG) < SVt_PVLV) {
1464 sv_upgrade(TARG, SVt_PVLV);
1465 sv_magic(TARG, Nullsv, 'v', Nullch, 0);
1470 LvTARGOFF(TARG) = offset;
1471 LvTARGLEN(TARG) = size;
1479 if (offset >= srclen)
1482 retnum = (unsigned long) s[offset] << 8;
1484 else if (size == 32) {
1485 if (offset >= srclen)
1487 else if (offset + 1 >= srclen)
1488 retnum = (unsigned long) s[offset] << 24;
1489 else if (offset + 2 >= srclen)
1490 retnum = ((unsigned long) s[offset] << 24) +
1491 ((unsigned long) s[offset + 1] << 16);
1493 retnum = ((unsigned long) s[offset] << 24) +
1494 ((unsigned long) s[offset + 1] << 16) +
1495 (s[offset + 2] << 8);
1500 retnum = (s[offset >> 3] >> (offset & 7)) & ((1 << size) - 1);
1505 else if (size == 16)
1506 retnum = ((unsigned long) s[offset] << 8) + s[offset+1];
1507 else if (size == 32)
1508 retnum = ((unsigned long) s[offset] << 24) +
1509 ((unsigned long) s[offset + 1] << 16) +
1510 (s[offset + 2] << 8) + s[offset+3];
1514 sv_setiv(TARG, (I32)retnum);
1529 I32 arybase = curcop->cop_arybase;
1534 offset = POPi - arybase;
1537 tmps = SvPV(big, biglen);
1540 else if (offset > biglen)
1542 if (!(tmps2 = fbm_instr((unsigned char*)tmps + offset,
1543 (unsigned char*)tmps + biglen, little)))
1544 retval = -1 + arybase;
1546 retval = tmps2 - tmps + arybase;
1563 I32 arybase = curcop->cop_arybase;
1569 tmps2 = SvPV(little, llen);
1570 tmps = SvPV(big, blen);
1574 offset = SvIV(offstr) - arybase + llen;
1577 else if (offset > blen)
1579 if (!(tmps2 = rninstr(tmps, tmps + offset,
1580 tmps2, tmps2 + llen)))
1581 retval = -1 + arybase;
1583 retval = tmps2 - tmps + arybase;
1590 dSP; dMARK; dORIGMARK; dTARGET;
1591 do_sprintf(TARG, SP-MARK, MARK+1);
1605 value = (I32) (*tmps & 255);
1610 value = (I32) (anum & 255);
1621 (void)SvUPGRADE(TARG,SVt_PV);
1627 (void)SvPOK_only(TARG);
1634 dSP; dTARGET; dPOPTOPssrl;
1636 char *tmps = SvPV(left, na);
1638 sv_setpv(TARG, fcrypt(tmps, SvPV(right, na)));
1640 sv_setpv(TARG, crypt(tmps, SvPV(right, na)));
1644 "The crypt() function is unimplemented due to excessive paranoia.");
1656 if (!SvPADTMP(sv)) {
1662 s = SvPV_force(sv, na);
1675 if (!SvPADTMP(sv)) {
1681 s = SvPV_force(sv, na);
1694 register char *send;
1697 if (!SvPADTMP(sv)) {
1703 s = SvPV_force(sv, len);
1718 register char *send;
1721 if (!SvPADTMP(sv)) {
1727 s = SvPV_force(sv, len);
1742 register char *s = SvPV(sv,len);
1746 (void)SvUPGRADE(TARG, SVt_PV);
1747 SvGROW(TARG, (len * 2) + 1);
1755 SvCUR_set(TARG, d - SvPVX(TARG));
1756 (void)SvPOK_only(TARG);
1759 sv_setpvn(TARG, s, len);
1768 dSP; dMARK; dORIGMARK;
1770 register AV* av = (AV*)POPs;
1771 register I32 lval = op->op_flags & OPf_MOD;
1772 I32 arybase = curcop->cop_arybase;
1775 if (SvTYPE(av) == SVt_PVAV) {
1776 if (lval && op->op_private & OPpLVAL_INTRO) {
1778 for (svp = mark + 1; svp <= sp; svp++) {
1783 if (max > AvMAX(av))
1786 while (++MARK <= SP) {
1787 elem = SvIVx(*MARK);
1791 svp = av_fetch(av, elem, lval);
1793 if (!svp || *svp == &sv_undef)
1794 DIE(no_aelem, elem);
1795 if (op->op_private & OPpLVAL_INTRO)
1798 *MARK = svp ? *svp : &sv_undef;
1801 if (GIMME != G_ARRAY) {
1809 /* Associative arrays. */
1814 HV *hash = (HV*)POPs;
1818 entry = hv_iternext(hash); /* might clobber stack_sp */
1823 PUSHs(hv_iterkeysv(entry)); /* won't clobber stack_sp */
1824 if (GIMME == G_ARRAY) {
1826 sv_setsv(TARG, hv_iterval(hash, entry)); /* might clobber stack_sp */
1831 else if (GIMME == G_SCALAR)
1854 if (SvTYPE(hv) != SVt_PVHV) {
1855 DIE("Not a HASH reference");
1857 sv = hv_delete_ent(hv, tmpsv,
1858 (op->op_private & OPpLEAVE_VOID ? G_DISCARD : 0), 0);
1871 if (SvTYPE(hv) != SVt_PVHV) {
1872 DIE("Not a HASH reference");
1874 if (hv_exists_ent(hv, tmpsv, 0))
1881 dSP; dMARK; dORIGMARK;
1883 register HV *hv = (HV*)POPs;
1884 register I32 lval = op->op_flags & OPf_MOD;
1886 if (SvTYPE(hv) == SVt_PVHV) {
1887 while (++MARK <= SP) {
1890 he = hv_fetch_ent(hv, keysv, lval, 0);
1892 if (!he || HeVAL(he) == &sv_undef)
1893 DIE(no_helem, SvPV(keysv, na));
1894 if (op->op_private & OPpLVAL_INTRO)
1895 save_svref(&HeVAL(he));
1897 *MARK = he ? HeVAL(he) : &sv_undef;
1900 if (GIMME != G_ARRAY) {
1908 /* List operators. */
1913 if (GIMME != G_ARRAY) {
1915 *MARK = *SP; /* unwanted list, return last item */
1926 SV **lastrelem = stack_sp;
1927 SV **lastlelem = stack_base + POPMARK;
1928 SV **firstlelem = stack_base + POPMARK + 1;
1929 register SV **firstrelem = lastlelem + 1;
1930 I32 arybase = curcop->cop_arybase;
1931 I32 lval = op->op_flags & OPf_MOD;
1932 I32 is_something_there = lval;
1934 register I32 max = lastrelem - lastlelem;
1935 register SV **lelem;
1938 if (GIMME != G_ARRAY) {
1939 ix = SvIVx(*lastlelem);
1944 if (ix < 0 || ix >= max)
1945 *firstlelem = &sv_undef;
1947 *firstlelem = firstrelem[ix];
1953 SP = firstlelem - 1;
1957 for (lelem = firstlelem; lelem <= lastlelem; lelem++) {
1963 else if (!(*lelem = firstrelem[ix]))
1968 if (ix >= max || !(*lelem = firstrelem[ix]))
1971 if (!is_something_there && (SvOKp(*lelem) || SvGMAGICAL(*lelem)))
1972 is_something_there = TRUE;
1974 if (is_something_there)
1977 SP = firstlelem - 1;
1984 I32 items = SP - MARK;
1986 XPUSHs((SV*)sv_2mortal((SV*)av_make(items, MARK+1)));
1992 dSP; dMARK; dORIGMARK;
1994 HV* hv = (HV*)sv_2mortal((SV*)newHV());
1998 SV *val = NEWSV(46, 0);
2000 sv_setsv(val, *++MARK);
2002 warn("Odd number of elements in hash list");
2003 (void)hv_store_ent(hv,key,val,0);
2012 dSP; dMARK; dORIGMARK;
2013 register AV *ary = (AV*)*++MARK;
2017 register I32 offset;
2018 register I32 length;
2027 offset = SvIVx(*MARK);
2029 offset += AvFILL(ary) + 1;
2031 offset -= curcop->cop_arybase;
2033 length = SvIVx(*MARK++);
2038 length = AvMAX(ary) + 1; /* close enough to infinity */
2042 length = AvMAX(ary) + 1;
2050 if (offset > AvFILL(ary) + 1)
2051 offset = AvFILL(ary) + 1;
2052 after = AvFILL(ary) + 1 - (offset + length);
2053 if (after < 0) { /* not that much array */
2054 length += after; /* offset+length now in array */
2060 /* At this point, MARK .. SP-1 is our new LIST */
2063 diff = newlen - length;
2065 if (diff < 0) { /* shrinking the area */
2067 New(451, tmparyval, newlen, SV*); /* so remember insertion */
2068 Copy(MARK, tmparyval, newlen, SV*);
2071 MARK = ORIGMARK + 1;
2072 if (GIMME == G_ARRAY) { /* copy return vals to stack */
2073 MEXTEND(MARK, length);
2074 Copy(AvARRAY(ary)+offset, MARK, length, SV*);
2076 for (i = length, dst = MARK; i; i--)
2077 sv_2mortal(*dst++); /* free them eventualy */
2082 *MARK = AvARRAY(ary)[offset+length-1];
2085 for (i = length - 1, dst = &AvARRAY(ary)[offset]; i > 0; i--)
2086 SvREFCNT_dec(*dst++); /* free them now */
2089 AvFILL(ary) += diff;
2091 /* pull up or down? */
2093 if (offset < after) { /* easier to pull up */
2094 if (offset) { /* esp. if nothing to pull */
2095 src = &AvARRAY(ary)[offset-1];
2096 dst = src - diff; /* diff is negative */
2097 for (i = offset; i > 0; i--) /* can't trust Copy */
2101 SvPVX(ary) = (char*)(AvARRAY(ary) - diff); /* diff is negative */
2105 if (after) { /* anything to pull down? */
2106 src = AvARRAY(ary) + offset + length;
2107 dst = src + diff; /* diff is negative */
2108 Move(src, dst, after, SV*);
2110 dst = &AvARRAY(ary)[AvFILL(ary)+1];
2111 /* avoid later double free */
2115 dst[--i] = &sv_undef;
2118 for (src = tmparyval, dst = AvARRAY(ary) + offset;
2120 *dst = NEWSV(46, 0);
2121 sv_setsv(*dst++, *src++);
2123 Safefree(tmparyval);
2126 else { /* no, expanding (or same) */
2128 New(452, tmparyval, length, SV*); /* so remember deletion */
2129 Copy(AvARRAY(ary)+offset, tmparyval, length, SV*);
2132 if (diff > 0) { /* expanding */
2134 /* push up or down? */
2136 if (offset < after && diff <= AvARRAY(ary) - AvALLOC(ary)) {
2140 Move(src, dst, offset, SV*);
2142 SvPVX(ary) = (char*)(AvARRAY(ary) - diff);/* diff is positive */
2144 AvFILL(ary) += diff;
2147 if (AvFILL(ary) + diff >= AvMAX(ary)) /* oh, well */
2148 av_extend(ary, AvFILL(ary) + diff);
2149 AvFILL(ary) += diff;
2152 dst = AvARRAY(ary) + AvFILL(ary);
2154 for (i = after; i; i--) {
2161 for (src = MARK, dst = AvARRAY(ary) + offset; newlen; newlen--) {
2162 *dst = NEWSV(46, 0);
2163 sv_setsv(*dst++, *src++);
2165 MARK = ORIGMARK + 1;
2166 if (GIMME == G_ARRAY) { /* copy return vals to stack */
2168 Copy(tmparyval, MARK, length, SV*);
2170 for (i = length, dst = MARK; i; i--)
2171 sv_2mortal(*dst++); /* free them eventualy */
2173 Safefree(tmparyval);
2177 else if (length--) {
2178 *MARK = tmparyval[length];
2181 while (length-- > 0)
2182 SvREFCNT_dec(tmparyval[length]);
2184 Safefree(tmparyval);
2195 dSP; dMARK; dORIGMARK; dTARGET;
2196 register AV *ary = (AV*)*++MARK;
2197 register SV *sv = &sv_undef;
2199 for (++MARK; MARK <= SP; MARK++) {
2202 sv_setsv(sv, *MARK);
2206 PUSHi( AvFILL(ary) + 1 );
2214 SV *sv = av_pop(av);
2215 if (sv != &sv_undef && AvREAL(av))
2216 (void)sv_2mortal(sv);
2225 SV *sv = av_shift(av);
2229 if (sv != &sv_undef && AvREAL(av))
2230 (void)sv_2mortal(sv);
2237 dSP; dMARK; dORIGMARK; dTARGET;
2238 register AV *ary = (AV*)*++MARK;
2242 av_unshift(ary, SP - MARK);
2245 sv_setsv(sv, *++MARK);
2246 (void)av_store(ary, i++, sv);
2250 PUSHi( AvFILL(ary) + 1 );
2260 if (GIMME == G_ARRAY) {
2271 register char *down;
2277 do_join(TARG, &sv_no, MARK, SP);
2279 sv_setsv(TARG, *SP);
2280 up = SvPV_force(TARG, len);
2282 down = SvPVX(TARG) + len - 1;
2288 (void)SvPOK_only(TARG);
2296 /* Explosives and implosives. */
2305 register char *pat = SvPV(left, llen);
2306 register char *s = SvPV(right, rlen);
2307 char *strend = s + rlen;
2309 register char *patend = pat + llen;
2314 /* These must not be in registers: */
2325 unsigned Quad_t auquad;
2331 register U32 culong;
2333 static char* bitcount = 0;
2335 if (GIMME != G_ARRAY) { /* arrange to do first one only */
2337 for (patend = pat; !isALPHA(*patend) || *patend == 'x'; patend++) ;
2338 if (strchr("aAbBhHP", *patend) || *pat == '%') {
2340 while (isDIGIT(*patend) || *patend == '*')
2346 while (pat < patend) {
2351 else if (*pat == '*') {
2352 len = strend - strbeg; /* long enough */
2355 else if (isDIGIT(*pat)) {
2357 while (isDIGIT(*pat))
2358 len = (len * 10) + (*pat++ - '0');
2361 len = (datumtype != '@');
2366 if (len == 1 && pat[-1] != '1')
2375 if (len > strend - strbeg)
2376 DIE("@ outside of string");
2380 if (len > s - strbeg)
2381 DIE("X outside of string");
2385 if (len > strend - s)
2386 DIE("x outside of string");
2391 if (len > strend - s)
2394 goto uchar_checksum;
2395 sv = NEWSV(35, len);
2396 sv_setpvn(sv, s, len);
2398 if (datumtype == 'A') {
2399 aptr = s; /* borrow register */
2400 s = SvPVX(sv) + len - 1;
2401 while (s >= SvPVX(sv) && (!*s || isSPACE(*s)))
2404 SvCUR_set(sv, s - SvPVX(sv));
2405 s = aptr; /* unborrow register */
2407 XPUSHs(sv_2mortal(sv));
2411 if (pat[-1] == '*' || len > (strend - s) * 8)
2412 len = (strend - s) * 8;
2415 Newz(601, bitcount, 256, char);
2416 for (bits = 1; bits < 256; bits++) {
2417 if (bits & 1) bitcount[bits]++;
2418 if (bits & 2) bitcount[bits]++;
2419 if (bits & 4) bitcount[bits]++;
2420 if (bits & 8) bitcount[bits]++;
2421 if (bits & 16) bitcount[bits]++;
2422 if (bits & 32) bitcount[bits]++;
2423 if (bits & 64) bitcount[bits]++;
2424 if (bits & 128) bitcount[bits]++;
2428 culong += bitcount[*(unsigned char*)s++];
2433 if (datumtype == 'b') {
2435 if (bits & 1) culong++;
2441 if (bits & 128) culong++;
2448 sv = NEWSV(35, len + 1);
2451 aptr = pat; /* borrow register */
2453 if (datumtype == 'b') {
2455 for (len = 0; len < aint; len++) {
2456 if (len & 7) /*SUPPRESS 595*/
2460 *pat++ = '0' + (bits & 1);
2465 for (len = 0; len < aint; len++) {
2470 *pat++ = '0' + ((bits & 128) != 0);
2474 pat = aptr; /* unborrow register */
2475 XPUSHs(sv_2mortal(sv));
2479 if (pat[-1] == '*' || len > (strend - s) * 2)
2480 len = (strend - s) * 2;
2481 sv = NEWSV(35, len + 1);
2484 aptr = pat; /* borrow register */
2486 if (datumtype == 'h') {
2488 for (len = 0; len < aint; len++) {
2493 *pat++ = hexdigit[bits & 15];
2498 for (len = 0; len < aint; len++) {
2503 *pat++ = hexdigit[(bits >> 4) & 15];
2507 pat = aptr; /* unborrow register */
2508 XPUSHs(sv_2mortal(sv));
2511 if (len > strend - s)
2516 if (aint >= 128) /* fake up signed chars */
2525 if (aint >= 128) /* fake up signed chars */
2528 sv_setiv(sv, (I32)aint);
2529 PUSHs(sv_2mortal(sv));
2534 if (len > strend - s)
2548 sv_setiv(sv, (I32)auint);
2549 PUSHs(sv_2mortal(sv));
2554 along = (strend - s) / sizeof(I16);
2559 Copy(s, &ashort, 1, I16);
2567 Copy(s, &ashort, 1, I16);
2570 sv_setiv(sv, (I32)ashort);
2571 PUSHs(sv_2mortal(sv));
2578 along = (strend - s) / sizeof(U16);
2583 Copy(s, &aushort, 1, U16);
2586 if (datumtype == 'n')
2587 aushort = ntohs(aushort);
2590 if (datumtype == 'v')
2591 aushort = vtohs(aushort);
2599 Copy(s, &aushort, 1, U16);
2603 if (datumtype == 'n')
2604 aushort = ntohs(aushort);
2607 if (datumtype == 'v')
2608 aushort = vtohs(aushort);
2610 sv_setiv(sv, (I32)aushort);
2611 PUSHs(sv_2mortal(sv));
2616 along = (strend - s) / sizeof(int);
2621 Copy(s, &aint, 1, int);
2624 cdouble += (double)aint;
2632 Copy(s, &aint, 1, int);
2635 sv_setiv(sv, (I32)aint);
2636 PUSHs(sv_2mortal(sv));
2641 along = (strend - s) / sizeof(unsigned int);
2646 Copy(s, &auint, 1, unsigned int);
2647 s += sizeof(unsigned int);
2649 cdouble += (double)auint;
2657 Copy(s, &auint, 1, unsigned int);
2658 s += sizeof(unsigned int);
2660 sv_setiv(sv, (I32)auint);
2661 PUSHs(sv_2mortal(sv));
2666 along = (strend - s) / sizeof(I32);
2671 Copy(s, &along, 1, I32);
2674 cdouble += (double)along;
2682 Copy(s, &along, 1, I32);
2685 sv_setiv(sv, (I32)along);
2686 PUSHs(sv_2mortal(sv));
2693 along = (strend - s) / sizeof(U32);
2698 Copy(s, &aulong, 1, U32);
2701 if (datumtype == 'N')
2702 aulong = ntohl(aulong);
2705 if (datumtype == 'V')
2706 aulong = vtohl(aulong);
2709 cdouble += (double)aulong;
2717 Copy(s, &aulong, 1, U32);
2721 if (datumtype == 'N')
2722 aulong = ntohl(aulong);
2725 if (datumtype == 'V')
2726 aulong = vtohl(aulong);
2728 sv_setnv(sv, (double)aulong);
2729 PUSHs(sv_2mortal(sv));
2734 along = (strend - s) / sizeof(char*);
2739 if (sizeof(char*) > strend - s)
2742 Copy(s, &aptr, 1, char*);
2748 PUSHs(sv_2mortal(sv));
2753 if (sizeof(char*) > strend - s)
2756 Copy(s, &aptr, 1, char*);
2761 sv_setpvn(sv, aptr, len);
2762 PUSHs(sv_2mortal(sv));
2768 if (s + sizeof(Quad_t) > strend)
2771 Copy(s, &aquad, 1, Quad_t);
2772 s += sizeof(Quad_t);
2775 sv_setiv(sv, (IV)aquad);
2776 PUSHs(sv_2mortal(sv));
2782 if (s + sizeof(unsigned Quad_t) > strend)
2785 Copy(s, &auquad, 1, unsigned Quad_t);
2786 s += sizeof(unsigned Quad_t);
2789 sv_setiv(sv, (IV)auquad);
2790 PUSHs(sv_2mortal(sv));
2794 /* float and double added gnb@melba.bby.oz.au 22/11/89 */
2797 along = (strend - s) / sizeof(float);
2802 Copy(s, &afloat, 1, float);
2810 Copy(s, &afloat, 1, float);
2813 sv_setnv(sv, (double)afloat);
2814 PUSHs(sv_2mortal(sv));
2820 along = (strend - s) / sizeof(double);
2825 Copy(s, &adouble, 1, double);
2826 s += sizeof(double);
2833 Copy(s, &adouble, 1, double);
2834 s += sizeof(double);
2836 sv_setnv(sv, (double)adouble);
2837 PUSHs(sv_2mortal(sv));
2842 along = (strend - s) * 3 / 4;
2843 sv = NEWSV(42, along);
2846 while (s < strend && *s > ' ' && *s < 'a') {
2851 len = (*s++ - ' ') & 077;
2853 if (s < strend && *s >= ' ')
2854 a = (*s++ - ' ') & 077;
2857 if (s < strend && *s >= ' ')
2858 b = (*s++ - ' ') & 077;
2861 if (s < strend && *s >= ' ')
2862 c = (*s++ - ' ') & 077;
2865 if (s < strend && *s >= ' ')
2866 d = (*s++ - ' ') & 077;
2869 hunk[0] = a << 2 | b >> 4;
2870 hunk[1] = b << 4 | c >> 2;
2871 hunk[2] = c << 6 | d;
2872 sv_catpvn(sv, hunk, len > 3 ? 3 : len);
2877 else if (s[1] == '\n') /* possible checksum byte */
2880 XPUSHs(sv_2mortal(sv));
2885 if (strchr("fFdD", datumtype) ||
2886 (checksum > 32 && strchr("iIlLN", datumtype)) ) {
2890 while (checksum >= 16) {
2894 while (checksum >= 4) {
2900 along = (1 << checksum) - 1;
2901 while (cdouble < 0.0)
2903 cdouble = modf(cdouble / adouble, &trouble) * adouble;
2904 sv_setnv(sv, cdouble);
2907 if (checksum < 32) {
2908 along = (1 << checksum) - 1;
2909 culong &= (U32)along;
2911 sv_setnv(sv, (double)culong);
2913 XPUSHs(sv_2mortal(sv));
2921 doencodes(sv, s, len)
2929 sv_catpvn(sv, hunk, 1);
2932 hunk[0] = ' ' + (077 & (*s >> 2));
2933 hunk[1] = ' ' + (077 & ((*s << 4) & 060 | (s[1] >> 4) & 017));
2934 hunk[2] = ' ' + (077 & ((s[1] << 2) & 074 | (s[2] >> 6) & 03));
2935 hunk[3] = ' ' + (077 & (s[2] & 077));
2936 sv_catpvn(sv, hunk, 4);
2940 for (s = SvPVX(sv); *s; s++) {
2944 sv_catpvn(sv, "\n", 1);
2949 dSP; dMARK; dORIGMARK; dTARGET;
2950 register SV *cat = TARG;
2953 register char *pat = SvPVx(*++MARK, fromlen);
2954 register char *patend = pat + fromlen;
2959 static char null10[] = {0,0,0,0,0,0,0,0,0,0};
2960 static char *space10 = " ";
2962 /* These must not be in registers: */
2971 unsigned Quad_t auquad;
2979 sv_setpvn(cat, "", 0);
2980 while (pat < patend) {
2981 #define NEXTFROM (items-- > 0 ? *MARK++ : &sv_no)
2984 len = strchr("@Xxu", datumtype) ? 0 : items;
2987 else if (isDIGIT(*pat)) {
2989 while (isDIGIT(*pat))
2990 len = (len * 10) + (*pat++ - '0');
2998 DIE("%% may only be used in unpack");
3009 if (SvCUR(cat) < len)
3010 DIE("X outside of string");
3017 sv_catpvn(cat, null10, 10);
3020 sv_catpvn(cat, null10, len);
3025 aptr = SvPV(fromstr, fromlen);
3029 sv_catpvn(cat, aptr, len);
3031 sv_catpvn(cat, aptr, fromlen);
3033 if (datumtype == 'A') {
3035 sv_catpvn(cat, space10, 10);
3038 sv_catpvn(cat, space10, len);
3042 sv_catpvn(cat, null10, 10);
3045 sv_catpvn(cat, null10, len);
3052 char *savepat = pat;
3057 aptr = SvPV(fromstr, fromlen);
3062 SvCUR(cat) += (len+7)/8;
3063 SvGROW(cat, SvCUR(cat) + 1);
3064 aptr = SvPVX(cat) + aint;
3069 if (datumtype == 'B') {
3070 for (len = 0; len++ < aint;) {
3071 items |= *pat++ & 1;
3075 *aptr++ = items & 0xff;
3081 for (len = 0; len++ < aint;) {
3087 *aptr++ = items & 0xff;
3093 if (datumtype == 'B')
3094 items <<= 7 - (aint & 7);
3096 items >>= 7 - (aint & 7);
3097 *aptr++ = items & 0xff;
3099 pat = SvPVX(cat) + SvCUR(cat);
3110 char *savepat = pat;
3115 aptr = SvPV(fromstr, fromlen);
3120 SvCUR(cat) += (len+1)/2;
3121 SvGROW(cat, SvCUR(cat) + 1);
3122 aptr = SvPVX(cat) + aint;
3127 if (datumtype == 'H') {
3128 for (len = 0; len++ < aint;) {
3130 items |= ((*pat++ & 15) + 9) & 15;
3132 items |= *pat++ & 15;
3136 *aptr++ = items & 0xff;
3142 for (len = 0; len++ < aint;) {
3144 items |= (((*pat++ & 15) + 9) & 15) << 4;
3146 items |= (*pat++ & 15) << 4;
3150 *aptr++ = items & 0xff;
3156 *aptr++ = items & 0xff;
3157 pat = SvPVX(cat) + SvCUR(cat);
3169 aint = SvIV(fromstr);
3171 sv_catpvn(cat, &achar, sizeof(char));
3174 /* Float and double added by gnb@melba.bby.oz.au 22/11/89 */
3179 afloat = (float)SvNV(fromstr);
3180 sv_catpvn(cat, (char *)&afloat, sizeof (float));
3187 adouble = (double)SvNV(fromstr);
3188 sv_catpvn(cat, (char *)&adouble, sizeof (double));
3194 ashort = (I16)SvIV(fromstr);
3196 ashort = htons(ashort);
3198 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
3204 ashort = (I16)SvIV(fromstr);
3206 ashort = htovs(ashort);
3208 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
3215 ashort = (I16)SvIV(fromstr);
3216 sv_catpvn(cat, (char*)&ashort, sizeof(I16));
3222 auint = U_I(SvNV(fromstr));
3223 sv_catpvn(cat, (char*)&auint, sizeof(unsigned int));
3229 aint = SvIV(fromstr);
3230 sv_catpvn(cat, (char*)&aint, sizeof(int));
3236 aulong = U_L(SvNV(fromstr));
3238 aulong = htonl(aulong);
3240 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
3246 aulong = U_L(SvNV(fromstr));
3248 aulong = htovl(aulong);
3250 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
3256 aulong = U_L(SvNV(fromstr));
3257 sv_catpvn(cat, (char*)&aulong, sizeof(U32));
3263 along = SvIV(fromstr);
3264 sv_catpvn(cat, (char*)&along, sizeof(I32));
3271 auquad = (unsigned Quad_t)SvIV(fromstr);
3272 sv_catpvn(cat, (char*)&auquad, sizeof(unsigned Quad_t));
3278 aquad = (Quad_t)SvIV(fromstr);
3279 sv_catpvn(cat, (char*)&aquad, sizeof(Quad_t));
3282 #endif /* HAS_QUAD */
3284 len = 1; /* assume SV is correct length */
3289 aptr = SvPV_force(fromstr, na); /* XXX Error if TEMP? */
3290 sv_catpvn(cat, (char*)&aptr, sizeof(char*));
3295 aptr = SvPV(fromstr, fromlen);
3296 SvGROW(cat, fromlen * 4 / 3);
3301 while (fromlen > 0) {
3308 doencodes(cat, aptr, todo);
3326 register I32 limit = POPi; /* note, negative is forever */
3329 register char *s = SvPV(sv, len);
3330 char *strend = s + len;
3331 register PMOP *pm = (PMOP*)POPs;
3335 I32 maxiters = (strend - s) + 10;
3338 I32 origlimit = limit;
3341 AV *oldstack = curstack;
3342 register REGEXP *rx = pm->op_pmregexp;
3344 I32 oldsave = savestack_ix;
3347 DIE("panic: do_split");
3348 if (pm->op_pmreplroot)
3349 ary = GvAVn((GV*)pm->op_pmreplroot);
3350 else if (gimme != G_ARRAY)
3354 if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) {
3358 for (i = AvFILL(ary); i >= 0; i--)
3359 AvARRAY(ary)[i] = &sv_undef; /* don't free mere refs */
3363 /* temporarily switch stacks */
3364 SWITCHSTACK(curstack, ary);
3366 base = SP - stack_base;
3368 if (pm->op_pmflags & PMf_SKIPWHITE) {
3372 if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
3374 multiline = pm->op_pmflags & PMf_MULTILINE;
3378 limit = maxiters + 2;
3379 if (pm->op_pmflags & PMf_WHITE) {
3382 for (m = s; m < strend && !isSPACE(*m); m++) ;
3385 dstr = NEWSV(30, m-s);
3386 sv_setpvn(dstr, s, m-s);
3391 for (s = m + 1; s < strend && isSPACE(*s); s++) ;
3394 else if (strEQ("^", rx->precomp)) {
3397 for (m = s; m < strend && *m != '\n'; m++) ;
3401 dstr = NEWSV(30, m-s);
3402 sv_setpvn(dstr, s, m-s);
3409 else if (pm->op_pmshort) {
3410 i = SvCUR(pm->op_pmshort);
3412 I32 fold = (pm->op_pmflags & PMf_FOLD);
3413 i = *SvPVX(pm->op_pmshort);
3414 if (fold && isUPPER(i))
3419 m < strend && *m != i &&
3420 (!isUPPER(*m) || toLOWER(*m) != i);
3421 m++) /*SUPPRESS 530*/
3424 else /*SUPPRESS 530*/
3425 for (m = s; m < strend && *m != i; m++) ;
3428 dstr = NEWSV(30, m-s);
3429 sv_setpvn(dstr, s, m-s);
3438 while (s < strend && --limit &&
3439 (m=fbm_instr((unsigned char*)s, (unsigned char*)strend,
3443 dstr = NEWSV(31, m-s);
3444 sv_setpvn(dstr, s, m-s);
3453 maxiters += (strend - s) * rx->nparens;
3454 while (s < strend && --limit &&
3455 pregexec(rx, s, strend, orig, 1, Nullsv, TRUE) ) {
3457 && rx->subbase != orig) {
3462 strend = s + (strend - m);
3465 dstr = NEWSV(32, m-s);
3466 sv_setpvn(dstr, s, m-s);
3471 for (i = 1; i <= rx->nparens; i++) {
3475 dstr = NEWSV(33, m-s);
3476 sv_setpvn(dstr, s, m-s);
3479 dstr = NEWSV(33, 0);
3488 LEAVE_SCOPE(oldsave);
3489 iters = (SP - stack_base) - base;
3490 if (iters > maxiters)
3493 /* keep field after final delim? */
3494 if (s < strend || (iters && origlimit)) {
3495 dstr = NEWSV(34, strend-s);
3496 sv_setpvn(dstr, s, strend-s);
3502 else if (!origlimit) {
3503 while (iters > 0 && SvCUR(TOPs) == 0)
3507 SWITCHSTACK(ary, oldstack);
3508 if (gimme == G_ARRAY) {
3510 Copy(AvARRAY(ary), SP + 1, iters, SV*);
3516 if (gimme == G_ARRAY)
3519 if (iters || !pm->op_pmreplroot) {