imports.c

来自「flash swf file player」· C语言 代码 · 共 81 行

C
81
字号
/* $Id: imports.c,v 1.2 2003/11/08 18:24:57 whamann Exp $ */#include <stdlib.h>#include <string.h>#include "imports.h"#include "method.h"intwriteSWFImportBlockToMethod(SWFBlock block, SWFByteOutputMethod method, void *data){	SWFImportBlock imports = (SWFImportBlock) block;	struct importitem *ip;	int length, count;	char *p;	length = 3 + strlen(imports->filename);	for(ip = imports->importlist, count = 0 ; ip ; ip = ip->next)	{	length += 3 + strlen(ip->name);		count++;	}	for(p = imports->filename ; *p ; )		method(*p++, data);	method(0, data);	methodWriteUInt16(count, method, data);	for(ip = imports->importlist ; ip ; ip = ip->next)	{	methodWriteUInt16(ip->id, method, data);		for(p = ip->name ; *p ; )			method(*p++, data);		method(0, data);	}	return length;}intcompleteSWFImportBlock(SWFBlock block){	SWFImportBlock imports = (SWFImportBlock) block;	struct importitem *ip;	int length = 3 + strlen(imports->filename);	for(ip = imports->importlist ; ip ; ip = ip->next)		length += 3 + strlen(ip->name);	return length;}voiddestroySWFImportBlock(SWFImportBlock importBlock){	struct importitem *ip, *nip;	if(importBlock->filename)		free(importBlock->filename);	for(ip = importBlock->importlist ; ip ; ip = nip)	{	nip = ip->next;		if(ip->name)			free(ip->name);		free(ip);	}	free(importBlock);}static char *cpy(const char *text){	char *res, *p;	p = res = (char *)malloc(strlen(text)+1);	while((*p++ = *text++))		;	return res;}SWFImportBlocknewSWFImportBlock(const char *filename){	SWFImportBlock iblock = (SWFImportBlock) malloc(sizeof(struct SWFImportBlock_s));	BLOCK(iblock)->type = SWF_IMPORTASSETS;	BLOCK(iblock)->writeBlock = (writeSWFBlockMethod) writeSWFImportBlockToMethod;	BLOCK(iblock)->complete = completeSWFImportBlock;	BLOCK(iblock)->dtor = (destroySWFBlockMethod) destroySWFImportBlock;	BLOCK(iblock)->isDefined = 0;	BLOCK(iblock)->completed = 0;	iblock->filename = cpy(filename);	iblock->importlist = NULL;	return iblock;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?