From 76a33f9395c43bd49e4d35b4c7662e703bd444a1 Mon Sep 17 00:00:00 2001 From: Nishi Date: Thu, 16 Apr 2026 15:01:47 +0900 Subject: [PATCH] oops --- .gitiginore => .gitignore | 0 Makefile | 10 ++-- bindgen.c | 34 -------------- bindgen.cxx | 98 +++++++++++++++++++++++++++++++++++++++ objs.mk | 1 + 5 files changed, 102 insertions(+), 41 deletions(-) rename .gitiginore => .gitignore (100%) delete mode 100644 bindgen.c create mode 100644 bindgen.cxx diff --git a/.gitiginore b/.gitignore similarity index 100% rename from .gitiginore rename to .gitignore diff --git a/Makefile b/Makefile index f9630ab..6498958 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ MILSKO = ../milsko XEMIL = ../xemil -CC = gcc -CXX = g++ -fno-rtti -fno-exceptions -std=c++98 +CXX = g++ -std=c++98 LIB = lib SO = .so @@ -10,21 +9,18 @@ SO = .so EXEC = .PHONY: all clean -.SUFFIXES: .c .cxx .o +.SUFFIXES: .cxx .o all: libMwCXX$(SO) include objs.mk bindgen$(EXEC): bindgen.o - $(CC) -L$(XEMIL)/lib -L$(XEMIL)/src -o $@ bindgen.o -lxemil + $(CXX) -L$(XEMIL)/lib -L$(XEMIL)/src -o $@ bindgen.o -lxemil libMwCXX$(SO): $(OBJS) $(CXX) -shared -L$(MILSKO)/lib -L$(MILSKO)/src -o $@ $(OBJS) -lMw -.c.o: - $(CC) -c -I$(MILSKO)/include -I$(XEMIL)/include -o $@ $< - .cxx.o: $(CXX) -c -I$(MILSKO)/include -I$(XEMIL)/include -o $@ $< diff --git a/bindgen.c b/bindgen.c deleted file mode 100644 index a0b7ebf..0000000 --- a/bindgen.c +++ /dev/null @@ -1,34 +0,0 @@ -#include - -int main(int argc, char** argv){ - xemil_t* h; - int fail = 0; - - if(argc < 2){ - printf("Usage: %s XML\n", argv[0]); - return 1; - } - - h = xl_open_file(argv[1]); - - if(h != NULL){ - h->param.new_text = 1; - - if(xl_parse(h)) { - }else{ - fail = 1; - } - - xl_close(h); - }else{ - fail = 1; - } - - if(fail){ - fprintf(stderr, "Failed to parse XML\n"); - - return 1; - } - - return 0; -} diff --git a/bindgen.cxx b/bindgen.cxx new file mode 100644 index 0000000..4421db4 --- /dev/null +++ b/bindgen.cxx @@ -0,0 +1,98 @@ +#include + +#include +#include +#include + +struct property { + std::string type; + std::string struct_name; + int common; +}; + +std::ofstream objs; + +std::map props; +std::map types; + +static std::string prop_type(std::string name){ + if(types.find(props[name].type) == types.end()) return "V" + name; + + return types[props[name].type] + name; +} + +static void scan_property(xl_node_t* node){ + property prop; + char* s; + + if(node->type != XL_NODE_NODE) return; + + prop.type = node->name; + prop.struct_name = ((s = xl_get_attribute(node, "defname")) != NULL) ? s : ""; + prop.common = ((s = xl_get_attribute(node, "common")) != NULL) && (strcmp(s, "yes") == 0); + + props[xl_get_attribute(node, "name")] = prop; +} + +static void scan_properties(xl_node_t* node){ + xl_node_t* child = node->first_child; + + while(child != NULL){ + scan_property(child); + + child = child->next; + } +} + +int main(int argc, char** argv){ + xemil_t* h; + int fail = 0; + + if(argc < 2){ + printf("Usage: %s XML\n", argv[0]); + return 1; + } + + h = xl_open_file(argv[1]); + + if(h != NULL){ + h->param.new_text = 1; + + if(xl_parse(h)) { + xl_node_t** nodes; + int i; + + objs = std::ofstream("objs.mk"); + + objs << "OBJS = "; + + types["integer"] = "I"; + types["string" ] = "S"; + types["handler"] = "C"; + + if((nodes = xl_get_path(h->root, "properties")) != NULL){ + for(i = 0; nodes[i] != NULL; i++){ + scan_properties(nodes[i]); + } + } + + objs << std::endl; + + objs.close(); + }else{ + fail = 1; + } + + xl_close(h); + }else{ + fail = 1; + } + + if(fail){ + fprintf(stderr, "Failed to parse XML\n"); + + return 1; + } + + return 0; +} diff --git a/objs.mk b/objs.mk index e69de29..36cdd1d 100644 --- a/objs.mk +++ b/objs.mk @@ -0,0 +1 @@ +OBJS =