From f143664a5b8670a54b6abd17e9720dd64e7d3586 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 5 Jun 2024 22:36:44 +0200 Subject: [PATCH] WIP: cleaning, simplifying, organizing #include parsing --- Makefile | 6 ++--- parsing.c.todo => parsing.c | 44 ++++++++++++++++++------------------- parsing.h.todo => parsing.h | 1 + 3 files changed, 25 insertions(+), 26 deletions(-) rename parsing.c.todo => parsing.c (93%) rename parsing.h.todo => parsing.h (98%) diff --git a/Makefile b/Makefile index 5d1340d..18f51cb 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,11 @@ NTHREADS= $(shell nproc) CC=gcc -CFLAGS=`pkg-config --cflags gtk4 gl glib-2.0` -LDFLAGS=`pkg-config --libs gtk4 gl glib-2.0` +CFLAGS=`pkg-config --cflags gtk4 gl glib-2.0 libxml-2.0` +LDFLAGS=`pkg-config --libs gtk4 gl glib-2.0 libxml-2.0` -lGL -lGLU -lm -lepoxy -lX11 -lGLEW WARNINGS = -Wall DEBUG = -ggdb -fno-omit-frame-pointer #-fdiagnostics-color=always -fsanitize=bounds -fstack-check OPTIMIZE = -O3 -INCLUDE= $(shell pkg-config --cflags glib-2.0 libxml-2.0 gtk4) -LIBS= $(shell pkg-config --libs glib-2.0 libxml-2.0 gtk4) -lGL -lGLU -lm -lepoxy -lX11 -lGLEW BINDIR=bin BUILDDIR=build diff --git a/parsing.c.todo b/parsing.c similarity index 93% rename from parsing.c.todo rename to parsing.c index 8e2c97f..b618d5b 100644 --- a/parsing.c.todo +++ b/parsing.c @@ -33,6 +33,8 @@ #include // http://xmlsoft.org/examples/#parse1.c // https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/general.html +#include "base.h" + #define READ_SITE 1 << 0 #define READ_WEIGHT 1 << 1 #define READ_X 1 << 2 @@ -125,8 +127,7 @@ static inline xmlChar* getFirstTag(xmlChar *path) path = (xmlChar *)xmlStrchr(path, '/'); path = xmlStrsub (path, 1, xmlStrlen(path)); - //printf("%s = %s + / + %s\n", preop,\ - xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1), path); + //printf("%s = %s + / + %s\n", preop, xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1), path); return xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1); } @@ -146,7 +147,7 @@ static xmlNodePtr model_get_node(xmlChar *path) { xmlNodePtr node; xmlChar *extrait; - xmlChar *reste, *last, *affich; + xmlChar *reste, *last; // Lookup for node from path in hash table node = xmlHashLookup(model_hashtable, path); @@ -158,7 +159,6 @@ static xmlNodePtr model_get_node(xmlChar *path) // no node found in hash table } else { reste = path; - affich = reste; last = getLastTag(reste); node = xmlDocGetRootElement(model); @@ -220,7 +220,7 @@ static inline bool model_get_node_str_attrib(xmlNodePtr node, while(attribute && attribute->name && attribute->children) { if (!xmlStrcmp(attribute->name, (const xmlChar *)id)) { value = xmlNodeListGetString(node->doc, attribute->children, 1); - strcpy(dest, value); + strcpy(dest, (char *)value); xmlFree(value); return true; } @@ -234,8 +234,8 @@ static inline bool model_get_node_str_attrib(xmlNodePtr node, char model_get_dim(void) { - xmlAttr *attribute; - xmlChar* value; + // xmlAttr *attribute; + // xmlChar* value; xmlNodePtr node = model_get_node( (xmlChar *)"parameters/space-param/dimension"); @@ -247,19 +247,19 @@ char model_get_dim(void) long model_get_dim_value(const char *axis) { - xmlAttr *attribute; - xmlChar *value; - long ret_value; + // xmlAttr *attribute; + // xmlChar *value; + // long ret_value; xmlNodePtr node = model_get_node( (xmlChar *)"parameters/space-param/dimension"); - return model_get_node_long_attrib(node, axis); + return model_get_node_long_attrib(node, (char *)axis); } char model_get_multiplicity(void) { - xmlAttr *attribute; - xmlChar* value; + // xmlAttr *attribute; + // xmlChar* value; xmlNodePtr node = model_get_node( (xmlChar *)"parameters/space-param/site_multiplicity"); @@ -273,8 +273,8 @@ char model_get_multiplicity(void) bool model_get_next_state(char *new_state_id) { static xmlNodePtr cur_node = NULL; - xmlAttr *attribute; - xmlChar *value; + // xmlAttr *attribute; + // xmlChar *value; if (cur_node == NULL) { // Get first state @@ -299,11 +299,11 @@ bool model_get_next_state(char *new_state_id) long model_get_state_arrows_count(const char *state_id) { xmlNodePtr cur_node = NULL; - xmlAttr *attribute; + // xmlAttr *attribute; long value = 0; bool found = false; char temp_char[25]; - uint check = 0; // bit field checker + // uint check = 0; // bit field checker //printf("NEW CALL : cur_node = %p\n", cur_node); @@ -314,11 +314,11 @@ long model_get_state_arrows_count(const char *state_id) // Lookup in properties while (cur_node && cur_node->properties) { - attribute = cur_node->properties; + // attribute = cur_node->properties; < usage ? // Look for the id attribute - if (model_get_node_str_attrib(cur_node, "id", &temp_char)) { - if (!xmlStrcmp(temp_char, (const xmlChar *)state_id)) { + if (model_get_node_str_attrib(cur_node, "id", (char *)&temp_char)) { + if (!xmlStrcmp((const xmlChar *)temp_char, (const xmlChar *)state_id)) { found = true; break; } @@ -372,8 +372,8 @@ bool model_get_next_arrow(struct arrow_t *new_arrow, attribute = cur_node->properties; // Look for the id attribute - if (model_get_node_str_attrib(cur_node, "id", &temp_char)) { - if (!xmlStrcmp(temp_char, (const xmlChar *)state_id)) { + if (model_get_node_str_attrib(cur_node, "id", (char *)&temp_char)) { + if (!xmlStrcmp((xmlChar *)temp_char, (const xmlChar *)state_id)) { found = true; break; } diff --git a/parsing.h.todo b/parsing.h similarity index 98% rename from parsing.h.todo rename to parsing.h index 307e723..de6af9b 100644 --- a/parsing.h.todo +++ b/parsing.h @@ -24,6 +24,7 @@ #pragma once #include +#include "base.h" bool model_init(const char *content, size_t length, const char *basename); bool model_shutdown(void);