forked from github/server
Merge branch 'develop' of github.com:badgerman/eressea into develop
This commit is contained in:
commit
d9ffd24ea5
|
@ -58,7 +58,7 @@
|
|||
<order name="tax" disable="yes"/>
|
||||
<order name="entertain" disable="yes"/>
|
||||
<order name="sell" disable="yes"/>
|
||||
<order name="origin" disable="yes"/>
|
||||
<order name="origin" disable="no"/>
|
||||
|
||||
<skill name="armorer" enable="true"/>
|
||||
<skill name="bow" enable="true"/>
|
||||
|
|
|
@ -21,6 +21,7 @@ IF(CMAKE_COMPILER_IS_GNUCC)
|
|||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion")
|
||||
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL")
|
||||
elseif(MSVC)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP")
|
||||
|
|
|
@ -282,7 +282,7 @@ static int tolua_faction_normalize(lua_State * L)
|
|||
plane *pl = rplane(r);
|
||||
int nx = r->x, ny = r->y;
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
adjust_coordinates(f, &nx, &ny, pl);
|
||||
tolua_pushnumber(L, (lua_Number)nx);
|
||||
tolua_pushnumber(L, (lua_Number)ny);
|
||||
return 2;
|
||||
|
@ -297,7 +297,7 @@ static int tolua_faction_set_origin(lua_State * L)
|
|||
plane *pl = rplane(r);
|
||||
int id = pl ? pl->id : 0;
|
||||
|
||||
set_origin(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
|
||||
faction_setorigin(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -317,7 +317,7 @@ static int cr_region(variant var, char *buffer, const void *userdata)
|
|||
plane *pl = rplane(r);
|
||||
int nx = r->x, ny = r->y;
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(report, &nx, &ny, pl, r);
|
||||
adjust_coordinates(report, &nx, &ny, pl);
|
||||
sprintf(buffer, "%d %d %d", nx, ny, plane_id(pl));
|
||||
return 0;
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ static int cr_regions(variant var, char *buffer, const void *userdata)
|
|||
int nx = r->x, ny = r->y;
|
||||
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
adjust_coordinates(f, &nx, &ny, pl);
|
||||
wp += sprintf(wp, "\"%d %d %d", nx, ny, z);
|
||||
for (i = 1; i != rdata->nregions; ++i) {
|
||||
r = rdata->regions[i];
|
||||
|
@ -1257,7 +1257,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
|
|||
else {
|
||||
nx = r->x, ny = r->y;
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
adjust_coordinates(f, &nx, &ny, pl);
|
||||
}
|
||||
|
||||
if (pl) {
|
||||
|
@ -1398,7 +1398,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
|
|||
plane *plx = rplane(r);
|
||||
|
||||
pnormalize(&nx, &ny, plx);
|
||||
adjust_coordinates(f, &nx, &ny, plx, r);
|
||||
adjust_coordinates(f, &nx, &ny, plx);
|
||||
fprintf(F, "SCHEMEN %d %d\n", nx, ny);
|
||||
fprintf(F, "\"%s\";Name\n", rname(r, f->locale));
|
||||
rl2 = rl2->next;
|
||||
|
@ -1623,7 +1623,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
|
|||
int nx = r->x, ny = r->y;
|
||||
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
adjust_coordinates(f, &nx, &ny, pl);
|
||||
if (!plid)
|
||||
fprintf(F, "BATTLE %d %d\n", nx, ny);
|
||||
else {
|
||||
|
|
|
@ -204,7 +204,8 @@ static void test_build_building_no_materials(CuTest *tc) {
|
|||
btype = bt_find("castle");
|
||||
assert(btype);
|
||||
set_level(u, SK_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, 0));
|
||||
u->orders = create_order(K_MAKE, u->faction->locale, 0);
|
||||
CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, u->orders));
|
||||
CuAssertPtrEquals(tc, 0, u->region->buildings);
|
||||
CuAssertPtrEquals(tc, 0, u->building);
|
||||
test_cleanup();
|
||||
|
@ -222,7 +223,8 @@ static void test_build_building_with_golem(CuTest *tc) {
|
|||
assert(btype->construction);
|
||||
|
||||
set_level(bf.u, SK_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 1, 0));
|
||||
u->orders = create_order(K_MAKE, u->faction->locale, 0);
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 1, u->orders));
|
||||
CuAssertPtrNotNull(tc, u->region->buildings);
|
||||
CuAssertIntEquals(tc, 1, u->region->buildings->size);
|
||||
CuAssertIntEquals(tc, 0, u->number);
|
||||
|
@ -245,7 +247,8 @@ static void test_build_building_success(CuTest *tc) {
|
|||
|
||||
i_change(&bf.u->items, rtype->itype, 1);
|
||||
set_level(u, SK_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, 0));
|
||||
u->orders = create_order(K_MAKE, u->faction->locale, 0);
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, u->orders));
|
||||
CuAssertPtrNotNull(tc, u->region->buildings);
|
||||
CuAssertPtrEquals(tc, u->region->buildings, u->building);
|
||||
CuAssertIntEquals(tc, 1, u->building->size);
|
||||
|
|
|
@ -257,7 +257,7 @@ unit *addplayer(region * r, faction * f)
|
|||
char buffer[32];
|
||||
|
||||
assert(f->units == NULL);
|
||||
set_origin(f, 0, r->x, r->y);
|
||||
faction_setorigin(f, 0, r->x, r->y);
|
||||
u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
|
||||
equip_items(&u->faction->items, get_equipment("new_faction"));
|
||||
equip_unit(u, get_equipment("first_unit"));
|
||||
|
@ -657,3 +657,38 @@ void remove_empty_factions(void)
|
|||
fp = &(*fp)->next;
|
||||
}
|
||||
}
|
||||
|
||||
void faction_getorigin(const faction * f, int id, int *x, int *y)
|
||||
{
|
||||
ursprung *ur;
|
||||
|
||||
assert(f && x && y);
|
||||
for (ur = f->ursprung; ur; ur = ur->next) {
|
||||
if (ur->id == id) {
|
||||
*x = ur->x;
|
||||
*y = ur->y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void faction_setorigin(faction * f, int id, int x, int y)
|
||||
{
|
||||
ursprung *ur;
|
||||
assert(f != NULL);
|
||||
for (ur = f->ursprung; ur; ur = ur->next) {
|
||||
if (ur->id == id) {
|
||||
ur->x = ur->x + x;
|
||||
ur->y = ur->y + y;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ur = calloc(1, sizeof(ursprung));
|
||||
ur->id = id;
|
||||
ur->x = x;
|
||||
ur->y = y;
|
||||
|
||||
addlist(&f->ursprung, ur);
|
||||
}
|
||||
|
||||
|
|
|
@ -154,6 +154,9 @@ extern "C" {
|
|||
void faction_setpassword(struct faction *self, const char *password);
|
||||
bool valid_race(const struct faction *f, const struct race *rc);
|
||||
|
||||
void faction_getorigin(const struct faction * f, int id, int *x, int *y);
|
||||
void faction_setorigin(struct faction * f, int id, int x, int y);
|
||||
|
||||
struct spellbook * faction_get_spellbook(struct faction *f);
|
||||
|
||||
/* skills */
|
||||
|
|
|
@ -112,15 +112,45 @@ static void test_get_monsters(CuTest *tc) {
|
|||
|
||||
static void test_set_origin(CuTest *tc) {
|
||||
faction *f;
|
||||
int x = 0, y = 0;
|
||||
plane *pl;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
pl = create_new_plane(0, "", 0, 19, 0, 19, 0);
|
||||
f = test_create_faction(0);
|
||||
CuAssertPtrEquals(tc, 0, f->ursprung);
|
||||
set_origin(f, 0, 1, 1);
|
||||
faction_setorigin(f, 0, 1, 1);
|
||||
CuAssertIntEquals(tc, 0, f->ursprung->id);
|
||||
CuAssertIntEquals(tc, 1, f->ursprung->x);
|
||||
CuAssertIntEquals(tc, 1, f->ursprung->y);
|
||||
faction_getorigin(f, 0, &x, &y);
|
||||
CuAssertIntEquals(tc, 1, x);
|
||||
CuAssertIntEquals(tc, 1, y);
|
||||
adjust_coordinates(f, &x, &y, pl);
|
||||
CuAssertIntEquals(tc, -9, x);
|
||||
CuAssertIntEquals(tc, -9, y);
|
||||
adjust_coordinates(f, &x, &y, 0);
|
||||
CuAssertIntEquals(tc, -10, x);
|
||||
CuAssertIntEquals(tc, -10, y);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_set_origin_bug(CuTest *tc) {
|
||||
faction *f;
|
||||
plane *pl;
|
||||
int x = 17, y = 10;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
pl = create_new_plane(0, "", 0, 19, 0, 19, 0);
|
||||
f = test_create_faction(0);
|
||||
faction_setorigin(f, 0, -10, 3);
|
||||
faction_setorigin(f, 0, -13, -4);
|
||||
adjust_coordinates(f, &x, &y, pl);
|
||||
CuAssertIntEquals(tc, 0, f->ursprung->id);
|
||||
CuAssertIntEquals(tc, -9, x);
|
||||
CuAssertIntEquals(tc, 2, y);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
@ -133,5 +163,6 @@ CuSuite *get_faction_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_remove_dead_factions);
|
||||
SUITE_ADD_TEST(suite, test_get_monsters);
|
||||
SUITE_ADD_TEST(suite, test_set_origin);
|
||||
SUITE_ADD_TEST(suite, test_set_origin_bug);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@ static void release_data(order_data * data)
|
|||
|
||||
void replace_order(order ** dlist, order * orig, const order * src)
|
||||
{
|
||||
assert(src);
|
||||
assert(orig);
|
||||
assert(dlist);
|
||||
while (*dlist != NULL) {
|
||||
order *dst = *dlist;
|
||||
if (dst->data == orig->data) {
|
||||
|
|
|
@ -143,6 +143,21 @@ static void test_skip_token(CuTest *tc) {
|
|||
CuAssertStrEquals(tc, 0, getstrtoken());
|
||||
}
|
||||
|
||||
static void test_replace_order(CuTest *tc) {
|
||||
order *orders = 0, *orig, *repl;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
|
||||
orig = create_order(K_MAKE, lang, 0);
|
||||
repl = create_order(K_ALLY, lang, 0);
|
||||
replace_order(&orders, orig, repl);
|
||||
CuAssertPtrEquals(tc, 0, orders);
|
||||
orders = orig;
|
||||
replace_order(&orders, orig, repl);
|
||||
CuAssertPtrNotNull(tc, orders);
|
||||
CuAssertPtrEquals(tc, 0, orders->next);
|
||||
CuAssertIntEquals(tc, getkeyword(repl), getkeyword(orders));
|
||||
}
|
||||
|
||||
CuSuite *get_order_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -152,6 +167,7 @@ CuSuite *get_order_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_parse_make_temp);
|
||||
SUITE_ADD_TEST(suite, test_parse_maketemp);
|
||||
SUITE_ADD_TEST(suite, test_init_order);
|
||||
SUITE_ADD_TEST(suite, test_replace_order);
|
||||
SUITE_ADD_TEST(suite, test_skip_token);
|
||||
SUITE_ADD_TEST(suite, test_getstrtoken);
|
||||
return suite;
|
||||
|
|
|
@ -136,7 +136,7 @@ ursprung_x(const faction * f, const plane * pl, const region * rdefault)
|
|||
}
|
||||
if (!rdefault)
|
||||
return 0;
|
||||
set_origin((faction *)f, id, rdefault->x - plane_center_x(pl),
|
||||
faction_setorigin((faction *)f, id, rdefault->x - plane_center_x(pl),
|
||||
rdefault->y - plane_center_y(pl));
|
||||
return rdefault->x - plane_center_x(pl);
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ ursprung_y(const faction * f, const plane * pl, const region * rdefault)
|
|||
}
|
||||
if (!rdefault)
|
||||
return 0;
|
||||
set_origin((faction *)f, id, rdefault->x - plane_center_x(pl),
|
||||
faction_setorigin((faction *)f, id, rdefault->x - plane_center_x(pl),
|
||||
rdefault->y - plane_center_y(pl));
|
||||
return rdefault->y - plane_center_y(pl);
|
||||
}
|
||||
|
@ -181,14 +181,15 @@ int plane_center_y(const plane * pl)
|
|||
}
|
||||
|
||||
void
|
||||
adjust_coordinates(const faction * f, int *x, int *y, const plane * pl,
|
||||
const region * r)
|
||||
adjust_coordinates(const faction * f, int *x, int *y, const plane * pl)
|
||||
{
|
||||
int nx = *x;
|
||||
int ny = *y;
|
||||
if (f) {
|
||||
nx -= ursprung_x(f, pl, r);
|
||||
ny -= ursprung_y(f, pl, r);
|
||||
int ux, uy;
|
||||
faction_getorigin(f, pl?pl->id:0, &ux, &uy);
|
||||
nx -= ux;
|
||||
ny -= uy;
|
||||
}
|
||||
if (pl) {
|
||||
int plx = plane_center_x(pl);
|
||||
|
@ -198,8 +199,8 @@ const region * r)
|
|||
int width_2 = width / 2;
|
||||
int height_2 = height / 2;
|
||||
|
||||
nx -= plx;
|
||||
ny -= ply;
|
||||
nx = (nx - plx) % width;
|
||||
ny = (ny - ply) % height;
|
||||
|
||||
if (nx < 0)
|
||||
nx = (width - (-nx) % width);
|
||||
|
@ -221,26 +222,6 @@ const region * r)
|
|||
*y = ny;
|
||||
}
|
||||
|
||||
void set_origin(faction * f, int id, int x, int y)
|
||||
{
|
||||
ursprung *ur;
|
||||
assert(f != NULL);
|
||||
for (ur = f->ursprung; ur; ur = ur->next) {
|
||||
if (ur->id == id) {
|
||||
ur->x = ur->x + x;
|
||||
ur->y = ur->y + y;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ur = calloc(1, sizeof(ursprung));
|
||||
ur->id = id;
|
||||
ur->x = x;
|
||||
ur->y = y;
|
||||
|
||||
addlist(&f->ursprung, ur);
|
||||
}
|
||||
|
||||
plane *create_new_plane(int id, const char *name, int minx, int maxx, int miny,
|
||||
int maxy, int flags)
|
||||
{
|
||||
|
|
|
@ -70,7 +70,6 @@ extern "C" {
|
|||
struct plane *getplanebyid(int id);
|
||||
int plane_center_x(const struct plane *pl);
|
||||
int plane_center_y(const struct plane *pl);
|
||||
void set_origin(struct faction *f, int id, int x, int y);
|
||||
struct plane *create_new_plane(int id, const char *name, int minx, int maxx,
|
||||
int miny, int maxy, int flags);
|
||||
struct plane *getplanebyname(const char *);
|
||||
|
@ -82,8 +81,7 @@ extern "C" {
|
|||
extern int read_plane_reference(plane ** pp, struct storage *store);
|
||||
extern int plane_width(const plane * pl);
|
||||
extern int plane_height(const plane * pl);
|
||||
void adjust_coordinates(const struct faction *f, int *x, int *y,
|
||||
const struct plane *pl, const struct region *r);
|
||||
void adjust_coordinates(const struct faction *f, int *x, int *y, const struct plane *pl);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -121,7 +121,7 @@ const char *write_regionname(const region * r, const faction * f, char *buffer,
|
|||
plane *pl = rplane(r);
|
||||
int nx = r->x, ny = r->y;
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
adjust_coordinates(f, &nx, &ny, pl);
|
||||
slprintf(buf, size, "%s (%d,%d)", rname(r, lang), nx, ny);
|
||||
}
|
||||
return buffer;
|
||||
|
|
|
@ -1250,7 +1250,7 @@ faction *readfaction(struct gamedata * data)
|
|||
READ_INT(data->store, &id);
|
||||
READ_INT(data->store, &ux);
|
||||
READ_INT(data->store, &uy);
|
||||
set_origin(f, id, ux, uy);
|
||||
faction_setorigin(f, id, ux, uy);
|
||||
}
|
||||
f->newbies = 0;
|
||||
|
||||
|
|
|
@ -2542,7 +2542,7 @@ int origin_cmd(unit * u, struct order *ord)
|
|||
px = (short)getint();
|
||||
py = (short)getint();
|
||||
|
||||
set_origin(u->faction, getplaneid(u->region), px, py);
|
||||
faction_setorigin(u->faction, getplaneid(u->region), px, py);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4382,7 +4382,7 @@ void init_processor(void)
|
|||
|
||||
p += 10;
|
||||
add_proc_order(p, K_QUIT, quit_cmd, 0, NULL);
|
||||
// add_proc_order(p, K_URSPRUNG, origin_cmd, 0, NULL);
|
||||
add_proc_order(p, K_URSPRUNG, origin_cmd, 0, NULL);
|
||||
add_proc_order(p, K_ALLY, ally_cmd, 0, NULL);
|
||||
add_proc_order(p, K_PREFIX, prefix_cmd, 0, NULL);
|
||||
add_proc_order(p, K_SETSTEALTH, setstealth_cmd, 0, NULL);
|
||||
|
|
|
@ -780,7 +780,7 @@ CuSuite *get_laws_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_force_leave_buildings);
|
||||
SUITE_ADD_TEST(suite, test_force_leave_ships);
|
||||
SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean);
|
||||
DISABLE_TEST(suite, test_peasant_luck_effect);
|
||||
SUITE_ADD_TEST(suite, test_peasant_luck_effect);
|
||||
SUITE_ADD_TEST(suite, test_luck_message);
|
||||
|
||||
return suite;
|
||||
|
|
55
src/report.c
55
src/report.c
|
@ -510,59 +510,6 @@ static void nr_spell(stream *out, spellbook_entry * sbe, const struct locale *la
|
|||
newline(out);
|
||||
}
|
||||
|
||||
void sparagraph(strlist ** SP, const char *s, unsigned int indent, char mark)
|
||||
{
|
||||
|
||||
/* Die Liste SP wird mit dem String s aufgefuellt, mit indent und einer
|
||||
* mark, falls angegeben. SP wurde also auf 0 gesetzt vor dem Aufruf.
|
||||
* Vgl. spunit (). */
|
||||
|
||||
unsigned int width;
|
||||
int firstline;
|
||||
static char buf[REPORTWIDTH + 1]; // FIXME: static return value
|
||||
|
||||
width = REPORTWIDTH - indent;
|
||||
firstline = 1;
|
||||
|
||||
while (s[0]) {
|
||||
unsigned int j = 0, i;
|
||||
|
||||
for (i=0; s[j]; j=i) {
|
||||
while (s[j] && s[j] != ' ')
|
||||
j++;
|
||||
if (j > width) {
|
||||
|
||||
/* j zeigt auf das ende der aktuellen zeile, i zeigt auf den anfang der
|
||||
* nächsten zeile. existiert ein wort am anfang der zeile, welches
|
||||
* länger als eine zeile ist, muss dieses hier abgetrennt werden. */
|
||||
|
||||
if (i == 0)
|
||||
i = width - 1;
|
||||
break;
|
||||
}
|
||||
i = j + 1;
|
||||
}
|
||||
|
||||
for (j = 0; j != indent; j++)
|
||||
buf[j] = ' ';
|
||||
|
||||
if (firstline && mark)
|
||||
buf[indent - 2] = mark;
|
||||
|
||||
for (j = 0; j != i - 1; j++)
|
||||
buf[indent + j] = s[j];
|
||||
buf[indent + j] = 0;
|
||||
|
||||
addstrlist(SP, buf);
|
||||
|
||||
if (s[i - 1] == 0)
|
||||
break;
|
||||
|
||||
s += i;
|
||||
firstline = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nr_curses_i(stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a, int self)
|
||||
{
|
||||
|
@ -1565,7 +1512,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
|
|||
int nx = r->x, ny = r->y;
|
||||
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
adjust_coordinates(f, &nx, &ny, pl);
|
||||
newline(out);
|
||||
if (pl && pl->id != 0) {
|
||||
sprintf(buf, "%s %d,%d,%d ; %s", LOC(f->locale,
|
||||
|
|
|
@ -956,9 +956,60 @@ const struct unit * u, struct skill * sv, int *dh, int days)
|
|||
return tsize;
|
||||
}
|
||||
|
||||
void lparagraph(struct strlist **SP, char *s, unsigned int indent, char mark)
|
||||
void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark)
|
||||
{
|
||||
|
||||
/* Die Liste SP wird mit dem String s aufgefuellt, mit indent und einer
|
||||
* mark, falls angegeben. SP wurde also auf 0 gesetzt vor dem Aufruf.
|
||||
* Vgl. spunit (). */
|
||||
bool firstline;
|
||||
static char buf[REPORTWIDTH + 1]; // FIXME: static buffer, artificial limit
|
||||
size_t len = strlen(s);
|
||||
|
||||
assert(width <= REPORTWIDTH);
|
||||
width -= indent;
|
||||
firstline = (mark!=0 && indent>2);
|
||||
*SP = 0;
|
||||
|
||||
while (len > 0) {
|
||||
unsigned int j;
|
||||
const char *cut = 0, *space = strchr(s, ' ');
|
||||
while (space && *space && (space - s) <= (ptrdiff_t)width) {
|
||||
cut = space;
|
||||
space = strchr(space + 1, ' ');
|
||||
if (!space && len < width) {
|
||||
cut = space = s + len;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j != indent; j++)
|
||||
buf[j] = ' ';
|
||||
|
||||
if (firstline) {
|
||||
buf[indent - 2] = mark;
|
||||
firstline = false;
|
||||
}
|
||||
if (!cut) {
|
||||
cut = s + _min(len, REPORTWIDTH);
|
||||
}
|
||||
strncpy(buf+indent, s, cut - s);
|
||||
buf[indent + (cut - s)] = 0;
|
||||
addstrlist(SP, buf); // TODO: too much string copying, cut out this function
|
||||
while (*cut == ' ') {
|
||||
++cut;
|
||||
}
|
||||
len -= (cut - s);
|
||||
s = cut;
|
||||
}
|
||||
}
|
||||
|
||||
void sparagraph(strlist ** SP, const char *s, unsigned int indent, char mark)
|
||||
{
|
||||
split_paragraph(SP, s, indent, REPORTWIDTH, mark);
|
||||
}
|
||||
|
||||
void lparagraph(struct strlist **SP, char *s, unsigned int indent, char mark)
|
||||
{
|
||||
/* Die Liste SP wird mit dem String s aufgefuellt, mit indent und einer
|
||||
* mark, falls angegeben. SP wurde also auf 0 gesetzt vor dem Aufruf.
|
||||
* Vgl. spunit (). */
|
||||
|
@ -2001,7 +2052,7 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size)
|
|||
int nx = r->x, ny = r->y;
|
||||
int named = (name && name[0]);
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
adjust_coordinates(f, &nx, &ny, pl);
|
||||
len = strlcpy(buffer, rname(r, f ? f->locale : 0), size);
|
||||
_snprintf(buffer + len, size - len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : "");
|
||||
buffer[size - 1] = 0;
|
||||
|
|
|
@ -151,6 +151,7 @@ extern "C" {
|
|||
|
||||
void addstrlist(strlist ** SP, const char *s);
|
||||
void freestrlist(strlist * s);
|
||||
void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark);
|
||||
|
||||
|
||||
#define GR_PLURAL 0x01 /* grammar: plural */
|
||||
|
|
|
@ -131,6 +131,30 @@ static void test_write_many_spaces(CuTest *tc) {
|
|||
mstream_done(&out);
|
||||
}
|
||||
|
||||
static void test_sparagraph(CuTest *tc) {
|
||||
strlist *sp = 0;
|
||||
split_paragraph(&sp, "Hello World", 0, 16, 0);
|
||||
CuAssertPtrNotNull(tc, sp);
|
||||
CuAssertStrEquals(tc, "Hello World", sp->s);
|
||||
CuAssertPtrEquals(tc, 0, sp->next);
|
||||
split_paragraph(&sp, "Hello World", 4, 16, 0);
|
||||
CuAssertPtrNotNull(tc, sp);
|
||||
CuAssertStrEquals(tc, " Hello World", sp->s);
|
||||
CuAssertPtrEquals(tc, 0, sp->next);
|
||||
split_paragraph(&sp, "Hello World", 4, 16, '*');
|
||||
CuAssertPtrNotNull(tc, sp);
|
||||
CuAssertStrEquals(tc, " * Hello World", sp->s);
|
||||
CuAssertPtrEquals(tc, 0, sp->next);
|
||||
split_paragraph(&sp, "12345678 90 12345678", 0, 8, '*');
|
||||
CuAssertPtrNotNull(tc, sp);
|
||||
CuAssertStrEquals(tc, "12345678", sp->s);
|
||||
CuAssertPtrNotNull(tc, sp->next);
|
||||
CuAssertStrEquals(tc, "90", sp->next->s);
|
||||
CuAssertPtrNotNull(tc, sp->next->next);
|
||||
CuAssertStrEquals(tc, "12345678", sp->next->next->s);
|
||||
CuAssertPtrEquals(tc, 0, sp->next->next->next);
|
||||
}
|
||||
|
||||
CuSuite *get_reports_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -139,5 +163,6 @@ CuSuite *get_reports_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_regionid);
|
||||
SUITE_ADD_TEST(suite, test_write_spaces);
|
||||
SUITE_ADD_TEST(suite, test_write_many_spaces);
|
||||
SUITE_ADD_TEST(suite, test_sparagraph);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue