diff -urd -X freeciv.clean/diff_ignore part_app/common/game.c work/common/game.c --- part_app/common/game.c Thu Feb 21 10:15:30 2002 +++ work/common/game.c Sat Feb 23 10:31:49 2002 @@ -150,13 +150,12 @@ { printf (".know (%d)\n ", p); WRITE_MAP_DATA("%c", - pcmap->claims[map_inx(x, y)]. - know & (1u << p) ? 'X' : '-'); - + TEST_BIT(pcmap->claims[map_inx(x, y)].know, + p) ? 'X' : '-'); printf (".cities (%d)\n ", p); WRITE_MAP_DATA("%c", - pcmap->claims[map_inx(x, y)]. - cities & (1u << p) ? 'O' : '-'); + TEST_BIT(pcmap->claims[map_inx(x, y)].cities, + p) ? 'O' : '-'); } } @@ -264,7 +263,7 @@ nextedge->y = y; nextedge++; (pcmap->player_landarea[owner])++; - if (pclaim->cities & (1u << owner)) { + if (TEST_BIT(pclaim->cities, owner)) { (pcmap->player_owndarea[owner])++; } pclaim->know = ptile->known; @@ -314,7 +313,7 @@ j = map_inx(mx, my); pclaim = &(pcmap->claims[j]); - if (pclaim->know & (1u << owner)) { + if (TEST_BIT(pclaim->know, owner)) { if (pclaim->when == 0) { pclaim->when = turn + 1; pclaim->whom = owner; @@ -322,7 +321,7 @@ nextedge->y = my; nextedge++; (pcmap->player_landarea[owner])++; - if (pclaim->cities & (1u << owner)) { + if (TEST_BIT(pclaim->cities, owner)) { (pcmap->player_owndarea[owner])++; } accum++; @@ -330,7 +329,7 @@ (pclaim->whom != no_owner) && (pclaim->whom != owner)) { other = pclaim->whom; - if (pclaim->cities & (1u << other)) { + if (TEST_BIT(pclaim->cities, other)) { (pcmap->player_owndarea[other])--; } (pcmap->player_landarea[other])--; diff -urd -X freeciv.clean/diff_ignore part_app/common/game.h work/common/game.h --- part_app/common/game.h Tue Feb 19 17:12:18 2002 +++ work/common/game.h Sat Feb 23 11:03:03 2002 @@ -184,7 +184,7 @@ int min_dist_bw_cities; int init_vis_radius_sq; int hut_overflight; - int pillage_select; + bool pillage_select; int nuke_contamination; int granary_food_ini; int granary_food_inc; diff -urd -X freeciv.clean/diff_ignore part_app/common/improvement.c work/common/improvement.c --- part_app/common/improvement.c Tue Feb 19 17:13:46 2002 +++ work/common/improvement.c Sat Feb 23 11:13:34 2002 @@ -283,7 +283,7 @@ if (improvement_types[id].is_wonder) { /* a wonder is obsolette, as soon as *any* player researched the obsolete tech */ - return BOOL_VAL(game.global_advances[improvement_types[id].obsolete_by]); + return game.global_advances[improvement_types[id].obsolete_by] != 0; } return (get_invention(pplayer, improvement_types[id].obsolete_by) diff -urd -X freeciv.clean/diff_ignore part_app/common/inputfile.c work/common/inputfile.c --- part_app/common/inputfile.c Thu Feb 21 15:36:49 2002 +++ work/common/inputfile.c Sat Feb 23 10:32:40 2002 @@ -508,11 +508,11 @@ freelog(loglevel, " file \"%s\", line %d, pos %d%s", inf->filename, inf->line_num, inf->cur_line_pos, (inf->at_eof ? ", EOF" : "")); - if (inf->cur_line.str && inf->cur_line.n) { + if (inf->cur_line.str && inf->cur_line.n > 0) { freelog(loglevel, " looking at: '%s'", inf->cur_line.str+inf->cur_line_pos); } - if (inf->copy_line.str && inf->copy_line.n) { + if (inf->copy_line.str && inf->copy_line.n > 0) { freelog(loglevel, " original line: '%s'", inf->copy_line.str); } if (inf->in_string) { diff -urd -X freeciv.clean/diff_ignore part_app/common/log.c work/common/log.c --- part_app/common/log.c Thu Feb 21 16:15:19 2002 +++ work/common/log.c Sat Feb 23 10:36:53 2002 @@ -227,7 +227,7 @@ { static char bufbuf[2][MAX_LEN_LOG_LINE]; char buf[MAX_LEN_LOG_LINE]; - static int whichbuf=0; + static bool bufbuf1 = FALSE; static unsigned int repeated=0; /* total times current message repeated */ static unsigned int next=2; /* next total to print update */ static unsigned int prev=0; /* total on last update */ @@ -245,7 +245,7 @@ } else fs=stderr; - my_vsnprintf(bufbuf[whichbuf], MAX_LEN_LOG_LINE, message, ap); + my_vsnprintf(bufbuf1 ? bufbuf[1] : bufbuf[0], MAX_LEN_LOG_LINE, message, ap); if(level==prev_level && 0==strncmp(bufbuf[0],bufbuf[1],MAX_LEN_LOG_LINE-1)){ repeated++; @@ -263,7 +263,7 @@ if(repeated>0 && repeated!=prev){ if(repeated==1) { /* just repeat the previous message: */ - log_write(fs, prev_level, bufbuf[!whichbuf]); + log_write(fs, prev_level, bufbuf1 ? bufbuf[0] : bufbuf[1]); } else { if(repeated-prev==1) { sz_strlcpy(buf, _("last message repeated once")); @@ -281,9 +281,9 @@ repeated=0; next=2; prev=0; - log_write(fs, level, bufbuf[whichbuf]); + log_write(fs, level, bufbuf1 ? bufbuf[1] : bufbuf[0]); } - whichbuf= !whichbuf; + bufbuf1 = !bufbuf1; fflush(fs); if(log_filename) fclose(fs); diff -urd -X freeciv.clean/diff_ignore part_app/common/map.h work/common/map.h --- part_app/common/map.h Fri Feb 22 21:36:00 2002 +++ work/common/map.h Sat Feb 23 10:33:46 2002 @@ -168,8 +168,8 @@ int riverlength; int forestsize; int generator; - int tinyisles; - int separatepoles; + bool tinyisles; + bool separatepoles; int num_start_positions; int fixed_start_positions; bool have_specials; diff -urd -X freeciv.clean/diff_ignore part_app/common/netintf.c work/common/netintf.c --- part_app/common/netintf.c Thu Feb 14 09:46:05 2002 +++ work/common/netintf.c Sat Feb 23 10:37:39 2002 @@ -170,7 +170,7 @@ sock->sin_family = AF_INET; #ifdef HAVE_INET_ATON - if (inet_aton(hostname, &sock->sin_addr)) { + if (inet_aton(hostname, &sock->sin_addr) != 0) { return TRUE; } #else diff -urd -X freeciv.clean/diff_ignore part_app/common/packets.c work/common/packets.c --- part_app/common/packets.c Sat Feb 23 10:10:27 2002 +++ work/common/packets.c Sat Feb 23 11:16:47 2002 @@ -1170,7 +1170,7 @@ } /* avoid using strlen (or strcpy) on an (unsigned char*) --dwp */ - for(c=piter->ptr; *c && (c-piter->base) < piter->len; c++) ; + for (c = piter->ptr; *c != '\0' && (c - piter->base) < piter->len; c++); if ((c-piter->base) >= piter->len) { ps_len = pack_iter_remaining(piter); @@ -1319,7 +1319,7 @@ iget_uint8(piter, &data); for(b=0; b<8 && iid); iget_uint8(&iter, &data); - pinfo->used = data&1; - pinfo->established = (data>>=1)&1; - pinfo->observer = (data>>=1)&1; + pinfo->used = TEST_BIT(data, 0); + pinfo->established = TEST_BIT(data, 1); + pinfo->observer = TEST_BIT(data, 2); iget_uint8(&iter, &pinfo->player_num); iget_uint8(&iter, &data); @@ -2269,12 +2269,12 @@ cptr=put_uint8(buffer+2, PACKET_UNIT_INFO); cptr=put_uint16(cptr, req->id); cptr=put_uint8(cptr, req->owner); - pack=(req->select_it ? 0x04 : 0) - | (req->carried ? 0x08 : 0) - | (req->veteran ? 0x10 : 0) - | (req->ai ? 0x20 : 0) - | (req->paradropped ? 0x40 : 0) - | (req->connecting ? 0x80 : 0); + pack = (COND_SET_BIT(req->select_it, 2) | + COND_SET_BIT(req->carried, 3) | + COND_SET_BIT(req->veteran, 4) | + COND_SET_BIT(req->ai, 5) | + COND_SET_BIT(req->paradropped, 6) | + COND_SET_BIT(req->connecting, 7)); cptr=put_uint8(cptr, pack); cptr=put_uint8(cptr, req->x); cptr=put_uint8(cptr, req->y); @@ -2375,7 +2375,7 @@ cptr=put_uint8(cptr, req->city_options); for (data = 0; data < NUM_TRADEROUTES; data++) { - if(req->trade[data]) { + if(req->trade[data] != 0) { cptr=put_uint16(cptr, req->trade[data]); cptr=put_uint8(cptr,req->trade_value[data]); } @@ -2453,13 +2453,13 @@ iget_worklist(pc, &iter, &packet->worklist); iget_uint8(&iter, &data); - packet->is_building_unit = data&1; - packet->did_buy = (data>>=1)&1; - packet->did_sell = (data>>=1)&1; - packet->was_happy = (data>>=1)&1; - packet->airlift = (data>>=1)&1; - packet->diplomat_investigate = (data>>=1)&1; - packet->changed_from_is_unit = (data>>=1)&1; + packet->is_building_unit = TEST_BIT(data, 0); + packet->did_buy = TEST_BIT(data, 1); + packet->did_sell = TEST_BIT(data, 2); + packet->was_happy = TEST_BIT(data, 3); + packet->airlift = TEST_BIT(data, 4); + packet->diplomat_investigate = TEST_BIT(data, 5); + packet->changed_from_is_unit = TEST_BIT(data, 6); iget_city_map(&iter, (char*)packet->city_map, sizeof(packet->city_map)); iget_bit_string(&iter, (char*)packet->improvements, @@ -2534,9 +2534,9 @@ iget_uint8(&iter, &packet->size); iget_uint8(&iter, &i); - packet->happy = i & 1; - packet->capital = i & 2; - packet->walls = i & 4; + packet->happy = TEST_BIT(i, 0); + packet->capital = TEST_BIT(i, 1); + packet->walls = TEST_BIT(i, 2); if (has_capability("short_city_tile_trade", pc->capability)) { iget_uint16(&iter, &packet->tile_trade); @@ -2565,12 +2565,13 @@ iget_uint16(&iter, &packet->id); iget_uint8(&iter, &packet->owner); iget_uint8(&iter, &pack); - packet->veteran = (pack&0x10) ? 1 : 0; - packet->ai = (pack&0x20) ? 1 : 0; - packet->paradropped = (pack&0x40) ? 1 : 0; - packet->connecting = (pack&0x80) ? 1 : 0; - packet->carried = (pack&0x08) ? 1 : 0; - packet->select_it = (pack&0x04) ? 1 : 0; + + packet->select_it = TEST_BIT(pack, 2); + packet->carried = TEST_BIT(pack, 3); + packet->veteran = TEST_BIT(pack, 4); + packet->ai = TEST_BIT(pack, 5); + packet->paradropped = TEST_BIT(pack, 6); + packet->connecting = TEST_BIT(pack, 7); iget_uint8(&iter, &packet->x); iget_uint8(&iter, &packet->y); iget_uint16(&iter, &packet->homecity); @@ -2771,12 +2772,12 @@ iget_uint32(&iter, &packet->minor_version); iget_uint32(&iter, &packet->patch_version); iget_string(&iter, packet->capability, sizeof(packet->capability)); - if (pack_iter_remaining(&iter)) { + if (pack_iter_remaining(&iter) > 0) { iget_string(&iter, packet->name, sizeof(packet->name)); } else { sz_strlcpy(packet->name, packet->short_name); } - if (pack_iter_remaining(&iter)) { + if (pack_iter_remaining(&iter) > 0) { iget_string(&iter, packet->version_label, sizeof(packet->version_label)); } else { packet->version_label[0] = '\0'; @@ -3128,7 +3129,7 @@ iget_string(&iter, packet->name, sizeof(packet->name)); iget_string(&iter, packet->graphic_str, sizeof(packet->graphic_str)); iget_string(&iter, packet->graphic_alt, sizeof(packet->graphic_alt)); - if(packet->flags & (1L<flags, F_PARATROOPERS)) { iget_uint16(&iter, &packet->paratroopers_range); iget_uint8(&iter, &packet->paratroopers_mr_req); iget_uint8(&iter, &packet->paratroopers_mr_sub); @@ -3140,11 +3141,11 @@ if (has_capability("pop_cost", pc->capability)) { iget_uint8(&iter, &packet->pop_cost); } else { - packet->pop_cost=(packet->flags & (1L<pop_cost = TEST_BIT(packet->flags, F_CITIES) ? 1 : 0; } len = pack_iter_remaining(&iter); - if (len) { + if (len > 0) { packet->helptext = fc_malloc(len); iget_string(&iter, packet->helptext, len); } else { @@ -3209,7 +3210,7 @@ iget_string(&iter, packet->name, sizeof(packet->name)); len = pack_iter_remaining(&iter); - if (len) { + if (len > 0) { packet->helptext = fc_malloc(len); iget_string(&iter, packet->helptext, len); } else { @@ -3319,7 +3320,7 @@ iget_string(&iter, packet->name, sizeof(packet->name)); len = pack_iter_remaining(&iter); - if (len) { + if (len > 0) { packet->helptext = fc_malloc(len); iget_string(&iter, packet->helptext, len); } else { @@ -3432,7 +3433,7 @@ } len = pack_iter_remaining(&iter); - if (len) { + if (len > 0) { packet->helptext = fc_malloc(len); iget_string(&iter, packet->helptext, len); } else { @@ -3520,7 +3521,7 @@ iget_uint16(&iter, &packet->fallout_trade_penalty); len = pack_iter_remaining(&iter); - if (len) { + if (len > 0) { packet->river_help_text = fc_malloc(len); iget_string(&iter, packet->river_help_text, len); } else { @@ -3694,7 +3695,7 @@ iget_string(&iter, packet->graphic_alt, sizeof(packet->graphic_alt)); len = pack_iter_remaining(&iter); - if (len) { + if (len > 0) { packet->helptext = fc_malloc(len); iget_string(&iter, packet->helptext, len); } else { @@ -3856,7 +3857,7 @@ cptr=put_uint8(cptr, packet->min_dist_bw_cities); cptr=put_uint8(cptr, packet->init_vis_radius_sq); cptr=put_uint8(cptr, packet->hut_overflight); - cptr=put_uint8(cptr, packet->pillage_select); + cptr=put_bool8(cptr, packet->pillage_select); cptr=put_uint8(cptr, packet->nuke_contamination); cptr=put_uint8(cptr, packet->granary_food_ini); cptr=put_uint8(cptr, packet->granary_food_inc); @@ -3890,7 +3891,7 @@ iget_uint8(&iter, &packet->min_dist_bw_cities); iget_uint8(&iter, &packet->init_vis_radius_sq); iget_uint8(&iter, &packet->hut_overflight); - iget_uint8(&iter, &packet->pillage_select); + iget_bool8(&iter, &packet->pillage_select); iget_uint8(&iter, &packet->nuke_contamination); iget_uint8(&iter, &packet->granary_food_ini); iget_uint8(&iter, &packet->granary_food_inc); diff -urd -X freeciv.clean/diff_ignore part_app/common/packets.h work/common/packets.h --- part_app/common/packets.h Thu Feb 21 09:39:48 2002 +++ work/common/packets.h Sat Feb 23 11:05:29 2002 @@ -788,7 +788,7 @@ int min_dist_bw_cities; int init_vis_radius_sq; int hut_overflight; - int pillage_select; + bool pillage_select; int nuke_contamination; int granary_food_ini; int granary_food_inc; diff -urd -X freeciv.clean/diff_ignore part_app/common/player.c work/common/player.c --- part_app/common/player.c Thu Feb 21 15:36:49 2002 +++ work/common/player.c Sat Feb 23 10:55:25 2002 @@ -41,9 +41,9 @@ ***************************************************************/ bool player_has_embassy(struct player *pplayer, struct player *pplayer2) { - return (pplayer->embassy & (1<player_no)) || - (player_owns_active_wonder(pplayer, B_MARCO) && - pplayer != pplayer2 && !is_barbarian(pplayer2)); + return (TEST_BIT(pplayer->embassy, pplayer2->player_no) || + (player_owns_active_wonder(pplayer, B_MARCO) && + pplayer != pplayer2 && !is_barbarian(pplayer2))); } /**************************************************************** diff -urd -X freeciv.clean/diff_ignore part_app/common/registry.c work/common/registry.c --- part_app/common/registry.c Sat Feb 23 10:10:32 2002 +++ work/common/registry.c Sat Feb 23 10:54:18 2002 @@ -830,7 +830,7 @@ assert(val == TRUE || val == FALSE); - pentry->ivalue=val; + pentry->ivalue = val ? 1 : 0; pentry->svalue = NULL; pentry->comment = NULL; } diff -urd -X freeciv.clean/diff_ignore part_app/common/shared.h work/common/shared.h --- part_app/common/shared.h Thu Feb 21 08:58:04 2002 +++ work/common/shared.h Sat Feb 23 10:50:10 2002 @@ -59,6 +59,8 @@ and inserts a zero at the top. */ #define WIPEBIT(val, no) ( ((~(-1<<(no)))&(val)) \ | (( (-1<<((no)+1)) & (val)) >>1) ) +#define TEST_BIT(val, no) (((val) & (1u << (no))) == (1u << (no))) +#define COND_SET_BIT(cond, no) ((cond) ? (1u << (no)) : 0) /* This is duplicated in rand.h to avoid extra includes: */ #define MAX_UINT32 0xFFFFFFFF diff -urd -X freeciv.clean/diff_ignore part_app/common/tech.c work/common/tech.c --- part_app/common/tech.c Thu Feb 14 09:46:05 2002 +++ work/common/tech.c Sat Feb 23 11:12:31 2002 @@ -79,10 +79,8 @@ if (tech == goal) { return FALSE; } else { - /* *INDENT-OFF* */ - return BOOL_VAL(pplayer->research.inventions[goal]. - required_techs[tech / 8] & (1 << (tech % 8))); - /* *INDENT-ON* */ + return TEST_BIT(pplayer->research.inventions[goal]. + required_techs[tech / 8], tech % 8); } } @@ -257,7 +255,7 @@ bool tech_flag(Tech_Type_id tech, enum tech_flag_id flag) { assert(flag>=0 && flagowner != pcity->owner) return FALSE; - if (city1->airlift + pcity->airlift < 2) + if (!city1->airlift || !pcity->airlift) return FALSE; if (!is_ground_unit(punit)) return FALSE; @@ -387,8 +387,9 @@ /************************************************************************** ... **************************************************************************/ -bool kills_citizen_after_attack(struct unit *punit) { - return (game.killcitizen >> ((int)unit_type(punit)->move_type-1)) & 1; +bool kills_citizen_after_attack(struct unit *punit) +{ + return TEST_BIT(game.killcitizen, (int) (unit_type(punit)->move_type) - 1); } /************************************************************************** @@ -636,7 +637,7 @@ case ACTIVITY_ROAD: return (terrain_control.may_road && unit_flag(punit, F_SETTLERS) && - !tile_has_special(ptile, S_ROAD) && type->road_time && + !tile_has_special(ptile, S_ROAD) && type->road_time != 0 && ((ptile->terrain != T_RIVER && !tile_has_special(ptile, S_RIVER)) || player_knows_techs_with_flag(pplayer, TF_BRIDGE))); @@ -716,7 +717,7 @@ unit_flag(punit, F_SETTLERS) && (tile_has_special(ptile, S_ROAD) || (punit->connecting && - (type->road_time && + (type->road_time != 0 && ((ptile->terrain!=T_RIVER && !tile_has_special(ptile, S_RIVER)) || player_knows_techs_with_flag(pplayer, TF_BRIDGE))))) && !tile_has_special(ptile, S_RAILROAD) && @@ -727,7 +728,7 @@ int pspresent; int psworking; pspresent = get_tile_infrastructure_set(ptile); - if (pspresent && is_ground_unit(punit)) { + if (pspresent != S_NO_SPECIAL && is_ground_unit(punit)) { psworking = get_unit_tile_pillage_set(punit->x, punit->y); if (ptile->city && (contains_special(target, S_ROAD) || contains_special(target, S_RAILROAD))) diff -urd -X freeciv.clean/diff_ignore part_app/common/unittype.c work/common/unittype.c --- part_app/common/unittype.c Sat Feb 16 17:46:44 2002 +++ work/common/unittype.c Sat Feb 23 11:13:07 2002 @@ -132,7 +132,7 @@ int utype_shield_cost(struct unit_type *ut, struct government *g) { if (government_has_flag(g, G_FANATIC_TROOPS) && - (ut->flags & (1 << F_FANATIC))) return 0; + TEST_BIT(ut->flags, F_FANATIC)) return 0; return ut->shield_cost * g->unit_shield_cost_factor; } @@ -166,7 +166,7 @@ bool unit_type_flag(Unit_Type_id id, int flag) { assert(flag>=0 && flag=L_FIRST && role