author | ecalot
<ecalot> 2005-12-17 18:11:50 UTC |
committer | ecalot
<ecalot> 2005-12-17 18:11:50 UTC |
parent | 0aeba79b3298f1b976e2ec340daae0d7f6858737 |
PR/src/Makefile | +1 | -1 |
PR/src/include/stringformat.h | +65 | -0 |
PR/src/include/tree.h | +2 | -2 |
PR/src/include/unknown.h | +2 | -2 |
PR/src/lib/xml/tree.c | +11 | -6 |
PR/src/lib/xml/unknown.c | +11 | -6 |
diff --git a/PR/src/Makefile b/PR/src/Makefile index 064e1a2..d0bfc1f 100644 --- a/PR/src/Makefile +++ b/PR/src/Makefile @@ -54,7 +54,7 @@ endif ACTIONS = .import.o .export.o .classify.o XML = .parse.o .search.o .resources.o .translate.o COMPRESS = .compress.o .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o -LAYERS = .dat.o .memory.o .list.o .reslist.o .disk.o .idlist.o .autodetect.o +LAYERS = .dat.o .memory.o .list.o .reslist.o .disk.o .idlist.o .autodetect.o .stringformat.o FORMAT = .bmp.o .mid.o .pal.o .wav.o .plv.o CONSOLE = .main.o .filedir.o MAIN = .pr.o diff --git a/PR/src/include/stringformat.h b/PR/src/include/stringformat.h new file mode 100644 index 0000000..5b6323b --- /dev/null +++ b/PR/src/include/stringformat.h @@ -0,0 +1,65 @@ +/* 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 +*/ + +/* +stringformat.c: Princed Resources : format string parsing header +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf + Copyright 2005 Princed Development Team + Created: 17 Dec 2005 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.00 (2005-Dec-17) + + Note: + DO NOT remove this copyright notice +*/ + +#ifndef _STRINGFORMAT_H_ +#define _STRINGFORMAT_H_ + +const char* parseformat(const char* format,long value,const char* index, const char* type, const char* extension, long numberOfThisType, int order, const char* desc); + /* This function parses format in this way: + * %v - the value + * %i - the 4-chars index name + * %I - the human-like index name + * %t - the item type (image, wave, etc) + * %e - the extension (bmp, wav, etc) + * %n - the number of the item typed in %t + * %o - the order number (in case the index and values are the same) + * %d - the description + * %% - a % sign + * + * TODO: add name + * + * Modifiers: (TODO: truncate flag) + * %5i - the index truncated to 5 bytes or the index size, whatever comes first + * %05i - the same, but in case the index is sized less than 5 it's filled with spaces + * %5v - the value tabulated to 5 digits (filled with spaces), in case the number is bigger, more digits will be used + * %05v - the same, but in case the value is sized less than 5 it's filled with zeros + * + * Examples: + * "%i%05v.%e" for shap25001.bmp + * "%t%02n.%e" for image01.bmp + * + * Limitations: + * The generated string size has a limit, in case it is reached, a NULL pointer will be returned + */ + +#endif diff --git a/PR/src/include/tree.h b/PR/src/include/tree.h index a897cea..95059c8 100644 --- a/PR/src/include/tree.h +++ b/PR/src/include/tree.h @@ -37,9 +37,9 @@ resources.h: Princed Resources : Resource Handler headers /* XML generation defines */ #define RES_XML_UNKNOWN_PATH "%s/unknown/%s/" -#define RES_XML_UNKNOWN_FILES "%s%03d.%s" +#define RES_XML_UNKNOWN_FILES "%t%03n.%e" #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"\" type=\"%s\" flags=\"0x%lx\">Unknown %s %d</item>\n" +#define RES_XML_UNKNOWN_ITEM " <item value=\"%d\" index=\"%s\" path=\"%s\" type=\"%s\" flags=\"0x%lx\">Unknown %s %d</item>\n" #define RES_XML_UNKNOWN_END " </folder>\n</resources>\n" /* File extensions */ diff --git a/PR/src/include/unknown.h b/PR/src/include/unknown.h index a897cea..95059c8 100644 --- a/PR/src/include/unknown.h +++ b/PR/src/include/unknown.h @@ -37,9 +37,9 @@ resources.h: Princed Resources : Resource Handler headers /* XML generation defines */ #define RES_XML_UNKNOWN_PATH "%s/unknown/%s/" -#define RES_XML_UNKNOWN_FILES "%s%03d.%s" +#define RES_XML_UNKNOWN_FILES "%t%03n.%e" #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"\" type=\"%s\" flags=\"0x%lx\">Unknown %s %d</item>\n" +#define RES_XML_UNKNOWN_ITEM " <item value=\"%d\" index=\"%s\" path=\"%s\" type=\"%s\" flags=\"0x%lx\">Unknown %s %d</item>\n" #define RES_XML_UNKNOWN_END " </folder>\n</resources>\n" /* File extensions */ diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c index 1f8ffa2..3099bd5 100644 --- a/PR/src/lib/xml/tree.c +++ b/PR/src/lib/xml/tree.c @@ -41,6 +41,7 @@ resources.c: Princed Resources : Resource Handler #include "disk.h" #include "resources.h" #include "search.h" +#include "stringformat.h" #include "translate.h" /***************************************************************\ @@ -85,7 +86,7 @@ char* toLower(const char* txt) { return ret; } -void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,tResourceType type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count, unsigned long int flags,const char* format) { +void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,tResourceType type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count, unsigned long int flags,const char* filename) { /* Open file if not open */ if (unknownXmlFile==NULL) { char xmlFile[MAX_FILENAME_SIZE]; @@ -96,14 +97,14 @@ void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext /* Save headers */ if (type==eResTypePalette) pal=id; - fprintf(unknownXmlFile,RES_XML_UNKNOWN_START"%s", - vFiledat,vFiledatWithPath,pal.value,translateInt2Ext(toLower(pal.index)),format + fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, + vFiledat,vFiledatWithPath,pal.value,translateInt2Ext(toLower(pal.index)) ); } /* Write item */ fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, - id.value,translateInt2Ext(toLower(id.index)),getExtDesc(type),count,ext,getExtDesc(type),flags,getExtDesc(type),count + id.value,translateInt2Ext(toLower(id.index)),filename,getExtDesc(type),flags,getExtDesc(type),count ); /* To the xml output */ } @@ -121,6 +122,7 @@ void endUnknownXml(int optionflag, const char* backupExtension) { void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension,const char* format) { static const char* extarray[]=RES_FILE_EXTENSIONS; + const char* filename; int pos; if (r->path==NULL) { @@ -128,8 +130,11 @@ void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const cha typeCount[pos]++; /* set filename */ - sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vDatFileName,getExtDesc(pos),typeCount[pos],extarray[pos]); - AddToUnknownXml(vDatFileName,r->id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos],r->flags,format); + if (!format) format=RES_XML_UNKNOWN_FILES; + filename=parseformat(format,r->id.value,r->id.index,getExtDesc(pos),extarray[pos],typeCount[pos],r->id.order,r->desc); + + sprintf(vFileext,RES_XML_UNKNOWN_PATH"%s",vDirExt,vDatFileName,filename); + AddToUnknownXml(vDatFileName,r->id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos],r->flags,filename); } 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 1f8ffa2..3099bd5 100644 --- a/PR/src/lib/xml/unknown.c +++ b/PR/src/lib/xml/unknown.c @@ -41,6 +41,7 @@ resources.c: Princed Resources : Resource Handler #include "disk.h" #include "resources.h" #include "search.h" +#include "stringformat.h" #include "translate.h" /***************************************************************\ @@ -85,7 +86,7 @@ char* toLower(const char* txt) { return ret; } -void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,tResourceType type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count, unsigned long int flags,const char* format) { +void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext,tResourceType type,const char* vDirExt,tResourceId pal,const char* vFiledat,int optionflag,int count, unsigned long int flags,const char* filename) { /* Open file if not open */ if (unknownXmlFile==NULL) { char xmlFile[MAX_FILENAME_SIZE]; @@ -96,14 +97,14 @@ void AddToUnknownXml(const char* vFiledatWithPath,tResourceId id,const char* ext /* Save headers */ if (type==eResTypePalette) pal=id; - fprintf(unknownXmlFile,RES_XML_UNKNOWN_START"%s", - vFiledat,vFiledatWithPath,pal.value,translateInt2Ext(toLower(pal.index)),format + fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, + vFiledat,vFiledatWithPath,pal.value,translateInt2Ext(toLower(pal.index)) ); } /* Write item */ fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, - id.value,translateInt2Ext(toLower(id.index)),getExtDesc(type),count,ext,getExtDesc(type),flags,getExtDesc(type),count + id.value,translateInt2Ext(toLower(id.index)),filename,getExtDesc(type),flags,getExtDesc(type),count ); /* To the xml output */ } @@ -121,6 +122,7 @@ void endUnknownXml(int optionflag, const char* backupExtension) { void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const char* vFiledat, const char* vDatFileName,int optionflag, const char* backupExtension,const char* format) { static const char* extarray[]=RES_FILE_EXTENSIONS; + const char* filename; int pos; if (r->path==NULL) { @@ -128,8 +130,11 @@ void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const cha typeCount[pos]++; /* set filename */ - sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vDatFileName,getExtDesc(pos),typeCount[pos],extarray[pos]); - AddToUnknownXml(vDatFileName,r->id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos],r->flags,format); + if (!format) format=RES_XML_UNKNOWN_FILES; + filename=parseformat(format,r->id.value,r->id.index,getExtDesc(pos),extarray[pos],typeCount[pos],r->id.order,r->desc); + + sprintf(vFileext,RES_XML_UNKNOWN_PATH"%s",vDirExt,vDatFileName,filename); + AddToUnknownXml(vDatFileName,r->id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,typeCount[pos],r->flags,filename); } else { /* set filename */ sprintf(vFileext,"%s/%s",vDirExt,r->path);