98 lines
1.6 KiB
C++
98 lines
1.6 KiB
C++
#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;
|
|
}
|