line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* $Id: deHTMLxs.xs,v 1.6 2006/02/16 19:16:00 rsoderberg Exp $ */ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#include "EXTERN.h" |
4
|
|
|
|
|
|
|
#include "perl.h" |
5
|
|
|
|
|
|
|
#include "XSUB.h" |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
/* try to be compatible with older perls */ |
8
|
|
|
|
|
|
|
/* SvPV_nolen() macro first defined in 5.005_55 */ |
9
|
|
|
|
|
|
|
/* this is slow, not threadsafe, but works */ |
10
|
|
|
|
|
|
|
#include "patchlevel.h" |
11
|
|
|
|
|
|
|
#if (PATCHLEVEL == 4) || ((PATCHLEVEL == 5) && (SUBVERSION < 55)) |
12
|
|
|
|
|
|
|
static STRLEN nolen_na; |
13
|
|
|
|
|
|
|
# define SvPV_nolen(sv) SvPV ((sv), nolen_na) |
14
|
|
|
|
|
|
|
#endif |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#include "deHTMLxs.h" |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
typedef struct mystate { |
19
|
|
|
|
|
|
|
int is_xs; |
20
|
|
|
|
|
|
|
} *Razor2__Preproc__deHTMLxs; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
MODULE = Razor2::Preproc::deHTMLxs PACKAGE = Razor2::Preproc::deHTMLxs |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
PROTOTYPES: ENABLE |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Razor2::Preproc::deHTMLxs |
28
|
|
|
|
|
|
|
new(class) |
29
|
|
|
|
|
|
|
SV * class |
30
|
|
|
|
|
|
|
CODE: |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
|
Newz(0, RETVAL, 1, struct mystate); |
34
|
1
|
|
|
|
|
|
RETVAL->is_xs = 1; /* placeholder, not used now */ |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
OUTPUT: |
38
|
|
|
|
|
|
|
RETVAL |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
int |
41
|
|
|
|
|
|
|
is_xs(self) |
42
|
|
|
|
|
|
|
Razor2::Preproc::deHTMLxs self; |
43
|
|
|
|
|
|
|
CODE: |
44
|
1
|
|
|
|
|
|
RETVAL = 1; |
45
|
|
|
|
|
|
|
OUTPUT: |
46
|
|
|
|
|
|
|
RETVAL |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
char * |
49
|
|
|
|
|
|
|
testxs(self, str) |
50
|
|
|
|
|
|
|
Razor2::Preproc::deHTMLxs self; |
51
|
|
|
|
|
|
|
char * str; |
52
|
|
|
|
|
|
|
CODE: |
53
|
0
|
|
|
|
|
|
RETVAL = str + 1; |
54
|
|
|
|
|
|
|
OUTPUT: |
55
|
|
|
|
|
|
|
RETVAL |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
SV * |
58
|
|
|
|
|
|
|
isit(self, scalarref) |
59
|
|
|
|
|
|
|
Razor2::Preproc::deHTMLxs self; |
60
|
|
|
|
|
|
|
SV * scalarref; |
61
|
|
|
|
|
|
|
CODE: |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
/* 2002/11/21 Anne Bennett: use the right type def: */ |
64
|
|
|
|
|
|
|
STRLEN size; |
65
|
|
|
|
|
|
|
char * raw; |
66
|
|
|
|
|
|
|
SV * text; |
67
|
8
|
|
|
|
|
|
const char mynull = 0; |
68
|
|
|
|
|
|
|
|
69
|
8
|
50
|
|
|
|
|
if (SvROK(scalarref)) { |
70
|
8
|
|
|
|
|
|
text = SvRV(scalarref); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
/* normally perl has '\0' on end, but not guaranteed */ |
73
|
8
|
|
|
|
|
|
sv_catpv(text,&mynull); |
74
|
8
|
50
|
|
|
|
|
raw = SvPV(text,size); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
/* bool CM_PREPROC_is_html(const char *); */ |
77
|
8
|
50
|
|
|
|
|
if (CM_PREPROC_is_html(raw)) { |
78
|
8
|
|
|
|
|
|
RETVAL = newSVpv ("1", 0); |
79
|
|
|
|
|
|
|
} else { |
80
|
8
|
|
|
|
|
|
RETVAL = newSVpv ("", 0); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} else { |
83
|
0
|
|
|
|
|
|
RETVAL = newSVpv ("", 0); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
OUTPUT: |
87
|
|
|
|
|
|
|
RETVAL |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
SV * |
90
|
|
|
|
|
|
|
doit(self, scalarref) |
91
|
|
|
|
|
|
|
Razor2::Preproc::deHTMLxs self; |
92
|
|
|
|
|
|
|
SV * scalarref |
93
|
|
|
|
|
|
|
CODE: |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
char * cleaned, * raw, * res; |
96
|
|
|
|
|
|
|
/* 2002/11/21 Anne Bennett: use the right type def: */ |
97
|
|
|
|
|
|
|
STRLEN size; |
98
|
|
|
|
|
|
|
SV * text; |
99
|
|
|
|
|
|
|
SV * newtext; |
100
|
|
|
|
|
|
|
SV * newref; |
101
|
|
|
|
|
|
|
|
102
|
8
|
50
|
|
|
|
|
if (SvROK(scalarref)) { |
103
|
8
|
|
|
|
|
|
text = SvRV(scalarref); |
104
|
8
|
50
|
|
|
|
|
raw = SvPV(text,size); |
105
|
|
|
|
|
|
|
|
106
|
8
|
|
|
|
|
|
*(raw + size - 1) = '\0'; |
107
|
8
|
50
|
|
|
|
|
if ( (cleaned = malloc(size+1)) && |
|
|
50
|
|
|
|
|
|
108
|
|
|
|
|
|
|
(res = CM_PREPROC_html_strip(raw, cleaned)) /* html_strip will memset cleaned to 0 */ |
109
|
|
|
|
|
|
|
) { |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
/* |
112
|
|
|
|
|
|
|
* hook it up so scalarref will dereference to new scalar |
113
|
|
|
|
|
|
|
*/ |
114
|
|
|
|
|
|
|
|
115
|
8
|
|
|
|
|
|
newtext = newSVpv (res, 0); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
/* newtext is new scalar containing cleaned html. |
118
|
|
|
|
|
|
|
* we want scalarref to point to that instead of its old dude, text. */ |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
/* sv_setsv (SV* dest, SV* src) */ |
121
|
8
|
|
|
|
|
|
sv_setsv(text, newtext); |
122
|
|
|
|
|
|
|
|
123
|
8
|
|
|
|
|
|
SvREFCNT_inc(scalarref); |
124
|
|
|
|
|
|
|
|
125
|
8
|
|
|
|
|
|
RETVAL = scalarref; |
126
|
8
|
|
|
|
|
|
free(cleaned); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} else { |
129
|
0
|
0
|
|
|
|
|
if (cleaned) { |
130
|
0
|
|
|
|
|
|
free(cleaned); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
8
|
|
|
|
|
|
RETVAL = newSVpv ("", 0); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} else { |
136
|
0
|
|
|
|
|
|
RETVAL = newSVpv ("", 0); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
OUTPUT: |
141
|
|
|
|
|
|
|
RETVAL |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|