File: eperl_parse.c

package info (click to toggle)
wml 2.0.11-1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 13,668 kB
  • ctags: 5,794
  • sloc: ansic: 54,590; sh: 17,145; perl: 14,812; makefile: 2,295; yacc: 445
file content (636 lines) | stat: -rw-r--r-- 21,297 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
/*
**        ____           _ 
**    ___|  _ \ ___ _ __| |
**   / _ \ |_) / _ \ '__| |
**  |  __/  __/  __/ |  | |
**   \___|_|   \___|_|  |_|
** 
**  ePerl -- Embedded Perl 5 Language
**
**  ePerl interprets an ASCII file bristled with Perl 5 program statements
**  by evaluating the Perl 5 code while passing through the plain ASCII
**  data. It can operate both as a standard Unix filter for general file
**  generation tasks and as a powerful Webserver scripting language for
**  dynamic HTML page programming. 
**
**  ======================================================================
**
**  Copyright (c) 1996,1997,1998,1999 Ralf S. Engelschall <rse@engelschall.com>
**
**  This program is free software; it may be redistributed and/or modified
**  only under the terms of either the Artistic License or the GNU General
**  Public License, which may be found in the ePerl source distribution.
**  Look at the files ARTISTIC and COPYING or run ``eperl -l'' to receive
**  a built-in copy of both license files.
**
**  This program is distributed in the hope that it will be useful, but
**  WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either the
**  Artistic License or the GNU General Public License for more details.
**
**  ======================================================================
**
**  eperl_parse.c -- ePerl parser stuff
*/


#include "eperl_config.h"
#include "eperl_global.h"
#include "eperl_proto.h"


/*
**
**  Static Data
**
*/

char       *ePerl_begin_delimiter           = NULL;
char       *ePerl_end_delimiter             = NULL;
int         ePerl_case_sensitive_delimiters = TRUE;
int         ePerl_convert_entities          = FALSE;
int         ePerl_line_continuation         = FALSE;
static char ePerl_ErrorString[1024]         = "";

/*
**
**  Functions
**
*/

/*
**  set ePerl error string
*/
void ePerl_SetError(char *str, ...)
{
    va_list ap;

    va_start(ap, str);
    vsnprintf(ePerl_ErrorString, sizeof(ePerl_ErrorString), str, ap);
    ePerl_ErrorString[sizeof(ePerl_ErrorString)-1] = NUL;
    va_end(ap);
    return;
}

/*
**  get ePerl error string
*/
char *ePerl_GetError(void)
{
    return ePerl_ErrorString;
}

#if 0 /* unsafe ? */
/*
**  fprintf for internal buffer 
*/
char *ePerl_fprintf(char *cpOut, char *str, ...)
{
    va_list ap;

    va_start(ap, str);
    vsprintf(cpOut, str, ap);
    va_end(ap);
    return cpOut+strlen(cpOut);
}
#else /* safe version */
char *ePerl_fnprintf(char *cpOut, int *n, char *str, ...)
{
    va_list ap;

    if (*n <= 0) { abort(); } /* hope NEVER */
    va_start(ap, str);
    vsnprintf(cpOut, *n, str, ap);
    cpOut[*n - 1] = NUL;
    va_end(ap);
    *n -= strlen(cpOut);
    if (*n <= 0) { abort(); } /* hope NEVER */
    return cpOut+strlen(cpOut);
}
#endif

/*
**  fwrite for internal buffer 
*/
#if 0 /* unsafe */
char *ePerl_fwrite(char *cpBuf, int nBuf, int cNum, char *cpOut)
{
    char *cp;
    int n;

    n = nBuf*cNum;
    (void)strncpy(cpOut, cpBuf, n);
    cp = cpOut + n;
    *cp = NUL;
    return cp;
}
#else /* safe */
char *ePerl_fnwrite(char *cpBuf, int nBuf, int cNum, char *cpOut, int *cpOutLen)
{
    char *cp;
    int n;

    n = nBuf*cNum;
    if (*cpOutLen < n) { abort(); }
    (void)strncpy(cpOut, cpBuf, n);
    cpOut[*cpOutLen - 1] = NUL;
    cp = cpOut + n;
    *cp = NUL;
    *cpOutLen -= n;
    return cp;
}
#endif

