+static void add_dependencies(asset_resolver_t*assets, abc_asset_t*asset, TAG*tag)
+{
+ int num = swf_GetNumUsedIDs(tag);
+ int*positions = malloc(sizeof(int)*num);
+ swf_GetUsedIDs(tag, positions);
+ int t;
+ for(t=0;t<num;t++) {
+ U16 id = GET16(&tag->data[positions[t]]);
+
+ /* check whether we already processed this one */
+ int s;
+ for(s=0;s<t;s++) {
+ if(GET16(&tag->data[positions[s]])==id) break; //seen before
+ }
+ if(s!=t) continue;
+
+ /* count number of occurences */
+ int count=0;
+ for(s=t;s<num;s++) {
+ if(GET16(&tag->data[positions[s]])==id)
+ count++;
+ }
+
+ /* create dependency */
+ NEW(asset_dependency_t,d);
+ d->asset = assets->id2asset[id];
+ d->patch = malloc(sizeof(int)*count);
+ d->patch_size = count;
+ count = 0;
+ for(s=t;s<num;s++) {
+ if(GET16(&tag->data[positions[s]])==id)
+ d->patch[count++] = positions[s];
+ }
+ if(!d->asset) {
+ fprintf(stderr, "Error: ID %d referenced, but not defined\n", id);
+ } else {
+ list_append(asset->dependencies, d);
+ }
+ }
+ free(positions);
+}
+