git » fp-git.git » commit 6cd2e09

changed the error codes for the XML parser

author ecalot
2005-06-10 10:43:27 UTC
committer ecalot
2005-06-10 10:43:27 UTC
parent 01d94106ca9210799e2652aceed9c77c535f3310

changed the error codes for the XML parser

PR/src/console/main.c +10 -10
PR/src/include/common.h +24 -2
PR/src/lib/actions/export.c +2 -2
PR/src/lib/layers/autodetect.c +2 -3
PR/src/lib/layers/idlist.c +2 -3
PR/src/lib/pr.c +1 -4
PR/src/lib/xml/parse.c +3 -3
PR/src/lib/xml/tree.c +2 -3
PR/src/lib/xml/unknown.c +2 -3

diff --git a/PR/src/console/main.c b/PR/src/console/main.c
index 02c9f53..fdd447b 100644
--- a/PR/src/console/main.c
+++ b/PR/src/console/main.c
@@ -66,9 +66,9 @@ int main (int argc, char **argv) {
 	char* extension        =NULL;
 	char* resFile          =NULL;
 	char* file;
-	char* exportErrors[]   =PR_TEXT_EXPORT_ARRAY;
+	/*char* exportErrors[]   =PR_TEXT_EXPORT_ARRAY;
 	char* classifyErrors[] =PR_TEXT_CLASSIFY_ARRAY;
-	char* importErrors[]   =PR_TEXT_IMPORT_ARRAY;
+	char* importErrors[]   =PR_TEXT_IMPORT_ARRAY;*/
 	int   c,result;
 	int   optionflag=0;
 
@@ -151,7 +151,6 @@ int main (int argc, char **argv) {
 	/* Show about or cgi stuff */
 	if (hasFlag(cgi_flag)) {
 		fprintf(outputStream,PR_CGI_TEXT1);
-	} else {
 		fprintf(outputStream,PR_ABOUT);
 	}
 
@@ -198,20 +197,25 @@ int main (int argc, char **argv) {
 					/* import */
 					fprintf(outputStream,PR_TEXT_TASK_COMPILE,file,dirName);
 					result=prImportDatOpt(file,dirName,resFile,optionflag,dat,extension);
+					/*
 					if (result>0) {
 						fprintf(outputStream,PR_TEXT_RESULT_ERR,result,result);
 					} else {
 						fprintf(outputStream,PR_TEXT_RESULT,importErrors[-result],result);
 					}
+					*/
+					fprintf(outputStream,"result: %d\n",result);
 				} else if (hasFlag(export_flag)) {
 					/* export */
-					fprintf(outputStream,PR_TEXT_TASK_EXTRACT,file,dirName);
+					/*fprintf(outputStream,PR_TEXT_TASK_EXTRACT,file,dirName);*/
 					result=prExportDatOpt(file,dirName,resFile,optionflag,dat,datAuthor,extension);
-					fprintf(outputStream,PR_TEXT_RESULT,exportErrors[-result],result);
+					/*fprintf(outputStream,PR_TEXT_RESULT,exportErrors[-result],result);*/
+					fprintf(outputStream,"result: %d\n",result);
 				} else {
 					/* classify */
 					result=prClassifyDat(file);
-					fprintf(outputStream,PR_TEXT_RESULT,classifyErrors[result+2],result);
+					/*fprintf(outputStream,PR_TEXT_RESULT,classifyErrors[result+2],result);*/
+					fprintf(outputStream,"result: %d\n",result);
 				}
 				free(file);
 				free(datfile);
@@ -222,10 +226,6 @@ int main (int argc, char **argv) {
 			fprintf(stderr,"Error, check the xml file\n");
 			break;
 		}
-		/*parseGivenPath(datFilePath);*/
-
-		/* Run main program */
-		/*prStart(optionflag,extension,dirName,resFile,datFilePath,datFileName,datAuthor,stdout);*/
 	}
 	freeParsingCache();
 	freeAllocation(datAuthor);
diff --git a/PR/src/include/common.h b/PR/src/include/common.h
index 726f97d..13c6480 100644
--- a/PR/src/include/common.h
+++ b/PR/src/include/common.h
@@ -78,8 +78,6 @@ common.h: Princed Resources : Defines and prototypes common to all PR code
 
 #define DEFAULT_BACKUP_EXTENSION "bak"
 
-/* Define max & min's */
-
 /***************************************************************\
 |                        L A N G U A G E                        |
 \***************************************************************/
@@ -178,5 +176,29 @@ PARSING_OPTRAW\
 #define hasFlag(a) (optionflag&(a))
 #define setFlag(a) optionflag|=(a)
 
+#define PR_RESULT_SUCCESS 0
+#define PR_RESULT_ERR_EXTRACTION -1
+#define PR_RESULT_ERR_FILE_DAT_NOTFOUND -2
+#define PR_RESULT_ERR_FILE_DAT_NOTOPEN -3
+#define PR_RESULT_ERR_FILE_NOTFOUND -4
+#define PR_RESULT_ERR_FILE_NOTOPEN -5
+#define PR_RESULT_ERR_INVALID_DAT -6
+#define PR_RESULT_ERR_MEMORY -7
+#define PR_RESULT_ERR_XML_ATTR -8
+#define PR_RESULT_ERR_XML_FILE -9
+#define PR_RESULT_ERR_XML_PARSING -10
+#define PR_RESULT_TYPE_1BINARY 1
+#define PR_RESULT_TYPE_1GRAPHIC_BAD 2
+#define PR_RESULT_TYPE_1GRAPHIC_PAL 3
+#define PR_RESULT_TYPE_1LEVEL 4
+#define PR_RESULT_TYPE_1PCS 5
+#define PR_RESULT_TYPE_1WAVE 6
+#define PR_RESULT_TYPE_2BINARY 11
+#define PR_RESULT_TYPE_2GRAPHIC_BAD 12
+#define PR_RESULT_TYPE_2GRAPHIC_PAL 13
+#define PR_RESULT_TYPE_2LEVEL 14
+#define PR_RESULT_TYPE_2PCS 15
+#define PR_RESULT_TYPE_2WAVE 16
+
 #endif
 
diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index 2d602b8..e8801d7 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -19,8 +19,8 @@
 */
 
 /*
-extract.c: Princed Resources : DAT Extractor
-\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+export.c: Princed Resources : DAT Extractor
+\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
  Copyright 2003-2005 Princed Development Team
   Created: 24 Aug 2003
 
diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c
index c4db3f3..9ffbf5d 100644
--- a/PR/src/lib/layers/autodetect.c
+++ b/PR/src/lib/layers/autodetect.c
@@ -235,7 +235,7 @@ void freePartialList() {
 int checkSum(const unsigned char* data,int size) {
 	unsigned char  checksum = 1;
 
-	/* calculates the checksum */
+	/* validates the checksum */
 	while (size--) checksum+=*(data++);
 	return !checksum;
 }
