git » fp-git.git » commit 2769880

commited current unknown.xml work, not finished

author ecalot
2005-12-23 23:43:39 UTC
committer ecalot
2005-12-23 23:43:39 UTC
parent 1946e493ef561f91b1701d095469db557066d4b9

commited current unknown.xml work, not finished

PR/src/include/parse.h +7 -0
PR/src/include/pr.h +1 -0
PR/src/lib/xml/parse.c +3 -3
PR/src/lib/xml/tree.c +65 -3
PR/src/lib/xml/unknown.c +65 -3

diff --git a/PR/src/include/parse.h b/PR/src/include/parse.h
index 3f7c13e..ffdf0c2 100644
--- a/PR/src/include/parse.h
+++ b/PR/src/include/parse.h
@@ -36,9 +36,16 @@ parse.h: Princed Resources : xml handling functions headers
 
 const char* getExtDesc(int type);
 
+#define IGNOREVERIFYDATTYPES
+#ifdef IGNOREVERIFYDATTYPES
+#include "pr.h"
+void showTag(int n,tTag* t);
+#endif
+
 /* Constants */
 #define MAX_VALUE_SIZE        3000
 #define RES_TYPECOUNT         9
+
 /* for RES_FILE_TYPES */
 #include "common.h"
 
diff --git a/PR/src/include/pr.h b/PR/src/include/pr.h
index d8a985f..6b3103d 100644
--- a/PR/src/include/pr.h
+++ b/PR/src/include/pr.h
@@ -98,6 +98,7 @@ int   prImportDatOpt(const char* vDatFile, const char* vDirName,
       const char* backupExtension);
 
 /* Option functions */
+#include <stdio.h> /* FILE* */
 void  prSetOutput         (FILE* output);
 void  setCompressionLevel (int cl);
 
diff --git a/PR/src/lib/xml/parse.c b/PR/src/lib/xml/parse.c
index 217d612..7e7436a 100644
--- a/PR/src/lib/xml/parse.c
+++ b/PR/src/lib/xml/parse.c
@@ -52,8 +52,6 @@ parse.c: Princed Resources : xml parsing functions
 #define XML_WASNT_TEXT 6
 #define XML_WAS_TAG 7
 
-extern FILE* outputStream;
-
 /****************************************************************\
 |                   Tag Tree Handling Functions                  |
 \****************************************************************/
