Unicode WIP:

- creport.c compiles
This commit is contained in:
Enno Rehling 2007-07-22 09:31:39 +00:00
parent 7031e9d032
commit e63c3dc4a1
4 changed files with 45 additions and 37 deletions

View File

@ -19,7 +19,7 @@
/* tweakable features */ /* tweakable features */
#define ENCODE_SPECIAL 1 #define ENCODE_SPECIAL 1
#define RENDER_CRMESSAGES #define RENDER_CRMESSAGES
#define BUFFERSIZE 32768
/* modules include */ /* modules include */
#include <modules/score.h> #include <modules/score.h>
@ -88,7 +88,7 @@ boolean opt_cr_absolute_coords = false;
#define TAG_LOCALE "de" #define TAG_LOCALE "de"
#ifdef TAG_LOCALE #ifdef TAG_LOCALE
static const char * static const xmlChar *
crtag(const char * key) crtag(const char * key)
{ {
static const struct locale * lang = NULL; static const struct locale * lang = NULL;
@ -96,7 +96,7 @@ crtag(const char * key)
return (const xmlChar*)locale_string(lang, key); return (const xmlChar*)locale_string(lang, key);
} }
#else #else
#define crtag(x) (x) #define crtag(x) (const xmlChar*)(x)
#endif #endif
/* /*
* translation table * translation table
@ -111,7 +111,7 @@ typedef struct translation {
static translation * translation_table[TRANSMAXHASH]; static translation * translation_table[TRANSMAXHASH];
static translation * junkyard; static translation * junkyard;
static const char * static const xmlChar *
add_translation(const char * key, const xmlChar * value) add_translation(const char * key, const xmlChar * value)
{ {
int kk = ((key[0] << 5) + key[0]) % TRANSMAXHASH; int kk = ((key[0] << 5) + key[0]) % TRANSMAXHASH;
@ -250,6 +250,7 @@ print_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ)
msg = msg_curse(c, obj, typ, self); msg = msg_curse(c, obj, typ, self);
if (msg) { if (msg) {
char buf[BUFFERSIZE];
if (!header) { if (!header) {
header = 1; header = 1;
fputs("EFFECTS\n", F); fputs("EFFECTS\n", F);
@ -370,7 +371,7 @@ cr_skill(variant var, char * buffer, const void * userdata)
const faction * report = (const faction*)userdata; const faction * report = (const faction*)userdata;
skill_t sk = (skill_t)var.i; skill_t sk = (skill_t)var.i;
if (sk!=NOSKILL) sprintf(buffer, "\"%s\"", if (sk!=NOSKILL) sprintf(buffer, "\"%s\"",
add_translation(skillname(sk, NULL), skillname(sk, report->locale))); add_translation(skillnames[sk], skillname(sk, report->locale)));
else strcpy(buffer, "\"\""); else strcpy(buffer, "\"\"");
return 0; return 0;
} }
@ -381,8 +382,8 @@ cr_order(variant var, char * buffer, const void * userdata)
order * ord = (order*)var.v; order * ord = (order*)var.v;
if (ord!=NULL) { if (ord!=NULL) {
char * wp = buffer; char * wp = buffer;
char * cmd = getcommand(ord); xmlChar * cmd = getcommand(ord);
const char * rp = cmd; const xmlChar * rp = cmd;
*wp++ = '\"'; *wp++ = '\"';
while (*rp) { while (*rp) {
@ -425,7 +426,6 @@ cr_resources(variant var, char * buffer, const void * userdata)
static int static int
cr_regions(variant var, char * buffer, const void * userdata) cr_regions(variant var, char * buffer, const void * userdata)
{ {
const faction * report = (const faction*)userdata;
const arg_regions * rdata = (const arg_regions *)var.v; const arg_regions * rdata = (const arg_regions *)var.v;
char * wp = buffer; char * wp = buffer;
if (rdata!=NULL && rdata->nregions>0) { if (rdata!=NULL && rdata->nregions>0) {
@ -502,7 +502,7 @@ render_messages(FILE * F, faction * f, message_list *msgs)
{ {
struct mlist* m = msgs->begin; struct mlist* m = msgs->begin;
while (m) { while (m) {
char crbuffer[1024*32]; /* gross, wegen spionage-messages :-( */ char crbuffer[BUFFERSIZE]; /* gross, wegen spionage-messages :-( */
boolean printed = false; boolean printed = false;
const struct message_type * mtype = m->msg->type; const struct message_type * mtype = m->msg->type;
unsigned int hash = mtype->key; unsigned int hash = mtype->key;
@ -570,7 +570,7 @@ cr_output_buildings(FILE * F, building * b, const unit * owner, int fno, faction
bname = buildingtype(type, b, b->size); bname = buildingtype(type, b, b->size);
fprintf(F, "\"%s\";Typ\n", add_translation(bname, LOC(f->locale, bname))); fprintf(F, "\"%s\";Typ\n", add_translation(bname, LOC(f->locale, bname)));
fprintf(F, "\"%s\";Name\n", b->name); fprintf(F, "\"%s\";Name\n", b->name);
if (b->display && strlen(b->display)) if (b->display && b->display[0])
fprintf(F, "\"%s\";Beschr\n", b->display); fprintf(F, "\"%s\";Beschr\n", b->display);
if (b->size) if (b->size)
fprintf(F, "%d;Groesse\n", b->size); fprintf(F, "%d;Groesse\n", b->size);
@ -592,7 +592,7 @@ cr_output_ship(FILE * F, const ship * sh, const unit * u, int fcaptain, const fa
assert(sh); assert(sh);
fprintf(F, "SCHIFF %d\n", sh->no); fprintf(F, "SCHIFF %d\n", sh->no);
fprintf(F, "\"%s\";Name\n", sh->name); fprintf(F, "\"%s\";Name\n", sh->name);
if (sh->display && strlen(sh->display)) if (sh->display && sh->display[0])
fprintf(F, "\"%s\";Beschr\n", sh->display); fprintf(F, "\"%s\";Beschr\n", sh->display);
fprintf(F, "\"%s\";Typ\n", add_translation(sh->type->name[0], locale_string(f->locale, sh->type->name[0]))); fprintf(F, "\"%s\";Typ\n", add_translation(sh->type->name[0], locale_string(f->locale, sh->type->name[0])));
fprintf(F, "%d;Groesse\n", sh->size); fprintf(F, "%d;Groesse\n", sh->size);
@ -635,7 +635,7 @@ cr_output_unit(FILE * F, const region * r,
{ {
/* Race attributes are always plural and item attributes always /* Race attributes are always plural and item attributes always
* singular */ * singular */
const char * str; const xmlChar * str;
const item_type * lasttype; const item_type * lasttype;
int pr; int pr;
item *itm, *show; item *itm, *show;
@ -761,7 +761,8 @@ cr_output_unit(FILE * F, const region * r,
/* additional information for own units */ /* additional information for own units */
if (u->faction == f || omniscient(f)) { if (u->faction == f || omniscient(f)) {
order * ord; order * ord;
const char *c; const xmlChar *xc;
const char * c;
int i; int i;
i = ualias(u); i = ualias(u);
@ -781,9 +782,9 @@ cr_output_unit(FILE * F, const region * r,
fprintf(F, "%d;Tarnung\n", i); fprintf(F, "%d;Tarnung\n", i);
} }
} }
c = uprivate(u); xc = uprivate(u);
if (c) { if (xc) {
fprintf(F, "\"%s\";privat\n", c); fprintf(F, "\"%s\";privat\n", xc);
} }
c = hp_status(u); c = hp_status(u);
if (c && *c && (u->faction == f || omniscient(f))) { if (c && *c && (u->faction == f || omniscient(f))) {
@ -840,7 +841,7 @@ cr_output_unit(FILE * F, const region * r,
fprintf(F, "TALENTE\n"); fprintf(F, "TALENTE\n");
} }
fprintf(F, "%d %d;%s\n", u->number*level_days(sv->level), esk, fprintf(F, "%d %d;%s\n", u->number*level_days(sv->level), esk,
add_translation(skillname(sk, NULL), skillname(sk, f->locale))); add_translation(skillnames[sk], skillname(sk, f->locale)));
} }
} }
/* spells */ /* spells */
@ -854,14 +855,14 @@ cr_output_unit(FILE * F, const region * r,
for (;slist; slist = slist->next) { for (;slist; slist = slist->next) {
spell * sp = slist->data; spell * sp = slist->data;
if (sp->level <= t) { if (sp->level <= t) {
const char * name = add_translation(mkname("spell", sp->sname), spell_name(sp, f->locale)); const xmlChar * name = add_translation(mkname("spell", sp->sname), spell_name(sp, f->locale));
fprintf(F, "\"%s\"\n", name); fprintf(F, "\"%s\"\n", name);
} }
} }
for (i=0;i!=MAXCOMBATSPELLS;++i) { for (i=0;i!=MAXCOMBATSPELLS;++i) {
const spell * sp = mage->combatspells[i].sp; const spell * sp = mage->combatspells[i].sp;
if (sp) { if (sp) {
const char * name = add_translation(mkname("spell", sp->sname), spell_name(sp, f->locale)); const xmlChar * name = add_translation(mkname("spell", sp->sname), spell_name(sp, f->locale));
fprintf(F, "KAMPFZAUBER %d\n", i); fprintf(F, "KAMPFZAUBER %d\n", i);
fprintf(F, "\"%s\";name\n", name); fprintf(F, "\"%s\";name\n", name);
fprintf(F, "%d;level\n", mage->combatspells[i].level); fprintf(F, "%d;level\n", mage->combatspells[i].level);
@ -1006,9 +1007,9 @@ static void
cr_reportspell(FILE * F, spell *sp, const struct locale * lang) cr_reportspell(FILE * F, spell *sp, const struct locale * lang)
{ {
int k; int k;
const char * name = add_translation(mkname("spell", sp->sname), spell_name(sp, lang)); const xmlChar * name = add_translation(mkname("spell", sp->sname), spell_name(sp, lang));
fprintf(F, "ZAUBER %d\n", hashstring(spell_name(sp, default_locale))); fprintf(F, "ZAUBER %d\n", hashstring(sp->sname));
fprintf(F, "\"%s\";name\n", name); fprintf(F, "\"%s\";name\n", name);
fprintf(F, "%d;level\n", sp->level); fprintf(F, "%d;level\n", sp->level);
fprintf(F, "%d;rank\n", sp->rank); fprintf(F, "%d;rank\n", sp->rank);
@ -1125,7 +1126,7 @@ report_computer(const char * filename, report_context * ctx)
building *b; building *b;
ship *sh; ship *sh;
unit *u; unit *u;
const char * mailto = locale_string(f->locale, "mailto"); const xmlChar * mailto = locale_string(f->locale, "mailto");
const attrib * a; const attrib * a;
seen_region * sr = NULL; seen_region * sr = NULL;
#ifdef SCORE_MODULE #ifdef SCORE_MODULE
@ -1249,7 +1250,8 @@ report_computer(const char * filename, report_context * ctx)
for (a=a_find(f->attribs, &at_showitem);a && a->type==&at_showitem;a=a->next) { for (a=a_find(f->attribs, &at_showitem);a && a->type==&at_showitem;a=a->next) {
const potion_type * ptype = resource2potion(((const item_type*)a->data.v)->rtype); const potion_type * ptype = resource2potion(((const item_type*)a->data.v)->rtype);
requirement * m; requirement * m;
const char * ch, * description = NULL; const char * ch;
const xmlChar * description = NULL;
if (ptype==NULL) continue; if (ptype==NULL) continue;
m = ptype->itype->construction->materials; m = ptype->itype->construction->materials;
@ -1296,7 +1298,12 @@ report_computer(const char * filename, report_context * ctx)
#endif #endif
else fprintf(F, "REGION %d %d %d\n", region_x(r, f), region_y(r, f), r->planep->id); else fprintf(F, "REGION %d %d %d\n", region_x(r, f), region_y(r, f), r->planep->id);
} }
if (r->land && strlen(rname(r, f->locale))) fprintf(F, "\"%s\";Name\n", rname(r, f->locale)); if (r->land) {
const xmlChar * str = rname(r, f->locale);
if (str && str[0]) {
fprintf(F, "\"%s\";Name\n", str);
}
}
tname = terrain_name(r); tname = terrain_name(r);
fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale, tname))); fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale, tname)));
@ -1313,9 +1320,9 @@ report_computer(const char * filename, report_context * ctx)
} else { } else {
int stealthmod = stealth_modifier(sr->mode); int stealthmod = stealth_modifier(sr->mode);
#define RESOURCECOMPAT #define RESOURCECOMPAT
char cbuf[8192], *pos = cbuf; char cbuf[BUFFERSIZE], *pos = cbuf;
#ifdef RESOURCECOMPAT #ifdef RESOURCECOMPAT
if (r->display && strlen(r->display)) if (r->display && r->display[0])
fprintf(F, "\"%s\";Beschr\n", r->display); fprintf(F, "\"%s\";Beschr\n", r->display);
#endif #endif
if (fval(r->terrain, LAND_REGION)) { if (fval(r->terrain, LAND_REGION)) {

View File

@ -497,7 +497,7 @@ paint_status(window * wnd, const state * st)
map_region * mr = cursor_region(&st->display, &st->cursor); map_region * mr = cursor_region(&st->display, &st->cursor);
if (mr && mr->r) { if (mr && mr->r) {
if (mr->r->land) { if (mr->r->land) {
name = mr->r->land->name; name = (const char *)mr->r->land->name;
} else { } else {
name = mr->r->terrain->_name; name = mr->r->terrain->_name;
} }
@ -527,7 +527,7 @@ paint_info_region(window * wnd, const state * st)
if (mr && mr->r) { if (mr && mr->r) {
const region * r = mr->r; const region * r = mr->r;
if (r->land) { if (r->land) {
mvwaddnstr(win, line++, 1, r->land->name, size); mvwaddnstr(win, line++, 1, (char *)r->land->name, size);
} else { } else {
mvwaddnstr(win, line++, 1, r->terrain->_name, size); mvwaddnstr(win, line++, 1, r->terrain->_name, size);
} }
@ -556,7 +556,7 @@ paint_info_region(window * wnd, const state * st)
for (u=r->units;u && line<maxline;u=u->next) { for (u=r->units;u && line<maxline;u=u->next) {
if (!fval(u->faction, FFL_MARK)) { if (!fval(u->faction, FFL_MARK)) {
mvwprintw(win, line, 1, "%.4s ", itoa36(u->faction->no)); mvwprintw(win, line, 1, "%.4s ", itoa36(u->faction->no));
mvwaddnstr(win, line++, 6, u->faction->name, size-5); mvwaddnstr(win, line++, 6, (char *)u->faction->name, size-5);
fset(u->faction, FFL_MARK); fset(u->faction, FFL_MARK);
} }
} }
@ -571,7 +571,7 @@ paint_info_region(window * wnd, const state * st)
wattroff(win, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); wattroff(win, A_BOLD | COLOR_PAIR(COLOR_YELLOW));
for (u=r->units;u && line<maxline;u=u->next) { for (u=r->units;u && line<maxline;u=u->next) {
mvwprintw(win, line, 1, "%.4s ", itoa36(u->no)); mvwprintw(win, line, 1, "%.4s ", itoa36(u->no));
mvwaddnstr(win, line++, 6, u->name, size-5); mvwaddnstr(win, line++, 6, (char *)u->name, size-5);
} }
} }
} }
@ -1101,7 +1101,7 @@ handlekey(state * st, int c)
} }
} }
for (r=first;;) { for (r=first;;) {
if (findmode=='r' && r->land && r->land->name && strstr(r->land->name, locate)) { if (findmode=='r' && r->land && r->land->name && strstr((const char*)r->land->name, locate)) {
break; break;
} else if (findmode=='f') { } else if (findmode=='f') {
unit * u; unit * u;

View File

@ -66,7 +66,7 @@ class bind_orders {
public: public:
static order * next(order * node) { return node->next; } static order * next(order * node) { return node->next; }
static std::string value(order * node) { static std::string value(order * node) {
char * cmd = getcommand(node); char * cmd = (char*)getcommand(node);
std::string s(cmd); std::string s(cmd);
free(cmd); free(cmd);
return s; return s;
@ -372,7 +372,7 @@ unit_setid(unit& u, int id)
static const char * static const char *
unit_getname(const unit& u) unit_getname(const unit& u)
{ {
return u.name; return (const char *)u.name;
} }
static void static void
@ -385,7 +385,7 @@ unit_setname(unit& u, const char * name)
static const char * static const char *
unit_getinfo(const unit& u) unit_getinfo(const unit& u)
{ {
return u.display; return (const char *)u.display;
} }
static void static void
@ -478,7 +478,7 @@ unit_setmagic(unit& u, const char * type)
static void static void
unit_addorder(unit& u, const char * str) unit_addorder(unit& u, const char * str)
{ {
order * ord = parse_order(str, u.faction->locale); order * ord = parse_order((const xmlChar *)str, u.faction->locale);
addlist(&u.orders, ord); addlist(&u.orders, ord);
u.faction->lastorders = turn; u.faction->lastorders = turn;
} }
@ -568,7 +568,7 @@ unit_capacity(const struct unit& u)
static void static void
unit_addnotice(unit& u, const char * str) unit_addnotice(unit& u, const char * str)
{ {
addmessage(u.region, u.faction, str, MSG_MESSAGE, ML_IMPORTANT); addmessage(u.region, u.faction, (const xmlChar*)str, MSG_MESSAGE, ML_IMPORTANT);
} }
void void

View File

@ -666,6 +666,7 @@ main(int argc, char *argv[])
// run the main script // run the main script
if (luafile==NULL) lua_console(luaState); if (luafile==NULL) lua_console(luaState);
else { else {
char buf[MAX_PATH];
if (script_path) sprintf(buf, "%s/%s", script_path, luafile); if (script_path) sprintf(buf, "%s/%s", script_path, luafile);
else strcpy(buf, luafile); else strcpy(buf, luafile);
#ifdef LUABIND_NO_EXCEPTIONS #ifdef LUABIND_NO_EXCEPTIONS