aboutsummaryrefslogtreecommitdiff
path: root/signpost.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-10-01 12:52:12 +0100
committerSimon Tatham <anakin@pobox.com>2017-10-01 15:18:14 +0100
commiteeb2db283de9115f7256fa4cc49597d63e06b0ab (patch)
tree48de59795d6a338ef56c5a0f1e1247478c6ad6b9 /signpost.c
parentedcf839d4c557c3993d681665829390697353344 (diff)
downloadpuzzles-eeb2db283de9115f7256fa4cc49597d63e06b0ab.zip
puzzles-eeb2db283de9115f7256fa4cc49597d63e06b0ab.tar.gz
puzzles-eeb2db283de9115f7256fa4cc49597d63e06b0ab.tar.bz2
puzzles-eeb2db283de9115f7256fa4cc49597d63e06b0ab.tar.xz
New name UI_UPDATE for interpret_move's return "".
Now midend.c directly tests the returned pointer for equality to this value, instead of checking whether it's the empty string. A minor effect of this is that games may now return a dynamically allocated empty string from interpret_move() and treat it as just another legal move description. But I don't expect anyone to be perverse enough to actually do that! The main purpose is that it avoids returning a string literal from a function whose return type is a pointer to _non-const_ char, i.e. we are now one step closer to being able to make this code base clean under -Wwrite-strings.
Diffstat (limited to 'signpost.c')
-rw-r--r--signpost.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/signpost.c b/signpost.c
index ca72768..9d782f0 100644
--- a/signpost.c
+++ b/signpost.c
@@ -1441,18 +1441,20 @@ static char *interpret_move(const game_state *state, game_ui *ui,
ui->dx = COORD(ui->cx) + TILE_SIZE/2;
ui->dy = COORD(ui->cy) + TILE_SIZE/2;
}
- return "";
+ return UI_UPDATE;
} else if (IS_CURSOR_SELECT(button)) {
if (!ui->cshow)
ui->cshow = 1;
else if (ui->dragging) {
ui->dragging = FALSE;
- if (ui->sx == ui->cx && ui->sy == ui->cy) return "";
+ if (ui->sx == ui->cx && ui->sy == ui->cy) return UI_UPDATE;
if (ui->drag_is_from) {
- if (!isvalidmove(state, 0, ui->sx, ui->sy, ui->cx, ui->cy)) return "";
+ if (!isvalidmove(state, 0, ui->sx, ui->sy, ui->cx, ui->cy))
+ return UI_UPDATE;
sprintf(buf, "L%d,%d-%d,%d", ui->sx, ui->sy, ui->cx, ui->cy);
} else {
- if (!isvalidmove(state, 0, ui->cx, ui->cy, ui->sx, ui->sy)) return "";
+ if (!isvalidmove(state, 0, ui->cx, ui->cy, ui->sx, ui->sy))
+ return UI_UPDATE;
sprintf(buf, "L%d,%d-%d,%d", ui->cx, ui->cy, ui->sx, ui->sy);
}
return dupstr(buf);
@@ -1464,7 +1466,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
ui->dy = COORD(ui->cy) + TILE_SIZE/2;
ui->drag_is_from = (button == CURSOR_SELECT) ? 1 : 0;
}
- return "";
+ return UI_UPDATE;
}
if (IS_MOUSE_DOWN(button)) {
if (ui->cshow) {
@@ -1492,29 +1494,31 @@ static char *interpret_move(const game_state *state, game_ui *ui,
ui->dx = mx;
ui->dy = my;
ui->cshow = 0;
- return "";
+ return UI_UPDATE;
} else if (IS_MOUSE_DRAG(button) && ui->dragging) {
ui->dx = mx;
ui->dy = my;
- return "";
+ return UI_UPDATE;
} else if (IS_MOUSE_RELEASE(button) && ui->dragging) {
ui->dragging = FALSE;
- if (ui->sx == x && ui->sy == y) return ""; /* single click */
+ if (ui->sx == x && ui->sy == y) return UI_UPDATE; /* single click */
if (!INGRID(state, x, y)) {
int si = ui->sy*w+ui->sx;
if (state->prev[si] == -1 && state->next[si] == -1)
- return "";
+ return UI_UPDATE;
sprintf(buf, "%c%d,%d",
(int)(ui->drag_is_from ? 'C' : 'X'), ui->sx, ui->sy);
return dupstr(buf);
}
if (ui->drag_is_from) {
- if (!isvalidmove(state, 0, ui->sx, ui->sy, x, y)) return "";
+ if (!isvalidmove(state, 0, ui->sx, ui->sy, x, y))
+ return UI_UPDATE;
sprintf(buf, "L%d,%d-%d,%d", ui->sx, ui->sy, x, y);
} else {
- if (!isvalidmove(state, 0, x, y, ui->sx, ui->sy)) return "";
+ if (!isvalidmove(state, 0, x, y, ui->sx, ui->sy))
+ return UI_UPDATE;
sprintf(buf, "L%d,%d-%d,%d", x, y, ui->sx, ui->sy);
}
return dupstr(buf);
@@ -1523,7 +1527,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
else if ((button == 'x' || button == 'X') && ui->cshow) {
int si = ui->cy*w + ui->cx;
if (state->prev[si] == -1 && state->next[si] == -1)
- return "";
+ return UI_UPDATE;
sprintf(buf, "%c%d,%d",
(int)((button == 'x') ? 'C' : 'X'), ui->cx, ui->cy);
return dupstr(buf);