git » fp-git.git » commit 698838e

added return comments and simplified the source

author ecalot
2006-01-07 20:52:05 UTC
committer ecalot
2006-01-07 20:52:05 UTC
parent 267047960419718a4c9160950ed68fef6709c7b2

added return comments and simplified the source

PR/src/lib/layers/dat.c +35 -29
PR/src/lib/layers/idlist.c +16 -10
PR/src/lib/layers/list.c +9 -9
PR/src/lib/layers/memory.c +10 -8
PR/src/lib/xml/parse.c +9 -7
PR/src/lib/xml/search.c +17 -14
PR/src/lib/xml/tree.c +46 -48
PR/src/lib/xml/unknown.c +22 -21

diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c
index 0ec44c7..f84046a 100644
--- a/PR/src/lib/layers/dat.c
+++ b/PR/src/lib/layers/dat.c
@@ -42,11 +42,9 @@ dat.c: Princed Resources : DAT library
 #include "reslist.h"
 
 /***************************************************************\
-|                     DAT reading primitives                    |
+|                    Private layer structures                   |
 \***************************************************************/
 
-#ifdef PR_DAT_INCLUDE_DATREAD
-
 typedef struct {
 	tPopVersion         popVersion;
 	unsigned char*      highData;
@@ -76,8 +74,9 @@ int checkSum(const unsigned char* data,int size) {
 	return !checksum;
 }
 
-/* private functions */
-/* todo: move to datindex.c */
+/***************************************************************\
+|                         Private layer                         |
+\***************************************************************/
 
 #define toLower(a) (('A'<=(a)&&(a)<='Z')?(a)|0x20:(a))
 #define toUpper(a) (('a'<=(a)&&(a)<='z')?(a)&0xDF:(a))
@@ -121,11 +120,11 @@ void saveIndex(char* to, const char* from) {
 int dat_cursorNextIndex(tIndexCursor* r) {
 	if (r->popVersion==pop1) {
 		/* POP1 */
-		return 0;
+		return 0; /* false */
 	} else {
 		/* POP2 */
 		if (r->currentMasterItem==r->masterItems) {
-			return 0; /* its over */
+			return 0; /* false: its over */
 		}
 
 		/* remember the new slave index name */
@@ -139,7 +138,7 @@ int dat_cursorNextIndex(tIndexCursor* r) {
 		r->currentSlaveItem=0;
 		r->currentRecord=r->highData+array2short(r->highData+6+6*r->currentMasterItem)+2;
 	}
-	return 1;
+	return 1; /* true */
 }
 
 int dat_cursorNext(tIndexCursor* r) {
@@ -148,15 +147,15 @@ int dat_cursorNext(tIndexCursor* r) {
 		r->currentSlaveItem++;
 		r->currentRecord+=8;
 		if (r->currentSlaveItem==r->slaveItems)
-			return 0;
+			return 0; /* false */
 	} else {
 		/* POP2 */
-			r->currentSlaveItem++;
-			r->currentRecord+=11;
+		r->currentSlaveItem++;
+		r->currentRecord+=11;
 		if (r->currentSlaveItem==r->slaveItems)
 			return dat_cursorNextIndex(r);
 	}
-	return 1;
+	return 1; /* true */
 }
 
 void dat_cursorFirst(tIndexCursor* r) {
@@ -181,22 +180,22 @@ int dat_cursorMoveId(tIndexCursor* r, tResourceId id) {
 		if (!strcmp(r->slaveIndexName,id.index)) {
 			/* the same index */
 			do {
-				if (strcmp(r->slaveIndexName,id.index)) return 0; /* in case we are passed */
-				if (array2short(r->currentRecord)==id.value) return 1; /* found! */
+				if (strcmp(r->slaveIndexName,id.index)) return 0; /* false: in case we are passed */
+				if (array2short(r->currentRecord)==id.value) return 1; /* true: found! */
 			} while (dat_cursorNext(r));
-			return 0; /* id not found */
+			return 0; /* false: id not found */
 		}
 	} while (dat_cursorNextIndex(r));
-	return 0; /* index name not found */
+	return 0; /* false: index name not found */
 }
 
 int dat_cursorMove(tIndexCursor* r,int pos) {
 	if (r->popVersion==pop1) {
 		/* POP1 */
-		if (r->slaveItems<=pos) return 0;
+		if (r->slaveItems<=pos) return 0; /* false */
 		r->currentSlaveItem=pos;
 		r->currentRecord=r->highData+8*pos+2;
-		return 1;
+		return 1; /* true */
 	} else {
 		/* POP2 */
 		int i;
@@ -216,11 +215,11 @@ int dat_cursorMove(tIndexCursor* r,int pos) {
 				r->currentMasterItem=i;
 				r->currentSlaveItem=pos;
 				r->currentRecord=r->highData+array2short(r->highData+6+6*r->currentMasterItem)+2+pos*11;
-				return 1;
+				return 1; /* true */
 			}
 			pos-=itemCount;
 		}
-		return 0; /* we had read all the master index and we didn't read the pos */
+		return 0; /* false: we had read all the master index and we didn't read the pos */
 	}
 }
 
@@ -313,7 +312,15 @@ tIndexCursor dat_createCursor(unsigned char* highData,int highDataSize,unsigned
 	}
 }
 
-/* public functions */
+/***************************************************************\
+|                          Public Layer                         |
+\***************************************************************/
+
+/***************************************************************\
+|                     DAT reading primitives                    |
+\***************************************************************/
+
+#ifdef PR_DAT_INCLUDE_DATREAD
 
 tPopVersion mReadGetVersion() {
 	return readIndexCursor.popVersion;
@@ -343,7 +350,7 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){
 			return PR_RESULT_ERR_FILE_DAT_NOT_OPEN_WASDIR;
 		case PR_RESULT_ERR_FILE_NOT_OPEN_NOTFOUND:
 			return PR_RESULT_ERR_FILE_DAT_NOT_OPEN_NOTFOUND;
-		case 0:
+		case PR_RESULT_SUCCESS:
 			return PR_RESULT_ERR_INVALID_DAT;
 		default:
 			return readDatFileSize;
@@ -388,15 +395,15 @@ void dat_readRes(tResource* res) {
 }
 
 int mReadFileInDatFileId(tResource* res) {
-	if (!dat_cursorMoveId(&readIndexCursor,res->id)) return 0; /* 0 means index not found */
+	if (!dat_cursorMoveId(&readIndexCursor,res->id)) return 0; /* false means index not found */
 	dat_readRes(res);
-	return 1;
+	return 1; /* true */
 }
 
 int mReadFileInDatFile(tResource* res, int k) {
-	if (!dat_cursorMove(&readIndexCursor,k)) return 0; /* 0 means out of range */
+	if (!dat_cursorMove(&readIndexCursor,k)) return 0; /* false means out of range */
 	dat_readRes(res);
-	return 1;
+	return 1; /* true */
 }
 
 #endif
@@ -501,7 +508,7 @@ void mWriteCloseDatFile(int dontSave,int optionflag, const char* backupExtension
 		if (!strncmp(res->id.index,textPop1,4)) { /* POP1 */
 			do {
 				totalItems++;
-				printf("Adding item id (%s,%d)\n",res->id.index,res->id.value);
+				/*printf("Adding item id (%s,%d)\n",res->id.index,res->id.value);*/
 				fwriteshort(&(res->id.value),writeDatFile);
 				fwritelong(&(res->offset),writeDatFile);
 				fwriteshort(&(res->size),writeDatFile);
@@ -575,7 +582,7 @@ void mWriteCloseDatFile(int dontSave,int optionflag, const char* backupExtension
 	/* Write totalItems */
 	fseek(writeDatFile,size1,SEEK_SET);
 	fwriteshort(&totalItems,writeDatFile); /* Definitive total items count */
-	
+
 	/* Write first 6 bytes header */
 	fseek(writeDatFile,0,SEEK_SET);
 	fwritelong(&size1,writeDatFile);
@@ -606,4 +613,3 @@ int mRWBeginDatFile(const char* vFile, unsigned short int *numberOfItems, int op
 }
 #endif
 #endif
-
diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c
index b426126..821a2e5 100644
--- a/PR/src/lib/layers/idlist.c
+++ b/PR/src/lib/layers/idlist.c
@@ -59,7 +59,7 @@ int partialListActive() {
 |                Partial Resource List Functions                |
 \***************************************************************/
 
-void parseGivenPath(char* path) {
+int parseGivenPath(char* path) {
 	/*
 	 * format: \([^@]*\)/(@\([0-9]\+\)?\(:[a-z ]*\)?\(#[a-z0-9]\+\)\)?
 	 * where: \1 is the dat filename, \2 is the partical list whole match if exists,
@@ -89,13 +89,14 @@ void parseGivenPath(char* path) {
 	int separator=0;
 	int j=0;
 	int size;
+	int error=0;
 
 	/* Check if the variable wasn't initialized before */
-	if (partialList.count!=0) return;
+	if (partialList.count!=0) return -2;
 	partialList.list=NULL;
 
 	/* Validates the NULL path */
-	if (path==NULL) return;
+	if (path==NULL) return 0;
 
 	/* Erase the last "/" if exists. */
 	if (path) {
@@ -105,12 +106,12 @@ void parseGivenPath(char* path) {
 			if (isDirSep(path,size)) path[size]=0;
 		}
 	}
-	
+
 	/* Locate the string separation */
 	while (path[separator]&&path[separator]!='@') separator++;
 
 	/* If no separation */
-	if (!path[separator]) return; /* There was no separator */
+	if (!path[separator]) return 0; /* There was no separator */
 
 	/* Count values, separate them with '\0' and alloc memory */
 	partialList.count=1;
@@ -126,11 +127,16 @@ void parseGivenPath(char* path) {
 	partialList.list=(tResourceMatch*)malloc(sizeof(tResourceMatch)*partialList.count);
 
 	/* Parse values and save them in the list */
-	for(i=separator;j!=partialList.count;i++) {
-		initRM(path+i,partialList.list+j); /* TODO: check for parsing error*/
+	for(i=separator;(!error)&&(j!=partialList.count);i++) {
+		error=initRM(path+i,partialList.list+j);
 		while (path[i]) i++;
 		j++;
 	}
+	if (error) {
+		for (i=0;i<j-1;i++) freeRM(partialList.list+i);
+		return -1;
+	}
+	return 0;
 }
 
 int isInThePartialList(const char* vFile, tResourceId id) {
@@ -144,12 +150,12 @@ int isInThePartialList(const char* vFile, tResourceId id) {
 	*/
 	int i;
 
-	if (!partialList.count) return 1;
+	if (!partialList.count) return 1; /* true */
 
 	for (i=0;i<partialList.count;i++)
-		if (runRM(partialList.list+i,repairFolders(vFile?vFile:""),&id)) return 1;
+		if (runRM(partialList.list+i,repairFolders(vFile?vFile:""),&id)) return 1; /* true */
 
-	return 0;
+	return 0; /* false */
 }
 
 void freePartialList() {
diff --git a/PR/src/lib/layers/list.c b/PR/src/lib/layers/list.c
index 526f0df..2fd2520 100644
--- a/PR/src/lib/layers/list.c
+++ b/PR/src/lib/layers/list.c
@@ -50,7 +50,7 @@ void list_insert(tList *list,const void* data) {
 	/* I will assume sequential access is very common,
 	 * so it is very possible that data is the next element.
 	 * I will check that and if not I'll start a sequential search */
-	tListNode *node; 
+	tListNode *node;
 	node=(tListNode*)malloc(sizeof(tListNode));
 	node->data=malloc(list->size);
 	memcpy(node->data,data,list->size);
@@ -68,7 +68,7 @@ void list_insert(tList *list,const void* data) {
 			list->first=node;
 		} else {
 			/* search until we find the first higher record or the end of the list */
-			while ((list->cursor->next) && (list->cmp(list->cursor->next->data/*>*/,data)!=GT)) 
+			while ((list->cursor->next) && (list->cmp(list->cursor->next->data/*>*/,data)!=GT))
 				list->cursor=list->cursor->next;
 
 			node->next=list->cursor->next;
@@ -94,15 +94,15 @@ void list_drop(tList *list) {
 
 void list_nextCursor(tList* list) {
 	if (list->cursor) list->cursor=list->cursor->next;
-} 
+}
 
 void list_firstCursor(tList* list) {
-	list->cursor=list->first;	
-} 
+	list->cursor=list->first;
+}
 
 int list_moveCursor(tList* list,const void* data) {
 	if (!list->first) {
-		return 0;
+		return 0; /* false */
 	} else {
 		/* if the data was lower, start searching from the beginning */
 		if ((!list->cursor)||(list->cmp(list->cursor->data/*>*/,data)==GT)) list->cursor=list->first;
@@ -111,17 +111,17 @@ int list_moveCursor(tList* list,const void* data) {
 			return list->cmp(list->first->data/*==*/,data)==EQ;
 		} else {
 			/* search until we find the first higher record or the end of the list */
-			while ((list->cursor->next) && (list->cmp(list->cursor->next->data/*>*/,data)!=GT)) 
+			while ((list->cursor->next) && (list->cmp(list->cursor->next->data/*>*/,data)!=GT))
 				list->cursor=list->cursor->next;
 			/* if the prior to the first higher record is equal to data, we've found it, if not 0 will be returned;
 			 * of course the cursor will be set to the prior to the first higher record in both cases */
 			return (list->cmp(list->cursor->data/*>*/,data)==EQ);
 		}
 	}
-} 
+}
 
 void* list_getCursor(tList* list) {
 	if (!list->cursor) return NULL;
 	return list->cursor->data;
-} 
+}
 
diff --git a/PR/src/lib/layers/memory.c b/PR/src/lib/layers/memory.c
index 42a339d..c33d5b0 100644
--- a/PR/src/lib/layers/memory.c
+++ b/PR/src/lib/layers/memory.c
@@ -63,17 +63,19 @@ char* toLower(const char* txt) {
 		txt++;
 	}
 	*r=0;
-	return ret;			
+	return ret;
 }
 
 int matchesIn(const char *s, const char *p) {
-  switch(*p) {
-    case 0: return !(*s);
-    case '*': while(*(p+1)=='*') p++; return matchesIn(s,p+1) || ((*s) && matchesIn(s+1,p));
-    case '?': return (*s) && matchesIn(s+1,p+1);
-    case '&': p++;
-    default: return ((*p)==(*s)) && matchesIn(s+1,p+1);
-  }
+	switch(*p) {
+		case 0:   return !(*s);
+		case '*': while(*(p+1)=='*') p++; return matchesIn(s,p+1) || ((*s) && matchesIn(s+1,p));
+		case '?': return (*s) && matchesIn(s+1,p+1);
+		case '\\':
+		case '/': return ('/'==(*s)||'\\'==(*s)) && matchesIn(s+1,p+1);
+		case '&': p++;
+		default:  return ((*p)==(*s)) && matchesIn(s+1,p+1);
+	}
 }
 
 #ifndef IGNORE_EQUALS
diff --git a/PR/src/lib/xml/parse.c b/PR/src/lib/xml/parse.c
index 8172b6b..3f81723 100644
--- a/PR/src/lib/xml/parse.c
+++ b/PR/src/lib/xml/parse.c
@@ -82,10 +82,13 @@ const char* getExtDesc(int type) {
 tTag* getTagStructure() {
 	/* initializes */
 	tTag* t;
+	int i;
+
 	t=(tTag*)malloc(sizeof(tTag));
 	if (t==NULL) return NULL;
+	for (i=0;i<sizeof(tTag);i++) ((char*)(t))[i]=0; /* I don't trust memset */
 
-	t->child=NULL; /* TODO: use memset,0 */
+/*	t->child=NULL;
 	t->next=NULL;
 	t->tag=NULL;
 	t->desc=NULL;
@@ -101,7 +104,7 @@ tTag* getTagStructure() {
 	t->paletteorder=NULL;
 	t->version=NULL;
 	t->number=NULL;
-	t->flags=NULL;
+	t->flags=NULL;*/
 
 	return t;
 }
@@ -136,7 +139,7 @@ int attribFill(char* attr,char* val, tTag* t) {
 
 	if (equalsIgnoreCase(attr,"?")) {
 		free(val);
-		return 0;
+		return PR_RESULT_SUCCESS;
 	}
 
 	FillAttr(t->desc,"desc");
@@ -270,7 +273,7 @@ int parseNext(char** pString, tTag* tag) {
 	}
 	free(attribute);
 	*pString=i;
-	return 0;
+	return PR_RESULT_SUCCESS;
 }
 
 int getNextTag(char** pString, char** value) {
@@ -577,7 +580,7 @@ tTag* resourceTreeGetChild(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) {
-	if (whereAmI==NULL) return 0;
+	if (whereAmI==NULL) return 0; /* false */
 	*tag=whereAmI->tag;
 	*desc=whereAmI->desc;
 	*path=whereAmI->path;
@@ -588,6 +591,5 @@ int   resourceTreeGetInfo (tTag* whereAmI, char** tag, char** desc, char** path,
 	*value=whereAmI->value;
 	*version=whereAmI->version;
 	*number=whereAmI->number;
-	return 1;
+	return 1; /* true */
 }
-
diff --git a/PR/src/lib/xml/search.c b/PR/src/lib/xml/search.c
index dea366d..857fdf0 100644
--- a/PR/src/lib/xml/search.c
+++ b/PR/src/lib/xml/search.c
@@ -70,16 +70,16 @@ int parseFile(const char* vFile, const char* datFile, tResourceList *rlist) {
 int getOrder(const char* order) {
 	if (order) {
 		if (equalsIgnoreCase(order,"first")) {
-			return 0;
+			return 0; /* first */
 		} else if (equalsIgnoreCase(order,"second")) {
-			return 1;
+			return 1; /* second */
 		} else if (equalsIgnoreCase(order,"last")) {
-			return 65535;
+			return 65535; /* last */
 		} else {
 			return atoi(order);
 		}
 	} else {
-		return 0;
+		return 0; /* else: first */
 	}
 }
 
@@ -91,13 +91,16 @@ int getOrder(const char* order) {
 
 #define keepStringAttribute(attribute) res.attribute=strallocandcopy(t->attribute)
 #define keepIntAttribute(attribute,type) res.attribute=(type)ptoi(t->attribute);
-#define keepIdAttributes(attribute,idnum,idindex) res.attribute.value=(unsigned short int)ptoi(t->idnum);\
-                                             if (t->idindex) str5lowercpy(res.attribute.index,translateExt2Int(t->idindex));\
-																	           else res.attribute.index[0]=0
-																	 
-#define keepIdAttributesElse(attribute,idnum,idindex,idelse) res.attribute.value=(unsigned short int)ptoi(t->idnum);\
-                                             if (t->idindex) str5lowercpy(res.attribute.index,translateExt2Int(t->idindex));\
-																	           else str5lowercpy(res.attribute.index,t->idelse)
+#define keepIdAttributes(attribute,idnum,idindex) \
+	res.attribute.value=(unsigned short int)ptoi(t->idnum);\
+	if (t->idindex) str5lowercpy(res.attribute.index,translateExt2Int(t->idindex));\
+	else res.attribute.index[0]=0
+
+#define keepIdAttributesElse(attribute,idnum,idindex,idelse) \
+	res.attribute.value=(unsigned short int)ptoi(t->idnum);\
+	if (t->idindex) str5lowercpy(res.attribute.index,translateExt2Int(t->idindex));\
+	else str5lowercpy(res.attribute.index,t->idelse)
+
 void workTag(const tTag* t,void* pass) {
 	/*
 		If the tag matches, it is converted to resource and added to the array
@@ -132,11 +135,11 @@ void workTag(const tTag* t,void* pass) {
 	/* Get the order */
 	res.id.order=getOrder(t->order);
 	res.palette.order=getOrder(t->paletteorder);
-	
-	/* Copy id and palette id */	
+
+	/* Copy id and palette id */
 	keepIdAttributes(id,value,index);
 	keepIdAttributesElse(palette,palette,paletteindex,index);
-	
+
 	/* Copy number, title, desc and path */
 	keepIntAttribute(number,unsigned char);    /* Transforms the char* levelnumer/number attribute into a char value, if error, demo level is used */
 	if (t->flags) {
diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c
index 0de5e56..cd41ab6 100644
--- a/PR/src/lib/xml/tree.c
+++ b/PR/src/lib/xml/tree.c
@@ -42,6 +42,7 @@ tree.c: Princed Resources : Tree handling routines
 #include "memory.h"
 #include "list.h" /* list primitives needed by the Common Factor routines */
 #include "unknown.h" /* typedef tUnknownFile */
+#include "parse.h" /* getTagStructure */
 
 /***************************************************************\
 |                     XML generation defines                    |
@@ -56,23 +57,22 @@ tree.c: Princed Resources : Tree handling routines
 \***************************************************************/
 
 /*
-Affected attributes: only fully inheritable
-PRE: inheritances are shown in the tree, so if the parent has
- file="a", then the son comes with file="a" except that other
- file was explicity specified for the child. NULL is never shown
- after a non-NULL parent.
-
-POST: if the folder has n childs and there are n/2 equal attributes
- then those attributes comes to the parent.
- 
- if the folder has n childs and there are at most 10/n different attributes
- we can say that there is a ratio of 10 items per atribute or more.
- If that happens for at least one attribute, the attribute with the highest
- ratio will be partitioned that way:
-       if an attribute value is present in 3 or more items, all items goes
-       together under a new folder with this item set.
-
-*/
+ * Affected attributes: only fully inheritable
+ * PRE: inheritances are shown in the tree, so if the parent has
+ * file="a", then the son comes with file="a" except that other
+ * file was explicity specified for the child. NULL is never shown
+ * after a non-NULL parent.
+ *
+ * POST: if the folder has n childs and there are n/2 equal attributes
+ * then those attributes comes to the parent.
+ *
+ * if the folder has n childs and there are at most 10/n different attributes
+ * we can say that there is a ratio of 10 items per atribute or more.
+ * If that happens for at least one attribute, the attribute with the highest
+ * ratio will be partitioned that way:
+ *   if an attribute value is present in 3 or more items, all items goes
+ *   together under a new folder with this item set.
+ */
 
 typedef struct {
 	const char* attr;
@@ -92,7 +92,7 @@ int attrcmp(const void* x,const void* y) {
 void increase(const char* attr,tList* l,int *lcount) {
 	tAttrCount a;
 	tAttrCount* aux;
-	
+
 	if (!attr) return; /* if not attribute, do nothing */
 
 /*	printf("increase: %s\n",attr);*/
@@ -164,7 +164,7 @@ void commonFactor(tTag* parent) {
 		if (result) {
 			if (getAttr(parent)!=result) { /* it is possible, and is the most probable case, that the parent was already the best choice. In that case, do nothing */
 				freeAllocation(getAttr(parent));
-				getAttr(parent)=strallocandcopy(result); /* TODO: assign result but avoid releasing below */
+				getAttr(parent)=strallocandcopy(result); /* result is copied to avoid checking each time a string is released below */
 			}
 			for (child=parent->child;child;child=child->next) {
 				if (getAttr(child)&&!strcmp(getAttr(child),getAttr(parent))) {
@@ -248,9 +248,8 @@ void test() {
 
 void unknown_folder(const char* path, const char* file, int palette, const char* paletteindex, tTreeStatus* status) {
 	char number[10];
-	tTag* folder=malloc(sizeof(tTag));
+	tTag* folder=getTagStructure();
 
-	memset(folder,0,sizeof(tTag));
 	sprintf(number,"%d",palette);
 	folder->tag=strallocandcopy("folder");
 	folder->name=strallocandcopy("unknown");
@@ -270,9 +269,8 @@ void unknown_folder(const char* path, const char* file, int palette, const char*
 
 void unknown_item(int value,const char* index,const char* path,const char* type,unsigned long int flags,const char* typedesc,int count, tTreeStatus* status) {
 	char aux[100];
-	tTag* item=malloc(sizeof(tTag));
+	tTag* item=getTagStructure();
 
-	memset(item,0,sizeof(tTag));
 	sprintf(aux,"%d",value);
 	item->tag=strallocandcopy("item");
 	item->value=strallocandcopy(aux);
@@ -305,22 +303,22 @@ void generateXML(int n,/*const*/ tTag* t,FILE* outputStream) {
 	if (t!=NULL) {
 		fprintf(outputStream,"<%s",t->tag);
 
-#define FillAttr(a,b) if (a) fprintf(outputStream," %s=\"%s\"",b,a)
-
-	if (t->child) FillAttr(t->desc,"name");
-	FillAttr(t->path,"path");
-	FillAttr(t->file,"file");
-	FillAttr(t->type,"type");
-	FillAttr(t->desc,"desc");
-	FillAttr(t->palette,"palette");
-	FillAttr(t->value,"value");
-	FillAttr(t->index,"index");
-	FillAttr(t->order,"order");
-	FillAttr(t->paletteindex,"paletteindex");
-	FillAttr(t->paletteorder,"paletteorder");
-	FillAttr(t->version,"version");
-	FillAttr(t->number,"number");
-	FillAttr(t->flags,"flags");
+#define FillAttr2(a,b) if (a) fprintf(outputStream," %s=\"%s\"",b,a)
+
+	if (t->child) FillAttr2(t->desc,"name");
+	FillAttr2(t->path,"path");
+	FillAttr2(t->file,"file");
+	FillAttr2(t->type,"type");
+	FillAttr2(t->desc,"desc");
+	FillAttr2(t->palette,"palette");
+	FillAttr2(t->value,"value");
+	FillAttr2(t->index,"index");
+	FillAttr2(t->order,"order");
+	FillAttr2(t->paletteindex,"paletteindex");
+	FillAttr2(t->paletteorder,"paletteorder");
+	FillAttr2(t->version,"version");
+	FillAttr2(t->number,"number");
+	FillAttr2(t->flags,"flags");
 
 #undef FillAttr
 
@@ -388,21 +386,21 @@ void unknown_deletetreefile(const char* file, tTag* tree) {
 |                  Inheritance fixing routines                  |
 \***************************************************************/
 
-#define TotalInheritance(a) if (parent->a&&child->a&&equalsIgnoreCase(parent->a,child->a)) {freeAllocation(child->a);child->a=NULL;}
+#define TotalInheritance2(a) if (parent->a&&child->a&&equalsIgnoreCase(parent->a,child->a)) {freeAllocation(child->a);child->a=NULL;}
 
 void rec_tree_fix(tTag* parent,tTag* child) {
 	if (child->next) rec_tree_fix(parent,child->next);
 	if (child->child) rec_tree_fix(child,child->child);
 
 	if (parent) {
-		TotalInheritance(palette);
-		TotalInheritance(paletteindex);
-		TotalInheritance(paletteorder);
-		TotalInheritance(type);
-		TotalInheritance(file);
-		TotalInheritance(index);
-		TotalInheritance(order);
-		TotalInheritance(flags);
+		TotalInheritance2(palette);
+		TotalInheritance2(paletteindex);
+		TotalInheritance2(paletteorder);
+		TotalInheritance2(type);
+		TotalInheritance2(file);
+		TotalInheritance2(index);
+		TotalInheritance2(order);
+		TotalInheritance2(flags);
 
 		/* partial */
 		if ((parent->path!=NULL)&&(child->path!=NULL)) {
diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c
index 2d968b2..0e53cc9 100644
--- a/PR/src/lib/xml/unknown.c
+++ b/PR/src/lib/xml/unknown.c
@@ -45,6 +45,7 @@ unknown.c: Princed Resources : Unknown resources handler
 #include "memory.h"
 #include "stringformat.h"
 #include "translate.h"
+#include "parse.h" /* getTagStructure */
 
 /***************************************************************\
 |                     Unknown.xml primitives                    |
@@ -57,19 +58,19 @@ unknown.c: Princed Resources : Unknown resources handler
 #define XML_ATTRV_VERSION     "build-1"
 
 char* getVersion(const char* oldVersion) {
-      char* newVersion;
-      int l,i;
-
-      if (!oldVersion||!oldVersion[0]) return strallocandcopy(XML_ATTRV_VERSION);
-      l=strlen(oldVersion);
-      newVersion=malloc(l+5); /* l+2 is enough */
-      for (i=0;i<l&&isNumber(oldVersion[l-i-1]);i++);
-
-      if (l!=i) strncpy(newVersion,oldVersion,l-i);
-      if (i)    sprintf(newVersion+(l-i),"%d",atoi(oldVersion+(l-i))+1);
-      else newVersion[l]=0;
-      
-      return newVersion;
+	char* newVersion;
+	int l,i;
+
+	if (!oldVersion||!oldVersion[0]) return strallocandcopy(XML_ATTRV_VERSION);
+	l=strlen(oldVersion);
+	newVersion=malloc(l+5); /* l+2 is enough */
+	for (i=0;i<l&&isNumber(oldVersion[l-i-1]);i++);
+
+	if (l!=i) strncpy(newVersion,oldVersion,l-i);
+	if (i)    sprintf(newVersion+(l-i),"%d",atoi(oldVersion+(l-i))+1);
+	else newVersion[l]=0;
+
+	return newVersion;
 }
 
 tUnknownFile unknownFile;
@@ -97,15 +98,14 @@ int unknownLogStart (const char* file,int optionflag, const char* backupExtensio
 		unknownFile.status.folderCursor=NULL;
 		unknownFile.tree=parseXmlFile(file,&error);
 		if (error) {
-			unknownFile.tree=malloc(sizeof(tTag));
-			memset(unknownFile.tree,0,sizeof(tTag));
+			unknownFile.tree=getTagStructure();
 			unknownFile.tree->version=strallocandcopy(XML_ATTRV_VERSION);
 			unknownFile.tree->tag=strallocandcopy(XML_TAG_RESOURCES);
 		} else {
-            char* version=getVersion(unknownFile.tree->version);
-            freeAllocation(unknownFile.tree->version);
-            unknownFile.tree->version=version;
-        }
+			char* version=getVersion(unknownFile.tree->version);
+			freeAllocation(unknownFile.tree->version);
+			unknownFile.tree->version=version;
+		}
 	}
 
 	/* Open the file */
@@ -162,7 +162,8 @@ int unknownLogAppend(const char* vFiledat,tResourceId id,const char* ext,tResour
 	if (!unknownFile.currentDat) { /* this is the beginning of the file */
 		unknown_folder(vFiledatWithPath,vFiledat,pal.value,translateInt2Ext(toLower(pal.index)),&unknownFile.status);
 		unknownFile.currentDat=strallocandcopy(vFiledat);
-		/* TODO: move here the read-parsing-loading and write-opening */
+		/* it could be moved here the read-parsing-loading and write-opening,
+		 * but it is necessary to know the parsing status before the extractions are started */
 		unknown_deletetreefile(vFiledat,unknownFile.tree);
 	} else if (!equalsIgnoreCase(unknownFile.currentDat,vFiledat)) {
 		int i;
@@ -193,7 +194,7 @@ void getFileName(char* vFileext,const char* vDirExt,const tResource* r,const cha
 
 		/* set filename */
 		if (!format) format=RES_XML_UNKNOWN_FILES;
-		filename=parseformat(format,r->id.value,r->id.index,getExtDesc(pos),extarray[pos],unknownFile.typeCount[pos],r->id.order,r->desc);
+		filename=parseformat(format,r->id.value,r->id.index,getExtDesc(pos),extarray[pos],unknownFile.typeCount[pos],r->id.order,r->desc,r->name);
 
 		sprintf(vFileext,"%s/"RES_XML_UNKNOWN_PATH"/%s/%s",vDirExt,vDatFileName,filename);
 		unknownLogAppend(vDatFileName,r->id,extarray[pos],r->type,vDirExt,r->palette,vFiledat,optionflag,unknownFile.typeCount[pos],r->flags,filename);