| 1 |
|
| /* |
| 2 |
|
| * This file was generated automatically by ExtUtils::ParseXS version 3.63 from the |
| 3 |
|
| * contents of Bare.xs. Do not edit this file, edit Bare.xs instead. |
| 4 |
|
| * |
| 5 |
|
| * ANY CHANGES MADE HERE WILL BE LOST! |
| 6 |
|
| * |
| 7 |
|
| */ |
| 8 |
|
| |
| 9 |
|
| // JEdit mode Line -> :folding=indent:mode=c++:indentSize=2:noTabs=true:tabSize=2: |
| 10 |
|
| #include "EXTERN.h" |
| 11 |
|
| #define PERL_IN_HV_C |
| 12 |
|
| #define PERL_HASH_INTERNAL_ACCESS |
| 13 |
|
| |
| 14 |
|
| #include "perl.h" |
| 15 |
|
| #include "XSUB.h" |
| 16 |
|
| #include "parser.h" |
| 17 |
|
| |
| 18 |
|
| U32 vhash; |
| 19 |
|
| U32 chash; |
| 20 |
|
| U32 phash; |
| 21 |
|
| U32 ihash; |
| 22 |
|
| U32 cdhash; |
| 23 |
|
| U32 zhash; |
| 24 |
|
| U32 ahash; |
| 25 |
|
| U32 content_hash; |
| 26 |
|
| |
| 27 |
|
| char *rootpos; |
| 28 |
|
| |
| 29 |
|
| //#define DEBUG |
| 30 |
|
| |
| 31 |
121 |
| SV *cxml2obj( struct parserc *parser, struct nodec *curnode ) { |
| 32 |
121 |
| HV *output = newHV(); // the root |
| 33 |
121 |
| SV *outputref = newRV_noinc( (SV *) output ); // return a reference to the root |
| 34 |
|
| int i; // loop index; defined at the top because this is C |
| 35 |
|
| struct attc *curatt; // current attribute being worked with |
| 36 |
121 |
| int numatts = curnode->numatt; // total number of attributes on the current node |
| 37 |
|
| SV *attval; |
| 38 |
|
| SV *attatt; |
| 39 |
|
| int cur_type; |
| 40 |
|
| |
| 41 |
121 |
| int length = curnode->numchildren; |
| 42 |
121 |
| SV *svi = newSViv( curnode->pos ); |
| 43 |
|
| |
| 44 |
121 |
| hv_store( output, "_pos", 4, svi, phash ); |
| 45 |
121 |
| hv_store( output, "_i", 2, newSViv( curnode->name - rootpos ), ihash ); |
| 46 |
121 |
| hv_store( output, "_z", 2, newSViv( curnode->z ), zhash ); |
| 47 |
|
| |
| 48 |
|
| #ifdef DEBUG |
| 49 |
|
| printf("Node: %.*s\n", curnode->namelen, curnode->name ); |
| 50 |
|
| #endif |
| 51 |
|
| |
| 52 |
|
| // node without children |
| 53 |
121 |
▶ | if( !length ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !length ) { |
57 |
64 |
121 |
|
| 54 |
57 |
▶ | if( curnode->vallen ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->vallen ) { |
36 |
21 |
57 |
|
| 55 |
36 |
| SV * sv = newSVpvn( curnode->value, curnode->vallen ); |
| 56 |
36 |
| SvUTF8_on(sv); |
| 57 |
36 |
| hv_store( output, "value", 5, sv, vhash ); |
| 58 |
36 |
▶ | if( curnode->type ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->type ) { |
3 |
33 |
36 |
|
| 59 |
3 |
| SV *svi = newSViv( 1 ); |
| 60 |
3 |
| hv_store( output, "_cdata", 6, svi, cdhash ); |
| 61 |
|
| } |
| 62 |
|
| } |
| 63 |
57 |
▶ | if( curnode->comlen ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->comlen ) { |
4 |
53 |
57 |
|
| 64 |
4 |
| SV * sv = newSVpvn( curnode->comment, curnode->comlen ); |
| 65 |
4 |
| SvUTF8_on(sv); |
| 66 |
4 |
| hv_store( output, "comment", 7, sv, chash ); |
| 67 |
|
| } |
| 68 |
|
| } |
| 69 |
|
| |
| 70 |
|
| // node with children |
| 71 |
|
| else { |
| 72 |
64 |
▶ | if( curnode->vallen ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->vallen ) { |
31 |
33 |
64 |
|
| 73 |
31 |
| SV *sv = newSVpvn( curnode->value, curnode->vallen ); |
| 74 |
31 |
| SvUTF8_on(sv); |
| 75 |
31 |
| hv_store( output, "value", 5, sv, vhash ); |
| 76 |
31 |
▶ | if( curnode->type ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->type ) { |
0 |
31 |
31 |
|
| 77 |
0 |
| SV *svi = newSViv( 1 ); |
| 78 |
0 |
| hv_store( output, "_cdata", 6, svi, cdhash ); |
| 79 |
|
| } |
| 80 |
|
| } |
| 81 |
64 |
▶ | if( curnode->comlen ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->comlen ) { |
0 |
64 |
64 |
|
| 82 |
0 |
| SV *sv = newSVpvn( curnode->comment, curnode->comlen ); |
| 83 |
0 |
| SvUTF8_on(sv); |
| 84 |
0 |
| hv_store( output, "comment", 7, sv, chash ); |
| 85 |
|
| } |
| 86 |
|
| |
| 87 |
|
| // loop through child nodes |
| 88 |
64 |
| curnode = curnode->firstchild; |
| 89 |
152 |
▶ | for( i = 0; i < length; i++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for( i = 0; i < length; i++ ) { |
88 |
64 |
152 |
|
| 90 |
88 |
| SV **cur = hv_fetch( output, curnode->name, curnode->namelen, 0 ); |
| 91 |
|
| |
| 92 |
|
| // check for multi_[name] nodes |
| 93 |
88 |
▶ | if( curnode->namelen > 6 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->namelen > 6 ) { |
2 |
86 |
88 |
|
| 94 |
2 |
▶ | if( !strncmp( curnode->name, "multi_", 6 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !strncmp( curnode->name, "multi_", 6 ) ) { |
2 |
0 |
2 |
|
| 95 |
2 |
| char *subname = &curnode->name[6]; |
| 96 |
2 |
| int subnamelen = curnode->namelen-6; |
| 97 |
2 |
| SV **old = hv_fetch( output, subname, subnamelen, 0 ); |
| 98 |
2 |
| AV *newarray = newAV(); |
| 99 |
2 |
| SV *newarrayref = newRV_noinc( (SV *) newarray ); |
| 100 |
2 |
▶ | if( !old ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !old ) { |
2 |
0 |
2 |
|
| 101 |
2 |
| hv_store( output, subname, subnamelen, newarrayref, 0 ); |
| 102 |
|
| } |
| 103 |
|
| else { |
| 104 |
0 |
▶ | if( SvTYPE( SvRV(*old) ) == SVt_PVHV ) { // check for hash ref |
Branch: 1 branch
| Branch | True | False | Total |
| if( SvTYPE( SvRV(*old) ) == SVt_PVHV ) { // check for hash ref |
0 |
0 |
0 |
|
| 105 |
0 |
| SV *newref = newRV( (SV *) SvRV(*old) ); |
| 106 |
0 |
| hv_delete( output, subname, subnamelen, 0 ); |
| 107 |
0 |
| hv_store( output, subname, subnamelen, newarrayref, 0 ); |
| 108 |
0 |
| av_push( newarray, newref ); |
| 109 |
|
| } |
| 110 |
|
| } |
| 111 |
|
| } |
| 112 |
|
| } |
| 113 |
|
| |
| 114 |
88 |
▶ | if( !cur ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !cur ) { |
81 |
7 |
88 |
|
| 115 |
81 |
| SV *ob = cxml2obj( parser, curnode ); |
| 116 |
81 |
| hv_store( output, curnode->name, curnode->namelen, ob, 0 ); |
| 117 |
|
| } |
| 118 |
|
| else { // there is already a node stored with this name |
| 119 |
7 |
| cur_type = SvTYPE( SvRV( *cur ) ); |
| 120 |
7 |
▶ | if( cur_type == SVt_PVHV ) { // sub value is a hash; must be anode |
Branch: 1 branch
| Branch | True | False | Total |
| if( cur_type == SVt_PVHV ) { // sub value is a hash; must be anode |
4 |
3 |
7 |
|
| 121 |
4 |
| AV *newarray = newAV(); |
| 122 |
4 |
| SV *newarrayref = newRV_noinc( (SV *) newarray ); |
| 123 |
4 |
| SV *newref = newRV( (SV *) SvRV( *cur ) ); |
| 124 |
|
| SV *ob; |
| 125 |
4 |
| hv_delete( output, curnode->name, curnode->namelen, 0 ); |
| 126 |
4 |
| hv_store( output, curnode->name, curnode->namelen, newarrayref, 0 ); |
| 127 |
4 |
| av_push( newarray, newref ); |
| 128 |
4 |
| ob = cxml2obj( parser, curnode ); |
| 129 |
4 |
| av_push( newarray, ob ); |
| 130 |
|
| } |
| 131 |
3 |
▶ | else if( cur_type == SVt_PVAV ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if( cur_type == SVt_PVAV ) { |
2 |
1 |
3 |
|
| 132 |
2 |
| AV *av = (AV *) SvRV( *cur ); |
| 133 |
2 |
| SV *ob = cxml2obj( parser, curnode ); |
| 134 |
2 |
| av_push( av, ob ); |
| 135 |
|
| } |
| 136 |
|
| else { |
| 137 |
|
| // something else; probably an existing value node; just wipe it out |
| 138 |
1 |
| SV *ob = cxml2obj( parser, curnode ); |
| 139 |
1 |
| hv_store( output, curnode->name, curnode->namelen, ob, 0 ); |
| 140 |
|
| } |
| 141 |
|
| } |
| 142 |
88 |
▶ | if( i != ( length - 1 ) ) curnode = curnode->next; |
Branch: 1 branch
| Branch | True | False | Total |
| if( i != ( length - 1 ) ) curnode = curnode->next; |
24 |
64 |
88 |
|
| 143 |
|
| } |
| 144 |
|
| |
| 145 |
64 |
| curnode = curnode->parent; |
| 146 |
|
| } |
| 147 |
|
| |
| 148 |
121 |
▶ | if( numatts ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( numatts ) { |
13 |
108 |
121 |
|
| 149 |
13 |
| curatt = curnode->firstatt; |
| 150 |
27 |
▶ | for( i = 0; i < numatts; i++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for( i = 0; i < numatts; i++ ) { |
14 |
13 |
27 |
|
| 151 |
14 |
| HV *atth = newHV(); |
| 152 |
14 |
| SV *atthref = newRV_noinc( (SV *) atth ); |
| 153 |
14 |
| hv_store( output, curatt->name, curatt->namelen, atthref, 0 ); |
| 154 |
|
| |
| 155 |
14 |
▶ | if( curatt->value == -1 ) attval = newSVpvn( "1", 1 ); |
Branch: 1 branch
| Branch | True | False | Total |
| if( curatt->value == -1 ) attval = newSVpvn( "1", 1 ); |
1 |
13 |
14 |
|
| 156 |
13 |
| else attval = newSVpvn( curatt->value, curatt->vallen ); |
| 157 |
14 |
| SvUTF8_on(attval); |
| 158 |
14 |
| hv_store( atth, "value", 5, attval, vhash ); |
| 159 |
14 |
| attatt = newSViv( 1 ); |
| 160 |
14 |
| hv_store( atth, "_att", 4, attatt, ahash ); |
| 161 |
14 |
▶ | if( i != ( numatts - 1 ) ) curatt = curatt->next; |
Branch: 1 branch
| Branch | True | False | Total |
| if( i != ( numatts - 1 ) ) curatt = curatt->next; |
1 |
13 |
14 |
|
| 162 |
|
| } |
| 163 |
|
| } |
| 164 |
121 |
| return outputref; |
| 165 |
|
| } |
| 166 |
|
| |
| 167 |
31 |
| SV *cxml2obj_simple( struct parserc *parser, struct nodec *curnode ) { |
| 168 |
|
| int i; |
| 169 |
|
| struct attc *curatt; |
| 170 |
31 |
| int numatts = curnode->numatt; |
| 171 |
|
| SV *attval; |
| 172 |
|
| SV *attatt; |
| 173 |
|
| HV *output; |
| 174 |
|
| SV *outputref; |
| 175 |
|
| |
| 176 |
31 |
| int length = curnode->numchildren; |
| 177 |
31 |
▶ | if( ( length + numatts ) == 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( ( length + numatts ) == 0 ) { |
8 |
23 |
31 |
|
| 178 |
8 |
▶ | if( curnode->vallen ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->vallen ) { |
5 |
3 |
8 |
|
| 179 |
5 |
| SV * sv = newSVpvn( curnode->value, curnode->vallen ); |
| 180 |
5 |
| SvUTF8_on(sv); |
| 181 |
5 |
| return sv; |
| 182 |
|
| } |
| 183 |
3 |
| return newSVpvn( "", 0 ); |
| 184 |
|
| } |
| 185 |
|
| |
| 186 |
23 |
| output = newHV(); |
| 187 |
23 |
| outputref = newRV_noinc( (SV *) output ); |
| 188 |
|
| |
| 189 |
23 |
▶ | if( length ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( length ) { |
19 |
4 |
23 |
|
| 190 |
19 |
| curnode = curnode->firstchild; |
| 191 |
40 |
▶ | for( i = 0; i < length; i++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for( i = 0; i < length; i++ ) { |
21 |
19 |
40 |
|
| 192 |
21 |
| SV *namesv = newSVpvn( curnode->name, curnode->namelen ); |
| 193 |
21 |
| SvUTF8_on(namesv); |
| 194 |
|
| |
| 195 |
21 |
| SV **cur = hv_fetch( output, curnode->name, curnode->namelen, 0 ); |
| 196 |
|
| |
| 197 |
21 |
▶ | if( curnode->namelen > 6 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->namelen > 6 ) { |
1 |
20 |
21 |
|
| 198 |
1 |
▶ | if( !strncmp( curnode->name, "multi_", 6 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !strncmp( curnode->name, "multi_", 6 ) ) { |
1 |
0 |
1 |
|
| 199 |
1 |
| char *subname = &curnode->name[6]; |
| 200 |
1 |
| int subnamelen = curnode->namelen-6; |
| 201 |
1 |
| SV **old = hv_fetch( output, subname, subnamelen, 0 ); |
| 202 |
1 |
| AV *newarray = newAV(); |
| 203 |
1 |
| SV *newarrayref = newRV_noinc( (SV *) newarray ); |
| 204 |
1 |
▶ | if( !old ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !old ) { |
1 |
0 |
1 |
|
| 205 |
1 |
| hv_store( output, subname, subnamelen, newarrayref, 0 ); |
| 206 |
|
| } |
| 207 |
|
| else { |
| 208 |
0 |
▶ | if( SvTYPE( SvRV(*old) ) == SVt_PVHV ) { // check for hash ref |
Branch: 1 branch
| Branch | True | False | Total |
| if( SvTYPE( SvRV(*old) ) == SVt_PVHV ) { // check for hash ref |
0 |
0 |
0 |
|
| 209 |
0 |
| SV *newref = newRV_noinc( (SV *) SvRV(*old) ); |
| 210 |
0 |
| hv_delete( output, subname, subnamelen, 0 ); |
| 211 |
0 |
| hv_store( output, subname, subnamelen, newarrayref, 0 ); |
| 212 |
0 |
| av_push( newarray, newref ); |
| 213 |
|
| } |
| 214 |
|
| } |
| 215 |
|
| } |
| 216 |
|
| } |
| 217 |
|
| |
| 218 |
21 |
▶ | if( !cur ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !cur ) { |
19 |
2 |
21 |
|
| 219 |
19 |
| SV *ob = cxml2obj_simple( parser, curnode ); |
| 220 |
19 |
| hv_store( output, curnode->name, curnode->namelen, ob, 0 ); |
| 221 |
|
| } |
| 222 |
|
| else { |
| 223 |
2 |
▶ | if( SvROK( *cur ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( SvROK( *cur ) ) { |
1 |
1 |
2 |
|
| 224 |
1 |
▶ | if( SvTYPE( SvRV(*cur) ) == SVt_PVHV ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( SvTYPE( SvRV(*cur) ) == SVt_PVHV ) { |
0 |
1 |
1 |
|
| 225 |
0 |
| AV *newarray = newAV(); |
| 226 |
0 |
| SV *newarrayref = newRV_noinc( (SV *) newarray ); |
| 227 |
0 |
| SV *newref = newRV( (SV *) SvRV( *cur ) ); |
| 228 |
0 |
| hv_delete( output, curnode->name, curnode->namelen, 0 ); |
| 229 |
0 |
| hv_store( output, curnode->name, curnode->namelen, newarrayref, 0 ); |
| 230 |
0 |
| av_push( newarray, newref ); |
| 231 |
0 |
| av_push( newarray, cxml2obj_simple( parser, curnode ) ); |
| 232 |
|
| } |
| 233 |
|
| else { |
| 234 |
1 |
| AV *av = (AV *) SvRV( *cur ); |
| 235 |
1 |
| av_push( av, cxml2obj_simple( parser, curnode ) ); |
| 236 |
|
| } |
| 237 |
|
| } |
| 238 |
|
| else { |
| 239 |
1 |
| AV *newarray = newAV(); |
| 240 |
1 |
| SV *newarrayref = newRV( (SV *) newarray ); |
| 241 |
|
| |
| 242 |
|
| STRLEN len; |
| 243 |
1 |
| char *ptr = SvPV(*cur, len); |
| 244 |
1 |
| SV *newsv = newSVpvn( ptr, len ); |
| 245 |
1 |
| SvUTF8_on(newsv); |
| 246 |
|
| |
| 247 |
1 |
| av_push( newarray, newsv ); |
| 248 |
1 |
| hv_delete( output, curnode->name, curnode->namelen, 0 ); |
| 249 |
1 |
| hv_store( output, curnode->name, curnode->namelen, newarrayref, 0 ); |
| 250 |
1 |
| av_push( newarray, cxml2obj_simple( parser, curnode ) ); |
| 251 |
|
| } |
| 252 |
|
| } |
| 253 |
21 |
▶ | if( i != ( length - 1 ) ) curnode = curnode->next; |
Branch: 1 branch
| Branch | True | False | Total |
| if( i != ( length - 1 ) ) curnode = curnode->next; |
2 |
19 |
21 |
|
| 254 |
|
| } |
| 255 |
19 |
| curnode = curnode->parent; |
| 256 |
|
| } |
| 257 |
|
| else { |
| 258 |
4 |
▶ | if( curnode->type ) { // store cdata value under content, even if empty or spaces |
Branch: 1 branch
| Branch | True | False | Total |
| if( curnode->type ) { // store cdata value under content, even if empty or spaces |
1 |
3 |
4 |
|
| 259 |
1 |
| SV * sv = newSVpvn( curnode->value, curnode->vallen ); |
| 260 |
1 |
| SvUTF8_on(sv); |
| 261 |
1 |
| hv_store( output, "content", 7, sv, content_hash ); |
| 262 |
|
| } |
| 263 |
|
| else { |
| 264 |
3 |
| int hasval = 0; |
| 265 |
3 |
▶ | for( i=0;i<curnode->vallen;i++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for( i=0;i<curnode->vallen;i++ ) { |
3 |
0 |
3 |
|
| 266 |
3 |
| char let = curnode->value[ i ]; |
| 267 |
3 |
▶ | if( let != ' ' && let != 0x0d && let != 0x0a ) { |
Branch: 3 branches
| Branch | True | False | Total |
| if( let != ' ' && let != 0x0d && let != 0x0a ) { |
3 |
0 |
3 |
| if( let != ' ' && let != 0x0d && let != 0x0a ) { |
3 |
0 |
3 |
| if( let != ' ' && let != 0x0d && let != 0x0a ) { |
3 |
0 |
3 |
|
| 268 |
3 |
| hasval = 1; |
| 269 |
3 |
| break; |
| 270 |
|
| } |
| 271 |
|
| } |
| 272 |
3 |
▶ | if( hasval ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( hasval ) { |
3 |
0 |
3 |
|
| 273 |
3 |
| SV * sv = newSVpvn( curnode->value, curnode->vallen ); |
| 274 |
3 |
| SvUTF8_on(sv); |
| 275 |
3 |
| hv_store( output, "content", 7, sv, content_hash ); |
| 276 |
|
| } |
| 277 |
|
| } |
| 278 |
|
| } |
| 279 |
|
| |
| 280 |
23 |
▶ | if( numatts ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( numatts ) { |
5 |
18 |
23 |
|
| 281 |
5 |
| curatt = curnode->firstatt; |
| 282 |
10 |
▶ | for( i = 0; i < numatts; i++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for( i = 0; i < numatts; i++ ) { |
5 |
5 |
10 |
|
| 283 |
5 |
▶ | if( curatt->value == -1 ) attval = newSVpvn( "1", 1 ); |
Branch: 1 branch
| Branch | True | False | Total |
| if( curatt->value == -1 ) attval = newSVpvn( "1", 1 ); |
1 |
4 |
5 |
|
| 284 |
4 |
| else attval = newSVpvn( curatt->value, curatt->vallen ); |
| 285 |
5 |
| SvUTF8_on(attval); |
| 286 |
5 |
| hv_store( output, curatt->name, curatt->namelen, attval, 0 ); |
| 287 |
5 |
▶ | if( i != ( numatts - 1 ) ) curatt = curatt->next; |
Branch: 1 branch
| Branch | True | False | Total |
| if( i != ( numatts - 1 ) ) curatt = curatt->next; |
0 |
5 |
5 |
|
| 288 |
|
| } |
| 289 |
|
| } |
| 290 |
|
| |
| 291 |
23 |
| return outputref; |
| 292 |
|
| } |
| 293 |
|
| |
| 294 |
43 |
| void init_hashes() { |
| 295 |
43 |
| PERL_HASH(vhash, "value", 5); |
| 296 |
43 |
| PERL_HASH(ahash, "_att", 4); |
| 297 |
43 |
| PERL_HASH(chash, "comment", 7); |
| 298 |
43 |
| PERL_HASH(phash, "_pos", 4); |
| 299 |
43 |
| PERL_HASH(ihash, "_i", 2 ); |
| 300 |
43 |
| PERL_HASH(zhash, "_z", 2 ); |
| 301 |
43 |
| PERL_HASH(cdhash, "_cdata", 6 ); |
| 302 |
43 |
| } |
| 303 |
|
| |
| 304 |
|
| #ifndef PERL_UNUSED_VAR |
| 305 |
|
| # define PERL_UNUSED_VAR(var) if (0) var = var |
| 306 |
|
| #endif |
| 307 |
|
| |
| 308 |
|
| #ifndef dVAR |
| 309 |
|
| # define dVAR dNOOP |
| 310 |
|
| #endif |
| 311 |
|
| |
| 312 |
|
| |
| 313 |
|
| /* This stuff is not part of the API! You have been warned. */ |
| 314 |
|
| #ifndef PERL_VERSION_DECIMAL |
| 315 |
|
| # define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s) |
| 316 |
|
| #endif |
| 317 |
|
| #ifndef PERL_DECIMAL_VERSION |
| 318 |
|
| # define PERL_DECIMAL_VERSION \ |
| 319 |
|
| PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION) |
| 320 |
|
| #endif |
| 321 |
|
| #ifndef PERL_VERSION_GE |
| 322 |
|
| # define PERL_VERSION_GE(r,v,s) \ |
| 323 |
|
| (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s)) |
| 324 |
|
| #endif |
| 325 |
|
| #ifndef PERL_VERSION_LE |
| 326 |
|
| # define PERL_VERSION_LE(r,v,s) \ |
| 327 |
|
| (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s)) |
| 328 |
|
| #endif |
| 329 |
|
| |
| 330 |
|
| /* XS_INTERNAL is the explicit static-linkage variant of the default |
| 331 |
|
| * XS macro. |
| 332 |
|
| * |
| 333 |
|
| * XS_EXTERNAL is the same as XS_INTERNAL except it does not include |
| 334 |
|
| * "static", ie. it exports XSUB symbols. You probably don't want that |
| 335 |
|
| * for anything but the BOOT XSUB. |
| 336 |
|
| * |
| 337 |
|
| * See XSUB.h in core! |
| 338 |
|
| */ |
| 339 |
|
| |
| 340 |
|
| |
| 341 |
|
| /* TODO: This might be compatible further back than 5.10.0. */ |
| 342 |
|
| #if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1) |
| 343 |
|
| # undef XS_EXTERNAL |
| 344 |
|
| # undef XS_INTERNAL |
| 345 |
|
| # if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING) |
| 346 |
|
| # define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name) |
| 347 |
|
| # define XS_INTERNAL(name) static XSPROTO(name) |
| 348 |
|
| # endif |
| 349 |
|
| # if defined(__SYMBIAN32__) |
| 350 |
|
| # define XS_EXTERNAL(name) EXPORT_C XSPROTO(name) |
| 351 |
|
| # define XS_INTERNAL(name) EXPORT_C static XSPROTO(name) |
| 352 |
|
| # endif |
| 353 |
|
| # ifndef XS_EXTERNAL |
| 354 |
|
| # if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus) |
| 355 |
|
| # define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__) |
| 356 |
|
| # define XS_INTERNAL(name) static void name(pTHX_ CV* cv __attribute__unused__) |
| 357 |
|
| # else |
| 358 |
|
| # ifdef __cplusplus |
| 359 |
|
| # define XS_EXTERNAL(name) extern "C" XSPROTO(name) |
| 360 |
|
| # define XS_INTERNAL(name) static XSPROTO(name) |
| 361 |
|
| # else |
| 362 |
|
| # define XS_EXTERNAL(name) XSPROTO(name) |
| 363 |
|
| # define XS_INTERNAL(name) static XSPROTO(name) |
| 364 |
|
| # endif |
| 365 |
|
| # endif |
| 366 |
|
| # endif |
| 367 |
|
| #endif |
| 368 |
|
| |
| 369 |
|
| /* perl >= 5.10.0 && perl <= 5.15.1 */ |
| 370 |
|
| |
| 371 |
|
| |
| 372 |
|
| /* The XS_EXTERNAL macro is used for functions that must not be static |
| 373 |
|
| * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL |
| 374 |
|
| * macro defined, the best we can do is assume XS is the same. |
| 375 |
|
| * Dito for XS_INTERNAL. |
| 376 |
|
| */ |
| 377 |
|
| #ifndef XS_EXTERNAL |
| 378 |
|
| # define XS_EXTERNAL(name) XS(name) |
| 379 |
|
| #endif |
| 380 |
|
| #ifndef XS_INTERNAL |
| 381 |
|
| # define XS_INTERNAL(name) XS(name) |
| 382 |
|
| #endif |
| 383 |
|
| |
| 384 |
|
| /* Now, finally, after all this mess, we want an ExtUtils::ParseXS |
| 385 |
|
| * internal macro that we're free to redefine for varying linkage due |
| 386 |
|
| * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use |
| 387 |
|
| * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to! |
| 388 |
|
| */ |
| 389 |
|
| |
| 390 |
|
| #undef XS_EUPXS |
| 391 |
|
| #if defined(PERL_EUPXS_ALWAYS_EXPORT) |
| 392 |
|
| # define XS_EUPXS(name) XS_EXTERNAL(name) |
| 393 |
|
| #else |
| 394 |
|
| /* default to internal */ |
| 395 |
|
| # define XS_EUPXS(name) XS_INTERNAL(name) |
| 396 |
|
| #endif |
| 397 |
|
| |
| 398 |
|
| #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE |
| 399 |
|
| #define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params) |
| 400 |
|
| |
| 401 |
|
| /* prototype to pass -Wmissing-prototypes */ |
| 402 |
|
| static void |
| 403 |
|
| S_croak_xs_usage(const CV *const cv, const char *const params); |
| 404 |
|
| |
| 405 |
|
| static void |
| 406 |
|
| S_croak_xs_usage(const CV *const cv, const char *const params) |
| 407 |
|
| { |
| 408 |
|
| const GV *const gv = CvGV(cv); |
| 409 |
|
| |
| 410 |
|
| PERL_ARGS_ASSERT_CROAK_XS_USAGE; |
| 411 |
|
| |
| 412 |
|
| if (gv) { |
| 413 |
|
| const char *const gvname = GvNAME(gv); |
| 414 |
|
| const HV *const stash = GvSTASH(gv); |
| 415 |
|
| const char *const hvname = stash ? HvNAME(stash) : NULL; |
| 416 |
|
| |
| 417 |
|
| if (hvname) |
| 418 |
|
| Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params); |
| 419 |
|
| else |
| 420 |
|
| Perl_croak_nocontext("Usage: %s(%s)", gvname, params); |
| 421 |
|
| } else { |
| 422 |
|
| /* Pants. I don't think that it should be possible to get here. */ |
| 423 |
|
| Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params); |
| 424 |
|
| } |
| 425 |
|
| } |
| 426 |
|
| #undef PERL_ARGS_ASSERT_CROAK_XS_USAGE |
| 427 |
|
| |
| 428 |
|
| #define croak_xs_usage S_croak_xs_usage |
| 429 |
|
| |
| 430 |
|
| #endif |
| 431 |
|
| |
| 432 |
|
| /* NOTE: the prototype of newXSproto() is different in versions of perls, |
| 433 |
|
| * so we define a portable version of newXSproto() |
| 434 |
|
| */ |
| 435 |
|
| #ifdef newXS_flags |
| 436 |
|
| #define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0) |
| 437 |
|
| #else |
| 438 |
|
| #define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv) |
| 439 |
|
| #endif /* !defined(newXS_flags) */ |
| 440 |
|
| |
| 441 |
|
| #if PERL_VERSION_LE(5, 21, 5) |
| 442 |
|
| # define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file) |
| 443 |
|
| #else |
| 444 |
|
| # define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b) |
| 445 |
|
| #endif |
| 446 |
|
| |
| 447 |
|
| /* simple backcompat versions of the TARGx() macros with no optimisation */ |
| 448 |
|
| #ifndef TARGi |
| 449 |
|
| # define TARGi(iv, do_taint) sv_setiv_mg(TARG, iv) |
| 450 |
|
| # define TARGu(uv, do_taint) sv_setuv_mg(TARG, uv) |
| 451 |
|
| # define TARGn(nv, do_taint) sv_setnv_mg(TARG, nv) |
| 452 |
|
| #endif |
| 453 |
|
| |
| 454 |
|
| |
| 455 |
|
| XS_EUPXS(XS_XML__Bare_xml2obj); /* prototype to pass -Wmissing-prototypes */ |
| 456 |
33 |
| XS_EUPXS(XS_XML__Bare_xml2obj) |
| 457 |
|
| { |
| 458 |
33 |
| dVAR; dXSARGS; |
| 459 |
33 |
▶ | if (items != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 1) |
0 |
33 |
33 |
|
| 460 |
0 |
| croak_xs_usage(cv, "parsersv"); |
| 461 |
|
| { |
| 462 |
33 |
| SV * parsersv = ST(0) |
| 463 |
|
| ; |
| 464 |
|
| SV * RETVAL; |
| 465 |
|
| struct parserc *parser; |
| 466 |
33 |
| parser = INT2PTR( struct parserc *, SvUV( parsersv ) ); |
| 467 |
33 |
▶ | if( parser->err ) RETVAL = newSViv( parser->err ); |
Branch: 1 branch
| Branch | True | False | Total |
| if( parser->err ) RETVAL = newSViv( parser->err ); |
0 |
33 |
33 |
|
| 468 |
|
| else { |
| 469 |
33 |
| RETVAL = cxml2obj( parser, parser->rootnode ); |
| 470 |
|
| //printf("refcnt: %i\n", SvREFCNT( RETVAL ) ); |
| 471 |
|
| } |
| 472 |
33 |
| RETVAL = sv_2mortal(RETVAL); |
| 473 |
33 |
| ST(0) = RETVAL; |
| 474 |
|
| } |
| 475 |
33 |
| XSRETURN(1); |
| 476 |
|
| } |
| 477 |
|
| |
| 478 |
|
| |
| 479 |
|
| XS_EUPXS(XS_XML__Bare_xml2obj_simple); /* prototype to pass -Wmissing-prototypes */ |
| 480 |
10 |
| XS_EUPXS(XS_XML__Bare_xml2obj_simple) |
| 481 |
|
| { |
| 482 |
10 |
| dVAR; dXSARGS; |
| 483 |
10 |
▶ | if (items != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 1) |
0 |
10 |
10 |
|
| 484 |
0 |
| croak_xs_usage(cv, "parsersv"); |
| 485 |
|
| { |
| 486 |
10 |
| SV * parsersv = ST(0) |
| 487 |
|
| ; |
| 488 |
|
| SV * RETVAL; |
| 489 |
10 |
| PERL_HASH( content_hash, "content", 7 ); |
| 490 |
|
| struct parserc *parser; |
| 491 |
10 |
| parser = INT2PTR( struct parserc *, SvUV( parsersv ) ); |
| 492 |
10 |
▶ | if( parser->err ) RETVAL = newSViv( parser->err ); |
Branch: 1 branch
| Branch | True | False | Total |
| if( parser->err ) RETVAL = newSViv( parser->err ); |
0 |
10 |
10 |
|
| 493 |
|
| else { |
| 494 |
10 |
| RETVAL = cxml2obj_simple( parser, parser->rootnode ); |
| 495 |
|
| //printf("refcnt: %i\n", SvREFCNT( RETVAL ) ); |
| 496 |
|
| } |
| 497 |
10 |
| RETVAL = sv_2mortal(RETVAL); |
| 498 |
10 |
| ST(0) = RETVAL; |
| 499 |
|
| } |
| 500 |
10 |
| XSRETURN(1); |
| 501 |
|
| } |
| 502 |
|
| |
| 503 |
|
| |
| 504 |
|
| XS_EUPXS(XS_XML__Bare_c_parse_more); /* prototype to pass -Wmissing-prototypes */ |
| 505 |
0 |
| XS_EUPXS(XS_XML__Bare_c_parse_more) |
| 506 |
|
| { |
| 507 |
0 |
| dVAR; dXSARGS; |
| 508 |
0 |
▶ | if (items != 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2) |
0 |
0 |
0 |
|
| 509 |
0 |
| croak_xs_usage(cv, "text, parsersv"); |
| 510 |
|
| { |
| 511 |
0 |
| char * text = (char *)SvPV_nolen(ST(0)) |
| 512 |
|
| ; |
| 513 |
0 |
| SV * parsersv = ST(1) |
| 514 |
|
| ; |
| 515 |
|
| SV * RETVAL; |
| 516 |
0 |
| struct parserc *parser = INT2PTR( struct parserc *, SvUV( parsersv ) ); |
| 517 |
0 |
| int err = parserc_parse( parser, text ); |
| 518 |
0 |
| RETVAL = newSVuv( PTR2UV( parser ) ); |
| 519 |
0 |
| RETVAL = sv_2mortal(RETVAL); |
| 520 |
0 |
| ST(0) = RETVAL; |
| 521 |
|
| } |
| 522 |
0 |
| XSRETURN(1); |
| 523 |
|
| } |
| 524 |
|
| |
| 525 |
|
| |
| 526 |
|
| XS_EUPXS(XS_XML__Bare_c_parse); /* prototype to pass -Wmissing-prototypes */ |
| 527 |
43 |
| XS_EUPXS(XS_XML__Bare_c_parse) |
| 528 |
|
| { |
| 529 |
43 |
| dVAR; dXSARGS; |
| 530 |
43 |
▶ | if (items != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 1) |
0 |
43 |
43 |
|
| 531 |
0 |
| croak_xs_usage(cv, "text"); |
| 532 |
|
| { |
| 533 |
43 |
| char * text = (char *)SvPV_nolen(ST(0)) |
| 534 |
|
| ; |
| 535 |
|
| SV * RETVAL; |
| 536 |
43 |
| init_hashes(); |
| 537 |
|
| |
| 538 |
43 |
| struct parserc *parser = (struct parserc *) malloc( sizeof( struct parserc ) ); |
| 539 |
43 |
| parser->last_state = 0; |
| 540 |
43 |
| int err = parserc_parse( parser, text ); |
| 541 |
43 |
| RETVAL = newSVuv( PTR2UV( parser ) ); |
| 542 |
43 |
| RETVAL = sv_2mortal(RETVAL); |
| 543 |
43 |
| ST(0) = RETVAL; |
| 544 |
|
| } |
| 545 |
43 |
| XSRETURN(1); |
| 546 |
|
| } |
| 547 |
|
| |
| 548 |
|
| |
| 549 |
|
| XS_EUPXS(XS_XML__Bare_c_parse_unsafely); /* prototype to pass -Wmissing-prototypes */ |
| 550 |
0 |
| XS_EUPXS(XS_XML__Bare_c_parse_unsafely) |
| 551 |
|
| { |
| 552 |
0 |
| dVAR; dXSARGS; |
| 553 |
0 |
▶ | if (items != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 1) |
0 |
0 |
0 |
|
| 554 |
0 |
| croak_xs_usage(cv, "text"); |
| 555 |
|
| { |
| 556 |
0 |
| char * text = (char *)SvPV_nolen(ST(0)) |
| 557 |
|
| ; |
| 558 |
|
| SV * RETVAL; |
| 559 |
0 |
| init_hashes(); |
| 560 |
|
| |
| 561 |
0 |
| struct parserc *parser = (struct parserc *) malloc( sizeof( struct parserc ) ); |
| 562 |
0 |
| parser->last_state = 0; |
| 563 |
0 |
| int err = parserc_parse_unsafely( parser, text ); |
| 564 |
0 |
| RETVAL = newSVuv( PTR2UV( parser ) ); |
| 565 |
0 |
| RETVAL = sv_2mortal(RETVAL); |
| 566 |
0 |
| ST(0) = RETVAL; |
| 567 |
|
| } |
| 568 |
0 |
| XSRETURN(1); |
| 569 |
|
| } |
| 570 |
|
| |
| 571 |
|
| |
| 572 |
|
| XS_EUPXS(XS_XML__Bare_c_parsefile); /* prototype to pass -Wmissing-prototypes */ |
| 573 |
0 |
| XS_EUPXS(XS_XML__Bare_c_parsefile) |
| 574 |
|
| { |
| 575 |
0 |
| dVAR; dXSARGS; |
| 576 |
0 |
▶ | if (items != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 1) |
0 |
0 |
0 |
|
| 577 |
0 |
| croak_xs_usage(cv, "filename"); |
| 578 |
|
| { |
| 579 |
0 |
| char * filename = (char *)SvPV_nolen(ST(0)) |
| 580 |
|
| ; |
| 581 |
|
| SV * RETVAL; |
| 582 |
|
| char *data; |
| 583 |
|
| unsigned long len; |
| 584 |
|
| FILE *handle; |
| 585 |
|
| |
| 586 |
0 |
| init_hashes(); |
| 587 |
|
| |
| 588 |
0 |
| handle = fopen(filename,"r"); |
| 589 |
|
| |
| 590 |
0 |
| fseek( handle, 0, SEEK_END ); |
| 591 |
|
| |
| 592 |
0 |
| len = ftell( handle ); |
| 593 |
|
| |
| 594 |
0 |
| fseek( handle, 0, SEEK_SET ); |
| 595 |
0 |
| data = (char *) malloc( len ); |
| 596 |
0 |
| rootpos = data; |
| 597 |
0 |
| fread( data, 1, len, handle ); |
| 598 |
0 |
| fclose( handle ); |
| 599 |
0 |
| struct parserc *parser = (struct parserc *) malloc( sizeof( struct parserc ) ); |
| 600 |
0 |
| parser->last_state = 0; |
| 601 |
0 |
| int err = parserc_parse( parser, data ); |
| 602 |
|
| //free( parser ); |
| 603 |
0 |
| RETVAL = newSVuv( PTR2UV( parser ) ); |
| 604 |
0 |
| RETVAL = sv_2mortal(RETVAL); |
| 605 |
0 |
| ST(0) = RETVAL; |
| 606 |
|
| } |
| 607 |
0 |
| XSRETURN(1); |
| 608 |
|
| } |
| 609 |
|
| |
| 610 |
|
| |
| 611 |
|
| XS_EUPXS(XS_XML__Bare_free_tree_c); /* prototype to pass -Wmissing-prototypes */ |
| 612 |
43 |
| XS_EUPXS(XS_XML__Bare_free_tree_c) |
| 613 |
|
| { |
| 614 |
43 |
| dVAR; dXSARGS; |
| 615 |
43 |
▶ | if (items != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 1) |
0 |
43 |
43 |
|
| 616 |
0 |
| croak_xs_usage(cv, "parsersv"); |
| 617 |
|
| { |
| 618 |
43 |
| SV * parsersv = ST(0) |
| 619 |
|
| ; |
| 620 |
|
| struct parserc *parser; |
| 621 |
43 |
| parser = INT2PTR( struct parserc *, SvUV( parsersv ) ); |
| 622 |
43 |
| struct nodec *rootnode = parser->rootnode; |
| 623 |
43 |
| del_nodec( rootnode ); // note this frees the pointer as well |
| 624 |
43 |
| free( parser ); |
| 625 |
|
| } |
| 626 |
43 |
| XSRETURN_EMPTY; |
| 627 |
|
| } |
| 628 |
|
| |
| 629 |
|
| #ifdef __cplusplus |
| 630 |
|
| extern "C" { |
| 631 |
|
| #endif |
| 632 |
|
| XS_EXTERNAL(boot_XML__Bare); /* prototype to pass -Wmissing-prototypes */ |
| 633 |
9 |
| XS_EXTERNAL(boot_XML__Bare) |
| 634 |
|
| { |
| 635 |
|
| #if PERL_VERSION_LE(5, 21, 5) |
| 636 |
|
| dVAR; dXSARGS; |
| 637 |
|
| #else |
| 638 |
9 |
| dVAR; dXSBOOTARGSXSAPIVERCHK; |
| 639 |
|
| #endif |
| 640 |
|
| #if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */ |
| 641 |
|
| char* file = __FILE__; |
| 642 |
|
| #else |
| 643 |
9 |
| const char* file = __FILE__; |
| 644 |
|
| #endif |
| 645 |
|
| |
| 646 |
|
| PERL_UNUSED_VAR(file); |
| 647 |
|
| |
| 648 |
|
| PERL_UNUSED_VAR(cv); /* -W */ |
| 649 |
|
| PERL_UNUSED_VAR(items); /* -W */ |
| 650 |
|
| #if PERL_VERSION_LE(5, 21, 5) |
| 651 |
|
| XS_VERSION_BOOTCHECK; |
| 652 |
|
| # ifdef XS_APIVERSION_BOOTCHECK |
| 653 |
|
| XS_APIVERSION_BOOTCHECK; |
| 654 |
|
| # endif |
| 655 |
|
| #endif |
| 656 |
|
| |
| 657 |
9 |
| newXS_deffile("XML::Bare::xml2obj", XS_XML__Bare_xml2obj); |
| 658 |
9 |
| newXS_deffile("XML::Bare::xml2obj_simple", XS_XML__Bare_xml2obj_simple); |
| 659 |
9 |
| newXS_deffile("XML::Bare::c_parse_more", XS_XML__Bare_c_parse_more); |
| 660 |
9 |
| newXS_deffile("XML::Bare::c_parse", XS_XML__Bare_c_parse); |
| 661 |
9 |
| newXS_deffile("XML::Bare::c_parse_unsafely", XS_XML__Bare_c_parse_unsafely); |
| 662 |
9 |
| newXS_deffile("XML::Bare::c_parsefile", XS_XML__Bare_c_parsefile); |
| 663 |
9 |
| newXS_deffile("XML::Bare::free_tree_c", XS_XML__Bare_free_tree_c); |
| 664 |
|
| #if PERL_VERSION_LE(5, 21, 5) |
| 665 |
|
| # if PERL_VERSION_GE(5, 9, 0) |
| 666 |
|
| if (PL_unitcheckav) |
| 667 |
|
| call_list(PL_scopestack_ix, PL_unitcheckav); |
| 668 |
|
| # endif |
| 669 |
|
| XSRETURN_YES; |
| 670 |
|
| #else |
| 671 |
9 |
| Perl_xs_boot_epilog(aTHX_ ax); |
| 672 |
|
| #endif |
| 673 |
9 |
| } |
| 674 |
|
| |
| 675 |
|
| #ifdef __cplusplus |
| 676 |
|
| } |
| 677 |
|
| #endif |