#if 0 /* unsafe */
/*
**  fwrite for internal buffer WITH character escaping
*/
char *ePerl_Efwrite(char *cpBuf, int nBuf, int cNum, char *cpOut)
{
    char *cpI;
    char *cpO;

    for (cpI = cpBuf, cpO = cpOut; cpI < (cpBuf+(nBuf*cNum)); ) {
        switch (*cpI) {
            case '"':  *cpO++ = '\\'; *cpO++ = *cpI++;     break;
            case '@':  *cpO++ = '\\'; *cpO++ = *cpI++;     break;
            case '$':  *cpO++ = '\\'; *cpO++ = *cpI++;     break;
            case '\\': *cpO++ = '\\'; *cpO++ = *cpI++;     break;
            case '\t': *cpO++ = '\\'; *cpO++ = 't'; cpI++; break;
            case '\n': *cpO++ = '\\'; *cpO++ = 'n'; cpI++; break;
            default: *cpO++ = *cpI++;
        }
    }
    *cpO = NUL;
    return cpO;
}
#else /* safe */
char *ePerl_Efnwrite(char *cpBuf, int nBuf, int cNum, char *cpOut, int *n)
{
    char *cpI;
    char *cpO;

    if (*n <= 0) { abort(); }
    for (cpI = cpBuf, cpO = cpOut; cpI < (cpBuf+(nBuf*cNum)); ) {
        switch (*cpI) {
            case '"':  *cpO++ = '\\'; *cpO++ = *cpI++; *n -= 2;    break;
            case '@':  *cpO++ = '\\'; *cpO++ = *cpI++; *n -= 2;    break;
            case '$':  *cpO++ = '\\'; *cpO++ = *cpI++; *n -= 2;    break;
            case '\\': *cpO++ = '\\'; *cpO++ = *cpI++; *n -= 2;    break;
            case '\t': *cpO++ = '\\'; *cpO++ = 't'; cpI++; *n -= 2;break;
            case '\n': *cpO++ = '\\'; *cpO++ = 'n'; cpI++; *n -= 2;break;
            default: *cpO++ = *cpI++; *n -= 1;
        }
        if (*n <= 0) { abort(); }
    }
    *cpO = NUL;
    return cpO;
}
#endif


/*
**  fwrite for internal buffer WITH HTML entity conversion
*/

struct html2char {
    char *h;
    char c;
};

