From 2886768d30823a46b5f45b8c0ca6e64ee1e88f7a Mon Sep 17 00:00:00 2001
From: Richard Nyberg <rnyberg@murmeldjur.se>
Date: Sun, 20 May 2007 14:43:40 +0000
Subject: [PATCH] Clean up the #include sections in the btpd files. Most common
 headers and all btpd headers are included through btpd.h.

---
 btpd/active.c        |  6 ------
 btpd/btpd.c          |  6 ++----
 btpd/btpd.h          | 30 ++++++++++++++++++++----------
 btpd/cli_if.c        | 18 +++---------------
 btpd/content.c       | 13 ++-----------
 btpd/download.c      |  3 ---
 btpd/download_subr.c |  9 ++-------
 btpd/http_tr_if.c    |  8 ++------
 btpd/main.c          | 14 ++------------
 btpd/net.c           | 19 ++-----------------
 btpd/net_buf.c       |  3 ---
 btpd/opts.c          |  3 +--
 btpd/peer.c          |  9 +--------
 btpd/tlib.c          | 11 +++--------
 btpd/torrent.c       | 16 +---------------
 btpd/tracker_req.c   |  4 ----
 btpd/udp_tr_if.c     |  9 +--------
 btpd/upload.c        |  2 --
 btpd/util.c          |  6 ++----
 19 files changed, 44 insertions(+), 145 deletions(-)

diff --git a/btpd/active.c b/btpd/active.c
index 9db9a04..567b7a5 100644
--- a/btpd/active.c
+++ b/btpd/active.c
@@ -1,9 +1,3 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <string.h>
-#include <unistd.h>
-
 #include "btpd.h"
 
 void
diff --git a/btpd/btpd.c b/btpd/btpd.c
index 965876b..67419ed 100644
--- a/btpd/btpd.c
+++ b/btpd/btpd.c
@@ -1,10 +1,8 @@
+#include "btpd.h"
+
 #include <signal.h>
-#include <string.h>
 #include <time.h>
 
-#include "btpd.h"
-#include "active.h"
-
 static uint8_t m_peer_id[20];
 static struct event m_sigint;
 static struct event m_sigterm;
diff --git a/btpd/btpd.h b/btpd/btpd.h
index 6651b49..848914c 100644
--- a/btpd/btpd.h
+++ b/btpd/btpd.h
@@ -2,23 +2,35 @@
 #define BTPD_H
 
 #include <sys/types.h>
-#include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
 #include <assert.h>
 #include <errno.h>
-#include <event.h>
+#include <fcntl.h>
+#include <math.h>
 #include <inttypes.h>
 #include <limits.h>
 #include <stddef.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
-#include "queue.h"
+#include <benc.h>
+#define DAEMON
+#include <btpd_if.h>
+#undef DAEMON
+#include <event.h>
+#include <metainfo.h>
+#include <queue.h>
+#include <subr.h>
 
-#include "benc.h"
-#include "metainfo.h"
-#include "subr.h"
-#include "iobuf.h"
+#include "active.h"
 #include "hashtable.h"
 #include "net_buf.h"
 #include "net_types.h"
@@ -30,9 +42,7 @@
 #include "upload.h"
 #include "content.h"
 #include "opts.h"
-#define DAEMON
-#include "btpd_if.h"
-#undef DAEMON
+#include "tracker_req.h"
 
 #define BTPD_VERSION PACKAGE_NAME "/" PACKAGE_VERSION
 
diff --git a/btpd/cli_if.c b/btpd/cli_if.c
index 20afbac..23f9f7a 100644
--- a/btpd/cli_if.c
+++ b/btpd/cli_if.c
@@ -1,19 +1,7 @@
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <arpa/inet.h>
-#include <sys/stat.h>
-
-#include <inttypes.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
 #include "btpd.h"
