Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Commit 476884b

Browse files
rogersmxenith
authored andcommitted
Add C99 stdbool.h to the codebase. (#36)
1 parent e6b9e6d commit 476884b

20 files changed

+151
-137
lines changed

src/action_safe.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stdio.h>
66
#include <string.h>
77
#include <unistd.h>
8+
#include <stdbool.h>
89

910
/* include main header file */
1011
#include "mud.h"
@@ -31,12 +32,12 @@ void cmd_quit(D_MOBILE *dMob, char *arg)
3132

3233
dMob->socket->player = NULL;
3334
free_mobile(dMob);
34-
close_socket(dMob->socket, FALSE);
35+
close_socket(dMob->socket, false);
3536
}
3637

3738
void cmd_shutdown(D_MOBILE *dMob, char *arg)
3839
{
39-
shut_down = TRUE;
40+
shut_down = true;
4041
}
4142

4243
void cmd_commands(D_MOBILE *dMob, char *arg)
@@ -128,7 +129,7 @@ void cmd_compress(D_MOBILE *dMob, char *arg)
128129
}
129130
else /* disable compression */
130131
{
131-
if (!compressEnd(dMob->socket, dMob->socket->compressing, FALSE))
132+
if (!compressEnd(dMob->socket, dMob->socket->compressing, false))
132133
{
133134
text_to_mobile(dMob, "Failed.\n\r");
134135
return;
@@ -162,12 +163,12 @@ void cmd_copyover(D_MOBILE *dMob, char *arg)
162163
AttachIterator(&Iter, dsock_list);
163164
while ((dsock = (D_SOCKET *) NextInList(&Iter)) != NULL)
164165
{
165-
compressEnd(dsock, dsock->compressing, FALSE);
166+
compressEnd(dsock, dsock->compressing, false);
166167

167168
if (dsock->state != STATE_PLAYING)
168169
{
169170
text_to_socket(dsock, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r");
170-
close_socket(dsock, FALSE);
171+
close_socket(dsock, false);
171172
}
172173
else
173174
{
@@ -205,7 +206,7 @@ void cmd_linkdead(D_MOBILE *dMob, char *arg)
205206
D_MOBILE *xMob;
206207
ITERATOR Iter;
207208
char buf[MAX_BUFFER];
208-
bool found = FALSE;
209+
bool found = false;
209210

210211
AttachIterator(&Iter, dmobile_list);
211212
while ((xMob = (D_MOBILE *) NextInList(&Iter)) != NULL)
@@ -214,7 +215,7 @@ void cmd_linkdead(D_MOBILE *dMob, char *arg)
214215
{
215216
snprintf(buf, MAX_BUFFER, "%s is linkdead.\n\r", xMob->name);
216217
text_to_mobile(dMob, buf);
217-
found = TRUE;
218+
found = true;
218219
}
219220
}
220221
DetachIterator(&Iter);

src/db.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <sqlite3.h>
33
#include <stdlib.h>
44
#include <string.h>
5+
#include <stdbool.h>
56

67
/* main header file */
78
#include "mud.h"
@@ -18,10 +19,10 @@ bool db_open()
1819

1920
db_close();
2021

21-
return FALSE;
22+
return false;
2223
}
2324

24-
return TRUE;
25+
return true;
2526
}
2627

2728
bool db_close()
@@ -30,10 +31,10 @@ bool db_close()
3031
{
3132
bug("Unable to close database: %s", sqlite3_errmsg(db));
3233

33-
return FALSE;
34+
return false;
3435
}
3536

36-
return TRUE;
37+
return true;
3738
}
3839

3940
bool db_execute(const char *sql, ...)
@@ -48,23 +49,23 @@ bool db_execute(const char *sql, ...)
4849
va_end(vars);
4950

5051
if ( stmt == NULL ) {
51-
return FALSE;
52+
return false;
5253
}
5354

5455

5556
if ( db_step(stmt) != SQLITE_DONE ) {
5657
bug("Failed to step through statement: %s", sqlite3_errmsg(db));
5758

58-
return FALSE;
59+
return false;
5960
}
6061

6162
if ( db_finalize(stmt) != SQLITE_OK ) {
6263
bug("Failed to finalize statement: %s", sqlite3_errmsg(db));
6364

64-
return FALSE;
65+
return false;
6566
}
6667

67-
return TRUE;
68+
return true;
6869
}
6970

7071
sqlite3_stmt *db_prepare(const char *sql, ...)

src/event-handler.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <string.h>
44
#include <unistd.h>
55
#include <stdlib.h>
6+
#include <stdbool.h>
7+
68

