several small fixes
[swftools.git] / src / swfc.c
index e189cec..49897ef 100644 (file)
@@ -77,7 +77,7 @@ int args_callback_longoption(char*name,char*val)
 }
 void args_callback_usage(char*name)
 {
-    printf("Usage: %s [-o filename] file.wav\n", name);
+    printf("Usage: %s [-o filename] file.sc\n", name);
     printf("\t-v , --verbose\t\t\t Be more verbose\n");
     printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n");
     printf("\t-V , --version\t\t\t Print program version and exit\n");
@@ -121,7 +121,7 @@ static void warning(char*format, ...)
     va_end(arglist);
     printf("\"%s\", line %d column %d: warning- %s\n", filename, line, column, buf);
 }
-   
+
 static void readToken()
 {
     type = file[pos].type;
@@ -811,26 +811,16 @@ void dumpSWF(SWF*swf)
     
 void s_font(char*name, char*filename)
 {
-    int f;
-    SWF swf;
     SWFFONT* font;
-    f = open(filename,O_RDONLY|O_BINARY);
-    if (f<0) { 
-       warning("Couldn't open file \"%s\": %s", filename, strerror(errno));
+    font = swf_LoadFont(filename);
+   
+    if(font == 0) {
+       warning("Couldn't open font file \"%s\"", filename);
        font = (SWFFONT*)malloc(sizeof(SWFFONT));
        memset(font, 0, sizeof(SWFFONT));
        dictionary_put2(&fonts, name, font);
        return;
     }
-    font = 0;
-    if (swf_ReadSWF(f,&swf)>=0) { 
-       swf_FontExtract(&swf, 0x4e46, &font);
-       swf_FreeTags(&swf);
-    }
-    close(f);
-    if (font==0) { 
-       syntaxerror("File \"%s\" isn't a valid rfxswf font file", filename);
-    }
 
     if(0)
     {
@@ -924,13 +914,15 @@ GRADIENT parseGradient(const char*str)
     memset(&gradient, 0, sizeof(GRADIENT));
     while(*p) {
        char*posstr,*colorstr;
+       float pos;
+       RGBA color;
        posstr = gradient_getToken(&p);
        if(!*posstr)
            break;
-       float pos = parsePercent(posstr);
+       pos = parsePercent(posstr);
        if(!*p) syntaxerror("Error in shape data: Color expected after %s", posstr);
        colorstr = gradient_getToken(&p);
-       RGBA color = parseColor(colorstr);
+       color = parseColor(colorstr);
        if(gradient.num == sizeof(gradient.ratios)/sizeof(gradient.ratios[0])) {
            warning("gradient record too big- max size is 8, rest ignored");
            break;
@@ -957,6 +949,18 @@ void s_gradient(char*name, const char*text, int radial)
     dictionary_put2(&gradients, name, gradient);
 }
 
+void s_action(const char*text)
+{
+    ActionTAG* a = 0;
+    a = swf_ActionCompile(text, stack[0].swf->fileVersion);
+
+    tag = swf_InsertTag(tag, ST_DOACTION);
+
+    swf_ActionSet(tag, a);
+
+    swf_ActionFree(a);
+}
+
 void s_outline(char*name, char*format, char*source)
 {
     outline_t* outline;
@@ -1919,7 +1923,7 @@ static int c_primitive(map_t*args)
     int type=0;
     char* font;
     char* text;
-    char* outline;
+    char* outline=0;
     RGBA fill;
     if(!strcmp(command, "circle"))
        type = 1;
@@ -2038,7 +2042,16 @@ int fakechar(map_t*args)
 }
 
 static int c_egon(map_t*args) {return fakechar(args);}
-static int c_button(map_t*args) {return fakechar(args);}
+static int c_button(map_t*args) {
+    char*action = "";
+    readToken();
+    if(type == RAWDATA)
+       action = text;
+    else
+       pushBack();
+
+    return fakechar(args);
+}
 static int c_edittext(map_t*args) {return fakechar(args);}
 
 static int c_morphshape(map_t*args) {return fakechar(args);}
@@ -2047,7 +2060,17 @@ static int c_movie(map_t*args) {return fakechar(args);}
 static int c_buttonsounds(map_t*args) {return 0;}
 static int c_buttonput(map_t*args) {return 0;}
 static int c_texture(map_t*args) {return 0;}
-static int c_action(map_t*args) {return 0;}
+
+static int c_action(map_t*args) 
+{
+    readToken();
+    if(type != RAWDATA)
+       syntaxerror("colon (:) expected");
+
+    s_action(text);
+   
+    return 0;
+}
 
 static struct {
     char*command;
@@ -2281,6 +2304,7 @@ static void parseArgumentsForCommand(char*command)
     int t;
     map_t args;
     int nr = -1;
+    msg("<verbose> parse Command: %s (line %d)", command, line);
     for(t=0;t<sizeof(arguments)/sizeof(arguments[0]);t++) {
        if(!strcmp(arguments[t].command, command)) {
 
@@ -2307,7 +2331,7 @@ static void parseArgumentsForCommand(char*command)
 
     (*arguments[nr].func)(&args);
 
-    if(!strcmp(command, "button") ||
+    /*if(!strcmp(command, "button") ||
        !strcmp(command, "action")) {
        while(1) {
            readToken();
@@ -2320,7 +2344,7 @@ static void parseArgumentsForCommand(char*command)
                }
            }
        }
-    }
+    }*/
 
     map_clear(&args);
     return;