/* vi: set ts=2: * * * Eressea PB(E)M host Copyright (C) 1998-2003 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de) * Enno Rehling (enno@eressea-pbem.de) * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) * * This program may not be used, modified or distributed without * prior permission by the authors of Eressea. */ #include #include #include "xmlreport.h" /* tweakable features */ #define ENCODE_SPECIAL 1 #define RENDER_CRMESSAGES /* modules include */ #include /* attributes include */ #include #include #include #include #include /* gamecode includes */ #include "laws.h" #include "economy.h" /* kernel includes */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* util includes */ #include #include #include #include /* libxml2 includes */ #include #include #ifdef USE_ICONV #include #endif /* libc includes */ #include #include #include #include #include #define L10N(x) x static xmlChar* xml_s(const char * str) { static xmlChar buffer[1024]; const char * inbuf = str; xmlChar * outbuf = buffer; int inbytes = (int)strlen(str)+1; int outbytes = (int)sizeof(buffer); isolat1ToUTF8(outbuf, &outbytes, BAD_CAST inbuf, &inbytes); return buffer; } static xmlChar* xml_i(double number) { static char buffer[128]; sprintf(buffer, "%.0lf", number); return (xmlChar*)buffer; } static xmlNodePtr report_faction(report_context * ctx, faction * f) { xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "faction"); xmlNewProp(node, BAD_CAST "id", xml_i(f->no)); xmlNewProp(node, BAD_CAST "name", f->name); xmlNewProp(node, BAD_CAST "email", xml_s(f->email)); if (f->banner && *f->banner) xmlNewProp(node, BAD_CAST "banner", f->banner); if (f==ctx->f) { const char * s; xmlNewProp(node, BAD_CAST "locale", BAD_CAST locale_name(f->locale)); xmlNewProp(node, BAD_CAST "age", xml_i(f->age)); xmlNewProp(node, BAD_CAST "options", xml_i(f->options)); xmlNewProp(node, BAD_CAST "race", xml_s(L10N(rc_name(f->race, 0)))); xmlNewProp(node, BAD_CAST "magic", xml_s(L10N(magietypen[f->magiegebiet]))); s = get_prefix(f->attribs);; if (s) { xmlNewProp(node, BAD_CAST "prefix", xml_s(L10N(s))); } } return node; } static xmlNodePtr report_region(report_context * ctx, seen_region * sr) { const region * r = sr->r; xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "region"); xmlNewProp(node, BAD_CAST "terrain", xml_s(L10N(terrain_name(r)))); xmlNewProp(node, BAD_CAST "x", xml_i(r->x)); xmlNewProp(node, BAD_CAST "y", xml_i(r->y)); xmlNewProp(node, BAD_CAST "view", xml_s(visibility[sr->mode])); if (r->planep) { xmlNewProp(node, BAD_CAST "plane", xml_s(r->planep->name)); } if (r->land!=NULL) { xmlNewProp(node, BAD_CAST "name", xml_s(r->land->name)); } return node; } /* main function of the xmlreport. creates the header and traverses all regions */ static int report_xml(const char * filename, report_context * ctx) { xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); xmlNodePtr xmlReport = xmlNewNode(NULL, BAD_CAST "report"); const faction_list * address; region * r = ctx->first, * rend = ctx->last; for (address=ctx->addresses;address;address=address->next) { xmlAddChild(xmlReport, report_faction(ctx, address->data)); } for (;r!=rend;r=r->next) { seen_region * sr = find_seen(ctx->seen, r); if (sr!=NULL) xmlAddChild(xmlReport, report_region(ctx, sr)); } xmlDocSetRootElement(doc, xmlReport); xmlKeepBlanksDefault(0); xmlSaveFormatFileEnc(filename, doc, "utf-8", 1); xmlFreeDoc(doc); return 0; } void xmlreport_init(void) { register_reporttype("xml", &report_xml, 1<