git » fp-git.git » commit f891f95

now using the recently-rewritten unknown.xml handling library

author ecalot
2005-12-21 10:00:29 UTC
committer ecalot
2005-12-21 10:00:29 UTC
parent ae5ef5825f34c5833b9a96aac1493462a0b43fde

now using the recently-rewritten unknown.xml handling library

PR/src/console/main.c +4 -0
PR/src/include/pr.h +12 -7
PR/src/include/tree.h +1 -1
PR/src/include/unknown.h +1 -1
PR/src/lib/xml/tree.c +9 -5
PR/src/lib/xml/unknown.c +9 -5

diff --git a/PR/src/console/main.c b/PR/src/console/main.c
index faa649a..0cc301e 100644
--- a/PR/src/console/main.c
+++ b/PR/src/console/main.c
@@ -199,7 +199,9 @@ int main (int argc, char **argv) {
 				if (hasFlag(import_flag)) {
 					/* import */
 					fprintf(outputStream,PR_TEXT_TASK_COMPILE,file,dirName);
+					unknownLogStart(NULL,optionflag,extension);
 					result=prImportDatOpt(file,dirName,resFile,optionflag,dat,extension);
+					unknownLogStop();
 					if (result>0) {
 						fprintf(outputStream,PR_TEXT_RESULT_ERR,result,result);
 					} else {
@@ -208,7 +210,9 @@ int main (int argc, char **argv) {
 				} else if (hasFlag(export_flag)) {
 					/* export */
 					fprintf(outputStream,PR_TEXT_TASK_EXTRACT,file,dirName);
+					unknownLogStart(NULL,optionflag,extension);
 					result=prExportDatOpt(file,dirName,resFile,optionflag,dat,datAuthor,extension,format);
+					unknownLogStop();
 					if (result>0) {
 						fprintf(outputStream,PR_TEXT_EXPORT_OK,result,result);
 					} else {
diff --git a/PR/src/include/pr.h b/PR/src/include/pr.h
index cd499a5..d8a985f 100644
--- a/PR/src/include/pr.h
+++ b/PR/src/include/pr.h
@@ -98,18 +98,23 @@ int   prImportDatOpt(const char* vDatFile, const char* vDirName,
       const char* backupExtension);
 
 /* Option functions */
-void  prSetOutput(FILE* output);
-void  setCompressionLevel(int cl);
+void  prSetOutput         (FILE* output);
+void  setCompressionLevel (int cl);
 
 /* Xml parsing functions */
 tTag* resourceTreeGetChild(tTag* whereAmI);
 tTag* resourceTreeGetNext (tTag* whereAmI);
 int   resourceTreeGetInfo (tTag* whereAmI,	char** tag, char** desc, char** path, char** file, char** type, char** name, char** palette, char** value, char** version, char** number);
-int   parseStructure(const char* vFile, tTag** structure);
-void  freeParsedStructure(tTag** structure);
-void  freeParsingCache();
-void  freeTagStructure (tTag* structure);
-tTag* parseXmlFile     (const char* vFile,int* error);
+int   parseStructure      (const char* vFile, tTag** structure);
+void  freeParsedStructure (tTag** structure);
+void  freeParsingCache    ();
+void  freeTagStructure    (tTag* structure);
+tTag* parseXmlFile        (const char* vFile,int* error);
+
+/* unknown.xml logging */
+
+int   unknownLogStart     (const char* file,int optionflag, const char* backupExtension);
+int   unknownLogStop      ();
 
 #endif
 
diff --git a/PR/src/include/tree.h b/PR/src/include/tree.h
index 9de35a0..19eb3fc 100644
--- a/PR/src/include/tree.h
+++ b/PR/src/include/tree.h
@@ -57,7 +57,7 @@ void getUpperFolder(char* aux, char* vFiledat);
 /* In case there are unknown resources it closes the unknown XML output */
 void endUnknownXml();
 
-/* Search files for the Import feature */
+/* Search files for the Import feature * TODO check this prototypes */
 int importDir(const char* directory, const char* vResFile, int pOption, const char* backupExtension,const char* vDirectory,FILE* output);
 int isntADatFile(const char* testFile, const char* vResFile);
 
diff --git a/PR/src/include/unknown.h b/PR/src/include/unknown.h
index 9de35a0..19eb3fc 100644
--- a/PR/src/include/unknown.h
+++ b/PR/src/include/unknown.h
@@ -57,7 +57,7 @@ void getUpperFolder(char* aux, char* vFiledat);
 /* In case there are unknown resources it closes the unknown XML output */
 void endUnknownXml();
 
-/* Search files for the Import feature */
+/* Search files for the Import feature * TODO check this prototypes */
 int importDir(const char* directory, const char* vResFile, int pOption, const char* backupExtension,const char* vDirectory,FILE* output);
 int isntADatFile(const char* testFile, const char* vResFile);
 
diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c
index 75abc6c..371ad7b 100644
--- a/PR/src/lib/xml/tree.c
+++ b/PR/src/lib/xml/tree.c
@@ -64,22 +64,22 @@ static struct {
 /* fwrite(RES_XML_UNKNOWN_END,1,sizeof(RES_XML_UNKNOWN_END)-1,unknownXmlFile);*/
 
 #define unknown_emptyfile()\
-	fprintf(unknownFile.fd, "<resources />\n")
+	fprintf(unknownFile.fd, "<?xml version=\"1.0\" ?>\n<resources />\n")
 
 #define unknown_folderclose()\
 	fprintf(unknownFile.fd, "\t</folder>\n\n")
 
 #define unknown_folder(file)\
-	fprintf(unknownFile.fd, "\t<folder file=\"%s\"", file)
+	fprintf(unknownFile.fd, "\t<folder file=\"%s\">\n", file)
 
 #define unknown_foot()\
 	fprintf(unknownFile.fd, "</resources>\n")
 
 #define unknown_head()\
-	fprintf(unknownFile.fd, "<?xml version=\"1.0\" ?><resources>\n")
+	fprintf(unknownFile.fd, "<?xml version=\"1.0\" ?>\n<resources>\n")
 
 #define unknown_item(path)\
-	fprintf(unknownFile.fd, "\t\t<item path=\"%s\" />", path)
+	fprintf(unknownFile.fd, "\t\t<item path=\"%s\" />\n", path)
 
 
 /* semantic layer */
@@ -87,6 +87,9 @@ static struct {
 int unknownLogStart (const char* file,int optionflag, const char* backupExtension) {
 	if (unknownFile.fd) return -1; /* File already open */
 
+	/* Use default filename if file is NULL */
+	if (!file) file="unknown.xml";
+
 	/* Remember optionflag and backupExtension */
 	unknownFile.optionflag=optionflag;
 	unknownFile.backupExtension=strallocandcopy(backupExtension);
@@ -130,6 +133,7 @@ int unknownLogAppend(const char* vFiledatWithPath,tResourceId id,const char* ext
 	if (!unknownFile.currentDat) { /* this is the beginning of the file */
 		unknown_head();
 		unknown_folder(vFiledat); 
+		unknownFile.currentDat=strallocandcopy(vFiledat);
 	} else if (!equalsIgnoreCase(unknownFile.currentDat,vFiledat)) {
 		unknown_folderclose(); 
 		unknown_folder(vFiledat); 
@@ -158,7 +162,7 @@ char* toLower(const char* txt) { /* TODO: send to memory.c */
 
 
 /* Resources output to xml functions. Private+abstract variable */
-static FILE* unknownXmlFile=NULL;
+/*static FILE* unknownXmlFile=NULL;*/
 
 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) {
 
diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c
index 75abc6c..371ad7b 100644
--- a/PR/src/lib/xml/unknown.c
+++ b/PR/src/lib/xml/unknown.c
@@ -64,22 +64,22 @@ static struct {
 /* fwrite(RES_XML_UNKNOWN_END,1,sizeof(RES_XML_UNKNOWN_END)-1,unknownXmlFile);*/
 
 #define unknown_emptyfile()\
-	fprintf(unknownFile.fd, "<resources />\n")
+	fprintf(unknownFile.fd, "<?xml version=\"1.0\" ?>\n<resources />\n")
 
 #define unknown_folderclose()\
 	fprintf(unknownFile.fd, "\t</folder>\n\n")
 
 #define unknown_folder(file)\
-	fprintf(unknownFile.fd, "\t<folder file=\"%s\"", file)
+	fprintf(unknownFile.fd, "\t<folder file=\"%s\">\n", file)
 
 #define unknown_foot()\
 	fprintf(unknownFile.fd, "</resources>\n")
 
 #define unknown_head()\
-	fprintf(unknownFile.fd, "<?xml version=\"1.0\" ?><resources>\n")
+	fprintf(unknownFile.fd, "<?xml version=\"1.0\" ?>\n<resources>\n")
 
 #define unknown_item(path)\
-	fprintf(unknownFile.fd, "\t\t<item path=\"%s\" />", path)
+	fprintf(unknownFile.fd, "\t\t<item path=\"%s\" />\n", path)
 
 
 /* semantic layer */
@@ -87,6 +87,9 @@ static struct {
 int unknownLogStart (const char* file,int optionflag, const char* backupExtension) {
 	if (unknownFile.fd) return -1; /* File already open */
 
+	/* Use default filename if file is NULL */
+	if (!file) file="unknown.xml";
+
 	/* Remember optionflag and backupExtension */
 	unknownFile.optionflag=optionflag;
 	unknownFile.backupExtension=strallocandcopy(backupExtension);
@@ -130,6 +133,7 @@ int unknownLogAppend(const char* vFiledatWithPath,tResourceId id,const char* ext
 	if (!unknownFile.currentDat) { /* this is the beginning of the file */
 		unknown_head();
 		unknown_folder(vFiledat); 
+		unknownFile.currentDat=strallocandcopy(vFiledat);
 	} else if (!equalsIgnoreCase(unknownFile.currentDat,vFiledat)) {
 		unknown_folderclose(); 
 		unknown_folder(vFiledat); 
@@ -158,7 +162,7 @@ char* toLower(const char* txt) { /* TODO: send to memory.c */
 
 
 /* Resources output to xml functions. Private+abstract variable */
-static FILE* unknownXmlFile=NULL;
+/*static FILE* unknownXmlFile=NULL;*/
 
 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) {