This commit is contained in:
Nishi 2026-04-16 15:01:47 +09:00
commit 76a33f9395
5 changed files with 102 additions and 41 deletions

View file

View file

@ -1,8 +1,7 @@
MILSKO = ../milsko MILSKO = ../milsko
XEMIL = ../xemil XEMIL = ../xemil
CC = gcc CXX = g++ -std=c++98
CXX = g++ -fno-rtti -fno-exceptions -std=c++98
LIB = lib LIB = lib
SO = .so SO = .so
@ -10,21 +9,18 @@ SO = .so
EXEC = EXEC =
.PHONY: all clean .PHONY: all clean
.SUFFIXES: .c .cxx .o .SUFFIXES: .cxx .o
all: libMwCXX$(SO) all: libMwCXX$(SO)
include objs.mk include objs.mk
bindgen$(EXEC): bindgen.o 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) libMwCXX$(SO): $(OBJS)
$(CXX) -shared -L$(MILSKO)/lib -L$(MILSKO)/src -o $@ $(OBJS) -lMw $(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.o:
$(CXX) -c -I$(MILSKO)/include -I$(XEMIL)/include -o $@ $< $(CXX) -c -I$(MILSKO)/include -I$(XEMIL)/include -o $@ $<

View file

@ -1,34 +0,0 @@
#include <xemil.h>
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;
}

98
bindgen.cxx Normal file
View file

@ -0,0 +1,98 @@
#include <xemil.h>
#include <map>
#include <string>
#include <fstream>
struct property {
std::string type;
std::string struct_name;
int common;
};
std::ofstream objs;
std::map<std::string, property> props;
std::map<std::string, std::string> 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;
}

View file

@ -0,0 +1 @@
OBJS =