This is my patch patch.1h for perl5.001.
[p5sagit/p5-mst-13.2.git] / pp_ctl.c
CommitLineData
a0d0e21e 1/* pp_ctl.c
2 *
3 * Copyright (c) 1991-1994, Larry Wall
4 *
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.
7 *
8 */
9
10/*
11 * Now far ahead the Road has gone,
12 * And I must follow, if I can,
13 * Pursuing it with eager feet,
14 * Until it joins some larger way
15 * Where many paths and errands meet.
16 * And whither then? I cannot say.
17 */
18
19#include "EXTERN.h"
20#include "perl.h"
21
22#ifndef WORD_ALIGN
23#define WORD_ALIGN sizeof(U16)
24#endif
25
26static OP *doeval _((int gimme));
27static OP *dofindlabel _((OP *op, char *label, OP **opstack));
28static void doparseform _((SV *sv));
29static I32 dopoptoeval _((I32 startingblock));
30static I32 dopoptolabel _((char *label));
31static I32 dopoptoloop _((I32 startingblock));
32static I32 dopoptosub _((I32 startingblock));
33static void save_lines _((AV *array, SV *sv));
34static int sortcmp _((const void *, const void *));
35static int sortcv _((const void *, const void *));
36
37static I32 sortcxix;
38
39PP(pp_wantarray)
40{
41 dSP;
42 I32 cxix;
43 EXTEND(SP, 1);
44
45 cxix = dopoptosub(cxstack_ix);
46 if (cxix < 0)
47 RETPUSHUNDEF;
48
49 if (cxstack[cxix].blk_gimme == G_ARRAY)
50 RETPUSHYES;
51 else
52 RETPUSHNO;
53}
54
55PP(pp_regcmaybe)
56{
57 return NORMAL;
58}
59
60PP(pp_regcomp) {
61 dSP;
62 register PMOP *pm = (PMOP*)cLOGOP->op_other;
63 register char *t;
64 SV *tmpstr;
65 STRLEN len;
66
67 tmpstr = POPs;
68 t = SvPV(tmpstr, len);
69
70 if (pm->op_pmregexp) {
71 regfree(pm->op_pmregexp);
72 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
73 }
74
75 pm->op_pmregexp = regcomp(t, t + len, pm);
76
77 if (!pm->op_pmregexp->prelen && curpm)
78 pm = curpm;
79 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
80 pm->op_pmflags |= PMf_WHITE;
81
82 if (pm->op_pmflags & PMf_KEEP) {
a0d0e21e 83 pm->op_pmflags &= ~PMf_RUNTIME; /* no point compiling again */
84 hoistmust(pm);
85 cLOGOP->op_first->op_next = op->op_next;
a0d0e21e 86 }
87 RETURN;
88}
89
90PP(pp_substcont)
91{
92 dSP;
93 register PMOP *pm = (PMOP*) cLOGOP->op_other;
94 register CONTEXT *cx = &cxstack[cxstack_ix];
95 register SV *dstr = cx->sb_dstr;
96 register char *s = cx->sb_s;
97 register char *m = cx->sb_m;
98 char *orig = cx->sb_orig;
99 register REGEXP *rx = pm->op_pmregexp;
100
101 if (cx->sb_iters++) {
102 if (cx->sb_iters > cx->sb_maxiters)
103 DIE("Substitution loop");
104
105 sv_catsv(dstr, POPs);
106 if (rx->subbase)
107 Safefree(rx->subbase);
108 rx->subbase = cx->sb_subbase;
109
110 /* Are we done */
111 if (cx->sb_once || !regexec(rx, s, cx->sb_strend, orig,
112 s == m, Nullsv, cx->sb_safebase))
113 {
114 SV *targ = cx->sb_targ;
115 sv_catpvn(dstr, s, cx->sb_strend - s);
748a9306 116
cb0b1708 117 Safefree(SvPVX(targ));
748a9306 118 SvPVX(targ) = SvPVX(dstr);
119 SvCUR_set(targ, SvCUR(dstr));
120 SvLEN_set(targ, SvLEN(dstr));
121 SvPVX(dstr) = 0;
122 sv_free(dstr);
123
a0d0e21e 124 (void)SvPOK_only(targ);
125 SvSETMAGIC(targ);
126 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
127 POPSUBST(cx);
128 RETURNOP(pm->op_next);
129 }
130 }
131 if (rx->subbase && rx->subbase != orig) {
132 m = s;
133 s = orig;
134 cx->sb_orig = orig = rx->subbase;
135 s = orig + (m - s);
136 cx->sb_strend = s + (cx->sb_strend - m);
137 }
138 cx->sb_m = m = rx->startp[0];
139 sv_catpvn(dstr, s, m-s);
140 cx->sb_s = rx->endp[0];
141 cx->sb_subbase = rx->subbase;
142
143 rx->subbase = Nullch; /* so recursion works */
144 RETURNOP(pm->op_pmreplstart);
145}
146
147PP(pp_formline)
148{
149 dSP; dMARK; dORIGMARK;
150 register SV *form = *++MARK;
151 register U16 *fpc;
152 register char *t;
153 register char *f;
154 register char *s;
155 register char *send;
156 register I32 arg;
157 register SV *sv;
158 char *item;
159 I32 itemsize;
160 I32 fieldsize;
161 I32 lines = 0;
162 bool chopspace = (strchr(chopset, ' ') != Nullch);
163 char *chophere;
164 char *linemark;
a0d0e21e 165 double value;
166 bool gotsome;
167 STRLEN len;
168
169 if (!SvCOMPILED(form)) {
170 SvREADONLY_off(form);
171 doparseform(form);
172 }
173
174 SvPV_force(formtarget, len);
175 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
176 t += len;
177 f = SvPV(form, len);
178 /* need to jump to the next word */
179 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
180
181 fpc = (U16*)s;
182
183 for (;;) {
184 DEBUG_f( {
185 char *name = "???";
186 arg = -1;
187 switch (*fpc) {
188 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
189 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
190 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
191 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
192 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
193
194 case FF_CHECKNL: name = "CHECKNL"; break;
195 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
196 case FF_SPACE: name = "SPACE"; break;
197 case FF_HALFSPACE: name = "HALFSPACE"; break;
198 case FF_ITEM: name = "ITEM"; break;
199 case FF_CHOP: name = "CHOP"; break;
200 case FF_LINEGLOB: name = "LINEGLOB"; break;
201 case FF_NEWLINE: name = "NEWLINE"; break;
202 case FF_MORE: name = "MORE"; break;
203 case FF_LINEMARK: name = "LINEMARK"; break;
204 case FF_END: name = "END"; break;
205 }
206 if (arg >= 0)
207 fprintf(stderr, "%-16s%ld\n", name, (long) arg);
208 else
209 fprintf(stderr, "%-16s\n", name);
210 } )
211 switch (*fpc++) {
212 case FF_LINEMARK:
213 linemark = t;
a0d0e21e 214 lines++;
215 gotsome = FALSE;
216 break;
217
218 case FF_LITERAL:
219 arg = *fpc++;
220 while (arg--)
221 *t++ = *f++;
222 break;
223
224 case FF_SKIP:
225 f += *fpc++;
226 break;
227
228 case FF_FETCH:
229 arg = *fpc++;
230 f += arg;
231 fieldsize = arg;
232
233 if (MARK < SP)
234 sv = *++MARK;
235 else {
236 sv = &sv_no;
237 if (dowarn)
238 warn("Not enough format arguments");
239 }
240 break;
241
242 case FF_CHECKNL:
243 item = s = SvPV(sv, len);
244 itemsize = len;
245 if (itemsize > fieldsize)
246 itemsize = fieldsize;
247 send = chophere = s + itemsize;
248 while (s < send) {
249 if (*s & ~31)
250 gotsome = TRUE;
251 else if (*s == '\n')
252 break;
253 s++;
254 }
255 itemsize = s - item;
256 break;
257
258 case FF_CHECKCHOP:
259 item = s = SvPV(sv, len);
260 itemsize = len;
261 if (itemsize <= fieldsize) {
262 send = chophere = s + itemsize;
263 while (s < send) {
264 if (*s == '\r') {
265 itemsize = s - item;
266 break;
267 }
268 if (*s++ & ~31)
269 gotsome = TRUE;
270 }
271 }
272 else {
273 itemsize = fieldsize;
274 send = chophere = s + itemsize;
275 while (s < send || (s == send && isSPACE(*s))) {
276 if (isSPACE(*s)) {
277 if (chopspace)
278 chophere = s;
279 if (*s == '\r')
280 break;
281 }
282 else {
283 if (*s & ~31)
284 gotsome = TRUE;
285 if (strchr(chopset, *s))
286 chophere = s + 1;
287 }
288 s++;
289 }
290 itemsize = chophere - item;
291 }
292 break;
293
294 case FF_SPACE:
295 arg = fieldsize - itemsize;
296 if (arg) {
297 fieldsize -= arg;
298 while (arg-- > 0)
299 *t++ = ' ';
300 }
301 break;
302
303 case FF_HALFSPACE:
304 arg = fieldsize - itemsize;
305 if (arg) {
306 arg /= 2;
307 fieldsize -= arg;
308 while (arg-- > 0)
309 *t++ = ' ';
310 }
311 break;
312
313 case FF_ITEM:
314 arg = itemsize;
315 s = item;
316 while (arg--) {
317#if 'z' - 'a' != 25
318 int ch = *t++ = *s++;
319 if (!iscntrl(ch))
320 t[-1] = ' ';
321#else
322 if ( !((*t++ = *s++) & ~31) )
323 t[-1] = ' ';
324#endif
325
326 }
327 break;
328
329 case FF_CHOP:
330 s = chophere;
331 if (chopspace) {
332 while (*s && isSPACE(*s))
333 s++;
334 }
335 sv_chop(sv,s);
336 break;
337
338 case FF_LINEGLOB:
339 item = s = SvPV(sv, len);
340 itemsize = len;
341 if (itemsize) {
342 gotsome = TRUE;
343 send = s + itemsize;
344 while (s < send) {
345 if (*s++ == '\n') {
346 if (s == send)
347 itemsize--;
348 else
349 lines++;
350 }
351 }
352 SvCUR_set(formtarget, t - SvPVX(formtarget));
353 sv_catpvn(formtarget, item, itemsize);
354 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
355 t = SvPVX(formtarget) + SvCUR(formtarget);
356 }
357 break;
358
359 case FF_DECIMAL:
360 /* If the field is marked with ^ and the value is undefined,
361 blank it out. */
362 arg = *fpc++;
363 if ((arg & 512) && !SvOK(sv)) {
364 arg = fieldsize;
365 while (arg--)
366 *t++ = ' ';
367 break;
368 }
369 gotsome = TRUE;
370 value = SvNV(sv);
371 if (arg & 256) {
372 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
373 } else {
374 sprintf(t, "%*.0f", (int) fieldsize, value);
375 }
376 t += fieldsize;
377 break;
378
379 case FF_NEWLINE:
380 f++;
381 while (t-- > linemark && *t == ' ') ;
382 t++;
383 *t++ = '\n';
384 break;
385
386 case FF_BLANK:
387 arg = *fpc++;
388 if (gotsome) {
389 if (arg) { /* repeat until fields exhausted? */
390 *t = '\0';
391 SvCUR_set(formtarget, t - SvPVX(formtarget));
392 lines += FmLINES(formtarget);
393 if (lines == 200) {
394 arg = t - linemark;
395 if (strnEQ(linemark, linemark - arg, arg))
396 DIE("Runaway format");
397 }
398 FmLINES(formtarget) = lines;
399 SP = ORIGMARK;
400 RETURNOP(cLISTOP->op_first);
401 }
402 }
403 else {
404 t = linemark;
405 lines--;
406 }
407 break;
408
409 case FF_MORE:
410 if (itemsize) {
411 arg = fieldsize - itemsize;
412 if (arg) {
413 fieldsize -= arg;
414 while (arg-- > 0)
415 *t++ = ' ';
416 }
417 s = t - 3;
418 if (strnEQ(s," ",3)) {
419 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
420 s--;
421 }
422 *s++ = '.';
423 *s++ = '.';
424 *s++ = '.';
425 }
426 break;
427
428 case FF_END:
429 *t = '\0';
430 SvCUR_set(formtarget, t - SvPVX(formtarget));
431 FmLINES(formtarget) += lines;
432 SP = ORIGMARK;
433 RETPUSHYES;
434 }
435 }
436}
437
438PP(pp_grepstart)
439{
440 dSP;
441 SV *src;
442
443 if (stack_base + *markstack_ptr == sp) {
444 (void)POPMARK;
445 if (GIMME != G_ARRAY)
446 XPUSHs(&sv_no);
447 RETURNOP(op->op_next->op_next);
448 }
449 stack_sp = stack_base + *markstack_ptr + 1;
450 pp_pushmark(); /* push dst */
451 pp_pushmark(); /* push src */
452 ENTER; /* enter outer scope */
453
454 SAVETMPS;
455 SAVESPTR(GvSV(defgv));
456
457 ENTER; /* enter inner scope */
458 SAVESPTR(curpm);
459
460 src = stack_base[*markstack_ptr];
461 SvTEMP_off(src);
462 GvSV(defgv) = src;
463
464 PUTBACK;
465 if (op->op_type == OP_MAPSTART)
466 pp_pushmark(); /* push top */
467 return ((LOGOP*)op->op_next)->op_other;
468}
469
470PP(pp_mapstart)
471{
472 DIE("panic: mapstart"); /* uses grepstart */
473}
474
475PP(pp_mapwhile)
476{
477 dSP;
478 I32 diff = (sp - stack_base) - *markstack_ptr;
479 I32 count;
480 I32 shift;
481 SV** src;
482 SV** dst;
483
484 ++markstack_ptr[-1];
485 if (diff) {
486 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
487 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
488 count = (sp - stack_base) - markstack_ptr[-1] + 2;
489
490 EXTEND(sp,shift);
491 src = sp;
492 dst = (sp += shift);
493 markstack_ptr[-1] += shift;
494 *markstack_ptr += shift;
495 while (--count)
496 *dst-- = *src--;
497 }
498 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
499 ++diff;
500 while (--diff)
501 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
502 }
503 LEAVE; /* exit inner scope */
504
505 /* All done yet? */
506 if (markstack_ptr[-1] > *markstack_ptr) {
507 I32 items;
508
509 (void)POPMARK; /* pop top */
510 LEAVE; /* exit outer scope */
511 (void)POPMARK; /* pop src */
512 items = --*markstack_ptr - markstack_ptr[-1];
513 (void)POPMARK; /* pop dst */
514 SP = stack_base + POPMARK; /* pop original mark */
515 if (GIMME != G_ARRAY) {
516 dTARGET;
517 XPUSHi(items);
518 RETURN;
519 }
520 SP += items;
521 RETURN;
522 }
523 else {
524 SV *src;
525
526 ENTER; /* enter inner scope */
527 SAVESPTR(curpm);
528
529 src = stack_base[markstack_ptr[-1]];
530 SvTEMP_off(src);
531 GvSV(defgv) = src;
532
533 RETURNOP(cLOGOP->op_other);
534 }
535}
536
537
538PP(pp_sort)
539{
540 dSP; dMARK; dORIGMARK;
541 register SV **up;
542 SV **myorigmark = ORIGMARK;
543 register I32 max;
544 HV *stash;
545 GV *gv;
546 CV *cv;
547 I32 gimme = GIMME;
548 OP* nextop = op->op_next;
549
550 if (gimme != G_ARRAY) {
551 SP = MARK;
552 RETPUSHUNDEF;
553 }
554
555 if (op->op_flags & OPf_STACKED) {
556 ENTER;
557 if (op->op_flags & OPf_SPECIAL) {
558 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
559 kid = kUNOP->op_first; /* pass rv2gv */
560 kid = kUNOP->op_first; /* pass leave */
561 sortcop = kid->op_next;
562 stash = curcop->cop_stash;
563 }
564 else {
565 cv = sv_2cv(*++MARK, &stash, &gv, 0);
566 if (!(cv && CvROOT(cv))) {
567 if (gv) {
568 SV *tmpstr = sv_newmortal();
569 gv_efullname(tmpstr, gv);
570 if (cv && CvXSUB(cv))
571 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
572 DIE("Undefined sort subroutine \"%s\" called",
573 SvPVX(tmpstr));
574 }
575 if (cv) {
576 if (CvXSUB(cv))
577 DIE("Xsub called in sort");
578 DIE("Undefined subroutine in sort");
579 }
580 DIE("Not a CODE reference in sort");
581 }
582 sortcop = CvSTART(cv);
583 SAVESPTR(CvROOT(cv)->op_ppaddr);
584 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
585
586 SAVESPTR(curpad);
587 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
588 }
589 }
590 else {
591 sortcop = Nullop;
592 stash = curcop->cop_stash;
593 }
594
595 up = myorigmark + 1;
596 while (MARK < SP) { /* This may or may not shift down one here. */
597 /*SUPPRESS 560*/
598 if (*up = *++MARK) { /* Weed out nulls. */
599 if (!SvPOK(*up))
600 (void)sv_2pv(*up, &na);
601 else
602 SvTEMP_off(*up);
603 up++;
604 }
605 }
606 max = --up - myorigmark;
607 if (sortcop) {
608 if (max > 1) {
609 AV *oldstack;
610 CONTEXT *cx;
611 SV** newsp;
612
613 SAVETMPS;
614 SAVESPTR(op);
615
616 oldstack = stack;
617 if (!sortstack) {
618 sortstack = newAV();
619 AvREAL_off(sortstack);
620 av_extend(sortstack, 32);
621 }
622 SWITCHSTACK(stack, sortstack);
623 if (sortstash != stash) {
624 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
625 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
626 sortstash = stash;
627 }
628
629 SAVESPTR(GvSV(firstgv));
630 SAVESPTR(GvSV(secondgv));
631 PUSHBLOCK(cx, CXt_LOOP, stack_base);
632 sortcxix = cxstack_ix;
633
634 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
635
636 POPBLOCK(cx,curpm);
637 SWITCHSTACK(sortstack, oldstack);
638 }
639 LEAVE;
640 }
641 else {
642 if (max > 1) {
643 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
644 qsort((char*)(ORIGMARK+1), max, sizeof(SV*), sortcmp);
645 }
646 }
647 stack_sp = ORIGMARK + max;
648 return nextop;
649}
650
651/* Range stuff. */
652
653PP(pp_range)
654{
655 if (GIMME == G_ARRAY)
656 return cCONDOP->op_true;
657 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
658}
659
660PP(pp_flip)
661{
662 dSP;
663
664 if (GIMME == G_ARRAY) {
665 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
666 }
667 else {
668 dTOPss;
669 SV *targ = PAD_SV(op->op_targ);
670
671 if ((op->op_private & OPpFLIP_LINENUM)
672 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
673 : SvTRUE(sv) ) {
674 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
675 if (op->op_flags & OPf_SPECIAL) {
676 sv_setiv(targ, 1);
677 RETURN;
678 }
679 else {
680 sv_setiv(targ, 0);
681 sp--;
682 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
683 }
684 }
685 sv_setpv(TARG, "");
686 SETs(targ);
687 RETURN;
688 }
689}
690
691PP(pp_flop)
692{
693 dSP;
694
695 if (GIMME == G_ARRAY) {
696 dPOPPOPssrl;
697 register I32 i;
698 register SV *sv;
699 I32 max;
700
701 if (SvNIOK(left) || !SvPOK(left) ||
702 (looks_like_number(left) && *SvPVX(left) != '0') ) {
703 i = SvIV(left);
704 max = SvIV(right);
705 if (max > i)
706 EXTEND(SP, max - i + 1);
707 while (i <= max) {
708 sv = sv_mortalcopy(&sv_no);
709 sv_setiv(sv,i++);
710 PUSHs(sv);
711 }
712 }
713 else {
714 SV *final = sv_mortalcopy(right);
715 STRLEN len;
716 char *tmps = SvPV(final, len);
717
718 sv = sv_mortalcopy(left);
719 while (!SvNIOK(sv) && SvCUR(sv) <= len &&
720 strNE(SvPVX(sv),tmps) ) {
721 XPUSHs(sv);
722 sv = sv_2mortal(newSVsv(sv));
723 sv_inc(sv);
724 }
725 if (strEQ(SvPVX(sv),tmps))
726 XPUSHs(sv);
727 }
728 }
729 else {
730 dTOPss;
731 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
732 sv_inc(targ);
733 if ((op->op_private & OPpFLIP_LINENUM)
734 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
735 : SvTRUE(sv) ) {
736 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
737 sv_catpv(targ, "E0");
738 }
739 SETs(targ);
740 }
741
742 RETURN;
743}
744
745/* Control. */
746
747static I32
748dopoptolabel(label)
749char *label;
750{
751 register I32 i;
752 register CONTEXT *cx;
753
754 for (i = cxstack_ix; i >= 0; i--) {
755 cx = &cxstack[i];
756 switch (cx->cx_type) {
757 case CXt_SUBST:
758 if (dowarn)
759 warn("Exiting substitution via %s", op_name[op->op_type]);
760 break;
761 case CXt_SUB:
762 if (dowarn)
763 warn("Exiting subroutine via %s", op_name[op->op_type]);
764 break;
765 case CXt_EVAL:
766 if (dowarn)
767 warn("Exiting eval via %s", op_name[op->op_type]);
768 break;
769 case CXt_LOOP:
770 if (!cx->blk_loop.label ||
771 strNE(label, cx->blk_loop.label) ) {
772 DEBUG_l(deb("(Skipping label #%d %s)\n",
773 i, cx->blk_loop.label));
774 continue;
775 }
776 DEBUG_l( deb("(Found label #%d %s)\n", i, label));
777 return i;
778 }
779 }
780 return i;
781}
782
783static I32
784dopoptosub(startingblock)
785I32 startingblock;
786{
787 I32 i;
788 register CONTEXT *cx;
789 for (i = startingblock; i >= 0; i--) {
790 cx = &cxstack[i];
791 switch (cx->cx_type) {
792 default:
793 continue;
794 case CXt_EVAL:
795 case CXt_SUB:
796 DEBUG_l( deb("(Found sub #%d)\n", i));
797 return i;
798 }
799 }
800 return i;
801}
802
803static I32
804dopoptoeval(startingblock)
805I32 startingblock;
806{
807 I32 i;
808 register CONTEXT *cx;
809 for (i = startingblock; i >= 0; i--) {
810 cx = &cxstack[i];
811 switch (cx->cx_type) {
812 default:
813 continue;
814 case CXt_EVAL:
815 DEBUG_l( deb("(Found eval #%d)\n", i));
816 return i;
817 }
818 }
819 return i;
820}
821
822static I32
823dopoptoloop(startingblock)
824I32 startingblock;
825{
826 I32 i;
827 register CONTEXT *cx;
828 for (i = startingblock; i >= 0; i--) {
829 cx = &cxstack[i];
830 switch (cx->cx_type) {
831 case CXt_SUBST:
832 if (dowarn)
833 warn("Exiting substitition via %s", op_name[op->op_type]);
834 break;
835 case CXt_SUB:
836 if (dowarn)
837 warn("Exiting subroutine via %s", op_name[op->op_type]);
838 break;
839 case CXt_EVAL:
840 if (dowarn)
841 warn("Exiting eval via %s", op_name[op->op_type]);
842 break;
843 case CXt_LOOP:
844 DEBUG_l( deb("(Found loop #%d)\n", i));
845 return i;
846 }
847 }
848 return i;
849}
850
851void
852dounwind(cxix)
853I32 cxix;
854{
855 register CONTEXT *cx;
856 SV **newsp;
857 I32 optype;
858
859 while (cxstack_ix > cxix) {
860 cx = &cxstack[cxstack_ix--];
861 DEBUG_l(fprintf(stderr, "Unwinding block %ld, type %s\n", (long) cxstack_ix+1,
862 block_type[cx->cx_type]));
863 /* Note: we don't need to restore the base context info till the end. */
864 switch (cx->cx_type) {
865 case CXt_SUB:
866 POPSUB(cx);
867 break;
868 case CXt_EVAL:
869 POPEVAL(cx);
870 break;
871 case CXt_LOOP:
872 POPLOOP(cx);
873 break;
874 case CXt_SUBST:
875 break;
876 }
877 }
878}
879
ecfc5424 880#ifdef I_STDARG
a0d0e21e 881OP *
882die(char* pat, ...)
883#else
884/*VARARGS0*/
885OP *
886die(pat, va_alist)
887 char *pat;
888 va_dcl
889#endif
890{
891 va_list args;
892 char *message;
893 int oldrunlevel = runlevel;
894 int was_in_eval = in_eval;
748a9306 895 HV *stash;
896 GV *gv;
897 CV *cv;
a0d0e21e 898
899#ifdef I_STDARG
900 va_start(args, pat);
901#else
902 va_start(args);
903#endif
904 message = mess(pat, &args);
905 va_end(args);
748a9306 906 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
907 dSP;
908
909 PUSHMARK(sp);
910 EXTEND(sp, 1);
911 PUSHs(sv_2mortal(newSVpv(message,0)));
912 PUTBACK;
913 perl_call_sv((SV*)cv, G_DISCARD);
914 }
a0d0e21e 915 restartop = die_where(message);
916 if ((!restartop && was_in_eval) || oldrunlevel > 1)
917 longjmp(top_env, 3);
918 return restartop;
919}
920
921OP *
922die_where(message)
923char *message;
924{
925 if (in_eval) {
926 I32 cxix;
927 register CONTEXT *cx;
928 I32 gimme;
929 SV **newsp;
748a9306 930 SV *errsv;
931
932 errsv = GvSV(gv_fetchpv("@",TRUE, SVt_PV));
933 /* As destructors may produce errors we set $@ at the last moment */
934 sv_setpv(errsv, ""); /* clear $@ before destroying */
a0d0e21e 935
a0d0e21e 936 cxix = dopoptoeval(cxstack_ix);
937 if (cxix >= 0) {
938 I32 optype;
939
940 if (cxix < cxstack_ix)
941 dounwind(cxix);
942
943 POPBLOCK(cx,curpm);
944 if (cx->cx_type != CXt_EVAL) {
945 fprintf(stderr, "panic: die %s", message);
946 my_exit(1);
947 }
948 POPEVAL(cx);
949
950 if (gimme == G_SCALAR)
951 *++newsp = &sv_undef;
952 stack_sp = newsp;
953
954 LEAVE;
748a9306 955
956 sv_insert(errsv, 0, 0, message, strlen(message));
a0d0e21e 957 if (optype == OP_REQUIRE)
958 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
959 return pop_return();
960 }
961 }
962 fputs(message, stderr);
963 (void)fflush(stderr);
964 if (e_fp)
965 (void)UNLINK(e_tmpname);
748a9306 966 statusvalue = SHIFTSTATUS(statusvalue);
967#ifdef VMS
968 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
969#else
a0d0e21e 970 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
748a9306 971#endif
a0d0e21e 972 return 0;
973}
974
975PP(pp_xor)
976{
977 dSP; dPOPTOPssrl;
978 if (SvTRUE(left) != SvTRUE(right))
979 RETSETYES;
980 else
981 RETSETNO;
982}
983
984PP(pp_andassign)
985{
986 dSP;
987 if (!SvTRUE(TOPs))
988 RETURN;
989 else
990 RETURNOP(cLOGOP->op_other);
991}
992
993PP(pp_orassign)
994{
995 dSP;
996 if (SvTRUE(TOPs))
997 RETURN;
998 else
999 RETURNOP(cLOGOP->op_other);
1000}
1001
1002#ifdef DEPRECATED
1003PP(pp_entersubr)
1004{
1005 dSP;
1006 SV** mark = (stack_base + *markstack_ptr + 1);
1007 SV* cv = *mark;
1008 while (mark < sp) { /* emulate old interface */
1009 *mark = mark[1];
1010 mark++;
1011 }
1012 *sp = cv;
1013 return pp_entersub();
1014}
1015#endif
1016
1017PP(pp_caller)
1018{
1019 dSP;
1020 register I32 cxix = dopoptosub(cxstack_ix);
1021 register CONTEXT *cx;
1022 I32 dbcxix;
1023 SV *sv;
1024 I32 count = 0;
1025
1026 if (MAXARG)
1027 count = POPi;
1028 EXTEND(SP, 6);
1029 for (;;) {
1030 if (cxix < 0) {
1031 if (GIMME != G_ARRAY)
1032 RETPUSHUNDEF;
1033 RETURN;
1034 }
1035 if (DBsub && cxix >= 0 &&
1036 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1037 count++;
1038 if (!count--)
1039 break;
1040 cxix = dopoptosub(cxix - 1);
1041 }
1042 cx = &cxstack[cxix];
1043 if (GIMME != G_ARRAY) {
1044 dTARGET;
1045
1046 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1047 PUSHs(TARG);
1048 RETURN;
1049 }
1050 dbcxix = dopoptosub(cxix - 1);
1051 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1052 cx = &cxstack[dbcxix];
1053
1054 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1055 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1056 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1057 if (!MAXARG)
1058 RETURN;
1059 if (cx->cx_type == CXt_SUB) {
1060 sv = NEWSV(49, 0);
1061 gv_efullname(sv, CvGV(cxstack[cxix].blk_sub.cv));
1062 PUSHs(sv_2mortal(sv));
1063 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1064 }
1065 else {
1066 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1067 PUSHs(sv_2mortal(newSViv(0)));
1068 }
1069 PUSHs(sv_2mortal(newSViv((I32)cx->blk_gimme)));
748a9306 1070 if (cx->cx_type == CXt_EVAL && cx->blk_eval.old_op_type == OP_ENTEREVAL)
1071 PUSHs(cx->blk_eval.cur_text);
1072
a0d0e21e 1073 if (cx->blk_sub.hasargs && curcop->cop_stash == debstash) {
1074 AV *ary = cx->blk_sub.argarray;
1075 int off = AvARRAY(ary) - AvALLOC(ary);
1076
1077 if (!dbargs) {
1078 GV* tmpgv;
1079 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1080 SVt_PVAV)));
1081 SvMULTI_on(tmpgv);
1082 AvREAL_off(dbargs); /* XXX Should be REIFY */
1083 }
1084
1085 if (AvMAX(dbargs) < AvFILL(ary) + off)
1086 av_extend(dbargs, AvFILL(ary) + off);
1087 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1088 AvFILL(dbargs) = AvFILL(ary) + off;
1089 }
1090 RETURN;
1091}
1092
1093static int
1094sortcv(a, b)
1095const void *a;
1096const void *b;
1097{
1098 SV **str1 = (SV **) a;
1099 SV **str2 = (SV **) b;
748a9306 1100 I32 oldsaveix = savestack_ix;
a0d0e21e 1101 I32 oldscopeix = scopestack_ix;
1102 I32 result;
1103 GvSV(firstgv) = *str1;
1104 GvSV(secondgv) = *str2;
1105 stack_sp = stack_base;
1106 op = sortcop;
1107 run();
1108 if (stack_sp != stack_base + 1)
1109 croak("Sort subroutine didn't return single value");
748a9306 1110 if (!SvNIOKp(*stack_sp))
a0d0e21e 1111 croak("Sort subroutine didn't return a numeric value");
1112 result = SvIV(*stack_sp);
1113 while (scopestack_ix > oldscopeix) {
1114 LEAVE;
1115 }
748a9306 1116 leave_scope(oldsaveix);
a0d0e21e 1117 return result;
1118}
1119
1120static int
1121sortcmp(a, b)
1122const void *a;
1123const void *b;
1124{
1125 register SV *str1 = *(SV **) a;
1126 register SV *str2 = *(SV **) b;
1127 I32 retval;
1128
1129 if (SvCUR(str1) < SvCUR(str2)) {
1130 /*SUPPRESS 560*/
1131 if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str1)))
1132 return retval;
1133 else
1134 return -1;
1135 }
1136 /*SUPPRESS 560*/
1137 else if (retval = memcmp(SvPVX(str1), SvPVX(str2), SvCUR(str2)))
1138 return retval;
1139 else if (SvCUR(str1) == SvCUR(str2))
1140 return 0;
1141 else
1142 return 1;
1143}
1144
1145PP(pp_reset)
1146{
1147 dSP;
1148 char *tmps;
1149
1150 if (MAXARG < 1)
1151 tmps = "";
1152 else
1153 tmps = POPp;
1154 sv_reset(tmps, curcop->cop_stash);
1155 PUSHs(&sv_yes);
1156 RETURN;
1157}
1158
1159PP(pp_lineseq)
1160{
1161 return NORMAL;
1162}
1163
1164PP(pp_dbstate)
1165{
1166 curcop = (COP*)op;
1167 TAINT_NOT; /* Each statement is presumed innocent */
1168 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1169 FREETMPS;
1170
1171 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1172 {
1173 SV **sp;
1174 register CV *cv;
1175 register CONTEXT *cx;
748a9306 1176 I32 gimme = G_ARRAY;
a0d0e21e 1177 I32 hasargs;
1178 GV *gv;
1179
1180 ENTER;
1181 SAVETMPS;
1182
a0d0e21e 1183 gv = DBgv;
1184 cv = GvCV(gv);
a0d0e21e 1185 if (!cv)
1186 DIE("No DB::DB routine defined");
1187
1188 if (CvDEPTH(cv) >= 1) /* don't do recursive DB::DB call */
1189 return NORMAL;
748a9306 1190
1191 SAVEI32(debug);
1192 SAVESPTR(stack_sp);
1193 debug = 0;
1194 hasargs = 0;
1195 sp = stack_sp;
1196
a0d0e21e 1197 push_return(op->op_next);
748a9306 1198 PUSHBLOCK(cx, CXt_SUB, sp);
a0d0e21e 1199 PUSHSUB(cx);
1200 CvDEPTH(cv)++;
1201 (void)SvREFCNT_inc(cv);
1202 SAVESPTR(curpad);
1203 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1204 RETURNOP(CvSTART(cv));
1205 }
1206 else
1207 return NORMAL;
1208}
1209
1210PP(pp_scope)
1211{
1212 return NORMAL;
1213}
1214
1215PP(pp_enteriter)
1216{
1217 dSP; dMARK;
1218 register CONTEXT *cx;
1219 I32 gimme = GIMME;
1220 SV **svp;
1221
1222 if (op->op_targ)
1223 svp = &curpad[op->op_targ]; /* "my" variable */
1224 else
1225 svp = &GvSV((GV*)POPs); /* symbol table variable */
1226
1227 ENTER;
1228 SAVETMPS;
1229 ENTER;
1230
1231 PUSHBLOCK(cx, CXt_LOOP, SP);
1232 PUSHLOOP(cx, svp, MARK);
1233 cx->blk_loop.iterary = stack;
1234 cx->blk_loop.iterix = MARK - stack_base;
1235
1236 RETURN;
1237}
1238
1239PP(pp_enterloop)
1240{
1241 dSP;
1242 register CONTEXT *cx;
1243 I32 gimme = GIMME;
1244
1245 ENTER;
1246 SAVETMPS;
1247 ENTER;
1248
1249 PUSHBLOCK(cx, CXt_LOOP, SP);
1250 PUSHLOOP(cx, 0, SP);
1251
1252 RETURN;
1253}
1254
1255PP(pp_leaveloop)
1256{
1257 dSP;
1258 register CONTEXT *cx;
1259 I32 gimme;
1260 SV **newsp;
1261 PMOP *newpm;
1262 SV **mark;
1263
1264 POPBLOCK(cx,newpm);
1265 mark = newsp;
1266 POPLOOP(cx);
1267 if (gimme == G_SCALAR) {
1268 if (op->op_private & OPpLEAVE_VOID)
1269 ;
1270 else {
1271 if (mark < SP)
1272 *++newsp = sv_mortalcopy(*SP);
1273 else
1274 *++newsp = &sv_undef;
1275 }
1276 }
1277 else {
1278 while (mark < SP)
1279 *++newsp = sv_mortalcopy(*++mark);
1280 }
1281 curpm = newpm; /* Don't pop $1 et al till now */
1282 sp = newsp;
1283 LEAVE;
1284 LEAVE;
1285
1286 RETURN;
1287}
1288
1289PP(pp_return)
1290{
1291 dSP; dMARK;
1292 I32 cxix;
1293 register CONTEXT *cx;
1294 I32 gimme;
1295 SV **newsp;
1296 PMOP *newpm;
1297 I32 optype = 0;
1298
1299 if (stack == sortstack) {
1300 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) < sortcxix) {
1301 AvARRAY(stack)[1] = *SP;
1302 stack_sp = stack_base + 1;
1303 return 0;
1304 }
1305 }
1306
1307 cxix = dopoptosub(cxstack_ix);
1308 if (cxix < 0)
1309 DIE("Can't return outside a subroutine");
1310 if (cxix < cxstack_ix)
1311 dounwind(cxix);
1312
1313 POPBLOCK(cx,newpm);
1314 switch (cx->cx_type) {
1315 case CXt_SUB:
1316 POPSUB(cx);
1317 break;
1318 case CXt_EVAL:
1319 POPEVAL(cx);
748a9306 1320 if (optype == OP_REQUIRE &&
1321 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1322 {
1323 char *name = cx->blk_eval.old_name;
1324 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1325 DIE("%s did not return a true value", name);
1326 }
a0d0e21e 1327 break;
1328 default:
1329 DIE("panic: return");
1330 break;
1331 }
1332
1333 if (gimme == G_SCALAR) {
1334 if (MARK < SP)
1335 *++newsp = sv_mortalcopy(*SP);
1336 else
1337 *++newsp = &sv_undef;
a0d0e21e 1338 }
1339 else {
a0d0e21e 1340 while (MARK < SP)
1341 *++newsp = sv_mortalcopy(*++MARK);
1342 }
1343 curpm = newpm; /* Don't pop $1 et al till now */
1344 stack_sp = newsp;
1345
1346 LEAVE;
1347 return pop_return();
1348}
1349
1350PP(pp_last)
1351{
1352 dSP;
1353 I32 cxix;
1354 register CONTEXT *cx;
1355 I32 gimme;
1356 I32 optype;
1357 OP *nextop;
1358 SV **newsp;
1359 PMOP *newpm;
1360 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
a0d0e21e 1361
1362 if (op->op_flags & OPf_SPECIAL) {
1363 cxix = dopoptoloop(cxstack_ix);
1364 if (cxix < 0)
1365 DIE("Can't \"last\" outside a block");
1366 }
1367 else {
1368 cxix = dopoptolabel(cPVOP->op_pv);
1369 if (cxix < 0)
1370 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1371 }
1372 if (cxix < cxstack_ix)
1373 dounwind(cxix);
1374
1375 POPBLOCK(cx,newpm);
1376 switch (cx->cx_type) {
1377 case CXt_LOOP:
1378 POPLOOP(cx);
1379 nextop = cx->blk_loop.last_op->op_next;
1380 LEAVE;
1381 break;
1382 case CXt_EVAL:
1383 POPEVAL(cx);
1384 nextop = pop_return();
1385 break;
1386 case CXt_SUB:
1387 POPSUB(cx);
1388 nextop = pop_return();
1389 break;
1390 default:
1391 DIE("panic: last");
1392 break;
1393 }
1394
1395 if (gimme == G_SCALAR) {
1396 if (mark < SP)
1397 *++newsp = sv_mortalcopy(*SP);
1398 else
1399 *++newsp = &sv_undef;
1400 }
1401 else {
1402 while (mark < SP)
1403 *++newsp = sv_mortalcopy(*++mark);
1404 }
1405 curpm = newpm; /* Don't pop $1 et al till now */
1406 sp = newsp;
1407
1408 LEAVE;
1409 RETURNOP(nextop);
1410}
1411
1412PP(pp_next)
1413{
1414 I32 cxix;
1415 register CONTEXT *cx;
1416 I32 oldsave;
1417
1418 if (op->op_flags & OPf_SPECIAL) {
1419 cxix = dopoptoloop(cxstack_ix);
1420 if (cxix < 0)
1421 DIE("Can't \"next\" outside a block");
1422 }
1423 else {
1424 cxix = dopoptolabel(cPVOP->op_pv);
1425 if (cxix < 0)
1426 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1427 }
1428 if (cxix < cxstack_ix)
1429 dounwind(cxix);
1430
1431 TOPBLOCK(cx);
1432 oldsave = scopestack[scopestack_ix - 1];
1433 LEAVE_SCOPE(oldsave);
1434 return cx->blk_loop.next_op;
1435}
1436
1437PP(pp_redo)
1438{
1439 I32 cxix;
1440 register CONTEXT *cx;
1441 I32 oldsave;
1442
1443 if (op->op_flags & OPf_SPECIAL) {
1444 cxix = dopoptoloop(cxstack_ix);
1445 if (cxix < 0)
1446 DIE("Can't \"redo\" outside a block");
1447 }
1448 else {
1449 cxix = dopoptolabel(cPVOP->op_pv);
1450 if (cxix < 0)
1451 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1452 }
1453 if (cxix < cxstack_ix)
1454 dounwind(cxix);
1455
1456 TOPBLOCK(cx);
1457 oldsave = scopestack[scopestack_ix - 1];
1458 LEAVE_SCOPE(oldsave);
1459 return cx->blk_loop.redo_op;
1460}
1461
1462static OP* lastgotoprobe;
1463
1464static OP *
1465dofindlabel(op,label,opstack)
1466OP *op;
1467char *label;
1468OP **opstack;
1469{
1470 OP *kid;
1471 OP **ops = opstack;
1472
1473 if (op->op_type == OP_LEAVE ||
1474 op->op_type == OP_SCOPE ||
1475 op->op_type == OP_LEAVELOOP ||
1476 op->op_type == OP_LEAVETRY)
1477 *ops++ = cUNOP->op_first;
1478 *ops = 0;
1479 if (op->op_flags & OPf_KIDS) {
1480 /* First try all the kids at this level, since that's likeliest. */
1481 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1482 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1483 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1484 return kid;
1485 }
1486 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
1487 if (kid == lastgotoprobe)
1488 continue;
1489 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
1490 if (ops > opstack &&
1491 (ops[-1]->op_type == OP_NEXTSTATE ||
1492 ops[-1]->op_type == OP_DBSTATE))
1493 *ops = kid;
1494 else
1495 *ops++ = kid;
1496 }
1497 if (op = dofindlabel(kid,label,ops))
1498 return op;
1499 }
1500 }
1501 *ops = 0;
1502 return 0;
1503}
1504
1505PP(pp_dump)
1506{
1507 return pp_goto(ARGS);
1508 /*NOTREACHED*/
1509}
1510
1511PP(pp_goto)
1512{
1513 dSP;
1514 OP *retop = 0;
1515 I32 ix;
1516 register CONTEXT *cx;
1517 OP *enterops[64];
1518 char *label;
1519 int do_dump = (op->op_type == OP_DUMP);
1520
1521 label = 0;
1522 if (op->op_flags & OPf_STACKED) {
1523 SV *sv = POPs;
1524
1525 /* This egregious kludge implements goto &subroutine */
1526 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1527 I32 cxix;
1528 register CONTEXT *cx;
1529 CV* cv = (CV*)SvRV(sv);
1530 SV** mark;
1531 I32 items = 0;
1532 I32 oldsave;
1533
1534 /* First do some returnish stuff. */
1535 cxix = dopoptosub(cxstack_ix);
1536 if (cxix < 0)
1537 DIE("Can't goto subroutine outside a subroutine");
1538 if (cxix < cxstack_ix)
1539 dounwind(cxix);
1540 TOPBLOCK(cx);
1541 mark = stack_sp;
1542 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1543 AV* av = cx->blk_sub.argarray;
1544
1545 items = AvFILL(av) + 1;
1546 Copy(AvARRAY(av), ++stack_sp, items, SV*);
1547 stack_sp += items;
1548 GvAV(defgv) = cx->blk_sub.savearray;
1549 av_clear(av);
1550 AvREAL_off(av);
1551 }
1552 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1553 SvREFCNT_dec(cx->blk_sub.cv);
1554 oldsave = scopestack[scopestack_ix - 1];
1555 LEAVE_SCOPE(oldsave);
1556
1557 /* Now do some callish stuff. */
1558 SAVETMPS;
1559 if (CvXSUB(cv)) {
1560 if (CvOLDSTYLE(cv)) {
ecfc5424 1561 I32 (*fp3)_((int,int,int));
a0d0e21e 1562 while (sp > mark) {
1563 sp[1] = sp[0];
1564 sp--;
1565 }
ecfc5424 1566 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1567 items = (*fp3)(CvXSUBANY(cv).any_i32,
1568 mark - stack_base + 1,
1569 items);
a0d0e21e 1570 sp = stack_base + items;
1571 }
1572 else {
1573 (void)(*CvXSUB(cv))(cv);
1574 }
1575 LEAVE;
1576 return pop_return();
1577 }
1578 else {
1579 AV* padlist = CvPADLIST(cv);
1580 SV** svp = AvARRAY(padlist);
1581 cx->blk_sub.cv = cv;
1582 cx->blk_sub.olddepth = CvDEPTH(cv);
1583 CvDEPTH(cv)++;
1584 if (CvDEPTH(cv) < 2)
1585 (void)SvREFCNT_inc(cv);
1586 else { /* save temporaries on recursion? */
1587 if (CvDEPTH(cv) == 100 && dowarn)
1588 warn("Deep recursion on subroutine \"%s\"",
1589 GvENAME(CvGV(cv)));
1590 if (CvDEPTH(cv) > AvFILL(padlist)) {
1591 AV *newpad = newAV();
748a9306 1592 AV *oldpad = (AV*)AvARRAY(svp[CvDEPTH(cv)-1]);
a0d0e21e 1593 I32 ix = AvFILL((AV*)svp[1]);
1594 svp = AvARRAY(svp[0]);
748a9306 1595 for ( ;ix > 0; ix--) {
a0d0e21e 1596 if (svp[ix] != &sv_undef) {
748a9306 1597 char *name = SvPVX(svp[ix]);
1598 if (SvFLAGS(svp[ix]) & SVf_FAKE) {
1599 /* outer lexical? */
1600 av_store(newpad, ix,
1601 SvREFCNT_inc(AvARRAY(oldpad)[ix]) );
1602 }
1603 else { /* our own lexical */
1604 if (*name == '@')
1605 av_store(newpad, ix, sv = (SV*)newAV());
1606 else if (*name == '%')
1607 av_store(newpad, ix, sv = (SV*)newHV());
1608 else
1609 av_store(newpad, ix, sv = NEWSV(0,0));
1610 SvPADMY_on(sv);
1611 }
a0d0e21e 1612 }
1613 else {
748a9306 1614 av_store(newpad, ix, sv = NEWSV(0,0));
a0d0e21e 1615 SvPADTMP_on(sv);
1616 }
1617 }
1618 if (cx->blk_sub.hasargs) {
1619 AV* av = newAV();
1620 av_extend(av, 0);
1621 av_store(newpad, 0, (SV*)av);
1622 AvFLAGS(av) = AVf_REIFY;
1623 }
1624 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1625 AvFILL(padlist) = CvDEPTH(cv);
1626 svp = AvARRAY(padlist);
1627 }
1628 }
1629 SAVESPTR(curpad);
1630 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1631 if (cx->blk_sub.hasargs) {
1632 AV* av = (AV*)curpad[0];
1633 SV** ary;
1634
1635 cx->blk_sub.savearray = GvAV(defgv);
1636 cx->blk_sub.argarray = av;
1637 GvAV(defgv) = cx->blk_sub.argarray;
1638 ++mark;
1639
1640 if (items >= AvMAX(av) + 1) {
1641 ary = AvALLOC(av);
1642 if (AvARRAY(av) != ary) {
1643 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1644 SvPVX(av) = (char*)ary;
1645 }
1646 if (items >= AvMAX(av) + 1) {
1647 AvMAX(av) = items - 1;
1648 Renew(ary,items+1,SV*);
1649 AvALLOC(av) = ary;
1650 SvPVX(av) = (char*)ary;
1651 }
1652 }
1653 Copy(mark,AvARRAY(av),items,SV*);
1654 AvFILL(av) = items - 1;
1655
1656 while (items--) {
1657 if (*mark)
1658 SvTEMP_off(*mark);
1659 mark++;
1660 }
1661 }
1662 RETURNOP(CvSTART(cv));
1663 }
1664 }
1665 else
1666 label = SvPV(sv,na);
1667 }
1668 else if (op->op_flags & OPf_SPECIAL) {
1669 if (! do_dump)
1670 DIE("goto must have label");
1671 }
1672 else
1673 label = cPVOP->op_pv;
1674
1675 if (label && *label) {
1676 OP *gotoprobe = 0;
1677
1678 /* find label */
1679
1680 lastgotoprobe = 0;
1681 *enterops = 0;
1682 for (ix = cxstack_ix; ix >= 0; ix--) {
1683 cx = &cxstack[ix];
1684 switch (cx->cx_type) {
1685 case CXt_SUB:
1686 gotoprobe = CvROOT(cx->blk_sub.cv);
1687 break;
1688 case CXt_EVAL:
1689 gotoprobe = eval_root; /* XXX not good for nested eval */
1690 break;
1691 case CXt_LOOP:
1692 gotoprobe = cx->blk_oldcop->op_sibling;
1693 break;
1694 case CXt_SUBST:
1695 continue;
1696 case CXt_BLOCK:
1697 if (ix)
1698 gotoprobe = cx->blk_oldcop->op_sibling;
1699 else
1700 gotoprobe = main_root;
1701 break;
1702 default:
1703 if (ix)
1704 DIE("panic: goto");
1705 else
1706 gotoprobe = main_root;
1707 break;
1708 }
1709 retop = dofindlabel(gotoprobe, label, enterops);
1710 if (retop)
1711 break;
1712 lastgotoprobe = gotoprobe;
1713 }
1714 if (!retop)
1715 DIE("Can't find label %s", label);
1716
1717 /* pop unwanted frames */
1718
1719 if (ix < cxstack_ix) {
1720 I32 oldsave;
1721
1722 if (ix < 0)
1723 ix = 0;
1724 dounwind(ix);
1725 TOPBLOCK(cx);
1726 oldsave = scopestack[scopestack_ix];
1727 LEAVE_SCOPE(oldsave);
1728 }
1729
1730 /* push wanted frames */
1731
748a9306 1732 if (*enterops && enterops[1]) {
a0d0e21e 1733 OP *oldop = op;
748a9306 1734 for (ix = 1; enterops[ix]; ix++) {
a0d0e21e 1735 op = enterops[ix];
1736 (*op->op_ppaddr)();
1737 }
1738 op = oldop;
1739 }
1740 }
1741
1742 if (do_dump) {
1743 restartop = retop;
1744 do_undump = TRUE;
1745
1746 my_unexec();
1747
1748 restartop = 0; /* hmm, must be GNU unexec().. */
1749 do_undump = FALSE;
1750 }
1751
748a9306 1752 if (stack == signalstack) {
1753 restartop = retop;
1754 longjmp(top_env, 3);
1755 }
1756
a0d0e21e 1757 RETURNOP(retop);
1758}
1759
1760PP(pp_exit)
1761{
1762 dSP;
1763 I32 anum;
1764
1765 if (MAXARG < 1)
1766 anum = 0;
1767 else
1768 anum = SvIVx(POPs);
1769 my_exit(anum);
1770 PUSHs(&sv_undef);
1771 RETURN;
1772}
1773
1774#ifdef NOTYET
1775PP(pp_nswitch)
1776{
1777 dSP;
1778 double value = SvNVx(GvSV(cCOP->cop_gv));
1779 register I32 match = I_32(value);
1780
1781 if (value < 0.0) {
1782 if (((double)match) > value)
1783 --match; /* was fractional--truncate other way */
1784 }
1785 match -= cCOP->uop.scop.scop_offset;
1786 if (match < 0)
1787 match = 0;
1788 else if (match > cCOP->uop.scop.scop_max)
1789 match = cCOP->uop.scop.scop_max;
1790 op = cCOP->uop.scop.scop_next[match];
1791 RETURNOP(op);
1792}
1793
1794PP(pp_cswitch)
1795{
1796 dSP;
1797 register I32 match;
1798
1799 if (multiline)
1800 op = op->op_next; /* can't assume anything */
1801 else {
1802 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
1803 match -= cCOP->uop.scop.scop_offset;
1804 if (match < 0)
1805 match = 0;
1806 else if (match > cCOP->uop.scop.scop_max)
1807 match = cCOP->uop.scop.scop_max;
1808 op = cCOP->uop.scop.scop_next[match];
1809 }
1810 RETURNOP(op);
1811}
1812#endif
1813
1814/* Eval. */
1815
1816static void
1817save_lines(array, sv)
1818AV *array;
1819SV *sv;
1820{
1821 register char *s = SvPVX(sv);
1822 register char *send = SvPVX(sv) + SvCUR(sv);
1823 register char *t;
1824 register I32 line = 1;
1825
1826 while (s && s < send) {
1827 SV *tmpstr = NEWSV(85,0);
1828
1829 sv_upgrade(tmpstr, SVt_PVMG);
1830 t = strchr(s, '\n');
1831 if (t)
1832 t++;
1833 else
1834 t = send;
1835
1836 sv_setpvn(tmpstr, s, t - s);
1837 av_store(array, line++, tmpstr);
1838 s = t;
1839 }
1840}
1841
1842static OP *
1843doeval(gimme)
1844int gimme;
1845{
1846 dSP;
1847 OP *saveop = op;
1848 HV *newstash;
748a9306 1849 AV* comppadlist;
a0d0e21e 1850
1851 in_eval = 1;
1852
1853 /* set up a scratch pad */
1854
1855 SAVEINT(padix);
1856 SAVESPTR(curpad);
1857 SAVESPTR(comppad);
1858 SAVESPTR(comppad_name);
1859 SAVEINT(comppad_name_fill);
1860 SAVEINT(min_intro_pending);
1861 SAVEINT(max_intro_pending);
748a9306 1862
1863 SAVESPTR(compcv);
1864 compcv = (CV*)NEWSV(1104,0);
1865 sv_upgrade((SV *)compcv, SVt_PVCV);
1866
a0d0e21e 1867 comppad = newAV();
1868 comppad_name = newAV();
1869 comppad_name_fill = 0;
1870 min_intro_pending = 0;
1871 av_push(comppad, Nullsv);
1872 curpad = AvARRAY(comppad);
1873 padix = 0;
1874
748a9306 1875 comppadlist = newAV();
1876 AvREAL_off(comppadlist);
1877 av_store(comppadlist, 0, SvREFCNT_inc((SV*)comppad_name));
1878 av_store(comppadlist, 1, SvREFCNT_inc((SV*)comppad));
1879 CvPADLIST(compcv) = comppadlist;
1880
a0d0e21e 1881 /* make sure we compile in the right package */
1882
1883 newstash = curcop->cop_stash;
1884 if (curstash != newstash) {
1885 SAVESPTR(curstash);
1886 curstash = newstash;
1887 }
1888 SAVESPTR(beginav);
1889 beginav = newAV();
1890 SAVEFREESV(beginav);
1891
1892 /* try to compile it */
1893
1894 eval_root = Nullop;
1895 error_count = 0;
1896 curcop = &compiling;
1897 curcop->cop_arybase = 0;
1898 rs = "\n";
1899 rslen = 1;
1900 rschar = '\n';
1901 rspara = 0;
1902 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
1903 if (yyparse() || error_count || !eval_root) {
1904 SV **newsp;
1905 I32 gimme;
1906 CONTEXT *cx;
1907 I32 optype;
1908
1909 op = saveop;
1910 if (eval_root) {
1911 op_free(eval_root);
1912 eval_root = Nullop;
1913 }
1914 POPBLOCK(cx,curpm);
1915 POPEVAL(cx);
1916 pop_return();
1917 lex_end();
1918 LEAVE;
1919 if (optype == OP_REQUIRE)
1920 DIE("%s", SvPVx(GvSV(gv_fetchpv("@",TRUE, SVt_PV)), na));
1921 rs = nrs;
1922 rslen = nrslen;
1923 rschar = nrschar;
1924 rspara = (nrslen == 2);
1925 RETPUSHUNDEF;
1926 }
1927 rs = nrs;
1928 rslen = nrslen;
1929 rschar = nrschar;
1930 rspara = (nrslen == 2);
1931 compiling.cop_line = 0;
748a9306 1932 SAVEFREESV(compcv);
a0d0e21e 1933 SAVEFREEOP(eval_root);
1934 if (gimme & G_ARRAY)
1935 list(eval_root);
1936 else
1937 scalar(eval_root);
1938
1939 DEBUG_x(dump_eval());
1940
1941 /* compiled okay, so do it */
1942
1943 RETURNOP(eval_start);
1944}
1945
1946PP(pp_require)
1947{
1948 dSP;
1949 register CONTEXT *cx;
1950 SV *sv;
1951 char *name;
1952 char *tmpname;
1953 SV** svp;
1954 I32 gimme = G_SCALAR;
1955 FILE *tryrsfp = 0;
1956
1957 sv = POPs;
1958 if (SvNIOK(sv) && !SvPOKp(sv)) {
1959 if (atof(patchlevel) + 0.000999 < SvNV(sv))
1960 DIE("Perl %3.3f required--this is only version %s, stopped",
1961 SvNV(sv),patchlevel);
1962 RETPUSHYES;
1963 }
1964 name = SvPV(sv, na);
1965 if (!*name)
1966 DIE("Null filename used");
1967 if (op->op_type == OP_REQUIRE &&
1968 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
1969 *svp != &sv_undef)
1970 RETPUSHYES;
1971
1972 /* prepare to compile file */
1973
1974 tmpname = savepv(name);
1975 if (*tmpname == '/' ||
1976 (*tmpname == '.' &&
1977 (tmpname[1] == '/' ||
748a9306 1978 (tmpname[1] == '.' && tmpname[2] == '/')))
1979#ifdef VMS
1980 || ((*tmpname == '[' || *tmpname == '<') &&
1981 (tmpname[1] == '-' || tmpname[1] == ']' || tmpname[1] == '>'))
1982#endif
1983 )
a0d0e21e 1984 {
1985 tryrsfp = fopen(tmpname,"r");
1986 }
1987 else {
1988 AV *ar = GvAVn(incgv);
1989 I32 i;
1990
1991 for (i = 0; i <= AvFILL(ar); i++) {
748a9306 1992#ifdef VMS
1993 if (tounixpath_ts(SvPVx(*av_fetch(ar, i, TRUE), na),buf) == NULL)
1994 croak("Error converting file specification %s",
1995 SvPVx(*av_fetch(ar, i, TRUE), na));
1996 strcat(buf,name);
1997#else
a0d0e21e 1998 (void)sprintf(buf, "%s/%s",
1999 SvPVx(*av_fetch(ar, i, TRUE), na), name);
748a9306 2000#endif
a0d0e21e 2001 tryrsfp = fopen(buf, "r");
2002 if (tryrsfp) {
2003 char *s = buf;
2004
2005 if (*s == '.' && s[1] == '/')
2006 s += 2;
2007 Safefree(tmpname);
2008 tmpname = savepv(s);
2009 break;
2010 }
2011 }
2012 }
2013 SAVESPTR(compiling.cop_filegv);
2014 compiling.cop_filegv = gv_fetchfile(tmpname);
2015 Safefree(tmpname);
2016 tmpname = Nullch;
2017 if (!tryrsfp) {
2018 if (op->op_type == OP_REQUIRE) {
2019 sprintf(tokenbuf,"Can't locate %s in @INC", name);
2020 if (instr(tokenbuf,".h "))
2021 strcat(tokenbuf," (change .h to .ph maybe?)");
2022 if (instr(tokenbuf,".ph "))
2023 strcat(tokenbuf," (did you run h2ph?)");
2024 DIE("%s",tokenbuf);
2025 }
2026
2027 RETPUSHUNDEF;
2028 }
2029
2030 /* Assume success here to prevent recursive requirement. */
2031 (void)hv_store(GvHVn(incgv), name, strlen(name),
2032 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2033
2034 ENTER;
2035 SAVETMPS;
2036 lex_start(sv_2mortal(newSVpv("",0)));
2037 rsfp = tryrsfp;
2038 name = savepv(name);
2039 SAVEFREEPV(name);
2040 SAVEI32(hints);
2041 hints = 0;
2042
2043 /* switch to eval mode */
2044
2045 push_return(op->op_next);
2046 PUSHBLOCK(cx, CXt_EVAL, SP);
2047 PUSHEVAL(cx, name, compiling.cop_filegv);
2048
2049 compiling.cop_line = 0;
2050
2051 PUTBACK;
2052 return doeval(G_SCALAR);
2053}
2054
2055PP(pp_dofile)
2056{
2057 return pp_require(ARGS);
2058}
2059
2060PP(pp_entereval)
2061{
2062 dSP;
2063 register CONTEXT *cx;
2064 dPOPss;
2065 I32 gimme = GIMME;
2066 char tmpbuf[32];
2067 STRLEN len;
2068
2069 if (!SvPV(sv,len) || !len)
2070 RETPUSHUNDEF;
748a9306 2071 TAINT_PROPER("eval");
a0d0e21e 2072
2073 ENTER;
a0d0e21e 2074 lex_start(sv);
748a9306 2075 SAVETMPS;
a0d0e21e 2076
2077 /* switch to eval mode */
2078
748a9306 2079 SAVESPTR(compiling.cop_filegv);
a0d0e21e 2080 sprintf(tmpbuf, "_<(eval %d)", ++evalseq);
2081 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2082 compiling.cop_line = 1;
2083 SAVEDELETE(defstash, savepv(tmpbuf), strlen(tmpbuf));
2084 SAVEI32(hints);
2085 hints = op->op_targ;
2086
2087 push_return(op->op_next);
2088 PUSHBLOCK(cx, CXt_EVAL, SP);
2089 PUSHEVAL(cx, 0, compiling.cop_filegv);
2090
2091 /* prepare to compile string */
2092
2093 if (perldb && curstash != debstash)
2094 save_lines(GvAV(compiling.cop_filegv), linestr);
2095 PUTBACK;
2096 return doeval(gimme);
2097}
2098
2099PP(pp_leaveeval)
2100{
2101 dSP;
2102 register SV **mark;
2103 SV **newsp;
2104 PMOP *newpm;
2105 I32 gimme;
2106 register CONTEXT *cx;
2107 OP *retop;
2108 I32 optype;
2109
2110 POPBLOCK(cx,newpm);
2111 POPEVAL(cx);
2112 retop = pop_return();
2113
2114 if (gimme == G_SCALAR) {
2115 if (op->op_private & OPpLEAVE_VOID)
2116 MARK = newsp;
2117 else {
2118 MARK = newsp + 1;
2119 if (MARK <= SP) {
2120 if (SvFLAGS(TOPs) & SVs_TEMP)
2121 *MARK = TOPs;
2122 else
2123 *MARK = sv_mortalcopy(TOPs);
2124 }
2125 else {
2126 MEXTEND(mark,0);
2127 *MARK = &sv_undef;
2128 }
2129 }
2130 SP = MARK;
2131 }
2132 else {
2133 for (mark = newsp + 1; mark <= SP; mark++)
2134 if (!(SvFLAGS(TOPs) & SVs_TEMP))
2135 *mark = sv_mortalcopy(*mark);
2136 /* in case LEAVE wipes old return values */
2137 }
2138 curpm = newpm; /* Don't pop $1 et al till now */
2139
2140 if (optype != OP_ENTEREVAL) {
2141 char *name = cx->blk_eval.old_name;
2142
2143 if (!(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp)) {
2144 /* Unassume the success we assumed earlier. */
748a9306 2145 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
a0d0e21e 2146
2147 if (optype == OP_REQUIRE)
2148 retop = die("%s did not return a true value", name);
2149 }
2150 }
2151
2152 lex_end();
2153 LEAVE;
2154 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2155
2156 RETURNOP(retop);
2157}
2158
a0d0e21e 2159PP(pp_entertry)
2160{
2161 dSP;
2162 register CONTEXT *cx;
2163 I32 gimme = GIMME;
2164
2165 ENTER;
2166 SAVETMPS;
2167
2168 push_return(cLOGOP->op_other->op_next);
2169 PUSHBLOCK(cx, CXt_EVAL, SP);
2170 PUSHEVAL(cx, 0, 0);
2171 eval_root = op; /* Only needed so that goto works right. */
2172
2173 in_eval = 1;
2174 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2175 RETURN;
2176}
2177
2178PP(pp_leavetry)
2179{
2180 dSP;
2181 register SV **mark;
2182 SV **newsp;
2183 PMOP *newpm;
2184 I32 gimme;
2185 register CONTEXT *cx;
2186 I32 optype;
2187
2188 POPBLOCK(cx,newpm);
2189 POPEVAL(cx);
2190 pop_return();
2191
2192 if (gimme == G_SCALAR) {
2193 if (op->op_private & OPpLEAVE_VOID)
2194 MARK = newsp;
2195 else {
2196 MARK = newsp + 1;
2197 if (MARK <= SP) {
2198 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2199 *MARK = TOPs;
2200 else
2201 *MARK = sv_mortalcopy(TOPs);
2202 }
2203 else {
2204 MEXTEND(mark,0);
2205 *MARK = &sv_undef;
2206 }
2207 }
2208 SP = MARK;
2209 }
2210 else {
2211 for (mark = newsp + 1; mark <= SP; mark++)
2212 if (!(SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP)))
2213 *mark = sv_mortalcopy(*mark);
2214 /* in case LEAVE wipes old return values */
2215 }
2216 curpm = newpm; /* Don't pop $1 et al till now */
2217
2218 LEAVE;
2219 sv_setpv(GvSV(gv_fetchpv("@",TRUE, SVt_PV)),"");
2220 RETURN;
2221}
2222
2223static void
2224doparseform(sv)
2225SV *sv;
2226{
2227 STRLEN len;
2228 register char *s = SvPV_force(sv, len);
2229 register char *send = s + len;
2230 register char *base;
2231 register I32 skipspaces = 0;
2232 bool noblank;
2233 bool repeat;
2234 bool postspace = FALSE;
2235 U16 *fops;
2236 register U16 *fpc;
2237 U16 *linepc;
2238 register I32 arg;
2239 bool ischop;
2240
2241 New(804, fops, (send - s)*3+2, U16); /* Almost certainly too long... */
2242 fpc = fops;
2243
2244 if (s < send) {
2245 linepc = fpc;
2246 *fpc++ = FF_LINEMARK;
2247 noblank = repeat = FALSE;
2248 base = s;
2249 }
2250
2251 while (s <= send) {
2252 switch (*s++) {
2253 default:
2254 skipspaces = 0;
2255 continue;
2256
2257 case '~':
2258 if (*s == '~') {
2259 repeat = TRUE;
2260 *s = ' ';
2261 }
2262 noblank = TRUE;
2263 s[-1] = ' ';
2264 /* FALL THROUGH */
2265 case ' ': case '\t':
2266 skipspaces++;
2267 continue;
2268
2269 case '\n': case 0:
2270 arg = s - base;
2271 skipspaces++;
2272 arg -= skipspaces;
2273 if (arg) {
2274 if (postspace) {
2275 *fpc++ = FF_SPACE;
2276 postspace = FALSE;
2277 }
2278 *fpc++ = FF_LITERAL;
2279 *fpc++ = arg;
2280 }
2281 if (s <= send)
2282 skipspaces--;
2283 if (skipspaces) {
2284 *fpc++ = FF_SKIP;
2285 *fpc++ = skipspaces;
2286 }
2287 skipspaces = 0;
2288 if (s <= send)
2289 *fpc++ = FF_NEWLINE;
2290 if (noblank) {
2291 *fpc++ = FF_BLANK;
2292 if (repeat)
2293 arg = fpc - linepc + 1;
2294 else
2295 arg = 0;
2296 *fpc++ = arg;
2297 }
2298 if (s < send) {
2299 linepc = fpc;
2300 *fpc++ = FF_LINEMARK;
2301 noblank = repeat = FALSE;
2302 base = s;
2303 }
2304 else
2305 s++;
2306 continue;
2307
2308 case '@':
2309 case '^':
2310 ischop = s[-1] == '^';
2311
2312 if (postspace) {
2313 *fpc++ = FF_SPACE;
2314 postspace = FALSE;
2315 }
2316 arg = (s - base) - 1;
2317 if (arg) {
2318 *fpc++ = FF_LITERAL;
2319 *fpc++ = arg;
2320 }
2321
2322 base = s - 1;
2323 *fpc++ = FF_FETCH;
2324 if (*s == '*') {
2325 s++;
2326 *fpc++ = 0;
2327 *fpc++ = FF_LINEGLOB;
2328 }
2329 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2330 arg = ischop ? 512 : 0;
2331 base = s - 1;
2332 while (*s == '#')
2333 s++;
2334 if (*s == '.') {
2335 char *f;
2336 s++;
2337 f = s;
2338 while (*s == '#')
2339 s++;
2340 arg |= 256 + (s - f);
2341 }
2342 *fpc++ = s - base; /* fieldsize for FETCH */
2343 *fpc++ = FF_DECIMAL;
2344 *fpc++ = arg;
2345 }
2346 else {
2347 I32 prespace = 0;
2348 bool ismore = FALSE;
2349
2350 if (*s == '>') {
2351 while (*++s == '>') ;
2352 prespace = FF_SPACE;
2353 }
2354 else if (*s == '|') {
2355 while (*++s == '|') ;
2356 prespace = FF_HALFSPACE;
2357 postspace = TRUE;
2358 }
2359 else {
2360 if (*s == '<')
2361 while (*++s == '<') ;
2362 postspace = TRUE;
2363 }
2364 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2365 s += 3;
2366 ismore = TRUE;
2367 }
2368 *fpc++ = s - base; /* fieldsize for FETCH */
2369
2370 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2371
2372 if (prespace)
2373 *fpc++ = prespace;
2374 *fpc++ = FF_ITEM;
2375 if (ismore)
2376 *fpc++ = FF_MORE;
2377 if (ischop)
2378 *fpc++ = FF_CHOP;
2379 }
2380 base = s;
2381 skipspaces = 0;
2382 continue;
2383 }
2384 }
2385 *fpc++ = FF_END;
2386
2387 arg = fpc - fops;
2388 { /* need to jump to the next word */
2389 int z;
2390 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2391 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2392 s = SvPVX(sv) + SvCUR(sv) + z;
2393 }
2394 Copy(fops, s, arg, U16);
2395 Safefree(fops);
2396 SvCOMPILED_on(sv);
2397}
2398