X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=toke.c;h=5a43c097b5c6c8a7086048e87aca2e08c93a982e;hb=5e79a27ab8657b40a1ba45b02fa151bd3d5fcd46;hp=d24eee9fd993e8866453b50535da141ba7d8df6a;hpb=c07a80fdfe3926b5eb0585b674aa5d1f57b32ade;p=p5sagit%2Fp5-mst-13.2.git diff --git a/toke.c b/toke.c index d24eee9..5a43c09 100644 --- a/toke.c +++ b/toke.c @@ -44,6 +44,7 @@ static I32 sublex_start _((void)); static int uni _((I32 f, char *s)); #endif static char * filter_gets _((SV *sv, FILE *fp)); +static void restore_rsfp _((void *f)); /* The following are arranged oddly so that the guard on the switch statement * can get by with a single comparison (if the compiler is smart enough). @@ -222,7 +223,7 @@ SV *line; SAVESPTR(linestr); SAVEPPTR(lex_brackstack); SAVEPPTR(lex_casestack); - SAVESPTR(rsfp); + SAVEDESTRUCTOR(restore_rsfp, rsfp); lex_state = LEX_NORMAL; lex_defer = 0; @@ -268,6 +269,19 @@ lex_end() } static void +restore_rsfp(f) +void *f; +{ + FILE *fp = (FILE*)f; + + if (rsfp == stdin) + clearerr(rsfp); + else if (rsfp && (rsfp != fp)) + fclose(rsfp); + rsfp = fp; +} + +static void incline(s) char *s; { @@ -1471,8 +1485,9 @@ yylex() if (*d++ == '-') { while (d = moreswitches(d)) ; if (perldb && !oldpdb || - minus_n && !oldn || - minus_p && !oldp) + ( minus_n || minus_p ) && !(oldn || oldp) ) + /* if we have already added "LINE: while (<>) {", + we must not do it again */ { sv_setpv(linestr, ""); oldoldbufptr = oldbufptr = s = SvPVX(linestr); @@ -1863,6 +1878,24 @@ yylex() if (expect == XSTATE && isALPHA(tmp) && (s == SvPVX(linestr)+1 || s[-2] == '\n') ) { + if (in_eval && !rsfp) { + d = bufend; + while (s < d) { + if (*s++ == '\n') { + incline(s); + if (strnEQ(s,"=cut",4)) { + s = strchr(s,'\n'); + if (s) + s++; + else + s = d; + incline(s); + goto retry; + } + } + } + goto retry; + } s = bufend; doextract = TRUE; goto retry; @@ -2283,10 +2316,9 @@ yylex() if (tmp < 0) { /* second-class keyword? */ GV* gv; if (expect != XOPERATOR && - (*s != ':' || s[1] != ':') && - (gv = gv_fetchpv(tokenbuf,FALSE, SVt_PVCV)) && - (GvFLAGS(gv) & GVf_IMPORTED) && - GvCV(gv)) + (*s != ':' || s[1] != ':') && + (gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) && + GvIMPORTED_CV(gv)) { tmp = 0; } @@ -2401,8 +2433,8 @@ yylex() if (gv && GvCV(gv)) { CV* cv = GvCV(gv); - nextval[nexttoke].opval = yylval.opval; if (*s == '(') { + nextval[nexttoke].opval = yylval.opval; expect = XTERM; force_next(WORD); yylval.ival = 0; @@ -2413,6 +2445,9 @@ yylex() tokenbuf, tokenbuf); last_lop = oldbufptr; last_lop_op = OP_ENTERSUB; + /* Resolve to GV now. */ + op_free(yylval.opval); + yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); /* Is there a prototype? */ if (SvPOK(cv)) { STRLEN len; @@ -2426,6 +2461,7 @@ yylex() PREBLOCK(LSTOPSUB); } } + nextval[nexttoke].opval = yylval.opval; expect = XTERM; force_next(WORD); TOKEN(NOAMP); @@ -2478,14 +2514,14 @@ yylex() GV *gv; /*SUPPRESS 560*/ - if (!in_eval || tokenbuf[2] == 'D') { + if (rsfp && (!in_eval || tokenbuf[2] == 'D')) { char dname[256]; char *pname = "main"; if (tokenbuf[2] == 'D') pname = HvNAME(curstash ? curstash : defstash); sprintf(dname,"%s::DATA", pname); gv = gv_fetchpv(dname,TRUE, SVt_PVIO); - SvMULTI_on(gv); + GvMULTI_on(gv); if (!GvIO(gv)) GvIOp(gv) = newIO(); IoIFP(GvIOp(gv)) = rsfp;