line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "xh_config.h" |
2
|
|
|
|
|
|
|
#include "xh_core.h" |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
SV * |
5
|
41
|
|
|
|
|
|
xh_h2x(xh_h2x_ctx_t *ctx) |
6
|
|
|
|
|
|
|
{ |
7
|
|
|
|
|
|
|
SV *result; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
/* run */ |
10
|
41
|
|
|
|
|
|
dXCPT; |
11
|
41
|
50
|
|
|
|
|
XCPT_TRY_START |
12
|
|
|
|
|
|
|
{ |
13
|
41
|
|
|
|
|
|
xh_stack_init(&ctx->stash, XH_H2X_STASH_SIZE, sizeof(SV *)); |
14
|
41
|
|
|
|
|
|
xh_writer_init(&ctx->writer, ctx->opts.encoding, ctx->opts.output, ctx->opts.buf_size, ctx->opts.indent, ctx->opts.trim); |
15
|
|
|
|
|
|
|
|
16
|
41
|
100
|
|
|
|
|
if (ctx->opts.xml_decl) { |
17
|
38
|
|
|
|
|
|
xh_xml_write_xml_declaration(&ctx->writer, ctx->opts.version, ctx->opts.encoding); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
41
|
|
|
|
|
|
switch (ctx->opts.method) { |
21
|
|
|
|
|
|
|
case XH_METHOD_NATIVE: |
22
|
21
|
|
|
|
|
|
xh_h2x_native(ctx, ctx->opts.root, xh_strlen(ctx->opts.root), SvRV(ctx->hash)); |
23
|
21
|
|
|
|
|
|
break; |
24
|
|
|
|
|
|
|
case XH_METHOD_NATIVE_ATTR_MODE: |
25
|
5
|
|
|
|
|
|
(void) xh_h2x_native_attr(ctx, ctx->opts.root, xh_strlen(ctx->opts.root), SvRV(ctx->hash), XH_H2X_F_COMPLEX); |
26
|
5
|
|
|
|
|
|
break; |
27
|
|
|
|
|
|
|
case XH_METHOD_LX: |
28
|
15
|
|
|
|
|
|
xh_h2x_lx(ctx, ctx->hash, NULL, 0, XH_H2X_F_NONE); |
29
|
15
|
|
|
|
|
|
break; |
30
|
|
|
|
|
|
|
default: |
31
|
0
|
|
|
|
|
|
croak("Invalid method"); |
32
|
|
|
|
|
|
|
} |
33
|
41
|
|
|
|
|
|
} XCPT_TRY_END |
34
|
|
|
|
|
|
|
|
35
|
41
|
50
|
|
|
|
|
XCPT_CATCH |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
|
|
|
xh_stash_clean(&ctx->stash); |
38
|
0
|
|
|
|
|
|
result = xh_writer_flush(&ctx->writer); |
39
|
0
|
0
|
|
|
|
|
if (result != NULL && result != &PL_sv_undef) { |
|
|
0
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
SvREFCNT_dec(result); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
xh_writer_destroy(&ctx->writer); |
43
|
0
|
0
|
|
|
|
|
XCPT_RETHROW; |
|
|
0
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
41
|
|
|
|
|
|
xh_stash_clean(&ctx->stash); |
47
|
41
|
|
|
|
|
|
result = xh_writer_flush(&ctx->writer); |
48
|
41
|
50
|
|
|
|
|
if (result != NULL && ctx->opts.utf8) { |
|
|
50
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#ifdef XH_HAVE_ENCODER |
50
|
41
|
100
|
|
|
|
|
if (ctx->writer.encoder == NULL) { |
51
|
39
|
|
|
|
|
|
SvUTF8_on(result); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
#else |
54
|
|
|
|
|
|
|
SvUTF8_on(result); |
55
|
|
|
|
|
|
|
#endif |
56
|
|
|
|
|
|
|
} |
57
|
41
|
|
|
|
|
|
xh_writer_destroy(&ctx->writer); |
58
|
|
|
|
|
|
|
|
59
|
41
|
|
|
|
|
|
return result; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#ifdef XH_HAVE_DOM |
63
|
|
|
|
|
|
|
SV * |
64
|
|
|
|
|
|
|
xh_h2d(xh_h2x_ctx_t *ctx) |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
dXCPT; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
xmlDocPtr doc = xmlNewDoc(BAD_CAST ctx->opts.version); |
69
|
|
|
|
|
|
|
if (doc == NULL) { |
70
|
|
|
|
|
|
|
croak("Can't create new document"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
if (ctx->opts.encoding[0] == '\0') { |
73
|
|
|
|
|
|
|
doc->encoding = (const xmlChar*) xmlStrdup((const xmlChar*) XH_INTERNAL_ENCODING); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else { |
76
|
|
|
|
|
|
|
doc->encoding = (const xmlChar*) xmlStrdup((const xmlChar*) ctx->opts.encoding); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
XCPT_TRY_START |
80
|
|
|
|
|
|
|
{ |
81
|
|
|
|
|
|
|
xh_stack_init(&ctx->stash, XH_H2X_STASH_SIZE, sizeof(SV *)); |
82
|
|
|
|
|
|
|
switch (ctx->opts.method) { |
83
|
|
|
|
|
|
|
case XH_METHOD_NATIVE: |
84
|
|
|
|
|
|
|
xh_h2d_native(ctx, (xmlNodePtr) doc, ctx->opts.root, xh_strlen(ctx->opts.root), SvRV(ctx->hash)); |
85
|
|
|
|
|
|
|
break; |
86
|
|
|
|
|
|
|
case XH_METHOD_NATIVE_ATTR_MODE: |
87
|
|
|
|
|
|
|
(void) xh_h2d_native_attr(ctx, (xmlNodePtr) doc, ctx->opts.root, xh_strlen(ctx->opts.root), SvRV(ctx->hash), XH_H2X_F_COMPLEX); |
88
|
|
|
|
|
|
|
break; |
89
|
|
|
|
|
|
|
case XH_METHOD_LX: |
90
|
|
|
|
|
|
|
xh_h2d_lx(ctx, (xmlNodePtr) doc, ctx->hash, NULL, 0, XH_H2X_F_NONE); |
91
|
|
|
|
|
|
|
break; |
92
|
|
|
|
|
|
|
default: |
93
|
|
|
|
|
|
|
croak("Invalid method"); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} XCPT_TRY_END |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
XCPT_CATCH |
98
|
|
|
|
|
|
|
{ |
99
|
|
|
|
|
|
|
xh_stash_clean(&ctx->stash); |
100
|
|
|
|
|
|
|
XCPT_RETHROW; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
xh_stash_clean(&ctx->stash); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return x_PmmNodeToSv((xmlNodePtr) doc, NULL); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
#endif |