refactoring: moving unitname to unit.c.

also removing static-string some cruft from config.c.
This commit is contained in:
Enno Rehling 2014-12-09 05:55:16 +01:00
parent 669712f04f
commit b551edbdb3
6 changed files with 26 additions and 50 deletions

View File

@ -15,6 +15,7 @@
#include "command.h"
#include <kernel/order.h>
#include <kernel/unit.h>
#include <util/umlaut.h>
#include <util/language.h>

View File

@ -1097,28 +1097,7 @@ typedef char name[OBJECTIDSIZE + 1];
static name idbuf[8];
static int nextbuf = 0;
char *estring_i(char *ibuf)
{
char *p = ibuf;
while (*p) {
if (isxspace(*(unsigned *)p) == ' ') {
*p = '~';
}
++p;
}
return ibuf;
}
char *estring(const char *s)
{
char *ibuf = idbuf[(++nextbuf) % 8];
strlcpy(ibuf, s, sizeof(name));
return estring_i(ibuf);
}
char *cstring_i(char *ibuf)
char *untilde(char *ibuf)
{
char *p = ibuf;
@ -1131,14 +1110,6 @@ char *cstring_i(char *ibuf)
return ibuf;
}
char *cstring(const char *s)
{
char *ibuf = idbuf[(++nextbuf) % 8];
strlcpy(ibuf, s, sizeof(name));
return cstring_i(ibuf);
}
building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
bool imaginary)
{
@ -1157,19 +1128,6 @@ building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
return best;
}
char *write_unitname(const unit * u, char *buffer, size_t size)
{
slprintf(buffer, size, "%s (%s)", (const char *)u->name, itoa36(u->no));
buffer[size - 1] = 0;
return buffer;
}
const char *unitname(const unit * u)
{
char *ubuf = idbuf[(++nextbuf) % 8];
return write_unitname(u, ubuf, sizeof(name));
}
/* -- Erschaffung neuer Einheiten ------------------------------ */
extern faction *dfindhash(int i);

View File

@ -34,6 +34,7 @@ extern "C" {
#define INSECT_POTION /* Spezialtrank für Insekten */
#define ORCIFICATION /* giving snotlings to the peasants gets counted */
// TODO: remove macro, move all alliance code into a module.
#define ALLIED(f1, f2) (f1==f2 || (f1->alliance && f1->alliance==f2->alliance))
/* for some good prime numbers, check http://www.math.niu.edu/~rusin/known-math/98/pi_x */
@ -179,12 +180,7 @@ extern "C" {
struct faction *getfaction(void);
char *estring(const char *s);
char *estring_i(char *s);
char *cstring(const char *s);
char *cstring_i(char *s);
const char *unitname(const struct unit *u);
char *write_unitname(const struct unit *u, char *buffer, size_t size);
char *untilde(char *s);
typedef int(*cmp_building_cb) (const struct building * b,
const struct building * a);

View File

@ -1843,3 +1843,21 @@ void remove_empty_units(void)
remove_empty_units_in_region(r);
}
}
typedef char name[OBJECTIDSIZE + 1];
static name idbuf[8];
static int nextbuf = 0;
char *write_unitname(const unit * u, char *buffer, size_t size)
{
slprintf(buffer, size, "%s (%s)", (const char *)u->name, itoa36(u->no));
buffer[size - 1] = 0;
return buffer;
}
const char *unitname(const unit * u)
{
char *ubuf = idbuf[(++nextbuf) % 8];
return write_unitname(u, ubuf, sizeof(name));
}

View File

@ -247,6 +247,9 @@ extern "C" {
struct unit *findunitr(const struct region *r, int n);
const char *unitname(const struct unit *u);
char *write_unitname(const struct unit *u, char *buffer, size_t size);
#ifdef __cplusplus
}
#endif

View File

@ -86,7 +86,7 @@ static int a_readdirection(attrib * a, void *owner, struct storage *store)
READ_TOK(store, NULL, 0);
READ_TOK(store, lbuf, sizeof(lbuf));
cstring_i(lbuf);
untilde(lbuf);
for (; dl; dl = dl->next) {
if (strcmp(lbuf, dl->oldname) == 0) {
d->keyword = _strdup(dl->name);