Project

General

Profile

Feature #1581 ยป 0083-mapimg.c-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 07/07/2025 01:49 AM

View differences:

common/mapimg.c
mapimg.mapdef = mapdef_list_new();
fc_assert_ret(mapimg_tile_known != NULL);
fc_assert_ret(mapimg_tile_known != nullptr);
mapimg.mapimg_tile_known = mapimg_tile_known;
fc_assert_ret(mapimg_tile_terrain != NULL);
fc_assert_ret(mapimg_tile_terrain != nullptr);
mapimg.mapimg_tile_terrain = mapimg_tile_terrain;
fc_assert_ret(mapimg_tile_owner != NULL);
fc_assert_ret(mapimg_tile_owner != nullptr);
mapimg.mapimg_tile_owner = mapimg_tile_owner;
fc_assert_ret(mapimg_tile_city != NULL);
fc_assert_ret(mapimg_tile_city != nullptr);
mapimg.mapimg_tile_city = mapimg_tile_city;
fc_assert_ret(mapimg_tile_unit != NULL);
fc_assert_ret(mapimg_tile_unit != nullptr);
mapimg.mapimg_tile_unit = mapimg_tile_unit;
fc_assert_ret(mapimg_plrcolor_count != NULL);
fc_assert_ret(mapimg_plrcolor_count != nullptr);
mapimg.mapimg_plrcolor_count = mapimg_plrcolor_count;
fc_assert_ret(mapimg_plrcolor_get != NULL);
fc_assert_ret(mapimg_plrcolor_get != nullptr);
mapimg.mapimg_plrcolor_get = mapimg_plrcolor_get;
mapimg.init = TRUE;
......
if (toolkit->formats & format) {
const char *name = imageformat_name(format);
if (name != NULL) {
if (name != nullptr) {
astr_add(&str_format, "%s'%s'", separator, name);
separator = ", ";
}
......
showplr = show_player_next(showplr)) {
const char *nameptr = show_player_name(showplr);
if (nameptr != NULL) {
if (nameptr != nullptr) {
char name[10];
fc_snprintf(name, sizeof(name), "'%s'", nameptr);
......
#define NUM_MAX_MAPOPTS 2
bool mapimg_define(const char *maparg, bool check)
{
struct mapdef *pmapdef = NULL;
struct mapdef *pmapdef = nullptr;
char *mapargs[NUM_MAX_MAPARGS], *mapopts[NUM_MAX_MAPOPTS];
int nmapargs, nmapopts, i;
bool ret = TRUE;
......
MAPIMG_ASSERT_RET_VAL(mapimg_initialised(), FALSE);
if (maparg == NULL) {
if (maparg == nullptr) {
MAPIMG_LOG(_("no map definition"));
return FALSE;
}
......
****************************************************************************/
struct mapdef *mapimg_isvalid(int id)
{
struct mapdef *pmapdef = NULL;
struct mapdef *pmapdef = nullptr;
if (!mapimg_test(id)) {
/* The error message is set in mapimg_test(). */
return NULL;
return nullptr;
}
pmapdef = mapdef_list_get(mapimg.mapdef, id);
......
switch (pmapdef->status) {
case MAPIMG_STATUS_UNKNOWN:
MAPIMG_LOG(_("map definition not checked (game not started)"));
return NULL;
break;
return nullptr;
case MAPIMG_STATUS_ERROR:
MAPIMG_LOG(_("map definition deactivated: %s"), pmapdef->error);
return NULL;
break;
return nullptr;
case MAPIMG_STATUS_OK:
/* nothing */
/* Nothing */
break;
}
......
****************************************************************************/
const struct strvec *mapimg_get_format_list(void)
{
static struct strvec *format_list = NULL;
static struct strvec *format_list = nullptr;
if (NULL == format_list) {
if (format_list == nullptr) {
enum imagetool tool;
format_list = strvec_new();
......
****************************************************************************/
bool mapimg_delete(int id)
{
struct mapdef *pmapdef = NULL;
struct mapdef *pmapdef = nullptr;
if (!mapimg_test(id)) {
/* The error message is set in mapimg_test(). */
return FALSE;
}
/* delete map definition */
/* Delete map definition */
pmapdef = mapdef_list_get(mapimg.mapdef, id);
mapdef_list_remove(mapimg.mapdef, pmapdef);
......
****************************************************************************/
bool mapimg_show(int id, char *str, size_t str_len, bool detail)
{
struct mapdef *pmapdef = NULL;
struct mapdef *pmapdef = nullptr;
if (!mapimg_test(id)) {
/* The error message is set in mapimg_test(). */
......
****************************************************************************/
bool mapimg_id2str(int id, char *str, size_t str_len)
{
struct mapdef *pmapdef = NULL;
struct mapdef *pmapdef = nullptr;
if (!mapimg_test(id)) {
/* The error message is set in mapimg_test(). */
......
pimg = img_new(pmapdef, 0, 0, SIZE_X + 2,
SIZE_Y * (max_playercolor / SIZE_X) + 2);
pixel = pimg->pixel_tile(NULL, NULL, FALSE);
pixel = pimg->pixel_tile(nullptr, nullptr, FALSE);
pcolor = imgcolor_special(IMGCOLOR_OCEAN);
for (i = 0; i < MAX(max_playercolor, max_terraincolor); i++) {
......
/* Set the image format. */
pmapdef->format = format;
if (tname != NULL) {
if (tname != nullptr) {
fc_snprintf(buf, sizeof(buf), "colortest-%s", tname);
} else {
fc_snprintf(buf, sizeof(buf), "colortest");
......
BV_SET_ALL(pmapdef->player.checked_plrbv);
break;
case SHOW_PLRNAME:
/* display players as requested in the map definition */
/* Display players as requested in the map definition */
BV_CLR_ALL(pmapdef->player.checked_plrbv);
pplayer = player_by_name_prefix(pmapdef->player.name, &result);
if (pplayer != NULL) {
if (pplayer != nullptr) {
BV_SET(pmapdef->player.checked_plrbv, player_index(pplayer));
} else {
pmapdef->status = MAPIMG_STATUS_ERROR;
......
}
break;
case SHOW_PLRID:
/* display players as requested in the map definition */
/* Display players as requested in the map definition */
BV_CLR_ALL(pmapdef->player.checked_plrbv);
pplayer = player_by_number(pmapdef->player.id);
if (pplayer != NULL) {
if (pplayer != nullptr) {
BV_SET(pmapdef->player.checked_plrbv, player_index(pplayer));
} else {
pmapdef->status = MAPIMG_STATUS_ERROR;
......
if (pmapdef->layers[layer]) {
const char *lname = mapimg_layer_name(layer);
if (lname != NULL) {
if (lname != nullptr) {
cat_snprintf(mapstr, sizeof(mapstr), "%s", lname);
} else {
cat_snprintf(mapstr, sizeof(mapstr), "-");
......
****************************************************************************/
static void mapdef_destroy(struct mapdef *pmapdef)
{
if (pmapdef == NULL) {
if (pmapdef == nullptr) {
return;
}
......
*/
/************************************************************************//**
Return the definition of the requested toolkit (or NULL).
Return the definition of the requested toolkit (or nullptr).
****************************************************************************/
static const struct toolkit *img_toolkit_get(enum imagetool tool)
{
......
}
} img_toolkit_iterate_end;
return NULL;
return nullptr;
}
/************************************************************************//**
......
****************************************************************************/
static void img_destroy(struct img *pimg)
{
if (pimg != NULL) {
/* do not free pimg->def */
if (pimg != nullptr) {
/* Do not free pimg->def */
free(pimg->map);
free(pimg);
}
......
return FALSE;
}
if (!path_is_absolute(mapimgfile) && path != NULL && path[0] != '\0') {
if (!path_is_absolute(mapimgfile) && path != nullptr && path[0] != '\0') {
if (!make_dir(path, DIRMODE_DEFAULT)) {
MAPIMG_LOG(_("can't create directory"));
return FALSE;
......
static bool img_save_magickwand(const struct img *pimg,
const char *mapimgfile)
{
const struct rgbcolor *pcolor = NULL;
struct player *pplr_now = NULL, *pplr_only = NULL;
const struct rgbcolor *pcolor = nullptr;
struct player *pplr_now = nullptr, *pplr_only = nullptr;
bool ret = TRUE;
char imagefile[MAX_LEN_PATH];
char str_color[32], comment[2048] = "", title[258];
......
i = (x - plroffset) / plrwidth;
pplr_now = player_by_number(i);
if (i > player_count() || pplr_now == NULL || !pplr_now->is_alive) {
if (i > player_count() || pplr_now == nullptr || !pplr_now->is_alive) {
continue;
}
......
pcolor = imgcolor_player(i);
SET_COLOR(str_color, pcolor);
PixelSetColor(pmw[x], str_color);
} else if (pplr_only != NULL) {
} else if (pplr_only != nullptr) {
/* Display the state between pplr_only and pplr_now:
* - if allied:
* - show each second pixel
......
mindex = img_index(x, y, pimg);
pcolor = pimg->map[mindex];
if (pcolor != NULL) {
if (pcolor != nullptr) {
SET_COLOR(str_color, pcolor);
/* zoom for x */
/* Zoom for x */
for (xxx = 0; xxx < pimg->def->zoom; xxx++) {
row = x * pimg->def->zoom + xxx;
PixelSetColor(pmw[row], str_color);
......
/* y coordinate */
for (y = 0; y < pimg->imgsize.y; y++) {
/* zoom for y */
/* Zoom for y */
for (yyy = 0; yyy < pimg->def->zoom; yyy++) {
/* x coordinate */
for (x = 0; x < pimg->imgsize.x; x++) {
mindex = img_index(x, y, pimg);
pcolor = pimg->map[mindex];
/* zoom for x */
/* Zoom for x */
for (xxx = 0; xxx < pimg->def->zoom; xxx++) {
if (pcolor == NULL) {
if (pcolor == nullptr) {
pcolor = imgcolor_special(IMGCOLOR_BACKGROUND);
}
fprintf(fp, "%d %d %d\n", pcolor->r, pcolor->g, pcolor->b);
......
const struct rgbcolor *pcolor;
bv_pixel pixel;
int player_id;
struct player *pplayer = NULL;
struct player *plr_tile = NULL, *plr_city = NULL, *plr_unit = NULL;
struct player *pplayer = nullptr;
struct player *plr_tile = nullptr, *plr_city = nullptr, *plr_unit = nullptr;
enum known_type tile_knowledge = TILE_UNKNOWN;
struct terrain *pterrain = NULL;
struct terrain *pterrain = nullptr;
bool plr_knowledge = pimg->def->layers[MAPIMG_LAYER_KNOWLEDGE];
whole_map_iterate(&(wld.map), ptile) {
if (bvplayers_count(pimg->def) == 1) {
/* only one player; get player id for 'known' and 'fogofwar' */
/* Only one player; get player id for 'known' and 'fogofwar' */
players_iterate(aplayer) {
if (BV_ISSET(pimg->def->player.checked_plrbv,
player_index(aplayer))) {
......
} players_iterate_end;
}
/* known tiles */
if (plr_knowledge && pplayer != NULL && tile_knowledge == TILE_UNKNOWN) {
/* plot nothing iff tile is not known */
/* Known tiles */
if (plr_knowledge && pplayer != nullptr && tile_knowledge == TILE_UNKNOWN) {
/* Plot nothing iff tile is not known */
continue;
}
/* terrain */
/* Terrain */
pterrain = mapimg.mapimg_tile_terrain(ptile, pplayer, plr_knowledge);
if (pimg->def->layers[MAPIMG_LAYER_TERRAIN]) {
/* full terrain */
/* Full terrain */
pixel = pimg->pixel_tile(ptile, pplayer, plr_knowledge);
pcolor = imgcolor_terrain(pterrain);
img_plot_tile(pimg, ptile, pcolor, pixel);
} else {
/* basic terrain */
/* Basic terrain */
pixel = pimg->pixel_tile(ptile, pplayer, plr_knowledge);
if (is_ocean(pterrain)) {
img_plot_tile(pimg, ptile, imgcolor_special(IMGCOLOR_OCEAN), pixel);
......
}
}
/* (land) area within borders and borders */
/* (Land) area within borders and borders */
plr_tile = mapimg.mapimg_tile_owner(ptile, pplayer, plr_knowledge);
if (game.info.borders > 0 && NULL != plr_tile) {
if (game.info.borders > 0 && plr_tile != nullptr) {
player_id = player_index(plr_tile);
if (pimg->def->layers[MAPIMG_LAYER_AREA] && !is_ocean(pterrain)
&& BV_ISSET(pimg->def->player.checked_plrbv, player_id)) {
/* the tile is land and inside the players borders */
/* The tile is land and inside the players borders */
pixel = pimg->pixel_tile(ptile, pplayer, plr_knowledge);
pcolor = imgcolor_player(player_id);
img_plot_tile(pimg, ptile, pcolor, pixel);
} else if (pimg->def->layers[MAPIMG_LAYER_BORDERS]
&& (BV_ISSET(pimg->def->player.checked_plrbv, player_id)
|| (plr_knowledge && pplayer != NULL))) {
/* plot borders if player is selected or view range of the one
|| (plr_knowledge && pplayer != nullptr))) {
/* Plot borders if player is selected or view range of the one
* displayed player */
pixel = pimg->pixel_border(ptile, pplayer, plr_knowledge);
pcolor = imgcolor_player(player_id);
......
}
}
/* cities and units */
/* Cities and units */
plr_city = mapimg.mapimg_tile_city(ptile, pplayer, plr_knowledge);
plr_unit = mapimg.mapimg_tile_unit(ptile, pplayer, plr_knowledge);
if (pimg->def->layers[MAPIMG_LAYER_CITIES] && plr_city) {
player_id = player_index(plr_city);
if (BV_ISSET(pimg->def->player.checked_plrbv, player_id)
|| (plr_knowledge && pplayer != NULL)) {
/* plot cities if player is selected or view range of the one
|| (plr_knowledge && pplayer != nullptr)) {
/* Plot cities if player is selected or view range of the one
* displayed player */
pixel = pimg->pixel_city(ptile, pplayer, plr_knowledge);
pcolor = imgcolor_player(player_id);
......
} else if (pimg->def->layers[MAPIMG_LAYER_UNITS] && plr_unit) {
player_id = player_index(plr_unit);
if (BV_ISSET(pimg->def->player.checked_plrbv, player_id)
|| (plr_knowledge && pplayer != NULL)) {
/* plot units if player is selected or view range of the one
|| (plr_knowledge && pplayer != nullptr)) {
/* Plot units if player is selected or view range of the one
* displayed player */
pixel = pimg->pixel_unit(ptile, pplayer, plr_knowledge);
pcolor = imgcolor_player(player_id);
......
}
}
/* fogofwar; if only 1 player is plotted */
/* Fogofwar; if only 1 player is plotted */
if (game.info.fogofwar && pimg->def->layers[MAPIMG_LAYER_FOGOFWAR]
&& pplayer != NULL
&& pplayer != nullptr
&& tile_knowledge == TILE_KNOWN_UNSEEN) {
pixel = pimg->pixel_fogofwar(ptile, pplayer, plr_knowledge);
pcolor = NULL;
pcolor = nullptr;
img_plot_tile(pimg, ptile, pcolor, pixel);
}
} whole_map_iterate_end;
......
BV_CLR_ALL(pixel);
fc_assert_ret_val(ptile != NULL, pixel);
fc_assert_ret_val(ptile != nullptr, pixel);
if (NULL == ptile) {
/* no tile */
if (ptile == nullptr) {
/* No tile */
return pixel;
}
owner = mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
if (NULL == owner) {
/* no border */
if (owner == nullptr) {
/* No border */
return pixel;
}
......
BV_CLR_ALL(pixel);
fc_assert_ret_val(ptile != NULL, pixel);
fc_assert_ret_val(ptile != nullptr, pixel);
if (NULL == ptile) {
/* no tile */
if (ptile == nullptr) {
/* No tile */
return pixel;
}
owner = mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
if (NULL == owner) {
/* no border */
if (owner == nullptr) {
/* No border */
return pixel;
}
......
BV_CLR_ALL(pixel);
fc_assert_ret_val(ptile != NULL, pixel);
fc_assert_ret_val(ptile != nullptr, pixel);
if (NULL == ptile) {
/* no tile */
if (ptile == nullptr) {
/* No tile */
return pixel;
}
owner = mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
if (NULL == owner) {
/* no border */
if (owner == nullptr) {
/* No border */
return pixel;
}
......
static const struct rgbcolor *imgcolor_special(enum img_special imgcolor)
{
static struct rgbcolor rgb_special[] = {
{ 255, 0, 0, NULL}, /* IMGCOLOR_ERROR */
{ 255, 0, 0, nullptr}, /* IMGCOLOR_ERROR */
/* FIXME: 'ocean' and 'ground' colors are also used in the overview; the
* values are defined in colors.tilespec. */
{ 0, 0, 200, NULL}, /* IMGCOLOR_OCEAN */
{ 0, 200, 0, NULL}, /* IMGCOLOR_GROUND */
{ 0, 0, 0, NULL}, /* IMGCOLOR_BACKGROUND */
{ 255, 255, 255, NULL}, /* IMGCOLOR_TEXT */
{ 0, 0, 200, nullptr}, /* IMGCOLOR_OCEAN */
{ 0, 200, 0, nullptr}, /* IMGCOLOR_GROUND */
{ 0, 0, 0, nullptr}, /* IMGCOLOR_BACKGROUND */
{ 255, 255, 255, nullptr}, /* IMGCOLOR_TEXT */
};
fc_assert_ret_val(imgcolor >= 0 && imgcolor < ARRAY_SIZE(rgb_special),
......
{
struct player *pplayer = player_by_number(plr_id);
fc_assert_ret_val(pplayer != NULL, imgcolor_special(IMGCOLOR_ERROR));
fc_assert_ret_val(pplayer->rgb != NULL,
fc_assert_ret_val(pplayer != nullptr, imgcolor_special(IMGCOLOR_ERROR));
fc_assert_ret_val(pplayer->rgb != nullptr,
imgcolor_special(IMGCOLOR_ERROR));
return pplayer->rgb;
......
/************************************************************************//**
Return rgbcolor for terrain.
FIXME: nearly identical with get_terrain_color() in colors_common.c.
FIXME: Nearly identical with get_terrain_color() in colors_common.c.
****************************************************************************/
static const struct rgbcolor
*imgcolor_terrain(const struct terrain *pterrain)
{
fc_assert_ret_val(pterrain != NULL, imgcolor_special(IMGCOLOR_ERROR));
fc_assert_ret_val(pterrain->rgb != NULL, imgcolor_special(IMGCOLOR_ERROR));
fc_assert_ret_val(pterrain != nullptr, imgcolor_special(IMGCOLOR_ERROR));
fc_assert_ret_val(pterrain->rgb != nullptr, imgcolor_special(IMGCOLOR_ERROR));
return pterrain->rgb;
}
    (1-1/1)