From 690eb3f5930079698f2e318c8be29fd6ef0c0a71 Mon Sep 17 00:00:00 2001
From: Yorhel <git@yorhel.nl>
Date: Sat, 11 Apr 2009 13:47:55 +0200
Subject: [PATCH] Header file cleanup

Moved everything that doesn't belong in ncdu.h into the other header
or c files. Looks much better this way.
---
 src/calc.c | 12 +++++++++++-
 src/calc.h |  2 ++
 src/main.c | 11 +++++++----
 src/ncdu.h | 51 ++++-----------------------------------------------
 src/util.h |  1 +
 5 files changed, 25 insertions(+), 52 deletions(-)

diff --git a/src/calc.c b/src/calc.c
index 08122ac..a8c9dc6 100644
--- a/src/calc.c
+++ b/src/calc.c
@@ -28,6 +28,16 @@
 #include "exclude.h"
 #include "util.h"
 
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <dirent.h>
+
 struct state_calc stcalc;
 
 
@@ -276,7 +286,7 @@ void calc_draw_progress() {
   char ani[15];
   int i;
 
-  nccreate(10, 60, dat == NULL ? "Calculating..." : "Recalculating...");
+  nccreate(10, 60, stcalc.sterr == ST_QUIT ? "Calculating..." : "Recalculating...");
 
   ncprint(2, 2, "Total items: %-8d size: %s",
     stcalc.parent->items, formatsize(stcalc.parent->size, sflags & SF_SI));
diff --git a/src/calc.h b/src/calc.h
index 527dd67..187208f 100644
--- a/src/calc.h
+++ b/src/calc.h
@@ -26,6 +26,8 @@
 #ifndef _calc_h
 #define _calc_h
 
+#include "ncdu.h"
+
 struct state_calc {
   char err;                /* 1/0, error or not */
   char cur[PATH_MAX];      /* current dir/item */
diff --git a/src/main.c b/src/main.c
index bcddfa3..d82e6df 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,9 +26,14 @@
 #include "ncdu.h"
 #include "exclude.h"
 #include "util.h"
+#include "calc.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <unistd.h>
 
-/* check ncdu.h what these are for */
-struct dir *dat;
 int sflags, bflags, sdelay, bgraph;
 int pstate;
 
@@ -129,8 +134,6 @@ void argv_parse(int argc, char **argv, char *dir) {
 
 /* main program */
 int main(int argc, char **argv) {
-  dat = NULL;
-
   argv_parse(argc, argv, stcalc.cur);
   pstate = ST_CALC;
   stcalc.sterr = ST_QUIT;
diff --git a/src/ncdu.h b/src/ncdu.h
index 3824729..eccc03a 100644
--- a/src/ncdu.h
+++ b/src/ncdu.h
@@ -27,25 +27,8 @@
 #define _ncdu_h
 
 #include "config.h"
-
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <limits.h>
-#include <errno.h>
-
-#include <ncurses.h>
-#include <form.h>
-
-#include <unistd.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <dirent.h>
-
-#include "calc.h"
 
 /* set S_BLKSIZE if not defined already in sys/stat.h */
 #ifndef S_BLKSIZE
@@ -85,10 +68,6 @@
 #endif
 
 
-
-/*
- *    G L O B A L   F L A G S
- */
 /* File Flags (struct dir -> flags) */
 #define FF_DIR    0x01
 #define FF_FILE   0x02
@@ -115,7 +94,7 @@
 #define BF_AS     0x40 /* show apparent sizes instead of disk usage */
 #define BF_INFO   0x80 /* show file information window */
 
-/* States */
+/* Program states */
 #define ST_CALC   0
 #define ST_BROWSE 1
 #define ST_DEL    2
@@ -123,10 +102,7 @@
 #define ST_QUIT   4
 
 
-
-/*
- *    S T R U C T U R E S
- */
+/* structure representing a file or directory */
 struct dir {
   struct dir *parent, *next, *sub;
   char *name;
@@ -135,33 +111,14 @@ struct dir {
   unsigned char flags;
 }; 
 
-
-
-/*
- *    G L O B A L   V A R I A B L E S
- *
- * (all defined in main.c)
- */
-/* main directory data */
-extern struct dir *dat;
 /* global settings */
 extern int sflags, bflags, sdelay, bgraph;
+
 /* program state */
 extern int pstate;
 
-
-/*
- *    G L O B A L   F U N C T I O N S
- */
-/* main.c */
+/* handle input from keyboard and update display */
 int input_handle(int);
-/* browser.c */
-void drawBrowser(int);
-void showBrowser(void);
-/* help.c */
-void showHelp(void);
-/* delete.c */
-struct dir *showDelete(struct dir *);
 
 
 #endif
diff --git a/src/util.h b/src/util.h
index f2b4c1b..b250007 100644
--- a/src/util.h
+++ b/src/util.h
@@ -27,6 +27,7 @@
 #define _util_h
 
 #include "ncdu.h"
+#include <ncurses.h>
 
 /* updated when window is resized */
 extern int winrows, wincols;
-- 
GitLab