WIP: [BUG] parsing without order constraint

This commit is contained in:
Adrien Bourmault 2021-08-24 01:39:00 +02:00
parent 991b2ec549
commit d6538985b8
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
4 changed files with 30 additions and 24 deletions

View File

@ -73,8 +73,8 @@
</transitions>
<!-- Non depth-specific tags -->
<!-- Non context-specific tags -->
<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>

View File

@ -174,6 +174,7 @@ struct {
struct ModelField_t {
char id[25];
char *value;
size_t valueSize;
struct ModelField_t *son;
struct ModelField_t *next;
} typedef ModelField_t;

View File

@ -31,7 +31,7 @@
static xmlDocPtr currentDocument = NULL;
static xmlNodePtr currentDocumentRoot = NULL;
void openCurrentDocument(const char *filename)
static inline void openCurrentDocument(const char *filename)
{
currentDocument = xmlParseFile(filename);
@ -53,28 +53,29 @@ void openCurrentDocument(const char *filename)
}
}
void closeCurrentDocument(void)
static inline void closeCurrentDocument(void)
{
xmlFreeDoc(currentDocument);
currentDocumentRoot = NULL;
currentDocument = NULL;
}
static void resetDocumentRoot(void)
static inline void resetDocumentRoot(void)
{
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 res = 0;
xmlNodePtr cur = currentDocumentRoot;
//printLog("Asked for %s\n", tagName);
printLog("Asked for %s\n", tagName);
while (cur != NULL) {
printLog("Got %s\n", cur->name);
if ((!xmlStrcmp(cur->name, (const xmlChar *)tagName))) {
curString = (char*)xmlNodeListGetString(currentDocument,
cur->xmlChildrenNode, 1);
@ -90,12 +91,12 @@ int parseTag(const char* tagName, char *destination, char destSize)
return res;
}
xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
static inline xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
{
xmlNodePtr cur = curRoot;
xmlNodePtr recur;
//printLog("Asked for %s\n", tagName);
printLog("Asked for %s\n", tagName);
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)tagName))){
@ -114,26 +115,25 @@ xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
return NULL;
}
int parseTree(ModelField_t *tree)
static inline int parseTree(ModelField_t *tree)
{
ModelField_t *curTree;
char tempString[50];
curTree = tree;
if ((findRoot(curTree->id, currentDocumentRoot)) == NULL)
return EBADF;
while (curTree) {
//printLog("Asked for %s\n", curTree->id);
if ((findRoot(curTree->id, currentDocumentRoot)) == NULL)
printLog("Asked for %s\n", curTree->id);
if ((parseTag(curTree->id, curTree->value, curTree->valueSize) == 0))
return EBADF;
bzero(tempString, sizeof(tempString));
if ((parseTag(curTree->id, tempString, sizeof(tempString)) == 0
&& curTree->value))
return EBADF;
if (!(tempString[0] == '\0')) {
printLog("Field %s: %s", curTree->id, tempString);
}
if (curTree->value[0])
if (!(curTree->value[0] == '\0')) {
printLog("Field %s: %s", curTree->id, curTree->value);
}
if (curTree->son)
parseTree(curTree->son);

View File

@ -275,26 +275,31 @@ static int ModelParseFile(Model_t *model)
strcpy(identityField.id, "identity");
identityField.value = NULL;
identityField.son = &nameField;
identityField.valueSize = 0;
identityField.son = &authorField;
identityField.next = NULL;
strcpy(nameField.id, "name");
nameField.value = model->name;
nameField.valueSize = 255;
nameField.son = NULL;
nameField.next = &authorField;
nameField.next = &dateField;
strcpy(authorField.id, "author");
authorField.value = NULL;
authorField.valueSize = 25;
authorField.son = NULL;
authorField.next = &dateField;
authorField.next = &nameField;
strcpy(dateField.id, "date");
dateField.value = NULL;
dateField.valueSize = 12;
dateField.son = NULL;
dateField.next = &versionField;
strcpy(versionField.id, "version");
versionField.value = NULL;
versionField.valueSize = 15;
versionField.son = NULL;
versionField.next = NULL;