docfix from Peter Scott <Peter@PSDT.com>.
[p5sagit/p5-mst-13.2.git] / toke.c
diff --git a/toke.c b/toke.c
index e47853e..f368367 100644 (file)
--- a/toke.c
+++ b/toke.c
 static char ident_too_long[] = "Identifier too long";
 
 static void restore_rsfp(pTHXo_ void *f);
+#ifndef PERL_NO_UTF16_FILTER
+static I32 utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen);
+static I32 utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen);
+#endif
 
 #define XFAKEBRACK 128
 #define XENUMMASK 127
@@ -326,36 +330,6 @@ S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
 }
 #endif
 
-#ifndef PERL_NO_UTF16_FILTER
-STATIC I32
-S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
-{
-    I32 count = FILTER_READ(idx+1, sv, maxlen);
-    if (count) {
-       U8* tmps;
-       U8* tend;
-       New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
-       tend = utf16_to_utf8((U16*)SvPVX(sv), tmps, SvCUR(sv));
-       sv_usepvn(sv, (char*)tmps, tend - tmps);
-    }
-    return count;
-}
-
-STATIC I32
-S_utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
-{
-    I32 count = FILTER_READ(idx+1, sv, maxlen);
-    if (count) {
-       U8* tmps;
-       U8* tend;
-       New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
-       tend = utf16_to_utf8_reversed((U16*)SvPVX(sv), tmps, SvCUR(sv));
-       sv_usepvn(sv, (char*)tmps, tend - tmps);
-    }
-    return count;
-}
-#endif
-
 /*
  * Perl_lex_start
  * Initialize variables.  Uses the Perl save_stack to save its state (for
@@ -2545,7 +2519,13 @@ Perl_yylex(pTHX)
                }
            } 
            if (bof)
+           {
+               PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
+               /* Shouldn't this wsallow_bom() be earlier, e.g.
+                * immediately after where bof is set?  Currently you can't
+                * have e.g. a UTF16 sharpbang line. --Mike Guy */
                s = swallow_bom((U8*)s);
+           }
            incline(s);
        } while (PL_doextract);
        PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
@@ -7422,7 +7402,7 @@ S_swallow_bom(pTHX_ U8 *s)
                Perl_croak(aTHX_ "Unsupported script encoding");
 #ifndef PERL_NO_UTF16_FILTER
            s += 2;
-           filter_add(S_utf16rev_textfilter, NULL);
+           filter_add(utf16rev_textfilter, NULL);
            New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
            PL_bufend = (char*)utf16_to_utf8((U16*)s, news,
                                             PL_bufend - (char*)s);
@@ -7436,7 +7416,7 @@ S_swallow_bom(pTHX_ U8 *s)
        if (s[1] == 0xFF) {   /* UTF-16 big-endian */
 #ifndef PERL_NO_UTF16_FILTER
            U8 *news;
-           filter_add(S_utf16_textfilter, NULL);
+           filter_add(utf16_textfilter, NULL);
            New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
            PL_bufend = (char*)utf16_to_utf8((U16*)s, news,
                                             PL_bufend - (char*)s);
@@ -7481,3 +7461,33 @@ restore_rsfp(pTHXo_ void *f)
        PerlIO_close(PL_rsfp);
     PL_rsfp = fp;
 }
+
+#ifndef PERL_NO_UTF16_FILTER
+static I32
+utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
+{
+    I32 count = FILTER_READ(idx+1, sv, maxlen);
+    if (count) {
+       U8* tmps;
+       U8* tend;
+       New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
+       tend = utf16_to_utf8((U16*)SvPVX(sv), tmps, SvCUR(sv));
+       sv_usepvn(sv, (char*)tmps, tend - tmps);
+    }
+    return count;
+}
+
+static I32
+utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
+{
+    I32 count = FILTER_READ(idx+1, sv, maxlen);
+    if (count) {
+       U8* tmps;
+       U8* tend;
+       New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
+       tend = utf16_to_utf8_reversed((U16*)SvPVX(sv), tmps, SvCUR(sv));
+       sv_usepvn(sv, (char*)tmps, tend - tmps);
+    }
+    return count;
+}
+#endif