WIP: simple opening of XML file
This commit is contained in:
parent
52e6c59d76
commit
d50ce9afe1
|
@ -1,25 +1,32 @@
|
||||||
#include <stdbool.h>
|
/*
|
||||||
#include <libxml/parser.h>
|
* Gem-graph OpenGL experiments
|
||||||
// #define LIBXML_TEST_VERSION
|
*
|
||||||
// xmlCheckVersion(20912)
|
* Desc: Model parsing header
|
||||||
|
*
|
||||||
bool model_init(char *docname);
|
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
|
||||||
bool model_shutdown(char *docname);
|
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
|
||||||
char model_get_dim(xmlChar *reste);
|
*
|
||||||
char model_get_dim_X(xmlChar *path);
|
* This file is part of Gem-graph.
|
||||||
char model_get_dim_Y(xmlChar *path);
|
*
|
||||||
char model_get_dim_Z(xmlChar *path);
|
* This program is free software: you can redistribute it and/or modify
|
||||||
char model_get_dim_value(xmlChar *path, xmlChar *axis);
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
char model_get_cond (xmlChar *path, xmlChar *node_id);
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
char model_get_trans (xmlChar *path, xmlChar *node_id);
|
* (at your option) any later version.
|
||||||
char model_get_cond_tree (xmlChar *path);
|
*
|
||||||
char model_get_multiplicity (xmlChar *path);
|
* This program is distributed in the hope that it will be useful,
|
||||||
char model_get_objects_list(xmlChar *path);
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
char model_get_states_list(xmlChar *path);
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
long model_get_state_arrows_count(xmlChar *path, long n);
|
* GNU Affero General Public License for more details.
|
||||||
int model_get_state(xmlChar *path, xmlChar *state_id);
|
*
|
||||||
char model_get_conditions_list(xmlChar *path);
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
char model_get_transitions_list(xmlChar *path);
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "../include/base.h"
|
||||||
|
|
||||||
|
bool model_init(const char *content, size_t length, const char *basename);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Gem-graph client
|
||||||
|
*
|
||||||
|
* Desc: Model parsing functions
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
|
||||||
|
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
|
||||||
|
*
|
||||||
|
* This file is part of Gem-graph.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -7,49 +31,47 @@
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/xmlreader.h> // http://xmlsoft.org/examples/#parse1.c
|
#include <libxml/xmlreader.h> // http://xmlsoft.org/examples/#parse1.c
|
||||||
#define VRB0 0
|
|
||||||
#define VRB1 0
|
|
||||||
#define VRB2 0
|
|
||||||
#define VRB3 0
|
|
||||||
#define VRB4 1
|
|
||||||
|
|
||||||
// https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/general.html
|
// https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/general.html
|
||||||
// make && bin/learning ./data/dimers\ random\ walk.xml
|
|
||||||
|
|
||||||
/****** WARNING ! VARIABLES GLOBALES !! ÇA PAS BON !!! > TODO < **********/
|
#include "../../include/base.h"
|
||||||
|
|
||||||
xmlDocPtr doc; // ! WARNING ! I TAKE FOR GRANTED THAT xmlDocPtr doc != NULL
|
|
||||||
xmlHashTable *my_table;
|
|
||||||
|
|
||||||
/******************************************************************************/
|
bool model_init(char *content, size_t length, char *basename)
|
||||||
|
|
||||||
bool model_init(char *docname)
|
|
||||||
{
|
{
|
||||||
xmlNodePtr node;
|
/*
|
||||||
|
* this initialize the library and check potential ABI mismatches
|
||||||
|
* between the version it was compiled for and the actual shared
|
||||||
|
* library used.
|
||||||
|
*/
|
||||||
|
LIBXML_TEST_VERSION
|
||||||
|
|
||||||
doc = xmlParseFile(docname);
|
xmlDocPtr doc;
|
||||||
|
|
||||||
|
doc = xmlReadMemory(content, length, basename, NULL, 0);
|
||||||
|
|
||||||
if (doc == NULL ) {
|
if (doc == NULL ) {
|
||||||
fprintf(stderr,"Document not parsed successfully.\n");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = xmlDocGetRootElement(doc);
|
g_free(basename);
|
||||||
|
g_free(content);
|
||||||
|
return true;
|
||||||
|
|
||||||
if (node == NULL) {
|
/* node = xmlDocGetRootElement(doc); */
|
||||||
fprintf(stderr,"empty document\n");
|
|
||||||
xmlFreeDoc(doc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xmlStrcmp(node->name, (xmlChar *) "gem-graph-model")) {
|
/* if (node == NULL) { */
|
||||||
fprintf(stderr,"document of the wrong type, root node != gem-graph-model\n");
|
/* fprintf(stderr,"empty document\n"); */
|
||||||
xmlFreeDoc(doc);
|
/* xmlFreeDoc(doc); */
|
||||||
return false;
|
/* return false; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
my_table = xmlHashCreate(10);
|
/* if (xmlStrcmp(node->name, (xmlChar *) "gem-graph-model")) { */
|
||||||
printf("-------------------- model_init(%s) -----------------------\n", docname);
|
/* fprintf(stderr,"document of the wrong type, root node != gem-graph-model\n"); */
|
||||||
|
/* xmlFreeDoc(doc); */
|
||||||
|
/* return false; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* my_table = xmlHashCreate(10); */
|
||||||
|
|
||||||
/* xmlDocPtr my_tree = xmlReadIO, */
|
/* xmlDocPtr my_tree = xmlReadIO, */
|
||||||
/* xmlInputReadCallback ioread, */
|
/* xmlInputReadCallback ioread, */
|
||||||
|
@ -58,345 +80,345 @@ bool model_init(char *docname)
|
||||||
/* const char * URL, */
|
/* const char * URL, */
|
||||||
/* const char * encoding, */
|
/* const char * encoding, */
|
||||||
/* int options); */
|
/* int options); */
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
bool model_shutdown(char *docname){
|
/* bool model_shutdown(char *docname){ */
|
||||||
|
|
||||||
xmlFreeDoc(doc);
|
/* * Cleanup function for the XML library. */
|
||||||
|
/* */
|
||||||
|
/* xmlCleanupParser(); */
|
||||||
|
/* * this is to debug memory for regression tests */
|
||||||
|
/* */
|
||||||
|
/* xmlMemoryDump(); */
|
||||||
|
|
||||||
printf("-------------------- model_shutdown(%s) -------------------\n", docname);
|
/* return true; */
|
||||||
|
/* } */
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
static xmlNodePtr getNextChild(xmlNodePtr node, xmlChar *last){
|
/* static xmlNodePtr getNextChild(xmlNodePtr node, xmlChar *last){ */
|
||||||
while (node != NULL && xmlStrcmp(node->name, last)) {
|
/* while (node != NULL && xmlStrcmp(node->name, last)) { */
|
||||||
// printf(" <>--- line n°%lu <%s>\n", xmlGetLineNo(node), node->name);
|
/* // printf(" <>--- line n°%lu <%s>\n", xmlGetLineNo(node), node->name); */
|
||||||
node = node->next;
|
/* node = node->next; */
|
||||||
}
|
/* } */
|
||||||
return node;
|
/* return node; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
static xmlChar* splitStrAtSlash(xmlChar *toSplit){
|
/* static xmlChar* splitStrAtSlash(xmlChar *toSplit){ */
|
||||||
toSplit = (xmlChar *)xmlStrchr(toSplit, '/');
|
/* toSplit = (xmlChar *)xmlStrchr(toSplit, '/'); */
|
||||||
toSplit = xmlStrsub (toSplit, 1, xmlStrlen(toSplit));
|
/* toSplit = xmlStrsub (toSplit, 1, xmlStrlen(toSplit)); */
|
||||||
return toSplit;
|
/* return toSplit; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
static xmlChar* getFirstTag(xmlChar *path){
|
/* static xmlChar* getFirstTag(xmlChar *path){ */
|
||||||
xmlChar *preop = path;
|
/* xmlChar *preop = path; */
|
||||||
path = (xmlChar *)xmlStrchr(path, '/');
|
/* path = (xmlChar *)xmlStrchr(path, '/'); */
|
||||||
path = xmlStrsub (path, 1, xmlStrlen(path));
|
/* path = xmlStrsub (path, 1, xmlStrlen(path)); */
|
||||||
/* printf("%s = %s + / + %s\n", preop,\ */
|
/* printf("%s = %s + / + %s\n", preop,\ */
|
||||||
/* xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1), path); */
|
/* xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1), path); */
|
||||||
return xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1);
|
/* return xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
static xmlChar* getLastTag(xmlChar *path){
|
/* static xmlChar* getLastTag(xmlChar *path){ */
|
||||||
while ((ulong)xmlStrchr (path, '/')) path = splitStrAtSlash((xmlChar *)path);
|
/* while ((ulong)xmlStrchr (path, '/')) path = splitStrAtSlash((xmlChar *)path); */
|
||||||
// printf("last tag in the path = <%s>\n", path);
|
/* // printf("last tag in the path = <%s>\n", path); */
|
||||||
return path; // which is no more the given path but only its last tag !
|
/* return path; // which is no more the given path but only its last tag ! */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
static xmlNodePtr model_get_node(xmlChar *path)
|
/* static xmlNodePtr model_get_node(xmlChar *path) */
|
||||||
{
|
/* { */
|
||||||
xmlNodePtr node;
|
/* xmlNodePtr node; */
|
||||||
|
|
||||||
// Lookup for node from path in hash table
|
/* // Lookup for node from path in hash table */
|
||||||
node = xmlHashLookup(my_table, path);
|
/* node = xmlHashLookup(my_table, path); */
|
||||||
|
|
||||||
// Found a node in hash table
|
/* // Found a node in hash table */
|
||||||
if(node){
|
/* if(node){ */
|
||||||
if (VRB0) printf("xmlHashLookup (my_table, path: <%s>, tag: <%s> @>%p)\n",
|
/* if (VRB0) printf("xmlHashLookup (my_table, path: <%s>, tag: <%s> @>%p)\n", */
|
||||||
path, node->name, node);
|
/* path, node->name, node); */
|
||||||
|
|
||||||
assert(node > (xmlNodePtr)2048);
|
/* assert(node > (xmlNodePtr)2048); */
|
||||||
|
|
||||||
return node;
|
/* return node; */
|
||||||
|
|
||||||
// no node found in hash table
|
/* // no node found in hash table */
|
||||||
} else {
|
/* } else { */
|
||||||
xmlChar *reste = path, *last = reste, *affich = reste;
|
/* xmlChar *reste = path, *last = reste, *affich = reste; */
|
||||||
last = getLastTag(last);
|
/* last = getLastTag(last); */
|
||||||
xmlNodePtr node = xmlDocGetRootElement(doc);
|
/* xmlNodePtr node = xmlDocGetRootElement(doc); */
|
||||||
|
|
||||||
if (VRB1) printf("line n° %lu : tag <%s> reste = %s\n",\
|
/* if (VRB1) printf("line n° %lu : tag <%s> reste = %s\n",\ */
|
||||||
xmlGetLineNo(node), (xmlChar *)node->name, (xmlChar *)affich);
|
/* xmlGetLineNo(node), (xmlChar *)node->name, (xmlChar *)affich); */
|
||||||
|
|
||||||
xmlChar *extrait;
|
/* xmlChar *extrait; */
|
||||||
|
|
||||||
while ((ulong)xmlStrchr (reste, '/')){
|
/* while ((ulong)xmlStrchr (reste, '/')){ */
|
||||||
extrait = getFirstTag(reste); //printf("extrait = %s\n", extrait);
|
/* extrait = getFirstTag(reste); //printf("extrait = %s\n", extrait); */
|
||||||
reste = splitStrAtSlash((xmlChar *)reste);//printf("reste = %s\n", reste);
|
/* reste = splitStrAtSlash((xmlChar *)reste);//printf("reste = %s\n", reste); */
|
||||||
node = node->xmlChildrenNode;
|
/* node = node->xmlChildrenNode; */
|
||||||
node = getNextChild(node, extrait);
|
/* node = getNextChild(node, extrait); */
|
||||||
|
|
||||||
if (VRB1) printf("line n°%lu : tag <%s> reste = %s\n",\
|
/* if (VRB1) printf("line n°%lu : tag <%s> reste = %s\n",\ */
|
||||||
xmlGetLineNo(node), (xmlChar *)extrait, (xmlChar *)reste);
|
/* xmlGetLineNo(node), (xmlChar *)extrait, (xmlChar *)reste); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if(node != NULL && xmlStrcmp(node->name, last)) {
|
/* if(node != NULL && xmlStrcmp(node->name, last)) { */
|
||||||
node = node->xmlChildrenNode;
|
/* node = node->xmlChildrenNode; */
|
||||||
|
|
||||||
while (node != NULL && xmlStrcmp(node->name, last)) {
|
/* while (node != NULL && xmlStrcmp(node->name, last)) { */
|
||||||
node = node->next;
|
/* node = node->next; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if (VRB1) printf("line n°%lu : tag <%s>\n",\
|
/* if (VRB1) printf("line n°%lu : tag <%s>\n",\ */
|
||||||
xmlGetLineNo(node), (xmlChar *)node->name);
|
/* xmlGetLineNo(node), (xmlChar *)node->name); */
|
||||||
|
|
||||||
xmlHashAddEntry (my_table, path, node);
|
/* xmlHashAddEntry (my_table, path, node); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if (VRB0) printf("VRB0 xmlHashAddEntry (my_table, path: <%s>, tag: <%s> @>%p)\n",\
|
/* if (VRB0) printf("VRB0 xmlHashAddEntry (my_table, path: <%s>, tag: <%s> @>%p)\n",\ */
|
||||||
path, node->name, node);
|
/* path, node->name, node); */
|
||||||
|
|
||||||
return node;
|
/* return node; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
return NULL; // ?
|
/* return NULL; // ? */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
static long model_get_node_attrib(xmlNodePtr node)
|
/* static long model_get_node_attrib(xmlNodePtr node) */
|
||||||
{
|
/* { */
|
||||||
long value = 0;
|
/* long value = 0; */
|
||||||
if (node && node->properties) {
|
/* if (node && node->properties) { */
|
||||||
xmlAttr* attribute = node->properties;
|
/* xmlAttr* attribute = node->properties; */
|
||||||
xmlChar* value_txt = NULL;
|
/* xmlChar* value_txt = NULL; */
|
||||||
char *ptr;
|
/* char *ptr; */
|
||||||
while(attribute && attribute->name && attribute->children)
|
/* while(attribute && attribute->name && attribute->children) */
|
||||||
{
|
/* { */
|
||||||
value_txt = xmlNodeListGetString(node->doc, attribute->children, 1);
|
/* value_txt = xmlNodeListGetString(node->doc, attribute->children, 1); */
|
||||||
value = strtol((char *)value_txt, &ptr, 10);
|
/* value = strtol((char *)value_txt, &ptr, 10); */
|
||||||
if (VRB3) printf ("model_get_node_attrib <%s> = %s = %ld\n",\
|
/* if (VRB3) printf ("model_get_node_attrib <%s> = %s = %ld\n",\ */
|
||||||
attribute->name, value_txt, value);
|
/* attribute->name, value_txt, value); */
|
||||||
attribute = attribute->next;
|
/* attribute = attribute->next; */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
return value;
|
/* return value; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
static long model_get_state_arrows_nb(xmlNodePtr node)
|
/* static long model_get_state_arrows_nb(xmlNodePtr node) */
|
||||||
{
|
/* { */
|
||||||
long arrows_nb= 0;
|
/* long arrows_nb= 0; */
|
||||||
if (VRB0) printf ("VRB0 model_get_state_arrows_nb <%s> start at line %ld\n",\
|
/* if (VRB0) printf ("VRB0 model_get_state_arrows_nb <%s> start at line %ld\n",\ */
|
||||||
node->name, xmlGetLineNo(node));
|
/* node->name, xmlGetLineNo(node)); */
|
||||||
while (node && node->next){
|
/* while (node && node->next){ */
|
||||||
if (VRB2) printf ("%s %ld >", (xmlChar *)node->name, arrows_nb);
|
/* if (VRB2) printf ("%s %ld >", (xmlChar *)node->name, arrows_nb); */
|
||||||
if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb;
|
/* if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb; */
|
||||||
if (VRB2) printf (" %ld ", arrows_nb);
|
/* if (VRB2) printf (" %ld ", arrows_nb); */
|
||||||
node = node->next;
|
/* node = node->next; */
|
||||||
}
|
/* } */
|
||||||
if (VRB2) printf ("\n");
|
/* if (VRB2) printf ("\n"); */
|
||||||
if (VRB0) printf ("VRB0 model_get_state_arrows_nb = %ld end at line %ld\n",\
|
/* if (VRB0) printf ("VRB0 model_get_state_arrows_nb = %ld end at line %ld\n",\ */
|
||||||
arrows_nb, xmlGetLineNo(node));
|
/* arrows_nb, xmlGetLineNo(node)); */
|
||||||
return arrows_nb;
|
/* return arrows_nb; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
char model_get_dim(xmlChar *path){
|
/* char model_get_dim(xmlChar *path){ */
|
||||||
|
|
||||||
xmlNodePtr node = model_get_node(path); if (VRB2) printf("@node = %p ", node);
|
/* xmlNodePtr node = model_get_node(path); if (VRB2) printf("@node = %p ", node); */
|
||||||
|
|
||||||
if (node && node->properties) {
|
/* if (node && node->properties) { */
|
||||||
xmlAttr* attribute = node->properties;
|
/* xmlAttr* attribute = node->properties; */
|
||||||
while(attribute && attribute->name && attribute->children)
|
/* while(attribute && attribute->name && attribute->children) */
|
||||||
{
|
/* { */
|
||||||
xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1);
|
/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */
|
||||||
// printf ("model_get_dim %s = %s\n", attribute->name, value);
|
/* // printf ("model_get_dim %s = %s\n", attribute->name, value); */
|
||||||
xmlFree(value);
|
/* xmlFree(value); */
|
||||||
attribute = attribute->next;
|
/* attribute = attribute->next; */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if (xmlHasProp (node, (xmlChar *) "z")) return 3;
|
/* if (xmlHasProp (node, (xmlChar *) "z")) return 3; */
|
||||||
if (xmlHasProp (node, (xmlChar *) "y")) return 2;
|
/* if (xmlHasProp (node, (xmlChar *) "y")) return 2; */
|
||||||
if (xmlHasProp (node, (xmlChar *) "x")) return 1;
|
/* if (xmlHasProp (node, (xmlChar *) "x")) return 1; */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_dim_value(xmlChar *path, xmlChar *axis){
|
/* int model_get_dim_value(xmlChar *path, xmlChar *axis){ */
|
||||||
xmlNodePtr node = model_get_node(path);
|
/* xmlNodePtr node = model_get_node(path); */
|
||||||
//xmlNodePtr node= xmlTextReadernoderentNode(reader);
|
/* //xmlNodePtr node= xmlTextReadernoderentNode(reader); */
|
||||||
if (node && node->properties) {
|
/* if (node && node->properties) { */
|
||||||
xmlAttr* attribute = node->properties;
|
/* xmlAttr* attribute = node->properties; */
|
||||||
while(attribute && attribute->name && attribute->children)
|
/* while(attribute && attribute->name && attribute->children) */
|
||||||
{
|
/* { */
|
||||||
xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1);
|
/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */
|
||||||
if (!xmlStrcmp(attribute->name, axis))
|
/* if (!xmlStrcmp(attribute->name, axis)) */
|
||||||
return (int)strtol((char *)value, NULL, 0);
|
/* return (int)strtol((char *)value, NULL, 0); */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char model_get_cond_tree (xmlChar *path){
|
/* char model_get_cond_tree (xmlChar *path){ */
|
||||||
xmlNodePtr node = model_get_node(path);
|
/* xmlNodePtr node = model_get_node(path); */
|
||||||
node = node->xmlChildrenNode;
|
/* node = node->xmlChildrenNode; */
|
||||||
node = getNextChild(node, (xmlChar *)"condition");
|
/* node = getNextChild(node, (xmlChar *)"condition"); */
|
||||||
node = xmlCopyNodeList (node->xmlChildrenNode);
|
/* node = xmlCopyNodeList (node->xmlChildrenNode); */
|
||||||
printf("model_get_cond_tree(\"%s\") > line n°%ld\n", path, xmlGetLineNo(node));
|
/* printf("model_get_cond_tree(\"%s\") > line n°%ld\n", path, xmlGetLineNo(node)); */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_cond (xmlChar *path, xmlChar *node_id){
|
/* int model_get_cond (xmlChar *path, xmlChar *node_id){ */
|
||||||
xmlNodePtr node = model_get_node(path);
|
/* xmlNodePtr node = model_get_node(path); */
|
||||||
printf("model_get_cond(...) {...node->name = %s...}\n", node->name);
|
/* printf("model_get_cond(...) {...node->name = %s...}\n", node->name); */
|
||||||
node = getNextChild(node->next, (xmlChar *)"condition");
|
/* node = getNextChild(node->next, (xmlChar *)"condition"); */
|
||||||
node = getNextChild(node->next, (xmlChar *)"condition");
|
/* node = getNextChild(node->next, (xmlChar *)"condition"); */
|
||||||
if (xmlHasProp (node, (xmlChar *) "site")) {
|
/* if (xmlHasProp (node, (xmlChar *) "site")) { */
|
||||||
printf(" node %s has attribute site\n", node->name);
|
/* printf(" node %s has attribute site\n", node->name); */
|
||||||
}
|
/* } */
|
||||||
if (xmlHasProp (node, (xmlChar *) "node_id")) {
|
/* if (xmlHasProp (node, (xmlChar *) "node_id")) { */
|
||||||
printf(" node %s has attribute %s with value %hhn %s %s\n",\
|
/* printf(" node %s has attribute %s with value %hhn %s %s\n",\ */
|
||||||
node->name,\
|
/* node->name,\ */
|
||||||
xmlHasProp (node, (xmlChar *) "node_id")->name,\
|
/* xmlHasProp (node, (xmlChar *) "node_id")->name,\ */
|
||||||
xmlGetProp (node, (xmlChar *) "node_id"),\
|
/* xmlGetProp (node, (xmlChar *) "node_id"),\ */
|
||||||
(xmlChar *)"?! xmlGetProp is deprecated !",\
|
/* (xmlChar *)"?! xmlGetProp is deprecated !",\ */
|
||||||
(xmlChar *)"");
|
/* (xmlChar *)""); */
|
||||||
}
|
/* } */
|
||||||
node = getNextChild(node->next, (xmlChar *)"condition");
|
/* node = getNextChild(node->next, (xmlChar *)"condition"); */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
long model_get_dim_X (xmlChar *path){
|
/* long model_get_dim_X (xmlChar *path){ */
|
||||||
xmlNodePtr node = xmlHashLookup(my_table, (xmlChar *)"get_X");
|
/* xmlNodePtr node = xmlHashLookup(my_table, (xmlChar *)"get_X"); */
|
||||||
if(node){
|
/* if(node){ */
|
||||||
//if (VRB1){
|
/* //if (VRB1){ */
|
||||||
printf("get_X > tag <%s> found in hash table\n",\
|
/* printf("get_X > tag <%s> found in hash table\n",\ */
|
||||||
node->name); // node->name = "x"
|
/* node->name); // node->name = "x" */
|
||||||
//}
|
/* //} */
|
||||||
return (long)xmlHashLookup(my_table, (xmlChar *)"get_X"); //TODO
|
/* return (long)xmlHashLookup(my_table, (xmlChar *)"get_X"); //TODO */
|
||||||
|
|
||||||
}else{
|
/* }else{ */
|
||||||
xmlNodePtr node = model_get_node(path); // node = dimension
|
/* xmlNodePtr node = model_get_node(path); // node = dimension */
|
||||||
if (node && node->properties) {
|
/* if (node && node->properties) { */
|
||||||
xmlAttr* attribute = node->properties;
|
/* xmlAttr* attribute = node->properties; */
|
||||||
while(attribute && attribute->name && attribute->children)
|
/* while(attribute && attribute->name && attribute->children) */
|
||||||
{
|
/* { */
|
||||||
xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1);
|
/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */
|
||||||
if (!xmlStrcmp(attribute->name, (xmlChar *)"x")) {
|
/* if (!xmlStrcmp(attribute->name, (xmlChar *)"x")) { */
|
||||||
xmlHashAddEntry (my_table, (xmlChar *)"get_X", attribute);
|
/* xmlHashAddEntry (my_table, (xmlChar *)"get_X", attribute); */
|
||||||
return (int)strtol((char *)value, NULL, 0);
|
/* return (int)strtol((char *)value, NULL, 0); */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_dim_Y (xmlChar *path){
|
/* int model_get_dim_Y (xmlChar *path){ */
|
||||||
printf("model_get_dim_Y(%s)\n", path);
|
/* printf("model_get_dim_Y(%s)\n", path); */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_dim_Z (xmlChar *path){
|
/* int model_get_dim_Z (xmlChar *path){ */
|
||||||
printf("model_get_dim_Z(%s)\n", path);
|
/* printf("model_get_dim_Z(%s)\n", path); */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_multiplicity (xmlChar *path){
|
/* int model_get_multiplicity (xmlChar *path){ */
|
||||||
xmlNodePtr node = model_get_node(path);
|
/* xmlNodePtr node = model_get_node(path); */
|
||||||
if(node) return (int)strtol((char *)xmlNodeGetContent(node), NULL, 0);
|
/* if(node) return (int)strtol((char *)xmlNodeGetContent(node), NULL, 0); */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_objects_list(xmlChar *path){
|
/* int model_get_objects_list(xmlChar *path){ */
|
||||||
return xmlGetLineNo(model_get_node(path));
|
/* return xmlGetLineNo(model_get_node(path)); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
xmlChar *model_get_states_list(xmlChar *path){
|
/* xmlChar *model_get_states_list(xmlChar *path){ */
|
||||||
xmlNodePtr node = model_get_node(path);
|
/* xmlNodePtr node = model_get_node(path); */
|
||||||
return (xmlChar *)xmlNodeGetContent(node);
|
/* return (xmlChar *)xmlNodeGetContent(node); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
long model_get_state_arrows_count(xmlChar *path, long n){
|
/* long model_get_state_arrows_count(xmlChar *path, long n){ */
|
||||||
// Ici, je sais que c'est le 'PREMIER' état qui est demandé car n == 0
|
/* // Ici, je sais que c'est le 'PREMIER' état qui est demandé car n == 0 */
|
||||||
char compl[] = "/state/arrow";
|
/* char compl[] = "/state/arrow"; */
|
||||||
char *new_p = calloc(1, (sizeof(compl) + strlen((char *)path)) * sizeof(char));
|
/* char *new_p = calloc(1, (sizeof(compl) + strlen((char *)path)) * sizeof(char)); */
|
||||||
strcat(new_p, (char *)path);
|
/* strcat(new_p, (char *)path); */
|
||||||
strcat(new_p + strlen((char *)path), compl); // printf("%s\n", new_p);
|
/* strcat(new_p + strlen((char *)path), compl); // printf("%s\n", new_p); */
|
||||||
|
|
||||||
xmlNodePtr node = model_get_node((xmlChar *)new_p);
|
/* xmlNodePtr node = model_get_node((xmlChar *)new_p); */
|
||||||
long size = model_get_state_arrows_nb(node);
|
/* long size = model_get_state_arrows_nb(node); */
|
||||||
int dim = model_get_dim((xmlChar *)"parameters/space-param/dimension");
|
/* int dim = model_get_dim((xmlChar *)"parameters/space-param/dimension"); */
|
||||||
if (VRB0) printf("VRB0 model_get_saved_state(size = %ld)->%p<-attrib dim = %d size = %ld\n",\
|
/* if (VRB0) printf("VRB0 model_get_saved_state(size = %ld)->%p<-attrib dim = %d size = %ld\n",\ */
|
||||||
size, (xmlNodePtr)model_get_node_attrib(node), dim, size * ( 2 + dim ) * sizeof(int));
|
/* size, (xmlNodePtr)model_get_node_attrib(node), dim, size * ( 2 + dim ) * sizeof(int)); */
|
||||||
|
|
||||||
int c = 0;
|
/* int c = 0; */
|
||||||
int *t = calloc(1, (size * ( 2 + dim ) * sizeof(int)));
|
/* int *t = calloc(1, (size * ( 2 + dim ) * sizeof(int))); */
|
||||||
// int rk = 0;
|
/* // int rk = 0; */
|
||||||
// int *s = calloc(1, ( 2 + dim ) * sizeof(int));
|
/* // int *s = calloc(1, ( 2 + dim ) * sizeof(int)); */
|
||||||
|
|
||||||
if(1)
|
/* if(1) */
|
||||||
{
|
/* { */
|
||||||
long arrows_nb= 0;
|
/* long arrows_nb= 0; */
|
||||||
if (VRB4) printf ("VRB4 model_get_state_arrows_nb <%s> start at line %ld\n",\
|
/* if (VRB4) printf ("VRB4 model_get_state_arrows_nb <%s> start at line %ld\n",\ */
|
||||||
node->name, xmlGetLineNo(node));
|
/* node->name, xmlGetLineNo(node)); */
|
||||||
while (node && node->next){
|
/* while (node && node->next){ */
|
||||||
if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb;
|
/* if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb; */
|
||||||
if (VRB4 && !xmlStrcmp(node->name, (xmlChar *)"arrow")) printf ("VRB4 %s-%ld ",\
|
/* if (VRB4 && !xmlStrcmp(node->name, (xmlChar *)"arrow")) printf ("VRB4 %s-%ld ",\ */
|
||||||
(xmlChar *)node->name, arrows_nb);
|
/* (xmlChar *)node->name, arrows_nb); */
|
||||||
if (node && node->properties) {
|
/* if (node && node->properties) { */
|
||||||
xmlAttr* attribute = node->properties;
|
/* xmlAttr* attribute = node->properties; */
|
||||||
while(attribute)
|
/* while(attribute) */
|
||||||
{
|
/* { */
|
||||||
xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1);
|
/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */
|
||||||
if (VRB4) printf("v=%s ", value);
|
/* if (VRB4) printf("v=%s ", value); */
|
||||||
*(t + c) = strtol((char*)value, NULL, 0);
|
/* *(t + c) = strtol((char*)value, NULL, 0); */
|
||||||
++c;
|
/* ++c; */
|
||||||
xmlFree(value);
|
/* xmlFree(value); */
|
||||||
attribute = attribute->next;
|
/* attribute = attribute->next; */
|
||||||
}
|
/* } */
|
||||||
if (VRB4) printf("\n");
|
/* if (VRB4) printf("\n"); */
|
||||||
}
|
/* } */
|
||||||
node = node->next;
|
/* node = node->next; */
|
||||||
}
|
/* } */
|
||||||
if (VRB4) printf ("VRB4 model_get_state_arrows_nb = %ld end at line %ld\n",\
|
/* if (VRB4) printf ("VRB4 model_get_state_arrows_nb = %ld end at line %ld\n",\ */
|
||||||
arrows_nb, xmlGetLineNo(node));
|
/* arrows_nb, xmlGetLineNo(node)); */
|
||||||
if (VRB4) for(int k = 0; k < c; k++) printf("%d ", *(t + k)); printf("\n");
|
/* if (VRB4) for(int k = 0; k < c; k++) printf("%d ", *(t + k)); printf("\n"); */
|
||||||
return arrows_nb;
|
/* return arrows_nb; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
return (long) size * ( 2 + dim ) * sizeof(int);
|
/* return (long) size * ( 2 + dim ) * sizeof(int); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_state(xmlChar *path, xmlChar *state_id){
|
/* int model_get_state(xmlChar *path, xmlChar *state_id){ */
|
||||||
printf("model_get_state (%s -> %s state)\n", path, state_id);
|
/* printf("model_get_state (%s -> %s state)\n", path, state_id); */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_conditions_list(xmlChar *path){
|
/* int model_get_conditions_list(xmlChar *path){ */
|
||||||
printf("model_get_conditions_list(%s)\n", path);
|
/* printf("model_get_conditions_list(%s)\n", path); */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int model_get_transitions_list(xmlChar *path){
|
/* int model_get_transitions_list(xmlChar *path){ */
|
||||||
printf("model_get_transitions_list(%s)\n", path);
|
/* printf("model_get_transitions_list(%s)\n", path); */
|
||||||
return 0;
|
/* return 0; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "../../include/base.h"
|
#include "../../include/base.h"
|
||||||
#include "../../include/graphics.h"
|
#include "../../include/graphics.h"
|
||||||
|
#include "../../include/parsing.h"
|
||||||
#include "../../include/ui.h"
|
#include "../../include/ui.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -318,16 +319,17 @@ void on_openfile_response_complete(GObject *source_object,
|
||||||
{
|
{
|
||||||
GFile *file = G_FILE(source_object);
|
GFile *file = G_FILE(source_object);
|
||||||
|
|
||||||
g_autofree char *contents = NULL;
|
char *content = NULL;
|
||||||
gsize length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
g_autoptr(GError) error = NULL;
|
GError *error = NULL;
|
||||||
|
char *basename = g_file_get_basename(file);
|
||||||
|
|
||||||
// Gives you the contents of the file as a byte array, or
|
// Gives you the contents of the file as a byte array, or
|
||||||
// set the error argument
|
// set the error argument
|
||||||
g_file_load_contents_finish(file,
|
g_file_load_contents_finish(file,
|
||||||
result,
|
result,
|
||||||
&contents,
|
&content,
|
||||||
&length,
|
&length,
|
||||||
NULL,
|
NULL,
|
||||||
&error);
|
&error);
|
||||||
|
@ -338,10 +340,15 @@ void on_openfile_response_complete(GObject *source_object,
|
||||||
g_printerr("Unable to open “%s”: %s\n",
|
g_printerr("Unable to open “%s”: %s\n",
|
||||||
g_file_peek_path(file),
|
g_file_peek_path(file),
|
||||||
error->message);
|
error->message);
|
||||||
|
g_free(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//g_print("File content is :\n%s\n", contents);
|
if (model_init(content, length, basename) == false) {
|
||||||
|
ui_send_internal_notification("Error while loading the model");
|
||||||
|
g_free(basename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ui_enable_action("closefile");
|
ui_enable_action("closefile");
|
||||||
ui_enable_action("savefile");
|
ui_enable_action("savefile");
|
||||||
|
|
Loading…
Reference in New Issue