made swf_Relocate return a success code
authorMatthias Kramm <kramm@quiss.org>
Tue, 20 Jan 2009 00:23:35 +0000 (16:23 -0800)
committerMatthias Kramm <kramm@quiss.org>
Tue, 20 Jan 2009 00:23:35 +0000 (16:23 -0800)
lib/modules/swftools.c
lib/rfxswf.h

index 16ab87d..cd57d6f 100644 (file)
@@ -966,12 +966,13 @@ void swf_GetUsedIDs(TAG * t, int * positions)
     enumerateUsedIDs(t, 0, callbackFillin, &ptr);
 }
 
-void swf_Relocate (SWF*swf, char*bitmap)
+char swf_Relocate (SWF*swf, char*bitmap)
 {
     TAG*tag;
     int slaveids[65536];
     memset(slaveids, -1, sizeof(slaveids));
     tag = swf->firstTag;
+    char ok = 1;
     while(tag)
     {
        int num; 
@@ -987,8 +988,7 @@ void swf_Relocate (SWF*swf, char*bitmap)
 
            if(!bitmap[id]) { //free
                newid = id;
-           }
-           else {
+           } else {
                newid = 0;
                for (t=1;t<65536;t++)
                {
@@ -998,6 +998,10 @@ void swf_Relocate (SWF*swf, char*bitmap)
                        break;
                    }
                }
+                if(t==65536) {
+                    fprintf(stderr, "swf_Relocate: Couldn't relocate: Out of IDs");
+                    return 0;
+                }
            }
            bitmap[newid] = 1;
            slaveids[id] = newid;
@@ -1015,6 +1019,7 @@ void swf_Relocate (SWF*swf, char*bitmap)
                if(slaveids[id]<0) {
                    fprintf(stderr, "swf_Relocate: Mapping id (%d) never encountered before in %s\n", id,
                            swf_TagGetName(tag));
+                    ok = 0;
                } else {
                    id = slaveids[id];
                    PUT16(&tag->data[ptr[t]], id);
@@ -1023,6 +1028,7 @@ void swf_Relocate (SWF*swf, char*bitmap)
        }
        tag=tag->next;
     }
+    return ok;
 }
 
 /* untested */
index ce4307f..2f6c429 100644 (file)
@@ -734,7 +734,7 @@ MATRIX * swf_MatrixMapTriangle(MATRIX * m,int dx,int dy,
                     int x0,int y0,int x1,int y1,int x2,int y2);
 int swf_GetNumUsedIDs(TAG * t);
 void swf_GetUsedIDs(TAG * t, int * positions);
-void swf_Relocate(SWF*swf, char*bitmap); // bitmap is 65536 bytes, bitmap[a]==0 means id a is free
+char swf_Relocate(SWF*swf, char*bitmap); // bitmap is 65536 bytes, bitmap[a]==0 means id a is free
 void swf_RelocateDepth(SWF*swf, char*bitmap); // bitmap is 65536 bytes, bitmap[d]==0 means depth d is free
 
 TAG* swf_Concatenate (TAG*list1,TAG*list2); // warning: both list1 and list2 are invalid after this call.