This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
allow final period in a file (not followed by a newline) to
[perl5.git] / run.c
CommitLineData
a0d0e21e
LW
1/* run.c
2 *
9607fc9c 3 * Copyright (c) 1991-1997, Larry Wall
a0d0e21e
LW
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
8 */
9
79072805
LW
10#include "EXTERN.h"
11#include "perl.h"
12
a0d0e21e
LW
13/*
14 * "Away now, Shadowfax! Run, greatheart, run as you have never run before!
15 * Now we are come to the lands where you were foaled, and every stone you
16 * know. Run now! Hope is in speed!" --Gandalf
17 */
18
76e3520e 19#ifdef PERL_OBJECT
4c2891ed 20#define CALLOP this->*PL_op
76e3520e 21#else
533c011a 22#define CALLOP *PL_op
76e3520e 23#endif
79072805 24
a0d0e21e 25int
17c3b450
GS
26runops_standard(void)
27{
11343788 28 dTHR;
a0d0e21e 29
533c011a 30 while ( PL_op = (CALLOP->op_ppaddr)(ARGS) ) ;
fd18d308
CS
31
32 TAINT_NOT;
a0d0e21e 33 return 0;
79072805
LW
34}
35
2ddcc7aa 36#ifdef DEBUGGING
76e3520e 37#ifndef PERL_OBJECT
11343788 38static void debprof _((OP*o));
76e3520e 39#endif
a0d0e21e 40
17c3b450
GS
41#endif /* DEBUGGING */
42
a0d0e21e 43int
35ff7856
GS
44runops_debug(void)
45{
46#ifdef DEBUGGING
11343788 47 dTHR;
533c011a 48 if (!PL_op) {
79072805 49 warn("NULL OP IN RUN");
a0d0e21e 50 return 0;
79072805 51 }
a0d0e21e 52
79072805 53 do {
3280af22 54 if (PL_debug) {
22c35a8c 55 if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
760ac839 56 PerlIO_printf(Perl_debug_log, "WARNING: %lx changed from %lx to %lx\n",
22c35a8c 57 (long)PL_watchaddr, (long)PL_watchok, (long)*PL_watchaddr);
79072805 58 DEBUG_s(debstack());
533c011a
NIS
59 DEBUG_t(debop(PL_op));
60 DEBUG_P(debprof(PL_op));
79072805 61 }
533c011a 62 } while ( PL_op = (CALLOP->op_ppaddr)(ARGS) );
fd18d308
CS
63
64 TAINT_NOT;
a0d0e21e 65 return 0;
35ff7856
GS
66#else
67 return runops_standard();
17c3b450 68#endif /* DEBUGGING */
79072805
LW
69}
70
79072805 71I32
8ac85365 72debop(OP *o)
79072805 73{
35ff7856 74#ifdef DEBUGGING
79072805 75 SV *sv;
22c35a8c 76 deb("%s", PL_op_name[o->op_type]);
11343788 77 switch (o->op_type) {
79072805 78 case OP_CONST:
5dc0d613 79 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
79072805
LW
80 break;
81 case OP_GVSV:
82 case OP_GV:
11343788 83 if (cGVOPo->op_gv) {
79072805 84 sv = NEWSV(0,0);
5dc0d613 85 gv_fullname3(sv, cGVOPo->op_gv, Nullch);
3280af22 86 PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, PL_na));
8990e307 87 SvREFCNT_dec(sv);
79072805
LW
88 }
89 else
760ac839 90 PerlIO_printf(Perl_debug_log, "(NULL)");
79072805 91 break;
a0d0e21e
LW
92 default:
93 break;
79072805 94 }
760ac839 95 PerlIO_printf(Perl_debug_log, "\n");
17c3b450 96#endif /* DEBUGGING */
79072805
LW
97 return 0;
98}
99
100void
8ac85365 101watch(char **addr)
79072805 102{
35ff7856 103#ifdef DEBUGGING
22c35a8c
GS
104 dTHR;
105 PL_watchaddr = addr;
106 PL_watchok = *addr;
760ac839 107 PerlIO_printf(Perl_debug_log, "WATCHING, %lx is currently %lx\n",
22c35a8c 108 (long)PL_watchaddr, (long)PL_watchok);
17c3b450 109#endif /* DEBUGGING */
79072805 110}
a0d0e21e 111
76e3520e 112STATIC void
8ac85365 113debprof(OP *o)
a0d0e21e 114{
35ff7856 115#ifdef DEBUGGING
3280af22
NIS
116 if (!PL_profiledata)
117 Newz(000, PL_profiledata, MAXO, U32);
118 ++PL_profiledata[o->op_type];
35ff7856 119#endif /* DEBUGGING */
a0d0e21e
LW
120}
121
122void
8ac85365 123debprofdump(void)
a0d0e21e 124{
35ff7856 125#ifdef DEBUGGING
9607fc9c 126 unsigned i;
3280af22 127 if (!PL_profiledata)
a0d0e21e
LW
128 return;
129 for (i = 0; i < MAXO; i++) {
3280af22 130 if (PL_profiledata[i])
9607fc9c 131 PerlIO_printf(Perl_debug_log,
3280af22 132 "%5lu %s\n", (unsigned long)PL_profiledata[i],
22c35a8c 133 PL_op_name[i]);
a0d0e21e 134 }
17c3b450 135#endif /* DEBUGGING */
35ff7856 136}