mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
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:
20
pegs.c
20
pegs.c
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user