author | ecalot
<ecalot> 2006-06-21 16:22:33 UTC |
committer | ecalot
<ecalot> 2006-06-21 16:22:33 UTC |
parent | 1967ab155cb51ccce9091bd86292904ad4ffcdbe |
PR/src/Makefile | +2 | -2 |
PR/src/include/disk.h | +2 | -0 |
PR/src/include/plv.h | +3 | -3 |
PR/src/lib/formats/plv.c | +17 | -21 |
PR/src/lib/object/level/level_common.c | +4 | -3 |
PR/src/lib/xml/tree.c | +3 | -2 |
PR/src/lib/xml/unknown.c | +1 | -0 |
diff --git a/PR/src/Makefile b/PR/src/Makefile index 6110db0..1ad1158 100644 --- a/PR/src/Makefile +++ b/PR/src/Makefile @@ -155,11 +155,11 @@ $(XMLFILE): xml/resources.xml $(INFO) Compiling resource list module... $(CC) $(OPTIONS) -c lib/layers/reslist.c -o $@ -.level.o: lib/object/level/level.c +.level.o: lib/object/level/level.c include/binary.h include/common.h include/dat.h include/disk.h include/plv.h include/types.h $(INFO) Compiling level class module... $(CC) $(OPTIONS) -c lib/object/level/level.c -o $@ -.sounds.o: lib/object/sound/sounds.c +.sounds.o: lib/object/sound/sounds.c include/binary.h include/common.h include/wav.h include/dat.h include/types.h $(INFO) Compiling sound list module... $(CC) $(OPTIONS) -c lib/object/sound/sounds.c -o $@ diff --git a/PR/src/include/disk.h b/PR/src/include/disk.h index e9773e9..45b1114 100644 --- a/PR/src/include/disk.h +++ b/PR/src/include/disk.h @@ -100,5 +100,7 @@ int macfwritel(const void* var,FILE* file); #define freadchar(var,file) fread ((var),1,1,file) #endif +#define fwritebinary(c,fd) fwrite((c).data,(c).size,1,fd) + #endif diff --git a/PR/src/include/plv.h b/PR/src/include/plv.h index d5a650f..850dd53 100644 --- a/PR/src/include/plv.h +++ b/PR/src/include/plv.h @@ -73,10 +73,10 @@ int writePlv(const char* file, tBinary content, int popversion, const char* datf #define DATE_MONTHS "Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0Sep\0Oct\0Nov\0Dec" /* Format stuff */ -#define PLV_HEADER_A "POP_LVL" -#define PLV_HEADER_A_SIZE 7 +#define PLV_HEADER_MAGIC "POP_LVL" +#define PLV_HEADER_MAGIC_SIZE 7 -#define PLV_HEADER_B_SIZE 4 +#define PLV_HEADER_B_SIZE 4 /* TODO: rename this macro */ #define PLV_FOOT_EDITOR "Editor Name\0PR\0Editor Version\0"PR_VERSION"\0Level Author" #define PLV_FOOT_TITLE "Level Title" diff --git a/PR/src/lib/formats/plv.c b/PR/src/lib/formats/plv.c index 597c11c..3d0e066 100644 --- a/PR/src/lib/formats/plv.c +++ b/PR/src/lib/formats/plv.c @@ -89,28 +89,25 @@ char* getDate() { } int writePlv(const char* file, tBinary content, int popversion, const char* datfile, int level, const char* filename, const char* desc, const char* title, const char* vDatAuthor, int optionflag,const char* backupExtension) { - /* Plv files are saved as raw except you must ignore the checksum and add the plv constant file header */ + /* PLV files are saved as raw except you must add the checksum and the plv constant file header and footer */ /* Variables */ - FILE* target; - int ok; - unsigned char sizeOfNow; - char* now; - unsigned char checksum; char levelnum[10]; + char* now; const char* nullString=""; - static const char* author=PLV_DEFAULT_AUTHOR; - unsigned long int block2size; const unsigned long int numberOfFieldPairs=9; + FILE* target; + int ok; + static const char* author=PLV_DEFAULT_AUTHOR; + unsigned char checksum; + unsigned char sizeOfNow; unsigned char version=popversion; + unsigned long int block2size; /* Get current time */ now=getDate(); sizeOfNow=(unsigned char)(strlen(now)+1); - /* Ignore checksum */ - /* size--; */ - /* Validate null strings when no description is set */ if (desc==NULL) desc=nullString; if (title==NULL) title=nullString; @@ -123,19 +120,18 @@ int writePlv(const char* file, tBinary content, int popversion, const char* datf ok=writeOpen(file,&target,optionflag); /* Write headers */ - ok=ok&&fwrite(PLV_HEADER_A,PLV_HEADER_A_SIZE,1,target); - /*if (size==12025) version=2; else version=1; * TODO: check if the checksum is included */ - ok=ok&&fwritechar(&version,target); + ok=ok&&fwrite(PLV_HEADER_MAGIC,PLV_HEADER_MAGIC_SIZE,1,target); + ok=ok&&fwritechar(&version,target); /* POP version */ version=1; - ok=ok&&fwritechar(&version,target); + ok=ok&&fwritechar(&version,target); /* PLV version */ ok=ok&&fwritechar(&level,target); ok=ok&&fwritelong(&numberOfFieldPairs,target); ok=ok&&fwritelong(&content.size,target); - /* Write block 1: raw data without ignoring checksum */ + /* Write block 1: checksum and raw data */ checksum=getChecksum(content); ok=ok&&fwritechar(&checksum,target); - ok=ok&&fwrite(content.data,content.size,1,target); + ok=ok&&fwritebinary(content,target); /* Write footers */ block2size=( @@ -180,17 +176,17 @@ int readPlv(tResource *res) { unsigned long int oldSize=res->content.size; /* integrity check 1 */ - if (oldSize<=PLV_HEADER_A_SIZE+1+PLV_HEADER_B_SIZE) return 0; /* false */ - if (memcmp(res->content.data,PLV_HEADER_A,PLV_HEADER_A_SIZE)) return 0; /* false */ + if (oldSize<=PLV_HEADER_MAGIC_SIZE+1+PLV_HEADER_B_SIZE) return 0; /* false */ + if (memcmp(res->content.data,PLV_HEADER_MAGIC,PLV_HEADER_MAGIC_SIZE)) return 0; /* false */ /* jump to size */ - pos=res->content.data+PLV_HEADER_A_SIZE+7; /* TODO: check this */ + pos=res->content.data+PLV_HEADER_MAGIC_SIZE+7; /* TODO: check this */ /* read size and jump to data */ res->content.size=array2long(pos);pos+=4; /* integrity check 2 */ - if (oldSize<=PLV_HEADER_A_SIZE+1+PLV_HEADER_B_SIZE+res->content.size) return 0; /* false */ + if (oldSize<=PLV_HEADER_MAGIC_SIZE+1+PLV_HEADER_B_SIZE+res->content.size) return 0; /* false */ /* validate checksum */ if (!checkSum(pos,res->content.size)) diff --git a/PR/src/lib/object/level/level_common.c b/PR/src/lib/object/level/level_common.c index 9c9b4f8..6926405 100644 --- a/PR/src/lib/object/level/level_common.c +++ b/PR/src/lib/object/level/level_common.c @@ -37,10 +37,11 @@ #include "binary.h" /* tBinary */ #include "common.h" -#include "dat.h" /* WriteDat */ -#include "types.h" /* tResources */ +#include "dat.h" /* WriteDat */ +#include "disk.h" /* getFileNameFromPath */ #include "plv.h" #include <stdlib.h> +#include "types.h" /* tResources */ /***************************************************************\ | Level Object | @@ -72,7 +73,7 @@ void* objectLevelCreate(tBinary content,int number,const char* datfile,const cha int objectLevelWrite(void* o, const char* file, int optionflag, const char* backupExtension,int version) { tPop1Level* b=o; - return writePlv(file,b->content,version,b->datfile,b->number,file,b->desc,b->name,b->datAuthor,optionflag,backupExtension); + return writePlv(file,b->content,version,b->datfile,b->number,getFileNameFromPath(file),b->desc,b->name,b->datAuthor,optionflag,backupExtension); } /* diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c index c17f335..7fd3b73 100644 --- a/PR/src/lib/xml/tree.c +++ b/PR/src/lib/xml/tree.c @@ -38,11 +38,12 @@ tree.c: Princed Resources : Specific XML tree handling routines /* Includes */ #include "common.h" -#include "list.h" /* list primitives needed by the Common Factor routines */ +#include "list.h" /* list primitives needed by the Common Factor routines */ #include "memory.h" -#include "parse.h" /* getTagStructure */ +#include "parse.h" /* getTagStructure */ #include "unknown.h" /* typedef tUnknownFile */ #include <stdio.h> +#include <string.h> /***************************************************************\ | XML generation defines | diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c index d5a5688..7a59c43 100644 --- a/PR/src/lib/xml/unknown.c +++ b/PR/src/lib/xml/unknown.c @@ -46,6 +46,7 @@ unknown.c: Princed Resources : Unknown resources handler implementation #include "tree.h" #include "unknown.h" #include <stdio.h> +#include <string.h> /***************************************************************\ | Unknown.xml primitives |