author | ecalot
<ecalot> 2005-06-14 12:06:27 UTC |
committer | ecalot
<ecalot> 2005-06-14 12:06:27 UTC |
parent | 211808f43ced279499983fd09bfaf91e190257b4 |
PR/src/Makefile | +37 | -29 |
PR/src/lib/layers/autodetect.c | +2 | -297 |
PR/src/lib/layers/idlist.c | +2 | -157 |
PR/src/lib/xml/tree.c | +1 | -255 |
PR/src/lib/xml/unknown.c | +1 | -255 |
diff --git a/PR/src/Makefile b/PR/src/Makefile index e343cca..edb41f8 100644 --- a/PR/src/Makefile +++ b/PR/src/Makefile @@ -51,16 +51,16 @@ else LINKERRELEASE = -s endif -FILES = .import.o .export.o .resources.o .classify.o .disk.o\ - .dat.o .bmp.o .mid.o .pal.o .wav.o .plv.o\ - .memory.o .pr.o .list.o .reslist.o - -XML = .parse.o .search.o +ACTIONS = .import.o .export.o .classify.o +XML = .parse.o .search.o .resources.o COMPRESS = .compress.o .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o +LAYERS = .dat.o .memory.o .list.o .reslist.o .disk.o .idlist.o .autodetect.o +FORMAT = .bmp.o .mid.o .pal.o .wav.o .plv.o CONSOLE = .main.o .filedir.o +MAIN = .pr.o -EXEOBJ = $(FILES) $(XML) $(COMPRESS) $(CONSOLE) $(PORTS) -LIBOBJ = $(FILES) $(XML) $(COMPRESS) $(PORTS) +EXEOBJ = $(MAIN) $(XML) $(COMPRESS) $(ACTIONS) $(LAYERS) $(FORMAT) $(PORTS) $(CONSOLE) +LIBOBJ = $(MAIN) $(XML) $(COMPRESS) $(ACTIONS) $(LAYERS) $(FORMAT) $(PORTS) EXEFILE = bin/pr XMLFILE = bin/resources.xml @@ -117,14 +117,34 @@ $(XMLFILE): xml/resources.xml $(INFO) Compiling import module... $(CC) $(OPTIONS) -c lib/actions/import.c -o $@ -.memory.o: lib/layers/memory.c include/memory.h - $(INFO) Compiling memory manager... - $(CC) $(OPTIONS) -c lib/layers/memory.c -o $@ +.classify.o: lib/actions/classify.c include/classify.h include/common.h include/dat.h include/disk.h include/memory.h include/resources.h + $(INFO) Compiling classification module... + $(CC) $(OPTIONS) -c lib/actions/classify.c -o $@ .export.o: lib/actions/export.c include/bmp.h include/common.h include/dat.h include/disk.h include/export.h include/memory.h include/mid.h include/pal.h include/plv.h include/reslist.h include/wav.h $(INFO) Compiling export module... $(CC) $(OPTIONS) -c lib/actions/export.c -o $@ +.autodetect.o: lib/layers/autodetect.c include/common.h include/compress.h include/disk.h include/memory.h include/resources.h include/xmlsearch.h + $(INFO) Compiling resource autodetection module... + $(CC) $(OPTIONS) -c lib/layers/autodetect.c -o $@ + +.idlist.o: lib/layers/idlist.c include/common.h include/compress.h include/disk.h include/memory.h include/resources.h include/xmlsearch.h + $(INFO) Compiling id list layer... + $(CC) $(OPTIONS) -c lib/layers/idlist.c -o $@ + +.disk.o: lib/layers/disk.c include/common.h include/direntwin.h include/disk.h include/memory.h include/xmlparse.h + $(INFO) Compiling disk access library... + $(CC) $(OPTIONS) -c lib/layers/disk.c -o $@ + +.dat.o: lib/layers/dat.c include/common.h include/dat.h include/disk.h include/reslist.h + $(INFO) Compiling DAT editing library... + $(CC) $(OPTIONS) -c lib/layers/dat.c -o $@ + +.memory.o: lib/layers/memory.c include/memory.h + $(INFO) Compiling memory manager... + $(CC) $(OPTIONS) -c lib/layers/memory.c -o $@ + .list.o: lib/layers/list.c include/list.h $(INFO) Compiling list implementation... $(CC) $(OPTIONS) -c lib/layers/list.c -o $@ @@ -153,25 +173,21 @@ $(XMLFILE): xml/resources.xml $(INFO) Compiling RLE uncompression module... $(CC) $(OPTIONS) -c lib/compression/rle_uncompress.c -o $@ -.main.o: console/main.c include/common.h include/compress.h include/disk.h include/filedir.h include/getopt.h include/memory.h include/xmlparse.h - $(INFO) Compiling command parsing module for standard mode... - $(CC) $(OPTIONS) -c console/main.c -o $@ - .pr.o: lib/pr.c include/classify.h include/common.h include/compress.h include/disk.h include/export.h include/import.h include/memory.h $(INFO) Compiling main library primitives for both modes... $(CC) $(OPTIONS) -c lib/pr.c -o $@ +.main.o: console/main.c include/common.h include/compress.h include/disk.h include/filedir.h include/getopt.h include/memory.h include/xmlparse.h + $(INFO) Compiling command parsing module for standard mode... + $(CC) $(OPTIONS) -c console/main.c -o $@ + .filedir.o: console/filedir.c include/disk.h include/memory.h include/xmlsearch.h $(INFO) Compiling directory and recursive file reading module for standard mode... $(CC) $(OPTIONS) -c console/filedir.c -o $@ -.resources.o: lib/resources.c include/common.h include/compress.h include/disk.h include/memory.h include/resources.h include/xmlsearch.h - $(INFO) Compiling resource manager module... - $(CC) $(OPTIONS) -c lib/resources.c -o $@ - -.classify.o: lib/actions/classify.c include/classify.h include/common.h include/dat.h include/disk.h include/memory.h include/resources.h - $(INFO) Compiling classification module... - $(CC) $(OPTIONS) -c lib/actions/classify.c -o $@ +.resources.o: lib/xml/resources.c include/common.h include/compress.h include/disk.h include/memory.h include/resources.h include/xmlsearch.h + $(INFO) Compiling XML resource reading module... + $(CC) $(OPTIONS) -c lib/xml/resources.c -o $@ .parse.o: lib/xml/parse.c include/common.h include/disk.h include/memory.h include/xmlparse.h $(INFO) Compiling XML parsing module... @@ -181,14 +197,6 @@ $(XMLFILE): xml/resources.xml $(INFO) Compiling XML search features... $(CC) $(OPTIONS) -c lib/xml/search.c -o $@ -.disk.o: lib/layers/disk.c include/common.h include/direntwin.h include/disk.h include/memory.h include/xmlparse.h - $(INFO) Compiling disk access library... - $(CC) $(OPTIONS) -c lib/layers/disk.c -o $@ - -.dat.o: lib/layers/dat.c include/common.h include/dat.h include/disk.h include/reslist.h - $(INFO) Compiling DAT editing library... - $(CC) $(OPTIONS) -c lib/layers/dat.c -o $@ - .bmp.o: lib/formats/bmp.c include/bmp.h include/common.h include/dat.h include/disk.h include/memory.h $(INFO) Compiling bitmap files support \(bmp\)... $(CC) $(OPTIONS) -c lib/formats/bmp.c -o $@ diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c index a1d5a7d..6ed3413 100644 --- a/PR/src/lib/layers/autodetect.c +++ b/PR/src/lib/layers/autodetect.c @@ -19,7 +19,7 @@ */ /* -resources.c: Princed Resources : Resource Handler +autodetect.c: Princed Resources : Resource Handler \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf Copyright 2003 Princed Development Team Created: 24 Aug 2003 @@ -39,14 +39,7 @@ resources.c: Princed Resources : Resource Handler #include <stdio.h> #include <string.h> #include <stdlib.h> -#include "common.h" -#include "xmlsearch.h" -#include "disk.h" -#include "memory.h" -#include "resources.h" -#include "compress.h" - -extern FILE* outputStream; +#include "reslist.h" /***************************************************************\ | Item Type Detector | @@ -104,291 +97,3 @@ tResourceType verifyHeader(const unsigned char *array, int size) { return RES_TYPE_BINARY; } -/***************************************************************\ -| Partial Resource List Functions | -\***************************************************************/ - -static tResIdList partialList; - -int partialListActive() { - return partialList.count; -} - -#define PARSING_MAX_TOKEN_SIZE 200 - -void parseGivenPath(char* path) { - /* - PRE: partialList.list was not allocated - POST: - partialList.count=0 and partialList.list=NULL if all resources - path was trimed in the "@" - */ - - int i; - int separator=0; - int j=0; - int size; - char aux[PARSING_MAX_TOKEN_SIZE]; - - /* Check if the variable wasn't initialized before */ - if (partialList.count!=0) return; - partialList.list=NULL; - - /* Validates the NULL path */ - if (path==NULL) return; - - /* Erase the last "/" if exists. */ - if (path) { - size=strlen(path); - if (size>0) { - size--; - if (isDirSep(path,size)) path[size]=0; - } - } - - /* Locate the string separation */ - while (path[separator]&&path[separator]!='@') separator++; - - /* If no separation */ - if (!path[separator]) return; /* There was no separator */ - - /* Count values, separate them with '\0' and alloc memory */ - partialList.count=1; - path[separator]=0; /* Trim the path to the separator */ - i=++separator; - while(path[i]) { - if (path[i]==',') { - partialList.count++; - path[i]=0; - } - i++; - } - partialList.list=(tResIdListItem*)malloc(sizeof(tResIdListItem)*partialList.count); - - /* Parse values and save them in the list */ - for(i=separator;j!=partialList.count;i++) { - unsigned int value; - int converted; - char index[5]; - converted=sscanf(path+i,"%u:%5s",&value,index); - switch (converted) { - case 2: - partialList.list[j].type=eId; - partialList.list[j].field.id.value=value; - str5uppercpy(partialList.list[j].field.id.index,index); - break; - case 1: - partialList.list[j].type=eIdValue; - partialList.list[j].field.id.value=value; - break; - default: - partialList.list[j].type=eString; - aux[0]='/';aux[1]=0; - strcat(aux,path+i); - partialList.list[j].field.text=strallocandcopy(repairFolders(aux)); - break; - } - while (path[i]) i++; - j++; - } -} - -/* Code taken from PR 0.1 */ -int getMaskToken(const char texto[],char token[],int* i,int k) { - int j=0; - /* Copy text string until a space is found or the end of line is reached. - * In case the text diesn't fit inside the token it is truncated, but i is increased until the end of the token */ - char entreComillas=0; /* flag indicating if we are inside the quotation marks */ - while ((((entreComillas^=(texto[(*i)]=='"')) || (texto[*i]!=' ')) && ((j<k)?(token[j++]=texto[(*i)++]):(texto[(*i)++])))); - token[j]='\0'; - return (texto[((*i)++)-1]); -} - -int matches1(const char* text,const char* mask,int ptext, int pmask) { - /* - * Verify if the text matches in the mask. - * In case a wildcar * is found it recurses to itself - * Optimization: - * i) multiple contiguous wildcars are taken as single to avoid - * executing the recursivity of order O(n\xb2) more extra times. - * ii) a wildcard at the end of the mask is taken as the end of the - * comparission. No recursivity is needed to know that is true. - * - * " are ignored - * ? is interpreted as any character (including * and ? itself) - * - * Returns true in case it matches and false in case it doesn't - */ - - while (text[ptext]||mask[pmask]) { - if (mask[pmask]=='"') { - pmask++; - } else if (mask[pmask]=='?') { - pmask++; - if (!text[ptext]) return 0; - ptext++; - } else if (mask[pmask]=='*') { - int aux; - while (mask[pmask++]=='*'); /* optimization i */ - pmask--; - if (!mask[pmask]) return 1; /* optimization ii */ - while ((text[ptext]) && !(aux=matches1(text,mask,ptext++,pmask))); - return aux; - } else { - if (text[ptext]!=mask[pmask]) return 0; - ptext++; - pmask++; - } - } - return (text[ptext]==mask[pmask]); -} - -int matchesIn(const char* text,const char* mask) { - int i=0; - char token[PARSING_MAX_TOKEN_SIZE]; - char valor=0; - - /* - * matches in main function: partitionates the text using spaces and matches - * each token against the text - */ - while (getMaskToken(mask,token,&i,PARSING_MAX_TOKEN_SIZE) && !(valor=(valor || matches1(text,token,0,0)))); - return valor?1:matches1(text,token,0,0); -} - -int isInThePartialList(const char* vFile, tResourceId id) { - /* - Cases: - "path/path@" all files are false - "path/path" all files are true - "path/path@12file/jjj.bmp,777" only file "12file/jjj.bmp" and id 777 are true - "path/path@1,2,3" only ids 1, 2 and 3 are true - "path/path@12file/?mage1*.bmp" each file matching "12file/?mage1*.bmp" is true - */ - int i; - - if (!partialList.count) return 1; - - for (i=0;i<partialList.count;i++) { - switch (partialList.list[i].type) { - case eIdValue: - if (id.value==partialList.list[i].field.id.value) return 1; - break; - case eString: - if (vFile && matchesIn(repairFolders(vFile),partialList.list[i].field.text)) return 1; - break; - case eId: - if (!resIdCmp(id,partialList.list[i].field.id)) return 1; - break; - } - } - return 0; -} - -void freePartialList() { - int i; - for (i=0;i<partialList.count;i++) { - if (partialList.list[i].type==eString) - free(partialList.list[i].field.text); - } - free(partialList.list); - partialList.count=0; -} - -/***************************************************************\ -| Parsing resource file | -\***************************************************************/ - -/* parse file */ -int parseFile(const char* vFile, const char* datFile, tResourceList *r) { - /* Declare error variable */ - int error; - tPassWork pass; - tTag* structure; - - /* Generate xml structure if doesn't exist */ - if ((error=parseStructure(vFile,&structure))) return error; - - /* Use the xml structure to Generate the resource structure of the file */ - pass.datFile=datFile; - pass.r=r; - workTree(structure,&pass,workTag); - - /* All done */ - return PR_RESULT_SUCCESS; -} - -/***************************************************************\ -| Unknown.xml primitives | -\***************************************************************/ - -/* Resources output to xml functions. Private+abstract variable */ -static FILE* unknownXmlFile=NULL; - -char* toLower(const char* txt) { - static char ret[5]; - char* r=ret; - while (*txt) { - *r=(('A'<=(*txt)) && ((*txt)<='Z'))?(*txt)|0x20:*txt; - r++; - txt++; - } - *r=0; - return ret; -} - -void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,char type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count) { - /* Open file if not open */ - if (unknownXmlFile==NULL) { - char xmlFile[MAX_FILENAME_SIZE]; - sprintf(xmlFile,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_XML,vDirExt,vFiledatWithPath); - - /* Open file */ - if (!writeOpen(xmlFile,&unknownXmlFile,optionflag)) return; - - /* Save headers */ - if (type==6) pal=id; - fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, - vFiledat,vFiledatWithPath,pal.value,toLower(pal.index) - ); - } - - /* Write item */ - fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, - id.value,toLower(id.index),getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count - ); /* To the xml output */ -} - -static unsigned int typeCount[RES_TYPECOUNT]; /* initialized in 0 */ - -void endUnknownXml(int optionflag, const char* backupExtension) { - if (unknownXmlFile!=NULL) { - int i; - fwrite(RES_XML_UNKNOWN_END,1,sizeof(RES_XML_UNKNOWN_END)-1,unknownXmlFile); - writeCloseOk(unknownXmlFile,optionflag,backupExtension); - unknownXmlFile=NULL; - for (i=0;i<RES_TYPECOUNT;i++) typeCount[i]=0; - } -} - -/***************************************************************\ -| Resources extra functions | -\***************************************************************/ - -void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension) { - static const char* extarray[]=RES_FILE_EXTENSIONS; - int pos; - - if (r->path==NULL) { - pos=((r->type<RES_TYPECOUNT)&&(r->type>=0))?r->type:RES_TYPE_BINARY; - typeCount[pos]++; - - /* set filename */ - sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vDatFileName,getExtDesc(pos),typeCount[pos],extarray[pos]); - AddToUnknownXml(vDatFileName,r->id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos]); - } else { - /* set filename */ - sprintf(vFileext,"%s/%s",vDirExt,r->path); - } -} - diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c index a1d5a7d..e9ab0bd 100644 --- a/PR/src/lib/layers/idlist.c +++ b/PR/src/lib/layers/idlist.c @@ -19,8 +19,8 @@ */ /* -resources.c: Princed Resources : Resource Handler -\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf +idlist.c: Princed Resources : Partial Id list +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf Copyright 2003 Princed Development Team Created: 24 Aug 2003 @@ -46,64 +46,6 @@ resources.c: Princed Resources : Resource Handler #include "resources.h" #include "compress.h" -extern FILE* outputStream; - -/***************************************************************\ -| Item Type Detector | -\***************************************************************/ - -int verifyLevelHeader(const unsigned char *array, int size) { - return (((size==2306)||(size==2305))&&!(array[1698]&0x0F)&&!(array[1700]&0x0F)&&!(array[1702]&0x0F)); -} - -int verifyImageHeader(const unsigned char *array, int size) { - unsigned char imageBitRate; - imageBitRate=((unsigned char)array[6]&0xF0); - return (size>7) && (!array[5]) && ((imageBitRate==0xB0)); - /* return (size>7) && (!array[5]) && ((imageBitRate==0xB0)||(imageBitRate==0x00)); */ -} - -int verifyPaletteHeader(const unsigned char *array, int size) { - /* this is only pop2 palette */ - return ((size==101)&&(!array[2])&&(!array[3])&&(array[4]==0x10)); -} - -int verifySpeakerHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x00)+(even number)+3 bytes per note */ - return - (size>4)&&(array[1]==0x00)&&(!(array[2]%2))&&(!(size%3)) - ; -} - -int verifyWaveHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x01)+raw wave */ - return - (size>1)&&(array[1]==0x01)&&((size%3)==2) - ; -} - -int verifyMidiHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x02)+"MThd"... */ - return - (size>6) && - (array[1]==0x02) && - (array[2]=='M') && - (array[3]=='T') && - (array[4]=='h') && - (array[5]=='d') - ; -} - -tResourceType verifyHeader(const unsigned char *array, int size) { - if (verifyLevelHeader (array,size)) return RES_TYPE_LEVEL; - if (verifyMidiHeader (array,size)) return RES_TYPE_MIDI; - if (verifyImageHeader (array,size)) return RES_TYPE_IMAGE; - if (verifyPaletteHeader(array,size)) return RES_TYPE_PALETTE; - if (verifyWaveHeader (array,size)) return RES_TYPE_WAVE; - if (verifySpeakerHeader(array,size)) return RES_TYPE_PCSPEAKER; - return RES_TYPE_BINARY; -} - /***************************************************************\ | Partial Resource List Functions | \***************************************************************/ @@ -295,100 +237,3 @@ void freePartialList() { partialList.count=0; } -/***************************************************************\ -| Parsing resource file | -\***************************************************************/ - -/* parse file */ -int parseFile(const char* vFile, const char* datFile, tResourceList *r) { - /* Declare error variable */ - int error; - tPassWork pass; - tTag* structure; - - /* Generate xml structure if doesn't exist */ - if ((error=parseStructure(vFile,&structure))) return error; - - /* Use the xml structure to Generate the resource structure of the file */ - pass.datFile=datFile; - pass.r=r; - workTree(structure,&pass,workTag); - - /* All done */ - return PR_RESULT_SUCCESS; -} - -/***************************************************************\ -| Unknown.xml primitives | -\***************************************************************/ - -/* Resources output to xml functions. Private+abstract variable */ -static FILE* unknownXmlFile=NULL; - -char* toLower(const char* txt) { - static char ret[5]; - char* r=ret; - while (*txt) { - *r=(('A'<=(*txt)) && ((*txt)<='Z'))?(*txt)|0x20:*txt; - r++; - txt++; - } - *r=0; - return ret; -} - -void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,char type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count) { - /* Open file if not open */ - if (unknownXmlFile==NULL) { - char xmlFile[MAX_FILENAME_SIZE]; - sprintf(xmlFile,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_XML,vDirExt,vFiledatWithPath); - - /* Open file */ - if (!writeOpen(xmlFile,&unknownXmlFile,optionflag)) return; - - /* Save headers */ - if (type==6) pal=id; - fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, - vFiledat,vFiledatWithPath,pal.value,toLower(pal.index) - ); - } - - /* Write item */ - fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, - id.value,toLower(id.index),getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count - ); /* To the xml output */ -} - -static unsigned int typeCount[RES_TYPECOUNT]; /* initialized in 0 */ - -void endUnknownXml(int optionflag, const char* backupExtension) { - if (unknownXmlFile!=NULL) { - int i; - fwrite(RES_XML_UNKNOWN_END,1,sizeof(RES_XML_UNKNOWN_END)-1,unknownXmlFile); - writeCloseOk(unknownXmlFile,optionflag,backupExtension); - unknownXmlFile=NULL; - for (i=0;i<RES_TYPECOUNT;i++) typeCount[i]=0; - } -} - -/***************************************************************\ -| Resources extra functions | -\***************************************************************/ - -void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension) { - static const char* extarray[]=RES_FILE_EXTENSIONS; - int pos; - - if (r->path==NULL) { - pos=((r->type<RES_TYPECOUNT)&&(r->type>=0))?r->type:RES_TYPE_BINARY; - typeCount[pos]++; - - /* set filename */ - sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vDatFileName,getExtDesc(pos),typeCount[pos],extarray[pos]); - AddToUnknownXml(vDatFileName,r->id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos]); - } else { - /* set filename */ - sprintf(vFileext,"%s/%s",vDirExt,r->path); - } -} - diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c index a1d5a7d..e8f267e 100644 --- a/PR/src/lib/xml/tree.c +++ b/PR/src/lib/xml/tree.c @@ -44,259 +44,9 @@ resources.c: Princed Resources : Resource Handler #include "disk.h" #include "memory.h" #include "resources.h" -#include "compress.h" - -extern FILE* outputStream; /***************************************************************\ -| Item Type Detector | -\***************************************************************/ - -int verifyLevelHeader(const unsigned char *array, int size) { - return (((size==2306)||(size==2305))&&!(array[1698]&0x0F)&&!(array[1700]&0x0F)&&!(array[1702]&0x0F)); -} - -int verifyImageHeader(const unsigned char *array, int size) { - unsigned char imageBitRate; - imageBitRate=((unsigned char)array[6]&0xF0); - return (size>7) && (!array[5]) && ((imageBitRate==0xB0)); - /* return (size>7) && (!array[5]) && ((imageBitRate==0xB0)||(imageBitRate==0x00)); */ -} - -int verifyPaletteHeader(const unsigned char *array, int size) { - /* this is only pop2 palette */ - return ((size==101)&&(!array[2])&&(!array[3])&&(array[4]==0x10)); -} - -int verifySpeakerHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x00)+(even number)+3 bytes per note */ - return - (size>4)&&(array[1]==0x00)&&(!(array[2]%2))&&(!(size%3)) - ; -} - -int verifyWaveHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x01)+raw wave */ - return - (size>1)&&(array[1]==0x01)&&((size%3)==2) - ; -} - -int verifyMidiHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x02)+"MThd"... */ - return - (size>6) && - (array[1]==0x02) && - (array[2]=='M') && - (array[3]=='T') && - (array[4]=='h') && - (array[5]=='d') - ; -} - -tResourceType verifyHeader(const unsigned char *array, int size) { - if (verifyLevelHeader (array,size)) return RES_TYPE_LEVEL; - if (verifyMidiHeader (array,size)) return RES_TYPE_MIDI; - if (verifyImageHeader (array,size)) return RES_TYPE_IMAGE; - if (verifyPaletteHeader(array,size)) return RES_TYPE_PALETTE; - if (verifyWaveHeader (array,size)) return RES_TYPE_WAVE; - if (verifySpeakerHeader(array,size)) return RES_TYPE_PCSPEAKER; - return RES_TYPE_BINARY; -} - -/***************************************************************\ -| Partial Resource List Functions | -\***************************************************************/ - -static tResIdList partialList; - -int partialListActive() { - return partialList.count; -} - -#define PARSING_MAX_TOKEN_SIZE 200 - -void parseGivenPath(char* path) { - /* - PRE: partialList.list was not allocated - POST: - partialList.count=0 and partialList.list=NULL if all resources - path was trimed in the "@" - */ - - int i; - int separator=0; - int j=0; - int size; - char aux[PARSING_MAX_TOKEN_SIZE]; - - /* Check if the variable wasn't initialized before */ - if (partialList.count!=0) return; - partialList.list=NULL; - - /* Validates the NULL path */ - if (path==NULL) return; - - /* Erase the last "/" if exists. */ - if (path) { - size=strlen(path); - if (size>0) { - size--; - if (isDirSep(path,size)) path[size]=0; - } - } - - /* Locate the string separation */ - while (path[separator]&&path[separator]!='@') separator++; - - /* If no separation */ - if (!path[separator]) return; /* There was no separator */ - - /* Count values, separate them with '\0' and alloc memory */ - partialList.count=1; - path[separator]=0; /* Trim the path to the separator */ - i=++separator; - while(path[i]) { - if (path[i]==',') { - partialList.count++; - path[i]=0; - } - i++; - } - partialList.list=(tResIdListItem*)malloc(sizeof(tResIdListItem)*partialList.count); - - /* Parse values and save them in the list */ - for(i=separator;j!=partialList.count;i++) { - unsigned int value; - int converted; - char index[5]; - converted=sscanf(path+i,"%u:%5s",&value,index); - switch (converted) { - case 2: - partialList.list[j].type=eId; - partialList.list[j].field.id.value=value; - str5uppercpy(partialList.list[j].field.id.index,index); - break; - case 1: - partialList.list[j].type=eIdValue; - partialList.list[j].field.id.value=value; - break; - default: - partialList.list[j].type=eString; - aux[0]='/';aux[1]=0; - strcat(aux,path+i); - partialList.list[j].field.text=strallocandcopy(repairFolders(aux)); - break; - } - while (path[i]) i++; - j++; - } -} - -/* Code taken from PR 0.1 */ -int getMaskToken(const char texto[],char token[],int* i,int k) { - int j=0; - /* Copy text string until a space is found or the end of line is reached. - * In case the text diesn't fit inside the token it is truncated, but i is increased until the end of the token */ - char entreComillas=0; /* flag indicating if we are inside the quotation marks */ - while ((((entreComillas^=(texto[(*i)]=='"')) || (texto[*i]!=' ')) && ((j<k)?(token[j++]=texto[(*i)++]):(texto[(*i)++])))); - token[j]='\0'; - return (texto[((*i)++)-1]); -} - -int matches1(const char* text,const char* mask,int ptext, int pmask) { - /* - * Verify if the text matches in the mask. - * In case a wildcar * is found it recurses to itself - * Optimization: - * i) multiple contiguous wildcars are taken as single to avoid - * executing the recursivity of order O(n\xb2) more extra times. - * ii) a wildcard at the end of the mask is taken as the end of the - * comparission. No recursivity is needed to know that is true. - * - * " are ignored - * ? is interpreted as any character (including * and ? itself) - * - * Returns true in case it matches and false in case it doesn't - */ - - while (text[ptext]||mask[pmask]) { - if (mask[pmask]=='"') { - pmask++; - } else if (mask[pmask]=='?') { - pmask++; - if (!text[ptext]) return 0; - ptext++; - } else if (mask[pmask]=='*') { - int aux; - while (mask[pmask++]=='*'); /* optimization i */ - pmask--; - if (!mask[pmask]) return 1; /* optimization ii */ - while ((text[ptext]) && !(aux=matches1(text,mask,ptext++,pmask))); - return aux; - } else { - if (text[ptext]!=mask[pmask]) return 0; - ptext++; - pmask++; - } - } - return (text[ptext]==mask[pmask]); -} - -int matchesIn(const char* text,const char* mask) { - int i=0; - char token[PARSING_MAX_TOKEN_SIZE]; - char valor=0; - - /* - * matches in main function: partitionates the text using spaces and matches - * each token against the text - */ - while (getMaskToken(mask,token,&i,PARSING_MAX_TOKEN_SIZE) && !(valor=(valor || matches1(text,token,0,0)))); - return valor?1:matches1(text,token,0,0); -} - -int isInThePartialList(const char* vFile, tResourceId id) { - /* - Cases: - "path/path@" all files are false - "path/path" all files are true - "path/path@12file/jjj.bmp,777" only file "12file/jjj.bmp" and id 777 are true - "path/path@1,2,3" only ids 1, 2 and 3 are true - "path/path@12file/?mage1*.bmp" each file matching "12file/?mage1*.bmp" is true - */ - int i; - - if (!partialList.count) return 1; - - for (i=0;i<partialList.count;i++) { - switch (partialList.list[i].type) { - case eIdValue: - if (id.value==partialList.list[i].field.id.value) return 1; - break; - case eString: - if (vFile && matchesIn(repairFolders(vFile),partialList.list[i].field.text)) return 1; - break; - case eId: - if (!resIdCmp(id,partialList.list[i].field.id)) return 1; - break; - } - } - return 0; -} - -void freePartialList() { - int i; - for (i=0;i<partialList.count;i++) { - if (partialList.list[i].type==eString) - free(partialList.list[i].field.text); - } - free(partialList.list); - partialList.count=0; -} - -/***************************************************************\ -| Parsing resource file | +| Filtering xml structure to tResourceList | \***************************************************************/ /* parse file */ @@ -371,10 +121,6 @@ void endUnknownXml(int optionflag, const char* backupExtension) { } } -/***************************************************************\ -| Resources extra functions | -\***************************************************************/ - void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension) { static const char* extarray[]=RES_FILE_EXTENSIONS; int pos; diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c index a1d5a7d..e8f267e 100644 --- a/PR/src/lib/xml/unknown.c +++ b/PR/src/lib/xml/unknown.c @@ -44,259 +44,9 @@ resources.c: Princed Resources : Resource Handler #include "disk.h" #include "memory.h" #include "resources.h" -#include "compress.h" - -extern FILE* outputStream; /***************************************************************\ -| Item Type Detector | -\***************************************************************/ - -int verifyLevelHeader(const unsigned char *array, int size) { - return (((size==2306)||(size==2305))&&!(array[1698]&0x0F)&&!(array[1700]&0x0F)&&!(array[1702]&0x0F)); -} - -int verifyImageHeader(const unsigned char *array, int size) { - unsigned char imageBitRate; - imageBitRate=((unsigned char)array[6]&0xF0); - return (size>7) && (!array[5]) && ((imageBitRate==0xB0)); - /* return (size>7) && (!array[5]) && ((imageBitRate==0xB0)||(imageBitRate==0x00)); */ -} - -int verifyPaletteHeader(const unsigned char *array, int size) { - /* this is only pop2 palette */ - return ((size==101)&&(!array[2])&&(!array[3])&&(array[4]==0x10)); -} - -int verifySpeakerHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x00)+(even number)+3 bytes per note */ - return - (size>4)&&(array[1]==0x00)&&(!(array[2]%2))&&(!(size%3)) - ; -} - -int verifyWaveHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x01)+raw wave */ - return - (size>1)&&(array[1]==0x01)&&((size%3)==2) - ; -} - -int verifyMidiHeader(const unsigned char *array, int size) { - /* format: (checksum)+(0x02)+"MThd"... */ - return - (size>6) && - (array[1]==0x02) && - (array[2]=='M') && - (array[3]=='T') && - (array[4]=='h') && - (array[5]=='d') - ; -} - -tResourceType verifyHeader(const unsigned char *array, int size) { - if (verifyLevelHeader (array,size)) return RES_TYPE_LEVEL; - if (verifyMidiHeader (array,size)) return RES_TYPE_MIDI; - if (verifyImageHeader (array,size)) return RES_TYPE_IMAGE; - if (verifyPaletteHeader(array,size)) return RES_TYPE_PALETTE; - if (verifyWaveHeader (array,size)) return RES_TYPE_WAVE; - if (verifySpeakerHeader(array,size)) return RES_TYPE_PCSPEAKER; - return RES_TYPE_BINARY; -} - -/***************************************************************\ -| Partial Resource List Functions | -\***************************************************************/ - -static tResIdList partialList; - -int partialListActive() { - return partialList.count; -} - -#define PARSING_MAX_TOKEN_SIZE 200 - -void parseGivenPath(char* path) { - /* - PRE: partialList.list was not allocated - POST: - partialList.count=0 and partialList.list=NULL if all resources - path was trimed in the "@" - */ - - int i; - int separator=0; - int j=0; - int size; - char aux[PARSING_MAX_TOKEN_SIZE]; - - /* Check if the variable wasn't initialized before */ - if (partialList.count!=0) return; - partialList.list=NULL; - - /* Validates the NULL path */ - if (path==NULL) return; - - /* Erase the last "/" if exists. */ - if (path) { - size=strlen(path); - if (size>0) { - size--; - if (isDirSep(path,size)) path[size]=0; - } - } - - /* Locate the string separation */ - while (path[separator]&&path[separator]!='@') separator++; - - /* If no separation */ - if (!path[separator]) return; /* There was no separator */ - - /* Count values, separate them with '\0' and alloc memory */ - partialList.count=1; - path[separator]=0; /* Trim the path to the separator */ - i=++separator; - while(path[i]) { - if (path[i]==',') { - partialList.count++; - path[i]=0; - } - i++; - } - partialList.list=(tResIdListItem*)malloc(sizeof(tResIdListItem)*partialList.count); - - /* Parse values and save them in the list */ - for(i=separator;j!=partialList.count;i++) { - unsigned int value; - int converted; - char index[5]; - converted=sscanf(path+i,"%u:%5s",&value,index); - switch (converted) { - case 2: - partialList.list[j].type=eId; - partialList.list[j].field.id.value=value; - str5uppercpy(partialList.list[j].field.id.index,index); - break; - case 1: - partialList.list[j].type=eIdValue; - partialList.list[j].field.id.value=value; - break; - default: - partialList.list[j].type=eString; - aux[0]='/';aux[1]=0; - strcat(aux,path+i); - partialList.list[j].field.text=strallocandcopy(repairFolders(aux)); - break; - } - while (path[i]) i++; - j++; - } -} - -/* Code taken from PR 0.1 */ -int getMaskToken(const char texto[],char token[],int* i,int k) { - int j=0; - /* Copy text string until a space is found or the end of line is reached. - * In case the text diesn't fit inside the token it is truncated, but i is increased until the end of the token */ - char entreComillas=0; /* flag indicating if we are inside the quotation marks */ - while ((((entreComillas^=(texto[(*i)]=='"')) || (texto[*i]!=' ')) && ((j<k)?(token[j++]=texto[(*i)++]):(texto[(*i)++])))); - token[j]='\0'; - return (texto[((*i)++)-1]); -} - -int matches1(const char* text,const char* mask,int ptext, int pmask) { - /* - * Verify if the text matches in the mask. - * In case a wildcar * is found it recurses to itself - * Optimization: - * i) multiple contiguous wildcars are taken as single to avoid - * executing the recursivity of order O(n\xb2) more extra times. - * ii) a wildcard at the end of the mask is taken as the end of the - * comparission. No recursivity is needed to know that is true. - * - * " are ignored - * ? is interpreted as any character (including * and ? itself) - * - * Returns true in case it matches and false in case it doesn't - */ - - while (text[ptext]||mask[pmask]) { - if (mask[pmask]=='"') { - pmask++; - } else if (mask[pmask]=='?') { - pmask++; - if (!text[ptext]) return 0; - ptext++; - } else if (mask[pmask]=='*') { - int aux; - while (mask[pmask++]=='*'); /* optimization i */ - pmask--; - if (!mask[pmask]) return 1; /* optimization ii */ - while ((text[ptext]) && !(aux=matches1(text,mask,ptext++,pmask))); - return aux; - } else { - if (text[ptext]!=mask[pmask]) return 0; - ptext++; - pmask++; - } - } - return (text[ptext]==mask[pmask]); -} - -int matchesIn(const char* text,const char* mask) { - int i=0; - char token[PARSING_MAX_TOKEN_SIZE]; - char valor=0; - - /* - * matches in main function: partitionates the text using spaces and matches - * each token against the text - */ - while (getMaskToken(mask,token,&i,PARSING_MAX_TOKEN_SIZE) && !(valor=(valor || matches1(text,token,0,0)))); - return valor?1:matches1(text,token,0,0); -} - -int isInThePartialList(const char* vFile, tResourceId id) { - /* - Cases: - "path/path@" all files are false - "path/path" all files are true - "path/path@12file/jjj.bmp,777" only file "12file/jjj.bmp" and id 777 are true - "path/path@1,2,3" only ids 1, 2 and 3 are true - "path/path@12file/?mage1*.bmp" each file matching "12file/?mage1*.bmp" is true - */ - int i; - - if (!partialList.count) return 1; - - for (i=0;i<partialList.count;i++) { - switch (partialList.list[i].type) { - case eIdValue: - if (id.value==partialList.list[i].field.id.value) return 1; - break; - case eString: - if (vFile && matchesIn(repairFolders(vFile),partialList.list[i].field.text)) return 1; - break; - case eId: - if (!resIdCmp(id,partialList.list[i].field.id)) return 1; - break; - } - } - return 0; -} - -void freePartialList() { - int i; - for (i=0;i<partialList.count;i++) { - if (partialList.list[i].type==eString) - free(partialList.list[i].field.text); - } - free(partialList.list); - partialList.count=0; -} - -/***************************************************************\ -| Parsing resource file | +| Filtering xml structure to tResourceList | \***************************************************************/ /* parse file */ @@ -371,10 +121,6 @@ void endUnknownXml(int optionflag, const char* backupExtension) { } } -/***************************************************************\ -| Resources extra functions | -\***************************************************************/ - void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension) { static const char* extarray[]=RES_FILE_EXTENSIONS; int pos;