1 #include <stdio.h>
2 #include <stdarg.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "compile.h"
7 #include "actiontypes.h"
8 #include "libming.h"
9
10 #define print(x) {fputs(x,stdout);}
11
12 static char *buffer;
13 static int bufferLen;
14
15 #define BUFFER_INC 1024
16
17 void printDoAction(Buffer f, int length);
18
19 #include "../blocks/error.h"
20
21 void (*SWF_error)(const char *msg, ...);
22 void (*SWF_warn)(const char *msg, ...);
23
24 static int SWF_versionNumber = 5;
25
print_error(const char * msg,...)26 void print_error(const char *msg, ...)
27 {
28 va_list args;
29
30 va_start(args, msg);
31 vprintf(msg, args);
32 va_end(args);
33 exit(0);
34 }
35
print_warn(const char * msg,...)36 void print_warn(const char *msg, ...)
37 {
38 va_list args;
39
40 va_start(args, msg);
41 vprintf(msg, args);
42 va_end(args);
43 }
44
main(int argc,char * argv[])45 int main(int argc, char *argv[])
46 {
47 FILE *f;
48 Buffer b;
49 int size = 0;
50
51 SWF_error = print_error;
52 SWF_warn = print_warn;
53
54 buffer = (char *)malloc(BUFFER_INC);
55 bufferLen = 0;
56
57 while (argc > 1) {
58 if (strcmp(argv[1], "--4") == 0) {
59 SWF_versionNumber = 4;
60 argc--;
61 argv++;
62 } else
63 if (strcmp(argv[1], "--5") == 0) {
64 SWF_versionNumber = 5;
65 argc--;
66 argv++;
67 } else
68 if (strcmp(argv[1], "--6") == 0) {
69 SWF_versionNumber = 6;
70 argc--;
71 argv++;
72 } else
73 break;
74 }
75
76 if(argc > 1)
77 {
78 f = fopen(argv[1], "r");
79
80 if(f == NULL)
81 {
82 printf("Couldn't open input file %s\n", argv[1]);
83 exit(-1);
84 }
85 }
86 else
87 f = stdin;
88
89 while((size = fread(buffer+bufferLen, 1, BUFFER_INC, f)) == BUFFER_INC)
90 {
91 buffer = (char *)realloc(buffer, bufferLen+2*BUFFER_INC);
92 bufferLen += BUFFER_INC;
93 }
94
95 bufferLen += size;
96
97 // swf5compiler may understand different code
98 if (SWF_versionNumber == 4) {
99 printf("======================\n");
100 printf("Using Flash 4 compiler\n");
101 printf("======================\n");
102 swf4ParseInit(buffer, 1, SWF_versionNumber);
103 swf4parse((void *)&b);
104 } else {
105 printf("======================\n");
106 printf("Using Flash 5 compiler\n");
107 printf("======================\n");
108 swf5ParseInit(buffer, 1, SWF_versionNumber);
109 swf5parse((void *)&b);
110 }
111
112 if(b == NULL)
113 {
114 printf("\nOutput buffer empty\n");
115 exit(1);
116 }
117
118 bufferWriteU8(b, SWFACTION_END);
119
120 putchar('\n');
121 putchar('\n');
122
123 printDoAction(b, bufferLength(b));
124
125 putchar('\n');
126
127 exit(0);
128 }
129