diff options
| author | Simon Tatham <anakin@pobox.com> | 2017-10-01 12:52:12 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2017-10-01 15:18:14 +0100 |
| commit | eeb2db283de9115f7256fa4cc49597d63e06b0ab (patch) | |
| tree | 48de59795d6a338ef56c5a0f1e1247478c6ad6b9 /pegs.c | |
| parent | edcf839d4c557c3993d681665829390697353344 (diff) | |
| download | puzzles-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 'pegs.c')
| -rw-r--r-- | pegs.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -848,7 +848,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->dx = x; ui->dy = y; ui->cur_visible = ui->cur_jumping = 0; - return ""; /* ui modified */ + return UI_UPDATE; } } else if (button == LEFT_DRAG && ui->dragging) { /* @@ -856,7 +856,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, */ ui->dx = x; ui->dy = y; - return ""; /* ui modified */ + return UI_UPDATE; } else if (button == LEFT_RELEASE && ui->dragging) { int tx, ty, dx, dy; @@ -868,18 +868,18 @@ static char *interpret_move(const game_state *state, game_ui *ui, tx = FROMCOORD(x); ty = FROMCOORD(y); if (tx < 0 || tx >= w || ty < 0 || ty >= h) - return ""; /* target out of range */ + return UI_UPDATE; /* target out of range */ dx = tx - ui->sx; dy = ty - ui->sy; if (max(abs(dx),abs(dy)) != 2 || min(abs(dx),abs(dy)) != 0) - return ""; /* move length was wrong */ + return UI_UPDATE; /* move length was wrong */ dx /= 2; dy /= 2; if (state->grid[ty*w+tx] != GRID_HOLE || state->grid[(ty-dy)*w+(tx-dx)] != GRID_PEG || state->grid[ui->sy*w+ui->sx] != GRID_PEG) - return ""; /* grid contents were invalid */ + return UI_UPDATE; /* grid contents were invalid */ /* * We have a valid move. Encode it simply as source and @@ -899,7 +899,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->cur_x = cx; ui->cur_y = cy; } - return ""; + return UI_UPDATE; } else { int dx, dy, mx, my, jx, jy; @@ -922,21 +922,21 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->cur_x = jx; ui->cur_y = jy; return dupstr(buf); } - return ""; + return UI_UPDATE; } } else if (IS_CURSOR_SELECT(button)) { if (!ui->cur_visible) { ui->cur_visible = 1; - return ""; + return UI_UPDATE; } if (ui->cur_jumping) { ui->cur_jumping = 0; - return ""; + return UI_UPDATE; } if (state->grid[ui->cur_y*w+ui->cur_x] == GRID_PEG) { /* cursor is on peg: next arrow-move wil jump. */ ui->cur_jumping = 1; - return ""; + return UI_UPDATE; } return NULL; } |