79
/* include main header file */
810
#include "mud.h"
@@ -28,7 +30,7 @@ bool enqueue_event(EVENT_DATA *event, int game_pulses)
2830
if (event->ownertype == EVENT_UNOWNED)
2931
{
3032
bug("enqueue_event: event type %d with no owner.", event->type);
31-
return FALSE;
33+
return false;
3234
}
3335

3436
/* An event must be enqueued into the future */
@@ -49,7 +51,7 @@ bool enqueue_event(EVENT_DATA *event, int game_pulses)
4951
AttachToList(event, eventqueue[bucket]);
5052

5153
/* success */
52-
return TRUE;
54+
return true;
5355
}
5456

5557
/* function :: dequeue_event()
@@ -181,7 +183,7 @@ void heartbeat()
181183
*
182184
* bool event_function ( EVENT_DATA *event );
183185
*
184-
* Any event returning TRUE is not dequeued, it is assumed
186+
* Any event returning true is not dequeued, it is assumed
185187
* that the event has dequeued itself.
186188
*/
187189
if (!((*event->fun)(event)))
@@ -221,7 +223,7 @@ void add_event_mobile(EVENT_DATA *event, D_MOBILE *dMob, int delay)
221223
AttachToList(event, dMob->events);
222224

223225
/* attempt to enqueue the event */
224-
if (enqueue_event(event, delay) == FALSE)
226+
if (enqueue_event(event, delay) == false)
225227
bug("add_event_mobile: event type %d failed to be enqueued.", event->type);
226228
}
227229

@@ -256,7 +258,7 @@ void add_event_socket(EVENT_DATA *event, D_SOCKET *dSock, int delay)
256258
AttachToList(event, dSock->events);
257259

258260
/* attempt to enqueue the event */
259-
if (enqueue_event(event, delay) == FALSE)
261+
if (enqueue_event(event, delay) == false)
260262
bug("add_event_socket: event type %d failed to be enqueued.", event->type);
261263
}
262264

@@ -290,7 +292,7 @@ void add_event_game(EVENT_DATA *event, int delay)
290292
AttachToList(event, global_events);
291293

292294
/* attempt to enqueue the event */
293-
if (enqueue_event(event, delay) == FALSE)
295+
if (enqueue_event(event, delay) == false)
294296
bug("add_event_game: event type %d failed to be enqueued.", event->type);
295297
}
296298

src/event.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdio.h>
33
#include <string.h>
44
#include <unistd.h>
5+
#include <stdbool.h>
56

67
/* include main header file */
78
#include "mud.h"
@@ -28,21 +29,21 @@ bool event_game_tick(EVENT_DATA *event)
2829
event->type = EVENT_GAME_TICK;
2930
add_event_game(event, 10 * 60 * PULSES_PER_SECOND);
3031

31-
return FALSE;
32+
return false;
3233
}
3334

3435
bool event_mobile_save(EVENT_DATA *event)
3536
{
3637
D_MOBILE *dMob;
3738

3839
/* Check to see if there is an owner of this event.
39-
* If there is no owner, we return TRUE, because
40+
* If there is no owner, we return true, because
4041
* it's the safest - and post a bug message.
4142
*/
4243
if ((dMob = event->owner.dMob) == NULL)
4344
{
4445
bug("event_mobile_save: no owner.");
45-
return TRUE;
46+
return true;
4647
}
4748

4849
/* save the actual player file */
@@ -54,30 +55,30 @@ bool event_mobile_save(EVENT_DATA *event)
5455
event->type = EVENT_MOBILE_SAVE;
5556
add_event_mobile(event, dMob, 2 * 60 * PULSES_PER_SECOND);
5657

57-
return FALSE;
58+
return false;
5859
}
5960

6061
bool event_socket_idle(EVENT_DATA *event)
6162
{
6263
D_SOCKET *dSock;
6364

6465
/* Check to see if there is an owner of this event.
65-
* If there is no owner, we return TRUE, because
66+
* If there is no owner, we return true, because
6667
* it's the safest - and post a bug message.
6768
*/
6869
if ((dSock = event->owner.dSock) == NULL)
6970
{
7071
bug("event_socket_idle: no owner.");
71-
return TRUE;
72+
return true;
7273
}
7374

7475
/* tell the socket that it has idled out, and close it */
7576
text_to_socket(dSock, "You have idled out...\n\n\r");
76-
close_socket(dSock, FALSE);
77+
close_socket(dSock, false);
7778

7879
/* since we closed the socket, all events owned
7980
* by that socket has been dequeued, and we need
80-
* to return TRUE, so the caller knows this.
81+
* to return true, so the caller knows this.
8182
*/
82-
return TRUE;
83+
return true;
8384
}

