swfmill 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/.document +5 -0
  2. data/.gitignore +23 -0
  3. data/.swfmill +240 -0
  4. data/LICENSE +340 -0
  5. data/README.rdoc +37 -0
  6. data/Rakefile +59 -0
  7. data/VERSION +1 -0
  8. data/ext/.gitignore +5 -0
  9. data/ext/extconf.rb +86 -0
  10. data/ext/swfmill/.gitignore +27 -0
  11. data/ext/swfmill/AUTHORS +9 -0
  12. data/ext/swfmill/COPYING +340 -0
  13. data/ext/swfmill/Makefile.am +14 -0
  14. data/ext/swfmill/Makefile.in +635 -0
  15. data/ext/swfmill/NEWS +189 -0
  16. data/ext/swfmill/README +170 -0
  17. data/ext/swfmill/TODO +33 -0
  18. data/ext/swfmill/aclocal.m4 +7712 -0
  19. data/ext/swfmill/autogen.sh +7 -0
  20. data/ext/swfmill/compile +142 -0
  21. data/ext/swfmill/config.guess +1516 -0
  22. data/ext/swfmill/config.sub +1626 -0
  23. data/ext/swfmill/configure +21868 -0
  24. data/ext/swfmill/configure.ac +55 -0
  25. data/ext/swfmill/depcomp +589 -0
  26. data/ext/swfmill/install-sh +519 -0
  27. data/ext/swfmill/ltmain.sh +6964 -0
  28. data/ext/swfmill/missing +367 -0
  29. data/ext/swfmill/src/Geom.cpp +107 -0
  30. data/ext/swfmill/src/Geom.h +100 -0
  31. data/ext/swfmill/src/Makefile.am +86 -0
  32. data/ext/swfmill/src/Makefile.in +1025 -0
  33. data/ext/swfmill/src/SWF.h +11941 -0
  34. data/ext/swfmill/src/SWFAction.cpp +41 -0
  35. data/ext/swfmill/src/SWFAction.h +19 -0
  36. data/ext/swfmill/src/SWFBasic.h +7 -0
  37. data/ext/swfmill/src/SWFFile.cpp +406 -0
  38. data/ext/swfmill/src/SWFFile.h +34 -0
  39. data/ext/swfmill/src/SWFFilter.cpp +25 -0
  40. data/ext/swfmill/src/SWFFilter.h +15 -0
  41. data/ext/swfmill/src/SWFGlyphList.cpp +262 -0
  42. data/ext/swfmill/src/SWFGlyphList.h +34 -0
  43. data/ext/swfmill/src/SWFIdItem.h +85 -0
  44. data/ext/swfmill/src/SWFIdItems.h +16 -0
  45. data/ext/swfmill/src/SWFItem.cpp +235 -0
  46. data/ext/swfmill/src/SWFItem.h +60 -0
  47. data/ext/swfmill/src/SWFList.h +179 -0
  48. data/ext/swfmill/src/SWFReader.cpp +352 -0
  49. data/ext/swfmill/src/SWFReader.h +73 -0
  50. data/ext/swfmill/src/SWFShapeItem.cpp +220 -0
  51. data/ext/swfmill/src/SWFShapeItem.h +45 -0
  52. data/ext/swfmill/src/SWFShapeMaker.cpp +401 -0
  53. data/ext/swfmill/src/SWFShapeMaker.h +128 -0
  54. data/ext/swfmill/src/SWFTag.cpp +49 -0
  55. data/ext/swfmill/src/SWFTag.h +20 -0
  56. data/ext/swfmill/src/SWFTrait.cpp +35 -0
  57. data/ext/swfmill/src/SWFTrait.h +22 -0
  58. data/ext/swfmill/src/SWFWriter.cpp +312 -0
  59. data/ext/swfmill/src/SWFWriter.h +84 -0
  60. data/ext/swfmill/src/base64.c +110 -0
  61. data/ext/swfmill/src/base64.h +15 -0
  62. data/ext/swfmill/src/codegen/Makefile.am +15 -0
  63. data/ext/swfmill/src/codegen/Makefile.in +346 -0
  64. data/ext/swfmill/src/codegen/basic.xsl +45 -0
  65. data/ext/swfmill/src/codegen/basics.xsl +235 -0
  66. data/ext/swfmill/src/codegen/dumper.xsl +109 -0
  67. data/ext/swfmill/src/codegen/header.xsl +131 -0
  68. data/ext/swfmill/src/codegen/mk.xsl +26 -0
  69. data/ext/swfmill/src/codegen/parser.xsl +196 -0
  70. data/ext/swfmill/src/codegen/parsexml.xsl +312 -0
  71. data/ext/swfmill/src/codegen/size.xsl +189 -0
  72. data/ext/swfmill/src/codegen/source.xml +2197 -0
  73. data/ext/swfmill/src/codegen/writer.xsl +190 -0
  74. data/ext/swfmill/src/codegen/writexml.xsl +138 -0
  75. data/ext/swfmill/src/swfmill.cpp +482 -0
  76. data/ext/swfmill/src/swft/Makefile.am +55 -0
  77. data/ext/swfmill/src/swft/Makefile.in +717 -0
  78. data/ext/swfmill/src/swft/Parser.cpp +76 -0
  79. data/ext/swfmill/src/swft/Parser.h +37 -0
  80. data/ext/swfmill/src/swft/SVGAttributeParser.cpp +78 -0
  81. data/ext/swfmill/src/swft/SVGAttributeParser.h +35 -0
  82. data/ext/swfmill/src/swft/SVGColor.cpp +116 -0
  83. data/ext/swfmill/src/swft/SVGColor.h +37 -0
  84. data/ext/swfmill/src/swft/SVGColors.h +167 -0
  85. data/ext/swfmill/src/swft/SVGGradient.cpp +258 -0
  86. data/ext/swfmill/src/swft/SVGGradient.h +81 -0
  87. data/ext/swfmill/src/swft/SVGPathParser.cpp +155 -0
  88. data/ext/swfmill/src/swft/SVGPathParser.h +126 -0
  89. data/ext/swfmill/src/swft/SVGPointsParser.cpp +51 -0
  90. data/ext/swfmill/src/swft/SVGPointsParser.h +25 -0
  91. data/ext/swfmill/src/swft/SVGStyle.cpp +181 -0
  92. data/ext/swfmill/src/swft/SVGStyle.h +80 -0
  93. data/ext/swfmill/src/swft/SVGTransformParser.cpp +72 -0
  94. data/ext/swfmill/src/swft/SVGTransformParser.h +32 -0
  95. data/ext/swfmill/src/swft/readpng.c +305 -0
  96. data/ext/swfmill/src/swft/readpng.h +92 -0
  97. data/ext/swfmill/src/swft/swft.cpp +251 -0
  98. data/ext/swfmill/src/swft/swft.h +64 -0
  99. data/ext/swfmill/src/swft/swft_document.cpp +57 -0
  100. data/ext/swfmill/src/swft/swft_import.cpp +38 -0
  101. data/ext/swfmill/src/swft/swft_import_binary.cpp +82 -0
  102. data/ext/swfmill/src/swft/swft_import_jpeg.cpp +255 -0
  103. data/ext/swfmill/src/swft/swft_import_mp3.cpp +268 -0
  104. data/ext/swfmill/src/swft/swft_import_png.cpp +231 -0
  105. data/ext/swfmill/src/swft/swft_import_ttf.cpp +519 -0
  106. data/ext/swfmill/src/swft/swft_import_wav.cpp +255 -0
  107. data/ext/swfmill/src/swft/swft_path.cpp +178 -0
  108. data/ext/swfmill/src/xslt/Makefile.am +51 -0
  109. data/ext/swfmill/src/xslt/Makefile.in +536 -0
  110. data/ext/swfmill/src/xslt/README +19 -0
  111. data/ext/swfmill/src/xslt/assemble.xsl +38 -0
  112. data/ext/swfmill/src/xslt/simple-deprecated.xslt +62 -0
  113. data/ext/swfmill/src/xslt/simple-elements.xslt +627 -0
  114. data/ext/swfmill/src/xslt/simple-import.xslt +565 -0
  115. data/ext/swfmill/src/xslt/simple-svg.xslt +383 -0
  116. data/ext/swfmill/src/xslt/simple-tools.xslt +255 -0
  117. data/ext/swfmill/src/xslt/simple.cpp +1686 -0
  118. data/ext/swfmill/src/xslt/simple.xml +7 -0
  119. data/ext/swfmill/src/xslt/xslt.h +7 -0
  120. data/ext/swfmill/test/Makefile.am +1 -0
  121. data/ext/swfmill/test/Makefile.in +490 -0
  122. data/ext/swfmill/test/xml/Makefile.am +20 -0
  123. data/ext/swfmill/test/xml/Makefile.in +353 -0
  124. data/ext/swfmill/test/xml/test-xml +21 -0
  125. data/ext/swfmill_ext.cc +375 -0
  126. data/lib/swfmill.rb +30 -0
  127. data/spec/data/swfmill-banner1.swf +0 -0
  128. data/spec/spec.opts +1 -0
  129. data/spec/spec_helper.rb +14 -0
  130. data/spec/swfmill_spec.rb +125 -0
  131. metadata +206 -0
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
3
+
4
+ <xsl:include href="basic.xsl"/>
5
+ <xsl:include href="basics.xsl"/>
6
+ <xsl:include href="header.xsl"/>
7
+ <xsl:include href="parser.xsl"/>
8
+ <xsl:include href="dumper.xsl"/>
9
+ <xsl:include href="size.xsl"/>
10
+ <xsl:include href="writer.xsl"/>
11
+ <xsl:include href="writexml.xsl"/>
12
+ <xsl:include href="parsexml.xsl"/>
13
+ <xsl:strip-space elements="*"/>
14
+
15
+ <xsl:template match="format">
16
+ <xsl:call-template name="basics"/>
17
+ <xsl:call-template name="header"/>
18
+ <xsl:call-template name="parser"/>
19
+ <xsl:call-template name="dumper"/>
20
+ <xsl:call-template name="size"/>
21
+ <xsl:call-template name="writer"/>
22
+ <xsl:call-template name="writexml"/>
23
+ <xsl:call-template name="parsexml"/>
24
+ </xsl:template>
25
+
26
+ </xsl:stylesheet>
@@ -0,0 +1,196 @@
1
+ <?xml version="1.0"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
3
+ <xsl:template name="parser">
4
+ <xsl:document href="g{/format/@format}Parser.cpp" method="text">
5
+
6
+ #include "<xsl:value-of select="/format/@format"/>.h"
7
+ #include "<xsl:value-of select="/format/@format"/>Item.h"
8
+ #include "<xsl:value-of select="/format/@format"/>List.h"
9
+
10
+ namespace <xsl:value-of select="/format/@format"/> {
11
+
12
+ <xsl:for-each select="type|tag|action|filter|style|stackitem|namespaceconstant|multinameconstant|trait|opcode">
13
+ //////////////////////////////////// <xsl:value-of select="@name"/>
14
+
15
+ bool <xsl:value-of select="@name"/>::parse( Reader *r, int end, Context *ctx ) {
16
+ if( ctx->debugTrace ) fprintf( stderr, "PARSE <xsl:value-of select="@name"/> @%i-%i :%i\n", r->getPosition(), r->getBits(), end );
17
+ file_offset = r->getPosition();
18
+
19
+ <xsl:apply-templates mode="parse"/>
20
+
21
+ <xsl:if test="name()='tag'">
22
+ if( r->getPosition() != file_offset + len ) {
23
+ fprintf( stderr, "WARNING: end of tag <xsl:value-of select="@name"/> is @%i, should be @%i\n", r->getPosition(), file_offset+len );
24
+ r->seekTo( file_offset + len );
25
+ }
26
+ </xsl:if>
27
+
28
+ return r->getError() == SWFR_OK;
29
+ }
30
+
31
+ </xsl:for-each>
32
+
33
+ }
34
+
35
+ </xsl:document>
36
+ </xsl:template>
37
+
38
+
39
+ <xsl:template match="flagged" mode="parse">
40
+ if( <xsl:if test="@negative">!</xsl:if><xsl:value-of select="@flag"/>
41
+ <xsl:if test="@signifier"> &amp; <xsl:value-of select="@signifier"/></xsl:if> ) {
42
+
43
+ <xsl:apply-templates mode="parse"/>
44
+ } else {
45
+ <xsl:for-each select="*[@default]">
46
+ <xsl:value-of select="@name"/> = <xsl:value-of select="@default"/>;
47
+ </xsl:for-each>
48
+ }
49
+ </xsl:template>
50
+
51
+ <xsl:template match="if" mode="parse">
52
+ if( ctx->debugTrace ) fprintf( stderr, "PARSE IF <xsl:value-of select="@expression"/> - " );
53
+ if( <xsl:value-of select="@expression"/> ) {
54
+ if( ctx->debugTrace ) fprintf( stderr, "TRUE\n" );
55
+ <xsl:apply-templates mode="parse"/>
56
+ } else {
57
+ if( ctx->debugTrace ) fprintf( stderr, "FALSE\n" );
58
+ <xsl:for-each select="*[@default]">
59
+ <xsl:value-of select="@name"/> = <xsl:value-of select="@default"/>;
60
+ </xsl:for-each>
61
+ }
62
+ </xsl:template>
63
+
64
+ <xsl:template match="byte|word|fixedpoint|fixedpoint2|bit|integer|string|uint32|float|double|double2|half|xml|u30|s24|encodedu32" mode="parse">
65
+ <xsl:value-of select="@name"/> = <xsl:apply-templates select="." mode="get"/>;
66
+ if( ctx->debugTrace ) fprintf( stderr, "PARSE <xsl:value-of select="@name"/>: <xsl:apply-templates select="." mode="printf"/>\n", <xsl:value-of select="@name"/> );
67
+ <xsl:if test="@context">
68
+ ctx-&gt;<xsl:value-of select="@name"/> = <xsl:value-of select="@name"/>;
69
+ </xsl:if>
70
+ <xsl:if test="@next">
71
+ <!-- this describes the offset to end of this object, so we use it for end -->
72
+ if( <xsl:value-of select="@name"/> &amp;&amp; <xsl:value-of select="@name"/>+r->getPosition() &lt; end ) {
73
+ if( ctx->debugTrace ) fprintf(stderr, "- has next offset, setting end to current+%i\n", <xsl:value-of select="@name"/> );
74
+ end = r->getPosition() + <xsl:value-of select="@name"/>
75
+ <xsl:if test="@next-offset"> + (<xsl:value-of select="@next-offset"/>)</xsl:if>;
76
+ }
77
+ </xsl:if>
78
+ </xsl:template>
79
+ <xsl:template match="byte" mode="get">r->getByte()</xsl:template>
80
+ <xsl:template match="word" mode="get">r->getWord()</xsl:template>
81
+ <xsl:template match="fixedpoint" mode="get">r->getNBitFixed(<xsl:value-of select="@size"/>,<xsl:value-of select="@exp"/><xsl:if test="@signed">,true</xsl:if>)</xsl:template>
82
+ <xsl:template match="fixedpoint2" mode="get">r->getNBitFixed2(<xsl:value-of select="@size"/>,<xsl:value-of select="@exp"/><xsl:if test="@signed">,true</xsl:if>)</xsl:template>
83
+ <xsl:template match="uint32" mode="get">r->getInt()</xsl:template>
84
+ <xsl:template match="float" mode="get">r->getFloat()</xsl:template>
85
+ <xsl:template match="double" mode="get">r->getDouble()</xsl:template>
86
+ <xsl:template match="double2" mode="get">r->getDouble2()</xsl:template>
87
+ <xsl:template match="half" mode="get">r->getHalf()</xsl:template>
88
+ <xsl:template match="bit" mode="get">r->getNBitInt(1)</xsl:template>
89
+ <xsl:template match="integer" mode="get">r->getNBitInt(<xsl:value-of select="@size"/>
90
+ <xsl:if test="@size-add">+<xsl:value-of select="@size-add"/></xsl:if>
91
+ <xsl:if test="@signed">,true</xsl:if>)</xsl:template>
92
+ <xsl:template match="u30" mode="get">r->getU30()</xsl:template>
93
+ <xsl:template match="s24" mode="get">r->getS24()</xsl:template>
94
+ <xsl:template match="encodedu32" mode="get">r->getEncodedU32()</xsl:template>
95
+ <xsl:template match="string[@mode='pascal']" mode="get">r->getPString()</xsl:template>
96
+ <xsl:template match="string[@mode='pascalU30']" mode="get">r->getPStringU30()</xsl:template>
97
+ <xsl:template match="string" mode="get" priority="-1">r->getString()</xsl:template>
98
+ <xsl:template match="xml" mode="get" priority="-1">r->getString()</xsl:template>
99
+
100
+ <xsl:template match="byteOrWord" mode="parse">
101
+ <xsl:value-of select="@name"/> = r->getByte();
102
+ if( <xsl:value-of select="@name"/> == 0xff &amp;&amp; ctx->tagVersion >= 2 ) {
103
+ <xsl:value-of select="@name"/> = r->getWord();
104
+ }
105
+
106
+ if( ctx->debugTrace ) fprintf( stderr, "PARSE <xsl:value-of select="@name"/>: <xsl:apply-templates select="." mode="printf"/>\n", <xsl:value-of select="@name"/> );
107
+ <xsl:if test="@context">
108
+ ctx-&gt;<xsl:value-of select="@name"/> = <xsl:value-of select="@name"/>;
109
+ </xsl:if>
110
+ <xsl:if test="@next">
111
+ <!-- this describes the offset to end of this object, so we use it for end -->
112
+ if( <xsl:value-of select="@name"/> &amp;&amp; <xsl:value-of select="@name"/>+r->getPosition() &lt; end ) {
113
+ if( ctx->debugTrace ) fprintf(stderr, "- has next offset, setting end to current+%i\n", <xsl:value-of select="@name"/> );
114
+ end = r->getPosition() + <xsl:value-of select="@name"/>
115
+ <xsl:if test="@next-offset"> + (<xsl:value-of select="@next-offset"/>)</xsl:if>;
116
+ }
117
+ </xsl:if>
118
+ </xsl:template>
119
+
120
+ <xsl:template match="object" mode="parse">
121
+ <xsl:value-of select="@name"/>.parse(r,end,ctx);
122
+ </xsl:template>
123
+
124
+ <xsl:template match="list[@length]" mode="parse" priority="1">
125
+ <xsl:variable name="length">
126
+ <xsl:choose>
127
+ <xsl:when test="@length-add">
128
+ ( <xsl:value-of select="@length"/> + <xsl:value-of select="@length-add"/> )
129
+ </xsl:when>
130
+ <xsl:when test="@length-sub">
131
+ ( <xsl:value-of select="@length"/> &lt; <xsl:value-of select="@length-sub"/>
132
+ ? 0
133
+ : <xsl:value-of select="@length"/> - <xsl:value-of select="@length-sub"/> )
134
+ </xsl:when>
135
+ <xsl:otherwise>
136
+ <xsl:value-of select="@length"/>
137
+ </xsl:otherwise>
138
+ </xsl:choose>
139
+ </xsl:variable>
140
+
141
+ {
142
+ if( ctx->debugTrace ) fprintf( stderr, "PARSE list&lt;<xsl:value-of select="@type"/>&gt; <xsl:value-of select="@name"/>: %i items, @%i-%i :%i\n", <xsl:value-of select="$length"/>, r->getPosition(), r->getBits(), end );
143
+ <xsl:value-of select="@type"/> *item;
144
+ for( int i=0; i&lt;<xsl:value-of select="$length"/>; i++ ) {
145
+ item = <xsl:value-of select="@type"/>::get(r,end,ctx);
146
+ <xsl:value-of select="@name"/>.append( item );
147
+ }
148
+ }
149
+ </xsl:template>
150
+
151
+ <xsl:template match="list" mode="parse" priority="-1">
152
+ {
153
+ if( ctx->debugTrace ) fprintf( stderr, "PARSE list&lt;<xsl:value-of select="@type"/>&gt; <xsl:value-of select="@name"/> @%i-%i :%i\n", r->getPosition(), r->getBits(), end );
154
+ int myend = end;
155
+ <xsl:if test="@end">
156
+ myend = r->getPosition() + <xsl:value-of select="@end"/>
157
+ <xsl:if test="@end-offset"> + (<xsl:value-of select="@end-offset"/>)</xsl:if>;
158
+ </xsl:if>
159
+
160
+ if( r->getPosition() &lt; myend ) {
161
+ <xsl:value-of select="@type"/> *item;
162
+ item = <xsl:value-of select="@type"/>::get(r,end,ctx);
163
+ while( item &amp;&amp; r->getPosition() &lt;= myend ) {
164
+ <xsl:value-of select="@name"/>.append( item );
165
+ if( r->getPosition() &lt; myend || (r->getPosition()==myend &amp;&amp; r->getBits() ))
166
+ item = <xsl:value-of select="@type"/>::get(r,myend,ctx);
167
+ else item = NULL;
168
+ <xsl:if test="@end-condition">
169
+ if(item &amp;&amp; <xsl:value-of select="@end-condition"/>) {
170
+ <xsl:value-of select="@name"/>.append( item );
171
+ item = NULL;
172
+ }
173
+ </xsl:if>
174
+ }
175
+ }
176
+ }
177
+ </xsl:template>
178
+
179
+ <xsl:template match="data" mode="parse">
180
+ {
181
+ int sz = <xsl:value-of select="@size"/>;
182
+
183
+ <xsl:value-of select="@name"/> = new unsigned char[ sz ];
184
+ r->getData( <xsl:value-of select="@name"/>, sz );
185
+ }
186
+ </xsl:template>
187
+
188
+ <xsl:template match="fill-byte" mode="parse">
189
+ r->byteAlign();
190
+ </xsl:template>
191
+
192
+ <xsl:template match="context" mode="parse">
193
+ ctx-><xsl:value-of select="@param"/> = <xsl:value-of select="@value"/>;
194
+ </xsl:template>
195
+
196
+ </xsl:stylesheet>
@@ -0,0 +1,312 @@
1
+ <?xml version="1.0"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
3
+ <xsl:template name="parsexml">
4
+ <xsl:document href="g{/format/@format}ParseXML.cpp" method="text">
5
+
6
+ #include "<xsl:value-of select="/format/@format"/>.h"
7
+ #include &lt;cstring&gt;
8
+ #include &lt;cctype&gt;
9
+ #include &lt;cstdlib&gt;
10
+ #include "base64.h"
11
+
12
+ using namespace std;
13
+
14
+ namespace <xsl:value-of select="/format/@format"/> {
15
+
16
+ char *strdupx(const char *src) {
17
+ char *t = new char[strlen(src)+1];
18
+ strcpy(t, src);
19
+ return t;
20
+ }
21
+
22
+ <xsl:for-each select="type|tag|action|filter|style|stackitem|namespaceconstant|multinameconstant|trait|opcode">
23
+ void <xsl:value-of select="@name"/>::parseXML( xmlNodePtr node, Context *ctx ) {
24
+ xmlNodePtr node2;
25
+ xmlChar *tmp;
26
+
27
+ // printf("<xsl:value-of select="@name"/>::parseXML\n");
28
+
29
+ <xsl:for-each select="*[@context]">
30
+ ctx-&gt;<xsl:value-of select="@name"/> = <xsl:apply-templates select="." mode="default"/>;
31
+ </xsl:for-each>
32
+
33
+ <xsl:apply-templates select="*[@prop]|flagged|if|context" mode="parsexml"/>
34
+
35
+ <xsl:if test="@name='UnknownTag' or @name='UnknownAction'">
36
+ tmp = xmlGetProp( node, (const xmlChar *)"id" );
37
+ if( tmp ) {
38
+ sscanf( (char *)tmp, "%X", &amp;type );
39
+ xmlFree( (xmlChar *)tmp );
40
+ }
41
+ </xsl:if>
42
+
43
+ <xsl:for-each select="*[@context]">
44
+ <xsl:choose>
45
+ <xsl:when test="@context='inverse'">
46
+ ctx-><xsl:value-of select="@name"/> = <xsl:value-of select="@name"/>;
47
+ </xsl:when>
48
+ <xsl:when test="@set-from-bits-needed">
49
+ <xsl:value-of select="@name"/> = SWFBitsNeeded( <xsl:value-of select="@set-from-bits-needed"/> );
50
+ if( <xsl:value-of select="@name"/> > ctx-><xsl:value-of select="@name"/> ) ctx-><xsl:value-of select="@name"/> = <xsl:value-of select="@name"/>;
51
+ </xsl:when>
52
+ <xsl:otherwise>
53
+ <xsl:value-of select="@name"/> = ctx-><xsl:value-of select="@name"/>;
54
+ </xsl:otherwise>
55
+ </xsl:choose>
56
+ </xsl:for-each>
57
+ }
58
+ </xsl:for-each>
59
+
60
+ }
61
+
62
+ </xsl:document>
63
+ </xsl:template>
64
+
65
+
66
+ <xsl:template match="byte|word|byteOrWord|fixedpoint|fixedpoint2|bit|integer|string|uint32|float|double|double2|half|u30|s24|encodedu32" mode="has">
67
+ if( <xsl:if test="../@negative">!</xsl:if>xmlHasProp( node, (const xmlChar *)"<xsl:value-of select="@name"/>" ) ) has = true;
68
+ </xsl:template>
69
+
70
+ <xsl:template match="object|list|data|xml" mode="has">
71
+ {
72
+ xmlNodePtr child = node->children;
73
+ while( child &amp;&amp; !has ) {
74
+ if( !strcmp( (const char *)child->name, "<xsl:value-of select="@name"/>" ) ) has = true;
75
+ child = child->next;
76
+ }
77
+ }
78
+ </xsl:template>
79
+
80
+
81
+ <xsl:template match="flagged" mode="parsexml">
82
+ {
83
+ bool has = false;
84
+ <xsl:for-each select="*[@prop]|flagged|if">
85
+ <xsl:apply-templates select="." mode="has"/>
86
+ <xsl:choose>
87
+ <xsl:when test="../@signifier">
88
+ if( has ) <xsl:value-of select="../@flag"/> |= <xsl:value-of select="$signifier"/>;
89
+ else <xsl:value-of select="../@flag"/> ^= <xsl:value-of select="$signifier"/>;
90
+ </xsl:when>
91
+ <xsl:otherwise>
92
+ if( has ) <xsl:value-of select="../@flag"/> = <xsl:if test="../@negative">!</xsl:if>true;
93
+ </xsl:otherwise>
94
+ </xsl:choose>
95
+ </xsl:for-each>
96
+
97
+ if( has ) {
98
+ <xsl:apply-templates select="*[@prop]|flagged|if" mode="parsexml"/>
99
+ }
100
+
101
+ <xsl:for-each select="*[@context]">
102
+ <xsl:value-of select="@name"/> = ctx-><xsl:value-of select="@name"/>;
103
+ </xsl:for-each>
104
+ }
105
+ </xsl:template>
106
+
107
+ <xsl:template match="if" mode="parsexml">
108
+ if( <xsl:value-of select="@expression"/> ) {
109
+ <xsl:apply-templates select="*[@prop]|flagged|if" mode="parsexml"/>
110
+ }
111
+ </xsl:template>
112
+
113
+
114
+ <xsl:template match="byte|word|byteOrWord|bit|uint32|u30|s24" mode="parsexml">
115
+ tmp = xmlGetProp( node, (const xmlChar *)"<xsl:value-of select="@name"/>" );
116
+ if( tmp ) {
117
+ int tmp_int;
118
+ sscanf( (char *)tmp, "<xsl:apply-templates select="." mode="printf"/>", &amp;tmp_int );
119
+ <xsl:value-of select="@name"/> = tmp_int;
120
+ xmlFree( tmp );
121
+ }
122
+ </xsl:template>
123
+
124
+ <xsl:template match="float|double|double2|half" mode="parsexml">
125
+ tmp = xmlGetProp( node, (const xmlChar *)"<xsl:value-of select="@name"/>" );
126
+ if( tmp ) {
127
+ double tmp_float;
128
+ sscanf( (char *)tmp, "%lg", &amp;tmp_float );
129
+ <xsl:value-of select="@name"/> = tmp_float;
130
+ xmlFree( tmp );
131
+ }
132
+ </xsl:template>
133
+
134
+ <xsl:template match="fixedpoint|fixedpoint2" mode="parsexml">
135
+ tmp = xmlGetProp( node, (const xmlChar *)"<xsl:value-of select="@name"/>" );
136
+ if( tmp ) {
137
+ double t;
138
+ sscanf( (char *)tmp, "%lg", &amp;t);
139
+ <xsl:value-of select="@name"/> = t;
140
+ xmlFree( tmp );
141
+ <xsl:choose>
142
+ <!-- should this be done in writer.xsl? -->
143
+ <xsl:when test="@constant-size"/>
144
+ <xsl:otherwise>
145
+ int b = SWFBitsNeeded( (long)(<xsl:value-of select="@name"/>*(1&lt;&lt; <xsl:value-of select="@exp"/>))<xsl:if test="@signed">, true</xsl:if> );
146
+ <xsl:if test="@size-add">b -= <xsl:value-of select="@size-add"/>;</xsl:if>
147
+ if( b > <xsl:value-of select="@size"/> ) <xsl:value-of select="@size"/> = b;
148
+ </xsl:otherwise>
149
+ </xsl:choose>
150
+ } else {
151
+ fprintf(stderr,"WARNING: no <xsl:value-of select="@name"/> property in %s element\n", (const char *)node->name );
152
+ }
153
+ </xsl:template>
154
+
155
+ <xsl:template match="integer" mode="parsexml">
156
+ tmp = xmlGetProp( node, (const xmlChar *)"<xsl:value-of select="@name"/>" );
157
+ if( tmp ) {
158
+ sscanf( (char *)tmp, "<xsl:apply-templates select="." mode="printf"/>", &amp;<xsl:value-of select="@name"/>);
159
+ xmlFree( tmp );
160
+ <xsl:choose>
161
+ <!-- should this be done in writer.xsl? -->
162
+ <xsl:when test="@constant-size"/>
163
+ <xsl:otherwise>
164
+ int b = SWFBitsNeeded( <xsl:value-of select="@name"/><xsl:if test="@signed">, true</xsl:if> );
165
+ <xsl:if test="@size-add">b -= <xsl:value-of select="@size-add"/>;</xsl:if>
166
+ if( b > <xsl:value-of select="@size"/> ) <xsl:value-of select="@size"/> = b;
167
+ </xsl:otherwise>
168
+ </xsl:choose>
169
+ } else {
170
+ fprintf(stderr,"WARNING: no <xsl:value-of select="@name"/> property in %s element\n", (const char *)node->name );
171
+ }
172
+ </xsl:template>
173
+
174
+ <xsl:template match="string" mode="parsexml">
175
+ tmp = xmlGetProp( node, (const xmlChar *)"<xsl:value-of select="@name"/>" );
176
+ if( tmp ) {
177
+ <xsl:value-of select="@name"/> = strdupx((const char *)tmp);
178
+ xmlFree(tmp);
179
+ } else {
180
+ fprintf(stderr,"WARNING: no <xsl:value-of select="@name"/> property in %s element\n", (const char *)node->name );
181
+ <xsl:value-of select="@name"/> = strdupx("[undefined]");
182
+ }
183
+ </xsl:template>
184
+
185
+ <xsl:template match="object" mode="parsexml">
186
+ node2 = node->children;
187
+ while( node2 ) {
188
+ if( !strcmp( (const char *)node2->name, "<xsl:value-of select="@name"/>" ) ) {
189
+ <!--
190
+ <xsl:value-of select="@name"/>.parseXML( node2, ctx );
191
+ node=NULL;
192
+ -->
193
+ xmlNodePtr child = node2->children;
194
+ while( child ) {
195
+ if( !xmlNodeIsText( child ) ) {
196
+ <xsl:value-of select="@name"/>.parseXML( child, ctx );
197
+ node2 = child = NULL;
198
+ node2 = NULL;
199
+ } else {
200
+ child = child->next;
201
+ }
202
+ }
203
+ }
204
+ if( node2 ) node2 = node2->next;
205
+ }
206
+ </xsl:template>
207
+
208
+ <xsl:template match="list" mode="parsexml">
209
+ node2 = node->children;
210
+ while( node2 ) {
211
+ if( !strcmp( (const char *)node2->name, "<xsl:value-of select="@name"/>" ) ) {
212
+ <xsl:if test="@length and not(@constant-length)">
213
+ <xsl:value-of select="@length"/>=0;
214
+ </xsl:if>
215
+ <xsl:if test="@end">
216
+ size_t l = 0;
217
+ </xsl:if>
218
+
219
+ xmlNodePtr child = node2->children;
220
+ while( child ) {
221
+ if( !xmlNodeIsText( child ) ) {
222
+ <xsl:value-of select="@type"/>* item = <xsl:value-of select="@type"/>::getByName( (const char *)child->name );
223
+ if( item ) {
224
+ item->parseXML( child, ctx );
225
+ <xsl:value-of select="@name"/>.append( item );
226
+ <xsl:if test="@length and not(@constant-length)">
227
+ <xsl:value-of select="@length"/>++;
228
+ </xsl:if>
229
+ <xsl:if test="@end">
230
+ l += item->getSize(ctx, l);
231
+ </xsl:if>
232
+ }
233
+ }
234
+ child = child->next;
235
+ }
236
+
237
+ <xsl:if test="@length and @length-add">
238
+ <xsl:value-of select="@length"/> -= <xsl:value-of select="@length-add"/>;
239
+ </xsl:if>
240
+ <xsl:if test="@length and @length-sub">
241
+ if( <xsl:value-of select="@length"/> > 0 ) {
242
+ <xsl:value-of select="@length"/> += <xsl:value-of select="@length-sub"/>;
243
+ }
244
+ </xsl:if>
245
+ <xsl:if test="@end">
246
+ <xsl:value-of select="@end"/> = (l/8)<xsl:if test="@end-offset"> - (<xsl:value-of select="@end-offset"/>)</xsl:if>;
247
+ </xsl:if>
248
+
249
+ node2=NULL;
250
+ } else {
251
+ node2 = node2->next;
252
+ }
253
+ }
254
+ </xsl:template>
255
+
256
+ <xsl:template match="data" mode="parsexml">
257
+ {
258
+ <xsl:value-of select="@name"/> = NULL;
259
+ <xsl:value-of select="@size"/> = 0;
260
+
261
+ xmlChar *xmld = xmlNodeGetContent( node );
262
+ char *d = (char *)xmld;
263
+ if( d ) {
264
+ // unsure if this is neccessary
265
+ for( int i=strlen(d)-1; i>0 &amp;&amp; isspace(d[i]); i-- ) d[i]=0;
266
+ while( isspace(d[0]) ) d++;
267
+ int l = strlen(d); //BASE64_GET_MAX_DECODED_LEN(strlen( d ));
268
+ char *dst = new char[ l ];
269
+ int lout = base64_decode( dst, (char*)d, l );
270
+ if( lout > 0 ) {
271
+ <xsl:value-of select="@size"/> = lout;
272
+ <xsl:value-of select="@name"/> = new unsigned char[ lout ];
273
+ memcpy( <xsl:value-of select="@name"/>, dst, lout );
274
+ }
275
+ delete dst;
276
+ xmlFree( xmld );
277
+ }
278
+ }
279
+ </xsl:template>
280
+
281
+ <xsl:template match="xml" mode="parsexml">
282
+ {
283
+ xmlNodePtr child = NULL;
284
+ xmlNodePtr currentChild = node->children;
285
+ while( currentChild &amp;&amp; child == NULL) {
286
+ if( ! strcmp( (const char *)currentChild->name, (const char *)"<xsl:value-of select="@name"/>" ) ) {
287
+ child = currentChild;
288
+ }
289
+
290
+ currentChild = currentChild->next;
291
+ }
292
+
293
+ <!-- FIXME: standardize string handling on xmlString. this should be deleted somewhere, and checked... -->
294
+ if (child == NULL) {
295
+ fprintf(stderr,"WARNING: no <xsl:value-of select="@name"/> child element in %s element\n", (const char *)node->name );
296
+ <xsl:value-of select="@name"/> = strdupx("[undefined]");
297
+ } else {
298
+ xmlDocPtr out = xmlNewDoc((const xmlChar*)"1.0");
299
+ out->xmlRootNode = xmlCopyNode( child, 1 );
300
+
301
+ char *data; int size;
302
+ xmlDocDumpFormatMemory( out, (xmlChar**)&amp;data, &amp;size, 1 );
303
+ <xsl:value-of select="@name"/> = data;
304
+ }
305
+ }
306
+ </xsl:template>
307
+
308
+ <xsl:template match="context" mode="parsexml">
309
+ ctx-><xsl:value-of select="@param"/> = <xsl:value-of select="@value"/>;
310
+ </xsl:template>
311
+
312
+ </xsl:stylesheet>