git » fp-git.git » commit 1f5474d

Finished last small TODOs

author ecalot
2004-07-06 09:55:15 UTC
committer ecalot
2004-07-06 09:55:15 UTC
parent 8e1e89cded962adee282c229c8dfded2c7ed14f9

Finished last small TODOs

PR/src/console/main.c +1 -12
PR/src/lib/actions/export.c +0 -2
PR/src/lib/actions/import.c +10 -2
PR/src/lib/formats/plv.c +3 -5
PR/src/lib/layers/autodetect.c +11 -1
PR/src/lib/layers/dat.c +1 -1
PR/src/lib/layers/idlist.c +11 -1
PR/src/lib/pr.c +1 -12
PR/src/lib/xml/tree.c +11 -1
PR/src/lib/xml/unknown.c +11 -1

diff --git a/PR/src/console/main.c b/PR/src/console/main.c
index 7180321..9a0b3ce 100644
--- a/PR/src/console/main.c
+++ b/PR/src/console/main.c
@@ -459,16 +459,7 @@ int main (int argc, char **argv) {
 		}
 	} while (c!=-1);
 
-	if (optind < argc) {
-		int size;
-		datFilePath=strallocandcopy(argv[optind]);
-		/* Erase the last "/" if exists. TODO: send to parseGivenPath  */
-		size=strlen(datFilePath);
-		if (size>0) {
-			size--;
-			if (isDirSep(datFilePath,size)) datFilePath[size]=0;
-		}
-	}
+	if (optind < argc) datFilePath=strallocandcopy(argv[optind]);
 
 	/* At least one of these options must be selected, if not, the user needs help! */
 	if (!(hasFlag(import_flag|export_flag|classify_flag))) setFlag(help_flag);