src/gmcp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,29 @@
77
#include <stdio.h>
88
#include <string.h>
99
#include <stdlib.h>
10+
#include <stdbool.h>
11+
1012
#include "mud.h"
1113

1214
const unsigned char gmcp_head [] = { IAC, SB, TELOPT_GMCP, 0 };
1315
const unsigned char gmcp_tail [] = { IAC, SE, 0 };
1416

1517
bool gmcpEnable(D_S *dsock)
1618
{
17-
dsock->gmcp_enabled = TRUE;
19+
dsock->gmcp_enabled = true;
1820
gmcpSend(dsock, "Test data");
1921
return dsock->gmcp_enabled;
2022
}
2123

2224
bool gmcpSend(D_S *dsock, const char *data)
2325
{
2426
if (!dsock->gmcp_enabled)
25-
return FALSE;
27+
return false;
2628

2729
text_to_socket(dsock, (char *) gmcp_head);
2830
text_to_socket(dsock, (char *) data);
2931
text_to_socket(dsock, (char *) gmcp_tail);
30-
return TRUE;
32+
return true;
3133
}
3234

3335
void gmcpReceived(D_S *dsock)

src/help.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <stdio.h>
1313
#include <time.h>
1414
#include <dirent.h>
15+
#include <stdbool.h>
16+
1517

1618
/* include main header file */
1719
#include "mud.h"
@@ -39,7 +41,7 @@ bool check_help(D_MOBILE *dMob, char *helpfile)
3941
ITERATOR Iter;
4042
char buf[MAX_HELP_ENTRY + 80];
4143
char *entry, *hFile;
42-
bool found = FALSE;
44+
bool found = false;
4345

4446
hFile = capitalize(helpfile);
4547

@@ -48,7 +50,7 @@ bool check_help(D_MOBILE *dMob, char *helpfile)
4850
{
4951
if (is_prefix(helpfile, pHelp->keyword))
5052
{
51-
found = TRUE;
53+
found = true;
5254
break;
5355
}
5456
}
@@ -67,10 +69,10 @@ bool check_help(D_MOBILE *dMob, char *helpfile)
6769
{
6870
/* helpfiles do not contain double dots (no moving out of the helpdir) */
6971
if (strstr(hFile, "..") != NULL)
70-
return FALSE;
72+
return false;
7173

7274
if ((entry = read_help_entry(hFile)) == NULL)
73-
return FALSE;
75+
return false;
7476
else
7577
{
7678
if ((pHelp = (HELP_DATA *) malloc(sizeof(*pHelp))) == NULL)
@@ -88,7 +90,7 @@ bool check_help(D_MOBILE *dMob, char *helpfile)
8890
snprintf(buf, MAX_HELP_ENTRY + 80, "=== %s ===\n\r%s", pHelp->keyword, pHelp->text);
8991
text_to_mobile(dMob, buf);
9092

91-
return TRUE;
93+
return true;
9294
}
9395

9496
/*

src/interpret.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
#include <sys/types.h>
55
#include <stdio.h>
6+
#include <stdbool.h>
67

78
/* include main header file */
89
#include "mud.h"
@@ -11,7 +12,7 @@ void handle_cmd_input(D_SOCKET *dsock, char *arg)
1112
{
1213
D_MOBILE *dMob;
1314
char command[MAX_BUFFER];
14-
bool found_cmd = FALSE;
15+
bool found_cmd = false;
1516
int i;
1617

1718
if ((dMob = dsock->player) == NULL)
@@ -25,7 +26,7 @@ void handle_cmd_input(D_SOCKET *dsock, char *arg)
2526

2627
if (is_prefix(command, tabCmd[i].cmd_name))
2728
{
28-
found_cmd = TRUE;
29+
found_cmd = true;
2930
(*tabCmd[i].cmd_funct)(dMob, arg);
3031
}
3132
}

src/io.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdarg.h>
1010
#include <ctype.h>
1111
#include <stdlib.h>
12+
#include <stdbool.h>
1213

1314
/* include main header file */
1415
#include "mud.h"
@@ -176,7 +177,7 @@ char *fread_line(FILE *fp)
176177
int fread_number(FILE *fp)
177178
{
178179
int c, number = 0;
179-
bool negative = FALSE;
180+
bool negative = false;
180181

181182
/* initial read */
182183
c = getc(fp);
@@ -192,7 +193,7 @@ int fread_number(FILE *fp)
192193
abort();
193194
}
194195
else if (c == '-')
195-
negative = TRUE;
196+
negative = true;
196197
else if (!isdigit(c))
197198
{
198199
bug("Fread_number: Not a number.");

0 commit comments

Comments
 (0)