@@ -255,13 +255,12 @@ int parseFile(const char* vFile, const char* datFile, tResourceList *r) {
 	if ((error=parseStructure(vFile,&structure))) return error;
 
 	/* Use the xml structure to Generate the resource structure of the file */
-	/*emptyTable(r);*/
 	pass.datFile=datFile;
 	pass.r=r;
 	workTree(structure,&pass,workTag);
 
 	/* All done */
-	return 0;
+	return PR_RESULT_SUCCESS;
 }
 
 /***************************************************************\
diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c
index c4db3f3..9ffbf5d 100644
--- a/PR/src/lib/layers/idlist.c
+++ b/PR/src/lib/layers/idlist.c
@@ -235,7 +235,7 @@ void freePartialList() {
 int checkSum(const unsigned char* data,int size) {
 	unsigned char  checksum = 1;
 
-	/* calculates the checksum */
+	/* validates the checksum */
 	while (size--) checksum+=*(data++);
 	return !checksum;
 }
@@ -255,13 +255,12 @@ int parseFile(const char* vFile, const char* datFile, tResourceList *r) {
 	if ((error=parseStructure(vFile,&structure))) return error;
 
 	/* Use the xml structure to Generate the resource structure of the file */
-	/*emptyTable(r);*/
 	pass.datFile=datFile;
 	pass.r=r;
 	workTree(structure,&pass,workTag);
 
 	/* All done */
-	return 0;
+	return PR_RESULT_SUCCESS;
 }
 
 /***************************************************************\
diff --git a/PR/src/lib/pr.c b/PR/src/lib/pr.c
index 6bad3a6..a74ddd4 100644
--- a/PR/src/lib/pr.c
+++ b/PR/src/lib/pr.c
@@ -140,10 +140,7 @@ int prExportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF
 
 	/* Parse XML and export the file */
 	a=parseFile(vResFile,currentDatFileName,&r);