@@ -502,5 +493,3 @@ int main (int argc, char **argv) {
 void start() {}
 #endif
 
-
-
diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index 9729f7d..e8c1e09 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -87,8 +87,6 @@ int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int option
 
 	/* Initializes the palette list */
 	initializePaletteList;
-	
-
 
 	/* main loop */
 	for (indexNumber=0;ok&&(indexNumber<numberOfItems);indexNumber++) {
diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c
index 67d8f6d..c289892 100644
--- a/PR/src/lib/actions/import.c
+++ b/PR/src/lib/actions/import.c
@@ -164,9 +164,17 @@ int partialCompile(const char* vFiledat, const char* vDirExt, tResource* r[], in
 	/* main loop */
 	for (indexNumber=0;(indexNumber<numberOfItems);indexNumber++) {
 		id=mReadFileInDatFile(indexNumber,&data,&size);
-		if (id<0) RW_ERROR; /* Read error */ /* TODO BUG: return doesn't close file */
+		
+		/* Validations */
+		if (id<0) {
+			mRWCloseDatFile(0);
+			RW_ERROR; /* Read error */
+		}
 		if (id==0xFFFF) continue; /* Tammo Jan Bug fix */
-		if (id>=MAX_RES_COUNT) RW_ERROR; /* A file with an ID out of range will be treated as invalid */
+		if (id>=MAX_RES_COUNT) { 
+			mRWCloseDatFile(0);
+			RW_ERROR; /* A file with an ID out of range will be treated as invalid */
+		}
 
 		mWriteInitResource(r+id);
 		if (r[id]&&isInThePartialList(r[id]->path,id)) { /* If the resource was specified */
diff --git a/PR/src/lib/formats/plv.c b/PR/src/lib/formats/plv.c
index 1d1db38..45b7753 100644
--- a/PR/src/lib/formats/plv.c
+++ b/PR/src/lib/formats/plv.c
@@ -167,20 +167,18 @@ int mFormatImportPlv(unsigned char* data, tResource *res) {
 
 	/* 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(data,PLV_HEADER_A,PLV_HEADER_A_SIZE)) return 0;
 
 	/* jump to size */
 	pos=data+PLV_HEADER_A_SIZE+1+PLV_HEADER_B_SIZE;
+
 	/* read size and jump to data */
 	res->size=array2long(pos);pos+=4;
 
 	/* integrity check 2 */
 	if (oldSize<=PLV_HEADER_A_SIZE+1+PLV_HEADER_B_SIZE+res->size) return 0;
 
-	/* verify checksum */
-
-/* TODO: uncomment this line and validate checksums in plvs */
+	/* validate checksum */
 	if (!checkSum(pos,res->size)) return 0;
 
 	/* save data */
diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c
index 35f6cf5..a7583be 100644
--- a/PR/src/lib/layers/autodetect.c
+++ b/PR/src/lib/layers/autodetect.c
@@ -129,6 +129,7 @@ void parseGivenPath(char* path) {
 	int resourceValue;
 	int j=0;
 	unsigned char n;
+	int size;
 
 	/* Check if the variable wasn't initialized before */
 	if (partialList.count!=0) return;
@@ -137,6 +138,15 @@ void parseGivenPath(char* path) {
 	/* Validates the NULL path */
 	if (path==NULL) return;
 
+	/* Erase the last "/" if exists. */
+	if (path) {
+		size=strlen(path);
+		if (size>0) {
+			size--;
+			if (isDirSep(path,size)) path[size]=0;
+		}
+	}
+	
 	/* Locate the string separation */
 	while (path[separator]&&path[separator]!='@') separator++;
 
@@ -311,7 +321,7 @@ static unsigned int typeCount[RES_TYPECOUNT]; /* initialized in 0 */
 void endUnknownXml(int optionflag, const char* backupExtension) {
 	if (unknownXmlFile!=NULL) {
 		int i;
-		fprintf(unknownXmlFile,RES_XML_UNKNOWN_END); /* TODO: use fwrite instead */
+		fwrite(RES_XML_UNKNOWN_END,1,sizeof(RES_XML_UNKNOWN_END)-1,unknownXmlFile);
 		writeCloseOk(unknownXmlFile,optionflag,backupExtension);
 		unknownXmlFile=NULL;
 		for (i=0;i<RES_TYPECOUNT;i++) typeCount[i]=0;
diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c
index 7d48e22..6640cf3 100644
--- a/PR/src/lib/layers/dat.c
+++ b/PR/src/lib/layers/dat.c
@@ -127,7 +127,7 @@ int mReadInitResource(tResource** res,const unsigned char* data,long size) {
 		(*res)->palette=0;
 		(*res)->number=0;
 		(*res)->size=(unsigned short int)size;
-		(*res)->offset=(unsigned short)offset; /* TODO delete this line */
+		/* (*res)->offset=(unsigned short)offset; TODO delete this line */
 		(*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);
diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c
index 35f6cf5..a7583be 100644
--- a/PR/src/lib/layers/idlist.c
+++ b/PR/src/lib/layers/idlist.c
@@ -129,6 +129,7 @@ void parseGivenPath(char* path) {
 	int resourceValue;
 	int j=0;
 	unsigned char n;
+	int size;
 
 	/* Check if the variable wasn't initialized before */
 	if (partialList.count!=0) return;
@@ -137,6 +138,15 @@ void parseGivenPath(char* path) {
 	/* Validates the NULL path */
 	if (path==NULL) return;
 
+	/* Erase the last "/" if exists. */
+	if (path) {
+		size=strlen(path);
+		if (size>0) {
+			size--;
+			if (isDirSep(path,size)) path[size]=0;
+		}
+	}
+	
 	/* Locate the string separation */
 	while (path[separator]&&path[separator]!='@') separator++;
 
@@ -311,7 +321,7 @@ static unsigned int typeCount[RES_TYPECOUNT]; /* initialized in 0 */
 void endUnknownXml(int optionflag, const char* backupExtension) {
 	if (unknownXmlFile!=NULL) {
 		int i;
-		fprintf(unknownXmlFile,RES_XML_UNKNOWN_END); /* TODO: use fwrite instead */
+		fwrite(RES_XML_UNKNOWN_END,1,sizeof(RES_XML_UNKNOWN_END)-1,unknownXmlFile);
 		writeCloseOk(unknownXmlFile,optionflag,backupExtension);
 		unknownXmlFile=NULL;
 		for (i=0;i<RES_TYPECOUNT;i++) typeCount[i]=0;
diff --git a/PR/src/lib/pr.c b/PR/src/lib/pr.c
index 7180321..9a0b3ce 100644
--- a/PR/src/lib/pr.c
+++ b/PR/src/lib/pr.c
@@ -459,16 +459,7 @@ int main (int argc, char **argv) {
 		}
 	} while (c!=-1);
 
-	if (optind < argc) {
-		int size;
-		datFilePath=strallocandcopy(argv[optind]);
-		/* Erase the last "/" if exists. TODO: send to parseGivenPath  */
-		size=strlen(datFilePath);
-		if (size>0) {
-			size--;
-			if (isDirSep(datFilePath,size)) datFilePath[size]=0;
-		}
-	}
+	if (optind < argc) datFilePath=strallocandcopy(argv[optind]);
 
 	/* At least one of these options must be selected, if not, the user needs help! */
 	if (!(hasFlag(import_flag|export_flag|classify_flag))) setFlag(help_flag);
@@ -502,5 +493,3 @@ int main (int argc, char **argv) {
 void start() {}
 #endif
 
-
-
diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c
index 35f6cf5..a7583be 100644
--- a/PR/src/lib/xml/tree.c
+++ b/PR/src/lib/xml/tree.c
@@ -129,6 +129,7 @@ void parseGivenPath(char* path) {
 	int resourceValue;
 	int j=0;
 	unsigned char n;
+	int size;
 
 	/* Check if the variable wasn't initialized before */
 	if (partialList.count!=0) return;
@@ -137,6 +138,15 @@ void parseGivenPath(char* path) {
 	/* Validates the NULL path */
 	if (path==NULL) return;
 
+	/* Erase the last "/" if exists. */
+	if (path) {
+		size=strlen(path);
+		if (size>0) {
+			size--;
+			if (isDirSep(path,size)) path[size]=0;
+		}
+	}
+	
 	/* Locate the string separation */
 	while (path[separator]&&path[separator]!='@') separator++;
 
@@ -311,7 +321,7 @@ static unsigned int typeCount[RES_TYPECOUNT]; /* initialized in 0 */
 void endUnknownXml(int optionflag, const char* backupExtension) {
 	if (unknownXmlFile!=NULL) {
 		int i;
-		fprintf(unknownXmlFile,RES_XML_UNKNOWN_END); /* TODO: use fwrite instead */
+		fwrite(RES_XML_UNKNOWN_END,1,sizeof(RES_XML_UNKNOWN_END)-1,unknownXmlFile);
 		writeCloseOk(unknownXmlFile,optionflag,backupExtension);
 		unknownXmlFile=NULL;
 		for (i=0;i<RES_TYPECOUNT;i++) typeCount[i]=0;
diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c
index 35f6cf5..a7583be 100644
--- a/PR/src/lib/xml/unknown.c
+++ b/PR/src/lib/xml/unknown.c
@@ -129,6 +129,7 @@ void parseGivenPath(char* path) {
 	int resourceValue;
 	int j=0;
 	unsigned char n;
+	int size;
 
 	/* Check if the variable wasn't initialized before */
 	if (partialList.count!=0) return;
@@ -137,6 +138,15 @@ void parseGivenPath(char* path) {
 	/* Validates the NULL path */
 	if (path==NULL) return;
 
+	/* Erase the last "/" if exists. */
+	if (path) {
+		size=strlen(path);
+		if (size>0) {
+			size--;
+			if (isDirSep(path,size)) path[size]=0;
+		}
+	}
+	
 	/* Locate the string separation */
 	while (path[separator]&&path[separator]!='@') separator++;
 
@@ -311,7 +321,7 @@ static unsigned int typeCount[RES_TYPECOUNT]; /* initialized in 0 */
 void endUnknownXml(int optionflag, const char* backupExtension) {
 	if (unknownXmlFile!=NULL) {
 		int i;
-		fprintf(unknownXmlFile,RES_XML_UNKNOWN_END); /* TODO: use fwrite instead */
+		fwrite(RES_XML_UNKNOWN_END,1,sizeof(RES_XML_UNKNOWN_END)-1,unknownXmlFile);
 		writeCloseOk(unknownXmlFile,optionflag,backupExtension);
 		unknownXmlFile=NULL;
 		for (i=0;i<RES_TYPECOUNT;i++) typeCount[i]=0;