[Swfed-svn] swfed-svn [374] - setActionVariables の度に DoAction を増やすのをやめて、既にある場合は変数代入イメージを混ぜるように改造。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 3日 (木) 23:26:29 JST


Revision: 374
          http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=374
Author:   yoya
Date:     2011-03-03 23:26:29 +0900 (Thu, 03 Mar 2011)

Log Message:
-----------
- setActionVariables の度に DoAction を増やすのをやめて、既にある場合は変数代入イメージを混ぜるように改造。
- 不要な変数の削除やエラー文言の修正。

Modified Paths:
--------------
    trunk/src/swf_object.c
    trunk/src/swf_tag.c
    trunk/src/swf_tag.h
    trunk/src/swf_tag_action.c
    trunk/src/swf_tag_action.h


-------------- next part --------------
Modified: trunk/src/swf_object.c
===================================================================
--- trunk/src/swf_object.c	2011-03-03 12:55:52 UTC (rev 373)
+++ trunk/src/swf_object.c	2011-03-03 14:26:29 UTC (rev 374)
@@ -10,6 +10,7 @@
 #include <zlib.h>
 #include "bitstream.h"
 #include "swf_define.h"
+#include "swf_tag.h"
 #include "swf_tag_action.h"
 #include "swf_tag_jpeg.h"
 #include "swf_tag_lossless.h"
