Esempio n. 1
0
BStream *BStream_new(void)
{
	BStream *self = (BStream *)calloc(1, sizeof(BStream));
	self->ba = ByteArray_new();
	self->ownsByteArray = 1;
	self->tmp = ByteArray_new();
	self->errorBa = ByteArray_new();
	self->index = 0;
	self->typeBuf = (unsigned char *)malloc(512);
	return self;
}
Esempio n. 2
0
File: pdf.c Progetto: db00/reader
//Method exposed to ActionScript
//Takes a String and echos it
static AS3_Val echo(void* self, AS3_Val args)
{
	AS3_Val byteArray;
	AS3_ArrayValue( args, "AS3ValType", &byteArray);
	AS3_Val length = AS3_GetS(byteArray, "length");  

	sztrace("length getted!");
	int len = AS3_IntValue(length);
	//if(len>0) return length;

	char *data=NULL;
	data=malloc(len);
	memset(data,0,len);
	int fileLen = AS3_ByteArray_readBytes(data,byteArray, len);
	char *out= NULL;
	out = malloc(fileLen);
	memset(out,0,fileLen);



	ByteArray * bytearray = ByteArray_new(fileLen);
	bytearray->data = data;

	PdfFile_free(PdfFile_parse(bytearray,out));
	ByteArray_free(bytearray);

	return AS3_String(out);
}
Esempio n. 3
0
File: pdf.c Progetto: db00/reader
int main(int argc,char**argv)
{
	char * filename;
	if(argc>1)
	{
		filename = argv[argc-1];
	}else{
		filename = "FFMPEG.pdf";
	}

	FILE * _file = fopen(filename,"rb");
	int fileLen = fseek(_file,0,SEEK_END);
	fileLen = ftell(_file);
	rewind(_file);
	printf("%s,%d\n",filename,fileLen);

	ByteArray * bytearray = ByteArray_new(fileLen);
	fread(bytearray->data,1,fileLen,_file);
	fclose(_file);

	char * out = malloc(fileLen);
	memset(out,0,fileLen);
	PdfFile_free(PdfFile_parse(bytearray,out));
	printf("%s\n",out);
	return 0;
}
Esempio n. 4
0
File: docx.c Progetto: db00/reader
int main(int argc,char **argv)
{
	char * filename;
	if(argc>1)
	{
		filename = argv[argc-1];
	}else{
		filename = "RAR.docx";
	}

	FILE * _file = fopen(filename,"rb");
	int fileLen = fseek(_file,0,SEEK_END);
	fileLen = ftell(_file);
	rewind(_file);
	printf("%s,%d\n",filename,fileLen);

	ByteArray * bytearray = ByteArray_new(fileLen);
	fread(bytearray->data,1,fileLen,_file);
	fclose(_file);

	char * out = malloc(fileLen*10);
	memset(out,0,fileLen*10);
	int outlen=0;
	//ZipFile_free(ZipFile_parser(bytearray,"",out,&outlen));
	ZipFile * zipfile = ZipFile_parser(bytearray,"word/document.xml",out,&outlen);
	//printf("\n%s",out);

	/*
	//<w:p 分段
	char **matched_arr=(char**)malloc(strlen(out));
	memset(matched_arr,0,strlen(out));
	//<w:t>文本</w:t>
	int len = regex_search_all(out,"/<w:t>([^<>]*)<\\/w:t>/",matched_arr);
	printf("%d\n",len);
	char * connected = string_concat(matched_arr,len,"");
	printf("%s",regex_replace_all(connected,"/<[\\/]*w:t>/",""));
	fflush(stdout);
	regex_matchedarrClear(matched_arr,len);
	*/


	xmlDocPtr doc = xmlParseMemory(out, strlen(out));
	//for(i=0;i<MAXNS;i++) xmlXPathRegisterNs(context,NSNAME[i],NS[i]);//  //默认ns :   @"//*[local-name()='price'] " 
	/*检查解析文档是否成功,如果不成功,libxml将指一个注册的错误并停止。一个常见错误是不适当的编码。XML标准文档除了用UTF-8或UTF-16外还可用其它编码保存。如果文档是这样,libxml将自动地为你转换到UTF-8。更多关于XML编码信息包含在XML标准中。*/
	if (doc == NULL )
	{
		fprintf(stderr,"Document not parsed successfully. \n");
		return -1;
	}

	xmlChar *xpath = (xmlChar*)"//w:p";
	xmlXPathObjectPtr app_result = get_nodeset(doc,xpath);
	if (app_result == NULL)
	{
		printf("app_result is NULL\n");
		return -4;
	}
	int i = 0;
	if(app_result)
	{
		xmlNodeSetPtr nodeset = app_result->nodesetval;
		for (i=0; i < nodeset->nodeNr; i++)
		{
			xmlNodePtr cur = nodeset->nodeTab[i];   
			xmlChar *value = xmlNodeGetContent(cur);
			printf("%s", (char *)value);
			xmlFree(value);
			//printf("name: %s\n", (char *)cur->name);
			/*
			   xmlNodePtr son = cur->xmlChildrenNode; 
			   while(son)
			   {  
			   value = xmlNodeGetContent(son);
			   if (value != NULL)
			   {
			   printf("%s", (char *)value);
			   xmlFree(value);
			   }
			   son = son->next;
			   }
			   */
			printf("\r\n");
		}
		//printf("\r\n");
		xmlXPathFreeObject (app_result);
	}

	xmlFreeDoc(doc); 



	ZipFile_free(zipfile);
	return 0;
}
Esempio n. 5
0
File: xlsx.c Progetto: db00/reader
int main(int argc,char **argv)
{
	char * filename;
	if(argc>1)
	{
		filename = argv[argc-1];
	}else{
		filename = "xls.xlsx";
	}

	FILE * _file = fopen(filename,"rb");
	int fileLen = fseek(_file,0,SEEK_END);
	fileLen = ftell(_file);
	rewind(_file);
	printf("%s,%d\n",filename,fileLen);

	ByteArray * bytearray = ByteArray_new(fileLen);
	fread(bytearray->data,1,fileLen,_file);
	fclose(_file);

	char * out = malloc(fileLen*10);
	memset(out,0,fileLen*10);
	int outlen=0;
	//ZipFile_free(ZipFile_parser(bytearray,"",out,&outlen));

	ZipFile * zipfile = ZipFile_parser(bytearray,"xl/sharedStrings.xml",out,&outlen);
	//printf("\n%s",out);
	ZipFile_free(zipfile);

	/*
	   char **matched_arr=(char**)malloc(strlen(out));
	   memset(matched_arr,0,strlen(out));
	//<w:t></w:t>
	int len = regex_search_all(out,"/<t>([^<>]*)<\\/t>/",matched_arr);
	printf("%d\n",len);
	char * connected = string_concat(matched_arr,len,"");
	printf("%s",regex_replace_all(connected,"/<[\\/]*w:t>/",""));
	fflush(stdout);
	*/
	xmlDocPtr string_doc = xmlParseMemory(out, strlen(out));
	if (string_doc== NULL )
	{
		fprintf(stderr,"Document not parsed successfully. \n");
		return -1;
	}

	xmlChar *xpath1 = (xmlChar*)("//ns:t");
	xmlXPathObjectPtr _result = get_nodeset(string_doc,xpath1);
	if (_result == NULL)
	{
		printf("_result is NULL\n");
		return -4;
	}
	int i;
	i = 0;
	xmlChar ** str_arr=NULL;
	if(_result)
	{
		xmlNodeSetPtr nodeset = _result->nodesetval;
		str_arr = malloc(sizeof(char**)*nodeset->nodeNr);
		memset(str_arr,0,sizeof(char**)*nodeset->nodeNr);
		for (i=0; i < nodeset->nodeNr; i++)
		{
			xmlNodePtr cur;  //定义结点指针(你需要它为了在各个结点间移动)
			cur = nodeset->nodeTab[i];   
			//printf("name: %s\n", (char *)cur->name);
			cur = cur->xmlChildrenNode; 
			while(cur!=NULL)
			{  
				xmlChar *value;
				value = xmlNodeGetContent(cur);
				str_arr[i]=value;
				if (value != NULL)
				{
					//printf("%s\t", (char *)value);
					//xmlFree(value);
				}
				cur = cur->next;
			}
			//printf("\r\n");
		}
		xmlXPathFreeObject (_result);
	}

	xmlFreeDoc(string_doc); 






	int sheetIndex = 0;
	while(1){
		sheetIndex++;
		memset(out,0,fileLen*10);
		// xl/worksheets/sheet1.xml
		char sheetName[64];
		memset(sheetName,0,64);
		sprintf(sheetName,"xl/worksheets/sheet%d.xml",sheetIndex);
		bytearray->position=0;
		ZipFile_free(ZipFile_parser(bytearray,sheetName,out,&outlen));
		//printf("\n%s\n",out);
		if(out==NULL || strlen(out)==0)
			break;

		xmlDocPtr doc = xmlParseMemory(out, strlen(out));
		if (doc == NULL )
		{
			fprintf(stderr,"Document not parsed successfully. \n");
			return -1;
		}

		xmlChar *xpath = (xmlChar*)("//ns:row");
		xmlXPathObjectPtr app_result = get_nodeset(doc,xpath);
		if (app_result == NULL)
		{
			printf("app_result is NULL\n");
			return -4;
		}
		if(app_result)
		{
			xmlNodeSetPtr nodeset = app_result->nodesetval;
			xmlNodePtr cur = nodeset->nodeTab[0];   
			while(cur)
			{
				//printf("name: %s\n", (char *)cur->name);
				xmlNodePtr son = cur->xmlChildrenNode;
				while(son)
				{  
					xmlChar *value;
					xmlChar* prop = xmlGetProp(son, (const xmlChar*)"t");  
					//if(prop) printf("prop:%s",prop);
					value = xmlNodeGetContent(son);
					if (value != NULL)
					{
						if(prop && strcmp("s",(char*)prop)==0)
						{
							//printf("====%s\t", (char *)value);
							printf("%s\t", (char *)str_arr[atoi((char*)value)]);
						}else{
							printf("%s\t", (char *)value);
						}
						xmlFree(value);
					}
					son = son->next;
					xmlFree(prop); 
				}
				printf("\r\n");
				cur = cur->next;
			}
			printf("\r\n");
			xmlXPathFreeObject (app_result);
		}
		xmlFreeDoc(doc); 
	}



	/*
	   xmlNodePtr cur;  //定义结点指针(你需要它为了在各个结点间移动)
	   cur = xmlDocGetRootElement(doc);  //确定文档根元素
	   if (cur == NULL)
	   {
	   fprintf(stderr,"empty document\n");
	   xmlFreeDoc(doc);
	   return -2;
	   }
	   if (xmlStrcmp(cur->name, (const xmlChar *) "worksheet"))
	   {
	   xmlFreeDoc(doc);
	   return -3;
	   }
	   cur = cur->xmlChildrenNode;
	   while(cur!=NULL)
	   {
	   xmlNodePtr son = cur->children;
	   while(son){
		//xmlChar* prop = xmlGetProp(son, "spans");  
		//printf("\n%s,%s",son->name,prop);

		xmlChar *key;
		if ((!xmlStrcmp(son->name, (const xmlChar *)"sheetData")))
		{
		key = xmlNodeListGetString(doc, son->xmlChildrenNode, 1);
		printf("keyword: %s\n", key);
		xmlFree(key);
		}
		son = son->next;
		}
		cur = cur->next;
		}
		*/





		return 0;
		//regex_matchedarrClear(matched_arr,len);
}