-	if (a<0) {
-		/* parsing errors */
-		a-=3;
-	} else {
+	if (a==PR_RESULT_SUCCESS) {
 		/* exporting errors/no errors */
 		a=extract(currentDatFile,vDirName,&r,opt,currentDatFileName,datAuthor,backupExtension);
 	}
diff --git a/PR/src/lib/xml/parse.c b/PR/src/lib/xml/parse.c
index a1d3bd7..fd692de 100644
--- a/PR/src/lib/xml/parse.c
+++ b/PR/src/lib/xml/parse.c
@@ -483,7 +483,7 @@ tTag* parseXmlFile(const char* vFile,int* error) {
 	father=getTagStructure();
 	tag=makeTree(&p,value,error,father);
 
-	if (*error) {
+	if ((*error)<0) {
 		freeTagStructure(tag);
 		free(l);
 		free(father);
@@ -498,8 +498,8 @@ tTag* parseXmlFile(const char* vFile,int* error) {
 		free(father);
 		return NULL; /* Fatal error will stop the execusion of the parsing */
 	}
-	if (*error==3) {
-		*error=0;
+	if (*error==3) { /* 3 means end of document */
+		*error=PR_RESULT_SUCCESS;
 		free(father);
 		return tag;
 	} else {
diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c
index c4db3f3..9ffbf5d 100644
--- a/PR/src/lib/xml/tree.c
+++ b/PR/src/lib/xml/tree.c
@@ -235,7 +235,7 @@ void freePartialList() {
 int checkSum(const unsigned char* data,int size) {
 	unsigned char  checksum = 1;
 
-	/* calculates the checksum */
+	/* validates the checksum */
 	while (size--) checksum+=*(data++);
 	return !checksum;
 }
@@ -255,13 +255,12 @@ int parseFile(const char* vFile, const char* datFile, tResourceList *r) {
 	if ((error=parseStructure(vFile,&structure))) return error;
 
 	/* Use the xml structure to Generate the resource structure of the file */
-	/*emptyTable(r);*/
 	pass.datFile=datFile;
 	pass.r=r;
 	workTree(structure,&pass,workTag);
 
 	/* All done */
-	return 0;
+	return PR_RESULT_SUCCESS;
 }
 
 /***************************************************************\
diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c
index c4db3f3..9ffbf5d 100644
--- a/PR/src/lib/xml/unknown.c
+++ b/PR/src/lib/xml/unknown.c
@@ -235,7 +235,7 @@ void freePartialList() {
 int checkSum(const unsigned char* data,int size) {
 	unsigned char  checksum = 1;
 
-	/* calculates the checksum */
+	/* validates the checksum */
 	while (size--) checksum+=*(data++);
 	return !checksum;
 }
@@ -255,13 +255,12 @@ int parseFile(const char* vFile, const char* datFile, tResourceList *r) {
 	if ((error=parseStructure(vFile,&structure))) return error;
 
 	/* Use the xml structure to Generate the resource structure of the file */
-	/*emptyTable(r);*/
 	pass.datFile=datFile;
 	pass.r=r;
 	workTree(structure,&pass,workTag);
 
 	/* All done */
-	return 0;
+	return PR_RESULT_SUCCESS;
 }
 
 /***************************************************************\