static struct html2char html2char[] = {
    { "copy",   '' },    /* Copyright */
    { "die",    '' },    /* Diresis / Umlaut */
    { "laquo",  '' },    /* Left angle quote, guillemot left */
    { "not",    '' },    /* Not sign */
    { "ordf",   '' },    /* Feminine ordinal */
    { "sect",   '' },    /* Section sign */
    { "um",     '' },    /* Diresis / Umlaut */
    { "AElig",  '' },    /* Capital AE ligature */
    { "Aacute", '' },    /* Capital A, acute accent */
    { "Acirc",  '' },    /* Capital A, circumflex */
    { "Agrave", '' },    /* Capital A, grave accent */
    { "Aring",  '' },    /* Capital A, ring */
    { "Atilde", '' },    /* Capital A, tilde */
    { "Auml",   '' },    /* Capital A, diresis / umlaut */
    { "Ccedil", '' },    /* Capital C, cedilla */
    { "ETH",    '' },    /* Capital Eth, Icelandic */
    { "Eacute", '' },    /* Capital E, acute accent */
    { "Ecirc",  '' },    /* Capital E, circumflex */
    { "Egrave", '' },    /* Capital E, grave accent */
    { "Euml",   '' },    /* Capital E, diresis / umlaut */
    { "Iacute", '' },    /* Capital I, acute accent */
    { "Icirc",  '' },    /* Capital I, circumflex */
    { "Igrave", '' },    /* Capital I, grave accent */
    { "Iuml",   '' },    /* Capital I, diresis / umlaut */
    { "Ntilde", '' },    /* Capital N, tilde */
    { "Oacute", '' },    /* Capital O, acute accent */
    { "Ocirc",  '' },    /* Capital O, circumflex */
    { "Ograve", '' },    /* Capital O, grave accent */
    { "Oslash", '' },    /* Capital O, slash */
    { "Otilde", '' },    /* Capital O, tilde */
    { "Ouml",   '' },    /* Capital O, diresis / umlaut */
    { "THORN",  '' },    /* Capital Thorn, Icelandic */
    { "Uacute", '' },    /* Capital U, acute accent */
    { "Ucirc",  '' },    /* Capital U, circumflex */
    { "Ugrave", '' },    /* Capital U, grave accent */
    { "Uuml",   '' },    /* Capital U, diresis / umlaut */
    { "Yacute", '' },    /* Capital Y, acute accent */
    { "aacute", '' },    /* Small a, acute accent */
    { "acirc",  '' },    /* Small a, circumflex */
    { "acute",  '' },    /* Acute accent */
    { "aelig",  '' },    /* Small ae ligature */
    { "agrave", '' },    /* Small a, grave accent */
    { "amp",    '&' },    /* Ampersand */
    { "aring",  '' },    /* Small a, ring */
    { "atilde", '' },    /* Small a, tilde */
    { "auml",   '' },    /* Small a, diresis / umlaut */
    { "brkbar", '' },    /* Broken vertical bar */
    { "brvbar", '' },    /* Broken vertical bar */
    { "ccedil", '' },    /* Small c, cedilla */
    { "cedil",  '' },    /* Cedilla */
    { "cent",   '' },    /* Cent sign */
    { "curren", '' },    /* General currency sign */
    { "deg",    '' },    /* Degree sign */
    { "divide", '' },    /* Division sign */
    { "eacute", '' },    /* Small e, acute accent */
    { "ecirc",  '' },    /* Small e, circumflex */
    { "egrave", '' },    /* Small e, grave accent */
    { "eth",    '' },    /* Small eth, Icelandic */
    { "euml",   '' },    /* Small e, diresis / umlaut */
    { "frac12", '' },    /* Fraction one-half */
    { "frac14", '' },    /* Fraction one-fourth */
    { "frac34", '' },    /* Fraction three-fourths */
    { "gt",     '>' },    /* Greater than */
    { "hibar",  '' },    /* Macron accent */
    { "iacute", '' },    /* Small i, acute accent */
    { "icirc",  '' },    /* Small i, circumflex */
    { "iexcl",  '' },    /* Inverted exclamation */
    { "igrave", '' },    /* Small i, grave accent */
    { "iquest", '' },    /* Inverted question mark */
    { "iuml",   '' },    /* Small i, diresis / umlaut */
    { "lt",     '<' },    /* Less than */
    { "macr",   '' },    /* Macron accent */
    { "micro",  '' },    /* Micro sign */
    { "middot", '' },    /* Middle dot */
    { "nbsp",   ' ' },    /* Non-breaking Space */
    { "ntilde", '' },    /* Small n, tilde */
    { "oacute", '' },    /* Small o, acute accent */
    { "ocirc",  '' },    /* Small o, circumflex */
    { "ograve", '' },    /* Small o, grave accent */
    { "ordm",   '' },    /* Masculine ordinal */
    { "oslash", '' },    /* Small o, slash */
    { "otilde", '' },    /* Small o, tilde */
    { "ouml",   '' },    /* Small o, diresis / umlaut */
    { "para",   '' },    /* Paragraph sign */
    { "plusmn", '' },    /* Plus or minus */
    { "pound",  '' },    /* Pound sterling */
    { "quot",   '"' },    /* Quotation mark */
    { "raquo",  '' },    /* Right angle quote, guillemot right */
    { "reg",    '' },    /* Registered trademark */
    { "shy",    '' },    /* Soft hyphen */
    { "sup1",   '' },    /* Superscript one */
    { "sup2",   '' },    /* Superscript two */
    { "sup3",   '' },    /* Superscript three */
    { "szlig",  '' },    /* Small sharp s, German sz */
    { "thorn",  '' },    /* Small thorn, Icelandic */
    { "times",  '' },    /* Multiply sign */
    { "uacute", '' },    /* Small u, acute accent */
    { "ucirc",  '' },    /* Small u, circumflex */
    { "ugrave", '' },    /* Small u, grave accent */
    { "uuml",   '' },    /* Small u, diresis / umlaut */
    { "yacute", '' },    /* Small y, acute accent */
    { "yen",    '' },    /* Yen sign */
    { "yuml",'\255' },    /* Small y, diresis / umlaut */
    { NULL, NUL }
};

