author | ecalot
<ecalot> 2005-06-10 11:25:57 UTC |
committer | ecalot
<ecalot> 2005-06-10 11:25:57 UTC |
parent | 6cd2e0972ffafbc1c9e2306b595a16d9713205a1 |
PR/doc/changelog.txt | +2 | -1 |
PR/src/include/common.h | +1 | -0 |
PR/src/lib/actions/export.c | +7 | -4 |
PR/src/lib/actions/import.c | +4 | -4 |
PR/src/lib/layers/dat.c | +12 | -11 |
PR/src/lib/pr.c | +1 | -4 |
diff --git a/PR/doc/changelog.txt b/PR/doc/changelog.txt index 44c2905..8e8d11e 100644 --- a/PR/doc/changelog.txt +++ b/PR/doc/changelog.txt @@ -152,9 +152,10 @@ Versions: - Rewritten resource handling using dynamic structures - Added pop2 palette support - Improved resources.xml. Now it works in bird.dat - x Centralize all the return values in defines + - Centralize all the return values in defines x Support of partial list folder selection (e.g. vdungeon.dat@vdungeon/chopper) + - Fixed memory leaks in xml parser in the error exceptions 2) ToDo List & Future Plans: diff --git a/PR/src/include/common.h b/PR/src/include/common.h index 13c6480..ebe9cce 100644 --- a/PR/src/include/common.h +++ b/PR/src/include/common.h @@ -180,6 +180,7 @@ PARSING_OPTRAW\ #define PR_RESULT_ERR_EXTRACTION -1 #define PR_RESULT_ERR_FILE_DAT_NOTFOUND -2 #define PR_RESULT_ERR_FILE_DAT_NOTOPEN -3 +#define PR_RESULT_ERR_FILE_DAT_NOTOPEN_W -3 #define PR_RESULT_ERR_FILE_NOTFOUND -4 #define PR_RESULT_ERR_FILE_NOTOPEN -5 #define PR_RESULT_ERR_INVALID_DAT -6 diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index e8801d7..62c77fd 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -68,15 +68,17 @@ extern FILE* outputStream; int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int optionflag, const char* vDatFileName, const char* vDatAuthor,const char* backupExtension) { char vFileext[MAX_FILENAME_SIZE]; int indexNumber; - int ok=1; + int ok; tImage image; /* this is used to make a persistent palette */ unsigned short int numberOfItems; tResourceList paletteBuffer; tResourceId bufferedPalette={0,""}; tResource res; + int count=0; /* Initialize abstract variables to read this new DAT file */ - if (mReadBeginDatFile(&numberOfItems,vFiledat)) return -1; + if ((ok=mReadBeginDatFile(&numberOfItems,vFiledat))) return ok; + ok=1; /* initialize palette buffer */ paletteBuffer=resourceListCreate(1); @@ -86,7 +88,7 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti /* main loop */ for (indexNumber=0;ok&&(indexNumber<numberOfItems);indexNumber++) { - if (!mReadFileInDatFile(&res,indexNumber)) return -3; /* Read error */ + if (!mReadFileInDatFile(&res,indexNumber)) return PR_RESULT_ERR_INVALID_DAT; /* Read error */ if (res.id.value==0xFFFF) continue; /* Tammo Jan Bug fix */ /* add to res more information from the resource list */ @@ -151,6 +153,7 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti fprintf(outputStream,PR_TEXT_EXPORT_ERROR,getFileNameFromPath(vFileext)); } } + if (ok) count++; } else { /* if the dat file is unknown, add it in the xml */ getFileName(vFileext,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension); @@ -165,6 +168,6 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti /* Close unknownXML */ endUnknownXml(optionflag,backupExtension); - return ok-1; + return ok?count:PR_RESULT_ERR_EXTRACTION; } diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index 3e8a63f..ab938c4 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -19,8 +19,8 @@ */ /* -compile.c: Princed Resources : DAT Compiler -\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf +import.c: Princed Resources : DAT Compiler +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf Copyright 2003 Princed Development Team Created: 24 Aug 2003 @@ -96,7 +96,7 @@ int fullCompile(const char* vFiledat, const char* vDirExt, tResourceList* r, int const tResource* res; tResource newRes; - if (!mWriteBeginDatFile(vFiledat,optionflag)) return -1; /* File couldn't be open */ + if (mWriteBeginDatFile(vFiledat,optionflag)) return PR_RESULT_ERR_FILE_DAT_NOTOPEN_W; /* File couldn't be open */ list_firstCursor(r); while ((res=list_getCursor(r))) { @@ -134,7 +134,7 @@ int fullCompile(const char* vFiledat, const char* vDirExt, tResourceList* r, int return error; } -#define RW_ERROR {mRWCloseDatFile(1);return 0;} +#define RW_ERROR {mRWCloseDatFile(1);return PR_RESULT_ERR_FILE_NOTOPEN;} int partialCompile(const char* vFiledat, const char* vDirExt, tResourceList* r, int optionflag, const char* vDatFileName,const char* backupExtension) { /* Return values: diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c index 85c3d67..a29323b 100644 --- a/PR/src/lib/layers/dat.c +++ b/PR/src/lib/layers/dat.c @@ -297,10 +297,10 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ /* Open file */ readDatFileSize=mLoadFileArray(vFiledat,&readDatFile); - if (!readDatFileSize) return -2; + if (!readDatFileSize) return PR_RESULT_ERR_FILE_DAT_NOTOPEN; if (readDatFileSize<=6) { free(readDatFile); - return -1; + return PR_RESULT_ERR_INVALID_DAT; } /* read header */ @@ -310,16 +310,16 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ /* verify dat format: the index offset belongs to the file and the file size is the index size plus the index offset */ if ((indexOffset>readDatFileSize)&&((indexOffset+indexSize)!=readDatFileSize)) { free(readDatFile); - return -1; /* this is not a valid prince dat file */ + return PR_RESULT_ERR_INVALID_DAT; /* this is not a valid prince dat file */ } /* create cursor */ readIndexCursor=dat_createCursor(readDatFile+indexOffset,indexSize,numberOfItems); /* pop version check */ - if (!dat_readCursorGetVersion(readIndexCursor)) return -1; + if (!dat_readCursorGetVersion(readIndexCursor)) return PR_RESULT_ERR_INVALID_DAT; - return 0; + return PR_RESULT_SUCCESS; } void dat_readRes(tResource* res) { @@ -373,9 +373,9 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) { fwriteshort(&fill,writeDatFile); /* Fill the file with 6 starting null bytes */ fwriteshort(&fill,writeDatFile); /* Fill the file with 6 starting null bytes */ fwriteshort(&fill,writeDatFile); /* Fill the file with 6 starting null bytes */ - return 1; + return PR_RESULT_SUCCESS; } else { - return 0; + return PR_RESULT_ERR_FILE_DAT_NOTOPEN_W; } } @@ -470,12 +470,13 @@ void mWriteCloseDatFile(int dontSave,int optionflag, const char* backupExtension #ifdef PR_DAT_INCLUDE_DATREAD #ifdef PR_DAT_INCLUDE_DATWRITE int mRWBeginDatFile(const char* vFile, unsigned short int *numberOfItems, int optionflag) { - if (mReadBeginDatFile(numberOfItems,vFile)) return -2; - if (!mWriteBeginDatFile(vFile,optionflag)) { + int error; + if ((error=mReadBeginDatFile(numberOfItems,vFile))) return error; + if ((error=mWriteBeginDatFile(vFile,optionflag))) { mReadCloseDatFile(); - return -1; + return error; } - return 0; + return PR_RESULT_SUCCESS; } #endif #endif diff --git a/PR/src/lib/pr.c b/PR/src/lib/pr.c index a74ddd4..f3cd381 100644 --- a/PR/src/lib/pr.c +++ b/PR/src/lib/pr.c @@ -217,10 +217,7 @@ int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF /* Parse XML and import files */ a=parseFile(vResFile,currentDatFileName,&r); - if (a<0) { - /* parsing errors */ - a-=2; - } else { + if (a==PR_RESULT_SUCCESS) { /* importing errors/no errors */ a=compile (currentDatFile, vDirName,&r,opt,currentDatFileName,backupExtension); }