From 24480c7cb7f148a84f1ab3de37a16a6369808dfd Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Sat, 2 Jan 2021 14:12:13 +0000 Subject: [PATCH] Move all required includes to specific files to follow yet another standard and reformat code --- src/buffer.c | 12 ++++++++++++ src/buffer.h | 9 --------- src/channels.c | 23 +++++++++++++++++++---- src/channels.h | 10 +--------- src/configuration.c | 7 +++++++ src/configuration.h | 4 ---- src/connection.c | 19 +++++++++++++++++++ src/connection.h | 14 ++------------ src/filesystem.c | 14 ++++++++++++++ src/filesystem.h | 16 +++++----------- src/logging.h | 2 -- src/main.c | 20 ++++++++++++++++++++ src/main.h | 15 --------------- src/memory.c | 7 +++++++ src/memory.h | 6 ------ src/signal.c | 8 ++++++++ src/signal.h | 8 +------- 17 files changed, 115 insertions(+), 79 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 0b98ac2..4081451 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -18,6 +18,18 @@ #include "buffer.h" +#include "logging.h" + +#include // errno +#include // fprintf() +#include // strerror() +#include // size_t ssize_t +#include // write() + +#define UIRC_IRCV3 +#define UIRC_HELPERS +#include // Tok_mesg() + ssize_t get_buffer_line(char* buf) { diff --git a/src/buffer.h b/src/buffer.h index 2d9010c..2090178 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -16,16 +16,7 @@ * along with uIRCd. If not, see . */ -#include "logging.h" - -#include // errno -#include // strerror() #include // size_t ssize_t -#include // write() - -#define UIRC_IRCV3 -#define UIRC_HELPERS -#include // Tok_mesg() ssize_t get_buffer_line(char* buf); ssize_t flush_buffer(char* buf, size_t buflen, int fd); diff --git a/src/channels.c b/src/channels.c index 15036ab..7c32d9b 100644 --- a/src/channels.c +++ b/src/channels.c @@ -18,6 +18,17 @@ #include "channels.h" +#include "logging.h" // LOG() +#include "memory.h" // allocate_copy() + +#include // errno +#include // bool +#include // snprintf() +#include // strerror() +#include // sockaddr connect() +#include // size_t ssize_t socklen_t +#include // malloc() realloc() + int init_chanarray(Channel** chans) { @@ -40,9 +51,9 @@ resize_chanarray(Channel** chans) Channel* tmp = NULL; LOG(LOG_DEBUG, "Found %i existing channels.", i); if ((tmp = realloc(*chans, (i + 2) * sizeof(Channel))) != NULL) { - *chans = tmp; - tmp[i+1].name = NULL; - tmp[i+1].key = NULL; + *chans = tmp; + tmp[i + 1].name = NULL; + tmp[i + 1].key = NULL; } else { LOG(LOG_WARN, "Could not allocate channel struct. " ERRNOFMT, strerror(errno), errno); return -1; @@ -62,7 +73,11 @@ set_channel(Channel* chan, const char* name, const char* key, bool joined) } if (key != NULL) { if (!allocate_copy(&chan->key, key)) { - LOG(LOG_WARN, "Couldn't allocate memory for the channel %s key. " ERRNOFMT, (name == NULL) ? chan->name : name, strerror(errno), errno); + LOG(LOG_WARN, + "Couldn't allocate memory for the channel %s key. " ERRNOFMT, + (name == NULL) ? chan->name : name, + strerror(errno), + errno); return 0; } } diff --git a/src/channels.h b/src/channels.h index abbcb7b..df0d11c 100644 --- a/src/channels.h +++ b/src/channels.h @@ -16,15 +16,7 @@ * along with uIRCd. If not, see . */ -#include "logging.h" // LOG() -#include "memory.h" // allocate_copy() - -#include // errno -#include // bool -#include // snprintf() -#include // strerror() -#include // sockaddr connect() -#include // size_t ssize_t socklen_t +#include // bool #ifndef UIRCD_GUARD_CHANNELS #define UIRCD_GUARD_CHANNELS diff --git a/src/configuration.c b/src/configuration.c index b5832d7..87ada96 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -18,7 +18,14 @@ #include "configuration.h" +#include "channels.h" +#include "connection.h" +#include "logging.h" +#include "memory.h" + #ifdef UIRCD_FEATURE_LIBCONFIG +#include // config_t config_setting_t config_init() ... + int parse_configfile(char* config_path, Connection* conn) { diff --git a/src/configuration.h b/src/configuration.h index f5f375c..3c5434b 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -20,11 +20,7 @@ #include // config_t config_setting_t config_init() ... #endif /* UIRCD_FEATURE_LIBCONFIG */ - -#include "channels.h" #include "connection.h" -#include "logging.h" -#include "memory.h" #ifndef UIRCD_GUARD_CONFIGURATION #define UIRCD_GUARD_CONFIGURATION diff --git a/src/connection.c b/src/connection.c index 58749ce..44f8c58 100644 --- a/src/connection.c +++ b/src/connection.c @@ -18,6 +18,25 @@ #include "connection.h" +#include "buffer.h" +#include "channels.h" +#include "limits.h" +#include "logging.h" +#include "memory.h" + +#include // errno +#include // ?? +#include // getaddrinfo() gai_strerror() +#include // bool +#include // snprintf() +#include // strerror() +#include // sockaddr connect() +#include // size_t ssize_t socklen_t +#include // ?? + +#define UIRC_HELPERS +#include // Assm_mesg Assm_cmd... + signed int init_connection(Connection* conn) { diff --git a/src/connection.h b/src/connection.h index 035993e..3e47afe 100644 --- a/src/connection.h +++ b/src/connection.h @@ -16,21 +16,11 @@ * along with uIRCd. If not, see . */ -#include "buffer.h" #include "channels.h" #include "limits.h" -#include "logging.h" -#include "memory.h" -#include // errno -#include // ?? -#include // getaddrinfo() gai_strerror() -#include // bool -#include // snprintf() -#include // strerror() -#include // sockaddr connect() -#include // size_t ssize_t socklen_t -#include // ?? +#include // bool +#include // size_t ssize_t socklen_t #define UIRC_IRCV3 #define UIRC_HELPERS diff --git a/src/filesystem.c b/src/filesystem.c index b21110e..f7fd7eb 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -18,6 +18,20 @@ #include "filesystem.h" +#include "connection.h" +#include "limits.h" +#include "logging.h" + +#include // isalpha() isdigit() +#include // errno +#include // fnctl() +#include // ?? +#include // bool +#include // fopen() FILE fprintf() +#include // strerror() +#include // mkfifo() mkdir() +#include // size_t ssize_t mode_t + int mkdir_bottomup(char* path) { diff --git a/src/filesystem.h b/src/filesystem.h index 2011ad7..2e750b8 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -17,18 +17,12 @@ */ #include "connection.h" -#include "limits.h" -#include "logging.h" -#include // isalpha() isdigit() -#include // errno -#include // fnctl() -#include // ?? -#include // bool -#include // fopen() FILE fprintf() -#include // strerror() -#include // mkfifo() mkdir() -#include // size_t ssize_t mode_t +#include +#include + +#define UIRC_IRCV3 +#include // IRC_Message #ifndef UIRCD_GUARD_FILESYSTEM #define UIRCD_GUARD_FILESYSTEM diff --git a/src/logging.h b/src/logging.h index 46251cd..8d93083 100644 --- a/src/logging.h +++ b/src/logging.h @@ -16,8 +16,6 @@ * along with uIRCd. If not, see . */ -#include // fprintf() - #ifndef UIRCD_GUARD_LOGGING #define UIRCD_GUARD_LOGGING diff --git a/src/main.c b/src/main.c index 191bad6..b235f3c 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,26 @@ #include "main.h" +#include "buffer.h" +#include "configuration.h" +#include "connection.h" +#include "filesystem.h" +#include "logging.h" +#include "memory.h" +#include "signal.h" + +#include // errno +#include // O_NONBLOCK +#include // printf() +#include // srand() +#include // strerror() +#include // time_t size_t +#include // getopt() chdir() close() + +#define UIRC_IRCV3 +#define UIRC_HELPERS +#include // IRC_Message + int parse_args(int argc, char** argv, Connection* conn) { diff --git a/src/main.h b/src/main.h index 99ff8b8..38a7a50 100644 --- a/src/main.h +++ b/src/main.h @@ -16,22 +16,7 @@ * along with uIRCd. If not, see . */ -#include "buffer.h" -#include "configuration.h" #include "connection.h" -#include "filesystem.h" -#include "logging.h" -#include "memory.h" -#include "signal.h" - -#include // printf() -#include // srand() -#include // time_t size_t -#include // getopt() chdir() close() - -#define UIRC_IRCV3 -#define UIRC_HELPERS -#include // IRC_Message #ifndef UIRCD_GUARD_MAIN #define UIRCD_GUARD_MAIN diff --git a/src/memory.c b/src/memory.c index efc0510..f457199 100644 --- a/src/memory.c +++ b/src/memory.c @@ -18,6 +18,13 @@ #include "memory.h" +#include "logging.h" + +#include // bool +#include // fprintf() +#include // malloc() free() +#include // strcpy() + /* Description: * This is a allocation manager that frees or allocates variables to pointers depending on the context. * If the pointer is already allocated it will free it and replace it with var diff --git a/src/memory.h b/src/memory.h index 4a401c8..5bc305b 100644 --- a/src/memory.h +++ b/src/memory.h @@ -16,12 +16,6 @@ * along with uIRCd. If not, see . */ -#include "logging.h" - -#include // bool -#include // malloc() free() -#include // strcpy() - #ifndef UIRCD_GUARD_MEMORY #define UIRCD_GUARD_MEMORY diff --git a/src/signal.c b/src/signal.c index 02f2819..5c512cd 100644 --- a/src/signal.c +++ b/src/signal.c @@ -18,6 +18,14 @@ #include "signal.h" +#include "logging.h" + +#include // errno +#include // sig_atomic_t +#include // true, false +#include // NULL, fprintf() +#include // strerror() + sig_atomic_t volatile run = true; void diff --git a/src/signal.h b/src/signal.h index 02cb647..bce9d85 100644 --- a/src/signal.h +++ b/src/signal.h @@ -16,13 +16,7 @@ * along with uIRCd. If not, see . */ -#include "logging.h" - -#include // errno -#include // sig_atomic_t -#include // true, false -#include // NULL -#include // strerror() +#include // sig_atomic_t, siginfo_t #ifndef UIRCD_GUARD_SIGNAL #define UIRCD_GUARD_SIGNAL