#if 0 /* unsafe */
char *ePerl_Cfwrite(char *cpBuf, int nBuf, int cNum, char *cpOut)
{
    char *cpI;
    char *cpO;
    int i;
    int n;
    char *cpE;

    cpI = cpBuf;
    cpO = cpOut;
    cpE = cpBuf+(nBuf*cNum);
    while (cpI < cpE) {
        if (*cpI == '&') {
            for (i = 0; html2char[i].h != NULL; i++) {
                n = strlen(html2char[i].h);
                if (cpI+1+n+1 < cpE) {
                    if (*(cpI+1+n) == ';') {
                        if (strncmp(cpI+1, html2char[i].h, n) == 0) {
                            *cpO++ = html2char[i].c;
                            cpI += 1+n+1;
                            continue;
                        }
                    }
                }
            }
        }
        *cpO++ = *cpI++;
    }
    *cpO = NUL;
    return cpO;
}
#else /* safe */
char *ePerl_Cfnwrite(char *cpBuf, int nBuf, int cNum, char *cpOut, int *cpOutLen)
{
    char *cpI;
    char *cpO;
    int i;
    int n;
    char *cpE;

    if (*cpOutLen <= 0) { abort(); }
    cpI = cpBuf;
    cpO = cpOut;
    cpE = cpBuf+(nBuf*cNum);
    while (cpI < cpE) {
        if (*cpI == '&') {
            for (i = 0; html2char[i].h != NULL; i++) {
                n = strlen(html2char[i].h);
                if (cpI+1+n+1 < cpE) {
                    if (*(cpI+1+n) == ';') {
                        if (strncmp(cpI+1, html2char[i].h, n) == 0) {
                            *cpO++ = html2char[i].c;
                            if (--*cpOutLen <= 0) { abort(); }
                            cpI += 1+n+1;
                            continue;
                        }
                    }
                }
            }
        }
        *cpO++ = *cpI++;
        if (--*cpOutLen <= 0) { abort(); }
    }
    *cpO = NUL;
    return cpO;
}
#endif


/*
**
**  Own string functions with maximum length (n) support 
**
*/

char *ep_strnchr(char *buf, char chr, int n)
{
    char *cp;
    char *cpe;

    for (cp = buf, cpe = buf+n-1; cp <= cpe; cp++) {
        if (*cp == chr)
            return cp;
    }
    return NULL;
}

char *ep_strnstr(char *buf, char *str, int n)
{
    char *cp;
    char *cpe;
    int len;
    
    len = strlen(str);
    for (cp = buf, cpe = buf+n-len; cp <= cpe; cp++) {
        if (strncmp(cp, str, len) == 0)
            return cp;
    }
    return NULL;
}

