author | ecalot
<ecalot> 2005-06-08 10:06:34 UTC |
committer | ecalot
<ecalot> 2005-06-08 10:06:34 UTC |
parent | b1c4604f8e06cf7437ac9d8ebc42a1a508df5d61 |
PR/src/Makefile | +9 | -1 |
PR/src/include/autodetect.h | +7 | -23 |
PR/src/include/bitmap.h | +1 | -1 |
PR/src/include/bmp.h | +1 | -1 |
PR/src/include/dat.h | +30 | -10 |
PR/src/include/export.h | +1 | -2 |
PR/src/include/idlist.h | +7 | -23 |
PR/src/include/import.h | +1 | -1 |
PR/src/include/list.h | +4 | -4 |
PR/src/include/mid.h | +1 | -1 |
PR/src/include/pal.h | +6 | -2 |
PR/src/include/plv.h | +1 | -1 |
PR/src/include/png.h | +1 | -1 |
PR/src/include/pr.h | +1 | -0 |
PR/src/include/reslist.h | +54 | -0 |
PR/src/include/search.h | +1 | -1 |
PR/src/include/tree.h | +7 | -23 |
PR/src/include/types.h | +54 | -0 |
PR/src/include/unknown.h | +7 | -23 |
PR/src/include/wav.h | +1 | -1 |
PR/src/lib/actions/classify.c | +7 | -12 |
PR/src/lib/actions/export.c | +49 | -75 |
PR/src/lib/actions/import.c | +37 | -41 |
PR/src/lib/formats/bmp.c | +4 | -6 |
PR/src/lib/formats/mid.c | +5 | -4 |
PR/src/lib/formats/pal.c | +7 | -4 |
PR/src/lib/formats/plv.c | +5 | -4 |
PR/src/lib/formats/wav.c | +6 | -4 |
PR/src/lib/layers/autodetect.c | +11 | -13 |
PR/src/lib/layers/dat.c | +196 | -94 |
PR/src/lib/layers/idlist.c | +11 | -13 |
PR/src/lib/layers/list.c | +8 | -8 |
PR/src/lib/layers/reslist.c | +67 | -35 |
PR/src/lib/pr.c | +13 | -7 |
PR/src/lib/xml/parse.c | +5 | -1 |
PR/src/lib/xml/search.c | +37 | -19 |
PR/src/lib/xml/tree.c | +11 | -13 |
PR/src/lib/xml/unknown.c | +11 | -13 |
PR/src/xml/resources.xml | +1 | -1 |
diff --git a/PR/src/Makefile b/PR/src/Makefile index 5b3e52a..1cb4e51 100644 --- a/PR/src/Makefile +++ b/PR/src/Makefile @@ -53,7 +53,7 @@ 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 + .memory.o .pr.o .list.o .reslist.o XML = .parse.o .search.o COMPRESS = .compress.o .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o @@ -125,6 +125,14 @@ $(XMLFILE): xml/resources.xml $(INFO) Compiling export module... $(CC) $(OPTIONS) -c lib/actions/export.c -o $@ +.list.o: lib/layers/list.c + $(INFO) Compiling list implementation... + $(CC) $(OPTIONS) -c lib/layers/list.c -o $@ + +.reslist.o: lib/layers/reslist.c + $(INFO) Compiling resource list module... + $(CC) $(OPTIONS) -c lib/layers/reslist.c -o $@ + .compress.o: lib/compression/main.c $(INFO) Compiling compression module... $(CC) $(OPTIONS) -c lib/compression/main.c -o .compress.o -o $@ diff --git a/PR/src/include/autodetect.h b/PR/src/include/autodetect.h index a493c21..0105dc7 100644 --- a/PR/src/include/autodetect.h +++ b/PR/src/include/autodetect.h @@ -38,7 +38,7 @@ resources.h: Princed Resources : Resource Handler headers #define RES_XML_UNKNOWN_PATH "%s/unknown/%s/" #define RES_XML_UNKNOWN_FILES "%s%02d.%s" -#define RES_XML_UNKNOWN_START "<?xml version=\"1.0\" ?>\n<resources version=\"generated\">\n <folder name=\"unknown\" path=\"%s\" file=\"%s\" palette=\"%d\">\n" +#define RES_XML_UNKNOWN_START "<?xml version=\"1.0\" ?>\n<resources version=\"generated\">\n <folder name=\"unknown\" path=\"%s\" file=\"%s\" palette=\"%d\" paletteindex=\"%s\">\n" #define RES_XML_UNKNOWN_ITEM " <item value=\"%d\" index=\"%s\" path=\""RES_XML_UNKNOWN_FILES"\" itemtype=\"%s\">Unknown %s %d</item>\n" #define RES_XML_UNKNOWN_END " </folder>\n</resources>\n" @@ -60,18 +60,6 @@ resources.h: Princed Resources : Resource Handler headers #define RES_TYPECOUNT 8 -/* types */ -typedef struct { - unsigned short int palette; - unsigned short int size; - unsigned long int offset; /* Used internally in dat.c to remember the offset */ - unsigned char number; /* Used for level number */ - char type; - char* path; - unsigned char* palAux; - char* name; - char* desc; -}tResource; /* Id list for partial manipulation */ typedef enum {eString,eValue}tResIdType; @@ -90,8 +78,8 @@ typedef struct { }tResIdList; void parseGivenPath(char* path); -int partialListActive(); -int isInThePartialList(const char* file, int value); +int partialListActive(); +int isInThePartialList(const char* file, int value); void freePartialList(); /* Includes */ @@ -112,24 +100,20 @@ int verifyHeader(const unsigned char* array, int size); 07 Internal Speaker Sounds */ -/***************************************************************\ -| File format handling | -\***************************************************************/ +#include "dat.h" /* tResource */ +#include "reslist.h" /* tResourceList */ /* CheckSum verification */ int checkSum(const unsigned char* data,int size); -/* Empty resource table */ -void emptyTable(tResource* r[]); - /* Resources extras */ -void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short id,const char* vFiledat, const char* vDatFileName,int optionflag,const char* backupExtension,const char* indexName); +void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag,const char* backupExtension); void getUpperFolder(char* aux, char* vFiledat); const char* getExtDesc(int type); /* parse xml file */ -int parseFile(const char* vFile, const char* datFile, tResource* r[]); +int parseFile(const char* vFile, const char* datFile, tResourceList *r); /* In case there are unknown resources it closes the unknown XML output */ void endUnknownXml(); diff --git a/PR/src/include/bitmap.h b/PR/src/include/bitmap.h index f896737..770abb3 100644 --- a/PR/src/include/bitmap.h +++ b/PR/src/include/bitmap.h @@ -41,7 +41,7 @@ bmp.h: Princed Resources : BMP file support headers #define FORMATS_BMP_PALETTE_BW "\x00\x00\x00\0\xFF\xFF\xFF" int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned long int size,tImage image,int optionflag,const char* backupExtension); -int mFormatImportBmp(unsigned char* data, tResource *res); +int mFormatImportBmp(tResource *res); int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupExtension); int mReadBitMap(tImage* img,unsigned char* data, int size); /* Note: this will ignore the palette */ diff --git a/PR/src/include/bmp.h b/PR/src/include/bmp.h index f896737..770abb3 100644 --- a/PR/src/include/bmp.h +++ b/PR/src/include/bmp.h @@ -41,7 +41,7 @@ bmp.h: Princed Resources : BMP file support headers #define FORMATS_BMP_PALETTE_BW "\x00\x00\x00\0\xFF\xFF\xFF" int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned long int size,tImage image,int optionflag,const char* backupExtension); -int mFormatImportBmp(unsigned char* data, tResource *res); +int mFormatImportBmp(tResource *res); int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupExtension); int mReadBitMap(tImage* img,unsigned char* data, int size); /* Note: this will ignore the palette */ diff --git a/PR/src/include/dat.h b/PR/src/include/dat.h index 6bee1ee..ca2afa0 100644 --- a/PR/src/include/dat.h +++ b/PR/src/include/dat.h @@ -34,9 +34,28 @@ dat.h: Princed Resources : DAT library headers #ifndef _DAT_H_ #define _DAT_H_ -#include "resources.h" - -#define MAX_RES_COUNT 65000 +#define MAX_RES_COUNT 65000 /* TODO grep if this constant still exists */ + +/* types */ +typedef struct { + unsigned short int value; + char index[5]; +}tResourceId; + +typedef struct { + tResourceId id; + tResourceId palette; + unsigned short int size; + unsigned long int offset; /* Used internally in dat.c to remember the offset */ + unsigned char number; /* Used for level number */ + char type; + char* path; + unsigned char* palAux; + char* name; + char* desc; + unsigned char* data; + unsigned long flags; +}tResource; typedef enum { none=0, @@ -55,25 +74,26 @@ tPopVersion mReadGetVersion(); int mRWBeginDatFile(const char* vFile, unsigned short int *numberOfItems, int optionflag); #define mRWCloseDatFile(dontSave) \ mReadCloseDatFile();\ -mWriteCloseDatFile(r,dontSave,optionflag,backupExtension) +mWriteCloseDatFile(dontSave,optionflag,backupExtension) #endif #endif #ifdef PR_DAT_INCLUDE_DATREAD /* DAT reading primitives */ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFile); -int mReadFileInDatFile(int indexNumber,unsigned char* *data,unsigned long int *size, unsigned long int *flags,char* *indexName); -int mReadInitResource(tResource** res,const unsigned char* data,long size); +int mReadFileInDatFile(tResource* res, int k); +int mReadFileInDatFileId(tResource* res); +/*int mReadInitResource(tResource** res,const unsigned char* data,long size);*/ void mReadCloseDatFile(); #endif #ifdef PR_DAT_INCLUDE_DATWRITE /* DAT writing primitives */ int mWriteBeginDatFile(const char* vFile, int optionflag); -void mWriteFileInDatFile(const unsigned char* data, int size); -void mWriteFileInDatFileIgnoreChecksum(unsigned char* data,int size); -void mWriteInitResource(tResource** res); -void mWriteCloseDatFile(tResource* r[],int dontSave,int optionflag, const char* backupExtension); +void mWriteFileInDatFile(const tResource* res); +void mWriteFileInDatFileIgnoreChecksum(const tResource* res); +/*void mWriteInitResource(tResource** res);*/ +void mWriteCloseDatFile(int dontSave,int optionflag, const char* backupExtension); #endif #endif diff --git a/PR/src/include/export.h b/PR/src/include/export.h index dd78230..3b89e9a 100644 --- a/PR/src/include/export.h +++ b/PR/src/include/export.h @@ -36,6 +36,5 @@ extract.h: Princed Resources : DAT Extractor headers #include "resources.h" -int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int task, const char* vDatFileName, const char* vDatAuthor,const char* backupExtension); - +int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int task, const char* vDatFileName, const char* vDatAuthor,const char* backupExtension); #endif diff --git a/PR/src/include/idlist.h b/PR/src/include/idlist.h index a493c21..0105dc7 100644 --- a/PR/src/include/idlist.h +++ b/PR/src/include/idlist.h @@ -38,7 +38,7 @@ resources.h: Princed Resources : Resource Handler headers #define RES_XML_UNKNOWN_PATH "%s/unknown/%s/" #define RES_XML_UNKNOWN_FILES "%s%02d.%s" -#define RES_XML_UNKNOWN_START "<?xml version=\"1.0\" ?>\n<resources version=\"generated\">\n <folder name=\"unknown\" path=\"%s\" file=\"%s\" palette=\"%d\">\n" +#define RES_XML_UNKNOWN_START "<?xml version=\"1.0\" ?>\n<resources version=\"generated\">\n <folder name=\"unknown\" path=\"%s\" file=\"%s\" palette=\"%d\" paletteindex=\"%s\">\n" #define RES_XML_UNKNOWN_ITEM " <item value=\"%d\" index=\"%s\" path=\""RES_XML_UNKNOWN_FILES"\" itemtype=\"%s\">Unknown %s %d</item>\n" #define RES_XML_UNKNOWN_END " </folder>\n</resources>\n" @@ -60,18 +60,6 @@ resources.h: Princed Resources : Resource Handler headers #define RES_TYPECOUNT 8 -/* types */ -typedef struct { - unsigned short int palette; - unsigned short int size; - unsigned long int offset; /* Used internally in dat.c to remember the offset */ - unsigned char number; /* Used for level number */ - char type; - char* path; - unsigned char* palAux; - char* name; - char* desc; -}tResource; /* Id list for partial manipulation */ typedef enum {eString,eValue}tResIdType; @@ -90,8 +78,8 @@ typedef struct { }tResIdList; void parseGivenPath(char* path); -int partialListActive(); -int isInThePartialList(const char* file, int value); +int partialListActive(); +int isInThePartialList(const char* file, int value); void freePartialList(); /* Includes */ @@ -112,24 +100,20 @@ int verifyHeader(const unsigned char* array, int size); 07 Internal Speaker Sounds */ -/***************************************************************\ -| File format handling | -\***************************************************************/ +#include "dat.h" /* tResource */ +#include "reslist.h" /* tResourceList */ /* CheckSum verification */ int checkSum(const unsigned char* data,int size); -/* Empty resource table */ -void emptyTable(tResource* r[]); - /* Resources extras */ -void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short id,const char* vFiledat, const char* vDatFileName,int optionflag,const char* backupExtension,const char* indexName); +void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag,const char* backupExtension); void getUpperFolder(char* aux, char* vFiledat); const char* getExtDesc(int type); /* parse xml file */ -int parseFile(const char* vFile, const char* datFile, tResource* r[]); +int parseFile(const char* vFile, const char* datFile, tResourceList *r); /* In case there are unknown resources it closes the unknown XML output */ void endUnknownXml(); diff --git a/PR/src/include/import.h b/PR/src/include/import.h index bb80ef0..97014a7 100644 --- a/PR/src/include/import.h +++ b/PR/src/include/import.h @@ -37,6 +37,6 @@ compile.h: Princed Resources : DAT Compiler headers #include <stdio.h> #include "resources.h" -int compile(const char* vFiledat, const char* vDirExt, tResource* r[], int opt, const char* vDatFileName,const char* backupExtension); +int compile(const char* vFiledat, const char* vDirExt, tResourceList* r, int optionflag, const char* vDatFileName,const char* backupExtension); #endif diff --git a/PR/src/include/list.h b/PR/src/include/list.h index 445e47d..855c72b 100644 --- a/PR/src/include/list.h +++ b/PR/src/include/list.h @@ -46,16 +46,16 @@ typedef struct node { typedef struct { int size; - int (*cmp)(void*,void*); + int (*cmp)(const void*,const void*); tListNode *cursor,*first; }tList; -tList list_create(int dataSize,int dataCmp(void*,void*)); -void list_insert(tList *list,void* data); +tList list_create(int dataSize,int dataCmp(const void*,const void*)); +void list_insert(tList *list,const void* data); void list_drop(tList *list); void list_nextCursor(tList* list); void list_firstCursor(tList* list); -int list_moveCursor(tList* list,void* data); +int list_moveCursor(tList* list,const void* data); const void* list_getCursor(tList* list); #endif diff --git a/PR/src/include/mid.h b/PR/src/include/mid.h index 3bd8753..6f9b613 100644 --- a/PR/src/include/mid.h +++ b/PR/src/include/mid.h @@ -37,7 +37,7 @@ mid.h: Princed Resources : MIDI files support headers #include <stdio.h> #include "resources.h" -int mFormatImportMid(unsigned char* data, tResource *res); +int mFormatImportMid(tResource *res); int mFormatExportMid(const unsigned char* data, char *vFileext,unsigned long int size,int optionflag,const char* backupExtension); #endif diff --git a/PR/src/include/pal.h b/PR/src/include/pal.h index 3662f3c..beea592 100644 --- a/PR/src/include/pal.h +++ b/PR/src/include/pal.h @@ -42,8 +42,12 @@ pal.h: Princed Resources : JASC PAL files support headers #define PAL_SAMPLE {0x97, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x08, 0x0F, 0x07, 0x0C, 0x13, 0x0C, 0x11, 0x16, 0x11, 0x17, 0x1C, 0x1E, 0x21, 0x25, 0x2F, 0x31, 0x33, 0x3F, 0x3F, 0x3F, 0x2A, 0x2A, 0x2A, 0x15, 0x15, 0x15, 0x17, 0x1C, 0x20, 0x07, 0x0C, 0x13, 0x0C, 0x12, 0x17, 0x15, 0x1A, 0x1F, 0x00, 0x1D, 0x13, 0x00, 0x29, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} int mFormatExportPal(const unsigned char* data, char *vFileext,unsigned long int size,int optionflag,const char* backupExtensio); -int mFormatImportPal(unsigned char* data, tResource *res,const char* vFile); +int mFormatImportPal(tResource *res,const char* vFile); -#define mLoadPalette(array,image) memcpy(((image).pal),((array)+5),(16*3)) +#define mLoadPalette(array,image,popversion)\ + if (popversion==pop1)\ + memcpy(((image).pal),((array)+5),(16*3));\ + else\ + memcpy(((image).pal),(array),(16*3)) #endif diff --git a/PR/src/include/plv.h b/PR/src/include/plv.h index bbc9606..b2de179 100644 --- a/PR/src/include/plv.h +++ b/PR/src/include/plv.h @@ -64,7 +64,7 @@ plv.h: Princed Resources : PLV prince level files support headers #include "resources.h" #include "common.h" /* for PR_VERSION */ -int mFormatImportPlv(unsigned char* data, tResource *res); +int mFormatImportPlv(tResource *res); int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned long int size,unsigned char level, const char* filename, const char* desc, const char* title, const char* vDatAuthor,int optionflag, const char* backupExtension); /* Weekdays and months */ diff --git a/PR/src/include/png.h b/PR/src/include/png.h index f896737..770abb3 100644 --- a/PR/src/include/png.h +++ b/PR/src/include/png.h @@ -41,7 +41,7 @@ bmp.h: Princed Resources : BMP file support headers #define FORMATS_BMP_PALETTE_BW "\x00\x00\x00\0\xFF\xFF\xFF" int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned long int size,tImage image,int optionflag,const char* backupExtension); -int mFormatImportBmp(unsigned char* data, tResource *res); +int mFormatImportBmp(tResource *res); int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupExtension); int mReadBitMap(tImage* img,unsigned char* data, int size); /* Note: this will ignore the palette */ diff --git a/PR/src/include/pr.h b/PR/src/include/pr.h index f248d18..717328e 100644 --- a/PR/src/include/pr.h +++ b/PR/src/include/pr.h @@ -53,6 +53,7 @@ typedef struct tTag { char* itemtype; char* name; char* palette; + char* paletteindex; char* type; char* value; char* index; diff --git a/PR/src/include/reslist.h b/PR/src/include/reslist.h new file mode 100644 index 0000000..a090cd1 --- /dev/null +++ b/PR/src/include/reslist.h @@ -0,0 +1,54 @@ +/* Princed V3 - Prince of Persia Level Editor for PC Version + Copyright (C) 2003 Princed Development Team + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + The authors of this program may be contacted at http://forum.princed.com.ar +*/ + +/* +reslist.h: Princed Resources : Resource list +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf + Copyright 2005 Princed Development Team + Created: 05 Jun 2005 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.00 (2005-Jun-05) + + Note: + DO NOT remove this copyright notice +*/ + +#ifndef _RESLIST_H_ +#define _RESLIST_H_ + +#include "list.h" /* tList */ + +#define tResourceList tList + +#include "dat.h" /* tResourceId & tResource */ +/* TODO: fix header dependencies */ + +void printr(const tResource* record); /* for debug purposes */ + +int resIdCmp(tResourceId a,tResourceId b); +int resCmp(const void* a,const void* b); +void resourceListDrop(tResourceList* r); +tResourceList resourceListCreate(); +void resourceListAdd(tResourceList* r,const tResource* res); +void resourceListDebugPrint(tResourceList* r); +void resourceListAddInfo(tResourceList* r,tResource* res); + +#endif diff --git a/PR/src/include/search.h b/PR/src/include/search.h index 9a75beb..fd519a1 100644 --- a/PR/src/include/search.h +++ b/PR/src/include/search.h @@ -62,7 +62,7 @@ char* getFileFromList(); /* Abstract passing structures */ typedef struct tPassWork { const char* datFile; - tResource** r; + tResourceList* r; }tPassWork; typedef struct tPassCompare { diff --git a/PR/src/include/tree.h b/PR/src/include/tree.h index a493c21..0105dc7 100644 --- a/PR/src/include/tree.h +++ b/PR/src/include/tree.h @@ -38,7 +38,7 @@ resources.h: Princed Resources : Resource Handler headers #define RES_XML_UNKNOWN_PATH "%s/unknown/%s/" #define RES_XML_UNKNOWN_FILES "%s%02d.%s" -#define RES_XML_UNKNOWN_START "<?xml version=\"1.0\" ?>\n<resources version=\"generated\">\n <folder name=\"unknown\" path=\"%s\" file=\"%s\" palette=\"%d\">\n" +#define RES_XML_UNKNOWN_START "<?xml version=\"1.0\" ?>\n<resources version=\"generated\">\n <folder name=\"unknown\" path=\"%s\" file=\"%s\" palette=\"%d\" paletteindex=\"%s\">\n" #define RES_XML_UNKNOWN_ITEM " <item value=\"%d\" index=\"%s\" path=\""RES_XML_UNKNOWN_FILES"\" itemtype=\"%s\">Unknown %s %d</item>\n" #define RES_XML_UNKNOWN_END " </folder>\n</resources>\n" @@ -60,18 +60,6 @@ resources.h: Princed Resources : Resource Handler headers #define RES_TYPECOUNT 8 -/* types */ -typedef struct { - unsigned short int palette; - unsigned short int size; - unsigned long int offset; /* Used internally in dat.c to remember the offset */ - unsigned char number; /* Used for level number */ - char type; - char* path; - unsigned char* palAux; - char* name; - char* desc; -}tResource; /* Id list for partial manipulation */ typedef enum {eString,eValue}tResIdType; @@ -90,8 +78,8 @@ typedef struct { }tResIdList; void parseGivenPath(char* path); -int partialListActive(); -int isInThePartialList(const char* file, int value); +int partialListActive(); +int isInThePartialList(const char* file, int value); void freePartialList(); /* Includes */ @@ -112,24 +100,20 @@ int verifyHeader(const unsigned char* array, int size); 07 Internal Speaker Sounds */ -/***************************************************************\ -| File format handling | -\***************************************************************/ +#include "dat.h" /* tResource */ +#include "reslist.h" /* tResourceList */ /* CheckSum verification */ int checkSum(const unsigned char* data,int size); -/* Empty resource table */ -void emptyTable(tResource* r[]); - /* Resources extras */ -void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short id,const char* vFiledat, const char* vDatFileName,int optionflag,const char* backupExtension,const char* indexName); +void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag,const char* backupExtension); void getUpperFolder(char* aux, char* vFiledat); const char* getExtDesc(int type); /* parse xml file */ -int parseFile(const char* vFile, const char* datFile, tResource* r[]); +int parseFile(const char* vFile, const char* datFile, tResourceList *r); /* In case there are unknown resources it closes the unknown XML output */ void endUnknownXml(); diff --git a/PR/src/include/types.h b/PR/src/include/types.h new file mode 100644 index 0000000..a090cd1 --- /dev/null +++ b/PR/src/include/types.h @@ -0,0 +1,54 @@ +/* Princed V3 - Prince of Persia Level Editor for PC Version + Copyright (C) 2003 Princed Development Team + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + The authors of this program may be contacted at http://forum.princed.com.ar +*/ + +/* +reslist.h: Princed Resources : Resource list +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf + Copyright 2005 Princed Development Team + Created: 05 Jun 2005 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.00 (2005-Jun-05) + + Note: + DO NOT remove this copyright notice +*/ + +#ifndef _RESLIST_H_ +#define _RESLIST_H_ + +#include "list.h" /* tList */ + +#define tResourceList tList + +#include "dat.h" /* tResourceId & tResource */ +/* TODO: fix header dependencies */ + +void printr(const tResource* record); /* for debug purposes */ + +int resIdCmp(tResourceId a,tResourceId b); +int resCmp(const void* a,const void* b); +void resourceListDrop(tResourceList* r); +tResourceList resourceListCreate(); +void resourceListAdd(tResourceList* r,const tResource* res); +void resourceListDebugPrint(tResourceList* r); +void resourceListAddInfo(tResourceList* r,tResource* res); + +#endif diff --git a/PR/src/include/unknown.h b/PR/src/include/unknown.h index a493c21..0105dc7 100644 --- a/PR/src/include/unknown.h +++ b/PR/src/include/unknown.h @@ -38,7 +38,7 @@ resources.h: Princed Resources : Resource Handler headers #define RES_XML_UNKNOWN_PATH "%s/unknown/%s/" #define RES_XML_UNKNOWN_FILES "%s%02d.%s" -#define RES_XML_UNKNOWN_START "<?xml version=\"1.0\" ?>\n<resources version=\"generated\">\n <folder name=\"unknown\" path=\"%s\" file=\"%s\" palette=\"%d\">\n" +#define RES_XML_UNKNOWN_START "<?xml version=\"1.0\" ?>\n<resources version=\"generated\">\n <folder name=\"unknown\" path=\"%s\" file=\"%s\" palette=\"%d\" paletteindex=\"%s\">\n" #define RES_XML_UNKNOWN_ITEM " <item value=\"%d\" index=\"%s\" path=\""RES_XML_UNKNOWN_FILES"\" itemtype=\"%s\">Unknown %s %d</item>\n" #define RES_XML_UNKNOWN_END " </folder>\n</resources>\n" @@ -60,18 +60,6 @@ resources.h: Princed Resources : Resource Handler headers #define RES_TYPECOUNT 8 -/* types */ -typedef struct { - unsigned short int palette; - unsigned short int size; - unsigned long int offset; /* Used internally in dat.c to remember the offset */ - unsigned char number; /* Used for level number */ - char type; - char* path; - unsigned char* palAux; - char* name; - char* desc; -}tResource; /* Id list for partial manipulation */ typedef enum {eString,eValue}tResIdType; @@ -90,8 +78,8 @@ typedef struct { }tResIdList; void parseGivenPath(char* path); -int partialListActive(); -int isInThePartialList(const char* file, int value); +int partialListActive(); +int isInThePartialList(const char* file, int value); void freePartialList(); /* Includes */ @@ -112,24 +100,20 @@ int verifyHeader(const unsigned char* array, int size); 07 Internal Speaker Sounds */ -/***************************************************************\ -| File format handling | -\***************************************************************/ +#include "dat.h" /* tResource */ +#include "reslist.h" /* tResourceList */ /* CheckSum verification */ int checkSum(const unsigned char* data,int size); -/* Empty resource table */ -void emptyTable(tResource* r[]); - /* Resources extras */ -void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short id,const char* vFiledat, const char* vDatFileName,int optionflag,const char* backupExtension,const char* indexName); +void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag,const char* backupExtension); void getUpperFolder(char* aux, char* vFiledat); const char* getExtDesc(int type); /* parse xml file */ -int parseFile(const char* vFile, const char* datFile, tResource* r[]); +int parseFile(const char* vFile, const char* datFile, tResourceList *r); /* In case there are unknown resources it closes the unknown XML output */ void endUnknownXml(); diff --git a/PR/src/include/wav.h b/PR/src/include/wav.h index 8ca71bf..932e5f0 100644 --- a/PR/src/include/wav.h +++ b/PR/src/include/wav.h @@ -40,6 +40,6 @@ wav.h: Princed Resources : WAV files support headers #define WAVE_HEADER {0x52, 0x49, 0x46, 0x46, 0x12, 0x16, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x11, 0x2B, 0x00, 0x00, 0x11, 0x2B, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x64, 0x61, 0x74, 0x61, 0xA3, 0x15, 0x00, 0x00} int mFormatExportWav(const unsigned char* data, char *vFileext,unsigned long int size,int optionflag,const char* backupExtension); -int mFormatImportWav(unsigned char* data, tResource *res); +int mFormatImportWav(tResource *res); #endif diff --git a/PR/src/lib/actions/classify.c b/PR/src/lib/actions/classify.c index 9a8d795..d1133a5 100644 --- a/PR/src/lib/actions/classify.c +++ b/PR/src/lib/actions/classify.c @@ -47,27 +47,22 @@ tasks.c: Princed Resources : Classify a DAT file int prClassifyDat(const char* vFiledat) { int indexNumber; - long int id; - unsigned char* data; - unsigned long int size; int type=RES_TYPE_BINARY; unsigned short int numberOfItems; tPopVersion popVersion; - unsigned long int flags; - char* indexName; + tResource res; + int ok; /* Initialize abstract variables to read this new DAT file */ - if ((id=mReadBeginDatFile(&numberOfItems,vFiledat))) return id+1; /* -1 if not found or empty, 0 if invalid */ + if ((ok=mReadBeginDatFile(&numberOfItems,vFiledat))) return ok+1; /* -1 if not found or empty, 0 if invalid */ popVersion=mReadGetVersion(); /* main loop */ - for (id=0,indexNumber=0;(indexNumber<numberOfItems)&&(type==RES_TYPE_BINARY);indexNumber++) { - id=mReadFileInDatFile(indexNumber,&data,&size,&flags,&indexName); - if (id<0) READ_ERROR; /* Read error */ - if (id==0xFFFF) continue; /* Tammo Jan Bug fix */ - if (id>=MAX_RES_COUNT) READ_ERROR; /* A file with an ID out of range will be treated as invalid */ - type=verifyHeader(data,size); + for (indexNumber=0;(indexNumber<numberOfItems)&&(type==RES_TYPE_BINARY);indexNumber++) { + if (!mReadFileInDatFile(&res,indexNumber)) READ_ERROR; /* Read error */ + if (res.id.value==0xFFFF) continue; /* Tammo Jan Bug fix */ + type=verifyHeader(res.data,res.size); } mReadCloseDatFile(); diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index 253b616..8e98700 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -41,6 +41,7 @@ extract.c: Princed Resources : DAT Extractor #include "dat.h" #include "disk.h" #include "memory.h" +#include "reslist.h" /* resIdcmp, resourceList primitives for the palette */ #include "bmp.h" #include "wav.h" @@ -54,13 +55,6 @@ extern FILE* outputStream; | I M P L E M E N T A T I O N | \***************************************************************/ -#define initializePaletteList \ -for (id=0;id<MAX_RES_COUNT;id++) {\ - if (r[id]!=NULL) {\ - r[id]->palAux=NULL;\ - }\ -} - /***************************************************************\ | M A I N E X T R A C T | \***************************************************************/ @@ -71,96 +65,84 @@ for (id=0;id<MAX_RES_COUNT;id++) {\ For parameter documentation, see pr.c */ -int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName, const char* vDatAuthor,const char* backupExtension) { +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; - long int id; tImage image; /* this is used to make a persistent palette */ - unsigned char* data; - unsigned long int size; unsigned short int numberOfItems; - signed long int bufferedPalette=0; - unsigned long int flags; - char* indexName; + tResourceList paletteBuffer; + tResourceId bufferedPalette={0,""}; + tResource res; /* Initialize abstract variables to read this new DAT file */ if (mReadBeginDatFile(&numberOfItems,vFiledat)) return -1; - /* Initializes the palette list */ - initializePaletteList; - + /* initialize palette buffer */ + paletteBuffer=resourceListCreate(); + /* initialize the default palette */ + memcpy(image.pal,DEFAULT_PALETTE,SIZE_OF_PALETTE); + /* main loop */ for (indexNumber=0;ok&&(indexNumber<numberOfItems);indexNumber++) { - id=mReadFileInDatFile(indexNumber,&data,&size,&flags,&indexName); - - if (id<0) return -3; /* Read error */ - if (id==0xFFFF) continue; /* Tammo Jan Bug fix */ - if (id>=MAX_RES_COUNT) return -3; /* A file with an ID out of range will be treated as invalid */ - /* set resource information on this index entry */ - if (mReadInitResource(r+id,data,size)) return -2; + if (!mReadFileInDatFile(&res,indexNumber)) return -3; /* Read error */ + if (res.id.value==0xFFFF) continue; /* Tammo Jan Bug fix */ + /*if (id>=MAX_RES_COUNT) return -3; * DEPRECATED due to new id handling. + * A file with an ID out of range will be treated as invalid */ - if ((r[id]->type==RES_TYPE_PALETTE)||isInThePartialList(r[id]->path,id)) { /* If the resource was specified or is a palette, do the tasks */ + /* add to res more information from the resource list */ + resourceListAddInfo(r,&res); + + if (/*(res.type==RES_TYPE_PALETTE)||*/isInThePartialList(res.path,res.id.value /*TODO: use res.id and code the index support to the partial list*/)) { /* If the resource was specified or is a palette, do the tasks */ if (!(hasFlag(unknown_flag))) { /* If unknown flag is set do nothing but generate the unknown.xml file */ - if (hasFlag(raw_flag)) r[id]->type=0; /* If "extract as raw" is set, type is 0 */ + if (hasFlag(raw_flag)) res.type=0; /* If "extract as raw" is set, type is 0 */ /* get save file name (if unknown document it in the xml) */ - getFileName(vFileext,vDirExt,r[id],(unsigned short)id,vFiledat,vDatFileName,optionflag,backupExtension,indexName); + getFileName(vFileext,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension); - switch (r[id]->type) { - case RES_TYPE_LEVEL: - ok=ok&&mFormatExportPlv(data,vFileext,size,r[id]->number,vDatFileName,r[id]->name,r[id]->desc,vDatAuthor,optionflag,backupExtension); + switch (res.type) { + case RES_TYPE_LEVEL: + /* TODO: ok=ok&& is ok= */ + ok=ok&&mFormatExportPlv(res.data,vFileext,res.size,res.number,vDatFileName,res.name,res.desc,vDatAuthor,optionflag,backupExtension); break; case RES_TYPE_BINARY: /* Binary files */ case RES_TYPE_RAW: /* Raw files */ - ok=ok&&writeData(data,1,vFileext,size,optionflag,backupExtension); /* Ignore checksum */ + ok=ok&&writeData(res.data,1,vFileext,res.size,optionflag,backupExtension); /* Ignore checksum */ break; case RES_TYPE_PALETTE: /* save and remember palette file */ - /* This will remember the palette for the next images */ - r[id]->palAux=getMemory(size); - memcpy(r[id]->palAux,data,size); - if (!bufferedPalette) { /* In case the palette buffer is empty, load immediately the first found palette to clear garbage */ - mLoadPalette(data,image); - bufferedPalette=id; - } + /* This will remember the palette for the next images + * (because it's more probable to get all the images after its palette) */ + mLoadPalette(res.data,image,mReadGetVersion()); + bufferedPalette=res.id; + resourceListAdd(&paletteBuffer,&res); /* This will export the palette */ - if (isInThePartialList(r[id]->path,id)) /* If the palette was specified extract it */ - ok=ok&&mFormatExportPal(data,vFileext,size,optionflag,backupExtension); +/* if (isInThePartialList(res.path,res.id.value)) * If the palette was specified extract it */ + ok=ok&&mFormatExportPal(res.data,vFileext,res.size,optionflag,backupExtension); break; case RES_TYPE_PCSPEAKER: /* save pcs file */ case RES_TYPE_MIDI: /* save midi file */ - ok=ok&&mFormatExportMid(data,vFileext,size,optionflag,backupExtension); + ok=ok&&mFormatExportMid(res.data,vFileext,res.size,optionflag,backupExtension); break; case RES_TYPE_WAVE: /* save wav file */ - ok=ok&&mFormatExportWav(data,vFileext,size,optionflag,backupExtension); + ok=ok&&mFormatExportWav(res.data,vFileext,res.size,optionflag,backupExtension); break; case RES_TYPE_IMAGE: /* save image */ /* Palette handling */ - - if (r[id]->palette!=bufferedPalette) { /* The palette isn't in the buffer */ - if (r[id]->palette) { /* We need a palette */ - /* - We need a palette and it is not the palette we have loaded in buffer - So a new palette is going to be loaded. - */ - if ((r[r[id]->palette]->palAux)!=NULL) { /* If this palette wasn't loaded, it becomes loaded */ - mLoadPalette(r[r[id]->palette]->palAux,image); - bufferedPalette=r[id]->palette; /* sets the new palette loaded */ - } - } - } else { - /* It could be that r[id]->palette==bufferedPalette because both are 0, - * in that case there is no buffered palette, but I don't know what palette - * I need (cga case), so I'll use a default hard-coded palette */ - if (!bufferedPalette) { - memcpy(image.pal,DEFAULT_PALETTE,SIZE_OF_PALETTE); - bufferedPalette=-1; /* -1 is the id of this default palette */ - } - } + if (resIdCmp(res.palette,bufferedPalette)) { /* The palette isn't in the buffer */ + tResource readPalette; + readPalette.id=res.palette; + /* read the palette and load it into memory */ + if (mReadFileInDatFileId(&readPalette)) { + /* all right, it's not so bad, I can handle it! I'll buffer the new palette */ + bufferedPalette=readPalette.id; + mLoadPalette(readPalette.data,image,mReadGetVersion()); + resourceListAdd(&paletteBuffer,&readPalette); + } /* else, that's bad, I'll have to use the previous palette, even if it is the default */ + } /* else, good, the palette is buffered */ /* Export bitmap */ - ok=ok&&mFormatExportBmp(data,vFileext,size,image,optionflag,backupExtension); + ok=ok&&mFormatExportBmp(res.data,vFileext,res.size,image,optionflag,backupExtension); break; } @@ -174,23 +156,15 @@ int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int option } } else { /* if the dat file is unknown, add it in the xml */ - getFileName(vFileext,vDirExt,r[id],(unsigned short)id,vFiledat,vDatFileName,optionflag,backupExtension,indexName); + getFileName(vFileext,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension); } - /*freeAllocation(data);*/ } } /* Free allocated resources, dynamic strings and the index */ - for (id=0;id<MAX_RES_COUNT;id++) { - if (r[id]!=NULL) { - freeAllocation(r[id]->palAux); - freeAllocation(r[id]->desc); - freeAllocation(r[id]->name); - freeAllocation(r[id]->path); - free(r[id]); - } - } + resourceListDrop(r); mReadCloseDatFile(); + resourceListDrop(&paletteBuffer); /* Close unknownXML */ endUnknownXml(optionflag,backupExtension); diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index c70229b..8bd8133 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -56,28 +56,29 @@ extern FILE* outputStream; \***************************************************************/ /* Format detection function (private function, not in header file) */ -int mAddCompiledFileToDatFile(unsigned char* data, tResource* res,const char* vFile) { +int mAddCompiledFileToDatFile(tResource* res,const char* vFile) { /* return 1 if ok, 0 if error */ switch (res->type) { case RES_TYPE_LEVEL: - return mFormatImportPlv(data,res); + return mFormatImportPlv(res); case RES_TYPE_IMAGE: - return mFormatImportBmp(data,res); + return mFormatImportBmp(res); case RES_TYPE_WAVE: - return mFormatImportWav(data,res); + return mFormatImportWav(res); case RES_TYPE_MIDI: case RES_TYPE_PCSPEAKER: - return mFormatImportMid(data,res); + return mFormatImportMid(res); case RES_TYPE_PALETTE: - return mFormatImportPal(data,res,vFile); + return mFormatImportPal(res,vFile); case RES_TYPE_BINARY: default: - mWriteFileInDatFile(data,res->size); + mWriteFileInDatFile(res); break; } return 1; } +/* TODO: code the free resources into reslist.c */ #define freeResources \ for (id=0;id<MAX_RES_COUNT;id++) {\ if (r[id]!=NULL) {\ @@ -92,7 +93,7 @@ for (id=0;id<MAX_RES_COUNT;id++) {\ | M A I N F U N C T I O N | \***************************************************************/ -int fullCompile(const char* vFiledat, const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName,const char* backupExtension) { +int fullCompile(const char* vFiledat, const char* vDirExt, tResourceList* r, int optionflag, const char* vDatFileName,const char* backupExtension) { /* Return values: -1 File couldn't be open for writing @@ -103,45 +104,49 @@ int fullCompile(const char* vFiledat, const char* vDirExt, tResource* r[], int o char vFileext[MAX_FILENAME_SIZE]; int error=0; int ok=0; - unsigned char* data; - unsigned short int id=1; + const tResource* res; + tResource newRes; if (!mWriteBeginDatFile(vFiledat,optionflag)) return -1; /* File couldn't be open */ - - for (;id!=MAX_RES_COUNT;id++) { - if (r[id]!=NULL) { - if (hasFlag(raw_flag)) r[id]->type=0; /* compile from raw */ - getFileName(vFileext,vDirExt,r[id],id,vFiledat,vDatFileName,optionflag,backupExtension,"POP1"); + + list_firstCursor(r); + while ((res=list_getCursor(r))) { + /* remember only id and type */ + newRes.id=res->id; + newRes.type=res->type; + + if (hasFlag(raw_flag)) newRes.type=0; /* compile from raw */ + getFileName(vFileext,vDirExt,res,vFiledat,vDatFileName,optionflag,backupExtension); /* the file is in the archive, so i'll add it to the main dat body */ - if ((r[id]->size=((unsigned short)mLoadFileArray(vFileext,&data)))) { - mWriteInitResource(r+id); - if (!mAddCompiledFileToDatFile(data,r[id],vFileext)) { + if ((newRes.size=((unsigned short)mLoadFileArray(vFileext,&newRes.data)))) { + if (!mAddCompiledFileToDatFile(&newRes,vFileext)) { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); error++; } else { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext)); ok++; } - free(data); + /*free(data);*/ } else { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext)); error++; } - } + + list_nextCursor(r); } /* Close file. If empty, don't save */ - mWriteCloseDatFile(r,!ok,optionflag,backupExtension); + mWriteCloseDatFile(!ok,optionflag,backupExtension); /* Free allocated resources and dynamic strings */ - freeResources; + /*freeResources;*/ if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_DONE,ok,error); return error; } #define RW_ERROR {mRWCloseDatFile(1);return 0;} -int partialCompile(const char* vFiledat, const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName,const char* backupExtension) { +int partialCompile(const char* vFiledat, const char* vDirExt, tResourceList* r, int optionflag, const char* vDatFileName,const char* backupExtension) { /* Return values: -2 Previous DAT file was invalid @@ -150,35 +155,25 @@ int partialCompile(const char* vFiledat, const char* vDirExt, tResource* r[], in positive number: number of missing files */ - char vFileext[MAX_FILENAME_SIZE]; + /*char vFileext[MAX_FILENAME_SIZE];*/ int error,ok=0; int indexNumber; - long int id; - unsigned char* data; - unsigned long int size; - unsigned long int flags; unsigned short int numberOfItems; - char* indexName; + tResource res; /* Initialize abstract variables to read this new DAT file */ if ((error=mRWBeginDatFile(vFiledat,&numberOfItems,optionflag))) return error; /* main loop */ for (indexNumber=0;(indexNumber<numberOfItems);indexNumber++) { - id=mReadFileInDatFile(indexNumber,&data,&size,&flags,&indexName); - - /* Validations */ - if (id<0) { + if (!mReadFileInDatFile(&res,indexNumber)) { mRWCloseDatFile(0); RW_ERROR; /* Read error */ } - if (id==0xFFFF) continue; /* Tammo Jan Bug fix */ - if (id>=MAX_RES_COUNT) { - mRWCloseDatFile(0); - RW_ERROR; /* A file with an ID out of range will be treated as invalid */ - } +/* if (res->id.value==0xFFFF) continue; * Tammo Jan Bug fix TODO: move to the dat layer? */ - mWriteInitResource(r+id); +/* mWriteInitResource(r+id);*/ +#if 0 /* TODO: recode this based on extract function */ if (r[id]&&isInThePartialList(r[id]->path,id)) { /* If the resource was specified */ if (hasFlag(raw_flag)) r[id]->type=0; /* compile from raw */ getFileName(vFileext,vDirExt,r[id],(unsigned short)id,vFiledat,vDatFileName,optionflag,backupExtension,"POP1"); @@ -201,19 +196,20 @@ int partialCompile(const char* vFiledat, const char* vDirExt, tResource* r[], in r[id]->size=size-1; mWriteFileInDatFileIgnoreChecksum(data,size); } +#endif } /* Close dat file */ mRWCloseDatFile(0); /* Free allocated resources and dynamic strings */ - freeResources; + /*freeResources;*/ if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_DONE,ok,error); return error; } -int compile(const char* vFiledat, const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName,const char* backupExtension) { +int compile(const char* vFiledat, const char* vDirExt, tResourceList* r, int optionflag, const char* vDatFileName,const char* backupExtension) { if (partialListActive()) { return partialCompile(vFiledat,vDirExt,r,optionflag,vDatFileName,backupExtension); diff --git a/PR/src/lib/formats/bmp.c b/PR/src/lib/formats/bmp.c index 069d7aa..11ced6c 100644 --- a/PR/src/lib/formats/bmp.c +++ b/PR/src/lib/formats/bmp.c @@ -68,16 +68,14 @@ int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned lo } -int mFormatImportBmp(unsigned char* data, tResource *res) { +int mFormatImportBmp(tResource *res) { int size; tImage img; - unsigned char* aux; - if (!mReadBitMap(&img,data,res->size)) return 0; - mCompressGraphic(&aux,&img,&size); - mWriteFileInDatFile(aux,size); + if (!mReadBitMap(&img,res->data,res->size)) return 0; + mCompressGraphic(&(res->data),&img,(int*)&(res->size)); + mWriteFileInDatFile(res); free(img.pix); - free(aux); res->size=(unsigned short)size; return 1; diff --git a/PR/src/lib/formats/mid.c b/PR/src/lib/formats/mid.c index d3315ee..95b54fc 100644 --- a/PR/src/lib/formats/mid.c +++ b/PR/src/lib/formats/mid.c @@ -44,14 +44,15 @@ int mFormatExportMid(const unsigned char* data, char *vFileext,unsigned long int return writeData(data,2,vFileext,size,optionflag,backupExtension); } -int mFormatImportMid(unsigned char* data, tResource *res) { +int mFormatImportMid(tResource *res) { unsigned char* file; file=getMemory(res->size+1); file[0]=(unsigned char)((res->type==4)?2:0); /* Now should be 0x02: First character must be a 0x01 (wav type in dat) */ - memcpy(file+1,data,res->size); + memcpy(file+1,res->data,res->size); res->size++; - mWriteFileInDatFile(file,res->size); - free(file); + free(res->data); + res->data=file; + mWriteFileInDatFile(res); return 1; } diff --git a/PR/src/lib/formats/pal.c b/PR/src/lib/formats/pal.c index 0c6e41d..0bf604c 100644 --- a/PR/src/lib/formats/pal.c +++ b/PR/src/lib/formats/pal.c @@ -80,7 +80,7 @@ int mFormatExportPal(const unsigned char* data, char *vFileext,unsigned long int return i; } -int mFormatImportPal(unsigned char* data, tResource *res,const char* vFile) { +int mFormatImportPal(tResource *res,const char* vFile) { /* declare variables */ unsigned char* pals; @@ -102,7 +102,7 @@ int mFormatImportPal(unsigned char* data, tResource *res,const char* vFile) { if ((res->size)<130) return 0; /* verify jasc pal header */ - while (palh[i]==(data)[i++]); + while (palh[i]==(res->data)[i++]); if (i!=sizeof(palh)) return 0; /* palette differs with headers */ /* Read sample */ @@ -123,7 +123,7 @@ int mFormatImportPal(unsigned char* data, tResource *res,const char* vFile) { if (sample1) free(pals1); /* set current values */ - data2=strtok((char*)(data)+sizeof(palh)-1,enter); + data2=strtok((char*)(res->data)+sizeof(palh)-1,enter); while (k--) { if (!sscanf(data2,"%d %d %d",&r,&g,&b)) return 0; /* Those lines mean a loss of data (palette colors are saved in the nearest multiple of 4) */ @@ -134,7 +134,10 @@ int mFormatImportPal(unsigned char* data, tResource *res,const char* vFile) { } /* save and free palette */ - mWriteFileInDatFile(pal,res->size=100); + res->size=100; + free(res->data); + res->data=pal; + mWriteFileInDatFile(res); free(pal); return 1; diff --git a/PR/src/lib/formats/plv.c b/PR/src/lib/formats/plv.c index e7b561e..6aceef9 100644 --- a/PR/src/lib/formats/plv.c +++ b/PR/src/lib/formats/plv.c @@ -167,17 +167,17 @@ int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned lo extern FILE* outputStream; -int mFormatImportPlv(unsigned char* data, tResource *res) { +int mFormatImportPlv(tResource *res) { /* declare variables */ unsigned char* pos; unsigned long int oldSize=res->size; /* integrity check 1 */ if (oldSize<=PLV_HEADER_A_SIZE+1+PLV_HEADER_B_SIZE) return 0; - if (memcmp(data,PLV_HEADER_A,PLV_HEADER_A_SIZE)) return 0; + if (memcmp(res->data,PLV_HEADER_A,PLV_HEADER_A_SIZE)) return 0; /* jump to size */ - pos=data+PLV_HEADER_A_SIZE+1+PLV_HEADER_B_SIZE; + pos=res->data+PLV_HEADER_A_SIZE+1+PLV_HEADER_B_SIZE; /* read size and jump to data */ res->size=array2long(pos);pos+=4; @@ -190,7 +190,8 @@ int mFormatImportPlv(unsigned char* data, tResource *res) { fprintf(outputStream,PR_TEXT_IMPORT_PLV_WARN); /* save data */ - mWriteFileInDatFileIgnoreChecksum(pos,res->size--); + res->data=pos; + mWriteFileInDatFileIgnoreChecksum(res); /* TODO: check res->size-- */ return 1; } diff --git a/PR/src/lib/formats/wav.c b/PR/src/lib/formats/wav.c index d416add..2f96d9c 100644 --- a/PR/src/lib/formats/wav.c +++ b/PR/src/lib/formats/wav.c @@ -61,14 +61,16 @@ int mFormatExportWav(const unsigned char* data, char *vFileext,unsigned long int return ok; } -int mFormatImportWav(unsigned char* data, tResource *res) { +int mFormatImportWav(tResource *res) { unsigned char wav[]=WAVE_HEADER; int i=sizeof(wav); if (res->size<=i) return 0; res->size-=(--i); - while ((i==4||i==5||i==6||i==7||i==40||i==41||i==42||i==43||(data[i]==wav[i]))&&(i--)); - data[sizeof(wav)-1]=1; /* First character must be a 0x01 (wav type in dat) */ - if (i==-1) mWriteFileInDatFile(data+sizeof(wav)-1,res->size); + while ((i==4||i==5||i==6||i==7||i==40||i==41||i==42||i==43||((res->data)[i]==wav[i]))&&(i--)); + (res->data)[sizeof(wav)-1]=1; /* First character must be a 0x01 (wav type in dat) */ + res->data+=sizeof(wav)-1; + if (i==-1) mWriteFileInDatFile(res); return 1; } + diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c index 3cc79fd..3d59fc4 100644 --- a/PR/src/lib/layers/autodetect.c +++ b/PR/src/lib/layers/autodetect.c @@ -239,27 +239,24 @@ int checkSum(const unsigned char* data,int size) { | Parsing resource file | \***************************************************************/ -/* Initializes the resource table */ -void emptyTable(tResource* r[]) { - int i=MAX_RES_COUNT; - while (i--) *(r++)=NULL; -} - /* parse file */ -int parseFile(const char* vFile, const char* datFile, tResource* r[]) { +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 */ +printf("DEBUG: a punto de leer la estructura xml\n"); if ((error=parseStructure(vFile,&structure))) return error; +printf("DEBUG: termine de leer la estructura xml\n"); /* Use the xml structure to Generate the resource structure of the file */ - emptyTable(r); + /*emptyTable(r);*/ pass.datFile=datFile; pass.r=r; workTree(structure,&pass,workTag); +printf("DEBUG: termine de crear la resList a aprtir del datfile\n"); /* All done */ return 0; @@ -272,7 +269,8 @@ int parseFile(const char* vFile, const char* datFile, tResource* r[]) { /* Resources output to xml functions. Private+abstract variable */ static FILE* unknownXmlFile=NULL; -void AddToUnknownXml(const char* vFiledatWithPath,unsigned short id,const char* ext,char type,const char* vDirExt,unsigned short pal,const char* vFiledat,int optionflag,int count,const char* indexName) { +void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,char type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count) { + /* TODO: use lowercase for .index values */ /* Open file if not open */ if (unknownXmlFile==NULL) { char xmlFile[MAX_FILENAME_SIZE]; @@ -284,13 +282,13 @@ void AddToUnknownXml(const char* vFiledatWithPath,unsigned short id,const char* /* Save headers */ if (type==6) pal=id; fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, - vFiledat,vFiledatWithPath,pal + vFiledat,vFiledatWithPath,pal.value,pal.index ); } /* Write item */ fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, - id,indexName,getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count + id.value,id.index,getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count ); /* To the xml output */ } @@ -310,7 +308,7 @@ void endUnknownXml(int optionflag, const char* backupExtension) { | Resources extra functions | \***************************************************************/ -void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short id,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension,const char* indexName) { +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; @@ -320,7 +318,7 @@ void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short /* set filename */ sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vDatFileName,getExtDesc(pos),typeCount[pos],extarray[pos]); - AddToUnknownXml(vDatFileName,id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos],indexName); + 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/dat.c b/PR/src/lib/layers/dat.c index 8f9ee5b..34da397 100644 --- a/PR/src/lib/layers/dat.c +++ b/PR/src/lib/layers/dat.c @@ -39,6 +39,8 @@ dat.c: Princed Resources : DAT library #include "common.h" #include "dat.h" +#include "reslist.h" + /***************************************************************\ | DAT reading primitives | \***************************************************************/ @@ -65,15 +67,55 @@ tIndexCursor readIndexCursor; /* private functions */ /* todo: move to datindex.c */ +/* the cursor get functions */ + +#define dat_readCursorGetIndexName(r) (r.slaveIndexName) +#define dat_readCursorGetId(r) (array2short(r.currentRecord)) +#define dat_readCursorGetOffset(r) (array2long(r.currentRecord+2)) +#define dat_readCursorGetSize(r) (array2short(r.currentRecord+6)) +#define dat_readCursorGetFlags(r) ((r.popVersion==pop1)?(1<<31):(r.currentRecord[8]<<16|r.currentRecord[9]<<8|r.currentRecord[10])) +#define dat_readCursorGetVersion(r) (r.popVersion) + +/* the cursor move functions */ + +int dat_cursorNextIndex(tIndexCursor* r) { + if (r->popVersion==pop1) { + /* POP1 */ + return 0; + } else { + /* POP2 */ + if (r->currentMasterItem==r->masterItems) { + return 0; /* its over */ + } + + /* remember the new slave index name */ + strncpy(r->slaveIndexName,(char*)(r->highData+2+6*r->currentMasterItem),4); + + /* remember the new slave index size */ + r->slaveItems=array2short(r->highData+array2short(r->highData+6+6*r->currentMasterItem)); + + /* jump to next index */ + r->currentMasterItem++; + r->currentSlaveItem=0; + r->currentRecord=r->highData+array2short(r->highData+6+6*r->currentMasterItem)+2; + } + return 1; +} + int dat_cursorNext(tIndexCursor* r) { if (r->popVersion==pop1) { /* POP1 */ - if (r->currentSlaveItem==r->slaveItems) return 0; - r->currentSlaveItem++; - r->currentRecord+=8; + if (r->currentSlaveItem==r->slaveItems) { + return 0; + } else { + r->currentSlaveItem++; + r->currentRecord+=8; + } } else { /* POP2 */ if (r->currentSlaveItem==r->slaveItems) { + return dat_cursorNextIndex(r); +#if 0 if (r->currentMasterItem==r->masterItems) { return 0; /* its over */ } @@ -88,7 +130,7 @@ int dat_cursorNext(tIndexCursor* r) { r->currentMasterItem++; r->currentSlaveItem=0; r->currentRecord=r->highData+array2short(r->highData+6+6*r->currentMasterItem)+2; - +#endif } else { r->currentSlaveItem++; r->currentRecord+=11; @@ -97,26 +139,35 @@ int dat_cursorNext(tIndexCursor* r) { return 1; } -tIndexCursor dat_initPop2IndexCursor(unsigned char* highData,int highDataSize) { - tIndexCursor r; - r.popVersion=pop2; - r.highData=highData; - r.highDataSize=highDataSize; - r.masterItems=array2short(highData); - - /* remember the first slave index name */ - strncpy(r.slaveIndexName,(char*)(highData+2),4); - r.slaveIndexName[4]=0; /* now it is a null terminated string */ - - /* remember the first slave index size */ - r.slaveItems=array2short(highData+array2short(highData+6)); - - /* jump to the first index */ - r.currentMasterItem=0; - r.currentSlaveItem=0; - r.currentRecord=r.highData+array2short(r.highData+6)+2; +void dat_cursorFirst(tIndexCursor* r) { + if (r->popVersion==pop2) { + /* remember the first slave index name */ + strncpy(r->slaveIndexName,(char*)(r->highData+2),4); + r->slaveIndexName[4]=0; /* now it is a null terminated string */ + r->currentRecord=r->highData+array2short(r->highData+6)+2; + } else { + r->currentRecord=r->highData+2; + } - return r; + /* jump to the first index */ + r->currentMasterItem=0; + r->currentSlaveItem=0; +} + +int dat_cursorMoveId(tIndexCursor* r, tResourceId id) { + dat_cursorFirst(r); + /* first try to find the index name */ + do { + if (!strcmp(r->slaveIndexName,id.index)) { + /* the same index */ + do { + if (strcmp(r->slaveIndexName,id.index)) return 0; /* in case we are passed */ + if (array2short(r->currentRecord)==id.value) return 1; /* found! */ + } while (dat_cursorNext(r)); + return 0; /* id not found */ + } + } while (dat_cursorNextIndex(r)); + return 0; /* index name not found */ } int dat_cursorMove(tIndexCursor* r,int pos) { @@ -137,6 +188,7 @@ int dat_cursorMove(tIndexCursor* r,int pos) { /* remember the new slave index name */ strncpy(r->slaveIndexName,(char*)(r->highData+2+6*i),4); + r->slaveIndexName[4]=0; /* now it is a null terminated string */ /* remember the new slave index size */ r->slaveItems=itemCount; @@ -152,30 +204,8 @@ int dat_cursorMove(tIndexCursor* r,int pos) { return 0; /* we had read all the master index and we didn't read the pos */ } } - -#define dat_readCursorGetIndexName(r) (r.slaveIndexName) -#define dat_readCursorGetId(r) (array2short(r.currentRecord)) -#define dat_readCursorGetOffset(r) (array2long(r.currentRecord+2)) -#define dat_readCursorGetSize(r) (array2short(r.currentRecord+6)) -#define dat_readCursorGetFlags(r) ((r.popVersion==pop1)?(1<<31):(r.currentRecord[8]<<16|r.currentRecord[9]<<8|r.currentRecord[10])) -#define dat_readCursorGetVersion(r) (r.popVersion) - -tIndexCursor dat_initPop1IndexCursor(unsigned char* highData,int highDataSize) { - tIndexCursor r; - r.popVersion=pop1; - r.highData=highData; - r.highDataSize=highDataSize; - r.slaveItems=array2short(highData); - /* remember the first slave index name */ - strcpy(r.slaveIndexName,"POP1"); - - /* jump to the first index */ - r.currentSlaveItem=0; - r.currentRecord=r.highData+2; - - return r; -} +/* the detect function */ tPopVersion detectPopVersion(unsigned char* highArea,int highAreaSize,unsigned short int *numberOfItems) { const unsigned char* cursor; @@ -223,6 +253,49 @@ tPopVersion detectPopVersion(unsigned char* highArea,int highAreaSize,unsigned s return pop2; } +/* the cursor create functions */ + +/* TODO: abstract the cursor library from pop version, merge pop1 & pop2 create */ + +tIndexCursor dat_initPop2IndexCursor(unsigned char* highData,int highDataSize) { + tIndexCursor r; + r.popVersion=pop2; + r.highData=highData; + r.highDataSize=highDataSize; + r.masterItems=array2short(highData); + + /* remember the first slave index name */ + strncpy(r.slaveIndexName,(char*)(highData+2),4); + r.slaveIndexName[4]=0; /* now it is a null terminated string */ + + /* remember the first slave index size */ + r.slaveItems=array2short(highData+array2short(highData+6)); + + /* jump to the first index */ + r.currentMasterItem=0; + r.currentSlaveItem=0; + r.currentRecord=r.highData+array2short(r.highData+6)+2; + + return r; +} + +tIndexCursor dat_initPop1IndexCursor(unsigned char* highData,int highDataSize) { + tIndexCursor r; + r.popVersion=pop1; + r.highData=highData; + r.highDataSize=highDataSize; + r.slaveItems=array2short(highData); + + /* remember the first slave index name */ + strcpy(r.slaveIndexName,"POP1"); + + /* jump to the first index */ + r.currentSlaveItem=0; + r.currentRecord=r.highData+2; + + return r; +} + tIndexCursor dat_createCursor(unsigned char* indexOffset,int indexSize,unsigned short int* numberOfItems) { tPopVersion popVersion; tIndexCursor cursor; @@ -288,45 +361,44 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ return 0; } -int mReadFileInDatFile(int k,unsigned char* *data,unsigned long int *size, unsigned long int *flags,char* *index) { - unsigned short int id; - unsigned long int offset; +int mReadFileInDatFileId(tResource* res) { + if (!dat_cursorMoveId(&readIndexCursor,res->id)) return 0; /* 0 means index not found */ + /* TODO: use a function for common parts */ - if (!dat_cursorMove(&readIndexCursor,k)) return -2; /* -2 means: out of range */ - /* for each archived file the index is read */ - id= dat_readCursorGetId (readIndexCursor); - offset=dat_readCursorGetOffset (readIndexCursor); - *size= dat_readCursorGetSize (readIndexCursor); - *flags=dat_readCursorGetFlags (readIndexCursor); - *index=dat_readCursorGetIndexName (readIndexCursor); + res->id.value= dat_readCursorGetId (readIndexCursor); + strncpy(res->id.index,dat_readCursorGetIndexName (readIndexCursor),5); + res->offset= dat_readCursorGetOffset (readIndexCursor); + res->size= dat_readCursorGetSize (readIndexCursor); + res->flags= dat_readCursorGetFlags (readIndexCursor); /* if (offset>indexOffset) return -1; * a resourse offset is allways before the index offset TODO: move this check to detect pop version*/ - (*size)++; /* add the checksum */ + res->size++; /* add the checksum */ -printf("DEBUG: id=%d offset=%lu size=%lu flags=0x%08x index=%s\n",id,offset,*size,(int)(*flags),*index); - *data=readDatFile+offset; + res->data=readDatFile+res->offset; - return id; + return 1; + } -int mReadInitResource(tResource** res,const unsigned char* data,long size) { - if ((*res)==NULL) { - (*res)=(tResource*)malloc(sizeof(tResource)); - if ((*res)==NULL) return -1; /* no memory */ - (*res)->path=NULL; - (*res)->palAux=NULL; - (*res)->desc=NULL; - (*res)->name=NULL; - (*res)->palette=0; - (*res)->number=0; - (*res)->size=(unsigned short int)size; - (*res)->type=verifyHeader(data,(unsigned short int)size); - } else { /* If resource type is invalid or 0, the type will be decided by PR */ - if (!((*res)->type)) (*res)->type=verifyHeader(data,(unsigned short int)size); - } - return 0; +int mReadFileInDatFile(tResource* res, int k) { + + if (!dat_cursorMove(&readIndexCursor,k)) return 0; /* 0 means out of range */ + + /* for each archived file the index is read */ + res->id.value= dat_readCursorGetId (readIndexCursor); + strncpy(res->id.index,dat_readCursorGetIndexName (readIndexCursor),5); + res->offset= dat_readCursorGetOffset (readIndexCursor); + res->size= dat_readCursorGetSize (readIndexCursor); + res->flags= dat_readCursorGetFlags (readIndexCursor); + + /* if (offset>indexOffset) return -1; * a resourse offset is allways before the index offset TODO: move this check to detect pop version*/ + res->size++; /* add the checksum */ + res->data=readDatFile+res->offset; + + return 1; } + #endif /***************************************************************\ @@ -335,6 +407,7 @@ int mReadInitResource(tResource** res,const unsigned char* data,long size) { #ifdef PR_DAT_INCLUDE_DATWRITE FILE* writeDatFile; +tResourceList resIndex; int mWriteBeginDatFile(const char* vFile, int optionflag) { /* @@ -348,6 +421,7 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) { */ if (writeOpen(vFile,&writeDatFile,optionflag|backup_flag)) { short fill=0; + resIndex=resourceListCreate(); 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 */ @@ -356,7 +430,7 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) { return 0; } } - +/* void mWriteInitResource(tResource** res) { if ((*res)==NULL) { (*res)=(tResource*)malloc(sizeof(tResource)); @@ -367,51 +441,75 @@ void mWriteInitResource(tResource** res) { } (*res)->offset=(unsigned long)ftell(writeDatFile); } +*/ + +void dat_write(const tResource* res,unsigned long off) { + tResource insert; + + /* do the magic */ + fwrite(res->data,res->size,1,writeDatFile); + + /* remember only indexed values */ + insert.id=res->id; + insert.size=res->size; + insert.offset=off; + + /* TODO: use an abstract use of the list (at least macros in reslist.h) */ + list_insert(&resIndex,&insert); +} -void mWriteFileInDatFile(const unsigned char* data, int size) { +void mWriteFileInDatFileIgnoreChecksum(const tResource* res) { + dat_write(res,(unsigned long)ftell(writeDatFile)); +} + +void mWriteFileInDatFile(const tResource* res) { /* Adds a data resource to a dat file keeping abstractly the checksum verifications */ /* Declare variables */ - int k = size; + int k = res->size; unsigned char checksum = 0; - const unsigned char* dataAux = data; + const unsigned char* dataAux = res->data; + unsigned long off; /* calculates the checksum */ while (k--) checksum+=*(dataAux++); checksum=~checksum; /* writes the checksum and the data content */ + off=(unsigned long)ftell(writeDatFile); fwritechar(&checksum,writeDatFile); - fwrite(data,size,1,writeDatFile); -} -void mWriteFileInDatFileIgnoreChecksum(unsigned char* data, int size) { - fwrite(data,size,1,writeDatFile); + /* write the resource contents */ + dat_write(res,off); } -void mWriteCloseDatFile(tResource* r[],int dontSave,int optionflag, const char* backupExtension) { + +void mWriteCloseDatFile(int dontSave,int optionflag, const char* backupExtension) { /* Closes a dat file filling the index and other structures */ - unsigned short int id=1; unsigned short int totalItems=0; unsigned short int size2=2; unsigned long int size1=ftell(writeDatFile); + const tResource* res; /* Write index */ fwriteshort(&totalItems,writeDatFile); /* Junk total items count to reserve 2 bytes */ - for (;id!=MAX_RES_COUNT;id++) { - if (r[id]!=NULL) { - /* the file is in the archive, so i'll add it to the index */ - totalItems++; - fwriteshort(&id,writeDatFile); - fwritelong(&(r[id]->offset),writeDatFile); - fwriteshort(&(r[id]->size),writeDatFile); - } + + /* TODO: use an abstract use of the list (at least macros in reslist.h) */ + list_firstCursor(&resIndex); + while ((res=list_getCursor(&resIndex))) { + totalItems++; + fwriteshort(&(res->id.value),writeDatFile); + fwritelong(&(res->offset),writeDatFile); + fwriteshort(&(res->size),writeDatFile); + + list_nextCursor(&resIndex); } + size2+=totalItems<<3; fseek(writeDatFile,size1,SEEK_SET); fwriteshort(&totalItems,writeDatFile); /* Definitive total items count */ @@ -423,6 +521,9 @@ void mWriteCloseDatFile(tResource* r[],int dontSave,int optionflag, const char* /* Closes the file and flushes the buffer */ writeClose(writeDatFile,dontSave,optionflag,backupExtension); + + /* drops the index list */ + resourceListDrop(&resIndex); } #endif @@ -442,3 +543,4 @@ int mRWBeginDatFile(const char* vFile, unsigned short int *numberOfItems, int op } #endif #endif + diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c index 3cc79fd..3d59fc4 100644 --- a/PR/src/lib/layers/idlist.c +++ b/PR/src/lib/layers/idlist.c @@ -239,27 +239,24 @@ int checkSum(const unsigned char* data,int size) { | Parsing resource file | \***************************************************************/ -/* Initializes the resource table */ -void emptyTable(tResource* r[]) { - int i=MAX_RES_COUNT; - while (i--) *(r++)=NULL; -} - /* parse file */ -int parseFile(const char* vFile, const char* datFile, tResource* r[]) { +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 */ +printf("DEBUG: a punto de leer la estructura xml\n"); if ((error=parseStructure(vFile,&structure))) return error; +printf("DEBUG: termine de leer la estructura xml\n"); /* Use the xml structure to Generate the resource structure of the file */ - emptyTable(r); + /*emptyTable(r);*/ pass.datFile=datFile; pass.r=r; workTree(structure,&pass,workTag); +printf("DEBUG: termine de crear la resList a aprtir del datfile\n"); /* All done */ return 0; @@ -272,7 +269,8 @@ int parseFile(const char* vFile, const char* datFile, tResource* r[]) { /* Resources output to xml functions. Private+abstract variable */ static FILE* unknownXmlFile=NULL; -void AddToUnknownXml(const char* vFiledatWithPath,unsigned short id,const char* ext,char type,const char* vDirExt,unsigned short pal,const char* vFiledat,int optionflag,int count,const char* indexName) { +void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,char type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count) { + /* TODO: use lowercase for .index values */ /* Open file if not open */ if (unknownXmlFile==NULL) { char xmlFile[MAX_FILENAME_SIZE]; @@ -284,13 +282,13 @@ void AddToUnknownXml(const char* vFiledatWithPath,unsigned short id,const char* /* Save headers */ if (type==6) pal=id; fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, - vFiledat,vFiledatWithPath,pal + vFiledat,vFiledatWithPath,pal.value,pal.index ); } /* Write item */ fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, - id,indexName,getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count + id.value,id.index,getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count ); /* To the xml output */ } @@ -310,7 +308,7 @@ void endUnknownXml(int optionflag, const char* backupExtension) { | Resources extra functions | \***************************************************************/ -void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short id,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension,const char* indexName) { +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; @@ -320,7 +318,7 @@ void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short /* set filename */ sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vDatFileName,getExtDesc(pos),typeCount[pos],extarray[pos]); - AddToUnknownXml(vDatFileName,id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos],indexName); + 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/list.c b/PR/src/lib/layers/list.c index 37e5504..89cfde0 100644 --- a/PR/src/lib/layers/list.c +++ b/PR/src/lib/layers/list.c @@ -33,9 +33,10 @@ list.c: Princed Resources : Ordered Read-Only list implementarion /* Defines */ #include <stdlib.h> +#include <string.h> /* memcpy */ #include "list.h" -tList list_create(int dataSize,int dataCmp(void*,void*)) { +tList list_create(int dataSize,int dataCmp(const void*,const void*)) { tList r; r.size=dataSize; r.cmp=dataCmp; @@ -44,7 +45,7 @@ tList list_create(int dataSize,int dataCmp(void*,void*)) { return r; } -void list_insert(tList *list,void* data) { +void list_insert(tList *list,const void* data) { /* I will assume sequential access is very common, * so it is very possible that data is the next element. * I will check that and if not I'll start a sequential search */ @@ -53,7 +54,7 @@ void list_insert(tList *list,void* data) { node->data=malloc(list->size); memcpy(node->data,data,list->size); - if (!list->cursor) { + if (!list->first) { /* insert first */ list->first=node; node->next=NULL; @@ -97,16 +98,15 @@ void list_firstCursor(tList* list) { list->cursor=list->first; } -int list_moveCursor(tList* list,void* data) { - if (!list->cursor) { +int list_moveCursor(tList* list,const void* data) { + if (!list->first) { return 0; } else { /* if the data was lower, start searching from the beginning */ - if (list->cmp(list->cursor->data/*>*/,data)==GT) list->cursor=list->first; + if ((!list->cursor)||(list->cmp(list->cursor->data/*>*/,data)==GT)) list->cursor=list->first; /* in case the first record is higher than the data, we will move the cursor to the first and return 0 */ if ((list->cursor==list->first) && (list->cmp(list->first->data/*>=*/,data)!=LT)) { - list->cursor=list->first; - return 0; + return list->cmp(list->first->data/*==*/,data)==EQ; } else { /* search until we find the first higher record or the end of the list */ while ((list->cursor->next) && (list->cmp(list->cursor->next->data/*>*/,data)!=GT)) diff --git a/PR/src/lib/layers/reslist.c b/PR/src/lib/layers/reslist.c index 198d88f..7436fe9 100644 --- a/PR/src/lib/layers/reslist.c +++ b/PR/src/lib/layers/reslist.c @@ -32,50 +32,82 @@ reslist.c: Princed Resources : Ordered Read-Only list implementarion */ /* Defines */ -#include "list.h" - -/* app test */ +#include "reslist.h" +#include <string.h> /* strncmp */ +#include <stdio.h> /* debug */ + +/* resource list layer (that uses the abstract list layer primitives) */ + +int resIdCmp(tResourceId a,tResourceId b) { + /* the number has the priority */ + if (a.value>b.value) return GT; + if (a.value<b.value) return LT; + /* at this point, the numbers are the same, so the index name is the comparation */ + return strncmp(a.index,b.index,4); +} -int dataCmp(void* a,void* b) { - int ap,bp; - ap=*((int*)a); - bp=*((int*)b); +int resCmp(const void* a,const void* b) { + return resIdCmp(((tResource*)a)->id,((tResource*)b)->id); +} - if (ap>bp) return GT; - if (ap<bp) return LT; - return EQ; +void resourceListDrop(tResourceList* r) { + list_drop(r); } +tResourceList resourceListCreate() { + return list_create(sizeof(tResource),resCmp); +} -int main(int a, char** b) { - tList lista; - const int* value; - int k; - int i; +void resourceListAdd(tResourceList* r,const tResource* res) { + /* first try to detect if the resource exists */ + if (!list_moveCursor(r,res)) + list_insert(r,res); +} - lista=list_create(sizeof(int),dataCmp); +void printr(const tResource* record) { + printf("id=(%d,%s)\n",record->id.value,record->id.index); + printf("palette=(%d,%s)\n",record->palette.value,record->palette.index); + printf("size=%d offset=%lu\n",record->size,record->offset); + printf("number=%d type=%d\n",record->number,record->type); + printf("path='%s' name='%s' desc='%s'\n\n",record->path,record->name,record->desc); +} - for (i=1;i<a;i++) { - k=atoi(b[i]); - list_insert(&lista,&k); +void resourceListDebugPrint(tResourceList* r) { + const tResource* record; + list_firstCursor(r); + while ((record=list_getCursor(r))) { + printr(record); + list_nextCursor(r); } + list_firstCursor(r); +} - list_firstCursor(&lista); - while (value=list_getCursor(&lista)) { - printf("value: %d\n",*value); - list_nextCursor(&lista); +#include "resources.h" /* verifyHeader TODO: set 0 and autodetect type 0 in extraction time */ +void resourceListAddInfo(tResourceList* r,tResource* res) { + if (!list_moveCursor(r,res)) { + res->path=NULL; + res->palAux=NULL; + res->desc=NULL; + res->name=NULL; + res->palette.value=0; + memset(res->palette.index,0,5); + res->number=0; + res->type=verifyHeader(res->data,res->size); /* TODO: send the verifyHeader to the export module */ + } else { + const tResource* resInfo=list_getCursor(r); + /* copy only the list information */ + res->path=resInfo->path; + res->palAux=resInfo->palAux; + res->desc=resInfo->desc; + res->name=resInfo->name; + res->palette=resInfo->palette; + res->number=resInfo->number; + /* If resource type is invalid or 0, the type will be decided by PR */ + if (!resInfo->type) { + res->type=verifyHeader(res->data,res->size); + } else { + res->type=resInfo->type; + } } - - list_firstCursor(&lista); - k=100; - i=list_moveCursor(&lista,&k); - if (value=list_getCursor(&lista)) - printf("value prior 100: %d %d\n",*value,i); - - - printf("listo\n"); - list_drop(&lista); - return 0; } - diff --git a/PR/src/lib/pr.c b/PR/src/lib/pr.c index d884694..918618b 100644 --- a/PR/src/lib/pr.c +++ b/PR/src/lib/pr.c @@ -22,7 +22,7 @@ pr.c: Main source file for Princed Resources library \xaf\xaf\xaf\xaf Princed Resources editor - (c) Copyright 2003, Princed Development Team + (c) Copyright 2003-2005 Princed Development Team Authors Coding & main routines @@ -120,12 +120,14 @@ int prExportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF */ /* Declare variables */ - tResource* r[MAX_RES_COUNT]; + tResourceList r; int a; const char* aux; char* currentDatFileName; char* currentDatFile; + r=resourceListCreate(); + currentDatFile=strallocandcopy(vDatFile); parseGivenPath(currentDatFile); @@ -138,14 +140,15 @@ int prExportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF currentDatFileName=strallocandcopy(aux); /* Parse XML and export the file */ - a=parseFile(vResFile,currentDatFileName,r); + a=parseFile(vResFile,currentDatFileName,&r); if (a<0) { /* parsing errors */ a-=3; } else { /* exporting errors/no errors */ - a=extract(currentDatFile,vDirName,r,opt,currentDatFileName,datAuthor,backupExtension); + a=extract(currentDatFile,vDirName,&r,opt,currentDatFileName,datAuthor,backupExtension); } + resourceListDrop(&r); free(currentDatFileName); free(currentDatFile); freePartialList(); @@ -197,12 +200,14 @@ int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF */ /* Declare variables */ - tResource* r[MAX_RES_COUNT]; + tResourceList r; int a; const char* aux; char* currentDatFileName; char* currentDatFile; + r=resourceListCreate(); + currentDatFile=strallocandcopy(vDatFile); parseGivenPath(currentDatFile); @@ -215,14 +220,15 @@ int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF currentDatFileName=strallocandcopy(aux); /* Parse XML and import files */ - a=parseFile(vResFile,currentDatFileName,r); + a=parseFile(vResFile,currentDatFileName,&r); if (a<0) { /* parsing errors */ a-=2; } else { /* importing errors/no errors */ - a=compile (currentDatFile, vDirName,r,opt,currentDatFileName,backupExtension); + a=compile (currentDatFile, vDirName,&r,opt,currentDatFileName,backupExtension); } + resourceListDrop(&r); free(currentDatFileName); free(currentDatFile); freePartialList(); diff --git a/PR/src/lib/xml/parse.c b/PR/src/lib/xml/parse.c index 14dbbfb..c9d0331 100644 --- a/PR/src/lib/xml/parse.c +++ b/PR/src/lib/xml/parse.c @@ -87,6 +87,7 @@ tTag* getTagStructure() { t->type=NULL; t->value=NULL; t->index=NULL; + t->paletteindex=NULL; t->version=NULL; t->number=NULL; @@ -107,6 +108,7 @@ void freeTagStructure(tTag* t) { freeAllocation(t->type); freeAllocation(t->value); freeAllocation(t->index); + freeAllocation(t->paletteindex); freeAllocation(t->version); freeAllocation(t->number); free(t); @@ -133,7 +135,8 @@ int attribFill(char* attr,char* val, tTag* t) { FillAttr(t->palette,"palette"); FillAttr(t->type,"type"); FillAttr(t->value,"value"); - FillAttr(t->value,"index"); + FillAttr(t->index,"index"); + FillAttr(t->paletteindex,"paletteindex"); FillAttr(t->version,"version"); FillAttr(t->number,"levelnumber"); /* levelnumber is a number alias */ FillAttr(t->number,"number"); @@ -364,6 +367,7 @@ tTag* makeTree(char** p,char* name, int* error,tTag* father) { char* str; TotalInheritance(palette); + TotalInheritance(paletteindex); TotalInheritance(itemtype); TotalInheritance(file); TotalInheritance(index); diff --git a/PR/src/lib/xml/search.c b/PR/src/lib/xml/search.c index 4ba13a0..a723cd4 100644 --- a/PR/src/lib/xml/search.c +++ b/PR/src/lib/xml/search.c @@ -39,59 +39,77 @@ xmlsearch.c: Princed Resources : specific xml handling functions /* Includes */ #include "common.h" #include "xmlparse.h" -#include "resources.h" +#include "reslist.h" /* only to add to the list */ #include "xmlsearch.h" #include "memory.h" #include <string.h> +void str5uppercpy (char* dst,const char* src) { + int i; + for (i=0;(i<4)&&(*src);i++) { + *dst=((*src>='a')&&(*src<='z'))?*src&0xDF:*src; + src++; + dst++; + } + *dst=0; +} + /****************************************************************\ | Tag Tree Searching Functions | \****************************************************************/ #define ptoi(p) ((p!=NULL)?atoi(p):0) -#define keepStringAttribute(attribute) r[id]->attribute=strallocandcopy(t->attribute) -#define keepIntAttribute(attribute,type) r[id]->attribute=(type)ptoi(t->attribute); - +#define keepStringAttribute(attribute) res.attribute=strallocandcopy(t->attribute) +#define keepIntAttribute(attribute,type) res.attribute=(type)ptoi(t->attribute); +#define keepIdAttributes(attribute,idnum,idindex) res.attribute.value=(unsigned short int)ptoi(t->idnum);\ + if (t->idindex) str5uppercpy(res.attribute.index,t->idindex);\ + else res.attribute.index[0]=0 + +#define keepIdAttributesElse(attribute,idnum,idindex,idelse) res.attribute.value=(unsigned short int)ptoi(t->idnum);\ + if (t->idindex) str5uppercpy(res.attribute.index,t->idindex);\ + else str5uppercpy(res.attribute.index,t->idelse) void workTag(const tTag* t,void* pass) { /* If the tag matches, it is converted to resource and added to the array */ /* Declare variables */ - unsigned short id; const char* datFile=((tPassWork*)pass)->datFile; - tResource** r=((tPassWork*)pass)->r; + tResourceList* r=((tPassWork*)pass)->r; + tResource res; /* Skipping conditions */ if (!equalsIgnoreCase(t->file,datFile)) return; /* If it doesn't belong to the given dat file */ - if (!(id=(unsigned short)ptoi(t->value))) return; /* If there was not id or id contained wrong values */ + if (!t->value) return; /* If there was not number id */ + if (!t->index) return; /* If there was not index id */ if (!equalsIgnoreCase(t->tag,"item")) return; /* If the tag isn't an item */ - /* Process tag and copy values to resource */ - /* Create Resource */ - if (r[id]!=NULL) return; - r[id]=(tResource*)malloc(sizeof(tResource)); - if (r[id]==NULL) return; + /* Process tag and copy values to resource: */ /* Get string itemtype and convert into the itemtypeId */ - r[id]->type=0; + res.type=0; #ifndef IGNORERESOURCEFUNCTIONS - if (t->itemtype!=NULL) { /* NULL tells the extractor that the type must be auto detected */ + if (t->itemtype!=NULL) { /* NULL tells the extractor that the type should be auto detected */ int i=RES_TYPECOUNT; - while((!r[id]->type)&&(i--)) + while((!res.type)&&(i--)) if (equalsIgnoreCase(t->itemtype,getExtDesc(i))) - r[id]->type=i; + res.type=i; /* If error it returns 0 and the verifyHeader will try to detect the type */ } #endif - /* Copy palette, number, title, desc and path */ - keepIntAttribute(palette,unsigned short); /* Transforms the char* palette into a short ID value, if 0 or error no palette is needed */ + /* Copy id and palette id */ + keepIdAttributes(id,value,index); + keepIdAttributesElse(palette,palette,paletteindex,index); + + /* Copy number, title, desc and path */ keepIntAttribute(number,unsigned char); /* Transforms the char* levelnumer/number attribute into a char value, if error, demo level is used */ - keepStringAttribute(name); /* only for plv */ keepStringAttribute(desc); /* only for plv */ + keepStringAttribute(name); /* only for plv */ keepStringAttribute(path); + + resourceListAdd(r,&res); } void workTree(const tTag* t,void* pass, void (*function)(const tTag*,void*)) { diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c index 3cc79fd..3d59fc4 100644 --- a/PR/src/lib/xml/tree.c +++ b/PR/src/lib/xml/tree.c @@ -239,27 +239,24 @@ int checkSum(const unsigned char* data,int size) { | Parsing resource file | \***************************************************************/ -/* Initializes the resource table */ -void emptyTable(tResource* r[]) { - int i=MAX_RES_COUNT; - while (i--) *(r++)=NULL; -} - /* parse file */ -int parseFile(const char* vFile, const char* datFile, tResource* r[]) { +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 */ +printf("DEBUG: a punto de leer la estructura xml\n"); if ((error=parseStructure(vFile,&structure))) return error; +printf("DEBUG: termine de leer la estructura xml\n"); /* Use the xml structure to Generate the resource structure of the file */ - emptyTable(r); + /*emptyTable(r);*/ pass.datFile=datFile; pass.r=r; workTree(structure,&pass,workTag); +printf("DEBUG: termine de crear la resList a aprtir del datfile\n"); /* All done */ return 0; @@ -272,7 +269,8 @@ int parseFile(const char* vFile, const char* datFile, tResource* r[]) { /* Resources output to xml functions. Private+abstract variable */ static FILE* unknownXmlFile=NULL; -void AddToUnknownXml(const char* vFiledatWithPath,unsigned short id,const char* ext,char type,const char* vDirExt,unsigned short pal,const char* vFiledat,int optionflag,int count,const char* indexName) { +void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,char type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count) { + /* TODO: use lowercase for .index values */ /* Open file if not open */ if (unknownXmlFile==NULL) { char xmlFile[MAX_FILENAME_SIZE]; @@ -284,13 +282,13 @@ void AddToUnknownXml(const char* vFiledatWithPath,unsigned short id,const char* /* Save headers */ if (type==6) pal=id; fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, - vFiledat,vFiledatWithPath,pal + vFiledat,vFiledatWithPath,pal.value,pal.index ); } /* Write item */ fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, - id,indexName,getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count + id.value,id.index,getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count ); /* To the xml output */ } @@ -310,7 +308,7 @@ void endUnknownXml(int optionflag, const char* backupExtension) { | Resources extra functions | \***************************************************************/ -void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short id,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension,const char* indexName) { +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; @@ -320,7 +318,7 @@ void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short /* set filename */ sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vDatFileName,getExtDesc(pos),typeCount[pos],extarray[pos]); - AddToUnknownXml(vDatFileName,id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos],indexName); + 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/unknown.c b/PR/src/lib/xml/unknown.c index 3cc79fd..3d59fc4 100644 --- a/PR/src/lib/xml/unknown.c +++ b/PR/src/lib/xml/unknown.c @@ -239,27 +239,24 @@ int checkSum(const unsigned char* data,int size) { | Parsing resource file | \***************************************************************/ -/* Initializes the resource table */ -void emptyTable(tResource* r[]) { - int i=MAX_RES_COUNT; - while (i--) *(r++)=NULL; -} - /* parse file */ -int parseFile(const char* vFile, const char* datFile, tResource* r[]) { +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 */ +printf("DEBUG: a punto de leer la estructura xml\n"); if ((error=parseStructure(vFile,&structure))) return error; +printf("DEBUG: termine de leer la estructura xml\n"); /* Use the xml structure to Generate the resource structure of the file */ - emptyTable(r); + /*emptyTable(r);*/ pass.datFile=datFile; pass.r=r; workTree(structure,&pass,workTag); +printf("DEBUG: termine de crear la resList a aprtir del datfile\n"); /* All done */ return 0; @@ -272,7 +269,8 @@ int parseFile(const char* vFile, const char* datFile, tResource* r[]) { /* Resources output to xml functions. Private+abstract variable */ static FILE* unknownXmlFile=NULL; -void AddToUnknownXml(const char* vFiledatWithPath,unsigned short id,const char* ext,char type,const char* vDirExt,unsigned short pal,const char* vFiledat,int optionflag,int count,const char* indexName) { +void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,char type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count) { + /* TODO: use lowercase for .index values */ /* Open file if not open */ if (unknownXmlFile==NULL) { char xmlFile[MAX_FILENAME_SIZE]; @@ -284,13 +282,13 @@ void AddToUnknownXml(const char* vFiledatWithPath,unsigned short id,const char* /* Save headers */ if (type==6) pal=id; fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, - vFiledat,vFiledatWithPath,pal + vFiledat,vFiledatWithPath,pal.value,pal.index ); } /* Write item */ fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, - id,indexName,getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count + id.value,id.index,getExtDesc(type),count,ext,getExtDesc(type),getExtDesc(type),count ); /* To the xml output */ } @@ -310,7 +308,7 @@ void endUnknownXml(int optionflag, const char* backupExtension) { | Resources extra functions | \***************************************************************/ -void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short id,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension,const char* indexName) { +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; @@ -320,7 +318,7 @@ void getFileName(char* vFileext,const char* vDirExt,tResource* r,unsigned short /* set filename */ sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vDatFileName,getExtDesc(pos),typeCount[pos],extarray[pos]); - AddToUnknownXml(vDatFileName,id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos],indexName); + 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/xml/resources.xml b/PR/src/xml/resources.xml index d7e046e..dc0e6ac 100644 --- a/PR/src/xml/resources.xml +++ b/PR/src/xml/resources.xml @@ -1405,7 +1405,7 @@ resources.xml: Princed Resources : Resource tree <item value="2015" number="15" path="potions.plv">Potions level</item> </folder> - <folder index="pahs" name="the pop2 bird guard" file="bird.dat" itemtype="image" path="bird" palette="750"> + <folder index="pahs" name="the pop2 bird guard" file="bird.dat" itemtype="image" path="bird" palette="750" paletteindex="clap"> <item value="750" index="mark" path="binary01.bin" itemtype="binary">Unknown binary 1</item> <item value="750" index="clap" path="binary02.bin" itemtype="binary">Unknown binary 2</item> <item value="750" index="slap" path="bird.pal" itemtype="palette">The bird palette</item>