From 07554369bd5af77984e59deabc2326a2d1a93792 Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Tue, 8 Mar 2016 04:52:31 -0600 Subject: [PATCH] Detect stdbool.h and add conformant shims if it isn't available Charybdis requires C99 already, so it's high time we start using stdbool. I've converted a few pieces of code already. A lot of the old code that uses YES/NO should probably be updated too because that's fucking hideous. --- configure.ac | 1 + include/channel.h | 4 +++- include/common.h | 11 ----------- include/setup.h.in | 3 +++ include/stdinc.h | 16 ++++++++++++++++ ircd/blacklist.c | 4 ++-- ircd/chmode.c | 2 +- ircd/client.c | 4 ++-- ircd/s_serv.c | 4 ++-- modules/core/m_join.c | 4 ++-- modules/core/m_mode.c | 2 +- modules/m_testmask.c | 2 +- 12 files changed, 34 insertions(+), 23 deletions(-) diff --git a/configure.ac b/configure.ac index c68be64f1..e17ef34f7 100644 --- a/configure.ac +++ b/configure.ac @@ -120,6 +120,7 @@ AC_DEFINE_DIR([PKGLIBEXECDIR], [pkglibexecdir], [Directory where binaries the IR dnl Checks for header files. AC_HEADER_STDC +AC_HEADER_STDBOOL AC_CHECK_HEADERS([crypt.h sys/resource.h sys/param.h errno.h sys/syslog.h stddef.h sys/wait.h wait.h sys/epoll.h sys/uio.h machine/endian.h]) diff --git a/include/channel.h b/include/channel.h index 496d8e251..44323b0ec 100644 --- a/include/channel.h +++ b/include/channel.h @@ -31,6 +31,8 @@ #define MAXMODEPARAMS 4 #define MAXMODEPARAMSSERV 10 +#include + struct Client; /* mode structure for channels */ @@ -258,7 +260,7 @@ void resv_chan_forcepart(const char *name, const char *reason, int temp_time); extern void set_channel_mode(struct Client *client_p, struct Client *source_p, struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]); extern void set_channel_mlock(struct Client *client_p, struct Client *source_p, - struct Channel *chptr, const char *newmlock, int propagate); + struct Channel *chptr, const char *newmlock, bool propagate); extern struct ChannelMode chmode_table[256]; diff --git a/include/common.h b/include/common.h index e8838009d..e674e1004 100644 --- a/include/common.h +++ b/include/common.h @@ -30,17 +30,6 @@ #define NULL 0 #endif -#ifdef TRUE -#undef TRUE -#endif - -#ifdef FALSE -#undef FALSE -#endif - -#define FALSE 0 -#define TRUE 1 -#define HIDEME 2 /* Blah. I use these a lot. -Dianora */ #ifdef YES diff --git a/include/setup.h.in b/include/setup.h.in index e2432123f..fce3acbbc 100644 --- a/include/setup.h.in +++ b/include/setup.h.in @@ -169,6 +169,9 @@ /* Define to 1 if you have the `socketpair' function. */ #undef HAVE_SOCKETPAIR +/* Define to 1 if you have the header file. */ +#undef HAVE_STDBOOL_H + /* Define to 1 if you have the header file. */ #undef HAVE_STDDEF_H diff --git a/include/stdinc.h b/include/stdinc.h index ca5a1e9ee..9a32e5cec 100644 --- a/include/stdinc.h +++ b/include/stdinc.h @@ -71,6 +71,22 @@ char *alloca (); #endif +#ifdef HAVE_STDBOOL_H +# include +#else +# ifndef HAVE__BOOL +# ifdef __cplusplus +typedef bool _Bool; +# else +# define _Bool signed char +# endif +# endif +# define bool _Bool +# define false 0 +# define true 1 +# define __bool_true_false_are_defined 1 +#endif + #include #include diff --git a/ircd/blacklist.c b/ircd/blacklist.c index 18db5421d..dca1c2ed1 100644 --- a/ircd/blacklist.c +++ b/ircd/blacklist.c @@ -109,7 +109,7 @@ blwarn: static void blacklist_dns_callback(const char *result, int status, int aftype, void *vptr) { struct BlacklistClient *blcptr = (struct BlacklistClient *) vptr; - int listed = 0; + bool listed = false; if (blcptr == NULL || blcptr->client_p == NULL) return; @@ -125,7 +125,7 @@ static void blacklist_dns_callback(const char *result, int status, int aftype, v if (result != NULL && status) { if (blacklist_check_reply(blcptr, result)) - listed = TRUE; + listed = true; } /* they have a blacklist entry for this client */ diff --git a/ircd/chmode.c b/ircd/chmode.c index 3e0d41f3a..5616fc7c7 100644 --- a/ircd/chmode.c +++ b/ircd/chmode.c @@ -1833,7 +1833,7 @@ set_channel_mode(struct Client *client_p, struct Client *source_p, */ void set_channel_mlock(struct Client *client_p, struct Client *source_p, - struct Channel *chptr, const char *newmlock, int propagate) + struct Channel *chptr, const char *newmlock, bool propagate) { rb_free(chptr->mode_lock); chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL; diff --git a/ircd/client.c b/ircd/client.c index 3580c88de..0902af26c 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -1288,7 +1288,7 @@ exit_remote_client(struct Client *client_p, struct Client *source_p, struct Clie } /* - * This assumes IsUnknown(source_p) == TRUE and MyConnect(source_p) == TRUE + * This assumes IsUnknown(source_p) == true and MyConnect(source_p) == true */ static int @@ -1466,7 +1466,7 @@ exit_local_server(struct Client *client_p, struct Client *source_p, struct Clien /* - * This assumes IsPerson(source_p) == TRUE && MyConnect(source_p) == TRUE + * This assumes IsPerson(source_p) == true && MyConnect(source_p) == true */ static int diff --git a/ircd/s_serv.c b/ircd/s_serv.c index 6395aab8f..a479999e9 100644 --- a/ircd/s_serv.c +++ b/ircd/s_serv.c @@ -261,7 +261,7 @@ try_connections(void *unused) struct server_conf *tmp_p; struct Class *cltmp; rb_dlink_node *ptr; - int connecting = FALSE; + bool connecting = false; int confrq = 0; time_t next = 0; @@ -306,7 +306,7 @@ try_connections(void *unused) server_p = tmp_p; /* We connect only one at time... */ - connecting = TRUE; + connecting = true; } if((next > tmp_p->hold) || (next == 0)) diff --git a/modules/core/m_join.c b/modules/core/m_join.c index 966352b7f..af78d781e 100644 --- a/modules/core/m_join.c +++ b/modules/core/m_join.c @@ -488,7 +488,7 @@ ms_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ *modebuf = *parabuf = '\0'; /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ - set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); + set_channel_mlock(client_p, source_p, chptr, NULL, false); } if(!IsMember(source_p, chptr)) @@ -754,7 +754,7 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source strcpy(chptr->chname, parv[2]); /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ - set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); + set_channel_mlock(client_p, source_p, chptr, NULL, false); } if(*modebuf != '\0') diff --git a/modules/core/m_mode.c b/modules/core/m_mode.c index 26bb1b341..e44202931 100644 --- a/modules/core/m_mode.c +++ b/modules/core/m_mode.c @@ -235,7 +235,7 @@ ms_mlock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source return 0; if(IsServer(source_p)) - set_channel_mlock(client_p, source_p, chptr, parv[3], TRUE); + set_channel_mlock(client_p, source_p, chptr, parv[3], true); return 0; } diff --git a/modules/m_testmask.c b/modules/m_testmask.c index 782be8a87..53102abad 100644 --- a/modules/m_testmask.c +++ b/modules/m_testmask.c @@ -34,7 +34,7 @@ /* List of ircd includes from ../include/ */ #include "stdinc.h" #include "client.h" -#include "common.h" /* FALSE bleah */ +#include "common.h" #include "ircd.h" #include "match.h" #include "numeric.h"