From 21bf6b41d4e7294dd419e7a6000eb857eeca4dcf Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 23 Mar 2006 20:48:49 +0000 Subject: [PATCH] Use NULL instead of (FOO *)0, it's easier to read. --- src/lib/as/as_cache.c | 8 ++++---- src/lib/commands/best.c | 2 +- src/lib/commands/bomb.c | 2 +- src/lib/commands/dist.c | 2 +- src/lib/commands/navi.c | 8 ++++---- src/lib/commands/path.c | 8 ++++---- src/lib/commands/retr.c | 16 ++++++++-------- src/lib/commands/rout.c | 8 ++++---- src/lib/commands/sect.c | 6 +++--- src/lib/commands/surv.c | 6 +++--- src/lib/commands/terr.c | 2 +- src/lib/common/bestpath.c | 4 ++-- src/lib/common/maps.c | 8 ++++---- src/lib/common/path.c | 8 ++++---- src/lib/gen/queue.c | 6 +++--- src/lib/subs/attsub.c | 4 ++-- src/lib/subs/move.c | 21 ++++++++++----------- src/lib/subs/supply.c | 9 +++------ src/lib/update/distribute.c | 2 +- src/lib/update/finish.c | 16 ++++++++-------- src/lib/update/main.c | 4 ++-- src/lib/update/nxtitemp.c | 2 +- src/lib/update/plane.c | 2 +- 23 files changed, 75 insertions(+), 79 deletions(-) diff --git a/src/lib/as/as_cache.c b/src/lib/as/as_cache.c index e5c46700..1d15c5f9 100644 --- a/src/lib/as/as_cache.c +++ b/src/lib/as/as_cache.c @@ -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! */ diff --git a/src/lib/commands/best.c b/src/lib/commands/best.c index 7297fbb1..0b4212f4 100644 --- a/src/lib/commands/best.c +++ b/src/lib/commands/best.c @@ -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); diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index 92799b95..9b3f5e97 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -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) diff --git a/src/lib/commands/dist.c b/src/lib/commands/dist.c index 656fd238..c4c68131 100644 --- a/src/lib/commands/dist.c +++ b/src/lib/commands/dist.c @@ -102,7 +102,7 @@ dist(void) path = BestDistPath(buf, §, &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)); diff --git a/src/lib/commands/navi.c b/src/lib/commands/navi.c index 9eaad136..38d9a614 100644 --- a/src/lib/commands/navi.c +++ b/src/lib/commands/navi.c @@ -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) diff --git a/src/lib/commands/path.c b/src/lib/commands/path.c index abe1b009..12ca7756 100644 --- a/src/lib/commands/path.c +++ b/src/lib/commands/path.c @@ -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, §, &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) { diff --git a/src/lib/commands/retr.c b/src/lib/commands/retr.c index 5e5086a9..1876a88b 100644 --- a/src/lib/commands/retr.c +++ b/src/lib/commands/retr.c @@ -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); } diff --git a/src/lib/commands/rout.c b/src/lib/commands/rout.c index 7295226e..4db03efb 100644 --- a/src/lib/commands/rout.c +++ b/src/lib/commands/rout.c @@ -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) diff --git a/src/lib/commands/sect.c b/src/lib/commands/sect.c index b86343b5..4058d43b 100644 --- a/src/lib/commands/sect.c +++ b/src/lib/commands/sect.c @@ -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) { diff --git a/src/lib/commands/surv.c b/src/lib/commands/surv.c index d86e8673..214c86e6 100644 --- a/src/lib/commands/surv.c +++ b/src/lib/commands/surv.c @@ -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) { diff --git a/src/lib/commands/terr.c b/src/lib/commands/terr.c index 23d7c9e4..cd3fb95d 100644 --- a/src/lib/commands/terr.c +++ b/src/lib/commands/terr.c @@ -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(§)) return RET_FAIL; diff --git a/src/lib/common/bestpath.c b/src/lib/common/bestpath.c index 4f2c4fb7..62b5158f 100644 --- a/src/lib/common/bestpath.c +++ b/src/lib/common/bestpath.c @@ -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, diff --git a/src/lib/common/maps.c b/src/lib/common/maps.c index 26af05b4..169fdefc 100644 --- a/src/lib/common/maps.c +++ b/src/lib/common/maps.c @@ -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) diff --git a/src/lib/common/path.c b/src/lib/common/path.c index 3acf7222..92537795 100644 --- a/src/lib/common/path.c +++ b/src/lib/common/path.c @@ -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 = §p[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'; diff --git a/src/lib/gen/queue.c b/src/lib/gen/queue.c index bfd36004..6bd9fadd 100644 --- a/src/lib/gen/queue.c +++ b/src/lib/gen/queue.c @@ -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; } diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 83c2dc15..516e9fee 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -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; diff --git a/src/lib/subs/move.c b/src/lib/subs/move.c index 7b83f21f..940f676b 100644 --- a/src/lib/subs/move.c +++ b/src/lib/subs/move.c @@ -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; diff --git a/src/lib/subs/supply.c b/src/lib/subs/supply.c index 7f0e805a..86915d95 100644 --- a/src/lib/subs/supply.c +++ b/src/lib/subs/supply.c @@ -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, §, &move_cost, MOB_ROAD) == - (s_char *)0) + if (!BestLandPath(buf, &dest, §, &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, §, &move_cost, MOB_ROAD) == - (s_char *)0) + if (!BestLandPath(buf, &dest, §, &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, §); - if (BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD) == - (s_char *)0) + if (!BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD)) continue; if ((land.lnd_ship >= 0) && (sect.sct_type != SCT_HARBR)) diff --git a/src/lib/update/distribute.c b/src/lib/update/distribute.c index aabe4f01..2bec6e5b 100644 --- a/src/lib/update/distribute.c +++ b/src/lib/update/distribute.c @@ -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", diff --git a/src/lib/update/finish.c b/src/lib/update/finish.c index 799f795e..4c512ef1 100644 --- a/src/lib/update/finish.c +++ b/src/lib/update/finish.c @@ -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--; diff --git a/src/lib/update/main.c b/src/lib/update/main.c index 9e90de9f..8c88b808 100644 --- a/src/lib/update/main.c +++ b/src/lib/update/main.c @@ -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 diff --git a/src/lib/update/nxtitemp.c b/src/lib/update/nxtitemp.c index e24c3d08..af2c5fd1 100644 --- a/src/lib/update/nxtitemp.c +++ b/src/lib/update/nxtitemp.c @@ -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; diff --git a/src/lib/update/plane.c b/src/lib/update/plane.c index ed59081d..ae414833 100644 --- a/src/lib/update/plane.c +++ b/src/lib/update/plane.c @@ -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;