2017-03-23 11:51:58 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <xml.h>
|
|
|
|
|
2017-03-30 09:23:54 +00:00
|
|
|
#define TS (4*1024*1024)
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
#define PRINT(a) \
|
2017-03-30 09:23:54 +00:00
|
|
|
tag = (a); if (tag) { strncat(s, " <tag>", TS-strlen(s)); strncat(s, tag, TS-strlen(s)); strncat(s, "</tag>\n", TS-strlen(s)); }
|
2017-03-25 13:21:05 +00:00
|
|
|
|
2017-03-30 13:56:15 +00:00
|
|
|
static unsigned int tags_level = 0;
|
|
|
|
static unsigned int print_tags = 0;
|
|
|
|
|
2017-03-23 11:51:58 +00:00
|
|
|
char *
|
|
|
|
getCommandLineOption(int argc, char **argv, char const *option)
|
|
|
|
{
|
|
|
|
int slen = strlen(option);
|
|
|
|
char *rv = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++)
|
|
|
|
{
|
|
|
|
if (strncmp(argv[i], option, slen) == 0)
|
|
|
|
{
|
|
|
|
rv = "";
|
|
|
|
i++;
|
|
|
|
if (i<argc) rv = argv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
show_help()
|
|
|
|
{
|
|
|
|
printf("Usage: metdata [options]\n");
|
|
|
|
printf("Updates the metadata of a FlightGear aircraft configuration.\n");
|
|
|
|
printf("\nOptions:\n");
|
|
|
|
printf(" -i, --input <file>\t\taircraft configuration file to update\n");
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *strlwr(char *str)
|
|
|
|
{
|
|
|
|
unsigned char *p = (unsigned char *)str;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
*p = tolower((unsigned char)*p);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-03-30 09:23:54 +00:00
|
|
|
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<num; i++)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(id, xid, "*", i) != 0)
|
|
|
|
{
|
|
|
|
unsigned int anum, a;
|
|
|
|
char name[256];
|
|
|
|
xmlNodeCopyName(xid, (char *)&name, 256);
|
|
|
|
|
|
|
|
if (tags_level == 1 && !strcmp(name, "sim")) tags_level++;
|
|
|
|
|
|
|
|
fprintf(fd, "\n");
|
|
|
|
for(q=0; q<level; q++) fprintf(fd, " ");
|
|
|
|
fprintf(fd, "<%s", name);
|
|
|
|
|
|
|
|
anum = xmlAttributeGetNum(xid);
|
|
|
|
for (a=0; a<anum; a++)
|
|
|
|
{
|
|
|
|
char name[256], attrib[256];
|
|
|
|
if (xmlAttributeCopyName(xid, (char *)&name, 256, a) != 0)
|
|
|
|
{
|
|
|
|
xmlAttributeCopyString(xid, name, (char *)&attrib, 256);
|
|
|
|
fprintf(fd, " %s=\"%s\"", name, attrib);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(fd, ">");
|
|
|
|
|
|
|
|
level++;
|
|
|
|
print_xml(fd, xid, tags);
|
|
|
|
|
|
|
|
level--;
|
|
|
|
fprintf(fd, "</%s>", 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<level; q++) fprintf(fd, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
updateFile(char *fname, char *tags)
|
|
|
|
{
|
|
|
|
char bfname[4096];
|
|
|
|
FILE *fd = NULL;
|
|
|
|
void *rid;
|
|
|
|
|
|
|
|
snprintf(bfname, 4096, "%s.bak", fname);
|
|
|
|
rename(fname, bfname);
|
|
|
|
|
|
|
|
rid = xmlOpen(bfname);
|
|
|
|
if (rid)
|
|
|
|
{
|
|
|
|
fd = fopen(fname, "w");
|
|
|
|
if (!fd)
|
|
|
|
{
|
|
|
|
xmlClose(rid);
|
|
|
|
rid = NULL;
|
|
|
|
rename(bfname, fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rid)
|
|
|
|
{
|
|
|
|
unsigned int i, num;
|
|
|
|
void *xid;
|
|
|
|
|
|
|
|
fprintf(fd, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
|
|
|
|
|
|
|
|
xid = xmlMarkId(rid);
|
|
|
|
num = xmlNodeGetNum(xid, "*");
|
|
|
|
for (i=0; i<num; i++)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(rid, xid, "*", i) != 0)
|
|
|
|
{
|
|
|
|
unsigned int anum, a;
|
|
|
|
char name[256];
|
|
|
|
xmlNodeCopyName(xid, (char *)&name, 256);
|
|
|
|
|
|
|
|
if (strcmp(name, "PropertyList")) break;
|
|
|
|
|
|
|
|
tags_level++;
|
|
|
|
fprintf(fd, "<%s", name);
|
|
|
|
anum = xmlAttributeGetNum(xid);
|
|
|
|
for (a=0; a<anum; a++)
|
|
|
|
{
|
|
|
|
char name[256], attrib[256];
|
|
|
|
if (xmlAttributeCopyName(xid, (char *)&name, 256, a) != 0)
|
|
|
|
{
|
|
|
|
xmlAttributeCopyString(xid, name, (char *)&attrib, 256);
|
|
|
|
fprintf(fd, " %s=\"%s\"", name, attrib);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(fd, ">");
|
|
|
|
print_xml(fd, xid, tags);
|
|
|
|
fprintf(fd, "\n</%s>\n", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(xid);
|
|
|
|
|
|
|
|
xmlClose(rid);
|
|
|
|
fclose(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 13:56:15 +00:00
|
|
|
const char*
|
|
|
|
vendor_tag(char *desc)
|
|
|
|
{
|
|
|
|
char *p = strlwr(desc);
|
|
|
|
if (strstr(p, "boeing")) return "boeing";
|
|
|
|
if (strstr(p, "airbus")) return "airbus";
|
|
|
|
if (strstr(p, "antonov")) return "antonov";
|
|
|
|
if (strstr(p, "tupolev")) return "tupolev";
|
|
|
|
if (strstr(p, "ilyoushin")) return "ilyoushin";
|
|
|
|
if (strstr(p, "bombardier")) return "bombardier";
|
|
|
|
if (strstr(p, "fokker")) return "fokker";
|
|
|
|
if (strstr(p, "lockheed")) return "lockheed";
|
|
|
|
if (strstr(p, "general-dynamics")) return "general-dynamics";
|
|
|
|
if (strstr(p, "general dynamics")) return "general-dynamics";
|
|
|
|
if (strstr(p, "mig")) return "mikoyan-gurevich";
|
|
|
|
if (strstr(p, "mikoyan gurevich")) return "mikoyan-gurevich";
|
|
|
|
if (strstr(p, "mikoyan-gurevich")) return "mikoyan-gurevich";
|
|
|
|
if (strstr(p, "sukoi")) return "sukoi";
|
|
|
|
if (strstr(p, "cessna")) return "cessna";
|
|
|
|
if (strstr(p, "fairchild")) return "fairchild";
|
|
|
|
if (strstr(p, "dassult")) return "dassult";
|
|
|
|
if (strstr(p, "dornier")) return "dornier";
|
|
|
|
if (strstr(p, "arado")) return "arado";
|
|
|
|
if (strstr(p, "schleicher")) return "schleicher";
|
|
|
|
if (strstr(p, "avro")) return "avro";
|
|
|
|
if (strstr(p, "saab")) return "saab";
|
|
|
|
if (strstr(p, "dassault")) return "dassault";
|
|
|
|
if (strstr(p, "aermacchi")) return "aermacchi";
|
|
|
|
if (strstr(p, "arsenal")) return "arsenal";
|
|
|
|
if (strstr(p, "rockwell")) return "rockwell";
|
|
|
|
if (strstr(p, "northrop")) return "northrop";
|
|
|
|
if (strstr(p, "grumman")) return "grumman";
|
|
|
|
if (strstr(p, "mc donnell") && strstr(p, "douglas")) return "mc-donnell-douglas";
|
|
|
|
if (strstr(p, "douglas")) return "douglas";
|
|
|
|
if (strstr(p, "mc donnell")) return "mc-donnell";
|
|
|
|
if (strstr(p, "mc-donnell")) return "mc-donnell";
|
|
|
|
// if (strstr(p, "jaguar")) return "jaguar";
|
|
|
|
if (strstr(p, "junkers")) return "junkers";
|
|
|
|
if (strstr(p, "kawasaki")) return "kawasaki";
|
|
|
|
if (strstr(p, "de havilland")) return "de-havilland";
|
|
|
|
if (strstr(p, "de-havilland")) return "de-havilland";
|
|
|
|
if (strstr(p, "diamond")) return "diamond";
|
|
|
|
if (strstr(p, "bell")) return "bell";
|
|
|
|
if (strstr(p, "hughes")) return "hughes";
|
|
|
|
if (strstr(p, "kamov")) return "kamov";
|
|
|
|
if (strstr(p, "mil")) return "mil";
|
|
|
|
if (strstr(p, "eurocopter")) return "eurocopter";
|
|
|
|
if (strstr(p, "alouette")) return "alouette";
|
|
|
|
if (strstr(p, "aerospatiale")) return "aerospatiale";
|
|
|
|
if (strstr(p, "sikorsky")) return "sikorsky";
|
|
|
|
if (strstr(p, "bernard")) return "bernard";
|
|
|
|
if (strstr(p, "bleriot")) return "bleriot";
|
|
|
|
if (strstr(p, "bristol")) return "bristol";
|
|
|
|
if (strstr(p, "breguet")) return "breguet";
|
|
|
|
if (strstr(p, "wright")) return "wright";
|
|
|
|
if (strstr(p, "breda")) return "breda";
|
|
|
|
if (strstr(p, "rutan")) return "rutan";
|
|
|
|
if (strstr(p, "vought")) return "vought";
|
|
|
|
if (strstr(p, "fiat")) return "fiat";
|
|
|
|
if (strstr(p, "focke wulf")) return "focke-wulf";
|
|
|
|
if (strstr(p, "focke-wulf")) return "focke-wulf";
|
|
|
|
if (strstr(p, "gloster")) return "gloster";
|
|
|
|
if (strstr(p, "hawker")) return "hawker";
|
|
|
|
if (strstr(p, "heinkel")) return "heinkel";
|
|
|
|
if (strstr(p, "messerschmitt")) return "messerschmitt";
|
|
|
|
if (strstr(p, "north american")) return "north-american";
|
|
|
|
if (strstr(p, "north-american")) return "north-american";
|
|
|
|
if (strstr(p, "piaggio")) return "piaggio";
|
|
|
|
if (strstr(p, "pilatus")) return "pilatus";
|
|
|
|
if (strstr(p, "supermarine")) return "supermarine";
|
|
|
|
if (strstr(p, "beechcraft")) return "beechcraft";
|
|
|
|
if (strstr(p, "beech")) return "beechcraft";
|
|
|
|
if (strstr(p, "vickers")) return "vickers";
|
|
|
|
if (strstr(p, "westland")) return "westland";
|
|
|
|
if (strstr(p, "yakovlev")) return "yakovlev";
|
|
|
|
if (strstr(p, "schweizer")) return "schweizer";
|
|
|
|
|
|
|
|
/* educated guess */
|
|
|
|
if (strstr(p, "b7")) return "boeing";
|
|
|
|
if (strstr(p, "airbus")) return "airbus";
|
|
|
|
if (strstr(p, "an-")) return "antonov";
|
|
|
|
if (strstr(p, "tu-")) return "tupolev";
|
|
|
|
if (strstr(p, "il-")) return "ilyoushin";
|
|
|
|
if (strstr(p, "su-")) return "sukoi";
|
|
|
|
if (strstr(p, "dc-")) return "douglas";
|
|
|
|
if (strstr(p, "md-")) return "mc-donnell-douglas";
|
|
|
|
if (strstr(p, "ju-")) return "junkers";
|
|
|
|
if (strstr(p, "ec-")) return "eurocopter";
|
|
|
|
if (strstr(p, "he-")) return "heinkel";
|
|
|
|
if (strstr(p, "as-")) return "aerospatiale";
|
|
|
|
if (strstr(p, "me-")) return "messerschmitt";
|
|
|
|
if (strstr(p, "fw-")) return "focke-wulf";
|
|
|
|
if (strstr(p, "yak-")) return "yakovlev";
|
|
|
|
if (strstr(p, "sgs-")) return "schweizer";
|
|
|
|
if (strstr(p, "ask-")) return "schleicher";
|
|
|
|
if (strstr(p, "mirage")) return "dassault";
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-23 11:51:58 +00:00
|
|
|
/* -- JSBSim ---------------------------------------------------------------- */
|
|
|
|
const char*
|
2017-03-30 09:23:54 +00:00
|
|
|
jsb_wing_tag(void *xid, void *path)
|
2017-03-23 11:51:58 +00:00
|
|
|
{
|
2017-03-30 09:23:54 +00:00
|
|
|
void *xlid, *xmid, *xeid;
|
2017-03-23 11:51:58 +00:00
|
|
|
double aero_z = 0.0;
|
|
|
|
double eye_z = 0.0;
|
|
|
|
int i, num;
|
|
|
|
|
2017-03-30 09:23:54 +00:00
|
|
|
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");
|
2017-03-25 13:21:05 +00:00
|
|
|
if (!xmid) return NULL;
|
|
|
|
|
|
|
|
xlid = xmlMarkId(xmid);
|
2017-03-23 11:51:58 +00:00
|
|
|
num = xmlNodeGetNum(xmid, "location");
|
|
|
|
for (i=0; i<num; ++i)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xmid, xlid, "location", i) != 0)
|
|
|
|
{
|
|
|
|
if (!xmlAttributeCompareString(xlid, "name", "AERORP")) {
|
|
|
|
aero_z = xmlNodeGetDouble(xlid, "z");
|
|
|
|
} else if (!xmlAttributeCompareString(xlid, "name", "EYEPOINT")) {
|
|
|
|
eye_z = xmlNodeGetDouble(xlid, "z");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(xlid);
|
|
|
|
xmlFree(xmid);
|
|
|
|
|
|
|
|
if (aero_z > eye_z) return "high-wing";
|
|
|
|
else return "low-wing";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
jsb_gear_tag(void *xid)
|
|
|
|
{
|
2017-03-25 13:21:05 +00:00
|
|
|
void *xcid, *xgid = xmlNodeGet(xid, "/fdm_config/ground_reactions");
|
2017-03-23 11:51:58 +00:00
|
|
|
double nose_x = 0.0;
|
|
|
|
double main_x = 0.0;
|
|
|
|
int bogeys = 0;
|
|
|
|
int i, num;
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
if (!xgid) return NULL;
|
|
|
|
|
|
|
|
xcid = xmlMarkId(xgid);
|
2017-03-23 11:51:58 +00:00
|
|
|
num = xmlNodeGetNum(xgid, "contact");
|
|
|
|
for (i=0; i<num; ++i)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xgid, xcid, "contact", i) != 0)
|
|
|
|
{
|
|
|
|
if (!xmlAttributeCompareString(xcid, "type", "BOGEY"))
|
|
|
|
{
|
|
|
|
if (xmlNodeGetDouble(xcid, "location/y") == 0.0) {
|
|
|
|
nose_x = xmlNodeGetDouble(xcid, "location/x");
|
|
|
|
} else {
|
|
|
|
main_x = xmlNodeGetDouble(xcid, "location/x");
|
|
|
|
}
|
|
|
|
bogeys++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(xcid);
|
|
|
|
xmlFree(xgid);
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
if (bogeys == 0) return "skids";
|
|
|
|
else if (bogeys < 3 || main_x < nose_x) return "tail-dragger";
|
2017-03-23 11:51:58 +00:00
|
|
|
return "tricycle";
|
|
|
|
}
|
|
|
|
|
2017-03-23 12:32:36 +00:00
|
|
|
const char*
|
|
|
|
jsb_gear_retract_tag(void *xid)
|
|
|
|
{
|
|
|
|
int r = xmlNodeGetInt(xid, "/fdm_config/ground_reactions/contact/retractable");
|
|
|
|
if (r) return "retractable-gear";
|
|
|
|
else return "fixed-gear";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
jsb_gear_steering_tag(void *xid)
|
|
|
|
{
|
2017-03-25 13:21:05 +00:00
|
|
|
void *xcid, *xgid = xmlNodeGet(xid, "/fdm_config/ground_reactions");
|
|
|
|
char *rv = NULL;
|
2017-03-23 12:32:36 +00:00
|
|
|
int found = 0;
|
|
|
|
int i, num;
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
if (!xgid) return NULL;
|
|
|
|
|
|
|
|
xcid = xmlMarkId(xgid);
|
2017-03-23 12:32:36 +00:00
|
|
|
num = xmlNodeGetNum(xgid, "contact");
|
|
|
|
for (i=0; i<num; ++i)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xgid, xcid, "contact", i) != 0)
|
|
|
|
{
|
|
|
|
if (!xmlAttributeCompareString(xcid, "type", "BOGEY"))
|
|
|
|
{
|
|
|
|
if (xmlNodeGetDouble(xcid, "location/y") == 0.0)
|
|
|
|
{
|
|
|
|
double m = xmlNodeGetDouble(xcid, "max_steer");
|
|
|
|
int c = xmlNodeGetInt(xcid, "castered");
|
|
|
|
|
|
|
|
if (c || (m == 360.0 && !c)) {
|
2017-03-25 13:21:05 +00:00
|
|
|
rv = "castering";
|
2017-03-23 12:32:36 +00:00
|
|
|
break;
|
|
|
|
} else if (m > 0.0) {
|
2017-03-25 13:21:05 +00:00
|
|
|
// rv = "normal-steering";
|
2017-03-23 12:32:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
2017-03-25 13:21:05 +00:00
|
|
|
// rv = "no-steering";
|
2017-03-23 12:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(xcid);
|
|
|
|
xmlFree(xgid);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-03-23 11:51:58 +00:00
|
|
|
const char*
|
|
|
|
jsb_engines_tag(void *xid)
|
|
|
|
{
|
2017-03-25 13:21:05 +00:00
|
|
|
void *xeid, *xpid = xmlNodeGet(xid, "/fdm_config/propulsion");
|
|
|
|
const char* rv = NULL;
|
2017-03-23 11:51:58 +00:00
|
|
|
int engines = 0;
|
|
|
|
int i, num;
|
|
|
|
char *main;
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
if (!xpid) return rv;
|
|
|
|
|
|
|
|
xeid = xmlMarkId(xpid);
|
|
|
|
|
2017-03-23 11:51:58 +00:00
|
|
|
num = xmlNodeGetNum(xpid, "engine");
|
|
|
|
for (i=0; i<num; ++i)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xpid, xeid, "engine", i) != 0)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
main = xmlAttributeGetString(xeid, "file");
|
|
|
|
engines++;
|
|
|
|
}
|
|
|
|
else if (!xmlAttributeCompareString(xeid, "file", main)) {
|
|
|
|
engines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(main);
|
|
|
|
xmlFree(xeid);
|
|
|
|
xmlFree(xpid);
|
|
|
|
|
|
|
|
switch (engines)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
rv = "glider";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rv = "single-engine";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rv = "twin-engine";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
rv = "three-engine";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
rv = "four-engine";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
jsb_engine_tag(void *xid, char *path)
|
|
|
|
{
|
|
|
|
void *xeid = xmlNodeGet(xid, "/fdm_config/propulsion/engine");
|
2017-03-24 13:11:44 +00:00
|
|
|
char *engine, *fname;
|
2017-03-24 12:37:23 +00:00
|
|
|
const char *rv = NULL;
|
2017-03-23 11:51:58 +00:00
|
|
|
|
2017-03-24 13:11:44 +00:00
|
|
|
if (!xeid) return rv;
|
|
|
|
|
|
|
|
engine = xmlAttributeGetString(xeid, "file");
|
|
|
|
fname = calloc(1, strlen(path)+strlen("Engines/")+
|
|
|
|
strlen(engine)+strlen(".xml")+1);
|
2017-03-23 11:51:58 +00:00
|
|
|
if (fname)
|
|
|
|
{
|
|
|
|
void *xfid;
|
|
|
|
|
|
|
|
memcpy(fname, path, strlen(path));
|
|
|
|
memcpy(fname+strlen(path), "Engines/", strlen("Engines/"));
|
|
|
|
memcpy(fname+strlen(path)+strlen("Engines/"), engine, strlen(engine));
|
|
|
|
memcpy(fname+strlen(path)+strlen("Engines/")+strlen(engine), ".xml", strlen(".xml"));
|
|
|
|
|
|
|
|
xfid = xmlOpen(fname);
|
|
|
|
if (xfid)
|
|
|
|
{
|
2017-03-24 12:37:23 +00:00
|
|
|
if (xmlNodeTest(xfid, "turbine_engine")) rv = "jet";
|
2017-03-23 11:51:58 +00:00
|
|
|
else if (xmlNodeTest(xfid, "turboprop_engine")) rv = "turboprop";
|
|
|
|
else if (xmlNodeTest(xfid, "piston_engine")) rv = "piston";
|
|
|
|
else if (xmlNodeTest(xfid, "electric_engine")) rv = "electric";
|
|
|
|
else if (xmlNodeTest(xfid, "rocket_engine")) rv = "rocket";
|
|
|
|
|
|
|
|
xmlClose(xfid);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("JSBSim engine file not found: %s\n", fname);
|
|
|
|
}
|
|
|
|
free(fname);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("Unable to allocate memory\n");
|
|
|
|
}
|
|
|
|
xmlFree(engine);
|
|
|
|
xmlFree(xeid);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-03-24 12:37:23 +00:00
|
|
|
const char*
|
|
|
|
jsb_propulsion_tag(void *xid, char *path)
|
|
|
|
{
|
|
|
|
void *xeid = xmlNodeGet(xid, "fdm_config/propulsion/engine");
|
2017-03-24 13:11:44 +00:00
|
|
|
char *file, *fname;
|
2017-03-24 12:37:23 +00:00
|
|
|
const char *rv = NULL;
|
|
|
|
|
2017-03-24 13:11:44 +00:00
|
|
|
if (!xeid) return rv;
|
|
|
|
|
|
|
|
file = xmlAttributeGetString(xeid, "file");
|
|
|
|
fname = calloc(1, strlen(path)+strlen("Engines/")+
|
|
|
|
strlen(file)+strlen(".xml")+1);
|
2017-03-24 12:37:23 +00:00
|
|
|
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 (xmlNodeGetInt(xfid, "turbine_engine/augmented")) {
|
|
|
|
rv = "afterburner";
|
|
|
|
}
|
|
|
|
else if (xmlNodeGetInt(xfid, "piston_engine/numboostspeeds")) {
|
|
|
|
rv = "supercharged";
|
|
|
|
}
|
|
|
|
xmlClose(xfid);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("JSBSim engine file not found: %s\n", fname);
|
|
|
|
}
|
|
|
|
free(fname);
|
|
|
|
}
|
|
|
|
xmlFree(xeid);
|
|
|
|
xmlFree(file);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
jsb_thruster_tag(void *xid, char *path)
|
|
|
|
{
|
|
|
|
void *xeid = xmlNodeGet(xid, "/fdm_config/propulsion/engine/thruster");
|
2017-03-24 13:11:44 +00:00
|
|
|
char *file, *fname;
|
2017-03-24 12:37:23 +00:00
|
|
|
const char *rv = NULL;
|
|
|
|
|
2017-03-24 13:11:44 +00:00
|
|
|
if (!xeid) return rv;
|
|
|
|
|
|
|
|
file = xmlAttributeGetString(xeid, "file");
|
|
|
|
fname = calloc(1, strlen(path)+strlen("Engines/")+
|
|
|
|
strlen(file)+strlen(".xml")+1);
|
2017-03-24 12:37:23 +00:00
|
|
|
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, "propeller"))
|
|
|
|
{
|
|
|
|
double min = xmlNodeGetDouble(xfid, "propeller/minpitch");
|
|
|
|
double max = xmlNodeGetDouble(xfid, "propeller/maxpitch");
|
|
|
|
if (min == max) rv = "fixed-pitch";
|
|
|
|
else rv = "variable-pitch";
|
|
|
|
}
|
|
|
|
xmlClose(xfid);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("JSBSim thruster file not found: %s\n", fname);
|
|
|
|
}
|
|
|
|
free(fname);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("Unable to allocate memory\n");
|
|
|
|
}
|
|
|
|
xmlFree(file);
|
|
|
|
xmlFree(xeid);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-03-23 11:51:58 +00:00
|
|
|
void
|
2017-03-30 09:23:54 +00:00
|
|
|
update_metadata_jsb(char *sfname, char *path, char *aero, char *desc)
|
2017-03-23 11:51:58 +00:00
|
|
|
{
|
2017-03-24 12:37:23 +00:00
|
|
|
const char *tag;
|
2017-03-30 09:23:54 +00:00
|
|
|
char *s, *fname;
|
2017-03-23 11:51:58 +00:00
|
|
|
void *xid;
|
|
|
|
|
2017-03-23 15:10:44 +00:00
|
|
|
fname = calloc(1, strlen(path)+strlen(aero)+strlen(".xml")+1);
|
2017-03-23 11:51:58 +00:00
|
|
|
if (!fname)
|
|
|
|
{
|
|
|
|
printf("Unable to allocate memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(fname, path, strlen(path));
|
|
|
|
memcpy(fname+strlen(path), aero, strlen(aero));
|
|
|
|
memcpy(fname+strlen(path)+strlen(aero), ".xml", strlen(".xml"));
|
|
|
|
|
|
|
|
xid = xmlOpen(fname);
|
|
|
|
if (!xid)
|
|
|
|
{
|
|
|
|
printf("JSBSim aero file not found: '%s'\n", fname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-30 09:23:54 +00:00
|
|
|
s = malloc(65*1024);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
sprintf(s, " <tags>\n");
|
|
|
|
PRINT("auto-generated");
|
2017-03-30 13:56:15 +00:00
|
|
|
PRINT(vendor_tag(desc ? desc : aero));
|
2017-03-30 09:23:54 +00:00
|
|
|
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, " </tags>", TS-strlen(s));
|
|
|
|
|
2017-03-30 13:56:15 +00:00
|
|
|
if (print_tags) {
|
|
|
|
printf( "%s\n", s);
|
|
|
|
} else {
|
|
|
|
updateFile(sfname, s);
|
|
|
|
}
|
2017-03-30 09:23:54 +00:00
|
|
|
free(s);
|
|
|
|
}
|
2017-03-23 11:51:58 +00:00
|
|
|
xmlClose(xid);
|
|
|
|
free(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -- Yasim ----------------------------------------------------------------- */
|
|
|
|
|
2017-03-23 14:08:39 +00:00
|
|
|
const char*
|
|
|
|
yasim_wing_tag(void *xid)
|
|
|
|
{
|
2017-03-25 13:21:05 +00:00
|
|
|
void *xaid = xmlNodeGet(xid, "/airplane");
|
2017-03-23 15:10:44 +00:00
|
|
|
void *xwid, *xcid;
|
2017-03-25 13:21:05 +00:00
|
|
|
int n_wings;
|
2017-03-23 14:08:39 +00:00
|
|
|
double wing_z = 0.0;
|
|
|
|
double eye_z = 0.0;
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
if (xmlNodeTest(xaid, "rotor")) {
|
2017-03-23 15:10:44 +00:00
|
|
|
return "helicopter";
|
|
|
|
}
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
xwid = xmlNodeGet(xaid, "wing");
|
2017-03-23 14:08:39 +00:00
|
|
|
if (xwid)
|
|
|
|
{
|
|
|
|
wing_z = xmlAttributeGetDouble(xwid, "z");
|
|
|
|
xmlFree(xwid);
|
|
|
|
}
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
xcid = xmlNodeGet(xaid, "cockpit");
|
2017-03-23 14:08:39 +00:00
|
|
|
if (xcid)
|
|
|
|
{
|
|
|
|
eye_z = xmlAttributeGetDouble(xcid, "z");
|
|
|
|
xmlFree(xcid);
|
|
|
|
}
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
n_wings = xmlNodeGetNum(xaid, "mstab");
|
|
|
|
xmlFree(xaid);
|
|
|
|
|
|
|
|
// if (n_wings == 2) return "triplane";
|
|
|
|
// if (n_wings == 1) return "biplane";
|
|
|
|
|
2017-03-23 14:08:39 +00:00
|
|
|
if (wing_z > eye_z) return "high-wing";
|
2017-03-25 13:21:05 +00:00
|
|
|
return "low-wing";
|
2017-03-23 14:08:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
yasim_gear_tag(void *xid)
|
|
|
|
{
|
2017-03-24 13:11:44 +00:00
|
|
|
void *xaid = xmlNodeGet(xid, "/airplane");
|
2017-03-23 14:08:39 +00:00
|
|
|
void *xgid = xmlMarkId(xaid);
|
|
|
|
double nose_x = 0.0;
|
|
|
|
double main_x = 0.0;
|
|
|
|
int gears = 0;
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
num = xmlNodeGetNum(xaid, "gear");
|
|
|
|
for (i=0; i<num; ++i)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xaid, xgid, "gear", i) != 0)
|
|
|
|
{
|
|
|
|
if (xmlAttributeGetDouble(xgid, "y") == 0.0) {
|
|
|
|
nose_x = xmlAttributeGetDouble(xgid, "x");
|
|
|
|
} else {
|
|
|
|
main_x = xmlAttributeGetDouble(xgid, "x");
|
|
|
|
}
|
|
|
|
gears++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(xgid);
|
|
|
|
xmlFree(xaid);
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
if (gears == 0) return "skids";
|
|
|
|
else if (gears < 3 || main_x > nose_x) return "tail-dragger";
|
2017-03-23 14:08:39 +00:00
|
|
|
return "tricycle";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
yasim_gear_retract_tag(void *xid)
|
|
|
|
{
|
2017-03-24 13:11:44 +00:00
|
|
|
void *xaid = xmlNodeGet(xid, "/airplane");
|
2017-03-23 14:08:39 +00:00
|
|
|
void *xgid = xmlMarkId(xaid);
|
|
|
|
char *rv = "fixed-gear";
|
|
|
|
int found = 0;
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
num = xmlNodeGetNum(xaid, "gear");
|
|
|
|
for (i=0; i<num; ++i)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xaid, xgid, "gear", i) != 0)
|
|
|
|
{
|
|
|
|
void *xgcid = xmlMarkId(xgid);
|
|
|
|
int j, cnum = xmlNodeGetNum(xgid, "control-input");
|
|
|
|
for (j=0; j<cnum; ++j)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xgid, xgcid, "control-input", j))
|
|
|
|
{
|
|
|
|
if (!xmlAttributeCompareString(xgcid, "control", "EXTEND")) {
|
|
|
|
rv = "retractable-gear";
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(xgcid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(xgid);
|
|
|
|
xmlFree(xaid);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
yasim_gear_steering_tag(void *xid)
|
|
|
|
{
|
2017-03-24 13:11:44 +00:00
|
|
|
void *xaid = xmlNodeGet(xid, "/airplane");
|
2017-03-23 14:08:39 +00:00
|
|
|
void *xgid = xmlMarkId(xaid);
|
2017-03-25 13:21:05 +00:00
|
|
|
char *rv = NULL;
|
2017-03-23 14:08:39 +00:00
|
|
|
int found = 0;
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
num = xmlNodeGetNum(xaid, "gear");
|
|
|
|
for (i=0; i<num; ++i)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xaid, xgid, "gear", i) != 0)
|
|
|
|
{
|
|
|
|
void *xgcid = xmlMarkId(xgid);
|
|
|
|
int j, cnum = xmlNodeGetNum(xgid, "control-input");
|
|
|
|
for (j=0; j<cnum; ++j)
|
|
|
|
{
|
|
|
|
if (xmlNodeGetPos(xgid, xgcid, "control-input", j))
|
|
|
|
{
|
|
|
|
if (!xmlAttributeCompareString(xgcid, "control", "STEER")) {
|
2017-03-25 13:21:05 +00:00
|
|
|
// rv = "normal-steering";
|
2017-03-23 14:08:39 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!xmlAttributeCompareString(xgcid, "control", "CASTERING")) {
|
2017-03-25 13:21:05 +00:00
|
|
|
rv = "castering";
|
2017-03-23 14:08:39 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(xgcid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(xgid);
|
|
|
|
xmlFree(xaid);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
yasim_engines_tag(void *xid)
|
|
|
|
{
|
|
|
|
void *xeid = xmlNodeGet(xid, "/airplane");
|
|
|
|
const char* rv = "multi-engine";
|
|
|
|
int engines = 0;
|
|
|
|
|
|
|
|
if (xmlNodeTest(xeid, "propeller")) {
|
|
|
|
engines = xmlNodeGetNum(xeid, "propeller");
|
|
|
|
}
|
|
|
|
else if (xmlNodeTest(xeid, "jet")) {
|
|
|
|
engines = xmlNodeGetNum(xeid, "jet");
|
|
|
|
}
|
2017-03-23 15:10:44 +00:00
|
|
|
else if (xmlNodeTest(xeid, "rotor")) {
|
|
|
|
engines = 1;
|
|
|
|
}
|
2017-03-23 14:08:39 +00:00
|
|
|
|
|
|
|
switch (engines)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
rv = "glider";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rv = "single-engine";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rv = "twin-engine";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
rv = "three-engine";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
rv = "four-engine";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xmlFree(xeid);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
yasim_engine_tag(void *xid, char *path)
|
|
|
|
{
|
2017-03-24 12:37:23 +00:00
|
|
|
const char* rv = NULL;
|
2017-03-23 14:08:39 +00:00
|
|
|
|
|
|
|
if (xmlNodeTest(xid, "/airplane/propeller/piston-engine")) {
|
|
|
|
rv = "piston";
|
|
|
|
}
|
|
|
|
else if (xmlNodeTest(xid, "/airplane/propeller/turbine-engine")) {
|
|
|
|
rv = "turboprop";
|
|
|
|
}
|
|
|
|
else if (xmlNodeTest(xid, "/airplane/jet")) {
|
2017-03-24 12:37:23 +00:00
|
|
|
rv = "jet";
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
yasim_propulsion_tag(void *xid, char *path)
|
|
|
|
{
|
|
|
|
const char* rv = NULL;
|
|
|
|
void *xpid;
|
|
|
|
|
|
|
|
if ((xpid = xmlNodeGet(xid, "/airplane/jet")) != NULL)
|
|
|
|
{
|
|
|
|
if (xmlAttributeGetDouble(xpid, "afterburner") > 0.0) {
|
|
|
|
rv = "afterburner";
|
|
|
|
}
|
|
|
|
xmlFree(xpid);
|
2017-03-23 14:08:39 +00:00
|
|
|
}
|
2017-03-24 12:37:23 +00:00
|
|
|
else if ((xpid = xmlNodeGet(xid, "/airplane/propeller/piston-engine")) != NULL)
|
|
|
|
{
|
|
|
|
if (xmlAttributeGetInt(xpid, "supercharger") > 0) {
|
|
|
|
rv = "supercharger";
|
|
|
|
}
|
|
|
|
xmlFree(xpid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
yasim_thruster_tag(void *xid, char *path)
|
|
|
|
{
|
|
|
|
const char* rv = NULL;
|
|
|
|
void *xtid;
|
2017-03-23 14:08:39 +00:00
|
|
|
|
2017-03-24 12:37:23 +00:00
|
|
|
xtid = xmlNodeGet(xid, "/airplane/propeller/control-input");
|
|
|
|
if (xtid)
|
|
|
|
{
|
|
|
|
if (!xmlAttributeCompareString(xtid, "control", "ADVANCE")) {
|
|
|
|
rv = "variable-pitch";
|
|
|
|
} else rv = "fixed-pitch";
|
|
|
|
xmlFree(xtid);
|
|
|
|
}
|
|
|
|
|
2017-03-23 14:08:39 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-03-23 11:51:58 +00:00
|
|
|
void
|
2017-03-30 09:23:54 +00:00
|
|
|
update_metadata_yasim(char *sfname, char *path, char *aero, char *desc)
|
2017-03-23 11:51:58 +00:00
|
|
|
{
|
2017-03-24 12:37:23 +00:00
|
|
|
const char *tag;
|
2017-03-30 09:23:54 +00:00
|
|
|
char *s, *fname;
|
2017-03-23 11:51:58 +00:00
|
|
|
void *xid;
|
|
|
|
|
2017-03-23 15:10:44 +00:00
|
|
|
fname = calloc(1, strlen(path)+strlen(aero)+strlen(".xml")+1);
|
2017-03-23 11:51:58 +00:00
|
|
|
if (!fname)
|
|
|
|
{
|
|
|
|
printf("Unable to allocate memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(fname, path, strlen(path));
|
|
|
|
memcpy(fname+strlen(path), aero, strlen(aero));
|
|
|
|
memcpy(fname+strlen(path)+strlen(aero), ".xml", strlen(".xml"));
|
|
|
|
|
|
|
|
xid = xmlOpen(fname);
|
|
|
|
if (!xid)
|
|
|
|
{
|
|
|
|
printf("Yasim aero file not found: '%s'\n", fname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-30 09:23:54 +00:00
|
|
|
s = malloc(65*1024);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
sprintf(s, " <tags>\n");
|
|
|
|
PRINT("auto-generated");
|
2017-03-30 13:56:15 +00:00
|
|
|
PRINT(vendor_tag(desc ? desc : aero));
|
2017-03-30 09:23:54 +00:00
|
|
|
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, " </tags>", TS-strlen(s));
|
|
|
|
|
2017-03-30 13:56:15 +00:00
|
|
|
if (print_tags) {
|
|
|
|
printf( "%s\n", s);
|
|
|
|
} else {
|
|
|
|
updateFile(sfname, s);
|
|
|
|
}
|
2017-03-30 09:23:54 +00:00
|
|
|
free(s);
|
|
|
|
}
|
2017-03-23 11:51:58 +00:00
|
|
|
xmlClose(xid);
|
|
|
|
free(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
update_metadata(const char *fname)
|
|
|
|
{
|
|
|
|
void *xsid, *xid = xmlOpen(fname);
|
|
|
|
|
|
|
|
if (!xid)
|
|
|
|
{
|
|
|
|
printf("File not found: '%s'\n", fname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xsid = xmlNodeGet(xid, "/PropertyList/sim");
|
|
|
|
if (!xsid)
|
|
|
|
{
|
|
|
|
printf("path '/PropertyList/sim' not found in '%s'\n", fname);
|
|
|
|
xmlClose(xid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-23 15:10:44 +00:00
|
|
|
if (xmlNodeTest(xsid, "tags") == 0)
|
2017-03-23 11:51:58 +00:00
|
|
|
{
|
2017-03-25 13:21:05 +00:00
|
|
|
char *desc = NULL, *str = NULL;
|
2017-03-23 11:51:58 +00:00
|
|
|
char *path, *pend;
|
|
|
|
|
|
|
|
pend = strrchr(fname, '/');
|
|
|
|
if (!pend) pend = strrchr(fname, '\\');
|
|
|
|
if (!pend) path = strdup("./");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pend++;
|
|
|
|
path = calloc(1, pend-fname+1);
|
|
|
|
memcpy(path, fname, pend-fname);
|
|
|
|
}
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
desc = xmlNodeGetString(xsid, "description");
|
|
|
|
str = xmlNodeGetString(xsid, "aero");
|
|
|
|
if (!xmlNodeCompareString(xsid, "flight-model", "jsb")) {
|
2017-03-30 09:23:54 +00:00
|
|
|
update_metadata_jsb(fname, path, str, desc);
|
2017-03-23 11:51:58 +00:00
|
|
|
}
|
2017-03-25 13:21:05 +00:00
|
|
|
else if (!xmlNodeCompareString(xsid, "flight-model", "yasim")) {
|
2017-03-30 09:23:54 +00:00
|
|
|
update_metadata_yasim(fname, path, str, desc);
|
2017-03-23 11:51:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str = xmlNodeGetString(xsid, "flight-model");
|
|
|
|
printf("The '%s' flightmodel is unsupported at this time\n", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlFree(xsid);
|
|
|
|
|
2017-03-25 13:21:05 +00:00
|
|
|
xmlFree(desc);
|
2017-03-23 11:51:58 +00:00
|
|
|
xmlFree(str);
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("'%s' already contains metadata tags\n", fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlClose(xid);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *setFile;
|
|
|
|
|
|
|
|
if (argc == 1 || getCommandLineOption(argc, argv, "-h") ||
|
|
|
|
getCommandLineOption(argc, argv, "--help")) {
|
|
|
|
show_help();
|
|
|
|
}
|
|
|
|
|
2017-03-30 13:56:15 +00:00
|
|
|
if (getCommandLineOption(argc, argv, "-p") ||
|
|
|
|
getCommandLineOption(argc, argv, "--print")) {
|
|
|
|
print_tags = 1;
|
|
|
|
}
|
|
|
|
|
2017-03-23 11:51:58 +00:00
|
|
|
setFile = getCommandLineOption(argc, argv, "-i");
|
|
|
|
if (!setFile) {
|
|
|
|
setFile = getCommandLineOption(argc, argv, "-input");
|
|
|
|
}
|
|
|
|
if (!setFile) {
|
|
|
|
show_help();
|
|
|
|
}
|
|
|
|
|
2017-03-23 15:10:44 +00:00
|
|
|
printf("%s\n", setFile);
|
2017-03-23 11:51:58 +00:00
|
|
|
update_metadata(setFile);
|
2017-03-23 15:10:44 +00:00
|
|
|
printf("\n");
|
2017-03-23 11:51:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|