Use NULL instead of (FOO *)0, it's easier to read.

This commit is contained in:
Markus Armbruster 2006-03-23 20:48:49 +00:00
parent 3252f8a907
commit 21bf6b41d4
23 changed files with 75 additions and 79 deletions

View file

@ -85,9 +85,9 @@ as_add_cachepath(struct as_data *adp)
/* Note we will only allocate this once. Afterwards, we just keep
* zeroing it since it's rather small and we don't need to re-allocate
* each time. */
if (fromhead == (struct as_frompath **)0) {
if (fromhead == NULL) {
fromhead = calloc(1, sizeof(struct as_frompath *) * WORLD_Y);
if (fromhead == (struct as_frompath **)0)
if (fromhead == NULL)
return;
}
@ -143,7 +143,7 @@ as_clear_cachepath(void)
int i, j;
/* Cache not used yet :) */
if (fromhead == (struct as_frompath **)0)
if (fromhead == NULL)
return;
for (j = 0; j < WORLD_Y; j++) {
@ -181,7 +181,7 @@ as_find_cachepath(coord fx, coord fy, coord tx, coord ty)
return NULL;
/* Do we have any cached? */
if (fromhead == (struct as_frompath **)0)
if (fromhead == NULL)
return NULL;
/* Yes! */

View file

@ -65,7 +65,7 @@ best(void)
if (s2.sct_own != player->cnum)
continue;
s = BestLandPath(buf, &s1, &s2, &cost, MOB_ROAD);
if (s != (s_char *)0)
if (s)
pr("Best path from %s to %s is %s (cost %1.3f)\n",
xyas(s1.sct_x, s1.sct_y, player->cnum),
xyas(s2.sct_x, s2.sct_y, player->cnum), s, cost);

View file

@ -413,7 +413,7 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target)
pr("some %s\n", ip->i_name);
}
for (;;) {
ip = whatitem((s_char *)0, "commodity to bomb? ");
ip = whatitem(NULL, "commodity to bomb? ");
if (player->aborted)
return;
if (!ip)

View file

@ -102,7 +102,7 @@ dist(void)
path = BestDistPath(buf, &sect, &dsect, &move_cost, MOB_ROAD);
if (path == (s_char *)0) {
if (!path) {
pr("No owned path from %s to %s.\n",
xyas(dsect.sct_x, dsect.sct_y, player->cnum),
xyas(sect.sct_x, sect.sct_y, player->cnum));

View file

@ -224,9 +224,9 @@ nav_map(int x, int y, int show_designations)
int i;
/* Note this is not re-entrant anyway, so we keep the buffers
around */
static u_char *bitmap = (u_char *)0;
static s_char *wmapbuf = (s_char *)0;
static s_char **wmap = (s_char **)0;
static u_char *bitmap = NULL;
static s_char *wmapbuf = NULL;
static s_char **wmap = NULL;
s_char what[64];
int changed = 0;
@ -244,7 +244,7 @@ nav_map(int x, int y, int show_designations)
wmap[i] = &wmapbuf[MAPWIDTH(1) * i];
} else if (wmap) {
free(wmap);
wmap = (s_char **)0;
wmap = NULL;
}
}
if (!bitmap)

View file

@ -61,8 +61,8 @@ path(void)
s_char *pp, *p;
/* Note this is not re-entrant anyway, so we keep the buffers
around */
static s_char *mapbuf = (s_char *)0;
static s_char **map = (s_char **)0;
static s_char *mapbuf = NULL;
static s_char **map = NULL;
double move_cost;
s_char buf[1024];
@ -75,7 +75,7 @@ path(void)
}
getsect(sect.sct_dist_x, sect.sct_dist_y, &dsect);
pp = BestDistPath(buf, &sect, &dsect, &move_cost, MOB_ROAD);
if (pp == (s_char *)0) {
if (!pp) {
pr("No path possible from %s to distribution sector %s\n",
xyas(sect.sct_x, sect.sct_y, player->cnum),
xyas(dsect.sct_x, dsect.sct_y, player->cnum));
@ -90,7 +90,7 @@ path(void)
map[i] = &mapbuf[MAPWIDTH(3) * i];
} else if (map) {
free(map);
map = (s_char **)0;
map = NULL;
}
}
if (!mapbuf || !map) {

View file

@ -67,9 +67,9 @@ retr(void)
if (player->argp[2] != NULL)
pq = getstarg(player->argp[2], "Retreat path? ", buf1);
else
pq = (s_char *)0;
pq = NULL;
if (pq != (s_char *)0) {
if (pq != NULL) {
fl = getstarg(player->argp[3],
"Retreat conditions [i|t|s|h|b|d|u|c]? ", buf2);
if (!fl)
@ -129,7 +129,7 @@ retr(void)
}
if (rflags == -1)
pq = (s_char *)0;
pq = NULL;
zero = (rflags == -1);
if (zero)
@ -141,7 +141,7 @@ retr(void)
if (zero)
memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
if (pq != (s_char *)0) {
if (pq != NULL) {
strncpy(ship.shp_rpath, pq, sizeof(ship.shp_rpath));
putship(ship.shp_uid, &ship);
}
@ -215,8 +215,8 @@ lretr(void)
if (player->argp[2] != NULL)
pq = getstarg(player->argp[2], "Retreat path? ", buf1);
else
pq = (s_char *)0;
if (pq != (s_char *)0) {
pq = NULL;
if (pq != NULL) {
fl = getstarg(player->argp[3], "Retreat conditions [i|h|b|c]? ",
buf2);
if (!fl)
@ -256,7 +256,7 @@ lretr(void)
}
if (rflags == -1)
pq = (s_char *)0;
pq = NULL;
zero = (rflags == -1);
if (zero)
@ -268,7 +268,7 @@ lretr(void)
if (zero)
memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
if (pq != (s_char *)0) {
if (pq != NULL) {
strncpy(land.lnd_rpath, pq, sizeof(land.lnd_rpath));
putland(land.lnd_uid, &land);
}

View file

@ -67,9 +67,9 @@ rout(void)
s_char buf1[1024];
/* Note this is not re-entrant anyway, so we keep the buffers
around */
static s_char *mapbuf = (s_char *)0;
static s_char **map = (s_char **)0;
static s_char *buf = (s_char *)0;
static s_char *mapbuf = NULL;
static s_char **map = NULL;
static s_char *buf = NULL;
int i;
if ((ip = whatitem(player->argp[1], "What item? ")) == 0)
@ -98,7 +98,7 @@ rout(void)
map[i] = &mapbuf[MAPWIDTH(3) * i];
} else if (map) {
free(map);
map = (s_char **)0;
map = NULL;
}
}
if (!buf)

View file

@ -62,8 +62,8 @@ sct(void)
s_char buf[1024];
/* Note this is not re-entrant anyway, so we keep the buffers
around */
static s_char *mapbuf = (s_char *)0;
static s_char **map = (s_char **)0;
static s_char *mapbuf = NULL;
static s_char **map = NULL;
nsect = 0;
if (player->argp[1] == NULL) {
@ -90,7 +90,7 @@ sct(void)
map[i] = &mapbuf[MAPWIDTH(1) * i];
} else if (map) {
free(map);
map = (s_char **)0;
map = NULL;
}
}
if (!mapbuf || !map) {

View file

@ -70,8 +70,8 @@ surv(void)
s_char *str;
/* Note this is not re-entrant anyway, so we keep the buffers
around */
static s_char *mapbuf = (s_char *)0;
static s_char **map = (s_char **)0;
static s_char *mapbuf = NULL;
static s_char **map = NULL;
nsect = 0;
if ((ptr = getstarg(player->argp[1], "commodity or variable? ", buf)) == 0)
@ -109,7 +109,7 @@ surv(void)
map[i] = &mapbuf[MAPWIDTH(1) * i];
} else if (map) {
free(map);
map = (s_char **)0;
map = NULL;
}
}
if (!mapbuf || !map) {

View file

@ -78,7 +78,7 @@ terr(void)
sprintf(prompt, "%s %d%% %s territory? ",
xyas(nstr.x, nstr.y, player->cnum),
sect.sct_effic, dchr[sect.sct_type].d_name);
if ((p = getstarg((s_char *)0, prompt, buf)) == 0)
if ((p = getstarg(NULL, prompt, buf)) == 0)
return RET_FAIL;
if (!check_sect_ok(&sect))
return RET_FAIL;

View file

@ -117,8 +117,8 @@ int dy[6] = { 0, -1, -1, 0, 1, 1 };
* would be slow. And, since world size only changes at init
* time, we can do this safely.
*/
static unsigned int *mapbuf = (unsigned int *)0;
static unsigned int **mapindex = (unsigned int **)0;
static unsigned int *mapbuf;
static unsigned int **mapindex;
s_char *
bestownedpath(s_char *bpath,

View file

@ -66,9 +66,9 @@ draw_map(int bmap, s_char origin, int map_flags, struct nstr_sect *nsp)
int i;
/* Note this is not re-entrant anyway, so we keep the buffers
around */
static u_char *bitmap = (u_char *)0;
static s_char *wmapbuf = (s_char *)0;
static s_char **wmap = (s_char **)0;
static u_char *bitmap = NULL;
static s_char *wmapbuf = NULL;
static s_char **wmap = NULL;
if (!wmapbuf)
wmapbuf = malloc((WORLD_Y * MAPWIDTH(1)) * sizeof(s_char));
@ -79,7 +79,7 @@ draw_map(int bmap, s_char origin, int map_flags, struct nstr_sect *nsp)
wmap[i] = &wmapbuf[MAPWIDTH(1) * i];
} else if (wmap) {
free(wmap);
wmap = (s_char **)0;
wmap = NULL;
}
}
if (!bitmap)

View file

@ -88,7 +88,7 @@ bp_init(void)
if (bp->adp == NULL)
return NULL;
if (neighsects == (struct sctstr **)0)
if (neighsects == NULL)
neighsects = calloc(((WORLD_X * WORLD_Y) / 2) * 6,
sizeof(struct sctstr *));
@ -201,12 +201,12 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, s_char *pp)
offset = (sy * WORLD_X + sx) / 2;
from = &sectp[offset];
if (neighsects == (struct sctstr **)0)
if (neighsects == NULL)
ssp = (struct sctstr **)&tsp[0];
else
ssp = (struct sctstr **)&neighsects[offset * 6];
for (q = 1; q <= 6; q++, ssp++) {
if (*ssp == (struct sctstr *)0) {
if (*ssp == NULL) {
/* We haven't cached this neighbor yet */
nx = x + diroff[q][0];
ny = y + diroff[q][1];
@ -360,7 +360,7 @@ BestLandPath(s_char *path,
*path = 0;
*cost = 0.0;
if (best_path(from, to, path, mob_type) < 0)
return (s_char *)0;
return NULL;
*cost = pathcost(from, path, mob_type);
length = strlen(path);
path[length] = 'h';

View file

@ -50,11 +50,11 @@ emp_insque(struct emp_qelem *elem, struct emp_qelem *queue)
void
emp_remque(struct emp_qelem *elem)
{
if (elem == (struct emp_qelem *)0)
if (!elem)
return;
if (elem->q_forw != (struct emp_qelem *)0)
if (elem->q_forw)
elem->q_forw->q_back = elem->q_back;
if (elem->q_back != (struct emp_qelem *)0)
if (elem->q_back)
elem->q_back->q_forw = elem->q_forw;
}

View file

@ -2123,7 +2123,7 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
* Procedure: find the biggest unit remaining (in
* terms of mil) and give it the casualties.
*/
biggest = (struct emp_qelem *)0;
biggest = NULL;
biggest_mil = -1;
for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
llp = (struct llist *)qp;
@ -2133,7 +2133,7 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
biggest = qp;
}
}
if (biggest == (struct emp_qelem *)0)
if (biggest == NULL)
return CASUALTY_LUMP - to_take;
llp = (struct llist *)biggest;

View file

@ -85,9 +85,9 @@ move_ground(s_char *what, struct sctstr *start, struct sctstr *end,
pr("Looking for best path to %s\n", path);
path = BestLandPath(buf2, start, &ending_sect, &total_mcost,
MOB_ROAD);
if (exploring && (path != (s_char *)0)) /* take off the 'h' */
*(path + strlen(path) - 1) = '\0';
if (path == (s_char *)0)
if (exploring && path) /* take off the 'h' */
path[strlen(path) - 1] = '\0';
if (!path)
pr("No owned path exists!\n");
else {
pr("Using best path '%s', movement cost %1.3f\n",
@ -111,11 +111,11 @@ move_ground(s_char *what, struct sctstr *start, struct sctstr *end,
for (;;) {
oldx = curx;
oldy = cury;
if (movstr == 0 || *movstr == 0) {
if (!movstr || *movstr == 0) {
if (exploring) {
map(what, curx, cury, (s_char *)0);
map(what, curx, cury, NULL);
} else {
move_map(what, curx, cury, (s_char *)0);
move_map(what, curx, cury, NULL);
}
sprintf(prompt, "<%.1f: %c %s> ", mobility,
dchr[sect.sct_type].d_mnem,
@ -128,17 +128,16 @@ move_ground(s_char *what, struct sctstr *start, struct sctstr *end,
MOB_ROAD);
} else {
pr("Invalid destination sector!\n");
movstr = (s_char *)0;
movstr = NULL;
}
if (movstr == (s_char *)0) {
if (movstr == NULL) {
pr("Can't get to %s from here!\n",
xyas(dx, dy, player->cnum));
movstr = (s_char *)0;
} else {
if ((mv_cost * weight) > mobility) {
pr("Not enough mobility to go all the way. Nothing moved.\n");
movstr = (s_char *)0;
movstr = NULL;
} else {
pr("Using best path '%s', movement cost %1.3f\n",
movstr, mv_cost);
@ -147,7 +146,7 @@ move_ground(s_char *what, struct sctstr *start, struct sctstr *end,
}
}
}
if (movstr == 0 || *movstr == 0) {
if (!movstr || *movstr == 0) {
buf2[0] = dirch[DIR_STOP];
buf2[1] = 0;
movstr = buf2;

View file

@ -199,8 +199,7 @@ s_commod(int own, int x, int y, i_type type, int total_wanted,
continue;
if (sect.sct_effic < 60)
continue;
if (BestLandPath(buf, &dest, &sect, &move_cost, MOB_ROAD) ==
(s_char *)0)
if (!BestLandPath(buf, &dest, &sect, &move_cost, MOB_ROAD))
continue;
if (!opt_NOFOOD && type == I_FOOD) {
minimum = 2 + ((etu_per_update * eatrate)
@ -275,8 +274,7 @@ s_commod(int own, int x, int y, i_type type, int total_wanted,
continue;
if (sect.sct_effic < 2)
continue;
if (BestLandPath(buf, &dest, &sect, &move_cost, MOB_ROAD) ==
(s_char *)0)
if (!BestLandPath(buf, &dest, &sect, &move_cost, MOB_ROAD))
continue;
if (!opt_NOFOOD && type == I_FOOD)
minimum = 2 + ((etu_per_update * eatrate)
@ -351,8 +349,7 @@ s_commod(int own, int x, int y, i_type type, int total_wanted,
continue;
getsect(land.lnd_x, land.lnd_y, &sect);
if (BestLandPath(buf, &dest, &sect, &move_cost, MOB_ROAD) ==
(s_char *)0)
if (!BestLandPath(buf, &dest, &sect, &move_cost, MOB_ROAD))
continue;
if ((land.lnd_ship >= 0) && (sect.sct_type != SCT_HARBR))

View file

@ -79,7 +79,7 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
return 0;
if (path == (s_char *)0) {
if (!path) {
if (sp->sct_own != 0) {
if (imex == EXPORT) /* only want this once */
wu(0, sp->sct_own, "No path to dist sector for %s\n",

View file

@ -80,12 +80,12 @@ finish_sects(int etu)
int n;
struct distinfo *infptr;
if (g_distptrs == (struct distinfo *)0) {
if (g_distptrs == NULL) {
logerror("First update since reboot, allocating buffer\n");
/* Allocate the information buffer */
g_distptrs = (struct distinfo *)(malloc((WORLD_X * WORLD_Y) *
sizeof(struct distinfo)));
if (g_distptrs == (struct distinfo *)0) {
if (g_distptrs == NULL) {
logerror("malloc failed in finish_sects.\n");
return;
}
@ -191,7 +191,7 @@ assemble_dist_paths(struct distinfo *distptrs)
infptr = &distptrs[XYOFFSET(sp->sct_x, sp->sct_y)];
/* now, get the dist sector */
dist = getsectp(sp->sct_dist_x, sp->sct_dist_y);
if (dist == (struct sctstr *)0) {
if (dist == NULL) {
logerror("Bad dist sect %d,%d for %d,%d !\n", sp->sct_dist_x,
sp->sct_dist_y, sp->sct_x, sp->sct_y);
continue;
@ -202,13 +202,13 @@ assemble_dist_paths(struct distinfo *distptrs)
path = BestDistPath(buf, dist, sp, &d, MOB_ROAD);
/* Now, we have a path */
if (path != (s_char *)0) {
if (path != NULL) {
#ifdef SAVE_FINISH_PATHS
int len;
/* Here we malloc a buffer and save it */
len = strlen(path);
infptr->path = malloc(len);
if (infptr->path == (s_char *)0) {
if (infptr->path == NULL) {
logerror("malloc failed in assemble_dist_path!\n");
return;
}
@ -236,12 +236,12 @@ ReversePath(s_char *path)
static s_char new_path[512];
int ind;
if (path == (s_char *)0)
return (s_char *)0;
if (path == NULL)
return NULL;
ind = strlen(path);
if (ind == 0)
return (s_char *)0;
return NULL;
if (path[ind - 1] == 'h')
ind--;

View file

@ -102,7 +102,7 @@ update_main(void *unused)
bp = calloc(WORLD_X * WORLD_Y * 7, sizeof(int));
for (n = 0; n < MAXNOC; n++) {
money[n] = 0;
if ((np = getnatp(n)) == (struct natstr *)0)
if (!(np = getnatp(n)))
continue;
money[n] = np->nat_money;
tpops[n] = count_pop(n);
@ -118,7 +118,7 @@ update_main(void *unused)
memset(p_sect, 0, sizeof(p_sect));
mil_dbl_pay = 0;
if ((np = getnatp(x)) == (struct natstr *)0)
if (!(np = getnatp(x)))
continue;
if (np->nat_stat == STAT_SANCT) {
#ifdef DEBUG

View file

@ -63,7 +63,7 @@ nxtitemp(struct nstr_item *np)
np->cur++;
}
gp = ef_ptr(np->type, np->cur);
if (gp == (struct genitem *)0)
if (!gp)
return 0;
selected = 1;

View file

@ -103,7 +103,7 @@ prod_plane(int etus, int natnum, int *bp, int buildem)
}
onship = 0;
shp = (struct shpstr *)0;
shp = NULL;
if (pp->pln_ship >= 0 && (buildem == 1)) {
if (pp->pln_effic >= 80)
continue;