[Freeciv-Dev] patch: BOOL_VAL() (PR#215)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This is essentially a minor code tidy-up/prettify patch,
adding a macro BOOL_VAL(), to convert an expression to
boolean value (as discussed once upon a time...). It is
used for the return values of unit_flag() and unit_has_role(),
and a few other places replaces existing code with same effect.
(Also added some extra brackets to make WIPEBIT() safer.)
-- David
diff -u -r --exclude-from exclude fc-adv/client/gui-gtk/mapview.c
freeciv-mod/client/gui-gtk/mapview.c
--- fc-adv/client/gui-gtk/mapview.c Tue Dec 28 18:38:15 1999
+++ freeciv-mod/client/gui-gtk/mapview.c Wed Dec 29 11:53:43 1999
@@ -418,7 +418,7 @@
**************************************************************************/
GdkPixmap *get_thumb_pixmap(int onoff)
{
- return sprites.treaty_thumb[!!onoff]->pixmap;
+ return sprites.treaty_thumb[BOOL_VAL(onoff)]->pixmap;
}
/**************************************************************************
diff -u -r --exclude-from exclude fc-adv/client/gui-xaw/mapview.c
freeciv-mod/client/gui-xaw/mapview.c
--- fc-adv/client/gui-xaw/mapview.c Tue Dec 28 18:38:18 1999
+++ freeciv-mod/client/gui-xaw/mapview.c Wed Dec 29 11:53:30 1999
@@ -396,7 +396,7 @@
**************************************************************************/
Pixmap get_thumb_pixmap(int onoff)
{
- return sprites.treaty_thumb[!!onoff]->pixmap;
+ return sprites.treaty_thumb[BOOL_VAL(onoff)]->pixmap;
}
/**************************************************************************
diff -u -r --exclude-from exclude fc-adv/client/tilespec.c
freeciv-mod/client/tilespec.c
--- fc-adv/client/tilespec.c Tue Dec 28 18:38:20 1999
+++ freeciv-mod/client/tilespec.c Wed Dec 29 11:53:04 1999
@@ -382,8 +382,8 @@
{
static char c[] = "n0s0e0w0";
- sprintf(c, "n%ds%de%dw%d", !!(idx&BIT_NORTH), !!(idx&BIT_SOUTH),
- !!(idx&BIT_EAST), !!(idx&BIT_WEST));
+ sprintf(c, "n%ds%de%dw%d", BOOL_VAL(idx&BIT_NORTH), BOOL_VAL(idx&BIT_SOUTH),
+ BOOL_VAL(idx&BIT_EAST), BOOL_VAL(idx&BIT_WEST));
return c;
}
@@ -991,31 +991,31 @@
if((tspecial & S_ROAD) || (tspecial & S_RAILROAD)) {
int n, s, e, w;
- n = !!(tspecial_north&S_RAILROAD);
- s = !!(tspecial_south&S_RAILROAD);
- e = !!(tspecial_east&S_RAILROAD);
- w = !!(tspecial_west&S_RAILROAD);
+ n = BOOL_VAL(tspecial_north&S_RAILROAD);
+ s = BOOL_VAL(tspecial_south&S_RAILROAD);
+ e = BOOL_VAL(tspecial_east&S_RAILROAD);
+ w = BOOL_VAL(tspecial_west&S_RAILROAD);
rail_card_count = n + s + e + w;
rail_card_tileno = INDEX_NSEW(n,s,e,w);
- n = !!(tspecial_north&S_ROAD);
- s = !!(tspecial_south&S_ROAD);
- e = !!(tspecial_east&S_ROAD);
- w = !!(tspecial_west&S_ROAD);
+ n = BOOL_VAL(tspecial_north&S_ROAD);
+ s = BOOL_VAL(tspecial_south&S_ROAD);
+ e = BOOL_VAL(tspecial_east&S_ROAD);
+ w = BOOL_VAL(tspecial_west&S_ROAD);
road_card_count = n + s + e + w;
road_card_tileno = INDEX_NSEW(n,s,e,w);
- n = !!(tspecial_north_east&S_RAILROAD);
- s = !!(tspecial_south_west&S_RAILROAD);
- e = !!(tspecial_south_east&S_RAILROAD);
- w = !!(tspecial_north_west&S_RAILROAD);
+ n = BOOL_VAL(tspecial_north_east&S_RAILROAD);
+ s = BOOL_VAL(tspecial_south_west&S_RAILROAD);
+ e = BOOL_VAL(tspecial_south_east&S_RAILROAD);
+ w = BOOL_VAL(tspecial_north_west&S_RAILROAD);
rail_semi_count = n + s + e + w;
rail_semi_tileno = INDEX_NSEW(n,s,e,w);
- n = !!(tspecial_north_east&S_ROAD);
- s = !!(tspecial_south_west&S_ROAD);
- e = !!(tspecial_south_east&S_ROAD);
- w = !!(tspecial_north_west&S_ROAD);
+ n = BOOL_VAL(tspecial_north_east&S_ROAD);
+ s = BOOL_VAL(tspecial_south_west&S_ROAD);
+ e = BOOL_VAL(tspecial_south_east&S_ROAD);
+ w = BOOL_VAL(tspecial_north_west&S_ROAD);
road_semi_count = n + s + e + w;
road_semi_tileno = INDEX_NSEW(n,s,e,w);
diff -u -r --exclude-from exclude fc-adv/common/registry.c
freeciv-mod/common/registry.c
--- fc-adv/common/registry.c Tue Dec 28 18:38:21 1999
+++ freeciv-mod/common/registry.c Wed Dec 29 11:51:16 1999
@@ -849,7 +849,7 @@
vsprintf(buf, path, ap);
va_end(ap);
- return !!section_file_lookup_internal(my_section_file, buf);
+ return BOOL_VAL(section_file_lookup_internal(my_section_file, buf));
}
diff -u -r --exclude-from exclude fc-adv/common/shared.h
freeciv-mod/common/shared.h
--- fc-adv/common/shared.h Wed Dec 29 11:14:34 1999
+++ freeciv-mod/common/shared.h Wed Dec 29 11:50:17 1999
@@ -45,7 +45,9 @@
#define CLIP(lower,this,upper) \
((this)<(lower)?(lower):(this)>(upper)?(upper):(this))
-#define WIPEBIT(val, no) ((~(-1<<no))&val) | (( (-1<<(no+1)) &val) >>1)
+#define BOOL_VAL(x) ((x)!=0)
+
+#define WIPEBIT(val, no) ((~(-1<<(no)))&(val)) | (( (-1<<((no)+1)) & (val))
>>1)
/* This is duplicated in rand.h to avoid extra includes: */
#define MAX_UINT32 0xFFFFFFFF
diff -u -r --exclude-from exclude fc-adv/common/unit.c freeciv-mod/common/unit.c
--- fc-adv/common/unit.c Tue Dec 28 22:07:14 1999
+++ freeciv-mod/common/unit.c Wed Dec 29 11:51:01 1999
@@ -27,6 +27,7 @@
#include "map.h"
#include "mem.h"
#include "player.h"
+#include "shared.h"
#include "tech.h"
#include "unit.h"
@@ -596,7 +597,7 @@
int unit_flag(Unit_Type_id id, int flag)
{
assert(flag>=0 && flag<F_LAST);
- return unit_types[id].flags & (1<<flag);
+ return BOOL_VAL(unit_types[id].flags & (1<<flag));
}
/**************************************************************************
@@ -605,7 +606,7 @@
int unit_has_role(Unit_Type_id id, int role)
{
assert(role>=L_FIRST && role<L_LAST);
- return unit_types[id].roles & (1<<(role-L_FIRST));
+ return BOOL_VAL(unit_types[id].roles & (1<<(role-L_FIRST)));
}
/**************************************************************************
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] patch: BOOL_VAL() (PR#215),
David Pfitzner <=
|
|