| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
2
|
|
|
|
|
|
|
#include "perl.h" |
|
3
|
|
|
|
|
|
|
#include "XSUB.h" |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#include |
|
6
|
|
|
|
|
|
|
#include |
|
7
|
|
|
|
|
|
|
#include |
|
8
|
|
|
|
|
|
|
#include |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
static void |
|
12
|
34
|
|
|
|
|
|
_load_config_hash(TidyDoc tdoc, HV *tidy_options) |
|
13
|
|
|
|
|
|
|
{ |
|
14
|
|
|
|
|
|
|
HE *entry; |
|
15
|
|
|
|
|
|
|
|
|
16
|
34
|
|
|
|
|
|
(void) hv_iterinit(tidy_options); |
|
17
|
|
|
|
|
|
|
|
|
18
|
64
|
100
|
|
|
|
|
while ( (entry = hv_iternext(tidy_options)) != NULL ) { |
|
19
|
|
|
|
|
|
|
I32 key_len; |
|
20
|
|
|
|
|
|
|
|
|
21
|
30
|
|
|
|
|
|
const char * const key = hv_iterkey(entry,&key_len); |
|
22
|
30
|
|
|
|
|
|
const TidyOption opt = tidyGetOptionByName(tdoc,key); |
|
23
|
|
|
|
|
|
|
|
|
24
|
30
|
50
|
|
|
|
|
if (!opt) { |
|
25
|
0
|
|
|
|
|
|
warn( "HTML::Tidy: Unrecognized option: \"%s\"\n",key ); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
else { |
|
28
|
30
|
|
|
|
|
|
const TidyOptionId id = tidyOptGetId(opt); |
|
29
|
30
|
|
|
|
|
|
SV * const sv_data = hv_iterval(tidy_options,entry); |
|
30
|
|
|
|
|
|
|
STRLEN data_len; |
|
31
|
30
|
100
|
|
|
|
|
const char * const data = SvPV(sv_data,data_len); |
|
32
|
|
|
|
|
|
|
|
|
33
|
30
|
50
|
|
|
|
|
if ( ! tidyOptSetValue(tdoc,id,data) ) { |
|
34
|
30
|
|
|
|
|
|
warn( "HTML::Tidy: Can't set option: \"%s\" to \"%s\"\n", key, data ); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
34
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
MODULE = HTML::T5 PACKAGE = HTML::T5 |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
PROTOTYPES: ENABLE |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
void |
|
44
|
|
|
|
|
|
|
_tidy_messages(input, configfile, tidy_options) |
|
45
|
|
|
|
|
|
|
INPUT: |
|
46
|
|
|
|
|
|
|
const char *input |
|
47
|
|
|
|
|
|
|
const char *configfile |
|
48
|
|
|
|
|
|
|
HV *tidy_options |
|
49
|
|
|
|
|
|
|
PREINIT: |
|
50
|
21
|
|
|
|
|
|
TidyBuffer errbuf = {0}; |
|
51
|
21
|
|
|
|
|
|
TidyDoc tdoc = tidyCreate(); /* Initialize "document" */ |
|
52
|
|
|
|
|
|
|
const char* newline; |
|
53
|
21
|
|
|
|
|
|
int rc = 0; |
|
54
|
|
|
|
|
|
|
PPCODE: |
|
55
|
21
|
|
|
|
|
|
tidyBufInit(&errbuf); |
|
56
|
21
|
50
|
|
|
|
|
rc = ( tidyOptSetValue( tdoc, TidyCharEncoding, "utf8" ) ? rc : -1 ); |
|
57
|
|
|
|
|
|
|
|
|
58
|
21
|
50
|
|
|
|
|
if ( (rc >= 0 ) && configfile && *configfile ) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
|
rc = tidyLoadConfig( tdoc, configfile ); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
21
|
50
|
|
|
|
|
if ( rc >= 0 ) { |
|
63
|
21
|
|
|
|
|
|
_load_config_hash(tdoc,tidy_options); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
21
|
50
|
|
|
|
|
if ( rc >= 0 ) { |
|
67
|
|
|
|
|
|
|
/* Capture diagnostics */ |
|
68
|
21
|
|
|
|
|
|
rc = tidySetErrorBuffer( tdoc, &errbuf ); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
21
|
50
|
|
|
|
|
if ( rc >= 0 ) { |
|
72
|
|
|
|
|
|
|
/* Parse the input */ |
|
73
|
21
|
|
|
|
|
|
rc = tidyParseString( tdoc, input ); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
21
|
50
|
|
|
|
|
if ( rc >= 0 && errbuf.bp) { |
|
|
|
100
|
|
|
|
|
|
|
77
|
19
|
50
|
|
|
|
|
XPUSHs( sv_2mortal(newSVpvn((char *)errbuf.bp, errbuf.size)) ); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
/* TODO: Make this a function */ |
|
80
|
19
|
|
|
|
|
|
switch ( tidyOptGetInt(tdoc,TidyNewline) ) { |
|
81
|
|
|
|
|
|
|
case TidyLF: |
|
82
|
19
|
|
|
|
|
|
newline = "\n"; |
|
83
|
19
|
|
|
|
|
|
break; |
|
84
|
|
|
|
|
|
|
case TidyCR: |
|
85
|
0
|
|
|
|
|
|
newline = "\r"; |
|
86
|
0
|
|
|
|
|
|
break; |
|
87
|
|
|
|
|
|
|
default: |
|
88
|
0
|
|
|
|
|
|
newline = "\r\n"; |
|
89
|
0
|
|
|
|
|
|
break; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
19
|
50
|
|
|
|
|
XPUSHs( sv_2mortal(newSVpv(newline, 0)) ); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
else { |
|
94
|
2
|
|
|
|
|
|
rc = -1; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
21
|
100
|
|
|
|
|
if ( errbuf.bp ) |
|
98
|
19
|
|
|
|
|
|
tidyBufFree( &errbuf ); |
|
99
|
21
|
|
|
|
|
|
tidyRelease( tdoc ); |
|
100
|
|
|
|
|
|
|
|
|
101
|
21
|
100
|
|
|
|
|
if ( rc < 0 ) { |
|
102
|
2
|
|
|
|
|
|
XSRETURN_UNDEF; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
void |
|
107
|
|
|
|
|
|
|
_tidy_clean(input, configfile, tidy_options) |
|
108
|
|
|
|
|
|
|
INPUT: |
|
109
|
|
|
|
|
|
|
const char *input |
|
110
|
|
|
|
|
|
|
const char *configfile |
|
111
|
|
|
|
|
|
|
HV *tidy_options |
|
112
|
|
|
|
|
|
|
PREINIT: |
|
113
|
13
|
|
|
|
|
|
TidyBuffer errbuf = {0}; |
|
114
|
13
|
|
|
|
|
|
TidyBuffer output = {0}; |
|
115
|
13
|
|
|
|
|
|
TidyDoc tdoc = tidyCreate(); /* Initialize "document" */ |
|
116
|
|
|
|
|
|
|
const char* newline; |
|
117
|
13
|
|
|
|
|
|
int rc = 0; |
|
118
|
|
|
|
|
|
|
PPCODE: |
|
119
|
13
|
|
|
|
|
|
tidyBufInit(&output); |
|
120
|
13
|
|
|
|
|
|
tidyBufInit(&errbuf); |
|
121
|
|
|
|
|
|
|
/* Set our default first. */ |
|
122
|
|
|
|
|
|
|
/* Don't word-wrap */ |
|
123
|
13
|
50
|
|
|
|
|
rc = ( tidyOptSetInt( tdoc, TidyWrapLen, 0 ) ? rc : -1 ); |
|
124
|
|
|
|
|
|
|
|
|
125
|
13
|
50
|
|
|
|
|
if ( (rc >= 0 ) && configfile && *configfile ) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
|
rc = tidyLoadConfig( tdoc, configfile ); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
/* XXX I think this cascade is a bug waiting to happen */ |
|
130
|
|
|
|
|
|
|
|
|
131
|
13
|
50
|
|
|
|
|
if ( rc >= 0 ) { |
|
132
|
13
|
50
|
|
|
|
|
rc = ( tidyOptSetValue( tdoc, TidyCharEncoding, "utf8" ) ? rc : -1 ); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
13
|
50
|
|
|
|
|
if ( rc >= 0 ) { |
|
136
|
13
|
|
|
|
|
|
_load_config_hash( tdoc, tidy_options ); |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
13
|
50
|
|
|
|
|
if ( rc >= 0 ) { |
|
140
|
13
|
|
|
|
|
|
rc = tidySetErrorBuffer( tdoc, &errbuf ); /* Capture diagnostics */ |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
13
|
50
|
|
|
|
|
if ( rc >= 0 ) { |
|
144
|
13
|
|
|
|
|
|
rc = tidyParseString( tdoc, input ); /* Parse the input */ |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
13
|
50
|
|
|
|
|
if ( rc >= 0 ) { |
|
148
|
13
|
|
|
|
|
|
rc = tidyCleanAndRepair(tdoc); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
13
|
100
|
|
|
|
|
if ( rc > 1 ) { |
|
152
|
2
|
50
|
|
|
|
|
rc = ( tidyOptSetBool( tdoc, TidyForceOutput, yes ) ? rc : -1 ); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
13
|
50
|
|
|
|
|
if ( rc >= 0) { |
|
156
|
13
|
|
|
|
|
|
rc = tidySaveBuffer( tdoc, &output ); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
13
|
50
|
|
|
|
|
if ( rc >= 0) { |
|
160
|
13
|
|
|
|
|
|
rc = tidyRunDiagnostics( tdoc ); |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
13
|
50
|
|
|
|
|
if ( rc >= 0 && output.bp && errbuf.bp ) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
164
|
13
|
50
|
|
|
|
|
XPUSHs( sv_2mortal(newSVpvn((char *)output.bp, output.size)) ); |
|
165
|
13
|
50
|
|
|
|
|
XPUSHs( sv_2mortal(newSVpvn((char *)errbuf.bp, errbuf.size)) ); |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
/* TODO: Hoist this into a function */ |
|
168
|
13
|
|
|
|
|
|
switch ( tidyOptGetInt(tdoc,TidyNewline) ) { |
|
169
|
|
|
|
|
|
|
case TidyLF: |
|
170
|
12
|
|
|
|
|
|
newline = "\n"; |
|
171
|
12
|
|
|
|
|
|
break; |
|
172
|
|
|
|
|
|
|
case TidyCR: |
|
173
|
1
|
|
|
|
|
|
newline = "\r"; |
|
174
|
1
|
|
|
|
|
|
break; |
|
175
|
|
|
|
|
|
|
default: |
|
176
|
0
|
|
|
|
|
|
newline = "\r\n"; |
|
177
|
0
|
|
|
|
|
|
break; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
13
|
50
|
|
|
|
|
XPUSHs( sv_2mortal(newSVpv(newline, 0)) ); |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
else { |
|
182
|
0
|
|
|
|
|
|
rc = -1; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
13
|
|
|
|
|
|
tidyBufFree( &output ); |
|
186
|
13
|
|
|
|
|
|
tidyBufFree( &errbuf ); |
|
187
|
13
|
|
|
|
|
|
tidyRelease( tdoc ); |
|
188
|
|
|
|
|
|
|
|
|
189
|
13
|
50
|
|
|
|
|
if ( rc < 0 ) { |
|
190
|
0
|
|
|
|
|
|
XSRETURN_UNDEF; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
SV* |
|
195
|
|
|
|
|
|
|
_tidy_library_version() |
|
196
|
|
|
|
|
|
|
PREINIT: |
|
197
|
|
|
|
|
|
|
const char* version; |
|
198
|
|
|
|
|
|
|
CODE: |
|
199
|
3
|
|
|
|
|
|
version = tidyLibraryVersion(); |
|
200
|
3
|
|
|
|
|
|
RETVAL = newSVpv(version,0); /* will be automatically "mortalized" */ |
|
201
|
|
|
|
|
|
|
OUTPUT: |
|
202
|
|
|
|
|
|
|
RETVAL |