-#include "active.h"
-#include "tracker_req.h"
+
+#include <sys/un.h>
+#include <iobuf.h>
 
 struct cli {
     int sd;
diff --git a/btpd/content.c b/btpd/content.c
index 5807477..d29e22c 100644
--- a/btpd/content.c
+++ b/btpd/content.c
@@ -1,16 +1,7 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <fcntl.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
+#include "btpd.h"
 
 #include <openssl/sha.h>
-
-#include "btpd.h"
-#include "stream.h"
+#include <stream.h>
 
 struct content {
     enum { CM_INACTIVE, CM_STARTING, CM_ACTIVE } state;
diff --git a/btpd/download.c b/btpd/download.c
index 523886a..d24b0a2 100644
--- a/btpd/download.c
+++ b/btpd/download.c
@@ -1,7 +1,4 @@
-#include <math.h>
-
 #include "btpd.h"
-#include "tracker_req.h"
 
 /*
  * Called when a peer announces it's got a new piece.
diff --git a/btpd/download_subr.c b/btpd/download_subr.c
index d12efa9..2f57f07 100644
--- a/btpd/download_subr.c
+++ b/btpd/download_subr.c
@@ -19,15 +19,10 @@
  *
  */
 
-#include <fcntl.h>
-#include <math.h>
-#include <string.h>
-#include <unistd.h>
+#include "btpd.h"
 
 #include <openssl/sha.h>
-
-#include "btpd.h"
-#include "stream.h"
+#include <stream.h>
 
 static struct piece *
 piece_alloc(struct net *n, uint32_t index)
diff --git a/btpd/http_tr_if.c b/btpd/http_tr_if.c
index 78741ac..9247b5e 100644
--- a/btpd/http_tr_if.c
+++ b/btpd/http_tr_if.c
@@ -1,10 +1,6 @@
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <string.h>
-
 #include "btpd.h"
-#include "tracker_req.h"
-#include "http_client.h"
+
+#include <http_client.h>
 
 #define MAX_DOWNLOAD (1 << 18)  // 256kB
 
diff --git a/btpd/main.c b/btpd/main.c
index 79bbcd9..ea9df58 100644
--- a/btpd/main.c
+++ b/btpd/main.c
@@ -1,19 +1,9 @@
-#include <sys/types.h>
-#include <sys/file.h>
-#include <sys/stat.h>
-#include <arpa/inet.h>
+#include "btpd.h"
 
+#include <sys/file.h>
 #include <err.h>
-#include <errno.h>
-#include <event.h>
 #include <evdns.h>
-#include <fcntl.h>
 #include <getopt.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "btpd.h"
 
 static void
 writepid(int pidfd)
diff --git a/btpd/net.c b/btpd/net.c
index b2a1032..5829dc3 100644
--- a/btpd/net.c
+++ b/btpd/net.c
@@ -1,23 +1,8 @@
-#include <sys/types.h>
+#include "btpd.h"
+
 #include <sys/uio.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
 #include <netdb.h>
 
-#include <sys/mman.h>
-#include <sys/wait.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "btpd.h"
-
 static unsigned long m_bw_bytes_in;
 static unsigned long m_bw_bytes_out;
 
diff --git a/btpd/net_buf.c b/btpd/net_buf.c
index 0be194c..1d9c3bf 100644
--- a/btpd/net_buf.c
+++ b/btpd/net_buf.c
@@ -1,6 +1,3 @@
-#include <math.h>
-#include <string.h>
-
 #include "btpd.h"
 
 static struct net_buf *m_choke;
diff --git a/btpd/opts.c b/btpd/opts.c
index 1893e2c..a46bf42 100644
--- a/btpd/opts.c
+++ b/btpd/opts.c
@@ -1,5 +1,4 @@
-#include <btpd.h>
-#include <netinet/in.h>
+#include "btpd.h"
 
 const char *btpd_dir;
 #ifdef DEBUG
diff --git a/btpd/peer.c b/btpd/peer.c
index f84d886..7af6c21 100644
--- a/btpd/peer.c
+++ b/btpd/peer.c
@@ -1,13 +1,6 @@
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include "btpd.h"
 
 #include <ctype.h>
-#include <math.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "btpd.h"
 
 void
 peer_kill(struct peer *p)
diff --git a/btpd/tlib.c b/btpd/tlib.c
index 3debe85..03c1381 100644
--- a/btpd/tlib.c
+++ b/btpd/tlib.c
@@ -1,13 +1,8 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
+#include "btpd.h"
 
+#include <sys/mman.h>
 #include <dirent.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "btpd.h"
+#include <iobuf.h>
 
 HTBL_TYPE(numtbl, tlib, unsigned, num, nchain);
 HTBL_TYPE(hashtbl, tlib, uint8_t, hash, hchain);
diff --git a/btpd/torrent.c b/btpd/torrent.c
index d99cd80..c77e9da 100644
--- a/btpd/torrent.c
+++ b/btpd/torrent.c
@@ -1,21 +1,7 @@
-#include <sys/types.h>
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <math.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+#include "btpd.h"
 
 #include <openssl/sha.h>
 
-#include "btpd.h"
-#include "tracker_req.h"
-#include "stream.h"
-
 #define SAVE_INTERVAL 300
 
 static unsigned m_ntorrents;
diff --git a/btpd/tracker_req.c b/btpd/tracker_req.c
index 61425cb..f3acc1e 100644
--- a/btpd/tracker_req.c
+++ b/btpd/tracker_req.c
@@ -1,8 +1,4 @@
-#include <string.h>
-
 #include "btpd.h"
-#include "subr.h"
-#include "tracker_req.h"
 
 #define REQ_DELAY 1
 #define STOP_ERRORS 5
diff --git a/btpd/udp_tr_if.c b/btpd/udp_tr_if.c
index 6fcfa89..3790d95 100644
--- a/btpd/udp_tr_if.c
+++ b/btpd/udp_tr_if.c
@@ -1,13 +1,6 @@
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include "btpd.h"
 
-#include <event.h>
 #include <evdns.h>
-#include <string.h>
-
-#include "btpd.h"
-#include "tracker_req.h"
 
 struct udp_tr_req {
     enum { UDP_RESOLVE, UDP_CONN_SEND, UDP_CONN_RECV,
diff --git a/btpd/upload.c b/btpd/upload.c
index e2ea30b..cd8fabf 100644
--- a/btpd/upload.c
+++ b/btpd/upload.c
@@ -1,5 +1,3 @@
-#include <string.h>
-
 #include "btpd.h"
 
 #define CHOKE_INTERVAL (& (struct timeval) { 10, 0 })
diff --git a/btpd/util.c b/btpd/util.c
index c4d4757..b2f2b3d 100644
--- a/btpd/util.c
+++ b/btpd/util.c
@@ -1,10 +1,8 @@
+#include "btpd.h"
+
 #include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
 #include <time.h>
 
-#include "btpd.h"
-
 void *
 btpd_malloc(size_t size)
 {