[Swfed-svn] swfed-svn [71] swf_tag_t からリスト構造 ( 自己参照構造体 ) を swf_tag_list_t に分離。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 10月 14日 (火) 21:19:10 JST


Revision: 71
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=swfed&view=rev&rev=71
Author:   yoya
Date:     2008-10-14 21:19:10 +0900 (Tue, 14 Oct 2008)

Log Message:
-----------
swf_tag_t からリスト構造(自己参照構造体)を swf_tag_list_t に分離。
(tag block の中身でなく、tag block 自体を作り直す処理を作る準備)

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


-------------- next part --------------
Modified: trunk/src/swf_object.c
===================================================================
--- trunk/src/swf_object.c	2008-10-10 10:45:57 UTC (rev 70)
+++ trunk/src/swf_object.c	2008-10-14 12:19:10 UTC (rev 71)
@@ -26,24 +26,28 @@
 
 void
 swf_object_close(swf_object_t *swf) {
-    swf_tag_t *tag, *next_tag;
-    if (! swf) {
+    swf_tag_list_t *tag_list, *next_tag;
+    if (swf == NULL) {
         return ;
     }
-    for(tag = swf->tag; tag; tag = next_tag) {
-        next_tag = tag->next;
-        swf_tag_destroy(tag);
+    for (tag_list = swf->tag_list; tag_list; tag_list = next_tag) {
+        next_tag = tag_list->next;
+        if (tag_list->node) {
+            swf_tag_destroy(tag_list->node);
+        }
+        free(tag_list);
     }
     free(swf);
     malloc_debug_end(); /* DEBUG XXX */
     return ;
 }
+
 int
 swf_object_input(swf_object_t *swf, unsigned char *data,
                  unsigned long data_len) {
     int result;
     bitstream_t *bs = bitstream_open();
-    swf_tag_t **tag;
+    swf_tag_list_t *tag_list;
     bitstream_input(bs, data, data_len);
     result = swf_header_parse(bs, &swf->header);
     if (result) {
@@ -85,18 +89,18 @@
         bitstream_close(bs);
         return result;
     }
-    tag = &swf->tag;
+    swf->tag_list = tag_list = calloc(sizeof(*tag_list), 1);
     while(1) {
-        long pos;
-        pos = bitstream_getbytepos(bs);
+        long pos = bitstream_getbytepos(bs);
         if ((pos == -1) || ((long) swf->header.file_length <= pos)) {
             break;
         }
-        *tag = swf_tag_create(bs);
-        if (tag == NULL) {
+        tag_list->node = swf_tag_create(bs);
+        if (tag_list->node == NULL) {
             fprintf(stderr, "swf_object_input: swf_tag_create failed\n");
         }
-        tag = &((*tag)->next);
+        tag_list->next = calloc(sizeof(*tag_list), 1);
+        tag_list = tag_list->next;
     }
     bitstream_close(bs);
     return 0;
@@ -105,7 +109,7 @@
 unsigned char *
 swf_object_output(swf_object_t *swf, unsigned long *length) {
     int result;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     unsigned char *data;
     bitstream_t *bs = bitstream_open();
     *length = 0;
@@ -119,8 +123,8 @@
         bitstream_close(bs);
         return NULL;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        swf_tag_build(bs, tag, swf);
+    for (tag_list = swf->tag_list; tag_list && tag_list->node; tag_list = tag_list->next) {
+        swf_tag_build(bs, tag_list->node, swf);
     }
     swf->header.file_length = bitstream_getbytepos(bs);
     bitstream_setpos(bs, SWF_MAGIC_SIZE, 0);
@@ -162,17 +166,17 @@
 void
 swf_object_print(swf_object_t *swf) {
     int i;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     swf_header_print(&swf->header);
     swf_header_movie_print(&swf->header_movie);
-    tag = swf->tag;
-    for (i=0; tag; i++) {
+    tag_list = swf->tag_list;
+    for (i=0; tag_list && tag_list->node; i++) {
         printf("[%d] ", i);
-        swf_tag_print(tag, swf);
-        if (tag->tag == 0) { // END Tag
+        swf_tag_print(tag_list->node, swf);
+        if (tag_list->node->tag == 0) { // END Tag
             break;
         }
-        tag = tag->next;
+        tag_list = tag_list->next;
     }
 }
 
@@ -181,29 +185,32 @@
 
 unsigned char *
 swf_object_get_jpegdata(swf_object_t *swf, unsigned long *length, int image_id) {
-    swf_tag_t *tag, *tag_jpegtables = NULL;
+    swf_tag_list_t *tag_list;
+    swf_tag_t *tag_jpegtables = NULL;
     unsigned char *data = NULL;
     *length = 0;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_get_jpegdata: swf == NULL\n");
         return NULL;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        if (tag->tag == 8) { // JPEGTables
-            tag_jpegtables = tag;
+    for (tag_list = swf->tag_list; tag_list && tag_list->node; tag_list = tag_list->next) {
+        if (tag_list->node->tag == 8) { // JPEGTables
+            tag_jpegtables = tag_list->node;
             break;
         }
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        if (tag->tag == 8) {
-            tag_jpegtables = tag;
+    for (tag_list = swf->tag_list; tag_list && tag_list->node; tag_list = tag_list->next) {
+        if (tag_list->node->tag == 8) {
+            tag_jpegtables = tag_list->node;
             continue;
         }
         // DefineBitsJPEG(1),2,3
-        if ((tag->tag != 6) && (tag->tag != 21) && (tag->tag != 35)) {
+        if ((tag_list->node->tag != 6) &&
+            (tag_list->node->tag != 21) &&
+            (tag_list->node->tag != 35)) {
             continue;
         }
-        data = swf_tag_get_jpeg_data(tag, length, image_id, tag_jpegtables);
+        data = swf_tag_get_jpeg_data(tag_list->node, length, image_id, tag_jpegtables);
         if (data) {
             break;
         }
@@ -213,18 +220,20 @@
 
 unsigned char *
 swf_object_get_alphadata(swf_object_t *swf, unsigned long *length, int image_id) {
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     unsigned char *data = NULL;
     *length = 0;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_get_alphadata: swf == NULL\n");
         return NULL;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        if (tag->tag != 35) { // ! DefineBitsJPEG3
+    for (tag_list = swf->tag_list; tag_list && tag_list->node;
+         tag_list = tag_list->next) {
+        if (tag_list->node->tag != 35) { // ! DefineBitsJPEG3
             continue;
         }
-        data = swf_tag_get_alpha_data(tag, length, image_id);
+        data = swf_tag_get_alpha_data(tag_list->node, length,
+                                      image_id);
         if (data) {
             break;
         }
@@ -240,13 +249,14 @@
                             unsigned char *alpha_data,
                             unsigned long alpha_data_len) {
     int result = 1;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_replace_jpegdata: swf == NULL\n");
         return 1;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        result = swf_tag_replace_jpeg_data(tag, image_id,
+    for (tag_list = swf->tag_list; tag_list && tag_list->node;
+         tag_list = tag_list->next) {
+        result = swf_tag_replace_jpeg_data(tag_list->node, image_id,
                                            jpeg_data, jpeg_data_len,
                                            alpha_data, alpha_data_len);
         if (! result) {
@@ -259,19 +269,21 @@
 
 unsigned char *
 swf_object_get_pngdata(swf_object_t *swf, unsigned long *length, int image_id) {
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     unsigned char *data = NULL;
     *length = 0;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_get_pngdata: swf == NULL\n");
         return NULL;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
+    for (tag_list = swf->tag_list; tag_list && tag_list->node;
+         tag_list = tag_list->next) {
         // DefineBitsLossless(1),2
-        if ((tag->tag != 20) && (tag->tag != 36)) {
+        if ((tag_list->node->tag != 20) &&
+            (tag_list->node->tag != 36)) {
             continue;
         }
-        data = swf_tag_get_png_data(tag, length, image_id);
+        data = swf_tag_get_png_data(tag_list->node, length, image_id);
         if (data) {
             break;
         }
@@ -284,13 +296,14 @@
                             unsigned char *png_data,
                             unsigned long png_data_len) {
     int result = 1;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_replace_pngdata: swf == NULL\n");
         return 1;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        result = swf_tag_replace_png_data(tag, image_id,
+    for (tag_list = swf->tag_list; tag_list && tag_list->node;
+         tag_list = tag_list->next) {
+        result = swf_tag_replace_png_data(tag_list->node, image_id,
                                            png_data, png_data_len);
         if (! result) {
             break;
@@ -301,19 +314,20 @@
 
 unsigned char *
 swf_object_get_sounddata(swf_object_t *swf, unsigned long *length, int sound_id) {
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     unsigned char *data = NULL;
     *length = 0;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_get_sounddata: swf == NULL\n");
         return NULL;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
+    for (tag_list = swf->tag_list; tag_list && tag_list->node;
+         tag_list = tag_list->next) {
         // DefineSound
-        if (tag->tag != 14) {
+        if (tag_list->node->tag != 14) {
             continue;
         }
-        data = swf_tag_get_sound_data(tag, length, sound_id);
+        data = swf_tag_get_sound_data(tag_list->node, length, sound_id);
         if (data) {
             break;
         }
@@ -326,13 +340,14 @@
                             unsigned char *melo_data,
                             unsigned long melo_data_len) {
     int result = 1;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_replace_melodata: swf == NULL\n");
         return 1;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        result = swf_tag_replace_melo_data(tag, sound_id,
+    for (tag_list = swf->tag_list; tag_list && tag_list->node;
+         tag_list = tag_list->next) {
+        result = swf_tag_replace_melo_data(tag_list->node, sound_id,
                                            melo_data, melo_data_len);
         if (! result) {
             break;
@@ -345,14 +360,15 @@
 swf_object_get_editstring(swf_object_t *swf,
                           char *variable_name,
                           int variable_name_len) {
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     char *data = NULL;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_get_editstring: swf == NULL\n");
         return NULL;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        data = swf_tag_get_edit_string(tag, variable_name,
+    for (tag_list = swf->tag_list; tag_list && tag_list->node;
+         tag_list = tag_list->next) {
+        data = swf_tag_get_edit_string(tag_list->node, variable_name,
                                        variable_name_len, swf);
         if (data) {
             break;
@@ -367,13 +383,15 @@
                               char *initial_text,
                               int initial_text_len) {
     int result = 1;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_replace_editstring: swf == NULL\n");
         return 1;
     }
-    for (tag = swf->tag; tag; tag = tag->next) {
-        result = swf_tag_replace_edit_string(tag, variable_name,
+    for (tag_list = swf->tag_list; tag_list && tag_list->node;
+         tag_list = tag_list->next) {
+        result = swf_tag_replace_edit_string(tag_list->node,
+                                             variable_name,
                                              variable_name_len,
                                              initial_text,
                                              initial_text_len,
@@ -387,23 +405,24 @@
 
 unsigned char *
 swf_object_get_actiondata(swf_object_t *swf, unsigned long *length, int tag_seqno) {
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     swf_tag_action_detail_t *swf_tag_action;
     int i = 0;
-    for(tag = swf->tag; tag; tag = tag->next) {
+    for(tag_list = swf->tag_list; tag_list && tag_list->node;
+        tag_list = tag_list->next) {
         if (i == tag_seqno) {
             break;
         }
         i++;
     }
-    if (tag == NULL) {
+    if (tag_list == NULL) {
         return NULL;
     }
-    if ((tag->tag != 12) &&  (tag->tag != 59)) { //  DoAction, DoInitAction
+    if ((tag_list->node->tag != 12) &&  (tag_list->node->tag != 59)) { //  DoAction, DoInitAction
         return NULL;
     }
-    swf_tag_create_detail(tag, swf);
-    swf_tag_action = (swf_tag_action_detail_t *) tag->detail;
+    swf_tag_create_detail(tag_list->node, swf);
+    swf_tag_action = (swf_tag_action_detail_t *) tag_list->node->detail;
     *length = swf_tag_action->action_record_len;
     return swf_tag_action->action_record;
 }

Modified: trunk/src/swf_object.h
===================================================================
--- trunk/src/swf_object.h	2008-10-10 10:45:57 UTC (rev 70)
+++ trunk/src/swf_object.h	2008-10-14 12:19:10 UTC (rev 71)
@@ -14,7 +14,7 @@
 typedef struct swf_object_ {
     swf_header_t header;
     swf_header_movie_t header_movie;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
 } swf_object_t;
 
 

Modified: trunk/src/swf_tag.h
===================================================================
--- trunk/src/swf_tag.h	2008-10-10 10:45:57 UTC (rev 70)
+++ trunk/src/swf_tag.h	2008-10-14 12:19:10 UTC (rev 71)
@@ -21,6 +21,11 @@
     struct swf_tag_ *next;
 } swf_tag_t;
 
+typedef struct swf_tag_list_ {
+    struct swf_tag_ *node;
+    struct swf_tag_list_ *next;
+} swf_tag_list_t;
+
 typedef struct swf_tag_detail_handler_ {
     void          * (*create)   (unsigned char *data,
                                  unsigned long length,

Modified: trunk/src/swfed.c
===================================================================
--- trunk/src/swfed.c	2008-10-10 10:45:57 UTC (rev 70)
+++ trunk/src/swfed.c	2008-10-14 12:19:10 UTC (rev 71)
@@ -318,26 +318,26 @@
     int i = 0;
     zval *data;
     swf_object_t *swf;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     swf_tag_info_t *tag_info;
     if (ZEND_NUM_ARGS() != 0) {
         WRONG_PARAM_COUNT;
         RETURN_FALSE; /* XXX */
     }
     swf = get_swf_object(getThis());
-    tag = swf->tag;
     array_init(return_value);
-    for(tag = swf->tag; tag; tag=tag->next) {
+    for(tag_list = swf->tag_list; tag_list && tag_list->node;
+        tag_list = tag_list->next) {
         ALLOC_INIT_ZVAL(data);
         array_init(data);
-        add_assoc_long(data, "tag", tag->tag);
-        tag_info = get_swf_tag_info(tag->tag);
+        add_assoc_long(data, "tag", tag_list->node->tag);
+        tag_info = get_swf_tag_info(tag_list->node->tag);
         if (tag_info && tag_info->name) {
             add_assoc_string_ex(data,
                                 "tagName", sizeof("tagName"),
                                 (char *)tag_info->name, 1);
         }
-        add_assoc_long(data, "length", tag->length);
+        add_assoc_long(data, "length", tag_list->node->length);
         if (tag_info && tag_info->detail_handler) {
             add_assoc_bool(data, "detail", 1);
         }
@@ -349,7 +349,7 @@
 PHP_METHOD(swfed, getTagDetail) {
     long tag_seqno;
     swf_object_t *swf;
-    swf_tag_t *tag;
+    swf_tag_list_t *tag_list;
     swf_tag_info_t *tag_info;
     int i;
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
@@ -358,21 +358,22 @@
     }
     swf = get_swf_object(getThis());
     i = 0;
-    for(tag = swf->tag; tag; tag = tag->next) {
+    for (tag_list = swf->tag_list; tag_list && tag_list->node ;
+         tag_list = tag_list->next) {
         if (i == tag_seqno) {
             break;
         }
         i++;
     }
-    if (tag == NULL) {
+    if (tag_list == NULL) {
         RETURN_FALSE;
     }
-    tag_info = get_swf_tag_info(tag->tag);
+    tag_info = get_swf_tag_info(tag_list->node->tag);
     if ((tag_info == NULL) || (tag_info->detail_handler == NULL)) {
         RETURN_FALSE;
     }
-    swf_tag_create_detail(tag, swf);
-    switch (tag->tag) {
+    swf_tag_create_detail(tag_list->node, swf);
+    switch (tag_list->node->tag) {
         swf_tag_jpeg_detail_t     *tag_jpeg;
         swf_tag_lossless_detail_t *tag_lossless;
         swf_tag_edit_detail_t     *tag_edit;
@@ -381,7 +382,7 @@
       case 6:  // DefineBitsJPEG
       case 21: // DefineBitsJPEG2
       case 35: // DefineBitsJPEG3
-        tag_jpeg = tag->detail;
+        tag_jpeg = tag_list->node->detail;
         array_init(return_value);
         add_assoc_long(return_value, "image_id", tag_jpeg->image_id);
         add_assoc_long(return_value, "jpeg_data_len", tag_jpeg->jpeg_data_len);
@@ -392,7 +393,7 @@
         break;
       case 20: // DefineBitsLossless
       case 36: // DefineBitsLossless2
-        tag_lossless = tag->detail;
+        tag_lossless = tag_list->node->detail;
         array_init(return_value);
         add_assoc_long(return_value, "image_id", tag_lossless->image_id);
         add_assoc_long(return_value, "format", tag_lossless->format);
@@ -403,7 +404,7 @@
         }
         break;
     case 14: // DefineSound
-        tag_sound = tag->detail;
+        tag_sound = tag_list->node->detail;
         array_init(return_value);
         add_assoc_long(return_value, "sound_id", tag_sound->sound_id);
         add_assoc_long(return_value, "format", (unsigned long) tag_sound->sound_format);
@@ -415,9 +416,9 @@
         break;
     case 12: // DoAction
     case 59: // DoInitAction
-        tag_action = tag->detail;
+        tag_action = tag_list->node->detail;
         array_init(return_value);
-        if (tag->tag == 59) { // DoInitAction
+        if (tag_list->node->tag == 59) { // DoInitAction
             add_assoc_long(return_value, "action_sprite", tag_action->action_sprite);
         }
         if (tag_action->action_record && tag_action->action_record_len) {
@@ -425,7 +426,7 @@
         }
         break;
       case 37: // DefineEditText;
-        tag_edit = tag->detail;
+        tag_edit = tag_list->node->detail;
         array_init(return_value);
         add_assoc_long(return_value, "edit_id", tag_edit->edit_id);
         if (tag_edit->edit_variable_name && tag_edit->edit_variable_name[0]){


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