WIP: [BUG] parsing without order constraint
This commit is contained in:
parent
991b2ec549
commit
d6538985b8
|
@ -73,8 +73,8 @@
|
||||||
|
|
||||||
</transitions>
|
</transitions>
|
||||||
|
|
||||||
<!-- Non depth-specific tags -->
|
<!-- Non context-specific tags -->
|
||||||
<ref id="" date="">https://www.a-lec.org</ref>
|
<ref id="" date="">https://www.a-lec.org</ref>
|
||||||
<comment id="" date="" author="" lang="">Comment</comment>
|
<quote id="" date="" author="" lang="">Comment</quote>
|
||||||
|
|
||||||
</gem-graph-model>
|
</gem-graph-model>
|
||||||
|
|
|
@ -174,6 +174,7 @@ struct {
|
||||||
struct ModelField_t {
|
struct ModelField_t {
|
||||||
char id[25];
|
char id[25];
|
||||||
char *value;
|
char *value;
|
||||||
|
size_t valueSize;
|
||||||
struct ModelField_t *son;
|
struct ModelField_t *son;
|
||||||
struct ModelField_t *next;
|
struct ModelField_t *next;
|
||||||
} typedef ModelField_t;
|
} typedef ModelField_t;
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
static xmlDocPtr currentDocument = NULL;
|
static xmlDocPtr currentDocument = NULL;
|
||||||
static xmlNodePtr currentDocumentRoot = NULL;
|
static xmlNodePtr currentDocumentRoot = NULL;
|
||||||
|
|
||||||
void openCurrentDocument(const char *filename)
|
static inline void openCurrentDocument(const char *filename)
|
||||||
{
|
{
|
||||||
currentDocument = xmlParseFile(filename);
|
currentDocument = xmlParseFile(filename);
|
||||||
|
|
||||||
|
@ -53,28 +53,29 @@ void openCurrentDocument(const char *filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeCurrentDocument(void)
|
static inline void closeCurrentDocument(void)
|
||||||
{
|
{
|
||||||
xmlFreeDoc(currentDocument);
|
xmlFreeDoc(currentDocument);
|
||||||
currentDocumentRoot = NULL;
|
currentDocumentRoot = NULL;
|
||||||
currentDocument = NULL;
|
currentDocument = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resetDocumentRoot(void)
|
static inline void resetDocumentRoot(void)
|
||||||
{
|
{
|
||||||
currentDocumentRoot = xmlDocGetRootElement(currentDocument);
|
currentDocumentRoot = xmlDocGetRootElement(currentDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
int parseTag(const char* tagName, char *destination, char destSize)
|
static inline int parseTag(const char* tagName, char *destination, char destSize)
|
||||||
{
|
{
|
||||||
char *curString;
|
char *curString;
|
||||||
char res = 0;
|
char res = 0;
|
||||||
|
|
||||||
xmlNodePtr cur = currentDocumentRoot;
|
xmlNodePtr cur = currentDocumentRoot;
|
||||||
|
|
||||||
//printLog("Asked for %s\n", tagName);
|
printLog("Asked for %s\n", tagName);
|
||||||
|
|
||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
|
printLog("Got %s\n", cur->name);
|
||||||
if ((!xmlStrcmp(cur->name, (const xmlChar *)tagName))) {
|
if ((!xmlStrcmp(cur->name, (const xmlChar *)tagName))) {
|
||||||
curString = (char*)xmlNodeListGetString(currentDocument,
|
curString = (char*)xmlNodeListGetString(currentDocument,
|
||||||
cur->xmlChildrenNode, 1);
|
cur->xmlChildrenNode, 1);
|
||||||
|
@ -90,12 +91,12 @@ int parseTag(const char* tagName, char *destination, char destSize)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
|
static inline xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
|
||||||
{
|
{
|
||||||
xmlNodePtr cur = curRoot;
|
xmlNodePtr cur = curRoot;
|
||||||
xmlNodePtr recur;
|
xmlNodePtr recur;
|
||||||
|
|
||||||
//printLog("Asked for %s\n", tagName);
|
printLog("Asked for %s\n", tagName);
|
||||||
|
|
||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
if ((!xmlStrcmp(cur->name, (const xmlChar *)tagName))){
|
if ((!xmlStrcmp(cur->name, (const xmlChar *)tagName))){
|
||||||
|
@ -114,26 +115,25 @@ xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parseTree(ModelField_t *tree)
|
static inline int parseTree(ModelField_t *tree)
|
||||||
{
|
{
|
||||||
ModelField_t *curTree;
|
ModelField_t *curTree;
|
||||||
char tempString[50];
|
|
||||||
|
|
||||||
curTree = tree;
|
curTree = tree;
|
||||||
|
|
||||||
|
if ((findRoot(curTree->id, currentDocumentRoot)) == NULL)
|
||||||
|
return EBADF;
|
||||||
|
|
||||||
while (curTree) {
|
while (curTree) {
|
||||||
//printLog("Asked for %s\n", curTree->id);
|
printLog("Asked for %s\n", curTree->id);
|
||||||
if ((findRoot(curTree->id, currentDocumentRoot)) == NULL)
|
|
||||||
|
if ((parseTag(curTree->id, curTree->value, curTree->valueSize) == 0))
|
||||||
return EBADF;
|
return EBADF;
|
||||||
|
|
||||||
bzero(tempString, sizeof(tempString));
|
if (curTree->value[0])
|
||||||
if ((parseTag(curTree->id, tempString, sizeof(tempString)) == 0
|
if (!(curTree->value[0] == '\0')) {
|
||||||
&& curTree->value))
|
printLog("Field %s: %s", curTree->id, curTree->value);
|
||||||
return EBADF;
|
}
|
||||||
|
|
||||||
if (!(tempString[0] == '\0')) {
|
|
||||||
printLog("Field %s: %s", curTree->id, tempString);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curTree->son)
|
if (curTree->son)
|
||||||
parseTree(curTree->son);
|
parseTree(curTree->son);
|
||||||
|
|
11
src/model.c
11
src/model.c
|
@ -275,26 +275,31 @@ static int ModelParseFile(Model_t *model)
|
||||||
|
|
||||||
strcpy(identityField.id, "identity");
|
strcpy(identityField.id, "identity");
|
||||||
identityField.value = NULL;
|
identityField.value = NULL;
|
||||||
identityField.son = &nameField;
|
identityField.valueSize = 0;
|
||||||
|
identityField.son = &authorField;
|
||||||
identityField.next = NULL;
|
identityField.next = NULL;
|
||||||
|
|
||||||
strcpy(nameField.id, "name");
|
strcpy(nameField.id, "name");
|
||||||
nameField.value = model->name;
|
nameField.value = model->name;
|
||||||
|
nameField.valueSize = 255;
|
||||||
nameField.son = NULL;
|
nameField.son = NULL;
|
||||||
nameField.next = &authorField;
|
nameField.next = &dateField;
|
||||||
|
|
||||||
strcpy(authorField.id, "author");
|
strcpy(authorField.id, "author");
|
||||||
authorField.value = NULL;
|
authorField.value = NULL;
|
||||||
|
authorField.valueSize = 25;
|
||||||
authorField.son = NULL;
|
authorField.son = NULL;
|
||||||
authorField.next = &dateField;
|
authorField.next = &nameField;
|
||||||
|
|
||||||
strcpy(dateField.id, "date");
|
strcpy(dateField.id, "date");
|
||||||
dateField.value = NULL;
|
dateField.value = NULL;
|
||||||
|
dateField.valueSize = 12;
|
||||||
dateField.son = NULL;
|
dateField.son = NULL;
|
||||||
dateField.next = &versionField;
|
dateField.next = &versionField;
|
||||||
|
|
||||||
strcpy(versionField.id, "version");
|
strcpy(versionField.id, "version");
|
||||||
versionField.value = NULL;
|
versionField.value = NULL;
|
||||||
|
versionField.valueSize = 15;
|
||||||
versionField.son = NULL;
|
versionField.son = NULL;
|
||||||
versionField.next = NULL;
|
versionField.next = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue