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.
This commit is contained in:
Simon Tatham
2017-10-01 12:52:12 +01:00
parent edcf839d4c
commit eeb2db283d
41 changed files with 217 additions and 201 deletions

22
guess.c
View File

@ -779,7 +779,7 @@ static char *interpret_move(const game_state *from, game_ui *ui,
*/
if (button == 'l' || button == 'L') {
ui->show_labels = !ui->show_labels;
return "";
return UI_UPDATE;
}
if (from->solved) return NULL;
@ -836,13 +836,13 @@ static char *interpret_move(const game_state *from, game_ui *ui,
ui->drag_y = y;
debug(("Start dragging, col = %d, (%d,%d)",
ui->drag_col, ui->drag_x, ui->drag_y));
ret = "";
ret = UI_UPDATE;
}
} else if (button == LEFT_DRAG && ui->drag_col) {
ui->drag_x = x;
ui->drag_y = y;
debug(("Keep dragging, (%d,%d)", ui->drag_x, ui->drag_y));
ret = "";
ret = UI_UPDATE;
} else if (button == LEFT_RELEASE && ui->drag_col) {
if (over_guess > -1) {
debug(("Dropping colour %d onto guess peg %d",
@ -859,13 +859,13 @@ static char *interpret_move(const game_state *from, game_ui *ui,
ui->drag_opeg = -1;
ui->display_cur = 0;
debug(("Stop dragging."));
ret = "";
ret = UI_UPDATE;
} else if (button == RIGHT_BUTTON) {
if (over_guess > -1) {
/* we use ths feedback in the game_ui to signify
* 'carry this peg to the next guess as well'. */
ui->holds[over_guess] = 1 - ui->holds[over_guess];
ret = "";
ret = UI_UPDATE;
}
} else if (button == LEFT_RELEASE && over_hint && ui->markable) {
/* NB this won't trigger if on the end of a drag; that's on
@ -880,10 +880,10 @@ static char *interpret_move(const game_state *from, game_ui *ui,
ui->colour_cur++;
if (button == CURSOR_UP && ui->colour_cur > 0)
ui->colour_cur--;
ret = "";
ret = UI_UPDATE;
} else if (button == 'h' || button == 'H' || button == '?') {
compute_hint(from, ui);
ret = "";
ret = UI_UPDATE;
} else if (button == CURSOR_LEFT || button == CURSOR_RIGHT) {
int maxcur = from->params.npegs;
if (ui->markable) maxcur++;
@ -893,25 +893,25 @@ static char *interpret_move(const game_state *from, game_ui *ui,
ui->peg_cur++;
if (button == CURSOR_LEFT && ui->peg_cur > 0)
ui->peg_cur--;
ret = "";
ret = UI_UPDATE;
} else if (IS_CURSOR_SELECT(button)) {
ui->display_cur = 1;
if (ui->peg_cur == from->params.npegs) {
ret = encode_move(from, ui);
} else {
set_peg(&from->params, ui, ui->peg_cur, ui->colour_cur+1);
ret = "";
ret = UI_UPDATE;
}
} else if (button == 'D' || button == 'd' || button == '\b') {
ui->display_cur = 1;
set_peg(&from->params, ui, ui->peg_cur, 0);
ret = "";
ret = UI_UPDATE;
} else if (button == CURSOR_SELECT2) {
if (ui->peg_cur == from->params.npegs)
return NULL;
ui->display_cur = 1;
ui->holds[ui->peg_cur] = 1 - ui->holds[ui->peg_cur];
ret = "";
ret = UI_UPDATE;
}
return ret;
}