From c6976b8871fdf16390da23e55d66bbea7f70d4f2 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Thu, 30 Mar 2017 11:23:54 +0200 Subject: [PATCH] rename the soure-file to source-file.bak and construct a new 'source-file' with an added section --- utils/xmlgrep/metadata.c | 239 +++++++++++++++++++++++++++++++++------ 1 file changed, 207 insertions(+), 32 deletions(-) diff --git a/utils/xmlgrep/metadata.c b/utils/xmlgrep/metadata.c index ec406187a..c9c6ace18 100644 --- a/utils/xmlgrep/metadata.c +++ b/utils/xmlgrep/metadata.c @@ -6,8 +6,10 @@ #include +#define TS (4*1024*1024) + #define PRINT(a) \ - tag = (a); if (tag) printf(" %s\n", tag) + tag = (a); if (tag) { strncat(s, " ", TS-strlen(s)); strncat(s, tag, TS-strlen(s)); strncat(s, "\n", TS-strlen(s)); } char * getCommandLineOption(int argc, char **argv, char const *option) @@ -53,15 +55,174 @@ char *strlwr(char *str) return str; } +static unsigned int tags_level = 0; +void print_xml(FILE *fd, void *id, char *tags) +{ + static int level = 1; + void *xid = xmlMarkId(id); + unsigned int num; + + num = xmlNodeGetNum(xid, "*"); + if (num == 0) + { + char *s; + s = xmlGetString(xid); + if (s) + { + fprintf(fd, "%s", s); + free(s); + } + } + else + { + unsigned int i, q; + for (i=0; i"); + + level++; + print_xml(fd, xid, tags); + + level--; + fprintf(fd, "", name); + + if (tags_level == 2 && !strcmp(name, "aero")) { + fprintf(fd, "\n%s\n", tags); + } + } + else printf("error\n"); + } + fprintf(fd, "\n"); + for(q=1; q\n\n"); + + xid = xmlMarkId(rid); + num = xmlNodeGetNum(xid, "*"); + for (i=0; i"); + print_xml(fd, xid, tags); + fprintf(fd, "\n\n", name); + } + } + free(xid); + + xmlClose(rid); + fclose(fd); + } +} + /* -- JSBSim ---------------------------------------------------------------- */ const char* -jsb_wing_tag(void *xid) +jsb_wing_tag(void *xid, void *path) { - void *xlid, *xmid = xmlNodeGet(xid, "/fdm_config/metrics"); + void *xlid, *xmid, *xeid; double aero_z = 0.0; double eye_z = 0.0; int i, num; + xeid = xmlNodeGet(xid, "/fdm_config/propulsion/engine/thruster"); + if (xeid) + { + char *rv = NULL; + char *file = xmlAttributeGetString(xeid, "file"); + char *fname = calloc(1, strlen(path)+strlen("Engines/")+ + strlen(file)+strlen(".xml")+1); + if (fname) + { + void *xfid; + + memcpy(fname, path, strlen(path)); + memcpy(fname+strlen(path), "Engines/", strlen("Engines/")); + memcpy(fname+strlen(path)+strlen("Engines/"), file, strlen(file)); + memcpy(fname+strlen(path)+strlen("Engines/")+strlen(file), ".xml", strlen(".xml")); + + xfid = xmlOpen(fname); + if (xfid) + { + if (xmlNodeTest(xfid, "rotor")) rv = "helicopter"; + xmlClose(xfid); + } + free(fname); + } + xmlFree(file); + xmlFree(xeid); + if (rv) return rv; + } + + xmid = xmlNodeGet(xid, "/fdm_config/metrics"); if (!xmid) return NULL; xlid = xmlMarkId(xmid); @@ -364,10 +525,10 @@ jsb_thruster_tag(void *xid, char *path) } void -update_metadata_jsb(char *path, char *aero, char *desc) +update_metadata_jsb(char *sfname, char *path, char *aero, char *desc) { const char *tag; - char *fname; + char *s, *fname; void *xid; fname = calloc(1, strlen(path)+strlen(aero)+strlen(".xml")+1); @@ -388,18 +549,25 @@ update_metadata_jsb(char *path, char *aero, char *desc) return; } - printf(" \n"); - PRINT(strlwr(desc ? desc : aero)); - PRINT(jsb_wing_tag(xid)); - PRINT(jsb_gear_tag(xid)); - PRINT(jsb_gear_retract_tag(xid)); - PRINT(jsb_gear_steering_tag(xid)); - PRINT(jsb_engines_tag(xid)); - PRINT(jsb_engine_tag(xid, path)); - PRINT(jsb_propulsion_tag(xid, path)); - PRINT(jsb_thruster_tag(xid, path)); - printf(" \n"); + s = malloc(65*1024); + if (s) + { + sprintf(s, " \n"); + PRINT("auto-generated"); + PRINT(strlwr(desc ? desc : aero)); + PRINT(jsb_wing_tag(xid, path)); + PRINT(jsb_gear_tag(xid)); + PRINT(jsb_gear_retract_tag(xid)); + PRINT(jsb_gear_steering_tag(xid)); + PRINT(jsb_engines_tag(xid)); + PRINT(jsb_engine_tag(xid, path)); + PRINT(jsb_propulsion_tag(xid, path)); + PRINT(jsb_thruster_tag(xid, path)); + s = strncat(s, " ", TS-strlen(s)); + updateFile(sfname, s); + free(s); + } xmlClose(xid); free(fname); } @@ -654,10 +822,10 @@ yasim_thruster_tag(void *xid, char *path) } void -update_metadata_yasim(char *path, char *aero, char *desc) +update_metadata_yasim(char *sfname, char *path, char *aero, char *desc) { const char *tag; - char *fname; + char *s, *fname; void *xid; fname = calloc(1, strlen(path)+strlen(aero)+strlen(".xml")+1); @@ -678,18 +846,25 @@ update_metadata_yasim(char *path, char *aero, char *desc) return; } - printf(" \n"); - PRINT(strlwr(desc ? desc : aero)); - PRINT(yasim_wing_tag(xid)); - PRINT(yasim_gear_tag(xid)); - PRINT(yasim_gear_retract_tag(xid)); - PRINT(yasim_gear_steering_tag(xid)); - PRINT(yasim_engines_tag(xid)); - PRINT(yasim_engine_tag(xid, path)); - PRINT(yasim_propulsion_tag(xid, path)); - PRINT(yasim_thruster_tag(xid, path)); - printf(" \n"); - + s = malloc(65*1024); + if (s) + { + sprintf(s, " \n"); + PRINT("auto-generated"); + PRINT(strlwr(desc ? desc : aero)); + PRINT(yasim_wing_tag(xid)); + PRINT(yasim_gear_tag(xid)); + PRINT(yasim_gear_retract_tag(xid)); + PRINT(yasim_gear_steering_tag(xid)); + PRINT(yasim_engines_tag(xid)); + PRINT(yasim_engine_tag(xid, path)); + PRINT(yasim_propulsion_tag(xid, path)); + PRINT(yasim_thruster_tag(xid, path)); + s = strncat(s, " ", TS-strlen(s)); + + updateFile(sfname, s); + free(s); + } xmlClose(xid); free(fname); } @@ -733,10 +908,10 @@ update_metadata(const char *fname) desc = xmlNodeGetString(xsid, "description"); str = xmlNodeGetString(xsid, "aero"); if (!xmlNodeCompareString(xsid, "flight-model", "jsb")) { - update_metadata_jsb(path, str, desc); + update_metadata_jsb(fname, path, str, desc); } else if (!xmlNodeCompareString(xsid, "flight-model", "yasim")) { - update_metadata_yasim(path, str, desc); + update_metadata_yasim(fname, path, str, desc); } else {