@@ -266,7 +267,6 @@
     }
     if (tag) {
         if (tag->data) {
-            unsigned char *data;
             *length = tag->length - 2;
             return tag->data + 2;
         }
@@ -329,7 +329,7 @@
     }
     if (tag) {
         if (! isShapeTag(tag->tag)) {
-            fprintf(stderr, "");
+            fprintf(stderr, "swf_object_get_shapedata: not isShapeTag(%d)\n", tag->tag);
             return NULL;
         }
         if (tag->detail) {
@@ -344,7 +344,6 @@
             bitstream_close(bs);
         }
         if (tag->data) {
-            unsigned char *data;
             *length = tag->length - 2;
             return tag->data + 2;
         }
@@ -789,42 +788,68 @@
 int
 swf_object_insert_action_setvariables(swf_object_t *swf,
                                       y_keyvalue_t *kv) {
-    swf_tag_t *tag, *prev_tag = NULL, *next_tag = NULL;
+    swf_tag_t *tag, *prev = NULL;
+    swf_tag_t *action_tag = NULL, *prev_tag = NULL, *next_tag = NULL;
+    int ret, done = 0;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_insert_action_setvariables: swf == NULL\n");
         return 1; // NG
     }
     for (tag=swf->tag ; tag ; tag=tag->next) {
         switch (tag->tag) {
+        case 1: // ShowFrame
+            if (next_tag == NULL) {
+                prev_tag = prev;
+                next_tag = tag;
+            }
+            done = 1;
+            break;
+        case 12: // DoAction
+            action_tag = tag;
+            done = 1;
+            break;
         case 69: // FileAttributs
         case  9: // SetBackgroundColor
         case 24: // Protect
             break;
         default:
-            next_tag = tag;
+            if (next_tag == NULL) {
+                prev_tag = prev;
+                next_tag = tag;
+            }
             break;
         }
-        if (next_tag) { // found
+        if (done) {
             break;
         }
-        prev_tag = tag;
+        prev = tag;
     }
-    if (next_tag == NULL) {
-        fprintf(stderr, "swf_object_insert_action_setvariables: next_tag == NULL\n");
-        return 1;
+    if ((action_tag == NULL) && (next_tag == NULL)) {
+        fprintf(stderr, "swf_object_insert_action_setvariables: action_tag == NULL && next_tag == NULL\n");
+        return 1; // NG
     }
-    tag = swf_tag_create_action_setvariables(kv);
-    if (tag == NULL) {
-        fprintf(stderr, "swf_object_insert_action_setvariables: swf_tag_create_action_setvariables failed\n");
-        return 1;// NG
+    if (action_tag) { // DoAction の頭に変数代入イメージを挿入
+        ret = swf_tag_put_action_setvariables(action_tag,
+                                              kv,
+                                              swf);
+        if (ret) {
+            fprintf(stderr, "swf_object_insert_action_setvariables: swf_tag_put_action_setvariables failed\n");
+            return 1; // NG
+        }
+    } else { // 新規に DoAction を挿入
+        tag = swf_tag_create_action_setvariables(kv);
+        if (tag == NULL) {
+            fprintf(stderr, "swf_object_insert_action_setvariables: swf_tag_create_action_setvariables failed\n");
+            return 1; // NG
+        }
+        if (prev_tag == NULL) {
+            swf->tag = tag;
+            tag->next = next_tag;
+        } else {
+            prev_tag->next = tag;
+            tag->next = next_tag;
+        }
     }
-    if (prev_tag == NULL) {
-        swf->tag = tag;
-        tag->next = next_tag;
-    } else {
-        prev_tag->next = tag;
-        tag->next = next_tag;
-    }
     return 0; // SUCCESS
 }
 

Modified: trunk/src/swf_tag.c
===================================================================
--- trunk/src/swf_tag.c	2011-03-03 12:55:52 UTC (rev 373)
+++ trunk/src/swf_tag.c	2011-03-03 14:26:29 UTC (rev 374)
@@ -813,7 +813,27 @@
     ret = swf_tag_action_create_setvaribles(tag, kv);
     if (ret) {
         swf_tag_destroy(tag);
-        return 0;
+        return NULL;
     }
     return tag;
 }
+
+int
+swf_tag_put_action_setvariables(swf_tag_t *tag, y_keyvalue_t *kv,
+                                struct swf_object_ *swf) {
+    int ret;
+    if (! tag->detail) {
+        swf_tag_create_input_detail(tag, swf);
+    }
+    ret = swf_tag_action_put_setvaribles(tag, kv);
+    if (ret) {
+        swf_tag_destroy(tag);
+        return 1; // NG
+    }
+    if (tag->data) {
+        free(tag->data);
+        tag->data = NULL;
+    }
+    return 0;
+}
+

Modified: trunk/src/swf_tag.h
===================================================================
--- trunk/src/swf_tag.h	2011-03-03 12:55:52 UTC (rev 373)
+++ trunk/src/swf_tag.h	2011-03-03 14:26:29 UTC (rev 374)
@@ -106,5 +106,8 @@
                                            struct swf_object_ *swf);
 
 extern swf_tag_t *swf_tag_create_action_setvariables(y_keyvalue_t *kv);
+extern int swf_tag_put_action_setvariables(swf_tag_t *tag,
+                                           y_keyvalue_t *kv,
+                                           struct swf_object_ *swf);
 
 #endif /* __SWF_TAG_H__ */

Modified: trunk/src/swf_tag_action.c
===================================================================
--- trunk/src/swf_tag_action.c	2011-03-03 12:55:52 UTC (rev 373)
+++ trunk/src/swf_tag_action.c	2011-03-03 14:26:29 UTC (rev 374)
@@ -145,6 +145,41 @@
         bitstream_putbyte(bs, 0x96); // Push Data
         bitstream_putbytesLE(bs, key_len + 2 , 2);
         bitstream_putbyte(bs, 0);
+        bitstream_putstring(bs, (unsigned char*) key, key_len);
+        bitstream_putbyte(bs, 0);
+        bitstream_putbyte(bs, 0x96); // Push Data
+        bitstream_putbytesLE(bs, value_len + 2 , 2);
+        bitstream_putbyte(bs, 0);
+        bitstream_putstring(bs, (unsigned char*) value, value_len);
+        bitstream_putbyte(bs, 0);
+        bitstream_putbyte(bs, 0x1d); // Set Variable
+    }
+    bitstream_putbyte(bs, 0); // End
+    if (swf_tag_action->action_record) {
+        free(swf_tag_action->action_record);
+    }
+    swf_tag_action->action_record = bitstream_steal(bs, &data_len);
+    swf_tag_action->action_record_len = data_len;
+    bitstream_close(bs);
+    return 0;
+}
+
+int
+swf_tag_action_put_setvaribles(swf_tag_t *tag, y_keyvalue_t *kv) {
+    bitstream_t *bs, *bs2;
+    char *key, *value;
+    int key_len, value_len;
+    unsigned long data_len, append_data_len;
+    swf_tag_action_detail_t *swf_tag_action = (swf_tag_action_detail_t *) tag->detail;
+    swf_tag_action->action_sprite = 0;
+    bs = bitstream_open();
+    y_keyvalue_rewind(kv);
+    while (y_keyvalue_next(kv)) {
+        key   = y_keyvalue_get_currentkey(kv, &key_len);
+        value = y_keyvalue_get_currentvalue(kv, &value_len);
+        bitstream_putbyte(bs, 0x96); // Push Data
+        bitstream_putbytesLE(bs, key_len + 2 , 2);
+        bitstream_putbyte(bs, 0);
         bitstream_putstring(bs, key, key_len);
         bitstream_putbyte(bs, 0);
         bitstream_putbyte(bs, 0x96); // Push Data
@@ -154,7 +189,10 @@
         bitstream_putbyte(bs, 0);
         bitstream_putbyte(bs, 0x1d); // Set Variable
     }
-    bitstream_putbyte(bs, 0); // End
+    if (swf_tag_action->action_record) {
+        bitstream_putstring(bs, swf_tag_action->action_record, swf_tag_action->action_record_len);
+        free(swf_tag_action->action_record);
+    }
     swf_tag_action->action_record = bitstream_steal(bs, &data_len);
     swf_tag_action->action_record_len = data_len;
     bitstream_close(bs);

Modified: trunk/src/swf_tag_action.h
===================================================================
--- trunk/src/swf_tag_action.h	2011-03-03 12:55:52 UTC (rev 373)
+++ trunk/src/swf_tag_action.h	2011-03-03 14:26:29 UTC (rev 374)
@@ -31,5 +31,6 @@
 extern void swf_tag_action_destroy_detail(swf_tag_t *tag);
 
 extern int swf_tag_action_create_setvaribles(swf_tag_t *tag, y_keyvalue_t *kv);
+extern int swf_tag_action_put_setvaribles(swf_tag_t *tag, y_keyvalue_t *kv);
 
 #endif /* __SWF_TAG_ACTION__H__ */



Swfed-svn メーリングリストの案内
Back to archive index