char *ep_strncasestr(char *buf, char *str, int n)
{
    char *cp;
    char *cpe;
    int len;
    
    len = strlen(str);
    for (cp = buf, cpe = buf+n-len; cp <= cpe; cp++) {
        if (strncasecmp(cp, str, len) == 0)
            return cp;
    }
    return NULL;
}


/*
**  convert buffer from bristled format to plain format
*/
char *ePerl_Bristled2Plain(char *cpBuf)
{
    char *rc;
    char *cpOutBuf = NULL;
    char *cpOut = NULL;
    int cpOutLen = 0;
    char *cps, *cpe;
    char *cps2, *cpe2;
    int nBuf;
    char *cpEND;
    int n;

    if (strlen(cpBuf) == 0) {
        /* make sure we return a buffer which the caller can free() */
        cpOutBuf = (char *)malloc(sizeof(char) * 1);
        *cpOutBuf = NUL;
        return cpOutBuf;
    }

    nBuf = strlen(cpBuf);
    cpEND = cpBuf+nBuf;

    /* allocate memory for the Perl code */
    n = sizeof(char) * nBuf * 10;
    if (nBuf < 1024)
        n = 16384;
    if ((cpOutBuf = (char *)malloc(n)) == NULL) {
        ePerl_SetError("Cannot allocate %d bytes of memory", n);
        CU(NULL);
    }
    cpOut = cpOutBuf;
    cpOutLen = n;

    /* now step through the file and convert it to legal Perl code.
       This is a bit complicated because we have to make sure that
       we parse the correct delimiters while the delimiter
       characters could also occur inside the Perl code! */
    cps = cpBuf;
    while (cps < cpEND) {

        if (ePerl_case_sensitive_delimiters)
            cpe = ep_strnstr(cps, ePerl_begin_delimiter, cpEND-cps);
        else
            cpe = ep_strncasestr(cps, ePerl_begin_delimiter, cpEND-cps);
        if (cpe == NULL) {

            /* there are no more ePerl blocks, so
               just encapsulate the remaining contents into
               Perl print constructs */

            if (cps < cpEND) {
                cps2 = cps;
                /* first, do all complete lines */
                while (cps2 < cpEND && (cpe2 = ep_strnchr(cps2, '\n', cpEND-cps2)) != NULL) {
                    if (ePerl_line_continuation && cps < cpe2 && *(cpe2-1) == '\\') {
                        if (cpe2-1-cps2 > 0) {
                            cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "print \"");
                            cpOut = ePerl_Efnwrite(cps2, cpe2-1-cps2, 1, cpOut, &cpOutLen);
                            cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\";");
                        }
                        cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\n");
                    }
                    else {
                        cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "print \"");
                        cpOut = ePerl_Efnwrite(cps2, cpe2-cps2, 1, cpOut, &cpOutLen);
                        cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\\n\";\n");
                    }
                    cps2 = cpe2+1;
                }
                /* then do the remainder which is not
                   finished by a newline */
                if (cpEND > cps2) {
                    cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "print \"");
                    cpOut = ePerl_Efnwrite(cps2, cpEND-cps2, 1, cpOut, &cpOutLen);
                    cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\";");
                }
            }
            break; /* and break the whole processing step */

        }
        else {

            /* Ok, there is at least one more ePerl block */

            /* first, encapsulate the content from current pos
               up to the begin of the ePerl block as print statements */
            if (cps < cpe) {
                cps2 = cps;
                while ((cpe2 = ep_strnchr(cps2, '\n', cpe-cps2)) != NULL) {
                    if (ePerl_line_continuation && cps < cpe2 && *(cpe2-1) == '\\') {
                        if (cpe2-1-cps2 > 0) {
                            cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "print \"");
                            cpOut = ePerl_Efnwrite(cps2, cpe2-1-cps2, 1, cpOut, &cpOutLen);
                            cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\";");
                        }
                        cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\n");
                    }
                    else {
                        cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "print \"");
                        cpOut = ePerl_Efnwrite(cps2, cpe2-cps2, 1, cpOut, &cpOutLen);
                        cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\\n\";\n");
                    }
                    cps2 = cpe2+1;
                }
                if (cpe > cps2) {
                    cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "print \"");
                    cpOut = ePerl_Efnwrite(cps2, cpe-cps2, 1, cpOut, &cpOutLen);
                    cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\";");
                }
            }

            /* just output a leading space to make
               the -x display more readable. */
            if (cpOut > cpOutBuf && *(cpOut-1) != '\n') 
                cpOut = ePerl_fnprintf(cpOut, &cpOutLen, " ");

            /* skip the start delimiter */
            cps = cpe+strlen(ePerl_begin_delimiter);

            /* recognize the 'print' shortcut with '=',
             * e.g. <:=$var:>
             */
            if (*cps == '=') {
                cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "print ");
                cps++;
            }

            /* skip all following whitespaces.
               Be careful: we could skip newlines too, but then the
               error output will give wrong line numbers!!! */
            while (cps < cpEND) {
                if (*cps != ' ' && *cps != '\t')
                    break;
                cps++;
            }
            cpe = cps;

            /* move forward to end of ePerl block. */
            if (ePerl_case_sensitive_delimiters)
                cpe = ep_strnstr(cpe, ePerl_end_delimiter, cpEND-cpe);
            else
                cpe = ep_strncasestr(cpe, ePerl_end_delimiter, cpEND-cpe);
            if (cpe == NULL) {
                ePerl_SetError("Missing end delimiter");
                CU(NULL);
            }

            /* step again backward over whitespaces */
            for (cpe2 = cpe; 
                 cpe2 > cps && (*(cpe2-1) == ' ' || *(cpe2-1) == '\t' || *(cpe2-1) == '\n');
                 cpe2--)
                ;
            
            /* pass through the ePerl block without changes! */
            if (cpe2 > cps) { 
                if (ePerl_convert_entities == TRUE)
                    cpOut = ePerl_Cfnwrite(cps, cpe2-cps, 1, cpOut, &cpOutLen);
                else
                    cpOut = ePerl_fnwrite(cps, cpe2-cps, 1, cpOut, &cpOutLen);

                /* be smart and automatically add a semicolon
                   if not provided at the end of the ePerl block.
                   But know the continuation indicator "_". */
                if ((*(cpe2-1) != ';') &&
                    (*(cpe2-1) != '_')   )
                    cpOut = ePerl_fnprintf(cpOut, &cpOutLen, ";");
                if (*(cpe2-1) == '_') 
                    cpOut = cpOut - 1;
            }

            /* end preserve newlines for correct line numbers */
            for ( ; cpe2 <= cpe; cpe2++)
                if (*cpe2 == '\n')
                    cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\n");

            /* output a trailing space to make
               the -x display more readable when
               no newlines have finished the block. */
            if (cpOut > cpOutBuf && *(cpOut-1) != '\n') 
                cpOut = ePerl_fnprintf(cpOut, &cpOutLen, " ");

            /* and adjust the current position to the first character
               after the end delimiter */
            cps = cpe+strlen(ePerl_end_delimiter);

            /* finally just one more feature: when an end delimiter
               is directly followed by ``//'' this discards all
               data up to and including the following newline */
            if (cps < cpEND-2 && *cps == '/' && *(cps+1) == '/') {
                /* skip characters */
                cps += 2;
                for ( ; cps < cpEND && *cps != '\n'; cps++)
                    ;
                if (cps < cpEND)
                    cps++;
                /* but preserve the newline in the script */
                cpOut = ePerl_fnprintf(cpOut, &cpOutLen, "\n");
            }
        }
    }
    RETURN_WVAL(cpOutBuf);

    CUS:
    if (cpOutBuf) 
        free(cpOutBuf);
    RETURN_EXRC;
}

/*EOF*/