fix last commit. refactoring with the MSVC IDE is prone to errors.

This commit is contained in:
Enno Rehling 2018-04-28 15:57:51 +02:00
parent 0b22b50013
commit 08663b6eb5
11 changed files with 75 additions and 75 deletions

View File

@ -95,12 +95,12 @@ static void free_nodes(node * root)
}
}
struct selist *regions_in_range(struct region *start, int maxdist,
struct selist *regions_in_range(struct region *handle_start, int maxdist,
bool(*allowed) (const struct region *, const struct region *))
{
selist * rlist = NULL;
node *root = new_node(start, 0, NULL);
node **end = &root->next;
node *root = new_node(handle_start, 0, NULL);
node **handle_end = &root->next;
node *n = root;
while (n != NULL) {
@ -125,8 +125,8 @@ struct selist *regions_in_range(struct region *start, int maxdist,
/* make sure we don't go here again, and put the region into the set for
further BFS'ing */
fset(rn, RF_MARK);
*end = new_node(rn, depth, n);
end = &(*end)->next;
*handle_end = new_node(rn, depth, n);
handle_end = &(*handle_end)->next;
}
n = n->next;
}
@ -135,17 +135,17 @@ struct selist *regions_in_range(struct region *start, int maxdist,
return rlist;
}
static region **internal_path_find(region * start, const region * target,
static region **internal_path_find(region * handle_start, const region * target,
int maxlen, bool(*allowed) (const region *, const region *))
{
static region *path[MAXDEPTH + 2]; /* STATIC_RETURN: used for return, not across calls */
direction_t d;
node *root = new_node(start, 0, NULL);
node **end = &root->next;
node *root = new_node(handle_start, 0, NULL);
node **handle_end = &root->next;
node *n = root;
bool found = false;
assert(maxlen <= MAXDEPTH);
fset(start, RF_MARK);
fset(handle_start, RF_MARK);
while (n != NULL) {
region *r = n->r;
@ -173,8 +173,8 @@ static region **internal_path_find(region * start, const region * target,
}
else {
fset(rn, RF_MARK);
*end = new_node(rn, depth, n);
end = &(*end)->next;
*handle_end = new_node(rn, depth, n);
handle_end = &(*handle_end)->next;
}
}
if (found)
@ -188,22 +188,22 @@ static region **internal_path_find(region * start, const region * target,
}
bool
path_exists(region * start, const region * target, int maxlen,
path_exists(region * handle_start, const region * target, int maxlen,
bool(*allowed) (const region *, const region *))
{
assert((!fval(start, RF_MARK) && !fval(target, RF_MARK))
assert((!fval(handle_start, RF_MARK) && !fval(target, RF_MARK))
|| !"Some Algorithm did not clear its RF_MARKs!");
if (start == target)
if (handle_start == target)
return true;
if (internal_path_find(start, target, maxlen, allowed) != NULL)
if (internal_path_find(handle_start, target, maxlen, allowed) != NULL)
return true;
return false;
}
region **path_find(region * start, const region * target, int maxlen,
region **path_find(region * handle_start, const region * target, int maxlen,
bool(*allowed) (const region *, const region *))
{
assert((!fval(start, RF_MARK) && !fval(target, RF_MARK))
assert((!fval(handle_start, RF_MARK) && !fval(target, RF_MARK))
|| !"Did you call path_init()?");
return internal_path_find(start, target, maxlen, allowed);
return internal_path_find(handle_start, target, maxlen, allowed);
}

View File

@ -22,10 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
extern struct region **path_find(struct region *start,
extern struct region **path_find(struct region *handle_start,
const struct region *target, int maxlen,
bool(*allowed) (const struct region *, const struct region *));
extern bool path_exists(struct region *start, const struct region *target,
extern bool path_exists(struct region *handle_start, const struct region *target,
int maxlen, bool(*allowed) (const struct region *,
const struct region *));
extern bool allowed_swim(const struct region *src,

View File

@ -4103,11 +4103,11 @@ static void reset_game(void)
void turn_begin(void)
{
int start = first_turn();
int handle_start = first_turn();
assert(turn >= 0);
if (turn < start) {
if (turn < handle_start) {
/* this should only happen during tests */
turn = start;
turn = handle_start;
}
++turn;
reset_game();

View File

@ -2056,11 +2056,11 @@ void free_castorder(struct castorder *co)
void add_castorder(spellrank * cll, castorder * co)
{
if (cll->begin == NULL) {
cll->end = &cll->begin;
cll->handle_end = &cll->begin;
}
*cll->end = co;
cll->end = &co->next;
*cll->handle_end = co;
cll->handle_end = &co->next;
return;
}

View File

@ -272,7 +272,7 @@ extern "C" {
typedef struct spellrank {
struct castorder *begin;
struct castorder **end;
struct castorder **handle_end;
} spellrank;
struct castorder *create_castorder(struct castorder * co, struct unit *caster,

View File

@ -848,15 +848,15 @@ static double chaosfactor(region * r)
return fval(r, RF_CHAOTIC) ? ((double)(1 + get_chaoscount(r)) / 1000.0) : 0.0;
}
static int nrand(int start, int sub)
static int nrand(int handle_start, int sub)
{
int res = 0;
do {
if (rng_int() % 100 < start)
if (rng_int() % 100 < handle_start)
res++;
start -= sub;
} while (start > 0);
handle_start -= sub;
} while (handle_start > 0);
return res;
}

View File

@ -181,7 +181,7 @@ paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_ind
char marker)
{
size_t length = REPORTWIDTH;
const char *end, *begin, *mark = 0;
const char *handle_end, *begin, *mark = 0;
if (!str) return;
/* find out if there's a mark + indent already encoded in the string. */
@ -200,7 +200,7 @@ paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_ind
else {
mark = &marker;
}
begin = end = str;
begin = handle_end = str;
do {
const char *last_space = begin;
@ -217,25 +217,25 @@ paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_ind
else {
write_spaces(out, indent + hanging_indent);
}
while (*end && end <= begin + length - indent) {
if (*end == ' ') {
last_space = end;
while (*handle_end && handle_end <= begin + length - indent) {
if (*handle_end == ' ') {
last_space = handle_end;
}
++end;
++handle_end;
}
if (*end == 0)
last_space = end;
if (*handle_end == 0)
last_space = handle_end;
if (last_space == begin) {
/* there was no space in this line. clip it */
last_space = end;
last_space = handle_end;
}
swrite(begin, sizeof(char), last_space - begin, out);
begin = last_space;
while (*begin == ' ') {
++begin;
}
if (begin > end)
begin = end;
if (begin > handle_end)
begin = handle_end;
sputs("", out);
} while (*begin);
}
@ -1939,7 +1939,7 @@ static void nr_paragraph(struct stream *out, message * m, faction * f)
typedef struct cb_data {
struct stream *out;
char *start, *writep;
char *handle_start, *writep;
size_t size;
const faction *f;
int maxtravel, counter;
@ -1948,7 +1948,7 @@ typedef struct cb_data {
static void init_cb(cb_data *data, struct stream *out, char *buffer, size_t size, const faction *f) {
data->out = out;
data->writep = buffer;
data->start = buffer;
data->handle_start = buffer;
data->size = size;
data->f = f;
data->maxtravel = 0;
@ -1965,7 +1965,7 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) {
if (travelthru_cansee(r, f, u)) {
++data->counter;
do {
size_t len, size = data->size - (data->writep - data->start);
size_t len, size = data->size - (data->writep - data->handle_start);
const char *str;
char *writep = data->writep;
@ -2000,13 +2000,13 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) {
if (len >= size || data->counter == data->maxtravel) {
/* buffer is full */
*writep = 0;
paragraph(data->out, data->start, 0, 0, 0);
data->writep = data->start;
paragraph(data->out, data->handle_start, 0, 0, 0);
data->writep = data->handle_start;
if (data->counter == data->maxtravel) {
break;
}
}
} while (data->writep == data->start);
} while (data->writep == data->handle_start);
}
}

View File

@ -2242,7 +2242,7 @@ static void eval_regions(struct opstack **stack, const void *userdata)
{ /* order -> string */
const faction *report = (const faction *)userdata;
int i = opop(stack).i;
int end, begin = opop(stack).i;
int handle_end, begin = opop(stack).i;
const arg_regions *aregs = (const arg_regions *)opop(stack).v;
char buf[256];
size_t size = sizeof(buf) - 1;
@ -2250,19 +2250,19 @@ static void eval_regions(struct opstack **stack, const void *userdata)
char *bufp = buf;
if (aregs == NULL) {
end = begin;
handle_end = begin;
}
else {
if (i >= 0)
end = begin + i;
handle_end = begin + i;
else
end = aregs->nregions + i;
handle_end = aregs->nregions + i;
}
for (i = begin; i < end; ++i) {
for (i = begin; i < handle_end; ++i) {
const char *rname = (const char *)regionname(aregs->regions[i], report);
bufp = STRLCPY(bufp, rname, size);
if (i + 1 < end && size > 2) {
if (i + 1 < handle_end && size > 2) {
strcat(bufp, ", ");
bufp += 2;
size -= 2;
@ -2295,9 +2295,9 @@ static void eval_trail(struct opstack **stack, const void *userdata)
#endif
if (aregs != NULL) {
int i, end = 0, begin = 0;
end = aregs->nregions;
for (i = begin; i < end; ++i) {
int i, handle_end = 0, begin = 0;
handle_end = aregs->nregions;
for (i = begin; i < handle_end; ++i) {
region *r = aregs->regions[i];
const char *trail = trailinto(r, lang);
const char *rn = f_regionid_s(r, report);
@ -2305,10 +2305,10 @@ static void eval_trail(struct opstack **stack, const void *userdata)
if (wrptr(&bufp, &size, snprintf(bufp, size, trail, rn)) != 0)
WARN_STATIC_BUFFER();
if (i + 2 < end) {
if (i + 2 < handle_end) {
bufp = STRLCPY(bufp, ", ", size);
}
else if (i + 1 < end) {
else if (i + 1 < handle_end) {
bufp = STRLCPY(bufp, LOC(lang, "list_and"), size);
}
}

View File

@ -136,11 +136,11 @@ static const char *getbuf_latin1(FILE * F)
continue;
}
else if (c == CONTINUE_CHAR) {
const char *end = ++bp;
while (*end && isspace(*(unsigned char *)end))
++end; /* eatwhite */
if (*end == '\0') {
bp = end;
const char *handle_end = ++bp;
while (*handle_end && isspace(*(unsigned char *)handle_end))
++handle_end; /* eatwhite */
if (*handle_end == '\0') {
bp = handle_end;
cont = true;
continue;
}
@ -303,11 +303,11 @@ static const char *getbuf_utf8(FILE * F)
}
else {
if (*bp == CONTINUE_CHAR) {
const char *end;
const char *handle_end;
eatwhite(bp + 1, &white);
end = bp + 1 + white;
if (*end == '\0') {
bp = end;
handle_end = bp + 1 + white;
if (*handle_end == '\0') {
bp = handle_end;
cont = true;
continue;
}

View File

@ -157,13 +157,13 @@ unsigned int str_hash(const char *s)
const char *str_escape(const char *str, char *buffer,
size_t len)
{
const char *start = strchr(str, '\"');
if (!start) start = strchr(str, '\\');
const char *handle_start = strchr(str, '\"');
if (!handle_start) handle_start = strchr(str, '\\');
assert(buffer);
if (start) {
if (handle_start) {
const char *p;
char *o;
size_t skip = start - str;
size_t skip = handle_start - str;
if (skip > len) {
skip = len;

View File

@ -77,7 +77,7 @@ void opstack_push(opstack ** stackp, variant data)
#define BBUFSIZE 0x10000
static struct {
char *begin;
char *end;
char *handle_end;
char *last;
char *current;
} buffer;
@ -88,9 +88,9 @@ char *balloc(size_t size)
if (!init) {
init = 1;
buffer.current = buffer.begin = malloc(BBUFSIZE * sizeof(char));
buffer.end = buffer.begin + BBUFSIZE;
buffer.handle_end = buffer.begin + BBUFSIZE;
}
assert(buffer.current + size <= buffer.end || !"balloc is out of memory");
assert(buffer.current + size <= buffer.handle_end || !"balloc is out of memory");
buffer.last = buffer.current;
buffer.current += size;
return buffer.last;