forked from github/server
curses output doesn't deal well with non-ascii characters. "Fix" UTF8 characters by replacing them with ?
This commit is contained in:
parent
4f5bd43dcf
commit
69c0194628
49
src/gmtool.c
49
src/gmtool.c
|
@ -51,6 +51,7 @@
|
||||||
#include <items/itemtypes.h>
|
#include <items/itemtypes.h>
|
||||||
|
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
#include <util/unicode.h>
|
||||||
#include <util/lists.h>
|
#include <util/lists.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
|
@ -77,6 +78,40 @@ state *current_state = NULL;
|
||||||
|
|
||||||
static WINDOW *hstatus;
|
static WINDOW *hstatus;
|
||||||
|
|
||||||
|
static void simplify(const char *rp, char *wp) {
|
||||||
|
while (*rp) {
|
||||||
|
if (*rp & 0x80) {
|
||||||
|
while (*rp & 0x80) ++rp;
|
||||||
|
*wp++ = '?';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*wp++ = *rp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*wp = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int umvwprintw(WINDOW *win, int y, int x, const char *format, ...) {
|
||||||
|
char buffer[128];
|
||||||
|
int result;
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
result = vsnprintf(buffer, sizeof(buffer)-1, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
simplify(buffer, buffer);
|
||||||
|
|
||||||
|
return mvwaddstr(win, y, x, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
int umvwaddnstr(WINDOW *w, int y, int x, const char * str, int len) {
|
||||||
|
char buffer[128];
|
||||||
|
simplify(str, buffer);
|
||||||
|
return mvwaddnstr(w, y, x, buffer, len);
|
||||||
|
}
|
||||||
|
|
||||||
static void init_curses(void)
|
static void init_curses(void)
|
||||||
{
|
{
|
||||||
int fg, bg;
|
int fg, bg;
|
||||||
|
@ -354,7 +389,7 @@ static void paint_status(window * wnd, const state * st)
|
||||||
terrain = mr->r->terrain->_name;
|
terrain = mr->r->terrain->_name;
|
||||||
}
|
}
|
||||||
cnormalize(&st->cursor, &nx, &ny);
|
cnormalize(&st->cursor, &nx, &ny);
|
||||||
mvwprintw(win, 0, 0, "%4d %4d | %.4s | %.20s (%d)", nx, ny, terrain, name,
|
umvwprintw(win, 0, 0, "%4d %4d | %.4s | %.20s (%d)", nx, ny, terrain, name,
|
||||||
uid);
|
uid);
|
||||||
wclrtoeol(win);
|
wclrtoeol(win);
|
||||||
}
|
}
|
||||||
|
@ -377,13 +412,13 @@ static void 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, (char *)r->land->name, size);
|
umvwaddnstr(win, line++, 1, (char *)r->land->name, size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mvwaddnstr(win, line++, 1, r->terrain->_name, size);
|
umvwaddnstr(win, line++, 1, r->terrain->_name, size);
|
||||||
}
|
}
|
||||||
line++;
|
line++;
|
||||||
mvwprintw(win, line++, 1, "%s, age %d", r->terrain->_name, r->age);
|
umvwprintw(win, line++, 1, "%s, age %d", r->terrain->_name, r->age);
|
||||||
if (r->land) {
|
if (r->land) {
|
||||||
mvwprintw(win, line++, 1, "$:%6d P:%5d", rmoney(r), rpeasants(r));
|
mvwprintw(win, line++, 1, "$:%6d P:%5d", rmoney(r), rpeasants(r));
|
||||||
mvwprintw(win, line++, 1, "H:%6d %s:%5d", rhorses(r),
|
mvwprintw(win, line++, 1, "H:%6d %s:%5d", rhorses(r),
|
||||||
|
@ -398,7 +433,7 @@ static void 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 (sh = r->ships; sh && line < maxline; sh = sh->next) {
|
for (sh = r->ships; sh && line < maxline; sh = sh->next) {
|
||||||
mvwprintw(win, line, 1, "%.4s ", itoa36(sh->no));
|
mvwprintw(win, line, 1, "%.4s ", itoa36(sh->no));
|
||||||
mvwaddnstr(win, line++, 6, (char *)sh->type->_name, size - 5);
|
umvwaddnstr(win, line++, 6, (char *)sh->type->_name, size - 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (r->units && (st->info_flags & IFL_FACTIONS)) {
|
if (r->units && (st->info_flags & IFL_FACTIONS)) {
|
||||||
|
@ -409,7 +444,7 @@ static void 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, (char *)u->faction->name, size - 5);
|
umvwaddnstr(win, line++, 6, (char *)u->faction->name, size - 5);
|
||||||
fset(u->faction, FFL_MARK);
|
fset(u->faction, FFL_MARK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,7 +459,7 @@ static void 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, unit_getname(u), size - 5);
|
umvwaddnstr(win, line++, 6, unit_getname(u), size - 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue