From 0aa2840164fc782f150cd45f8668ca623e6002cf Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 11 Sep 2016 15:47:51 +0100 Subject: [PATCH] Group #include directives in 3-4 groups. 1. Current module (if C file). 2. Headers from current library. 3. Headers from other library (e.g. toxcore includes in toxav). 4. System headers. --- toxav/audio.c | 5 +++-- toxav/audio.h | 6 +++--- toxav/bwcontroller.c | 4 +++- toxav/bwcontroller.h | 1 + toxav/group.c | 3 ++- toxav/group.h | 4 ++-- toxav/msi.c | 3 ++- toxav/msi.h | 9 +++++---- toxav/rtp.c | 6 ++++-- toxav/rtp.h | 6 ++++-- toxav/toxav.c | 2 ++ toxav/toxav_old.c | 3 ++- toxav/video.c | 7 ++++--- toxav/video.h | 10 +++++----- toxcore/DHT.c | 11 ++++------- toxcore/LAN_discovery.c | 1 + toxcore/LAN_discovery.h | 1 - toxcore/Messenger.c | 9 +++++---- toxcore/TCP_client.c | 4 ++-- toxcore/TCP_connection.c | 1 + toxcore/TCP_server.c | 4 ++-- toxcore/TCP_server.h | 2 +- toxcore/assoc.c | 9 ++++----- toxcore/friend_connection.c | 1 + toxcore/friend_connection.h | 1 - toxcore/friend_requests.c | 2 +- toxcore/group.c | 1 + toxcore/net_crypto.c | 5 ++++- toxcore/net_crypto.h | 1 + toxcore/network.c | 6 +++--- toxcore/onion.c | 1 + toxcore/onion_announce.c | 3 ++- toxcore/onion_client.c | 3 ++- toxcore/ping.c | 6 +++--- toxcore/ping_array.c | 3 ++- toxcore/tox.c | 9 ++++----- toxcore/tox_group.c | 7 +++---- toxcore/util.c | 9 ++++----- 38 files changed, 94 insertions(+), 75 deletions(-) diff --git a/toxav/audio.c b/toxav/audio.c index c0bfa608..0b0aaf2d 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -23,13 +23,14 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ -#include - #include "audio.h" + #include "rtp.h" #include "../toxcore/logger.h" +#include + static struct JitterBuffer *jbuf_new(uint32_t capacity); static void jbuf_clear(struct JitterBuffer *q); static void jbuf_free(struct JitterBuffer *q); diff --git a/toxav/audio.h b/toxav/audio.h index 6832f6a9..5f9d7f7d 100644 --- a/toxav/audio.h +++ b/toxav/audio.h @@ -22,14 +22,14 @@ #ifndef AUDIO_H #define AUDIO_H -#include -#include - #include "toxav.h" #include "../toxcore/logger.h" #include "../toxcore/util.h" +#include +#include + struct RTPMessage; typedef struct ACSession_s { diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index 49a2d9e1..8ca22fbf 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -23,9 +23,11 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ +#include "bwcontroller.h" + #include "../toxcore/logger.h" #include "../toxcore/util.h" -#include "bwcontroller.h" + #include #define BWC_PACKET_ID 196 diff --git a/toxav/bwcontroller.h b/toxav/bwcontroller.h index 5e7ae9df..610194bf 100644 --- a/toxav/bwcontroller.h +++ b/toxav/bwcontroller.h @@ -21,6 +21,7 @@ #ifndef BWCONROLER_H #define BWCONROLER_H + #include "../toxcore/Messenger.h" typedef struct BWController_s BWController; diff --git a/toxav/group.c b/toxav/group.c index 969250f8..ea84bf72 100644 --- a/toxav/group.c +++ b/toxav/group.c @@ -22,9 +22,10 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ +#include "group.h" + #include "../toxcore/logger.h" #include "../toxcore/util.h" -#include "group.h" #define GROUP_JBUF_SIZE 6 #define GROUP_JBUF_DEAD_SECONDS 4 diff --git a/toxav/group.h b/toxav/group.h index e255796b..1929b17c 100644 --- a/toxav/group.h +++ b/toxav/group.h @@ -18,11 +18,11 @@ * along with Tox. If not, see . */ +#include "../toxcore/group.h" + /* Audio encoding/decoding */ #include -#include "../toxcore/group.h" - #define GROUP_AUDIO_PACKET_ID 192 /* Create a new toxav group. diff --git a/toxav/msi.c b/toxav/msi.c index 505a7df5..cb92525a 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -24,9 +24,10 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ +#include "msi.h" + #include "../toxcore/logger.h" #include "../toxcore/util.h" -#include "msi.h" #include #include diff --git a/toxav/msi.h b/toxav/msi.h index 8cb47384..f69e67ef 100644 --- a/toxav/msi.h +++ b/toxav/msi.h @@ -22,13 +22,14 @@ #ifndef MSI_H #define MSI_H -#include -#include - -#include "../toxcore/Messenger.h" #include "audio.h" #include "video.h" +#include "../toxcore/Messenger.h" + +#include +#include + /** * Error codes. */ diff --git a/toxav/rtp.c b/toxav/rtp.c index 6e0c22b2..05430c62 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -23,11 +23,13 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ +#include "rtp.h" + +#include "bwcontroller.h" + #include "../toxcore/Messenger.h" #include "../toxcore/logger.h" #include "../toxcore/util.h" -#include "bwcontroller.h" -#include "rtp.h" #include #include diff --git a/toxav/rtp.h b/toxav/rtp.h index 18929e12..30d8ca65 100644 --- a/toxav/rtp.h +++ b/toxav/rtp.h @@ -22,9 +22,11 @@ #ifndef RTP_H #define RTP_H -#include "../toxcore/Messenger.h" #include "bwcontroller.h" -#include "stdbool.h" + +#include "../toxcore/Messenger.h" + +#include /** * Payload type identifier. Also used as rtp callback prefix. diff --git a/toxav/toxav.c b/toxav/toxav.c index 749519a2..9cb7be33 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -23,6 +23,8 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ +#include "toxav.h" + #include "msi.h" #include "rtp.h" diff --git a/toxav/toxav_old.c b/toxav/toxav_old.c index b132080b..a344455d 100644 --- a/toxav/toxav_old.c +++ b/toxav/toxav_old.c @@ -22,9 +22,10 @@ * This file contains the group chats code for the backwards compatibility. */ -#include "group.h" #include "toxav.h" +#include "group.h" + /* Create a new toxav group. * * return group number on success. diff --git a/toxav/video.c b/toxav/video.c index 195ff041..9aba27ed 100644 --- a/toxav/video.c +++ b/toxav/video.c @@ -23,16 +23,17 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ -#include -#include +#include "video.h" #include "msi.h" #include "rtp.h" -#include "video.h" #include "../toxcore/logger.h" #include "../toxcore/network.h" +#include +#include + #define MAX_DECODE_TIME_US 0 /* Good quality encode. */ #define VIDEO_DECODE_BUFFER_SIZE 20 diff --git a/toxav/video.h b/toxav/video.h index 6aeeaef6..335240c7 100644 --- a/toxav/video.h +++ b/toxav/video.h @@ -22,6 +22,11 @@ #ifndef VIDEO_H #define VIDEO_H +#include "toxav.h" + +#include "../toxcore/logger.h" +#include "../toxcore/util.h" + #include #include #include @@ -33,11 +38,6 @@ #include -#include "toxav.h" - -#include "../toxcore/logger.h" -#include "../toxcore/util.h" - struct RTPMessage; typedef struct VCSession_s { diff --git a/toxcore/DHT.c b/toxcore/DHT.c index f9910b06..beff0499 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -27,23 +27,20 @@ #include "config.h" #endif -#include - -#include "logger.h" - #include "DHT.h" #ifdef ENABLE_ASSOC_DHT #include "assoc.h" #endif - -#include "ping.h" - #include "LAN_discovery.h" +#include "logger.h" #include "misc_tools.h" #include "network.h" +#include "ping.h" #include "util.h" +#include + /* The timeout after which a node is discarded completely. */ #define KILL_NODE_TIMEOUT (BAD_NODE_TIMEOUT + PING_INTERVAL) diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index f0b12a3e..115b626d 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -26,6 +26,7 @@ #endif #include "LAN_discovery.h" + #include "util.h" /* Used for get_broadcast(). */ diff --git a/toxcore/LAN_discovery.h b/toxcore/LAN_discovery.h index 358bea2f..65304791 100644 --- a/toxcore/LAN_discovery.h +++ b/toxcore/LAN_discovery.h @@ -25,7 +25,6 @@ #ifndef LAN_DISCOVERY_H #define LAN_DISCOVERY_H - #include "DHT.h" /* Interval in seconds between LAN discovery packet sending. */ diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 8616bd8d..b72fac93 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -25,16 +25,17 @@ #include "config.h" #endif -#ifdef TOX_DEBUG -#include -#endif - #include "Messenger.h" + #include "assoc.h" #include "logger.h" #include "network.h" #include "util.h" +#ifdef TOX_DEBUG +#include +#endif + static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata); static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data, diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 15e26107..d825cf38 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -26,12 +26,12 @@ #include "TCP_client.h" +#include "util.h" + #if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) #include #endif -#include "util.h" - /* return 1 on success * return 0 on failure */ diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index 623aeb4f..6a0b2c8a 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -26,6 +26,7 @@ #endif #include "TCP_connection.h" + #include "util.h" /* Set the size of the array to num. diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 81f884d8..d4b5ddd1 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -26,12 +26,12 @@ #include "TCP_server.h" +#include "util.h" + #if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) #include #endif -#include "util.h" - /* return 1 on success * return 0 on failure */ diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h index f5768594..dedb819f 100644 --- a/toxcore/TCP_server.h +++ b/toxcore/TCP_server.h @@ -28,7 +28,7 @@ #include "onion.h" #ifdef TCP_SERVER_USE_EPOLL -#include "sys/epoll.h" +#include #endif #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__MACH__) diff --git a/toxcore/assoc.c b/toxcore/assoc.c index 0a3845bc..df84fff5 100644 --- a/toxcore/assoc.c +++ b/toxcore/assoc.c @@ -1,16 +1,15 @@ - #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "DHT.h" #include "assoc.h" + +#include "DHT.h" +#include "LAN_discovery.h" #include "logger.h" #include "ping.h" - -#include "LAN_discovery.h" - #include "util.h" + #include /* diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 9e78a0c5..fa88f1bc 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c @@ -26,6 +26,7 @@ #endif #include "friend_connection.h" + #include "util.h" /* return 1 if the friendcon_id is not valid. diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h index c5179a6a..df017c1f 100644 --- a/toxcore/friend_connection.h +++ b/toxcore/friend_connection.h @@ -30,7 +30,6 @@ #include "net_crypto.h" #include "onion_client.h" - #define MAX_FRIEND_CONNECTION_CALLBACKS 2 #define MESSENGER_CALLBACK_INDEX 0 #define GROUPCHAT_CALLBACK_INDEX 1 diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index 3d10213b..a011c72e 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c @@ -26,8 +26,8 @@ #endif #include "friend_requests.h" -#include "util.h" +#include "util.h" /* Set and get the nospam variable used to prevent one type of friend request spam. */ void set_nospam(Friend_Requests *fr, uint32_t num) diff --git a/toxcore/group.c b/toxcore/group.c index c7844d6d..a85b7320 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -26,6 +26,7 @@ #endif #include "group.h" + #include "util.h" /* return 1 if the groupnumber is not valid. diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 72a34811..b93b5cde 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -27,10 +27,13 @@ #include "config.h" #endif -#include "math.h" #include "net_crypto.h" + #include "util.h" +#include + + static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_connection_id) { if ((uint32_t)crypt_connection_id >= c->crypto_connections_length) { diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index e676b864..7d2644f4 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -28,6 +28,7 @@ #include "LAN_discovery.h" #include "TCP_connection.h" #include "logger.h" + #include #define CRYPTO_CONN_NO_CONNECTION 0 diff --git a/toxcore/network.c b/toxcore/network.c index 2097078a..1e6661cb 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -29,7 +29,10 @@ #include "config.h" #endif +#include "network.h" + #include "logger.h" +#include "util.h" #if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) #include @@ -40,9 +43,6 @@ #include #endif -#include "network.h" -#include "util.h" - #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) static const char *inet_ntop(sa_family_t family, void *addr, char *buf, size_t bufsize) diff --git a/toxcore/onion.c b/toxcore/onion.c index 0f0abf26..ba3f1f4a 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -24,6 +24,7 @@ #endif #include "onion.h" + #include "util.h" #define RETURN_1 ONION_RETURN_1 diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 3be76ddf..42b3a635 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -23,8 +23,9 @@ #include "config.h" #endif -#include "LAN_discovery.h" #include "onion_announce.h" + +#include "LAN_discovery.h" #include "util.h" #define PING_ID_TIMEOUT 20 diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 092198f2..a140e008 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -24,8 +24,9 @@ #include "config.h" #endif -#include "LAN_discovery.h" #include "onion_client.h" + +#include "LAN_discovery.h" #include "util.h" /* defines for the array size and diff --git a/toxcore/ping.c b/toxcore/ping.c index a0cfbf18..d2a01f5d 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c @@ -27,15 +27,15 @@ #include "config.h" #endif -#include - -#include "DHT.h" #include "ping.h" +#include "DHT.h" #include "network.h" #include "ping_array.h" #include "util.h" +#include + #define PING_NUM_MAX 512 /* Maximum newly announced nodes to ping per TIME_TO_PING seconds. */ diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c index 8c5d72e9..8a23c6d8 100644 --- a/toxcore/ping_array.c +++ b/toxcore/ping_array.c @@ -26,8 +26,9 @@ #include "config.h" #endif -#include "crypto_core.h" #include "ping_array.h" + +#include "crypto_core.h" #include "util.h" static void clear_entry(Ping_Array *array, uint32_t index) diff --git a/toxcore/tox.c b/toxcore/tox.c index 40746656..9ec472c0 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -25,17 +25,16 @@ #include "config.h" #endif +#define TOX_DEFINED +typedef struct Messenger Tox; +#include "tox.h" + #include "Messenger.h" #include "group.h" #include "logger.h" #include "../toxencryptsave/defines.h" -#define TOX_DEFINED -typedef struct Messenger Tox; - -#include "tox.h" - #define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}} #if TOX_HASH_LENGTH != crypto_hash_sha256_BYTES diff --git a/toxcore/tox_group.c b/toxcore/tox_group.c index 2228ed88..62c84b22 100644 --- a/toxcore/tox_group.c +++ b/toxcore/tox_group.c @@ -25,13 +25,12 @@ #include "config.h" #endif -#include "Messenger.h" -#include "group.h" - #define TOX_DEFINED typedef struct Messenger Tox; +#include "tox_group.h" -#include "tox.h" +#include "Messenger.h" +#include "group.h" /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ diff --git a/toxcore/util.c b/toxcore/util.c index 92ad4510..40bf2849 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -26,13 +26,12 @@ #include "config.h" #endif -#include - -/* for crypto_box_PUBLICKEYBYTES */ -#include "crypto_core.h" - #include "util.h" +#include "crypto_core.h" /* for crypto_box_PUBLICKEYBYTES */ + +#include + /* don't call into system billions of times for no reason */ static uint64_t unix_time_value;