| 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
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
21
|
|
|
|
|
|
|
#include "perl.h" |
|
22
|
|
|
|
|
|
|
#define NEED_sv_2pv_flags |
|
23
|
|
|
|
|
|
|
#include "ppport.h" |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
/* the following #defines are stolen from assorted headers, not toke.c (mst) */ |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#define skipspace_flags(a,b) S_skipspace(aTHX_ a) |
|
28
|
|
|
|
|
|
|
#define skipspace(a) skipspace_flags(a, 0) |
|
29
|
|
|
|
|
|
|
#define incline(a) S_incline(aTHX_ a) |
|
30
|
|
|
|
|
|
|
#define filter_gets(a,b,c) S_filter_gets(aTHX_ a,b,c) |
|
31
|
|
|
|
|
|
|
#define scan_str(a,b,c,d,e) S_scan_str(aTHX_ a,b,c) |
|
32
|
|
|
|
|
|
|
#define scan_word(a,b,c,d,e) S_scan_word(aTHX_ a,b,c,d,e) |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
STATIC void S_incline(pTHX_ char *s); |
|
35
|
|
|
|
|
|
|
STATIC char* S_skipspace(pTHX_ char *s); |
|
36
|
|
|
|
|
|
|
STATIC char * S_filter_gets(pTHX_ SV *sv, PerlIO *fp, STRLEN append); |
|
37
|
|
|
|
|
|
|
STATIC char* S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims); |
|
38
|
|
|
|
|
|
|
STATIC char* S_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#ifndef DPTR2FPTR |
|
41
|
|
|
|
|
|
|
#define DPTR2FPTR(t,p) ((t)PTR2nat(p)) /* data pointer to function pointer */ |
|
42
|
|
|
|
|
|
|
#endif |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#ifndef FPTR2DPTR |
|
45
|
|
|
|
|
|
|
#define FPTR2DPTR(t,p) ((t)PTR2nat(p)) /* function pointer to data pointer */ |
|
46
|
|
|
|
|
|
|
#endif |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#ifndef PTR2nat |
|
49
|
|
|
|
|
|
|
#define PTR2nat(p) (PTRV)(p) /* pointer to integer of PTRSIZE */ |
|
50
|
|
|
|
|
|
|
#endif |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#ifndef MEM_WRAP_CHECK_ |
|
53
|
|
|
|
|
|
|
#define MEM_WRAP_CHECK_(n,t) MEM_WRAP_CHECK(n,t), |
|
54
|
|
|
|
|
|
|
#endif |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
/* On MacOS, respect nonbreaking spaces */ |
|
57
|
|
|
|
|
|
|
#ifdef MACOS_TRADITIONAL |
|
58
|
|
|
|
|
|
|
#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') |
|
59
|
|
|
|
|
|
|
#else |
|
60
|
|
|
|
|
|
|
#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') |
|
61
|
|
|
|
|
|
|
#endif |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#define LEX_NORMAL 10 /* normal code (ie not within "...") */ |
|
66
|
|
|
|
|
|
|
#define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */ |
|
67
|
|
|
|
|
|
|
#define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */ |
|
68
|
|
|
|
|
|
|
#define LEX_INTERPPUSH 7 /* starting a new sublex parse level */ |
|
69
|
|
|
|
|
|
|
#define LEX_INTERPSTART 6 /* expecting the start of a $var */ |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
/* at end of code, eg "$x" followed by: */ |
|
72
|
|
|
|
|
|
|
#define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */ |
|
73
|
|
|
|
|
|
|
#define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */ |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of |
|
76
|
|
|
|
|
|
|
string or after \E, $foo, etc */ |
|
77
|
|
|
|
|
|
|
#define LEX_INTERPCONST 2 /* NOT USED */ |
|
78
|
|
|
|
|
|
|
#define LEX_FORMLINE 1 /* expecting a format line */ |
|
79
|
|
|
|
|
|
|
#define LEX_KNOWNEXT 0 /* next token known; just return it */ |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
/* and these two are my own madness (mst) */ |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#if PERL_REVISION == 5 && PERL_VERSION == 8 && PERL_SUBVERSION >= 8 |
|
84
|
|
|
|
|
|
|
#define PERL_5_8_8_PLUS |
|
85
|
|
|
|
|
|
|
#endif |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#if PERL_REVISION == 5 && PERL_VERSION > 8 |
|
88
|
|
|
|
|
|
|
#define PERL_5_9_PLUS |
|
89
|
|
|
|
|
|
|
#endif |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#ifdef PERL_5_9_PLUS |
|
92
|
|
|
|
|
|
|
/* 5.9+ moves a bunch of things to a PL_parser struct so we need to |
|
93
|
|
|
|
|
|
|
declare the backcompat macros for things to still work (mst) */ |
|
94
|
|
|
|
|
|
|
#define PL_lex_formbrack (PL_parser->lex_formbrack) |
|
95
|
|
|
|
|
|
|
#define PL_lex_brackets (PL_parser->lex_brackets) |
|
96
|
|
|
|
|
|
|
#define PL_lex_inwhat (PL_parser->lex_inwhat) |
|
97
|
|
|
|
|
|
|
#define PL_sublex_info (PL_parser->sublex_info) |
|
98
|
|
|
|
|
|
|
#define PL_oldoldbufptr (PL_parser->oldoldbufptr) |
|
99
|
|
|
|
|
|
|
#define PL_oldbufptr (PL_parser->oldbufptr) |
|
100
|
|
|
|
|
|
|
#define PL_linestart (PL_parser->linestart) |
|
101
|
|
|
|
|
|
|
#define PL_last_lop (PL_parser->last_lop) |
|
102
|
|
|
|
|
|
|
#define PL_last_uni (PL_parser->last_uni) |
|
103
|
|
|
|
|
|
|
#define PL_multi_start (PL_parser->multi_start) |
|
104
|
|
|
|
|
|
|
#define PL_multi_open (PL_parser->multi_open) |
|
105
|
|
|
|
|
|
|
#define PL_multi_close (PL_parser->multi_close) |
|
106
|
|
|
|
|
|
|
#define PL_multi_end (PL_parser->multi_end) |
|
107
|
|
|
|
|
|
|
#define PL_lex_repl (PL_parser->lex_repl) |
|
108
|
|
|
|
|
|
|
#define PL_nexttype (PL_parser->nexttype) |
|
109
|
|
|
|
|
|
|
#define PL_nexttoke (PL_parser->nexttoke) |
|
110
|
|
|
|
|
|
|
#define PL_lex_defer (PL_parser->lex_defer) |
|
111
|
|
|
|
|
|
|
#define PL_lex_expect (PL_parser->lex_expect) |
|
112
|
|
|
|
|
|
|
#endif |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
/* and now we're back to the toke.c stuff again (mst) */ |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
static const char ident_too_long[] = |
|
117
|
|
|
|
|
|
|
"Identifier too long"; |
|
118
|
|
|
|
|
|
|
static const char c_without_g[] = |
|
119
|
|
|
|
|
|
|
"Use of /c modifier is meaningless without /g"; |
|
120
|
|
|
|
|
|
|
static const char c_in_subst[] = |
|
121
|
|
|
|
|
|
|
"Use of /c modifier is meaningless in s///"; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#ifdef USE_UTF8_SCRIPTS |
|
124
|
|
|
|
|
|
|
# define UTF (!IN_BYTES) |
|
125
|
|
|
|
|
|
|
#else |
|
126
|
|
|
|
|
|
|
# define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8)) |
|
127
|
|
|
|
|
|
|
#endif |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
/* Invoke the idxth filter function for the current rsfp. */ |
|
130
|
|
|
|
|
|
|
/* maxlen 0 = read one text line */ |
|
131
|
|
|
|
|
|
|
I32 |
|
132
|
0
|
|
|
|
|
|
Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
|
133
|
|
|
|
|
|
|
{ |
|
134
|
|
|
|
|
|
|
filter_t funcp; |
|
135
|
0
|
|
|
|
|
|
SV *datasv = NULL; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
if (!PL_rsfp_filters) |
|
|
|
0
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
return -1; |
|
139
|
0
|
0
|
|
|
|
|
if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
|
|
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
/* Provide a default input filter to make life easy. */ |
|
141
|
|
|
|
|
|
|
/* Note that we append to the line. This is handy. */ |
|
142
|
|
|
|
|
|
|
DEBUG_P(PerlIO_printf(Perl_debug_log, |
|
143
|
|
|
|
|
|
|
"filter_read %d: from rsfp\n", idx)); |
|
144
|
0
|
0
|
|
|
|
|
if (maxlen) { |
|
145
|
|
|
|
|
|
|
/* Want a block */ |
|
146
|
|
|
|
|
|
|
int len ; |
|
147
|
0
|
|
|
|
|
|
const int old_len = SvCUR(buf_sv); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
/* ensure buf_sv is large enough */ |
|
150
|
0
|
0
|
|
|
|
|
SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ; |
|
|
|
0
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
|
|
|
0
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
|
if (PerlIO_error(PL_rsfp)) |
|
|
|
0
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
return -1; /* error */ |
|
154
|
|
|
|
|
|
|
else |
|
155
|
0
|
|
|
|
|
|
return 0 ; /* end of file */ |
|
156
|
|
|
|
|
|
|
} |
|
157
|
0
|
|
|
|
|
|
SvCUR_set(buf_sv, old_len + len) ; |
|
158
|
|
|
|
|
|
|
} else { |
|
159
|
|
|
|
|
|
|
/* Want a line */ |
|
160
|
0
|
0
|
|
|
|
|
if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
|
|
|
0
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
if (PerlIO_error(PL_rsfp)) |
|
|
|
0
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
return -1; /* error */ |
|
163
|
|
|
|
|
|
|
else |
|
164
|
0
|
|
|
|
|
|
return 0 ; /* end of file */ |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
} |
|
167
|
0
|
|
|
|
|
|
return SvCUR(buf_sv); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
/* Skip this filter slot if filter has been deleted */ |
|
170
|
0
|
0
|
|
|
|
|
if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
|
|
|
0
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
DEBUG_P(PerlIO_printf(Perl_debug_log, |
|
172
|
|
|
|
|
|
|
"filter_read %d: skipped (filter deleted)\n", |
|
173
|
|
|
|
|
|
|
idx)); |
|
174
|
0
|
|
|
|
|
|
return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
/* Get function pointer hidden within datasv */ |
|
177
|
0
|
|
|
|
|
|
funcp = DPTR2FPTR(filter_t, IoANY(datasv)); |
|
178
|
|
|
|
|
|
|
DEBUG_P(PerlIO_printf(Perl_debug_log, |
|
179
|
|
|
|
|
|
|
"filter_read %d: via function %p (%s)\n", |
|
180
|
|
|
|
|
|
|
idx, datasv, SvPV_nolen_const(datasv))); |
|
181
|
|
|
|
|
|
|
/* Call function. The function is expected to */ |
|
182
|
|
|
|
|
|
|
/* call "FILTER_READ(idx+1, buf_sv)" first. */ |
|
183
|
|
|
|
|
|
|
/* Return: <0:error, =0:eof, >0:not eof */ |
|
184
|
0
|
|
|
|
|
|
return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
STATIC char * |
|
188
|
0
|
|
|
|
|
|
S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
|
189
|
|
|
|
|
|
|
{ |
|
190
|
|
|
|
|
|
|
#ifdef PERL_CR_FILTER |
|
191
|
|
|
|
|
|
|
if (!PL_rsfp_filters) { |
|
192
|
|
|
|
|
|
|
filter_add(S_cr_textfilter,NULL); |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
#endif |
|
195
|
0
|
0
|
|
|
|
|
if (PL_rsfp_filters) { |
|
|
|
0
|
|
|
|
|
|
|
196
|
0
|
0
|
|
|
|
|
if (!append) |
|
197
|
0
|
|
|
|
|
|
SvCUR_set(sv, 0); /* start with empty line */ |
|
198
|
0
|
0
|
|
|
|
|
if (FILTER_READ(0, sv, 0) > 0) |
|
199
|
0
|
|
|
|
|
|
return ( SvPVX(sv) ) ; |
|
200
|
|
|
|
|
|
|
else |
|
201
|
0
|
|
|
|
|
|
return Nullch ; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
else |
|
204
|
0
|
|
|
|
|
|
return (sv_gets(sv, fp, append)); |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
/* |
|
208
|
|
|
|
|
|
|
* S_skipspace |
|
209
|
|
|
|
|
|
|
* Called to gobble the appropriate amount and type of whitespace. |
|
210
|
|
|
|
|
|
|
* Skips comments as well. |
|
211
|
|
|
|
|
|
|
*/ |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
STATIC char * |
|
214
|
0
|
|
|
|
|
|
S_skipspace(pTHX_ register char *s) |
|
215
|
|
|
|
|
|
|
{ |
|
216
|
0
|
0
|
|
|
|
|
if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
|
|
|
0
|
|
|
|
|
|
|
217
|
0
|
0
|
|
|
|
|
while (s < PL_bufend && SPACE_OR_TAB(*s)) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
s++; |
|
219
|
0
|
|
|
|
|
|
return s; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
for (;;) { |
|
222
|
|
|
|
|
|
|
STRLEN prevlen; |
|
223
|
|
|
|
|
|
|
SSize_t oldprevlen, oldoldprevlen; |
|
224
|
0
|
|
|
|
|
|
SSize_t oldloplen = 0, oldunilen = 0; |
|
225
|
0
|
0
|
|
|
|
|
while (s < PL_bufend && isSPACE(*s)) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
226
|
0
|
0
|
|
|
|
|
if (*s++ == '\n' && PL_in_eval && !PL_rsfp) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
incline(s); |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
/* comment */ |
|
231
|
0
|
0
|
|
|
|
|
if (s < PL_bufend && *s == '#') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
232
|
0
|
0
|
|
|
|
|
while (s < PL_bufend && *s != '\n') |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
s++; |
|
234
|
0
|
0
|
|
|
|
|
if (s < PL_bufend) { |
|
|
|
0
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
s++; |
|
236
|
0
|
0
|
|
|
|
|
if (PL_in_eval && !PL_rsfp) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
incline(s); |
|
238
|
0
|
|
|
|
|
|
continue; |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
/* only continue to recharge the buffer if we're at the end |
|
244
|
|
|
|
|
|
|
* of the buffer, we're not reading from a source filter, and |
|
245
|
|
|
|
|
|
|
* we're in normal lexing mode |
|
246
|
|
|
|
|
|
|
*/ |
|
247
|
0
|
0
|
|
|
|
|
if (s < PL_bufend || !PL_rsfp || PL_lex_inwhat || |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
248
|
0
|
0
|
|
|
|
|
PL_lex_state == LEX_FORMLINE) |
|
249
|
0
|
|
|
|
|
|
return s; |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
/* try to recharge the buffer */ |
|
252
|
0
|
0
|
|
|
|
|
if ((s = filter_gets(PL_linestr, PL_rsfp, |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
(prevlen = SvCUR(PL_linestr)))) == Nullch) |
|
254
|
|
|
|
|
|
|
{ |
|
255
|
|
|
|
|
|
|
/* end of file. Add on the -p or -n magic */ |
|
256
|
0
|
0
|
|
|
|
|
if (PL_minus_p) { |
|
257
|
0
|
0
|
|
|
|
|
sv_setpv(PL_linestr, |
|
258
|
|
|
|
|
|
|
";}continue{print or die qq(-p destination: $!\\n);}"); |
|
259
|
0
|
|
|
|
|
|
PL_minus_n = PL_minus_p = 0; |
|
260
|
|
|
|
|
|
|
} |
|
261
|
0
|
0
|
|
|
|
|
else if (PL_minus_n) { |
|
262
|
0
|
0
|
|
|
|
|
sv_setpvn(PL_linestr, ";}", 2); |
|
263
|
0
|
|
|
|
|
|
PL_minus_n = 0; |
|
264
|
|
|
|
|
|
|
} |
|
265
|
|
|
|
|
|
|
else |
|
266
|
0
|
0
|
|
|
|
|
sv_setpvn(PL_linestr,";", 1); |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
/* reset variables for next time we lex */ |
|
269
|
0
|
0
|
|
|
|
|
PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
|
270
|
0
|
0
|
|
|
|
|
= SvPVX(PL_linestr); |
|
271
|
0
|
0
|
|
|
|
|
PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
PL_last_lop = PL_last_uni = Nullch; |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
/* In perl versions previous to p4-rawid: //depot/perl@32954 -P |
|
275
|
|
|
|
|
|
|
* preprocessors were supported here. We don't support -P at all, even |
|
276
|
|
|
|
|
|
|
* on perls that support it, and use the following chunk from blead |
|
277
|
|
|
|
|
|
|
* perl. (rafl) |
|
278
|
|
|
|
|
|
|
*/ |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
/* Close the filehandle. Could be from |
|
281
|
|
|
|
|
|
|
* STDIN, or a regular file. If we were reading code from |
|
282
|
|
|
|
|
|
|
* STDIN (because the commandline held no -e or filename) |
|
283
|
|
|
|
|
|
|
* then we don't close it, we reset it so the code can |
|
284
|
|
|
|
|
|
|
* read from STDIN too. |
|
285
|
|
|
|
|
|
|
*/ |
|
286
|
|
|
|
|
|
|
|
|
287
|
0
|
0
|
|
|
|
|
if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
|
|
|
0
|
|
|
|
|
|
|
288
|
0
|
0
|
|
|
|
|
PerlIO_clearerr(PL_rsfp); |
|
289
|
|
|
|
|
|
|
else |
|
290
|
0
|
0
|
|
|
|
|
(void)PerlIO_close(PL_rsfp); |
|
291
|
0
|
0
|
|
|
|
|
PL_rsfp = Nullfp; |
|
292
|
0
|
|
|
|
|
|
return s; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
/* not at end of file, so we only read another line */ |
|
296
|
|
|
|
|
|
|
/* make corresponding updates to old pointers, for yyerror() */ |
|
297
|
0
|
0
|
|
|
|
|
oldprevlen = PL_oldbufptr - PL_bufend; |
|
298
|
0
|
0
|
|
|
|
|
oldoldprevlen = PL_oldoldbufptr - PL_bufend; |
|
299
|
0
|
0
|
|
|
|
|
if (PL_last_uni) |
|
300
|
0
|
0
|
|
|
|
|
oldunilen = PL_last_uni - PL_bufend; |
|
301
|
0
|
0
|
|
|
|
|
if (PL_last_lop) |
|
302
|
0
|
0
|
|
|
|
|
oldloplen = PL_last_lop - PL_bufend; |
|
303
|
0
|
0
|
|
|
|
|
PL_linestart = PL_bufptr = s + prevlen; |
|
304
|
0
|
0
|
|
|
|
|
PL_bufend = s + SvCUR(PL_linestr); |
|
|
|
0
|
|
|
|
|
|
|
305
|
0
|
0
|
|
|
|
|
s = PL_bufptr; |
|
306
|
0
|
|
|
|
|
|
PL_oldbufptr = s + oldprevlen; |
|
307
|
0
|
|
|
|
|
|
PL_oldoldbufptr = s + oldoldprevlen; |
|
308
|
0
|
0
|
|
|
|
|
if (PL_last_uni) |
|
309
|
0
|
|
|
|
|
|
PL_last_uni = s + oldunilen; |
|
310
|
0
|
0
|
|
|
|
|
if (PL_last_lop) |
|
311
|
0
|
|
|
|
|
|
PL_last_lop = s + oldloplen; |
|
312
|
0
|
|
|
|
|
|
incline(s); |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
/* debugger active and we're not compiling the debugger code, |
|
315
|
|
|
|
|
|
|
* so store the line into the debugger's array of lines |
|
316
|
|
|
|
|
|
|
*/ |
|
317
|
0
|
0
|
|
|
|
|
if (PERLDB_LINE && PL_curstash != PL_debstash) { |
|
|
|
0
|
|
|
|
|
|
|
318
|
0
|
0
|
|
|
|
|
AV *fileav = CopFILEAV(PL_curcop); |
|
319
|
0
|
0
|
|
|
|
|
if (fileav) { |
|
320
|
0
|
|
|
|
|
|
SV * const sv = NEWSV(85,0); |
|
321
|
0
|
|
|
|
|
|
sv_upgrade(sv, SVt_PVMG); |
|
322
|
0
|
0
|
|
|
|
|
sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
323
|
0
|
|
|
|
|
|
(void)SvIOK_on(sv); |
|
324
|
0
|
|
|
|
|
|
SvIV_set(sv, 0); |
|
325
|
0
|
|
|
|
|
|
av_store(fileav,(I32)CopLINE(PL_curcop),sv); |
|
326
|
|
|
|
|
|
|
} |
|
327
|
|
|
|
|
|
|
} |
|
328
|
0
|
|
|
|
|
|
} |
|
329
|
|
|
|
|
|
|
} |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
STATIC char * |
|
332
|
0
|
|
|
|
|
|
S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
|
333
|
|
|
|
|
|
|
{ |
|
334
|
0
|
|
|
|
|
|
register char *d = dest; |
|
335
|
0
|
|
|
|
|
|
register char * const e = d + destlen - 3; /* two-character token, ending NUL */ |
|
336
|
|
|
|
|
|
|
for (;;) { |
|
337
|
0
|
0
|
|
|
|
|
if (d >= e) |
|
338
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ ident_too_long); |
|
339
|
0
|
0
|
|
|
|
|
if (isALNUM(*s)) /* UTF handled below */ |
|
340
|
0
|
|
|
|
|
|
*d++ = *s++; |
|
341
|
0
|
0
|
|
|
|
|
else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
342
|
0
|
|
|
|
|
|
*d++ = ':'; |
|
343
|
0
|
|
|
|
|
|
*d++ = ':'; |
|
344
|
0
|
|
|
|
|
|
s++; |
|
345
|
|
|
|
|
|
|
} |
|
346
|
0
|
0
|
|
|
|
|
else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
347
|
0
|
|
|
|
|
|
*d++ = *s++; |
|
348
|
0
|
|
|
|
|
|
*d++ = *s++; |
|
349
|
|
|
|
|
|
|
} |
|
350
|
0
|
0
|
|
|
|
|
else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
351
|
0
|
|
|
|
|
|
char *t = s + UTF8SKIP(s); |
|
352
|
0
|
0
|
|
|
|
|
while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
|
|
|
0
|
|
|
|
|
|
|
353
|
0
|
|
|
|
|
|
t += UTF8SKIP(t); |
|
354
|
0
|
0
|
|
|
|
|
if (d + (t - s) > e) |
|
355
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ ident_too_long); |
|
356
|
0
|
|
|
|
|
|
Copy(s, d, t - s, char); |
|
357
|
0
|
|
|
|
|
|
d += t - s; |
|
358
|
0
|
|
|
|
|
|
s = t; |
|
359
|
|
|
|
|
|
|
} |
|
360
|
|
|
|
|
|
|
else { |
|
361
|
0
|
|
|
|
|
|
*d = '\0'; |
|
362
|
0
|
|
|
|
|
|
*slp = d - dest; |
|
363
|
0
|
|
|
|
|
|
return s; |
|
364
|
|
|
|
|
|
|
} |
|
365
|
0
|
|
|
|
|
|
} |
|
366
|
|
|
|
|
|
|
} |
|
367
|
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
/* |
|
369
|
|
|
|
|
|
|
* S_incline |
|
370
|
|
|
|
|
|
|
* This subroutine has nothing to do with tilting, whether at windmills |
|
371
|
|
|
|
|
|
|
* or pinball tables. Its name is short for "increment line". It |
|
372
|
|
|
|
|
|
|
* increments the current line number in CopLINE(PL_curcop) and checks |
|
373
|
|
|
|
|
|
|
* to see whether the line starts with a comment of the form |
|
374
|
|
|
|
|
|
|
* # line 500 "foo.pm" |
|
375
|
|
|
|
|
|
|
* If so, it sets the current line number and file to the values in the comment. |
|
376
|
|
|
|
|
|
|
*/ |
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
STATIC void |
|
379
|
0
|
|
|
|
|
|
S_incline(pTHX_ char *s) |
|
380
|
|
|
|
|
|
|
{ |
|
381
|
|
|
|
|
|
|
char *t; |
|
382
|
|
|
|
|
|
|
char *n; |
|
383
|
|
|
|
|
|
|
char *e; |
|
384
|
|
|
|
|
|
|
char ch; |
|
385
|
|
|
|
|
|
|
|
|
386
|
0
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
|
387
|
0
|
0
|
|
|
|
|
if (*s++ != '#') |
|
388
|
0
|
|
|
|
|
|
return; |
|
389
|
0
|
0
|
|
|
|
|
while (SPACE_OR_TAB(*s)) s++; |
|
|
|
0
|
|
|
|
|
|
|
390
|
0
|
0
|
|
|
|
|
if (strnEQ(s, "line", 4)) |
|
391
|
0
|
|
|
|
|
|
s += 4; |
|
392
|
|
|
|
|
|
|
else |
|
393
|
0
|
|
|
|
|
|
return; |
|
394
|
0
|
0
|
|
|
|
|
if (SPACE_OR_TAB(*s)) |
|
|
|
0
|
|
|
|
|
|
|
395
|
0
|
|
|
|
|
|
s++; |
|
396
|
|
|
|
|
|
|
else |
|
397
|
0
|
|
|
|
|
|
return; |
|
398
|
0
|
0
|
|
|
|
|
while (SPACE_OR_TAB(*s)) s++; |
|
|
|
0
|
|
|
|
|
|
|
399
|
0
|
0
|
|
|
|
|
if (!isDIGIT(*s)) |
|
400
|
0
|
|
|
|
|
|
return; |
|
401
|
0
|
|
|
|
|
|
n = s; |
|
402
|
0
|
0
|
|
|
|
|
while (isDIGIT(*s)) |
|
403
|
0
|
|
|
|
|
|
s++; |
|
404
|
0
|
0
|
|
|
|
|
while (SPACE_OR_TAB(*s)) |
|
|
|
0
|
|
|
|
|
|
|
405
|
0
|
|
|
|
|
|
s++; |
|
406
|
0
|
0
|
|
|
|
|
if (*s == '"' && (t = strchr(s+1, '"'))) { |
|
|
|
0
|
|
|
|
|
|
|
407
|
0
|
|
|
|
|
|
s++; |
|
408
|
0
|
|
|
|
|
|
e = t + 1; |
|
409
|
|
|
|
|
|
|
} |
|
410
|
|
|
|
|
|
|
else { |
|
411
|
0
|
0
|
|
|
|
|
for (t = s; !isSPACE(*t); t++) ; |
|
412
|
0
|
|
|
|
|
|
e = t; |
|
413
|
|
|
|
|
|
|
} |
|
414
|
0
|
0
|
|
|
|
|
while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
415
|
0
|
|
|
|
|
|
e++; |
|
416
|
0
|
0
|
|
|
|
|
if (*e != '\n' && *e != '\0') |
|
|
|
0
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
|
return; /* false alarm */ |
|
418
|
|
|
|
|
|
|
|
|
419
|
0
|
|
|
|
|
|
ch = *t; |
|
420
|
0
|
|
|
|
|
|
*t = '\0'; |
|
421
|
0
|
0
|
|
|
|
|
if (t - s > 0) { |
|
422
|
|
|
|
|
|
|
/* this chunk was added to S_incline during 5.8.8. I don't know why but I don't |
|
423
|
|
|
|
|
|
|
honestly care since I probably want to be bug-compatible anyway (mst) */ |
|
424
|
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
/* ... my kingdom for a perl parser in perl ... (mst) */ |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
#ifdef PERL_5_8_8_PLUS |
|
428
|
|
|
|
|
|
|
#ifndef USE_ITHREADS |
|
429
|
|
|
|
|
|
|
const char *cf = CopFILE(PL_curcop); |
|
430
|
|
|
|
|
|
|
if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) { |
|
431
|
|
|
|
|
|
|
/* must copy *{"::_<(eval N)[oldfilename:L]"} |
|
432
|
|
|
|
|
|
|
* to *{"::_
|
|
433
|
|
|
|
|
|
|
char smallbuf[256], smallbuf2[256]; |
|
434
|
|
|
|
|
|
|
char *tmpbuf, *tmpbuf2; |
|
435
|
|
|
|
|
|
|
GV **gvp, *gv2; |
|
436
|
|
|
|
|
|
|
STRLEN tmplen = strlen(cf); |
|
437
|
|
|
|
|
|
|
STRLEN tmplen2 = strlen(s); |
|
438
|
|
|
|
|
|
|
if (tmplen + 3 < sizeof smallbuf) |
|
439
|
|
|
|
|
|
|
tmpbuf = smallbuf; |
|
440
|
|
|
|
|
|
|
else |
|
441
|
|
|
|
|
|
|
Newx(tmpbuf, tmplen + 3, char); |
|
442
|
|
|
|
|
|
|
if (tmplen2 + 3 < sizeof smallbuf2) |
|
443
|
|
|
|
|
|
|
tmpbuf2 = smallbuf2; |
|
444
|
|
|
|
|
|
|
else |
|
445
|
|
|
|
|
|
|
Newx(tmpbuf2, tmplen2 + 3, char); |
|
446
|
|
|
|
|
|
|
tmpbuf[0] = tmpbuf2[0] = '_'; |
|
447
|
|
|
|
|
|
|
tmpbuf[1] = tmpbuf2[1] = '<'; |
|
448
|
|
|
|
|
|
|
memcpy(tmpbuf + 2, cf, ++tmplen); |
|
449
|
|
|
|
|
|
|
memcpy(tmpbuf2 + 2, s, ++tmplen2); |
|
450
|
|
|
|
|
|
|
++tmplen; ++tmplen2; |
|
451
|
|
|
|
|
|
|
gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE); |
|
452
|
|
|
|
|
|
|
if (gvp) { |
|
453
|
|
|
|
|
|
|
gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE); |
|
454
|
|
|
|
|
|
|
if (!isGV(gv2)) |
|
455
|
|
|
|
|
|
|
gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE); |
|
456
|
|
|
|
|
|
|
/* adjust ${"::_
|
|
457
|
|
|
|
|
|
|
GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2); |
|
458
|
|
|
|
|
|
|
GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp)); |
|
459
|
|
|
|
|
|
|
GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp)); |
|
460
|
|
|
|
|
|
|
} |
|
461
|
|
|
|
|
|
|
if (tmpbuf != smallbuf) Safefree(tmpbuf); |
|
462
|
|
|
|
|
|
|
if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2); |
|
463
|
|
|
|
|
|
|
} |
|
464
|
|
|
|
|
|
|
#endif |
|
465
|
|
|
|
|
|
|
#endif |
|
466
|
|
|
|
|
|
|
/* second endif closes out the "are we 5.8.(8+)" conditional */ |
|
467
|
0
|
|
|
|
|
|
CopFILE_free(PL_curcop); |
|
468
|
0
|
|
|
|
|
|
CopFILE_set(PL_curcop, s); |
|
469
|
|
|
|
|
|
|
} |
|
470
|
0
|
|
|
|
|
|
*t = ch; |
|
471
|
0
|
|
|
|
|
|
CopLINE_set(PL_curcop, atoi(n)-1); |
|
472
|
|
|
|
|
|
|
} |
|
473
|
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
/* scan_str |
|
475
|
|
|
|
|
|
|
takes: start position in buffer |
|
476
|
|
|
|
|
|
|
keep_quoted preserve \ on the embedded delimiter(s) |
|
477
|
|
|
|
|
|
|
keep_delims preserve the delimiters around the string |
|
478
|
|
|
|
|
|
|
returns: position to continue reading from buffer |
|
479
|
|
|
|
|
|
|
side-effects: multi_start, multi_close, lex_repl or lex_stuff, and |
|
480
|
|
|
|
|
|
|
updates the read buffer. |
|
481
|
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
This subroutine pulls a string out of the input. It is called for: |
|
483
|
|
|
|
|
|
|
q single quotes q(literal text) |
|
484
|
|
|
|
|
|
|
' single quotes 'literal text' |
|
485
|
|
|
|
|
|
|
qq double quotes qq(interpolate $here please) |
|
486
|
|
|
|
|
|
|
" double quotes "interpolate $here please" |
|
487
|
|
|
|
|
|
|
qx backticks qx(/bin/ls -l) |
|
488
|
|
|
|
|
|
|
` backticks `/bin/ls -l` |
|
489
|
|
|
|
|
|
|
qw quote words @EXPORT_OK = qw( func() $spam ) |
|
490
|
|
|
|
|
|
|
m// regexp match m/this/ |
|
491
|
|
|
|
|
|
|
s/// regexp substitute s/this/that/ |
|
492
|
|
|
|
|
|
|
tr/// string transliterate tr/this/that/ |
|
493
|
|
|
|
|
|
|
y/// string transliterate y/this/that/ |
|
494
|
|
|
|
|
|
|
($*@) sub prototypes sub foo ($) |
|
495
|
|
|
|
|
|
|
(stuff) sub attr parameters sub foo : attr(stuff) |
|
496
|
|
|
|
|
|
|
<> readline or globs , <>, <$fh>, or <*.c> |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
In most of these cases (all but <>, patterns and transliterate) |
|
499
|
|
|
|
|
|
|
yylex() calls scan_str(). m// makes yylex() call scan_pat() which |
|
500
|
|
|
|
|
|
|
calls scan_str(). s/// makes yylex() call scan_subst() which calls |
|
501
|
|
|
|
|
|
|
scan_str(). tr/// and y/// make yylex() call scan_trans() which |
|
502
|
|
|
|
|
|
|
calls scan_str(). |
|
503
|
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
It skips whitespace before the string starts, and treats the first |
|
505
|
|
|
|
|
|
|
character as the delimiter. If the delimiter is one of ([{< then |
|
506
|
|
|
|
|
|
|
the corresponding "close" character )]}> is used as the closing |
|
507
|
|
|
|
|
|
|
delimiter. It allows quoting of delimiters, and if the string has |
|
508
|
|
|
|
|
|
|
balanced delimiters ([{<>}]) it allows nesting. |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
On success, the SV with the resulting string is put into lex_stuff or, |
|
511
|
|
|
|
|
|
|
if that is already non-NULL, into lex_repl. The second case occurs only |
|
512
|
|
|
|
|
|
|
when parsing the RHS of the special constructs s/// and tr/// (y///). |
|
513
|
|
|
|
|
|
|
For convenience, the terminating delimiter character is stuffed into |
|
514
|
|
|
|
|
|
|
SvIVX of the SV. |
|
515
|
|
|
|
|
|
|
*/ |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
STATIC char * |
|
518
|
0
|
|
|
|
|
|
S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
|
519
|
|
|
|
|
|
|
{ |
|
520
|
|
|
|
|
|
|
SV *sv; /* scalar value: string */ |
|
521
|
|
|
|
|
|
|
char *tmps; /* temp string, used for delimiter matching */ |
|
522
|
0
|
|
|
|
|
|
register char *s = start; /* current position in the buffer */ |
|
523
|
|
|
|
|
|
|
register char term; /* terminating character */ |
|
524
|
|
|
|
|
|
|
register char *to; /* current position in the sv's data */ |
|
525
|
0
|
|
|
|
|
|
I32 brackets = 1; /* bracket nesting level */ |
|
526
|
0
|
|
|
|
|
|
bool has_utf8 = FALSE; /* is there any utf8 content? */ |
|
527
|
|
|
|
|
|
|
I32 termcode; /* terminating char. code */ |
|
528
|
|
|
|
|
|
|
/* 5.8.7+ uses UTF8_MAXBYTES but also its utf8.h defs _MAXLEN to it so |
|
529
|
|
|
|
|
|
|
I'm reasonably hopeful this won't destroy anything (mst) */ |
|
530
|
|
|
|
|
|
|
U8 termstr[UTF8_MAXLEN]; /* terminating string */ |
|
531
|
|
|
|
|
|
|
STRLEN termlen; /* length of terminating string */ |
|
532
|
0
|
|
|
|
|
|
char *last = NULL; /* last position for nesting bracket */ |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
/* skip space before the delimiter */ |
|
535
|
0
|
0
|
|
|
|
|
if (isSPACE(*s)) |
|
536
|
0
|
|
|
|
|
|
s = skipspace(s); |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
/* mark where we are, in case we need to report errors */ |
|
539
|
0
|
0
|
|
|
|
|
CLINE; |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
/* after skipping whitespace, the next character is the terminator */ |
|
542
|
0
|
|
|
|
|
|
term = *s; |
|
543
|
0
|
0
|
|
|
|
|
if (!UTF) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
544
|
0
|
|
|
|
|
|
termcode = termstr[0] = term; |
|
545
|
0
|
|
|
|
|
|
termlen = 1; |
|
546
|
|
|
|
|
|
|
} |
|
547
|
|
|
|
|
|
|
else { |
|
548
|
0
|
|
|
|
|
|
termcode = utf8_to_uvchr((U8*)s, &termlen); |
|
549
|
0
|
|
|
|
|
|
Copy(s, termstr, termlen, U8); |
|
550
|
0
|
0
|
|
|
|
|
if (!UTF8_IS_INVARIANT(term)) |
|
551
|
0
|
|
|
|
|
|
has_utf8 = TRUE; |
|
552
|
|
|
|
|
|
|
} |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
/* mark where we are */ |
|
555
|
0
|
|
|
|
|
|
PL_multi_start = CopLINE(PL_curcop); |
|
556
|
0
|
|
|
|
|
|
PL_multi_open = term; |
|
557
|
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
/* find corresponding closing delimiter */ |
|
559
|
0
|
0
|
|
|
|
|
if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
|
|
|
0
|
|
|
|
|
|
|
560
|
0
|
|
|
|
|
|
termcode = termstr[0] = term = tmps[5]; |
|
561
|
|
|
|
|
|
|
|
|
562
|
0
|
|
|
|
|
|
PL_multi_close = term; |
|
563
|
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
/* create a new SV to hold the contents. 87 is leak category, I'm |
|
565
|
|
|
|
|
|
|
assuming. 79 is the SV's initial length. What a random number. */ |
|
566
|
0
|
|
|
|
|
|
sv = NEWSV(87,79); |
|
567
|
0
|
|
|
|
|
|
sv_upgrade(sv, SVt_PVIV); |
|
568
|
0
|
|
|
|
|
|
SvIV_set(sv, termcode); |
|
569
|
0
|
|
|
|
|
|
(void)SvPOK_only(sv); /* validate pointer */ |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
/* move past delimiter and try to read a complete string */ |
|
572
|
0
|
0
|
|
|
|
|
if (keep_delims) |
|
573
|
0
|
|
|
|
|
|
sv_catpvn(sv, s, termlen); |
|
574
|
0
|
|
|
|
|
|
s += termlen; |
|
575
|
|
|
|
|
|
|
for (;;) { |
|
576
|
|
|
|
|
|
|
if (PL_encoding && !UTF) { |
|
577
|
|
|
|
|
|
|
bool cont = TRUE; |
|
578
|
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
while (cont) { |
|
580
|
|
|
|
|
|
|
int offset = s - SvPVX_const(PL_linestr); |
|
581
|
|
|
|
|
|
|
const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, |
|
582
|
|
|
|
|
|
|
&offset, (char*)termstr, termlen); |
|
583
|
|
|
|
|
|
|
const char *ns = SvPVX_const(PL_linestr) + offset; |
|
584
|
|
|
|
|
|
|
char *svlast = SvEND(sv) - 1; |
|
585
|
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
for (; s < ns; s++) { |
|
587
|
|
|
|
|
|
|
if (*s == '\n' && !PL_rsfp) |
|
588
|
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
|
589
|
|
|
|
|
|
|
} |
|
590
|
|
|
|
|
|
|
if (!found) |
|
591
|
|
|
|
|
|
|
goto read_more_line; |
|
592
|
|
|
|
|
|
|
else { |
|
593
|
|
|
|
|
|
|
/* handle quoted delimiters */ |
|
594
|
|
|
|
|
|
|
if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
|
595
|
|
|
|
|
|
|
const char *t; |
|
596
|
|
|
|
|
|
|
for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';) |
|
597
|
|
|
|
|
|
|
t--; |
|
598
|
|
|
|
|
|
|
if ((svlast-1 - t) % 2) { |
|
599
|
|
|
|
|
|
|
if (!keep_quoted) { |
|
600
|
|
|
|
|
|
|
*(svlast-1) = term; |
|
601
|
|
|
|
|
|
|
*svlast = '\0'; |
|
602
|
|
|
|
|
|
|
SvCUR_set(sv, SvCUR(sv) - 1); |
|
603
|
|
|
|
|
|
|
} |
|
604
|
|
|
|
|
|
|
continue; |
|
605
|
|
|
|
|
|
|
} |
|
606
|
|
|
|
|
|
|
} |
|
607
|
|
|
|
|
|
|
if (PL_multi_open == PL_multi_close) { |
|
608
|
|
|
|
|
|
|
cont = FALSE; |
|
609
|
|
|
|
|
|
|
} |
|
610
|
|
|
|
|
|
|
else { |
|
611
|
|
|
|
|
|
|
const char *t; |
|
612
|
|
|
|
|
|
|
char *w; |
|
613
|
|
|
|
|
|
|
if (!last) |
|
614
|
|
|
|
|
|
|
last = SvPVX(sv); |
|
615
|
|
|
|
|
|
|
for (t = w = last; t < svlast; w++, t++) { |
|
616
|
|
|
|
|
|
|
/* At here, all closes are "was quoted" one, |
|
617
|
|
|
|
|
|
|
so we don't check PL_multi_close. */ |
|
618
|
|
|
|
|
|
|
if (*t == '\\') { |
|
619
|
|
|
|
|
|
|
if (!keep_quoted && *(t+1) == PL_multi_open) |
|
620
|
|
|
|
|
|
|
t++; |
|
621
|
|
|
|
|
|
|
else |
|
622
|
|
|
|
|
|
|
*w++ = *t++; |
|
623
|
|
|
|
|
|
|
} |
|
624
|
|
|
|
|
|
|
else if (*t == PL_multi_open) |
|
625
|
|
|
|
|
|
|
brackets++; |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
*w = *t; |
|
628
|
|
|
|
|
|
|
} |
|
629
|
|
|
|
|
|
|
if (w < t) { |
|
630
|
|
|
|
|
|
|
*w++ = term; |
|
631
|
|
|
|
|
|
|
*w = '\0'; |
|
632
|
|
|
|
|
|
|
SvCUR_set(sv, w - SvPVX_const(sv)); |
|
633
|
|
|
|
|
|
|
} |
|
634
|
|
|
|
|
|
|
last = w; |
|
635
|
|
|
|
|
|
|
if (--brackets <= 0) |
|
636
|
|
|
|
|
|
|
cont = FALSE; |
|
637
|
|
|
|
|
|
|
} |
|
638
|
|
|
|
|
|
|
} |
|
639
|
|
|
|
|
|
|
} |
|
640
|
|
|
|
|
|
|
if (!keep_delims) { |
|
641
|
|
|
|
|
|
|
SvCUR_set(sv, SvCUR(sv) - 1); |
|
642
|
|
|
|
|
|
|
*SvEND(sv) = '\0'; |
|
643
|
|
|
|
|
|
|
} |
|
644
|
|
|
|
|
|
|
break; |
|
645
|
|
|
|
|
|
|
} |
|
646
|
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
/* extend sv if need be */ |
|
648
|
0
|
0
|
|
|
|
|
SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
/* set 'to' to the next character in the sv's string */ |
|
650
|
0
|
|
|
|
|
|
to = SvPVX(sv)+SvCUR(sv); |
|
651
|
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
/* if open delimiter is the close delimiter read unbridle */ |
|
653
|
0
|
0
|
|
|
|
|
if (PL_multi_open == PL_multi_close) { |
|
654
|
0
|
0
|
|
|
|
|
for (; s < PL_bufend; s++,to++) { |
|
|
|
0
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
/* embedded newlines increment the current line number */ |
|
656
|
0
|
0
|
|
|
|
|
if (*s == '\n' && !PL_rsfp) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
657
|
0
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
|
658
|
|
|
|
|
|
|
/* handle quoted delimiters */ |
|
659
|
0
|
0
|
|
|
|
|
if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
660
|
0
|
0
|
|
|
|
|
if (!keep_quoted && s[1] == term) |
|
|
|
0
|
|
|
|
|
|
|
661
|
0
|
|
|
|
|
|
s++; |
|
662
|
|
|
|
|
|
|
/* any other quotes are simply copied straight through */ |
|
663
|
|
|
|
|
|
|
else |
|
664
|
0
|
|
|
|
|
|
*to++ = *s++; |
|
665
|
|
|
|
|
|
|
} |
|
666
|
|
|
|
|
|
|
/* terminate when run out of buffer (the for() condition), or |
|
667
|
|
|
|
|
|
|
have found the terminator */ |
|
668
|
0
|
0
|
|
|
|
|
else if (*s == term) { |
|
669
|
0
|
0
|
|
|
|
|
if (termlen == 1) |
|
670
|
0
|
|
|
|
|
|
break; |
|
671
|
0
|
0
|
|
|
|
|
if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
672
|
0
|
|
|
|
|
|
break; |
|
673
|
|
|
|
|
|
|
} |
|
674
|
0
|
0
|
|
|
|
|
else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
675
|
0
|
|
|
|
|
|
has_utf8 = TRUE; |
|
676
|
0
|
|
|
|
|
|
*to = *s; |
|
677
|
|
|
|
|
|
|
} |
|
678
|
|
|
|
|
|
|
} |
|
679
|
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
/* if the terminator isn't the same as the start character (e.g., |
|
681
|
|
|
|
|
|
|
matched brackets), we have to allow more in the quoting, and |
|
682
|
|
|
|
|
|
|
be prepared for nested brackets. |
|
683
|
|
|
|
|
|
|
*/ |
|
684
|
|
|
|
|
|
|
else { |
|
685
|
|
|
|
|
|
|
/* read until we run out of string, or we find the terminator */ |
|
686
|
0
|
0
|
|
|
|
|
for (; s < PL_bufend; s++,to++) { |
|
|
|
0
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
/* embedded newlines increment the line count */ |
|
688
|
0
|
0
|
|
|
|
|
if (*s == '\n' && !PL_rsfp) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
689
|
0
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
|
690
|
|
|
|
|
|
|
/* backslashes can escape the open or closing characters */ |
|
691
|
0
|
0
|
|
|
|
|
if (*s == '\\' && s+1 < PL_bufend) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
692
|
0
|
0
|
|
|
|
|
if (!keep_quoted && |
|
|
|
0
|
|
|
|
|
|
|
693
|
0
|
0
|
|
|
|
|
((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) |
|
694
|
0
|
|
|
|
|
|
s++; |
|
695
|
|
|
|
|
|
|
else |
|
696
|
0
|
|
|
|
|
|
*to++ = *s++; |
|
697
|
|
|
|
|
|
|
} |
|
698
|
|
|
|
|
|
|
/* allow nested opens and closes */ |
|
699
|
0
|
0
|
|
|
|
|
else if (*s == PL_multi_close && --brackets <= 0) |
|
|
|
0
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
break; |
|
701
|
0
|
0
|
|
|
|
|
else if (*s == PL_multi_open) |
|
702
|
0
|
|
|
|
|
|
brackets++; |
|
703
|
0
|
0
|
|
|
|
|
else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
704
|
0
|
|
|
|
|
|
has_utf8 = TRUE; |
|
705
|
0
|
|
|
|
|
|
*to = *s; |
|
706
|
|
|
|
|
|
|
} |
|
707
|
|
|
|
|
|
|
} |
|
708
|
|
|
|
|
|
|
/* terminate the copied string and update the sv's end-of-string */ |
|
709
|
0
|
|
|
|
|
|
*to = '\0'; |
|
710
|
0
|
|
|
|
|
|
SvCUR_set(sv, to - SvPVX_const(sv)); |
|
711
|
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
/* |
|
713
|
|
|
|
|
|
|
* this next chunk reads more into the buffer if we're not done yet |
|
714
|
|
|
|
|
|
|
*/ |
|
715
|
|
|
|
|
|
|
|
|
716
|
0
|
0
|
|
|
|
|
if (s < PL_bufend) |
|
|
|
0
|
|
|
|
|
|
|
717
|
0
|
|
|
|
|
|
break; /* handle case where we are done yet :-) */ |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
#ifndef PERL_STRICT_CR |
|
720
|
0
|
0
|
|
|
|
|
if (to - SvPVX_const(sv) >= 2) { |
|
721
|
0
|
0
|
|
|
|
|
if ((to[-2] == '\r' && to[-1] == '\n') || |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
722
|
0
|
0
|
|
|
|
|
(to[-2] == '\n' && to[-1] == '\r')) |
|
723
|
|
|
|
|
|
|
{ |
|
724
|
0
|
|
|
|
|
|
to[-2] = '\n'; |
|
725
|
0
|
|
|
|
|
|
to--; |
|
726
|
0
|
|
|
|
|
|
SvCUR_set(sv, to - SvPVX_const(sv)); |
|
727
|
|
|
|
|
|
|
} |
|
728
|
0
|
0
|
|
|
|
|
else if (to[-1] == '\r') |
|
729
|
0
|
|
|
|
|
|
to[-1] = '\n'; |
|
730
|
|
|
|
|
|
|
} |
|
731
|
0
|
0
|
|
|
|
|
else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r') |
|
|
|
0
|
|
|
|
|
|
|
732
|
0
|
|
|
|
|
|
to[-1] = '\n'; |
|
733
|
|
|
|
|
|
|
#endif |
|
734
|
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
read_more_line: |
|
736
|
|
|
|
|
|
|
/* if we're out of file, or a read fails, bail and reset the current |
|
737
|
|
|
|
|
|
|
line marker so we can report where the unterminated string began |
|
738
|
|
|
|
|
|
|
*/ |
|
739
|
0
|
0
|
|
|
|
|
if (!PL_rsfp || |
|
740
|
0
|
0
|
|
|
|
|
!(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
|
|
|
0
|
|
|
|
|
|
|
741
|
0
|
|
|
|
|
|
sv_free(sv); |
|
742
|
0
|
|
|
|
|
|
CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
|
743
|
0
|
|
|
|
|
|
return Nullch; |
|
744
|
|
|
|
|
|
|
} |
|
745
|
|
|
|
|
|
|
/* we read a line, so increment our line counter */ |
|
746
|
0
|
|
|
|
|
|
CopLINE_inc(PL_curcop); |
|
747
|
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
/* update debugger info */ |
|
749
|
0
|
0
|
|
|
|
|
if (PERLDB_LINE && PL_curstash != PL_debstash) { |
|
|
|
0
|
|
|
|
|
|
|
750
|
0
|
0
|
|
|
|
|
AV *fileav = CopFILEAV(PL_curcop); |
|
751
|
0
|
0
|
|
|
|
|
if (fileav) { |
|
752
|
0
|
|
|
|
|
|
SV *sv = NEWSV(88,0); |
|
753
|
0
|
|
|
|
|
|
sv_upgrade(sv, SVt_PVMG); |
|
754
|
0
|
0
|
|
|
|
|
sv_setsv(sv,PL_linestr); |
|
755
|
0
|
|
|
|
|
|
(void)SvIOK_on(sv); |
|
756
|
0
|
|
|
|
|
|
SvIV_set(sv, 0); |
|
757
|
0
|
|
|
|
|
|
av_store(fileav, (I32)CopLINE(PL_curcop), sv); |
|
758
|
|
|
|
|
|
|
} |
|
759
|
|
|
|
|
|
|
} |
|
760
|
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
/* having changed the buffer, we must update PL_bufend */ |
|
762
|
0
|
0
|
|
|
|
|
PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
763
|
0
|
|
|
|
|
|
PL_last_lop = PL_last_uni = Nullch; |
|
764
|
0
|
|
|
|
|
|
} |
|
765
|
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
/* at this point, we have successfully read the delimited string */ |
|
767
|
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
if (!PL_encoding || UTF) { |
|
769
|
0
|
0
|
|
|
|
|
if (keep_delims) |
|
770
|
0
|
|
|
|
|
|
sv_catpvn(sv, s, termlen); |
|
771
|
0
|
|
|
|
|
|
s += termlen; |
|
772
|
|
|
|
|
|
|
} |
|
773
|
0
|
0
|
|
|
|
|
if (has_utf8 || PL_encoding) |
|
774
|
0
|
|
|
|
|
|
SvUTF8_on(sv); |
|
775
|
|
|
|
|
|
|
|
|
776
|
0
|
|
|
|
|
|
PL_multi_end = CopLINE(PL_curcop); |
|
777
|
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
/* if we allocated too much space, give some back */ |
|
779
|
0
|
0
|
|
|
|
|
if (SvCUR(sv) + 5 < SvLEN(sv)) { |
|
780
|
0
|
|
|
|
|
|
SvLEN_set(sv, SvCUR(sv) + 1); |
|
781
|
|
|
|
|
|
|
/* 5.8.8 uses SvPV_renew, no prior version actually has the damn thing (mst) */ |
|
782
|
|
|
|
|
|
|
#ifdef PERL_5_8_8_PLUS |
|
783
|
|
|
|
|
|
|
SvPV_renew(sv, SvLEN(sv)); |
|
784
|
|
|
|
|
|
|
#else |
|
785
|
0
|
|
|
|
|
|
Renew(SvPVX(sv), SvLEN(sv), char); |
|
786
|
|
|
|
|
|
|
#endif |
|
787
|
|
|
|
|
|
|
} |
|
788
|
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
/* decide whether this is the first or second quoted string we've read |
|
790
|
|
|
|
|
|
|
for this op |
|
791
|
|
|
|
|
|
|
*/ |
|
792
|
|
|
|
|
|
|
|
|
793
|
0
|
0
|
|
|
|
|
if (PL_lex_stuff) |
|
|
|
0
|
|
|
|
|
|
|
794
|
0
|
|
|
|
|
|
PL_lex_repl = sv; |
|
795
|
|
|
|
|
|
|
else |
|
796
|
0
|
0
|
|
|
|
|
PL_lex_stuff = sv; |
|
797
|
0
|
|
|
|
|
|
return s; |
|
798
|
|
|
|
|
|
|
} |