* optimized a loop
[swftools.git] / lib / modules / swfaction.c
index d70d677..4c47d53 100644 (file)
@@ -128,7 +128,7 @@ r: register (byte)
 };
 static int definedactions = sizeof(actions)/sizeof(struct Action);
 
-ActionTAG* swf_GetActions(TAG*tag) 
+ActionTAG* swf_ActionGet(TAG*tag) 
 {
     U8 op = 1;
     int length;
@@ -149,10 +149,8 @@ ActionTAG* swf_GetActions(TAG*tag)
            length = swf_GetU16(tag);
 
        if(length) {
-           int t;
            data = malloc(length);
-           for(t=0;t<length;t++)
-               data[t] = swf_GetU8(tag);
+           swf_GetBlock(tag, data, length);
        } else {
          data = 0;
        }
@@ -164,7 +162,20 @@ ActionTAG* swf_GetActions(TAG*tag)
     return tmp.next;
 }
 
-void swf_SetActions(TAG*tag, ActionTAG*action)
+void swf_ActionFree(ActionTAG*action)
+{
+    while(action)
+    {
+       ActionTAG*tmp;
+       if(action->data && action->data != action->tmp)
+           free(action->data);
+       tmp = action;
+       action=action->next;
+       free(tmp);
+    }
+}
+
+void swf_ActionSet(TAG*tag, ActionTAG*action)
 {
     while(action)
     {
@@ -288,24 +299,27 @@ void swf_DumpActions(ActionTAG*atag, char*prefix)
                    if(type == 0) {
                        printf(" String:\"%s\"", value);
                    } else if (type == 1) {
-                       printf(" Float:\"%f\"", *(float*)value);
+                       printf(" Float:%f", *(float*)value);
                    } else if (type == 2) {
                        printf(" NULL");
                    } else if (type == 4) {
                        printf(" register:%d", *value);
                    } else if (type == 5) {
-                       printf(" %s", *value?"true":"false");
+                       printf(" bool:%s", *value?"true":"false");
                    } else if (type == 6) {
-                       printf(" %f", *(double*)value);
+                       printf(" float:%f", *(double*)value);
                    } else if (type == 7) {
-                       printf(" %d", *(int*)value);
+                       printf(" int:%d", *(int*)value);
                    } else if (type == 8) {
                        printf(" Lookup:%d", *value);
+                   } else {
+                       printf(" UNKNOWN[%02x]",type);
                    }
                } break;
            }
            data += OpAdvance(*cp, data);
-           if(*cp!='c' || !poollen)
+           if((*cp!='c' || !poollen) &&
+              (*cp!='p' || !(data<&atag->data[atag->len])))
                cp++;
            if(poollen)
                poollen--;
@@ -315,14 +329,14 @@ void swf_DumpActions(ActionTAG*atag, char*prefix)
        {
            int nl = ((atag->data+atag->len)-data);
            int t;
-           printf(" remainder of %d bytes:\"", nl);
+           printf(" (remainder of %d bytes:\"", nl);
            for(t=0;t<nl;t++) {
                if(data[t]<32)
                    printf("\\%d",data[t]);
                else
                    printf("%c", data[t]);
            }
-           printf("\"");
+           printf("\")");
        }
        printf("\n");
        atag = atag->next;
@@ -745,8 +759,8 @@ void action_GetUrl(char* url, char* label)
     int l2= strlen(label);
     char*ptr = malloc(l1+l2+2);
     strcpy(ptr, url);
-    strcat(&ptr[l2+1], label);
-    swf_AddActionTAG(ACTION_GOTOLABEL, ptr, strlen(ptr));
+    strcpy(&ptr[l1+1], label);
+    swf_AddActionTAG(ACTION_GETURL, ptr, l1+l2+2);
 }
 //TODO:
 void action_DefineFunction(U8*data, int len) {}