line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* stolen_chunk_of_toke.c - from perl 5.8.8 toke.c |
2
|
|
|
|
|
|
|
* |
3
|
|
|
|
|
|
|
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
4
|
|
|
|
|
|
|
* 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others |
5
|
|
|
|
|
|
|
* |
6
|
|
|
|
|
|
|
* You may distribute under the terms of either the GNU General Public |
7
|
|
|
|
|
|
|
* License or the Artistic License, as specified in the README file. |
8
|
|
|
|
|
|
|
* |
9
|
|
|
|
|
|
|
*/ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
/* |
12
|
|
|
|
|
|
|
* "It all comes from here, the stench and the peril." --Frodo |
13
|
|
|
|
|
|
|
*/ |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
/* |
16
|
|
|
|
|
|
|
* this is all blatantly stolen. I sincerely hopes it doesn't fuck anything |
17
|
|
|
|
|
|
|
* up but if it does blame me (Matt S Trout), not the poor original authors |
18
|
|
|
|
|
|
|
*/ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
/* the following #defines are stolen from assorted headers, not toke.c (mst) */ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#define skipspace(a) S_skipspace(aTHX_ a, 0) |
23
|
|
|
|
|
|
|
#define peekspace(a) S_skipspace(aTHX_ a, 1) |
24
|
|
|
|
|
|
|
#define skipspace_force(a) S_skipspace(aTHX_ a, 2) |
25
|
|
|
|
|
|
|
#define incline(a) S_incline(aTHX_ a) |
26
|
|
|
|
|
|
|
#define filter_gets(a,b,c) S_filter_gets(aTHX_ a,b,c) |
27
|
|
|
|
|
|
|
#define scan_str(a,b,c) S_scan_str(aTHX_ a,b,c) |
28
|
|
|
|
|
|
|
#define scan_word(a,b,c,d,e) S_scan_word(aTHX_ a,b,c,d,e) |
29
|
|
|
|
|
|
|
#define scan_ident(a,b,c,d,e) S_scan_ident(aTHX_ a,b,c,d,e) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
STATIC void S_incline(pTHX_ char *s); |
32
|
|
|
|
|
|
|
STATIC char* S_skipspace(pTHX_ char *s, int incline); |
33
|
|
|
|
|
|
|
STATIC char * S_filter_gets(pTHX_ SV *sv, PerlIO *fp, STRLEN append); |
34
|
|
|
|
|
|
|
STATIC char* S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims); |
35
|
|
|
|
|
|
|
STATIC char* S_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#define DPTR2FPTR(t,p) ((t)PTR2nat(p)) /* data pointer to function pointer */ |
38
|
|
|
|
|
|
|
#define FPTR2DPTR(t,p) ((t)PTR2nat(p)) /* function pointer to data pointer */ |
39
|
|
|
|
|
|
|
#define PTR2nat(p) (PTRV)(p) /* pointer to integer of PTRSIZE */ |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
/* conditionalise these two because as of 5.9.5 we already get them from |
42
|
|
|
|
|
|
|
the headers (mst) */ |
43
|
|
|
|
|
|
|
#ifndef Newx |
44
|
|
|
|
|
|
|
#define Newx(v,n,t) (v = (MEM_WRAP_CHECK_(n,t) (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))) |
45
|
|
|
|
|
|
|
#endif |
46
|
|
|
|
|
|
|
#ifndef SvPVX_const |
47
|
|
|
|
|
|
|
#define SvPVX_const(sv) ((const char*) (0 + SvPVX(sv))) |
48
|
|
|
|
|
|
|
#endif |
49
|
|
|
|
|
|
|
#ifndef MEM_WRAP_CHECK_ |
50
|
|
|
|
|
|
|
#define MEM_WRAP_CHECK_(n,t) MEM_WRAP_CHECK(n,t), |
51
|
|
|
|
|
|
|
#endif |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#define SvPV_renew(sv,n) \ |
54
|
|
|
|
|
|
|
STMT_START { SvLEN_set(sv, n); \ |
55
|
|
|
|
|
|
|
SvPV_set((sv), (MEM_WRAP_CHECK_(n,char) \ |
56
|
|
|
|
|
|
|
(char*)saferealloc((Malloc_t)SvPVX(sv), \ |
57
|
|
|
|
|
|
|
(MEM_SIZE)((n))))); \ |
58
|
|
|
|
|
|
|
} STMT_END |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x))) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
/* On MacOS, respect nonbreaking spaces */ |
63
|
|
|
|
|
|
|
#ifdef MACOS_TRADITIONAL |
64
|
|
|
|
|
|
|
#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') |
65
|
|
|
|
|
|
|
#else |
66
|
|
|
|
|
|
|
#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') |
67
|
|
|
|
|
|
|
#endif |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
/* |
70
|
|
|
|
|
|
|
* Normally, during compile time, PL_curcop == &PL_compiling is true. However, |
71
|
|
|
|
|
|
|
* Devel::Declare makes the interpreter call back to perl during compile time, |
72
|
|
|
|
|
|
|
* which temporarily enters runtime. Then perl space calls various functions |
73
|
|
|
|
|
|
|
* from this file, which are designed to work during compile time. They all |
74
|
|
|
|
|
|
|
* happen to operate on PL_curcop, not PL_compiling. That doesn't make a |
75
|
|
|
|
|
|
|
* difference in the core, but it does for Devel::Declare, which operates at |
76
|
|
|
|
|
|
|
* runtime, but still wants to mangle the things that are about to be compiled. |
77
|
|
|
|
|
|
|
* That's why we define our own PL_curcop and make it point to PL_compiling |
78
|
|
|
|
|
|
|
* here. |
79
|
|
|
|
|
|
|
*/ |
80
|
|
|
|
|
|
|
#undef PL_curcop |
81
|
|
|
|
|
|
|
#define PL_curcop (&PL_compiling) |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#define LEX_NORMAL 10 /* normal code (ie not within "...") */ |
86
|
|
|
|
|
|
|
#define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */ |
87
|
|
|
|
|
|
|
#define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */ |
88
|
|
|
|
|
|
|
#define LEX_INTERPPUSH 7 /* starting a new sublex parse level */ |
89
|
|
|
|
|
|
|
#define LEX_INTERPSTART 6 /* expecting the start of a $var */ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
/* at end of code, eg "$x" followed by: */ |
92
|
|
|
|
|
|
|
#define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */ |
93
|
|
|
|
|
|
|
#define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of |
96
|
|
|
|
|
|
|
string or after \E, $foo, etc */ |
97
|
|
|
|
|
|
|
#define LEX_INTERPCONST 2 /* NOT USED */ |
98
|
|
|
|
|
|
|
#define LEX_FORMLINE 1 /* expecting a format line */ |
99
|
|
|
|
|
|
|
#define LEX_KNOWNEXT 0 /* next token known; just return it */ |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
/* and these two are my own madness (mst) */ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#if PERL_REVISION == 5 && PERL_VERSION == 8 && PERL_SUBVERSION >= 8 |
104
|
|
|
|
|
|
|
#define PERL_5_8_8_PLUS |
105
|
|
|
|
|
|
|
#endif |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#if PERL_REVISION == 5 && PERL_VERSION > 8 |
108
|
|
|
|
|
|
|
#define PERL_5_9_PLUS |
109
|
|
|
|
|
|
|
#endif |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#if !defined(PERL_5_9_PLUS) && defined(PERL_IMPLICIT_CONTEXT) |
112
|
|
|
|
|
|
|
/* These two are not exported from the core on Windows. With 5.9+ |
113
|
|
|
|
|
|
|
it's not an issue, because they're part of the PL_parser structure, |
114
|
|
|
|
|
|
|
which is exported. On multiplicity/thread builds we can work |
115
|
|
|
|
|
|
|
around the lack of export by this formulation, where we provide |
116
|
|
|
|
|
|
|
a substitute implementation of the unexported accessor functions. |
117
|
|
|
|
|
|
|
On single-interpreter builds we can't, because access is directly |
118
|
|
|
|
|
|
|
via symbols that are not exported. */ |
119
|
|
|
|
|
|
|
# define Perl_Ilinestart_ptr my_Ilinestart_ptr |
120
|
|
|
|
|
|
|
char **my_Ilinestart_ptr(pTHX) { return &(aTHX->Ilinestart); } |
121
|
|
|
|
|
|
|
# define Perl_Isublex_info_ptr my_Isublex_info_ptr |
122
|
|
|
|
|
|
|
static SUBLEXINFO *my_Isublex_info_ptr(pTHX) { return &(aTHX->Isublex_info); } |
123
|
|
|
|
|
|
|
#endif |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#ifdef PERL_5_9_PLUS |
126
|
|
|
|
|
|
|
/* 5.9+ moves a bunch of things to a PL_parser struct so we need to |
127
|
|
|
|
|
|
|
declare the backcompat macros for things to still work (mst) */ |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
/* XXX temporary backwards compatibility */ |
130
|
|
|
|
|
|
|
#define PL_lex_brackets (PL_parser->lex_brackets) |
131
|
|
|
|
|
|
|
#define PL_lex_brackstack (PL_parser->lex_brackstack) |
132
|
|
|
|
|
|
|
#define PL_lex_casemods (PL_parser->lex_casemods) |
133
|
|
|
|
|
|
|
#define PL_lex_casestack (PL_parser->lex_casestack) |
134
|
|
|
|
|
|
|
#define PL_lex_defer (PL_parser->lex_defer) |
135
|
|
|
|
|
|
|
#define PL_lex_dojoin (PL_parser->lex_dojoin) |
136
|
|
|
|
|
|
|
#define PL_lex_expect (PL_parser->lex_expect) |
137
|
|
|
|
|
|
|
#define PL_lex_formbrack (PL_parser->lex_formbrack) |
138
|
|
|
|
|
|
|
#define PL_lex_inpat (PL_parser->lex_inpat) |
139
|
|
|
|
|
|
|
#define PL_lex_inwhat (PL_parser->lex_inwhat) |
140
|
|
|
|
|
|
|
#define PL_lex_op (PL_parser->lex_op) |
141
|
|
|
|
|
|
|
#define PL_lex_repl (PL_parser->lex_repl) |
142
|
|
|
|
|
|
|
#define PL_lex_starts (PL_parser->lex_starts) |
143
|
|
|
|
|
|
|
#define PL_lex_stuff (PL_parser->lex_stuff) |
144
|
|
|
|
|
|
|
#define PL_multi_start (PL_parser->multi_start) |
145
|
|
|
|
|
|
|
#define PL_multi_open (PL_parser->multi_open) |
146
|
|
|
|
|
|
|
#define PL_multi_close (PL_parser->multi_close) |
147
|
|
|
|
|
|
|
#define PL_pending_ident (PL_parser->pending_ident) |
148
|
|
|
|
|
|
|
#define PL_preambled (PL_parser->preambled) |
149
|
|
|
|
|
|
|
#define PL_sublex_info (PL_parser->sublex_info) |
150
|
|
|
|
|
|
|
#define PL_linestr (PL_parser->linestr) |
151
|
|
|
|
|
|
|
#define PL_sublex_info (PL_parser->sublex_info) |
152
|
|
|
|
|
|
|
#define PL_linestr (PL_parser->linestr) |
153
|
|
|
|
|
|
|
#define PL_expect (PL_parser->expect) |
154
|
|
|
|
|
|
|
#define PL_copline (PL_parser->copline) |
155
|
|
|
|
|
|
|
#define PL_bufptr (PL_parser->bufptr) |
156
|
|
|
|
|
|
|
#define PL_oldbufptr (PL_parser->oldbufptr) |
157
|
|
|
|
|
|
|
#define PL_oldoldbufptr (PL_parser->oldoldbufptr) |
158
|
|
|
|
|
|
|
#define PL_linestart (PL_parser->linestart) |
159
|
|
|
|
|
|
|
#define PL_bufend (PL_parser->bufend) |
160
|
|
|
|
|
|
|
#define PL_last_uni (PL_parser->last_uni) |
161
|
|
|
|
|
|
|
#define PL_last_lop (PL_parser->last_lop) |
162
|
|
|
|
|
|
|
#define PL_last_lop_op (PL_parser->last_lop_op) |
163
|
|
|
|
|
|
|
#define PL_lex_state (PL_parser->lex_state) |
164
|
|
|
|
|
|
|
#define PL_rsfp (PL_parser->rsfp) |
165
|
|
|
|
|
|
|
#define PL_rsfp_filters (PL_parser->rsfp_filters) |
166
|
|
|
|
|
|
|
#define PL_in_my (PL_parser->in_my) |
167
|
|
|
|
|
|
|
#define PL_in_my_stash (PL_parser->in_my_stash) |
168
|
|
|
|
|
|
|
#define PL_tokenbuf (PL_parser->tokenbuf) |
169
|
|
|
|
|
|
|
#define PL_multi_end (PL_parser->multi_end) |
170
|
|
|
|
|
|
|
#define PL_error_count (PL_parser->error_count) |
171
|
|
|
|
|
|
|
#define PL_nexttoke (PL_parser->nexttoke) |
172
|
|
|
|
|
|
|
/* these are from the non-PERL_MAD path but I don't -think- I need |
173
|
|
|
|
|
|
|
the PERL_MAD stuff since my code isn't really populating things (mst) */ |
174
|
|
|
|
|
|
|
# ifdef PERL_MAD |
175
|
|
|
|
|
|
|
# define PL_curforce (PL_parser->curforce) |
176
|
|
|
|
|
|
|
# define PL_lasttoke (PL_parser->lasttoke) |
177
|
|
|
|
|
|
|
# else |
178
|
|
|
|
|
|
|
# define PL_nexttype (PL_parser->nexttype) |
179
|
|
|
|
|
|
|
# define PL_nextval (PL_parser->nextval) |
180
|
|
|
|
|
|
|
# endif |
181
|
|
|
|
|
|
|
/* end of backcompat macros from 5.9 toke.c (mst) */ |
182
|
|
|
|
|
|
|
#endif |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
/* when ccflags include -DDEBUGGING we need this for earlier 5.8 perls */ |
185
|
|
|
|
|
|
|
#ifndef SvPV_nolen_const |
186
|
|
|
|
|
|
|
#define SvPV_nolen_const SvPV_nolen |
187
|
|
|
|
|
|
|
#endif |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
/* utf8_to_uvchr_buf() not defined in earlier perls, but less-capable |
190
|
|
|
|
|
|
|
* substitute is available */ |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
#ifndef utf8_to_uvchr_buf |
193
|
|
|
|
|
|
|
#define utf8_to_uvchr_buf(s, e, lp) ((e), utf8_to_uvchr(s, lp)) |
194
|
|
|
|
|
|
|
#endif |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
#ifndef isIDFIRST_lazy_if_safe |
197
|
|
|
|
|
|
|
# define isIDFIRST_lazy_if_safe(p,e,UTF) \ |
198
|
|
|
|
|
|
|
((! UTF || p > e) ? isIDFIRST_lazy_if(p,UTF) : 0) |
199
|
|
|
|
|
|
|
#endif |
200
|
|
|
|
|
|
|
#ifndef isALNUM_lazy_if_safe |
201
|
|
|
|
|
|
|
# define isALNUM_lazy_if_safe(p,e,UTF) \ |
202
|
|
|
|
|
|
|
((! UTF || p > e) ? isALNUM_lazy_if(p,UTF) : 0) |
203
|
|
|
|
|
|
|
#endif |
204
|
|
|
|
|
|
|
#ifndef isALNUM_utf8_safe |
205
|
|
|
|
|
|
|
# define isALNUM_utf8_safe(p,e) ((p > e) ? isALNUM_utf8(p) : 0) |
206
|
|
|
|
|
|
|
#endif |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
/* and now we're back to the toke.c stuff again (mst) */ |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
static const char ident_too_long[] = |
211
|
|
|
|
|
|
|
"Identifier too long"; |
212
|
|
|
|
|
|
|
static const char c_without_g[] = |
213
|
|
|
|
|
|
|
"Use of /c modifier is meaningless without /g"; |
214
|
|
|
|
|
|
|
static const char c_in_subst[] = |
215
|
|
|
|
|
|
|
"Use of /c modifier is meaningless in s///"; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
#ifdef USE_UTF8_SCRIPTS |
218
|
|
|
|
|
|
|
# define UTF (!IN_BYTES) |
219
|
|
|
|
|
|
|
#else |
220
|
|
|
|
|
|
|
# define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8)) |
221
|
|
|
|
|
|
|
#endif |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
/* Invoke the idxth filter function for the current rsfp. */ |
224
|
|
|
|
|
|
|
/* maxlen 0 = read one text line */ |
225
|
|
|
|
|
|
|
I32 |
226
|
0
|
|
|
|
|
|
Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
227
|
|
|
|
|
|
|
{ |
228
|
|
|
|
|
|
|
filter_t funcp; |
229
|
0
|
|
|
|
|
|
SV *datasv = NULL; |
230
|
|
|
|
|
|
|
|
231
|
0
|
0
|
|
|
|
|
if (!PL_rsfp_filters) |
232
|
0
|
|
|
|
|
|
return -1; |
233
|
0
|
0
|
|
|
|
|
if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
234
|
|
|
|
|
|
|
/* Provide a default input filter to make life easy. */ |
235
|
|
|
|
|
|
|
/* Note that we append to the line. This is handy. */ |
236
|
|
|
|
|
|
|
DEBUG_P(PerlIO_printf(Perl_debug_log, |
237
|
|
|
|
|
|
|
"filter_read %d: from rsfp\n", idx)); |
238
|
0
|
0
|
|
|
|
|
if (maxlen) { |
239
|
|
|
|
|
|
|
/* Want a block */ |
240
|
|
|
|
|
|
|
int len ; |
241
|
0
|
|
|
|
|
|
const int old_len = SvCUR(buf_sv); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
/* ensure buf_sv is large enough */ |
244
|
0
|
0
|
|
|
|
|
SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ; |
|
|
0
|
|
|
|
|
|
245
|
0
|
0
|
|
|
|
|
if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
246
|
0
|
0
|
|
|
|
|
if (PerlIO_error(PL_rsfp)) |
247
|
0
|
|
|
|
|
|
return -1; /* error */ |
248
|
|
|
|
|
|
|
else |
249
|
0
|
|
|
|
|
|
return 0 ; /* end of file */ |
250
|
|
|
|
|
|
|
} |
251
|
0
|
|
|
|
|
|
SvCUR_set(buf_sv, old_len + len) ; |
252
|
|
|
|
|
|
|
} else { |
253
|
|
|
|
|
|
|
/* Want a line */ |
254
|
0
|
0
|
|
|
|
|
if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
255
|
0
|
0
|
|
|
|
|
if (PerlIO_error(PL_rsfp)) |
256
|
0
|
|
|
|
|
|
return -1; /* error */ |
257
|
|
|
|
|
|
|
else |
258
|
0
|
|
|
|
|
|
return 0 ; /* end of file */ |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
} |
261
|
0
|
|
|
|
|
|
return SvCUR(buf_sv); |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
/* Skip this filter slot if filter has been deleted */ |
264
|
0
|
0
|
|
|
|
|
if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
|
|
0
|
|
|
|
|
|
265
|
|
|
|
|
|
|
DEBUG_P(PerlIO_printf(Perl_debug_log, |
266
|
|
|
|
|
|
|
"filter_read %d: skipped (filter deleted)\n", |
267
|
|
|
|
|
|
|
idx)); |
268
|
0
|
|
|
|
|
|
return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
/* Get function pointer hidden within datasv */ |
271
|
0
|
|
|
|
|
|
funcp = DPTR2FPTR(filter_t, IoANY(datasv)); |
272
|
|
|
|
|
|
|
DEBUG_P(PerlIO_printf(Perl_debug_log, |
273
|
|
|
|
|
|
|
"filter_read %d: via function %p (%s)\n", |
274
|
|
|
|
|
|
|
idx, datasv, SvPV_nolen_const(datasv))); |
275
|
|
|
|
|
|
|
/* Call function. The function is expected to */ |
276
|
|
|
|
|
|
|
/* call "FILTER_READ(idx+1, buf_sv)" first. */ |
277
|
|
|
|
|
|
|
/* Return: <0:error, =0:eof, >0:not eof */ |
278
|
0
|
|
|
|
|
|
return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
STATIC char * |
282
|
32
|
|
|
|
|
|
S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
283
|
|
|
|
|
|
|
{ |
284
|
|
|
|
|
|
|
#ifdef PERL_CR_FILTER |
285
|
|
|
|
|
|
|
if (!PL_rsfp_filters) { |
286
|
|
|
|
|
|
|
filter_add(S_cr_textfilter,NULL); |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
#endif |
289
|
32
|
50
|
|
|
|
|
if (PL_rsfp_filters) { |
290
|
32
|
100
|
|
|
|
|
if (!append) |
291
|
20
|
|
|
|
|
|
SvCUR_set(sv, 0); /* start with empty line */ |
292
|
32
|
50
|
|
|
|
|
if (FILTER_READ(0, sv, 0) > 0) |
293
|
32
|
|
|
|
|
|
return ( SvPVX(sv) ) ; |
294
|
|
|
|
|
|
|
else |
295
|
0
|
|
|
|
|
|
return Nullch ; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
else |
298
|
0
|
|
|
|
|
|
return (sv_gets(sv, fp, append)); |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
/* |
302
|
|
|
|
|
|
|
* S_skipspace |
303
|
|
|
|
|
|
|
* Called to gobble the appropriate amount and type of whitespace. |
304
|
|
|
|
|
|
|
* Skips comments as well. |
305
|
|
|
|
|
|
|
*/ |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
STATIC char * |
308
|
506
|
|
|
|
|
|
S_skipspace(pTHX_ register char *s, int incline) |
309
|
|
|
|
|
|
|
{ |
310
|
506
|
50
|
|
|
|
|
if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
|
|
0
|
|
|
|
|
|
311
|
0
|
0
|
|
|
|
|
while (s < PL_bufend && SPACE_OR_TAB(*s)) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
312
|
0
|
|
|
|
|
|
s++; |
313
|
0
|
|
|
|
|
|
return s; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
for (;;) { |
316
|
|
|
|
|
|
|
STRLEN prevlen; |
317
|
|
|
|
|
|
|
SSize_t oldprevlen, oldoldprevlen; |
318
|
518
|
|
|
|
|
|
SSize_t oldloplen = 0, oldunilen = 0; |
319
|
946
|
100
|
|
|
|
|
while (s < PL_bufend && isSPACE(*s)) { |
|
|
100
|
|
|
|
|
|
320
|
428
|
100
|
|
|
|
|
if (*s++ == '\n' && ((incline == 2) || (PL_in_eval && !PL_rsfp && !incline))) |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
321
|
3
|
|
|
|
|
|
incline(s); |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
/* comment */ |
325
|
518
|
100
|
|
|
|
|
if (s < PL_bufend && *s == '#') { |
|
|
100
|
|
|
|
|
|
326
|
47
|
50
|
|
|
|
|
while (s < PL_bufend && *s != '\n') |
|
|
100
|
|
|
|
|
|
327
|
42
|
|
|
|
|
|
s++; |
328
|
5
|
50
|
|
|
|
|
if (s < PL_bufend) { |
329
|
5
|
|
|
|
|
|
s++; |
330
|
5
|
50
|
|
|
|
|
if (PL_in_eval && !PL_rsfp && !incline) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
331
|
0
|
|
|
|
|
|
incline(s); |
332
|
0
|
|
|
|
|
|
continue; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
/* also skip leading whitespace on the beginning of a line before deciding |
338
|
|
|
|
|
|
|
* whether or not to recharge the linestr. --rafl |
339
|
|
|
|
|
|
|
*/ |
340
|
524
|
100
|
|
|
|
|
while (s < PL_bufend && isSPACE(*s)) { |
|
|
100
|
|
|
|
|
|
341
|
6
|
50
|
|
|
|
|
if (*s++ == '\n' && PL_in_eval && !PL_rsfp && !incline) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
342
|
0
|
|
|
|
|
|
incline(s); |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
/* only continue to recharge the buffer if we're at the end |
346
|
|
|
|
|
|
|
* of the buffer, we're not reading from a source filter, and |
347
|
|
|
|
|
|
|
* we're in normal lexing mode |
348
|
|
|
|
|
|
|
*/ |
349
|
518
|
100
|
|
|
|
|
if (s < PL_bufend || !PL_rsfp || PL_lex_inwhat || |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
350
|
12
|
|
|
|
|
|
PL_lex_state == LEX_FORMLINE) |
351
|
506
|
|
|
|
|
|
return s; |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
/* try to recharge the buffer */ |
354
|
12
|
50
|
|
|
|
|
if ((s = filter_gets(PL_linestr, PL_rsfp, |
355
|
|
|
|
|
|
|
(prevlen = SvCUR(PL_linestr)))) == Nullch) |
356
|
|
|
|
|
|
|
{ |
357
|
|
|
|
|
|
|
/* end of file. Add on the -p or -n magic */ |
358
|
0
|
0
|
|
|
|
|
if (PL_minus_p) { |
359
|
0
|
|
|
|
|
|
sv_setpv(PL_linestr, |
360
|
|
|
|
|
|
|
";}continue{print or die qq(-p destination: $!\\n);}"); |
361
|
0
|
|
|
|
|
|
PL_minus_n = PL_minus_p = 0; |
362
|
|
|
|
|
|
|
} |
363
|
0
|
0
|
|
|
|
|
else if (PL_minus_n) { |
364
|
0
|
|
|
|
|
|
sv_setpvn(PL_linestr, ";}", 2); |
365
|
0
|
|
|
|
|
|
PL_minus_n = 0; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
else |
368
|
0
|
|
|
|
|
|
sv_setpvn(PL_linestr,";", 1); |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
/* reset variables for next time we lex */ |
371
|
0
|
|
|
|
|
|
PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
372
|
0
|
|
|
|
|
|
= SvPVX(PL_linestr); |
373
|
0
|
|
|
|
|
|
PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
374
|
0
|
|
|
|
|
|
PL_last_lop = PL_last_uni = Nullch; |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
/* In perl versions previous to p4-rawid: //depot/perl@32954 -P |
377
|
|
|
|
|
|
|
* preprocessors were supported here. We don't support -P at all, even |
378
|
|
|
|
|
|
|
* on perls that support it, and use the following chunk from blead |
379
|
|
|
|
|
|
|
* perl. (rafl) |
380
|
|
|
|
|
|
|
*/ |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
/* Close the filehandle. Could be from |
383
|
|
|
|
|
|
|
* STDIN, or a regular file. If we were reading code from |
384
|
|
|
|
|
|
|
* STDIN (because the commandline held no -e or filename) |
385
|
|
|
|
|
|
|
* then we don't close it, we reset it so the code can |
386
|
|
|
|
|
|
|
* read from STDIN too. |
387
|
|
|
|
|
|
|
*/ |
388
|
|
|
|
|
|
|
|
389
|
0
|
0
|
|
|
|
|
if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
390
|
0
|
|
|
|
|
|
PerlIO_clearerr(PL_rsfp); |
391
|
|
|
|
|
|
|
else |
392
|
0
|
|
|
|
|
|
(void)PerlIO_close(PL_rsfp); |
393
|
0
|
|
|
|
|
|
PL_rsfp = Nullfp; |
394
|
0
|
|
|
|
|
|
return s; |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
/* not at end of file, so we only read another line */ |
398
|
|
|
|
|
|
|
/* make corresponding updates to old pointers, for yyerror() */ |
399
|
12
|
|
|
|
|
|
oldprevlen = PL_oldbufptr - PL_bufend; |
400
|
12
|
|
|
|
|
|
oldoldprevlen = PL_oldoldbufptr - PL_bufend; |
401
|
12
|
50
|
|
|
|
|
if (PL_last_uni) |
402
|
0
|
|
|
|
|
|
oldunilen = PL_last_uni - PL_bufend; |
403
|
12
|
50
|
|
|
|
|
if (PL_last_lop) |
404
|
0
|
|
|
|
|
|
oldloplen = PL_last_lop - PL_bufend; |
405
|
12
|
|
|
|
|
|
PL_linestart = PL_bufptr = s + prevlen; |
406
|
12
|
|
|
|
|
|
PL_bufend = s + SvCUR(PL_linestr); |
407
|
12
|
|
|
|
|
|
s = PL_bufptr; |
408
|
12
|
|
|
|
|
|
PL_oldbufptr = s + oldprevlen; |
409
|
12
|
|
|
|
|
|
PL_oldoldbufptr = s + oldoldprevlen; |
410
|
12
|
50
|
|
|
|
|
if (PL_last_uni) |
411
|
0
|
|
|
|
|
|
PL_last_uni = s + oldunilen; |
412
|
12
|
50
|
|
|
|
|
if (PL_last_lop) |
413
|
0
|
|
|
|
|
|
PL_last_lop = s + oldloplen; |
414
|
12
|
100
|
|
|
|
|
if (!incline) |
415
|
3
|
|
|
|
|
|
incline(s); |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
/* debugger active and we're not compiling the debugger code, |
418
|
|
|
|
|
|
|
* so store the line into the debugger's array of lines |
419
|
|
|
|
|
|
|
*/ |
420
|
12
|
50
|
|
|
|
|
if (PERLDB_LINE && PL_curstash != PL_debstash) { |
|
|
0
|
|
|
|
|
|
421
|
0
|
0
|
|
|
|
|
AV *fileav = CopFILEAV(PL_curcop); |
422
|
0
|
0
|
|
|
|
|
if (fileav) { |
423
|
0
|
|
|
|
|
|
SV * const sv = NEWSV(85,0); |
424
|
0
|
|
|
|
|
|
sv_upgrade(sv, SVt_PVMG); |
425
|
0
|
|
|
|
|
|
sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
426
|
0
|
|
|
|
|
|
(void)SvIOK_on(sv); |
427
|
0
|
|
|
|
|
|
SvIV_set(sv, 0); |
428
|
0
|
|
|
|
|
|
av_store(fileav,(I32)CopLINE(PL_curcop),sv); |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
} |
431
|
12
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
STATIC char * |
435
|
239
|
|
|
|
|
|
S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
436
|
|
|
|
|
|
|
{ |
437
|
239
|
|
|
|
|
|
register char *d = dest; |
438
|
239
|
|
|
|
|
|
register char * const e = d + destlen - 3; /* two-character token, ending NUL */ |
439
|
|
|
|
|
|
|
for (;;) { |
440
|
457
|
50
|
|
|
|
|
if (d >= e) |
441
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ ident_too_long); |
442
|
457
|
50
|
|
|
|
|
if (UTF && isIDFIRST_utf8_safe((const U8*) s, (const U8*) PL_bufend)) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
443
|
|
|
|
|
|
|
/* The UTF-8 case must come first, otherwise things |
444
|
|
|
|
|
|
|
* like c\N{COMBINING TILDE} would start failing, as the |
445
|
|
|
|
|
|
|
* isALNUM case below would gobble the 'c' up. |
446
|
|
|
|
|
|
|
*/ |
447
|
|
|
|
|
|
|
|
448
|
0
|
|
|
|
|
|
char *t = s + UTF8SKIP(s); |
449
|
0
|
0
|
|
|
|
|
while (isIDCONT_utf8_safe((const U8*) t, (const U8*) PL_bufend)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
450
|
0
|
|
|
|
|
|
t += UTF8SKIP(t); |
451
|
|
|
|
|
|
|
} |
452
|
0
|
0
|
|
|
|
|
if (d + (t - s) > e) |
453
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "%s", ident_too_long); |
454
|
0
|
|
|
|
|
|
Copy(s, d, t - s, char); |
455
|
0
|
|
|
|
|
|
*d += t - s; |
456
|
0
|
|
|
|
|
|
s = t; |
457
|
|
|
|
|
|
|
} |
458
|
457
|
100
|
|
|
|
|
else if (isALNUM(*s)) |
459
|
|
|
|
|
|
|
do { |
460
|
1179
|
|
|
|
|
|
*d++ = *s++; |
461
|
1179
|
100
|
|
|
|
|
} while (isWORDCHAR_A(*s) && d < e); |
|
|
50
|
|
|
|
|
|
462
|
247
|
50
|
|
|
|
|
else if ( *s == '\'' |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
463
|
0
|
0
|
|
|
|
|
&& allow_package |
464
|
0
|
0
|
|
|
|
|
&& isIDFIRST_lazy_if_safe(s+1, PL_bufend, UTF)) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
465
|
|
|
|
|
|
|
{ |
466
|
0
|
|
|
|
|
|
*d++ = ':'; |
467
|
0
|
|
|
|
|
|
*d++ = ':'; |
468
|
0
|
|
|
|
|
|
s++; |
469
|
|
|
|
|
|
|
} |
470
|
247
|
100
|
|
|
|
|
else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
471
|
8
|
|
|
|
|
|
*d++ = *s++; |
472
|
8
|
|
|
|
|
|
*d++ = *s++; |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
else { |
475
|
239
|
|
|
|
|
|
*d = '\0'; |
476
|
239
|
|
|
|
|
|
*slp = d - dest; |
477
|
239
|
|
|
|
|
|
return s; |
478
|
|
|
|
|
|
|
} |
479
|
218
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
/* |
483
|
|
|
|
|
|
|
* S_incline |
484
|
|
|
|
|
|
|
* This subroutine has nothing to do with tilting, whether at windmills |
485
|
|
|
|
|
|
|
* or pinball tables. Its name is short for "increment line". It |
486
|
|
|
|
|
|
|
* increments the current line number in CopLINE(PL_curcop) and checks |
487
|
|
|
|
|
|
|
* to see whether the line starts with a comment of the form |
488
|
|
|
|
|
|
|
* # line 500 "foo.pm" |
489
|
|
|
|
|
|
|
* If so, it sets the current line number and file to the values in the comment. |
490
|
|
|
|
|
|
|
*/ |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
STATIC void |
493
|
6
|
|
|
|
|
|
S_incline(pTHX_ char *s) |
494
|
|
|
|
|
|
|
{ |
495
|
|
|
|
|
|
|
char *t; |
496
|
|
|
|
|
|
|
char *n; |
497
|
|
|
|
|
|
|
char *e; |
498
|
|
|
|
|
|
|
char ch; |
499
|
|
|
|
|
|
|
|
500
|
6
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
501
|
6
|
50
|
|
|
|
|
if (*s++ != '#') |
502
|
6
|
|
|
|
|
|
return; |
503
|
0
|
0
|
|
|
|
|
while (SPACE_OR_TAB(*s)) s++; |
|
|
0
|
|
|
|
|
|
504
|
0
|
0
|
|
|
|
|
if (strnEQ(s, "line", 4)) |
505
|
0
|
|
|
|
|
|
s += 4; |
506
|
|
|
|
|
|
|
else |
507
|
0
|
|
|
|
|
|
return; |
508
|
0
|
0
|
|
|
|
|
if (SPACE_OR_TAB(*s)) |
|
|
0
|
|
|
|
|
|
509
|
0
|
|
|
|
|
|
s++; |
510
|
|
|
|
|
|
|
else |
511
|
0
|
|
|
|
|
|
return; |
512
|
0
|
0
|
|
|
|
|
while (SPACE_OR_TAB(*s)) s++; |
|
|
0
|
|
|
|
|
|
513
|
0
|
0
|
|
|
|
|
if (!isDIGIT(*s)) |
514
|
0
|
|
|
|
|
|
return; |
515
|
0
|
|
|
|
|
|
n = s; |
516
|
0
|
0
|
|
|
|
|
while (isDIGIT(*s)) |
517
|
0
|
|
|
|
|
|
s++; |
518
|
0
|
0
|
|
|
|
|
while (SPACE_OR_TAB(*s)) |
|
|
0
|
|
|
|
|
|
519
|
0
|
|
|
|
|
|
s++; |
520
|
0
|
0
|
|
|
|
|
if (*s == '"' && (t = strchr(s+1, '"'))) { |
|
|
0
|
|
|
|
|
|
521
|
0
|
|
|
|
|
|
s++; |
522
|
0
|
|
|
|
|
|
e = t + 1; |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
else { |
525
|
0
|
0
|
|
|
|
|
for (t = s; !isSPACE(*t); t++) ; |
526
|
0
|
|
|
|
|
|
e = t; |
527
|
|
|
|
|
|
|
} |
528
|
0
|
0
|
|
|
|
|
while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
529
|
0
|
|
|
|
|
|
e++; |
530
|
0
|
0
|
|
|
|
|
if (*e != '\n' && *e != '\0') |
|
|
0
|
|
|
|
|
|
531
|
0
|
|
|
|
|
|
return; /* false alarm */ |
532
|
|
|
|
|
|
|
|
533
|
0
|
|
|
|
|
|
ch = *t; |
534
|
0
|
|
|
|
|
|
*t = '\0'; |
535
|
0
|
0
|
|
|
|
|
if (t - s > 0) { |
536
|
|
|
|
|
|
|
/* this chunk was added to S_incline during 5.8.8. I don't know why but I don't |
537
|
|
|
|
|
|
|
honestly care since I probably want to be bug-compatible anyway (mst) */ |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
/* ... my kingdom for a perl parser in perl ... (mst) */ |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
#ifdef PERL_5_8_8_PLUS |
542
|
|
|
|
|
|
|
#ifndef USE_ITHREADS |
543
|
|
|
|
|
|
|
const char *cf = CopFILE(PL_curcop); |
544
|
|
|
|
|
|
|
if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) { |
545
|
|
|
|
|
|
|
/* must copy *{"::_<(eval N)[oldfilename:L]"} |
546
|
|
|
|
|
|
|
* to *{"::_
|
547
|
|
|
|
|
|
|
char smallbuf[256], smallbuf2[256]; |
548
|
|
|
|
|
|
|
char *tmpbuf, *tmpbuf2; |
549
|
|
|
|
|
|
|
GV **gvp, *gv2; |
550
|
|
|
|
|
|
|
STRLEN tmplen = strlen(cf); |
551
|
|
|
|
|
|
|
STRLEN tmplen2 = strlen(s); |
552
|
|
|
|
|
|
|
if (tmplen + 3 < sizeof smallbuf) |
553
|
|
|
|
|
|
|
tmpbuf = smallbuf; |
554
|
|
|
|
|
|
|
else |
555
|
|
|
|
|
|
|
Newx(tmpbuf, tmplen + 3, char); |
556
|
|
|
|
|
|
|
if (tmplen2 + 3 < sizeof smallbuf2) |
557
|
|
|
|
|
|
|
tmpbuf2 = smallbuf2; |
558
|
|
|
|
|
|
|
else |
559
|
|
|
|
|
|
|
Newx(tmpbuf2, tmplen2 + 3, char); |
560
|
|
|
|
|
|
|
tmpbuf[0] = tmpbuf2[0] = '_'; |
561
|
|
|
|
|
|
|
tmpbuf[1] = tmpbuf2[1] = '<'; |
562
|
|
|
|
|
|
|
memcpy(tmpbuf + 2, cf, ++tmplen); |
563
|
|
|
|
|
|
|
memcpy(tmpbuf2 + 2, s, ++tmplen2); |
564
|
|
|
|
|
|
|
++tmplen; ++tmplen2; |
565
|
|
|
|
|
|
|
gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE); |
566
|
|
|
|
|
|
|
if (gvp) { |
567
|
|
|
|
|
|
|
gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE); |
568
|
|
|
|
|
|
|
if (!isGV(gv2)) |
569
|
|
|
|
|
|
|
gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE); |
570
|
|
|
|
|
|
|
/* adjust ${"::_
|
571
|
|
|
|
|
|
|
GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2); |
572
|
|
|
|
|
|
|
GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp)); |
573
|
|
|
|
|
|
|
GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp)); |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
if (tmpbuf != smallbuf) Safefree(tmpbuf); |
576
|
|
|
|
|
|
|
if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2); |
577
|
|
|
|
|
|
|
} |
578
|
|
|
|
|
|
|
#endif |
579
|
|
|
|
|
|
|
#endif |
580
|
|
|
|
|
|
|
/* second endif closes out the "are we 5.8.(8+)" conditional */ |
581
|
0
|
|
|
|
|
|
CopFILE_free(PL_curcop); |
582
|
0
|
|
|
|
|
|
CopFILE_set(PL_curcop, s); |
583
|
|
|
|
|
|
|
} |
584
|
0
|
|
|
|
|
|
*t = ch; |
585
|
0
|
|
|
|
|
|
CopLINE_set(PL_curcop, atoi(n)-1); |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
/* scan_str |
589
|
|
|
|
|
|
|
takes: start position in buffer |
590
|
|
|
|
|
|
|
keep_quoted preserve \ on the embedded delimiter(s) |
591
|
|
|
|
|
|
|
keep_delims preserve the delimiters around the string |
592
|
|
|
|
|
|
|
returns: position to continue reading from buffer |
593
|
|
|
|
|
|
|
side-effects: multi_start, multi_close, lex_repl or lex_stuff, and |
594
|
|
|
|
|
|
|
updates the read buffer. |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
This subroutine pulls a string out of the input. It is called for: |
597
|
|
|
|
|
|
|
q single quotes q(literal text) |
598
|
|
|
|
|
|
|
' single quotes 'literal text' |
599
|
|
|
|
|
|
|
qq double quotes qq(interpolate $here please) |
600
|
|
|
|
|
|
|
" double quotes "interpolate $here please" |
601
|
|
|
|
|
|
|
qx backticks qx(/bin/ls -l) |
602
|
|
|
|
|
|
|
` backticks `/bin/ls -l` |
603
|
|
|
|
|
|
|
qw quote words @EXPORT_OK = qw( func() $spam ) |
604
|
|
|
|
|
|
|
m// regexp match m/this/ |
605
|
|
|
|
|
|
|
s/// regexp substitute s/this/that/ |
606
|
|
|
|
|
|
|
tr/// string transliterate tr/this/that/ |
607
|
|
|
|
|
|
|
y/// string transliterate y/this/that/ |
608
|
|
|
|
|
|
|
($*@) sub prototypes sub foo ($) |
609
|
|
|
|
|
|
|
(stuff) sub attr parameters sub foo : attr(stuff) |
610
|
|
|
|
|
|
|
<> readline or globs , <>, <$fh>, or <*.c> |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
In most of these cases (all but <>, patterns and transliterate) |
613
|
|
|
|
|
|
|
yylex() calls scan_str(). m// makes yylex() call scan_pat() which |
614
|
|
|
|
|
|
|
calls scan_str(). s/// makes yylex() call scan_subst() which calls |
615
|
|
|
|
|
|
|
scan_str(). tr/// and y/// make yylex() call scan_trans() which |
616
|
|
|
|
|
|
|
calls scan_str(). |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
It skips whitespace before the string starts, and treats the first |
619
|
|
|
|
|
|
|
character as the delimiter. If the delimiter is one of ([{< then |
620
|
|
|
|
|
|
|
the corresponding "close" character )]}> is used as the closing |
621
|
|
|
|
|
|
|
delimiter. It allows quoting of delimiters, and if the string has |
622
|
|
|
|
|
|
|
balanced delimiters ([{<>}]) it allows nesting. |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
On success, the SV with the resulting string is put into lex_stuff or, |
625
|
|
|
|
|
|
|
if that is already non-NULL, into lex_repl. The second case occurs only |
626
|
|
|
|
|
|
|
when parsing the RHS of the special constructs s/// and tr/// (y///). |
627
|
|
|
|
|
|
|
For convenience, the terminating delimiter character is stuffed into |
628
|
|
|
|
|
|
|
SvIVX of the SV. |
629
|
|
|
|
|
|
|
*/ |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
STATIC char * |
632
|
60
|
|
|
|
|
|
S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
633
|
|
|
|
|
|
|
{ |
634
|
|
|
|
|
|
|
SV *sv; /* scalar value: string */ |
635
|
|
|
|
|
|
|
char *tmps; /* temp string, used for delimiter matching */ |
636
|
60
|
|
|
|
|
|
register char *s = start; /* current position in the buffer */ |
637
|
|
|
|
|
|
|
register char term; /* terminating character */ |
638
|
|
|
|
|
|
|
register char *to; /* current position in the sv's data */ |
639
|
60
|
|
|
|
|
|
I32 brackets = 1; /* bracket nesting level */ |
640
|
60
|
|
|
|
|
|
bool has_utf8 = FALSE; /* is there any utf8 content? */ |
641
|
|
|
|
|
|
|
I32 termcode; /* terminating char. code */ |
642
|
|
|
|
|
|
|
/* 5.8.7+ uses UTF8_MAXBYTES but also its utf8.h defs _MAXLEN to it so |
643
|
|
|
|
|
|
|
I'm reasonably hopeful this won't destroy anything (mst) */ |
644
|
|
|
|
|
|
|
U8 termstr[UTF8_MAXLEN]; /* terminating string */ |
645
|
|
|
|
|
|
|
STRLEN termlen; /* length of terminating string */ |
646
|
60
|
|
|
|
|
|
char *last = NULL; /* last position for nesting bracket */ |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
/* skip space before the delimiter */ |
649
|
60
|
50
|
|
|
|
|
if (isSPACE(*s)) |
650
|
0
|
|
|
|
|
|
s = skipspace(s); |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
/* mark where we are, in case we need to report errors */ |
653
|
60
|
|
|
|
|
|
CLINE; |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
/* after skipping whitespace, the next character is the terminator */ |
656
|
60
|
|
|
|
|
|
term = *s; |
657
|
60
|
50
|
|
|
|
|
if (!UTF) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
658
|
60
|
|
|
|
|
|
termcode = termstr[0] = term; |
659
|
60
|
|
|
|
|
|
termlen = 1; |
660
|
|
|
|
|
|
|
} |
661
|
|
|
|
|
|
|
else { |
662
|
0
|
0
|
|
|
|
|
termcode = utf8_to_uvchr_buf((U8*)s, PL_bufend, &termlen); |
663
|
0
|
|
|
|
|
|
Copy(s, termstr, termlen, U8); |
664
|
0
|
0
|
|
|
|
|
if (!UTF8_IS_INVARIANT(term)) |
665
|
0
|
|
|
|
|
|
has_utf8 = TRUE; |
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
/* mark where we are */ |
669
|
60
|
|
|
|
|
|
PL_multi_start = CopLINE(PL_curcop); |
670
|
60
|
|
|
|
|
|
PL_multi_open = term; |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
/* find corresponding closing delimiter */ |
673
|
60
|
50
|
|
|
|
|
if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
|
|
50
|
|
|
|
|
|
674
|
60
|
|
|
|
|
|
termcode = termstr[0] = term = tmps[5]; |
675
|
|
|
|
|
|
|
|
676
|
60
|
|
|
|
|
|
PL_multi_close = term; |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
/* create a new SV to hold the contents. 87 is leak category, I'm |
679
|
|
|
|
|
|
|
assuming. 79 is the SV's initial length. What a random number. */ |
680
|
60
|
|
|
|
|
|
sv = NEWSV(87,79); |
681
|
60
|
|
|
|
|
|
sv_upgrade(sv, SVt_PVIV); |
682
|
60
|
|
|
|
|
|
SvIV_set(sv, termcode); |
683
|
60
|
|
|
|
|
|
(void)SvPOK_only(sv); /* validate pointer */ |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
/* move past delimiter and try to read a complete string */ |
686
|
60
|
50
|
|
|
|
|
if (keep_delims) |
687
|
0
|
|
|
|
|
|
sv_catpvn(sv, s, termlen); |
688
|
80
|
|
|
|
|
|
s += termlen; |
689
|
|
|
|
|
|
|
for (;;) { |
690
|
|
|
|
|
|
|
if (PL_encoding && !UTF) { |
691
|
|
|
|
|
|
|
bool cont = TRUE; |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
while (cont) { |
694
|
|
|
|
|
|
|
int offset = s - SvPVX_const(PL_linestr); |
695
|
|
|
|
|
|
|
const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, |
696
|
|
|
|
|
|
|
&offset, (char*)termstr, termlen); |
697
|
|
|
|
|
|
|
const char *ns = SvPVX_const(PL_linestr) + offset; |
698
|
|
|
|
|
|
|
char *svlast = SvEND(sv) - 1; |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
for (; s < ns; s++) { |
701
|
|
|
|
|
|
|
if (*s == '\n' && !PL_rsfp) |
702
|
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
if (!found) |
705
|
|
|
|
|
|
|
goto read_more_line; |
706
|
|
|
|
|
|
|
else { |
707
|
|
|
|
|
|
|
/* handle quoted delimiters */ |
708
|
|
|
|
|
|
|
if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
709
|
|
|
|
|
|
|
const char *t; |
710
|
|
|
|
|
|
|
for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';) |
711
|
|
|
|
|
|
|
t--; |
712
|
|
|
|
|
|
|
if ((svlast-1 - t) % 2) { |
713
|
|
|
|
|
|
|
if (!keep_quoted) { |
714
|
|
|
|
|
|
|
*(svlast-1) = term; |
715
|
|
|
|
|
|
|
*svlast = '\0'; |
716
|
|
|
|
|
|
|
SvCUR_set(sv, SvCUR(sv) - 1); |
717
|
|
|
|
|
|
|
} |
718
|
|
|
|
|
|
|
continue; |
719
|
|
|
|
|
|
|
} |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
if (PL_multi_open == PL_multi_close) { |
722
|
|
|
|
|
|
|
cont = FALSE; |
723
|
|
|
|
|
|
|
} |
724
|
|
|
|
|
|
|
else { |
725
|
|
|
|
|
|
|
const char *t; |
726
|
|
|
|
|
|
|
char *w; |
727
|
|
|
|
|
|
|
if (!last) |
728
|
|
|
|
|
|
|
last = SvPVX(sv); |
729
|
|
|
|
|
|
|
for (t = w = last; t < svlast; w++, t++) { |
730
|
|
|
|
|
|
|
/* At here, all closes are "was quoted" one, |
731
|
|
|
|
|
|
|
so we don't check PL_multi_close. */ |
732
|
|
|
|
|
|
|
if (*t == '\\') { |
733
|
|
|
|
|
|
|
if (!keep_quoted && *(t+1) == PL_multi_open) |
734
|
|
|
|
|
|
|
t++; |
735
|
|
|
|
|
|
|
else |
736
|
|
|
|
|
|
|
*w++ = *t++; |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
else if (*t == PL_multi_open) |
739
|
|
|
|
|
|
|
brackets++; |
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
*w = *t; |
742
|
|
|
|
|
|
|
} |
743
|
|
|
|
|
|
|
if (w < t) { |
744
|
|
|
|
|
|
|
*w++ = term; |
745
|
|
|
|
|
|
|
*w = '\0'; |
746
|
|
|
|
|
|
|
SvCUR_set(sv, w - SvPVX_const(sv)); |
747
|
|
|
|
|
|
|
} |
748
|
|
|
|
|
|
|
last = w; |
749
|
|
|
|
|
|
|
if (--brackets <= 0) |
750
|
|
|
|
|
|
|
cont = FALSE; |
751
|
|
|
|
|
|
|
} |
752
|
|
|
|
|
|
|
} |
753
|
|
|
|
|
|
|
} |
754
|
|
|
|
|
|
|
if (!keep_delims) { |
755
|
|
|
|
|
|
|
SvCUR_set(sv, SvCUR(sv) - 1); |
756
|
|
|
|
|
|
|
*SvEND(sv) = '\0'; |
757
|
|
|
|
|
|
|
} |
758
|
|
|
|
|
|
|
break; |
759
|
|
|
|
|
|
|
} |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
/* extend sv if need be */ |
762
|
80
|
50
|
|
|
|
|
SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
|
|
50
|
|
|
|
|
|
763
|
|
|
|
|
|
|
/* set 'to' to the next character in the sv's string */ |
764
|
80
|
|
|
|
|
|
to = SvPVX(sv)+SvCUR(sv); |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
/* if open delimiter is the close delimiter read unbridle */ |
767
|
80
|
50
|
|
|
|
|
if (PL_multi_open == PL_multi_close) { |
768
|
0
|
0
|
|
|
|
|
for (; s < PL_bufend; s++,to++) { |
769
|
|
|
|
|
|
|
/* embedded newlines increment the current line number */ |
770
|
0
|
0
|
|
|
|
|
if (*s == '\n' && !PL_rsfp) |
|
|
0
|
|
|
|
|
|
771
|
0
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
772
|
|
|
|
|
|
|
/* handle quoted delimiters */ |
773
|
0
|
0
|
|
|
|
|
if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
774
|
0
|
0
|
|
|
|
|
if (!keep_quoted && s[1] == term) |
|
|
0
|
|
|
|
|
|
775
|
0
|
|
|
|
|
|
s++; |
776
|
|
|
|
|
|
|
/* any other quotes are simply copied straight through */ |
777
|
|
|
|
|
|
|
else |
778
|
0
|
|
|
|
|
|
*to++ = *s++; |
779
|
|
|
|
|
|
|
} |
780
|
|
|
|
|
|
|
/* terminate when run out of buffer (the for() condition), or |
781
|
|
|
|
|
|
|
have found the terminator */ |
782
|
0
|
0
|
|
|
|
|
else if (*s == term) { |
783
|
0
|
0
|
|
|
|
|
if (termlen == 1) |
784
|
0
|
|
|
|
|
|
break; |
785
|
0
|
0
|
|
|
|
|
if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
|
|
0
|
|
|
|
|
|
786
|
0
|
|
|
|
|
|
break; |
787
|
|
|
|
|
|
|
} |
788
|
0
|
0
|
|
|
|
|
else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
789
|
0
|
|
|
|
|
|
has_utf8 = TRUE; |
790
|
0
|
|
|
|
|
|
*to = *s; |
791
|
|
|
|
|
|
|
} |
792
|
|
|
|
|
|
|
} |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
/* if the terminator isn't the same as the start character (e.g., |
795
|
|
|
|
|
|
|
matched brackets), we have to allow more in the quoting, and |
796
|
|
|
|
|
|
|
be prepared for nested brackets. |
797
|
|
|
|
|
|
|
*/ |
798
|
|
|
|
|
|
|
else { |
799
|
|
|
|
|
|
|
/* read until we run out of string, or we find the terminator */ |
800
|
396
|
100
|
|
|
|
|
for (; s < PL_bufend; s++,to++) { |
801
|
|
|
|
|
|
|
/* embedded newlines increment the line count */ |
802
|
374
|
100
|
|
|
|
|
if (*s == '\n' && !PL_rsfp) |
|
|
100
|
|
|
|
|
|
803
|
2
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
804
|
|
|
|
|
|
|
/* backslashes can escape the open or closing characters */ |
805
|
374
|
50
|
|
|
|
|
if (*s == '\\' && s+1 < PL_bufend) { |
|
|
0
|
|
|
|
|
|
806
|
0
|
0
|
|
|
|
|
if (!keep_quoted && |
|
|
0
|
|
|
|
|
|
807
|
0
|
0
|
|
|
|
|
((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) |
808
|
0
|
|
|
|
|
|
s++; |
809
|
|
|
|
|
|
|
else |
810
|
0
|
|
|
|
|
|
*to++ = *s++; |
811
|
|
|
|
|
|
|
} |
812
|
|
|
|
|
|
|
/* allow nested opens and closes */ |
813
|
374
|
100
|
|
|
|
|
else if (*s == PL_multi_close && --brackets <= 0) |
|
|
50
|
|
|
|
|
|
814
|
|
|
|
|
|
|
break; |
815
|
316
|
50
|
|
|
|
|
else if (*s == PL_multi_open) |
816
|
0
|
|
|
|
|
|
brackets++; |
817
|
316
|
50
|
|
|
|
|
else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
818
|
0
|
|
|
|
|
|
has_utf8 = TRUE; |
819
|
316
|
|
|
|
|
|
*to = *s; |
820
|
|
|
|
|
|
|
} |
821
|
|
|
|
|
|
|
} |
822
|
|
|
|
|
|
|
/* terminate the copied string and update the sv's end-of-string */ |
823
|
80
|
|
|
|
|
|
*to = '\0'; |
824
|
80
|
|
|
|
|
|
SvCUR_set(sv, to - SvPVX_const(sv)); |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
/* |
827
|
|
|
|
|
|
|
* this next chunk reads more into the buffer if we're not done yet |
828
|
|
|
|
|
|
|
*/ |
829
|
|
|
|
|
|
|
|
830
|
80
|
100
|
|
|
|
|
if (s < PL_bufend) |
831
|
58
|
|
|
|
|
|
break; /* handle case where we are done yet :-) */ |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
#ifndef PERL_STRICT_CR |
834
|
22
|
100
|
|
|
|
|
if (to - SvPVX_const(sv) >= 2) { |
835
|
20
|
50
|
|
|
|
|
if ((to[-2] == '\r' && to[-1] == '\n') || |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
836
|
2
|
50
|
|
|
|
|
(to[-2] == '\n' && to[-1] == '\r')) |
837
|
|
|
|
|
|
|
{ |
838
|
0
|
|
|
|
|
|
to[-2] = '\n'; |
839
|
0
|
|
|
|
|
|
to--; |
840
|
0
|
|
|
|
|
|
SvCUR_set(sv, to - SvPVX_const(sv)); |
841
|
|
|
|
|
|
|
} |
842
|
20
|
50
|
|
|
|
|
else if (to[-1] == '\r') |
843
|
20
|
|
|
|
|
|
to[-1] = '\n'; |
844
|
|
|
|
|
|
|
} |
845
|
2
|
50
|
|
|
|
|
else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r') |
|
|
50
|
|
|
|
|
|
846
|
0
|
|
|
|
|
|
to[-1] = '\n'; |
847
|
|
|
|
|
|
|
#endif |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
read_more_line: |
850
|
|
|
|
|
|
|
/* if we're out of file, or a read fails, bail and reset the current |
851
|
|
|
|
|
|
|
line marker so we can report where the unterminated string began |
852
|
|
|
|
|
|
|
*/ |
853
|
42
|
|
|
|
|
|
if (!PL_rsfp || |
854
|
20
|
|
|
|
|
|
!(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
855
|
2
|
|
|
|
|
|
sv_free(sv); |
856
|
2
|
|
|
|
|
|
CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
857
|
2
|
|
|
|
|
|
return Nullch; |
858
|
|
|
|
|
|
|
} |
859
|
|
|
|
|
|
|
/* we read a line, so increment our line counter */ |
860
|
20
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
/* update debugger info */ |
863
|
20
|
50
|
|
|
|
|
if (PERLDB_LINE && PL_curstash != PL_debstash) { |
|
|
0
|
|
|
|
|
|
864
|
0
|
0
|
|
|
|
|
AV *fileav = CopFILEAV(PL_curcop); |
865
|
0
|
0
|
|
|
|
|
if (fileav) { |
866
|
0
|
|
|
|
|
|
SV *sv = NEWSV(88,0); |
867
|
0
|
|
|
|
|
|
sv_upgrade(sv, SVt_PVMG); |
868
|
0
|
|
|
|
|
|
sv_setsv(sv,PL_linestr); |
869
|
0
|
|
|
|
|
|
(void)SvIOK_on(sv); |
870
|
0
|
|
|
|
|
|
SvIV_set(sv, 0); |
871
|
0
|
|
|
|
|
|
av_store(fileav, (I32)CopLINE(PL_curcop), sv); |
872
|
|
|
|
|
|
|
} |
873
|
|
|
|
|
|
|
} |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
/* having changed the buffer, we must update PL_bufend */ |
876
|
20
|
|
|
|
|
|
PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
877
|
20
|
|
|
|
|
|
PL_last_lop = PL_last_uni = Nullch; |
878
|
78
|
|
|
|
|
|
} |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
/* at this point, we have successfully read the delimited string */ |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
if (!PL_encoding || UTF) { |
883
|
58
|
50
|
|
|
|
|
if (keep_delims) |
884
|
0
|
|
|
|
|
|
sv_catpvn(sv, s, termlen); |
885
|
58
|
|
|
|
|
|
s += termlen; |
886
|
|
|
|
|
|
|
} |
887
|
58
|
50
|
|
|
|
|
if (has_utf8 || PL_encoding) |
888
|
0
|
|
|
|
|
|
SvUTF8_on(sv); |
889
|
|
|
|
|
|
|
|
890
|
58
|
|
|
|
|
|
PL_multi_end = CopLINE(PL_curcop); |
891
|
|
|
|
|
|
|
|
892
|
|
|
|
|
|
|
/* if we allocated too much space, give some back */ |
893
|
58
|
50
|
|
|
|
|
if (SvCUR(sv) + 5 < SvLEN(sv)) { |
894
|
58
|
|
|
|
|
|
SvLEN_set(sv, SvCUR(sv) + 1); |
895
|
|
|
|
|
|
|
/* 5.8.8 uses SvPV_renew, no prior version actually has the damn thing (mst) */ |
896
|
|
|
|
|
|
|
#ifdef PERL_5_8_8_PLUS |
897
|
|
|
|
|
|
|
SvPV_renew(sv, SvLEN(sv)); |
898
|
|
|
|
|
|
|
#else |
899
|
58
|
|
|
|
|
|
Renew(SvPVX(sv), SvLEN(sv), char); |
900
|
|
|
|
|
|
|
#endif |
901
|
|
|
|
|
|
|
} |
902
|
|
|
|
|
|
|
|
903
|
|
|
|
|
|
|
/* decide whether this is the first or second quoted string we've read |
904
|
|
|
|
|
|
|
for this op |
905
|
|
|
|
|
|
|
*/ |
906
|
|
|
|
|
|
|
|
907
|
58
|
50
|
|
|
|
|
if (PL_lex_stuff) |
908
|
0
|
|
|
|
|
|
PL_lex_repl = sv; |
909
|
|
|
|
|
|
|
else |
910
|
58
|
|
|
|
|
|
PL_lex_stuff = sv; |
911
|
60
|
|
|
|
|
|
return s; |
912
|
|
|
|
|
|
|
} |
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
#define XFAKEBRACK 128 |
915
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
STATIC char * |
917
|
0
|
|
|
|
|
|
S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni) |
918
|
|
|
|
|
|
|
{ |
919
|
|
|
|
|
|
|
register char *d; |
920
|
|
|
|
|
|
|
register char *e; |
921
|
0
|
|
|
|
|
|
char *bracket = Nullch; |
922
|
0
|
|
|
|
|
|
char funny = *s++; |
923
|
|
|
|
|
|
|
|
924
|
0
|
0
|
|
|
|
|
if (isSPACE(*s)) |
925
|
0
|
|
|
|
|
|
s = skipspace(s); |
926
|
0
|
|
|
|
|
|
d = dest; |
927
|
0
|
|
|
|
|
|
e = d + destlen - 3; /* two-character token, ending NUL */ |
928
|
0
|
0
|
|
|
|
|
if (isDIGIT(*s)) { |
929
|
0
|
0
|
|
|
|
|
while (isDIGIT(*s)) { |
930
|
0
|
0
|
|
|
|
|
if (d >= e) |
931
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ ident_too_long); |
932
|
0
|
|
|
|
|
|
*d++ = *s++; |
933
|
|
|
|
|
|
|
} |
934
|
|
|
|
|
|
|
} |
935
|
|
|
|
|
|
|
else { |
936
|
|
|
|
|
|
|
for (;;) { |
937
|
0
|
0
|
|
|
|
|
if (d >= e) |
938
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ ident_too_long); |
939
|
0
|
0
|
|
|
|
|
if (UTF && isIDFIRST_utf8_safe((const U8*) s, (const U8*) PL_bufend)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
940
|
|
|
|
|
|
|
/* The UTF-8 case must come first, otherwise things |
941
|
|
|
|
|
|
|
* like c\N{COMBINING TILDE} would start failing, as the |
942
|
|
|
|
|
|
|
* isALNUM case below would gobble the 'c' up. |
943
|
|
|
|
|
|
|
*/ |
944
|
|
|
|
|
|
|
|
945
|
0
|
|
|
|
|
|
char *t = s + UTF8SKIP(s); |
946
|
0
|
0
|
|
|
|
|
while (isIDCONT_utf8_safe((const U8*) t, (const U8*) PL_bufend)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
947
|
0
|
|
|
|
|
|
t += UTF8SKIP(t); |
948
|
|
|
|
|
|
|
} |
949
|
0
|
0
|
|
|
|
|
if (d + (t - s) > e) |
950
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "%s", ident_too_long); |
951
|
0
|
|
|
|
|
|
Copy(s, d, t - s, char); |
952
|
0
|
|
|
|
|
|
*d += t - s; |
953
|
0
|
|
|
|
|
|
s = t; |
954
|
|
|
|
|
|
|
} |
955
|
0
|
0
|
|
|
|
|
else if (isALNUM(*s)) |
956
|
|
|
|
|
|
|
do { |
957
|
0
|
|
|
|
|
|
*d++ = *s++; |
958
|
0
|
0
|
|
|
|
|
} while (isWORDCHAR_A(*s) && d < e); |
|
|
0
|
|
|
|
|
|
959
|
0
|
0
|
|
|
|
|
else if (*s == '\'' && isIDFIRST_lazy_if_safe(s+1,send,UTF)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
960
|
0
|
|
|
|
|
|
*d++ = ':'; |
961
|
0
|
|
|
|
|
|
*d++ = ':'; |
962
|
0
|
|
|
|
|
|
s++; |
963
|
|
|
|
|
|
|
} |
964
|
0
|
0
|
|
|
|
|
else if (*s == ':' && s[1] == ':') { |
|
|
0
|
|
|
|
|
|
965
|
0
|
|
|
|
|
|
*d++ = *s++; |
966
|
0
|
|
|
|
|
|
*d++ = *s++; |
967
|
|
|
|
|
|
|
} |
968
|
|
|
|
|
|
|
else |
969
|
|
|
|
|
|
|
break; |
970
|
0
|
|
|
|
|
|
} |
971
|
|
|
|
|
|
|
} |
972
|
0
|
|
|
|
|
|
*d = '\0'; |
973
|
0
|
|
|
|
|
|
d = dest; |
974
|
0
|
0
|
|
|
|
|
if (*d) { |
975
|
0
|
0
|
|
|
|
|
if (PL_lex_state != LEX_NORMAL) |
976
|
0
|
|
|
|
|
|
PL_lex_state = LEX_INTERPENDMAYBE; |
977
|
0
|
|
|
|
|
|
return s; |
978
|
|
|
|
|
|
|
} |
979
|
0
|
0
|
|
|
|
|
if (*s == '$' && s[1] && |
|
|
0
|
|
|
|
|
|
980
|
0
|
0
|
|
|
|
|
( isALNUM_lazy_if_safe(s+1,send,UTF) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
981
|
0
|
0
|
|
|
|
|
|| s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) ) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
982
|
|
|
|
|
|
|
{ |
983
|
0
|
|
|
|
|
|
return s; |
984
|
|
|
|
|
|
|
} |
985
|
0
|
0
|
|
|
|
|
if (*s == '{') { |
986
|
0
|
|
|
|
|
|
bracket = s; |
987
|
0
|
|
|
|
|
|
s++; |
988
|
|
|
|
|
|
|
} else if (ck_uni) { |
989
|
|
|
|
|
|
|
/* we always call this with ck_uni == 0, so no need for check_uni() */ |
990
|
|
|
|
|
|
|
/* check_uni(); */ |
991
|
|
|
|
|
|
|
} |
992
|
0
|
0
|
|
|
|
|
if (s < send) |
993
|
0
|
|
|
|
|
|
*d = *s++; |
994
|
0
|
|
|
|
|
|
d[1] = '\0'; |
995
|
0
|
0
|
|
|
|
|
if (*d == '^' && *s && isCONTROLVAR(*s)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
996
|
0
|
0
|
|
|
|
|
*d = toCTRL(*s); |
997
|
0
|
|
|
|
|
|
s++; |
998
|
|
|
|
|
|
|
} |
999
|
0
|
0
|
|
|
|
|
if (bracket) { |
1000
|
0
|
0
|
|
|
|
|
if (isSPACE(s[-1])) { |
1001
|
0
|
0
|
|
|
|
|
while (s < send) { |
1002
|
0
|
|
|
|
|
|
const char ch = *s++; |
1003
|
0
|
0
|
|
|
|
|
if (!SPACE_OR_TAB(ch)) { |
|
|
0
|
|
|
|
|
|
1004
|
0
|
|
|
|
|
|
*d = ch; |
1005
|
0
|
|
|
|
|
|
break; |
1006
|
|
|
|
|
|
|
} |
1007
|
|
|
|
|
|
|
} |
1008
|
|
|
|
|
|
|
} |
1009
|
0
|
0
|
|
|
|
|
if (isIDFIRST_lazy_if_safe(d,d+destlen,UTF)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1010
|
0
|
|
|
|
|
|
d++; |
1011
|
0
|
0
|
|
|
|
|
if (UTF) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1012
|
0
|
|
|
|
|
|
e = s; |
1013
|
0
|
0
|
|
|
|
|
while ( ( e < send |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1014
|
0
|
0
|
|
|
|
|
&& isIDFIRST_utf8_safe(e, send) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1015
|
0
|
0
|
|
|
|
|
|| *e == ':')) |
1016
|
|
|
|
|
|
|
{ |
1017
|
0
|
|
|
|
|
|
e += UTF8SKIP(e); |
1018
|
0
|
0
|
|
|
|
|
while (e < send && isIDFIRST_utf8_safe(e, send)) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1019
|
0
|
|
|
|
|
|
e += UTF8SKIP(e); |
1020
|
|
|
|
|
|
|
} |
1021
|
0
|
|
|
|
|
|
Copy(s, d, e - s, char); |
1022
|
0
|
|
|
|
|
|
d += e - s; |
1023
|
0
|
|
|
|
|
|
s = e; |
1024
|
|
|
|
|
|
|
} |
1025
|
|
|
|
|
|
|
else { |
1026
|
0
|
0
|
|
|
|
|
while ((isALNUM(*s) || *s == ':') && d < e) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1027
|
0
|
|
|
|
|
|
*d++ = *s++; |
1028
|
0
|
0
|
|
|
|
|
if (d >= e) |
1029
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ ident_too_long); |
1030
|
|
|
|
|
|
|
} |
1031
|
0
|
|
|
|
|
|
*d = '\0'; |
1032
|
0
|
0
|
|
|
|
|
while (s < send && SPACE_OR_TAB(*s)) s++; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1033
|
0
|
0
|
|
|
|
|
if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1034
|
|
|
|
|
|
|
/* we don't want perl to guess what is meant. the keyword |
1035
|
|
|
|
|
|
|
* parser decides that later. (rafl) |
1036
|
|
|
|
|
|
|
*/ |
1037
|
|
|
|
|
|
|
/* |
1038
|
|
|
|
|
|
|
if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
1039
|
|
|
|
|
|
|
const char *brack = *s == '[' ? "[...]" : "{...}"; |
1040
|
|
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
1041
|
|
|
|
|
|
|
"Ambiguous use of %c{%s%s} resolved to %c%s%s", |
1042
|
|
|
|
|
|
|
funny, dest, brack, funny, dest, brack); |
1043
|
|
|
|
|
|
|
} |
1044
|
|
|
|
|
|
|
*/ |
1045
|
0
|
|
|
|
|
|
bracket++; |
1046
|
0
|
|
|
|
|
|
PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
1047
|
0
|
|
|
|
|
|
return s; |
1048
|
|
|
|
|
|
|
} |
1049
|
|
|
|
|
|
|
} |
1050
|
|
|
|
|
|
|
/* Handle extended ${^Foo} variables |
1051
|
|
|
|
|
|
|
* 1999-02-27 mjd-perl-patch@plover.com */ |
1052
|
0
|
0
|
|
|
|
|
else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ |
|
|
0
|
|
|
|
|
|
1053
|
0
|
0
|
|
|
|
|
&& isALNUM(*s)) |
1054
|
|
|
|
|
|
|
{ |
1055
|
0
|
|
|
|
|
|
d++; |
1056
|
0
|
0
|
|
|
|
|
while (isALNUM(*s) && d < e) { |
|
|
0
|
|
|
|
|
|
1057
|
0
|
|
|
|
|
|
*d++ = *s++; |
1058
|
|
|
|
|
|
|
} |
1059
|
0
|
0
|
|
|
|
|
if (d >= e) |
1060
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ ident_too_long); |
1061
|
0
|
|
|
|
|
|
*d = '\0'; |
1062
|
|
|
|
|
|
|
} |
1063
|
0
|
0
|
|
|
|
|
if (*s == '}') { |
1064
|
0
|
|
|
|
|
|
s++; |
1065
|
0
|
0
|
|
|
|
|
if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) { |
|
|
0
|
|
|
|
|
|
1066
|
0
|
|
|
|
|
|
PL_lex_state = LEX_INTERPEND; |
1067
|
0
|
|
|
|
|
|
PL_expect = XREF; |
1068
|
|
|
|
|
|
|
} |
1069
|
0
|
0
|
|
|
|
|
if (funny == '#') |
1070
|
0
|
|
|
|
|
|
funny = '@'; |
1071
|
|
|
|
|
|
|
/* we don't want perl to guess what is meant. the keyword |
1072
|
|
|
|
|
|
|
* parser decides that later. (rafl) |
1073
|
|
|
|
|
|
|
*/ |
1074
|
|
|
|
|
|
|
/* |
1075
|
|
|
|
|
|
|
if (PL_lex_state == LEX_NORMAL) { |
1076
|
|
|
|
|
|
|
if (ckWARN(WARN_AMBIGUOUS) && |
1077
|
|
|
|
|
|
|
(keyword(dest, d - dest) || get_cv(dest, FALSE))) |
1078
|
|
|
|
|
|
|
{ |
1079
|
|
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
1080
|
|
|
|
|
|
|
"Ambiguous use of %c{%s} resolved to %c%s", |
1081
|
|
|
|
|
|
|
funny, dest, funny, dest); |
1082
|
|
|
|
|
|
|
} |
1083
|
|
|
|
|
|
|
} |
1084
|
|
|
|
|
|
|
*/ |
1085
|
|
|
|
|
|
|
} |
1086
|
|
|
|
|
|
|
else { |
1087
|
0
|
|
|
|
|
|
s = bracket; /* let the parser handle it */ |
1088
|
0
|
|
|
|
|
|
*dest = '\0'; |
1089
|
|
|
|
|
|
|
} |
1090
|
|
|
|
|
|
|
} |
1091
|
|
|
|
|
|
|
/* don't intuit. we really just want the string. (rafl) */ |
1092
|
|
|
|
|
|
|
/* |
1093
|
|
|
|
|
|
|
else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
1094
|
|
|
|
|
|
|
PL_lex_state = LEX_INTERPEND; |
1095
|
|
|
|
|
|
|
*/ |
1096
|
0
|
|
|
|
|
|
return s; |
1097
|
|
|
|
|
|
|
} |