tCleanup of signed and boolean variables - vaccinewars - be a doctor and try to… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit a756e93c834008f86ef3bd1d41a7c943cea404e8 | |
parent 2683ad504a0523490608cacb767f7cdbd48a5b4a | |
Author: Ben Webb <[email protected]> | |
Date: Wed, 12 Sep 2001 17:58:58 +0000 | |
Cleanup of signed and boolean variables | |
Diffstat: | |
M src/curses_client.c | 44 ++++++++++++++++++-----------… | |
M src/dopewars.c | 14 +++++++------- | |
M src/gtk_client.c | 10 +++++----- | |
M src/message.c | 5 +++-- | |
M src/serverside.c | 44 ++++++++++++++++-------------… | |
M src/tstring.c | 8 +++++--- | |
6 files changed, 68 insertions(+), 57 deletions(-) | |
--- | |
diff --git a/src/curses_client.c b/src/curses_client.c | |
t@@ -815,7 +815,7 @@ void PrintHighScore(char *Data) { | |
void PrintMessage(const gchar *text) { | |
/* Prints a message "text" received via. a "printmessage" message in the */ | |
/* bottom part of the screen. */ | |
- int i,line; | |
+ guint i,line; | |
attrset(TextAttr); | |
clear_line(16); | |
for (i=0;i<strlen(text);i++) { | |
t@@ -1026,7 +1026,8 @@ int GetKey(char *allowed,char *orig_allowed,gboolean All… | |
/* the prompt. If "ExpandOut" is also TRUE, the full words for */ | |
/* the commands, rather than just their first letters, are */ | |
/* displayed. */ | |
- int i,j,k,c; | |
+ int ch; | |
+ guint AllowInd,WordInd,i; | |
/* Expansions of the single-letter keypresses for the benefit of the user. | |
i.e. "Yes" is printed for the key "Y" etc. You should indicate to the | |
t@@ -1034,35 +1035,39 @@ int GetKey(char *allowed,char *orig_allowed,gboolean A… | |
capitalising it or similar. */ | |
gchar *Words[] = { N_("Yes"), N_("No"), N_("Run"), | |
N_("Fight"), N_("Attack"), N_("Evade") }; | |
- gint numWords = sizeof(Words) / sizeof(Words[0]); | |
+ guint numWords = sizeof(Words) / sizeof(Words[0]); | |
gchar *trWord; | |
curs_set(1); | |
- c=0; | |
+ ch='\0'; | |
+ | |
if (!allowed || strlen(allowed)==0) return 0; | |
+ | |
if (PrintAllowed) { | |
addch('[' | TextAttr); | |
- for (i=0;i<strlen(allowed);i++) { | |
- if (i>0) addch('/' | TextAttr); | |
- for (j=0;j<numWords;j++) { | |
- if (ExpandOut && orig_allowed[i]==Words[j][0]) { | |
- trWord=_(Words[j]); | |
- for (k=0;k<strlen(trWord);k++) { | |
- addch((guchar)trWord[k] | TextAttr); | |
+ for (AllowInd=0;AllowInd<strlen(allowed);AllowInd++) { | |
+ if (AllowInd>0) addch('/' | TextAttr); | |
+ for (WordInd=0;WordInd<numWords;WordInd++) { | |
+ if (ExpandOut && orig_allowed[AllowInd]==Words[WordInd][0]) { | |
+ trWord=_(Words[WordInd]); | |
+ for (i=0;i<strlen(trWord);i++) { | |
+ addch((guchar)trWord[i] | TextAttr); | |
} | |
break; | |
} | |
} | |
- if (j>=numWords) addch((guchar)allowed[i] | TextAttr); | |
+ if (WordInd>=numWords) addch((guchar)allowed[AllowInd] | TextAttr); | |
} | |
addch(']' | TextAttr); | |
addch(' ' | TextAttr); | |
} | |
while (1) { | |
- c=bgetch(); c=toupper(c); | |
- for (i=0;i<strlen(allowed);i++) if (allowed[i]==c) { | |
- addch((guint)c | TextAttr); | |
- curs_set(0); return orig_allowed[i]; | |
+ ch=bgetch(); ch=toupper(ch); | |
+ for (AllowInd=0;AllowInd<strlen(allowed);AllowInd++) { | |
+ if (allowed[AllowInd]==ch) { | |
+ addch((guint)ch | TextAttr); | |
+ curs_set(0); return orig_allowed[AllowInd]; | |
+ } | |
} | |
if (AllowOther) break; | |
} | |
t@@ -1165,10 +1170,13 @@ void display_message(char *buf) { | |
/* 10 to 14) scrolling previous messages up */ | |
/* If "buf" is NULL, clears the message area */ | |
/* If "buf" is a blank string, redisplays the message area */ | |
- int x,y; | |
- int wid; | |
+ guint x,y; | |
+ guint wid; | |
static char Messages[5][200]; | |
char *bufpt; | |
+ | |
+ if (Width<=4) return; | |
+ | |
wid = Width-4 < 200 ? Width-4 : 200; | |
if (!buf) { | |
for (y=0;y<5;y++) { | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -732,20 +732,20 @@ Player *GetPlayerByName(char *Name,GSList *First) { | |
price_t strtoprice(char *buf) { | |
/* Forms a price based on the string representation in "buf" */ | |
- int i,buflen,FracNum; | |
- char digit,minus,suffix; | |
- gboolean InFrac; | |
+ guint i,buflen,FracNum; | |
+ char digit,suffix; | |
+ gboolean minus,InFrac; | |
price_t val=0; | |
- minus=0; | |
+ minus=FALSE; | |
InFrac=FALSE; | |
- if (!buf) return 0; | |
+ if (!buf || !buf[0]) return 0; | |
buflen=strlen(buf); | |
suffix=buf[buflen-1]; | |
suffix=toupper(suffix); | |
if (suffix=='M') FracNum=6; | |
else if (suffix=='K') FracNum=3; | |
else FracNum=0; | |
- for (i=0;i<strlen(buf);i++) { | |
+ for (i=0;i<buflen;i++) { | |
digit=buf[i]; | |
if (digit=='.' || digit==',') { | |
InFrac=TRUE; | |
t@@ -754,7 +754,7 @@ price_t strtoprice(char *buf) { | |
else if (InFrac) FracNum--; | |
val*=10; | |
val+=(digit-'0'); | |
- } else if (digit=='-') minus=1; | |
+ } else if (digit=='-') minus=TRUE; | |
} | |
for (i=0;i<FracNum;i++) val*=10; | |
if (minus) val=-val; | |
diff --git a/src/gtk_client.c b/src/gtk_client.c | |
t@@ -748,7 +748,7 @@ static void UpdateCombatant(gchar *DefendName,int DefendBi… | |
/* Updates the display of information for a player/cop in the Fight dialog. */ | |
/* If the player's name (DefendName) already exists, updates the display of */ | |
/* total health and number of bitches - otherwise, adds a new entry. */ | |
- gint i,RowIndex; | |
+ guint i,RowIndex; | |
gchar *name; | |
struct combatant *compt; | |
GArray *combatants; | |
t@@ -2857,10 +2857,6 @@ void DestroyShowing(GtkWidget *widget,gpointer data) { | |
if (IsShowing) *IsShowing=FALSE; | |
} | |
-gint DisallowDelete(GtkWidget *widget,GdkEvent *event,gpointer data) { | |
- return(TRUE); | |
-} | |
- | |
static void NewNameOK(GtkWidget *widget,GtkWidget *window) { | |
GtkWidget *entry; | |
gchar *text; | |
t@@ -2918,6 +2914,10 @@ void NewNameDialog(void) { | |
gtk_widget_show_all(window); | |
} | |
+gint DisallowDelete(GtkWidget *widget,GdkEvent *event,gpointer data) { | |
+ return(TRUE); | |
+} | |
+ | |
void GunShopDialog(void) { | |
GtkWidget *window,*button,*hsep,*vbox,*hbox; | |
GtkAccelGroup *accel_group; | |
diff --git a/src/message.c b/src/message.c | |
t@@ -775,7 +775,7 @@ void AddURLEnc(GString *str,gchar *unenc) { | |
/* replacing "special" characters in the same way as the */ | |
/* application/x-www-form-urlencoded media type, suitable for sending */ | |
/* to CGI scripts etc. */ | |
- int i; | |
+ guint i; | |
if (!unenc || !str) return; | |
for (i=0;i<strlen(unenc);i++) { | |
if ((unenc[i]>='a' && unenc[i]<='z') || | |
t@@ -1474,7 +1474,8 @@ void ReceiveFightMessage(gchar *Data,gchar **AttackName,… | |
void SendFightMessage(Player *Attacker,Player *Defender, | |
int BitchesKilled,FightPoint fp, | |
price_t Loot,gboolean Broadcast,gchar *Msg) { | |
- int ArrayInd,ArmPercent,Damage,MaxDamage,i; | |
+ guint ArrayInd; | |
+ int ArmPercent,Damage,MaxDamage,i; | |
Player *To; | |
GString *text; | |
gchar *BitchName; | |
diff --git a/src/serverside.c b/src/serverside.c | |
t@@ -799,7 +799,7 @@ void StopServer() { | |
RemovePidFile(); | |
} | |
-void RemovePlayerFromServer(Player *Play,gboolean WantQuit) { | |
+void RemovePlayerFromServer(Player *Play) { | |
#ifdef GUI_SERVER | |
if (Play->InputTag) gdk_input_remove(Play->InputTag); | |
#endif | |
t@@ -822,8 +822,7 @@ void ServerLoop() { | |
GSList *list,*nextlist; | |
fd_set readfs,writefs,errorfs; | |
int topsock; | |
- char WantQuit=FALSE; | |
- char InputClosed=FALSE; | |
+ gboolean InputClosed=FALSE; | |
struct timeval timeout; | |
int MinTimeout; | |
GString *LineBuf; | |
t@@ -920,13 +919,14 @@ void ServerLoop() { | |
} | |
if (!DoneOK) { | |
/* The socket has been shut down, or the buffer was filled - remove player */ | |
- RemovePlayerFromServer(tmp,WantQuit); | |
+ RemovePlayerFromServer(tmp); | |
if (IsServerShutdown()) break; | |
tmp=NULL; | |
} | |
} | |
list=nextlist; | |
} | |
+ if (list && IsServerShutdown()) break; | |
} | |
StopServer(); | |
g_string_free(LineBuf,TRUE); | |
t@@ -938,12 +938,12 @@ static gint ListenTag=0; | |
static void SetSocketWriteTest(Player *Play,gboolean WriteTest); | |
static void GuiSetTimeouts(void); | |
static time_t NextTimeout=0; | |
-static guint TimeoutTag=-1; | |
+static guint TimeoutTag=0; | |
static gint GuiDoTimeouts(gpointer data) { | |
/* Forget the TimeoutTag so that GuiSetTimeouts doesn't delete it - it'll be | |
deleted automatically anyway when we return FALSE */ | |
- TimeoutTag=-1; | |
+ TimeoutTag=0; | |
NextTimeout=0; | |
FirstServer=HandleTimeouts(FirstServer); | |
t@@ -957,8 +957,8 @@ void GuiSetTimeouts(void) { | |
TimeNow=time(NULL); | |
MinTimeout=GetMinimumTimeout(FirstServer); | |
if (TimeNow+MinTimeout < NextTimeout || NextTimeout<TimeNow) { | |
- if (TimeoutTag!=-1) gtk_timeout_remove(TimeoutTag); | |
- TimeoutTag = -1; | |
+ if (TimeoutTag>0) gtk_timeout_remove(TimeoutTag); | |
+ TimeoutTag = 0; | |
if (MinTimeout>0) { | |
TimeoutTag=gtk_timeout_add(MinTimeout*1000,GuiDoTimeouts,NULL); | |
NextTimeout=TimeNow+MinTimeout; | |
t@@ -1048,7 +1048,7 @@ static void GuiHandleSocket(gpointer data,gint socket, | |
GuiSetTimeouts(); /* We may have set some new timeouts */ | |
} | |
if (!DoneOK) { | |
- RemovePlayerFromServer(Play,WantQuit); | |
+ RemovePlayerFromServer(Play); | |
if (IsServerShutdown()) GuiQuitServer(); | |
} | |
} | |
t@@ -1667,7 +1667,7 @@ void AllowNextShooter(Player *Play) { | |
} | |
void DoReturnFire(Player *Play) { | |
- int ArrayInd; | |
+ guint ArrayInd; | |
Player *Defend; | |
if (!Play || !Play->FightArray) return; | |
t@@ -1687,7 +1687,7 @@ void RunFromCombat(Player *Play,int ToLocation) { | |
/* is >=0, then it identifies the location that the player is */ | |
/* trying to run to. */ | |
int EscapeProb,RandNum; | |
- int ArrayInd; | |
+ guint ArrayInd; | |
gboolean FightingCop=FALSE; | |
Player *Defend; | |
char BackupAt; | |
t@@ -1724,7 +1724,7 @@ void RunFromCombat(Player *Play,int ToLocation) { | |
void CheckForKilledPlayers(Player *Play) { | |
Player *Defend; | |
- int ArrayInd; | |
+ guint ArrayInd; | |
GPtrArray *KilledPlayers; | |
KilledPlayers=g_ptr_array_new(); | |
t@@ -1754,7 +1754,7 @@ static void CheckCopsIntervene(Player *Play) { | |
/* If "Play" is attacking someone, and no cops are currently present, */ | |
/* then have the cops intervene (with a probability dependent on the */ | |
/* current location's PolicePresence) */ | |
- gint ArrayInd; | |
+ guint ArrayInd; | |
Player *Defend; | |
if (!Play || !Play->FightArray) return; /* Sanity check */ | |
t@@ -1780,7 +1780,7 @@ static Player *GetFireTarget(Player *Play) { | |
/* is attacking a designated target already, return that, otherwise */ | |
/* return the first valid opponent in the player's FightArray. */ | |
Player *Defend; | |
- gint ArrayInd; | |
+ guint ArrayInd; | |
if (Play->Attacking && g_slist_find(FirstServer,(gpointer)Play->Attacking))… | |
return Play->Attacking; | |
t@@ -1867,7 +1867,7 @@ Player *GetNextShooter(Player *Play) { | |
/* nothing (i.e. return NULL) */ | |
Player *MinPlay,*Defend; | |
time_t MinTimeout; | |
- int ArrayInd; | |
+ guint ArrayInd; | |
gboolean Tie=FALSE; | |
if (!FightTimeout) return NULL; | |
t@@ -1916,7 +1916,7 @@ void ResolveTipoff(Player *Play) { | |
void WithdrawFromCombat(Player *Play) { | |
/* Cleans up combat after player "Play" has left */ | |
- int i,j; | |
+ guint AttackInd,DefendInd; | |
gboolean FightDone; | |
Player *Attack,*Defend; | |
GSList *list; | |
t@@ -1926,10 +1926,10 @@ void WithdrawFromCombat(Player *Play) { | |
ResolveTipoff(Play); | |
FightDone=TRUE; | |
- for (i=0;i<Play->FightArray->len;i++) { | |
- Attack=(Player *)g_ptr_array_index(Play->FightArray,i); | |
- for (j=0;j<i;j++) { | |
- Defend=(Player *)g_ptr_array_index(Play->FightArray,j); | |
+ for (AttackInd=0;AttackInd<Play->FightArray->len;AttackInd++) { | |
+ Attack=(Player *)g_ptr_array_index(Play->FightArray,AttackInd); | |
+ for (DefendInd=0;DefendInd<AttackInd;DefendInd++) { | |
+ Defend=(Player *)g_ptr_array_index(Play->FightArray,DefendInd); | |
if (Attack!=Play && Defend!=Play && | |
IsOpponent(Attack,Defend)) { FightDone=FALSE; break; } | |
} | |
t@@ -1945,8 +1945,8 @@ void WithdrawFromCombat(Player *Play) { | |
g_ptr_array_remove(Play->FightArray,(gpointer)Play); | |
if (FightDone) { | |
- for (i=0;i<Play->FightArray->len;i++) { | |
- Defend=(Player *)g_ptr_array_index(Play->FightArray,i); | |
+ for (DefendInd=0;DefendInd<Play->FightArray->len;DefendInd++) { | |
+ Defend=(Player *)g_ptr_array_index(Play->FightArray,DefendInd); | |
Defend->FightArray=NULL; | |
ResolveTipoff(Defend); | |
if (IsCop(Defend)) { | |
diff --git a/src/tstring.c b/src/tstring.c | |
t@@ -78,10 +78,11 @@ gchar *GetTranslatedString(gchar *str,gchar *code,gboolean… | |
return tstr; | |
} | |
-void GetNextFormat(int *Index,gchar *str,int *StartPos, | |
+void GetNextFormat(guint *Index,gchar *str,int *StartPos, | |
int *EndPos,int *FmtPos,gchar *Type,int *ArgNum,int *Wid, | |
int *Prec,char *Code) { | |
- int anum,wid,prec,i; | |
+ int anum,wid,prec; | |
+ guint i; | |
gchar type; | |
*StartPos=-1; | |
*EndPos=*FmtPos=*ArgNum=*Wid=*Prec=0; | |
t@@ -124,7 +125,8 @@ void GetNextFormat(int *Index,gchar *str,int *StartPos, | |
} | |
gchar *HandleTFmt(gchar *format, va_list va) { | |
- int i,StrInd,StartPos,EndPos,FmtPos,ArgNum,DefaultArgNum,Wid,Prec; | |
+ int StrInd,StartPos,EndPos,FmtPos,Wid,Prec; | |
+ guint i,ArgNum,DefaultArgNum; | |
char Code[3],Type; | |
gchar *retstr,*fstr; | |
GString *string,*tmpfmt; |