author | ecalot
<ecalot> 2006-02-20 03:43:15 UTC |
committer | ecalot
<ecalot> 2006-02-20 03:43:15 UTC |
parent | 91f2d85463173312902bd7639b3f8dbc5d98e8f7 |
PR/src/include/disk.h | +3 | -1 |
PR/src/lib/actions/classify.c | +11 | -10 |
PR/src/lib/actions/import.c | +5 | -2 |
PR/src/lib/xml/parse.c | +11 | -8 |
diff --git a/PR/src/include/disk.h b/PR/src/include/disk.h index 3f1097c..fad1792 100644 --- a/PR/src/include/disk.h +++ b/PR/src/include/disk.h @@ -54,6 +54,8 @@ disk.h: Princed Resources : Disk Access & File handling prototypes #define DIR_SEPARATOR '\\' #endif +#include "binary.h" + typedef enum {eFile,eDirectory,eNotFound}whatIs; #define charToUpper(a) ((a)&0xDF) @@ -63,7 +65,7 @@ typedef enum {eFile,eDirectory,eNotFound}whatIs; int writeData (const unsigned char* data, int ignoreChars, const char* vFileext, int size, int optionflag,const char* backupExtension); int writeOpen (const char* vFileext, FILE* *fp, int optionflag); int writeClose (FILE* fp,int dontSave,int optionflag,const char* backupExtension); -int mLoadFileArray(const char* vFile,unsigned char** array); +tBinary mLoadFileArray(const char* vFile); int makebase (const char* p); const char* repairFolders(const char* a); const char* getFileNameFromPath(const char* path); diff --git a/PR/src/lib/actions/classify.c b/PR/src/lib/actions/classify.c index c3ae529..feab167 100644 --- a/PR/src/lib/actions/classify.c +++ b/PR/src/lib/actions/classify.c @@ -84,15 +84,16 @@ int prClassify(const char* fileName) { result=prClassifyDat(fileName); if (!result) { /* it's not a DAT file*/ - long int fileSize; - unsigned char* fileData; + /*long int fileContent.size; + unsigned char* fileData;*/ + tBinary fileContent; /* let's get it's content and see what it is */ - fileSize=mLoadFileArray(fileName,&fileData); - if (fileSize<=0) return fileSize; + fileContent=mLoadFileArray(fileName); + if (fileContent.size<=0) return fileContent.size; /* 2) let's compare the size with a .SAV size */ - if (fileSize==8) { + if (fileContent.size==8) { int framesLeft; /* check that the frames (seconds/12) are in the range [0*12,60*12) */ framesLeft=fileData[2]|fileData[3]<<8; @@ -101,7 +102,7 @@ int prClassify(const char* fileName) { } /* 3) let's compare the size with a .HOF size */ - if (fileSize==176) { + if (fileContent.size==176) { int records; /* check that the number of stored records are 6 or less */ records=fileData[0]|fileData[1]<<8; @@ -118,7 +119,7 @@ int prClassify(const char* fileName) { } /* 4) as the last resource, check if it is an EXE file */ - if (!result && fileSize>2 && fileData[0]=='M' && fileData[1]=='Z') { + if (!result && fileContent.size>2 && fileData[0]=='M' && fileData[1]=='Z') { static tExeClassification x[]={ /* install.pdm : 41 */ {717181985,4233}, /* prince.exe v1.0 THG : 42 */ {622612442,123335}, @@ -129,16 +130,16 @@ int prClassify(const char* fileName) { result=40; /* generic EXE file */ /* Now I'll try to recognize some known EXE files */ /* calculate checksum */ - for (i=0;i<fileSize;i++) { + for (i=0;i<fileContent.size;i++) { checkSum+=fileData[i]<<((3-(i%4))*8); } #ifdef DEBUG_GETCHECKSUM - printf("{%lu,%ld},\n",checkSum,fileSize); + printf("{%lu,%ld},\n",checkSum,fileContent.size); #endif /* compare checksum*/ for (i=0;x[i].size;i++) - if ((x[i].checkSum==checkSum) && (x[i].size==fileSize)) { + if ((x[i].checkSum==checkSum) && (x[i].size==fileContent.size)) { result=41+i; break; } diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index 89e281c..5175e4d 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -111,7 +111,9 @@ int import_full(const char* vFiledat, const char* vDirExt, tResourceList* r, int if (hasFlag(raw_flag)) newRes.type=0; /* compile from raw */ getFileName(vFileext,vDirExt,res,vFiledat,vDatFileName,optionflag,backupExtension,NULL); /* the file is in the archive, so I'll add it to the main DAT body */ - if ((newRes.content.size=(mLoadFileArray(vFileext,&newRes.content.data)))>0) { /* TODO: let each format handle the files */ + newRes.content=mLoadFileArray(vFileext); + if (newRes.content.size>0) { + /* TODO: let each format handle the files */ if (!mAddCompiledFileToDatFile(&newRes,vFileext)) { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); error++; @@ -174,7 +176,8 @@ int import_partial(const char* vFiledat, const char* vDirExt, tResourceList* r, getFileName(vFileext,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension,NULL); /* the file is in the partial matching list, so I'll import */ - if ((newRes.content.size=mLoadFileArray(vFileext,&newRes.content.data))>0) { + newRes.content=mLoadFileArray(vFileext); + if (newRes.content.size>0) { newRes.id=res.id; newRes.type=res.type; if (!mAddCompiledFileToDatFile(&newRes,vFileext)) { diff --git a/PR/src/lib/xml/parse.c b/PR/src/lib/xml/parse.c index bc18d27..997c78d 100644 --- a/PR/src/lib/xml/parse.c +++ b/PR/src/lib/xml/parse.c @@ -473,22 +473,25 @@ tTag* xmlParseFile(const char* vFile,int* error) { */ char* p; - char* l; + /*char* l;*/ char* value=NULL; tTag* tag; tTag* father; - int size; + /*int size;*/ + tBinary bin; + + bin=mLoadFileArray(vFile); - if (((size=mLoadFileArray(vFile,(unsigned char**)(&l)))<=0)) { + if (bin.size<=0) { *error=PR_RESULT_ERR_XML_FILE; /* File not open */ return NULL; } - /* bug fix moved to loadArray */ l[size-1]=0; /* The last character must be an end of line (the > is forbidden) */ - p=l; + /* bug fix moved to loadArray */ bin.data[bin.size-1]=0; /* The last character must be an end of line (the > is forbidden) */ + p=(char*)bin.data; *error=getNextTag(&p, &value); if ((*error)<0) { - free(l); + free(bin.data); return NULL; /* Fatal error will stop the execution of the parsing */ } @@ -497,14 +500,14 @@ tTag* xmlParseFile(const char* vFile,int* error) { if ((*error)<0) { freeTagStructure(tag); - free(l); + free(bin.data); free(father); return NULL; } *error=getNextTag(&p, &value); - free(l); + free(bin.data); if (*error<0) { freeTagStructure(tag); free(father);