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

View file

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

View file

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

View file

@ -272,7 +272,7 @@ extern "C" {
typedef struct spellrank { typedef struct spellrank {
struct castorder *begin; struct castorder *begin;
struct castorder **end; struct castorder **handle_end;
} spellrank; } spellrank;
struct castorder *create_castorder(struct castorder * co, struct unit *caster, 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; 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; int res = 0;
do { do {
if (rng_int() % 100 < start) if (rng_int() % 100 < handle_start)
res++; res++;
start -= sub; handle_start -= sub;
} while (start > 0); } while (handle_start > 0);
return res; return res;
} }

View file

@ -181,7 +181,7 @@ paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_ind
char marker) char marker)
{ {
size_t length = REPORTWIDTH; size_t length = REPORTWIDTH;
const char *end, *begin, *mark = 0; const char *handle_end, *begin, *mark = 0;
if (!str) return; if (!str) return;
/* find out if there's a mark + indent already encoded in the string. */ /* 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 { else {
mark = &marker; mark = &marker;
} }
begin = end = str; begin = handle_end = str;
do { do {
const char *last_space = begin; const char *last_space = begin;
@ -217,25 +217,25 @@ paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_ind
else { else {
write_spaces(out, indent + hanging_indent); write_spaces(out, indent + hanging_indent);
} }
while (*end && end <= begin + length - indent) { while (*handle_end && handle_end <= begin + length - indent) {
if (*end == ' ') { if (*handle_end == ' ') {
last_space = end; last_space = handle_end;
} }
++end; ++handle_end;
} }
if (*end == 0) if (*handle_end == 0)
last_space = end; last_space = handle_end;
if (last_space == begin) { if (last_space == begin) {
/* there was no space in this line. clip it */ /* there was no space in this line. clip it */
last_space = end; last_space = handle_end;
} }
swrite(begin, sizeof(char), last_space - begin, out); swrite(begin, sizeof(char), last_space - begin, out);
begin = last_space; begin = last_space;
while (*begin == ' ') { while (*begin == ' ') {
++begin; ++begin;
} }
if (begin > end) if (begin > handle_end)
begin = end; begin = handle_end;
sputs("", out); sputs("", out);
} while (*begin); } while (*begin);
} }
@ -1939,7 +1939,7 @@ static void nr_paragraph(struct stream *out, message * m, faction * f)
typedef struct cb_data { typedef struct cb_data {
struct stream *out; struct stream *out;
char *start, *writep; char *handle_start, *writep;
size_t size; size_t size;
const faction *f; const faction *f;
int maxtravel, counter; 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) { static void init_cb(cb_data *data, struct stream *out, char *buffer, size_t size, const faction *f) {
data->out = out; data->out = out;
data->writep = buffer; data->writep = buffer;
data->start = buffer; data->handle_start = buffer;
data->size = size; data->size = size;
data->f = f; data->f = f;
data->maxtravel = 0; data->maxtravel = 0;
@ -1965,7 +1965,7 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) {
if (travelthru_cansee(r, f, u)) { if (travelthru_cansee(r, f, u)) {
++data->counter; ++data->counter;
do { 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; const char *str;
char *writep = data->writep; 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) { if (len >= size || data->counter == data->maxtravel) {
/* buffer is full */ /* buffer is full */
*writep = 0; *writep = 0;
paragraph(data->out, data->start, 0, 0, 0); paragraph(data->out, data->handle_start, 0, 0, 0);
data->writep = data->start; data->writep = data->handle_start;
if (data->counter == data->maxtravel) { if (data->counter == data->maxtravel) {
break; 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 */ { /* order -> string */
const faction *report = (const faction *)userdata; const faction *report = (const faction *)userdata;
int i = opop(stack).i; 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; const arg_regions *aregs = (const arg_regions *)opop(stack).v;
char buf[256]; char buf[256];
size_t size = sizeof(buf) - 1; size_t size = sizeof(buf) - 1;
@ -2250,19 +2250,19 @@ static void eval_regions(struct opstack **stack, const void *userdata)
char *bufp = buf; char *bufp = buf;
if (aregs == NULL) { if (aregs == NULL) {
end = begin; handle_end = begin;
} }
else { else {
if (i >= 0) if (i >= 0)
end = begin + i; handle_end = begin + i;
else 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); const char *rname = (const char *)regionname(aregs->regions[i], report);
bufp = STRLCPY(bufp, rname, size); bufp = STRLCPY(bufp, rname, size);
if (i + 1 < end && size > 2) { if (i + 1 < handle_end && size > 2) {
strcat(bufp, ", "); strcat(bufp, ", ");
bufp += 2; bufp += 2;
size -= 2; size -= 2;
@ -2295,9 +2295,9 @@ static void eval_trail(struct opstack **stack, const void *userdata)
#endif #endif
if (aregs != NULL) { if (aregs != NULL) {
int i, end = 0, begin = 0; int i, handle_end = 0, begin = 0;
end = aregs->nregions; handle_end = aregs->nregions;
for (i = begin; i < end; ++i) { for (i = begin; i < handle_end; ++i) {
region *r = aregs->regions[i]; region *r = aregs->regions[i];
const char *trail = trailinto(r, lang); const char *trail = trailinto(r, lang);
const char *rn = f_regionid_s(r, report); 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) if (wrptr(&bufp, &size, snprintf(bufp, size, trail, rn)) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (i + 2 < end) { if (i + 2 < handle_end) {
bufp = STRLCPY(bufp, ", ", size); bufp = STRLCPY(bufp, ", ", size);
} }
else if (i + 1 < end) { else if (i + 1 < handle_end) {
bufp = STRLCPY(bufp, LOC(lang, "list_and"), size); bufp = STRLCPY(bufp, LOC(lang, "list_and"), size);
} }
} }

View file

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

View file

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

View file

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