lib/XML/ED/Bare.xs

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 76 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/XML/ED/Node.pm ↑ Summary lib/XML/ED/parser.c »
1 // JEdit mode Line -> :folding=indent:mode=c++:indentSize=2:noTabs=true:tabSize=2:
2 #include "EXTERN.h"
3 #define PERL_IN_HV_C
4 #define PERL_HASH_INTERNAL_ACCESS
5  
6 #include "perl.h"
7 #include "XSUB.h"
8 #include "parser.h"
9  
10 struct nodec *root;
11  
12 U32 Vhash;
13 U32 vhash;
14 U32 chash;
15 U32 phash;
16 U32 ihash;
17 U32 cdhash;
18 U32 typehash;
19 U32 zhash;
20 U32 nhash;
21 U32 ahash;
22  
23 struct nodec *curnode;
24 char *rootpos;
25
26 0 SV *cxml2obj() {
27 0 HV *output = newHV();
28 int i;
29 struct attc *curatt;
30 0 int numatts = curnode->numatt;
31 SV *attval;
32 SV *attatt;
33 0 HV *package = gv_stashpv("XML::ED::Node", GV_ADD);
34 0 SV *outputref = (SV *)sv_bless(newRV_noinc((SV*)output), package);
35  
36 0 int length = curnode->numchildren;
37
38 0 hv_store( output, "_pos", 4, newSViv( curnode->pos ), phash );
39 0 hv_store( output, "_i", 2, newSViv( curnode->name - rootpos ), ihash );
40 0 hv_store( output, "_z", 2, newSViv( curnode->z ), zhash );
41 0 hv_store( output, "_n", 2, newSViv( length ), nhash );
42 0 hv_store( output, "_name", 5, newSVpvn( curnode->name, curnode->namelen ), 0 );
43  
44 0 hv_store( output, "_type", 5, newSViv( curnode->type ), typehash);
45  
46 0 ▶ if( curnode->vallen ) {
Branch: 1 branch
BranchTrueFalseTotal
if( curnode->vallen ) { 0 0 0
47 0 SV * sv = newSVpvn( curnode->value, curnode->vallen );
48 0 SvUTF8_on(sv);
49 0 hv_store( output, "_value", 6, sv, Vhash );
50 }
51 0 ▶ if ( length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( length ) { 0 0 0
52 0 curnode = curnode->firstchild;
53 0 AV *newarray = newAV();
54 0 HV *package = gv_stashpv("XML::ED::NodeSet", GV_ADD);
55 0 SV *newarrayref = (SV *)sv_bless(newRV_noinc((SV*)newarray), package);
56 0 hv_store( output, "_data", 5, newarrayref, 0);
57  
58 0 ▶ for ( i = 0; i < length; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < length; i++ ) { 0 0 0
59 0 SV **cur = hv_fetch( output, curnode->name, curnode->namelen, 0 );
60 0 SV *ob = cxml2obj();
61 0 av_push( newarray, ob );
62  
63 0 ▶ if ( i != ( length - 1 ) ) curnode = curnode->next;
Branch: 1 branch
BranchTrueFalseTotal
if ( i != ( length - 1 ) ) curnode = curnode->next; 0 0 0
64 }
65
66 0 curnode = curnode->parent;
67 }
68
69 0 ▶ if ( numatts ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( numatts ) { 0 0 0
70 0 curatt = curnode->firstatt;
71 0 ▶ for ( i = 0; i < numatts; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < numatts; i++ ) { 0 0 0
72 0 HV *atth = newHV();
73 0 SV *atthref = newRV_noinc( (SV *) atth );
74 0 hv_store( output, curatt->name, curatt->namelen, atthref, 0 );
75
76 0 attval = newSVpvn( curatt->value, curatt->vallen );
77 0 SvUTF8_on(attval);
78 0 hv_store( atth, "value", 5, attval, vhash );
79 0 attatt = newSViv( 1 );
80 0 hv_store( atth, "_att", 4, attatt, ahash );
81 0 ▶ if( i != ( numatts - 1 ) ) curatt = curatt->next;
Branch: 1 branch
BranchTrueFalseTotal
if( i != ( numatts - 1 ) ) curatt = curatt->next; 0 0 0
82 }
83 }
84  
85 0 return outputref;
86 }
87  
88 struct parserc *parser = 0;
89  
90 MODULE = XML::ED::Bare PACKAGE = XML::ED::Bare
91  
92 SV *
93 xml2obj()
94 CODE:
95 0 curnode = parser->pcurnode;
96 0 ▶ if ( curnode->err ) RETVAL = newSViv( curnode->err );
Branch: 1 branch
BranchTrueFalseTotal
if ( curnode->err ) RETVAL = newSViv( curnode->err ); 0 0 0
97 0 else RETVAL = cxml2obj();
98 OUTPUT:
99 RETVAL
100
101 void
102 c_parse(text)
103 char * text
104 CODE:
105 0 rootpos = text;
106 0 PERL_HASH(vhash, "value", 5);
107 0 PERL_HASH(Vhash, "_value", 6);
108 0 PERL_HASH(ahash, "_att", 4);
109 0 PERL_HASH(chash, "comment", 7);
110 0 PERL_HASH(phash, "_pos", 4);
111 0 PERL_HASH(ihash, "_i", 2 );
112 0 PERL_HASH(zhash, "_z", 2 );
113 0 PERL_HASH(nhash, "_n", 2 );
114 0 PERL_HASH(cdhash, "_cdata", 6 );
115 0 PERL_HASH(typehash, "_type", 5 );
116 0 parser = (struct parserc *) malloc( sizeof( struct parserc ) );
117 0 root = parserc_parse( parser, text );
118  
119 SV *
120 get_root()
121 CODE:
122 0 RETVAL = newSVuv( PTR2UV( root ) );
123 OUTPUT:
124 RETVAL
125  
126 void
127 free_tree_c( rootsv )
128 SV *rootsv
129 CODE:
130 struct nodec *rootnode;
131 0 rootnode = INT2PTR( struct nodec *, SvUV( rootsv ) );
132 0 del_nodec( rootnode );
133  
« blib/lib/XML/ED/Node.pm ↑ Summary lib/XML/ED/parser.c »