@@ -444,13 +442,15 @@ tTag* makeTree(char** p,char* name, int* error,tTag* father) {
 
 #ifdef IGNOREVERIFYDATTYPES
 
+extern FILE* outputStream;
+
 void showTag(int n,tTag* t) {
 	int a;
 	tTag* children;
 
 	for(a=0;a<n;a++) fprintf (outputStream,"  ");
 	if (t!=NULL) {
-		fprintf(outputStream,"%s (%s@%s)\n",t->tag,t->file,t->value);
+		fprintf(outputStream,"%s (%s@%s:%s#%s)\n",t->tag,t->file,t->value,t->index,t->order);
 		children=t->child;
 
 		while (children!=NULL) {
diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c
index 4fd934a..5370f66 100644
--- a/PR/src/lib/xml/tree.c
+++ b/PR/src/lib/xml/tree.c
@@ -42,6 +42,7 @@ unknown.c: Princed Resources : Unknown resources handler
 #include "disk.h"
 #include "unknown.h"
 #include "memory.h"
+#include "parse.h" /* For the moment just testing */
 #include "stringformat.h"
 #include "translate.h"
 
@@ -59,6 +60,7 @@ static struct {
 	char* currentDat;
 	int optionflag;
 	unsigned int typeCount[RES_TYPECOUNT]; /* initialized in 0 */
+	tTag* tree;
 } unknownFile;
 
 /***************************************************************\
@@ -87,6 +89,48 @@ static struct {
 	"\t\t<item value=\"%d\" index=\"%s\" path=\"%s\" type=\"%s\" flags=\"0x%lx\">Unknown %s %d</item>\n",\
 	           value,       index,       path,       type,       flags,          typedesc, count)
 
+
+/* tree module */
+void rec_tree(tTag* *t,const char* file) {
+	tTag* aux=*t;
+	tTag* aux2;
+	
+	if (*t && (*t)->file) {
+		if (equalsIgnoreCase((aux->file),file)) {
+			if (aux->child) {
+				*t=aux->child; /* the children are now replacing his parent */
+				if ((*t)->next) {
+					for(aux2=*t;aux2->next;aux2=aux2->next); /* go to the last child */
+				 	aux2->next=aux->next; /* and set the next siebling as the parent next siebling */
+				}
+				aux->next=NULL;
+				aux->child=NULL;
+				/* freeTag(aux); */
+			} else {
+				if (*t)	rec_tree(t,file);
+			}
+		} else {
+			if ((*t) && (*t)->next)
+				rec_tree(&((*t)->next),file);
+		}
+	}
+	
+	if ((*t) && (*t)->child)
+		rec_tree(&((*t)->child),file);
+
+}
+
+void unknown_deletetreefile(const char* file) {
+	printf("deleting file %s from tree\n",file);
+	showTag(0,unknownFile.tree);
+	if (unknownFile.tree)
+		rec_tree(&(unknownFile.tree->child),file);
+
+
+	showTag(0,unknownFile.tree);
+
+}
+
 /***************************************************************\
 |                          Semantic Layer                       |
 \***************************************************************/
@@ -102,6 +146,19 @@ int unknownLogStart (const char* file,int optionflag, const char* backupExtensio
 	unknownFile.backupExtension=strallocandcopy(backupExtension);
 	unknownFile.currentDat=NULL;
 
+	/* Read the previous file if exists */
+	{
+		int error;
+
+		unknownFile.tree=parseXmlFile(file,&error);
+		if (!error) {
+		/*	showTag(0,unknownFile.tree);*/
+		} else {
+			unknownFile.tree=NULL;
+			printf("Error parsing %s (code=%d)\n",file,error);
+		}
+	}
+	
 	/* Open the file */
 	if (!writeOpen(file,&unknownFile.fd,optionflag)) return -2; /* file not open */
 
@@ -130,23 +187,28 @@ int unknownLogStop () {
 	unknownFile.backupExtension=NULL;
 	unknownFile.fd=NULL;
 	for (i=0;i<RES_TYPECOUNT;i++) unknownFile.typeCount[i]=0; /* re-initialize in 0 for next file processing */
+	showTag(0,unknownFile.tree);
+	freeParsedStructure (&unknownFile.tree);
 
 	return 0; /* Ok */
 }
 
-int unknownLogAppend(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) {
+int unknownLogAppend(const char* vFiledat,tResourceId id,const char* ext,tResourceType type,const char* vDirExt,tResourceId pal,const char* vFiledatWithPath,int optionflag,int count, unsigned long int flags,const char* filename) {
 	if (!unknownFile.fd) return -1; /* File not open, logging if off */
 
 	if (!unknownFile.currentDat) { /* this is the beginning of the file */
 		unknown_head();
-		unknown_folder(vFiledat,vFiledatWithPath,pal.value,translateInt2Ext(toLower(pal.index)));
+		unknown_folder(vFiledatWithPath,vFiledat,pal.value,translateInt2Ext(toLower(pal.index)));
 		unknownFile.currentDat=strallocandcopy(vFiledat);
+		/* TODO: move here the read-parsing-loading and write-opening */
+		unknown_deletetreefile(vFiledat);
 	} else if (!equalsIgnoreCase(unknownFile.currentDat,vFiledat)) {
 		int i;
 		unknown_folderclose(); 
-		unknown_folder(vFiledat,vFiledatWithPath,pal.value,translateInt2Ext(toLower(pal.index)));
+		unknown_folder(vFiledatWithPath,vFiledat,pal.value,translateInt2Ext(toLower(pal.index)));
 		freeAllocation(unknownFile.currentDat);
 		unknownFile.currentDat=strallocandcopy(vFiledat);
+		unknown_deletetreefile(vFiledat);
 		for (i=0;i<RES_TYPECOUNT;i++) unknownFile.typeCount[i]=0; /* re-initialize in 0 for next file processing */
 	}
 
diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c
index 4fd934a..5370f66 100644
--- a/PR/src/lib/xml/unknown.c
+++ b/PR/src/lib/xml/unknown.c
@@ -42,6 +42,7 @@ unknown.c: Princed Resources : Unknown resources handler
 #include "disk.h"
 #include "unknown.h"
 #include "memory.h"
+#include "parse.h" /* For the moment just testing */
 #include "stringformat.h"
 #include "translate.h"
 
@@ -59,6 +60,7 @@ static struct {
 	char* currentDat;
 	int optionflag;
 	unsigned int typeCount[RES_TYPECOUNT]; /* initialized in 0 */
+	tTag* tree;
 } unknownFile;
 
 /***************************************************************\
@@ -87,6 +89,48 @@ static struct {
 	"\t\t<item value=\"%d\" index=\"%s\" path=\"%s\" type=\"%s\" flags=\"0x%lx\">Unknown %s %d</item>\n",\
 	           value,       index,       path,       type,       flags,          typedesc, count)
 
+
+/* tree module */
+void rec_tree(tTag* *t,const char* file) {
+	tTag* aux=*t;
+	tTag* aux2;
+	
+	if (*t && (*t)->file) {
+		if (equalsIgnoreCase((aux->file),file)) {
+			if (aux->child) {
+				*t=aux->child; /* the children are now replacing his parent */
+				if ((*t)->next) {
+					for(aux2=*t;aux2->next;aux2=aux2->next); /* go to the last child */
+				 	aux2->next=aux->next; /* and set the next siebling as the parent next siebling */
+				}
+				aux->next=NULL;
+				aux->child=NULL;
+				/* freeTag(aux); */
+			} else {
+				if (*t)	rec_tree(t,file);
+			}
+		} else {
+			if ((*t) && (*t)->next)
+				rec_tree(&((*t)->next),file);
+		}
+	}
+	
+	if ((*t) && (*t)->child)
+		rec_tree(&((*t)->child),file);
+
+}
+
+void unknown_deletetreefile(const char* file) {
+	printf("deleting file %s from tree\n",file);
+	showTag(0,unknownFile.tree);
+	if (unknownFile.tree)
+		rec_tree(&(unknownFile.tree->child),file);
+
+
+	showTag(0,unknownFile.tree);
+
+}
+
 /***************************************************************\
 |                          Semantic Layer                       |
 \***************************************************************/
@@ -102,6 +146,19 @@ int unknownLogStart (const char* file,int optionflag, const char* backupExtensio
 	unknownFile.backupExtension=strallocandcopy(backupExtension);
 	unknownFile.currentDat=NULL;
 
+	/* Read the previous file if exists */
+	{
+		int error;
+
+		unknownFile.tree=parseXmlFile(file,&error);
+		if (!error) {
+		/*	showTag(0,unknownFile.tree);*/
+		} else {
+			unknownFile.tree=NULL;
+			printf("Error parsing %s (code=%d)\n",file,error);
+		}
+	}
+	
 	/* Open the file */
 	if (!writeOpen(file,&unknownFile.fd,optionflag)) return -2; /* file not open */
 
@@ -130,23 +187,28 @@ int unknownLogStop () {
 	unknownFile.backupExtension=NULL;
 	unknownFile.fd=NULL;
 	for (i=0;i<RES_TYPECOUNT;i++) unknownFile.typeCount[i]=0; /* re-initialize in 0 for next file processing */
+	showTag(0,unknownFile.tree);
+	freeParsedStructure (&unknownFile.tree);
 
 	return 0; /* Ok */
 }
 
-int unknownLogAppend(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) {
+int unknownLogAppend(const char* vFiledat,tResourceId id,const char* ext,tResourceType type,const char* vDirExt,tResourceId pal,const char* vFiledatWithPath,int optionflag,int count, unsigned long int flags,const char* filename) {
 	if (!unknownFile.fd) return -1; /* File not open, logging if off */
 
 	if (!unknownFile.currentDat) { /* this is the beginning of the file */
 		unknown_head();
-		unknown_folder(vFiledat,vFiledatWithPath,pal.value,translateInt2Ext(toLower(pal.index)));
+		unknown_folder(vFiledatWithPath,vFiledat,pal.value,translateInt2Ext(toLower(pal.index)));
 		unknownFile.currentDat=strallocandcopy(vFiledat);
+		/* TODO: move here the read-parsing-loading and write-opening */
+		unknown_deletetreefile(vFiledat);
 	} else if (!equalsIgnoreCase(unknownFile.currentDat,vFiledat)) {
 		int i;
 		unknown_folderclose(); 
-		unknown_folder(vFiledat,vFiledatWithPath,pal.value,translateInt2Ext(toLower(pal.index)));
+		unknown_folder(vFiledatWithPath,vFiledat,pal.value,translateInt2Ext(toLower(pal.index)));
 		freeAllocation(unknownFile.currentDat);
 		unknownFile.currentDat=strallocandcopy(vFiledat);
+		unknown_deletetreefile(vFiledat);
 		for (i=0;i<RES_TYPECOUNT;i++) unknownFile.typeCount[i]=0; /* re-initialize in 0 for next file processing */
 	}