WIP: cleaning, simplifying, organizing #include parsing

This commit is contained in:
Jean Sirmai 2024-06-05 22:36:44 +02:00
parent 45cecfe805
commit f143664a5b
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 25 additions and 26 deletions

View File

@ -5,13 +5,11 @@
NTHREADS= $(shell nproc) NTHREADS= $(shell nproc)
CC=gcc CC=gcc
CFLAGS=`pkg-config --cflags 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` LDFLAGS=`pkg-config --libs gtk4 gl glib-2.0 libxml-2.0` -lGL -lGLU -lm -lepoxy -lX11 -lGLEW
WARNINGS = -Wall WARNINGS = -Wall
DEBUG = -ggdb -fno-omit-frame-pointer #-fdiagnostics-color=always -fsanitize=bounds -fstack-check DEBUG = -ggdb -fno-omit-frame-pointer #-fdiagnostics-color=always -fsanitize=bounds -fstack-check
OPTIMIZE = -O3 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 BINDIR=bin
BUILDDIR=build BUILDDIR=build

View File

@ -33,6 +33,8 @@
#include <libxml/xmlreader.h> // http://xmlsoft.org/examples/#parse1.c #include <libxml/xmlreader.h> // http://xmlsoft.org/examples/#parse1.c
// https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/general.html // https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/general.html
#include "base.h"
#define READ_SITE 1 << 0 #define READ_SITE 1 << 0
#define READ_WEIGHT 1 << 1 #define READ_WEIGHT 1 << 1
#define READ_X 1 << 2 #define READ_X 1 << 2
@ -125,8 +127,7 @@ static inline xmlChar* getFirstTag(xmlChar *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);
} }
@ -146,7 +147,7 @@ static xmlNodePtr model_get_node(xmlChar *path)
{ {
xmlNodePtr node; xmlNodePtr node;
xmlChar *extrait; xmlChar *extrait;
xmlChar *reste, *last, *affich; xmlChar *reste, *last;
// Lookup for node from path in hash table // Lookup for node from path in hash table
node = xmlHashLookup(model_hashtable, path); node = xmlHashLookup(model_hashtable, path);
@ -158,7 +159,6 @@ static xmlNodePtr model_get_node(xmlChar *path)
// no node found in hash table // no node found in hash table
} else { } else {
reste = path; reste = path;
affich = reste;
last = getLastTag(reste); last = getLastTag(reste);
node = xmlDocGetRootElement(model); node = xmlDocGetRootElement(model);
@ -220,7 +220,7 @@ static inline bool model_get_node_str_attrib(xmlNodePtr node,
while(attribute && attribute->name && attribute->children) { while(attribute && attribute->name && attribute->children) {
if (!xmlStrcmp(attribute->name, (const xmlChar *)id)) { if (!xmlStrcmp(attribute->name, (const xmlChar *)id)) {
value = xmlNodeListGetString(node->doc, attribute->children, 1); value = xmlNodeListGetString(node->doc, attribute->children, 1);
strcpy(dest, value); strcpy(dest, (char *)value);
xmlFree(value); xmlFree(value);
return true; return true;
} }
@ -234,8 +234,8 @@ static inline bool model_get_node_str_attrib(xmlNodePtr node,
char model_get_dim(void) char model_get_dim(void)
{ {
xmlAttr *attribute; // xmlAttr *attribute;
xmlChar* value; // xmlChar* value;
xmlNodePtr node = model_get_node( xmlNodePtr node = model_get_node(
(xmlChar *)"parameters/space-param/dimension"); (xmlChar *)"parameters/space-param/dimension");
@ -247,19 +247,19 @@ char model_get_dim(void)
long model_get_dim_value(const char *axis) long model_get_dim_value(const char *axis)
{ {
xmlAttr *attribute; // xmlAttr *attribute;
xmlChar *value; // xmlChar *value;
long ret_value; // long ret_value;
xmlNodePtr node = model_get_node( xmlNodePtr node = model_get_node(
(xmlChar *)"parameters/space-param/dimension"); (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) char model_get_multiplicity(void)
{ {
xmlAttr *attribute; // xmlAttr *attribute;
xmlChar* value; // xmlChar* value;
xmlNodePtr node = model_get_node( xmlNodePtr node = model_get_node(
(xmlChar *)"parameters/space-param/site_multiplicity"); (xmlChar *)"parameters/space-param/site_multiplicity");
@ -273,8 +273,8 @@ char model_get_multiplicity(void)
bool model_get_next_state(char *new_state_id) bool model_get_next_state(char *new_state_id)
{ {
static xmlNodePtr cur_node = NULL; static xmlNodePtr cur_node = NULL;
xmlAttr *attribute; // xmlAttr *attribute;
xmlChar *value; // xmlChar *value;
if (cur_node == NULL) { if (cur_node == NULL) {
// Get first state // 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) long model_get_state_arrows_count(const char *state_id)
{ {
xmlNodePtr cur_node = NULL; xmlNodePtr cur_node = NULL;
xmlAttr *attribute; // xmlAttr *attribute;
long value = 0; long value = 0;
bool found = false; bool found = false;
char temp_char[25]; 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); //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 // Lookup in properties
while (cur_node && cur_node->properties) { while (cur_node && cur_node->properties) {
attribute = cur_node->properties; // attribute = cur_node->properties; < usage ?
// Look for the id attribute // Look for the id attribute
if (model_get_node_str_attrib(cur_node, "id", &temp_char)) { if (model_get_node_str_attrib(cur_node, "id", (char *)&temp_char)) {
if (!xmlStrcmp(temp_char, (const xmlChar *)state_id)) { if (!xmlStrcmp((const xmlChar *)temp_char, (const xmlChar *)state_id)) {
found = true; found = true;
break; break;
} }
@ -372,8 +372,8 @@ bool model_get_next_arrow(struct arrow_t *new_arrow,
attribute = cur_node->properties; attribute = cur_node->properties;
// Look for the id attribute // Look for the id attribute
if (model_get_node_str_attrib(cur_node, "id", &temp_char)) { if (model_get_node_str_attrib(cur_node, "id", (char *)&temp_char)) {
if (!xmlStrcmp(temp_char, (const xmlChar *)state_id)) { if (!xmlStrcmp((xmlChar *)temp_char, (const xmlChar *)state_id)) {
found = true; found = true;
break; break;
} }

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <unistd.h> #include <unistd.h>
#include "base.h"
bool model_init(const char *content, size_t length, const char *basename); bool model_init(const char *content, size_t length, const char *basename);
bool model_shutdown(void); bool model_shutdown(void);