summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/BitFlagg.cpp55
-rw-r--r--src/BitFlagg.h18
-rw-r--r--src/Cnfg.cpp51
-rw-r--r--src/Cnfg.h26
-rw-r--r--src/Constants.h12
-rw-r--r--src/CountFilesSumBytes.cpp33
-rw-r--r--src/CountFilesSumBytes.h22
-rw-r--r--src/FilesInDir.cpp162
-rw-r--r--src/FilesInDir.h34
-rw-r--r--src/Makefile.am16
-rw-r--r--src/MountArray.cpp55
-rw-r--r--src/MountArray.h31
-rw-r--r--src/ReturnSum.cpp35
-rw-r--r--src/ReturnSum.h20
-rw-r--r--src/ReturnValues.cpp53
-rw-r--r--src/ReturnValues.h30
-rw-r--r--src/SubDir.cpp60
-rw-r--r--src/SubDir.h35
-rw-r--r--src/SubDirectory.cpp303
-rw-r--r--src/SubDirectory.h40
-rw-r--r--src/main.cpp37
-rw-r--r--src/main.h4
22 files changed, 1132 insertions, 0 deletions
diff --git a/src/BitFlagg.cpp b/src/BitFlagg.cpp
new file mode 100644
index 0000000..48cf990
--- a/dev/null
+++ b/src/BitFlagg.cpp
@@ -0,0 +1,55 @@
+#include "BitFlagg.h"
+#include "Constants.h"
+BitFlagg::BitFlagg (int number_of_bits)
+{
+ Flagg = new char[max = number_of_bits / 8 + 1];
+}
+
+BitFlagg::BitFlagg ()
+{
+ Flagg = new char[max = 1];
+}
+
+BitFlagg::~BitFlagg ()
+{
+ delete Flagg;
+}
+
+void BitFlagg::Store (int offset, int TorF)
+{
+ int offset_byte, c;
+ char offset_bit;
+ int temp;
+
+ if ((offset_byte = offset / 8) < (max + 1)) {
+ offset_bit = offset % 8;
+ if (TorF == TRUE) {
+ temp = 0x01;
+ temp <<= offset_bit;
+ Flagg[offset_byte] |= temp;
+ } else {
+ temp = 0xFE;
+ for (c = 0; c < offset_bit; c++) {
+ temp <<= 1;
+ temp |= 0x01;
+ }
+ Flagg[offset_byte] &= temp;
+ }
+ }
+}
+
+int BitFlagg::Get (int offset)
+{
+ int offset_byte;
+ char offset_bit, temp;
+
+ offset_byte = offset / 8;
+ offset_bit = offset % 8;
+ temp = 0x01;
+ temp <<= offset_bit;
+ temp &= Flagg[offset_byte];
+ if (temp)
+ return TRUE;
+ else
+ return FALSE;
+}
diff --git a/src/BitFlagg.h b/src/BitFlagg.h
new file mode 100644
index 0000000..422903c
--- a/dev/null
+++ b/src/BitFlagg.h
@@ -0,0 +1,18 @@
+// Class to store a bit so that the mousemove can display whether the
+// directory has subdirectories which can be searched
+
+#if !defined(BIT_FLAGG_H_)
+#define BIT_FLAGG_H_
+class BitFlagg
+{
+ char *Flagg;
+ int max;
+public:int Get (int offset);
+ void Store (int offset, int TorF);
+ BitFlagg (int);
+ BitFlagg ();
+ ~BitFlagg ();
+};
+
+
+#endif // BIT_FLAGG_H_
diff --git a/src/Cnfg.cpp b/src/Cnfg.cpp
new file mode 100644
index 0000000..6be27bd
--- a/dev/null
+++ b/src/Cnfg.cpp
@@ -0,0 +1,51 @@
+//
+// File: Cnfg.cpp
+// Created by: User <Email>
+// Created on: Sat Jan 3 13:49:21 2004
+//
+
+#include <stdio.h>
+#include <string.h>
+#include <string>
+#include "Cnfg.h"
+#include "FilesInDir.h"
+
+
+Cnfg::Cnfg (int argc, char **textin, string & searchdir)
+{
+ RecurseMounts = FALSE;
+ Success = TRUE;
+ int counter = 1;
+
+ while (counter < argc) {
+ if (strncmp (textin[counter], "-", 1) == 0) {
+ if (strcmp (textin[counter], "-r") == 0)
+ RecurseMounts = TRUE;
+ } else {
+ string cdirsearch = textin[counter];
+ FilesInDir *pfid = new FilesInDir (cdirsearch);
+
+ if (pfid->open) {
+ searchdir = cdirsearch;
+ } else {
+ Success = FALSE;
+ char tmpchar[160];
+
+ sprintf (tmpchar,
+ "unable to open the directory passed to dirsum: %s\n",
+ cdirsearch.c_str ());
+ Error = tmpchar;
+ delete pfid;
+
+ return;
+ }
+ delete pfid;
+ }
+ counter++;
+ }
+}
+
+
+Cnfg::~Cnfg ()
+{
+}
diff --git a/src/Cnfg.h b/src/Cnfg.h
new file mode 100644
index 0000000..55476df
--- a/dev/null
+++ b/src/Cnfg.h
@@ -0,0 +1,26 @@
+//
+// File: Cnfg.h
+// Created by: User <Email>
+// Created on: Sat Jan 3 13:49:21 2004
+//
+
+#ifndef _CNFG_H_
+#define _CNFG_H_
+#include "Constants.h"
+using namespace std;
+
+
+class Cnfg
+{
+public:
+ Cnfg (int, char **, string &);
+ ~Cnfg ();
+
+ BOOL RecurseMounts;
+ BOOL Success;
+ string Error;
+protected:
+};
+
+
+#endif //_CNFG_H_
diff --git a/src/Constants.h b/src/Constants.h
new file mode 100644
index 0000000..17a01b1
--- a/dev/null
+++ b/src/Constants.h
@@ -0,0 +1,12 @@
+#if !defined(DIRSPACECONSTANTS_H)
+#define DIRSPACECONSTANTS_H
+
+#define NUMBEROFTABS 12
+#define CHECKDRIVES 26
+#define TRUE 1
+#define FALSE 0
+#define LEVELS 45
+typedef char BOOL;
+typedef unsigned long long ulnglng;
+
+#endif // #define DIRSPACECONSTANTS_H
diff --git a/src/CountFilesSumBytes.cpp b/src/CountFilesSumBytes.cpp
new file mode 100644
index 0000000..059bad8
--- a/dev/null
+++ b/src/CountFilesSumBytes.cpp
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include "CountFilesSumBytes.h"
+
+CountFilesSumBytes::CountFilesSumBytes ()
+{
+}
+
+CountFilesSumBytes::CountFilesSumBytes (string DirString)
+{
+ Cfsb (DirString);
+}
+
+CountFilesSumBytes & CountFilesSumBytes::Cfsb (string DirString)
+{
+ miFiles = mlBytes = 0;
+ pfid = new FilesInDir (DirString);
+ if (pfid->open) {
+ string EntryName;
+
+ while (pfid->NextFile (EntryName)) {
+ *this += pfid->FileSize ();
+ } // while Nextfile
+ } // if open
+ delete pfid;
+
+ return *this;
+}
+
+void CountFilesSumBytes::operator+= (ulnglng in)
+{
+ mlBytes += in;
+ miFiles++;
+}
diff --git a/src/CountFilesSumBytes.h b/src/CountFilesSumBytes.h
new file mode 100644
index 0000000..97958d9
--- a/dev/null
+++ b/src/CountFilesSumBytes.h
@@ -0,0 +1,22 @@
+#if !defined(COUNTFILESSUMBYTES_H)
+#define COUNTFILESSUMBYTES_H
+
+#include <strings.h>
+#include <string>
+#include <unistd.h>
+#include "FilesInDir.h"
+using namespace std;
+
+class CountFilesSumBytes
+{
+public:
+ int miFiles;
+ ulnglng mlBytes;
+ FilesInDir *pfid;
+ CountFilesSumBytes ();
+ CountFilesSumBytes (string);
+ CountFilesSumBytes & Cfsb (string);
+ string DirString;
+ void operator+= (ulnglng);
+};
+#endif // #define COUNTFILESSUMBYTES_H
diff --git a/src/FilesInDir.cpp b/src/FilesInDir.cpp
new file mode 100644
index 0000000..f183688
--- a/dev/null
+++ b/src/FilesInDir.cpp
@@ -0,0 +1,162 @@
+#include <stdio.h>
+#include "FilesInDir.h"
+
+FilesInDir::FilesInDir (string & Dirname, MountArray * Mtlist)
+{
+ DirectoryOpened = Dirname;
+ if ((Dir = opendir (Dirname.c_str ())) == NULL) {
+ string error ("Unable to open Directory ");
+
+ error += Dirname;
+ perror (error.c_str ());
+ open = FALSE;
+ } else
+ open = TRUE;
+ MntList = Mtlist;
+}
+
+FilesInDir::FilesInDir (string & Dirname)
+{
+ DirectoryOpened = Dirname;
+ if ((Dir = opendir (Dirname.c_str ())) == NULL) {
+ string error ("Unable to open Directory ");
+
+ error += Dirname;
+ perror (error.c_str ());
+ open = FALSE;
+ } else
+ open = TRUE;
+ MntList = NULL;
+}
+
+int FilesInDir::CountDirs ()
+{
+ int CountDirs = 0;
+
+ while (NULL != (DirentStruct = readdir (Dir))) {
+ string EntryName (DirentStruct->d_name);
+
+ if ((EntryName == ".") || (EntryName == ".."))
+ continue;
+ string fp;
+
+ if (DirectoryOpened != "/")
+ fp = DirectoryOpened + "/" + EntryName;
+ else
+ fp = DirectoryOpened + EntryName;
+ if ((MntList != NULL) && (MntList->MountCheck (fp) == TRUE))
+ continue;
+ if (DirectoryOpened == "/") {
+ if ((EntryName == "proc") || (EntryName == "dev")
+ || (EntryName == "sys"))
+ continue;
+ }
+ struct stat Stat;
+ struct stat *p_Stat = &Stat;
+
+ if (lstat (fp.c_str (), p_Stat) == 0) {
+ if ((S_ISDIR (Stat.st_mode)) && !(S_ISLNK (Stat.st_mode))) {
+ CountDirs++;
+ }
+ }
+ }
+ return CountDirs;
+}
+
+void FilesInDir::rewind ()
+{
+ rewinddir (Dir);
+}
+
+int FilesInDir::NextDir (string & Namein)
+{
+ Namein = "";
+ int done = FALSE;
+ int found = FALSE;
+
+ while (!done) {
+ if (NULL != (DirentStruct = readdir (Dir))) {
+ string EntryName = DirentStruct->d_name;
+
+ if ((EntryName == ".") || (EntryName == ".."))
+ continue;
+ if (EntryName == "hdd1") {
+ int x;
+
+ x++;
+ }
+ string fp;
+
+ if (DirectoryOpened != "/")
+ fp = DirectoryOpened + "/" + EntryName;
+ else
+ fp = DirectoryOpened + EntryName;
+ if ((MntList != NULL) && (MntList->MountCheck (fp) == TRUE))
+ continue;
+ if ((DirectoryOpened == "/") && (((EntryName == "proc") ||
+ (EntryName == "dev")
+ || (EntryName == "sys"))))
+ continue;
+ struct stat Stat;
+ struct stat *p_Stat = &Stat;
+
+ if (lstat (fp.c_str (), p_Stat) == 0) {
+ if ((S_ISDIR (Stat.st_mode)) && !(S_ISLNK (Stat.st_mode))) {
+ LastEntry = Namein = EntryName;
+ found = done = TRUE;
+ }
+ }
+ } else {
+ done = TRUE;
+ }
+ } // while
+ return found;
+}
+
+int FilesInDir::NextFile (string & Namein)
+{
+ Namein = "";
+ int done = FALSE;
+ int found = FALSE;
+
+ while (!done) {
+ if (NULL != (DirentStruct = readdir (Dir))) {
+ string EntryName = DirentStruct->d_name;
+
+ if ((EntryName == ".") || (EntryName == ".."))
+ continue;
+ struct stat Stat;
+ struct stat *p_Stat = &Stat;
+ string fp = DirectoryOpened + "/" + DirentStruct->d_name;
+
+ if (lstat (fp.c_str (), p_Stat) == 0) {
+ if (S_ISREG (Stat.st_mode)) {
+ LastEntry = Namein = EntryName;
+ found = done = TRUE;
+ }
+ }
+ } else {
+ done = TRUE;
+ }
+ } // while
+ return found;
+}
+
+int FilesInDir::FileSize ()
+{
+ struct stat Status;
+ struct stat *p_Stat = &Status;
+ int size = 0;
+
+ string file_w_path = DirectoryOpened + "/" + LastEntry;
+
+ if (lstat (file_w_path.c_str (), p_Stat) == 0) {
+ size = int (Status.st_size);
+ }
+ return size;
+}
+
+FilesInDir::~FilesInDir ()
+{
+ closedir (Dir);
+}
diff --git a/src/FilesInDir.h b/src/FilesInDir.h
new file mode 100644
index 0000000..bec1178
--- a/dev/null
+++ b/src/FilesInDir.h
@@ -0,0 +1,34 @@
+#if !defined(FILESINDIR_H)
+#define FILESINDIR_H
+#include "Constants.h"
+#include <strings.h>
+#include <string>
+#include <dirent.h> // for DIR*
+// next two for status to get number of bytes
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "MountArray.h"
+using namespace std;
+
+class FilesInDir
+{
+public:
+// data
+ int open;
+ DIR *Dir;
+ struct dirent *DirentStruct;
+ string DirectoryOpened;
+ string LastEntry;
+ MountArray *MntList;
+// functions
+ int CountDirs ();
+ void rewind ();
+ int NextDir (string &);
+ int NextFile (string &);
+ int FileSize ();
+ FilesInDir (string &, MountArray *);
+ FilesInDir (string &);
+ ~FilesInDir ();
+};
+
+#endif // #define FILESINDIR_H
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..ab25140
--- a/dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,16 @@
+cxx = g++
+SOURCES = BitFlagg.cpp CountFilesSumBytes.cpp \
+ ReturnSum.cpp SubDir.cpp \
+ Cnfg.cpp FilesInDir.cpp \
+ MountArray.cpp ReturnValues.cpp SubDirectory.cpp
+
+#objects := $(patsubst %.cpp,%.o,$(sources))
+#headers := $(patsubst %.cpp,%.h,$(sources))
+
+bin_PROGRAMS = dirsum
+dirsum_SOURCES = $(SOURCES) main.cpp
+
+#all : $(objects) dirsum
+
+#$(objects): %.o : %.cpp %.h
+# $(cxx) -c $(CFLAGS) $< -o $@
diff --git a/src/MountArray.cpp b/src/MountArray.cpp
new file mode 100644
index 0000000..9278489
--- a/dev/null
+++ b/src/MountArray.cpp
@@ -0,0 +1,55 @@
+#include "MountArray.h"
+#include <stdio.h>
+#include <string.h>
+
+MountArray::MountArray (BOOL recurse)
+{
+ MountCount = 0;
+ if (recurse == FALSE) {
+ char *Word;
+
+ MountArr = new string *[50];
+ FILE *conffile = fopen ("/etc/mtab", "r");
+
+ if (conffile) {
+ char confline[350];
+
+ while (fgets (confline, 350, conffile) != 0) {
+ int wordcount = 0;
+
+ Word = strtok (confline, " ");
+ while (Word != NULL) {
+ Word = strtok (NULL, " ");
+ if (wordcount == 0) {
+ //printf("%s\n",Word);
+ MountArr[MountCount] = new string (Word);
+ MountCount++;
+ }
+ wordcount++;
+ }
+ //printf("%s\n",confline);
+ }
+ }
+ }
+}
+
+MountArray::~MountArray ()
+{
+ int i;
+
+ for (i = 0; i < MountCount; i++)
+ delete MountArr[i];
+ delete MountArr;
+}
+
+BOOL MountArray::MountCheck (string & instring)
+{
+ int counter;
+
+ BOOL retval = FALSE;
+
+ for (counter = 0; counter < MountCount; counter++)
+ if (*MountArr[counter] == instring)
+ retval = TRUE;
+ return retval;
+}
diff --git a/src/MountArray.h b/src/MountArray.h
new file mode 100644
index 0000000..39b588d
--- a/dev/null
+++ b/src/MountArray.h
@@ -0,0 +1,31 @@
+//
+// File: MountArray.h
+// Created by: User <Email>
+// Created on: Mon Dec 29 16:04:15 2003
+//
+
+#ifndef _MOUNTARRAY_H_
+#define _MOUNTARRAY_H_
+#include <strings.h>
+#include <string>
+#include "Constants.h"
+using namespace std;
+
+class MountArray
+{
+public:
+ MountArray (BOOL);
+ ~MountArray ();
+
+ // MountArray interface
+ string **MountArr;
+ int MountCount;
+ BOOL MountCheck (string &);
+
+protected:
+ // MountArray variables
+
+};
+
+
+#endif //_MOUNTARRAY_H_
diff --git a/src/ReturnSum.cpp b/src/ReturnSum.cpp
new file mode 100644
index 0000000..6df3626
--- a/dev/null
+++ b/src/ReturnSum.cpp
@@ -0,0 +1,35 @@
+#include "CountFilesSumBytes.h"
+#include "ReturnValues.h"
+#include "ReturnSum.h"
+ReturnSum::ReturnSum ()
+{
+ mlNetTotal = 0;
+}
+
+ReturnSum & ReturnSum::operator+= (ReturnValues & in)
+{
+ miCount += in.miCount;
+ mlTotal += in.mlTotal;
+ miSubDir += in.miSubDir; // these are for sum totals
+ mlSTotal += in.mlSTotal;
+ miSFiles += in.miSFiles;
+ miSSubDir += in.miSSubDir;
+ mlSSTotal += in.mlSSTotal;
+ miSSFiles += in.miSSFiles;
+ mlNetTotal += (in.mlSTotal + in.mlSSTotal + in.mlTotal);
+ return *this;
+}
+
+ReturnSum & ReturnSum::operator+= (CountFilesSumBytes & in)
+{
+ miFiles = in.miFiles;
+ mlNetTotal += mlBytes = in.mlBytes;
+ return *this;
+}
+
+ReturnSum & ReturnSum::operator! ()
+{
+ !((ReturnValues) * this);
+ mlNetTotal = 0;
+ return *this;
+}
diff --git a/src/ReturnSum.h b/src/ReturnSum.h
new file mode 100644
index 0000000..9de9bec
--- a/dev/null
+++ b/src/ReturnSum.h
@@ -0,0 +1,20 @@
+// Class to return to the totals of files and bytes
+// at different levels of sum of the subdirectories of the directory in question
+// Each SubDirectory Class has one ReturnSum and an array
+// of ReturnValues and Output strings the number of subs long
+
+#if !defined(RETURN_SUM_)
+#define RETURN_SUM_
+class ReturnSum:public ReturnValues
+{
+public:ulnglng mlNetTotal;
+ int miFiles;
+ ulnglng mlBytes;
+ ReturnSum ();
+ ReturnSum & operator+= (ReturnValues &);
+ ReturnSum & operator! ();
+ ReturnSum & operator+= (CountFilesSumBytes &);
+};
+
+
+#endif // RETURN_SUM_
diff --git a/src/ReturnValues.cpp b/src/ReturnValues.cpp
new file mode 100644
index 0000000..34dbe75
--- a/dev/null
+++ b/src/ReturnValues.cpp
@@ -0,0 +1,53 @@
+#include "CountFilesSumBytes.h"
+#include "ReturnValues.h"
+ReturnValues::ReturnValues ()
+{
+ miCount = miSFiles = miSSFiles = mlSSTotal = miSSubDir = mlSTotal =
+ miSubDir = mlTotal = 0;
+}
+
+ReturnValues & ReturnValues::operator&= (CountFilesSumBytes & in)
+{
+ mlSTotal += in.mlBytes; // these are for sum totals
+ miSFiles += in.miFiles;
+ miSubDir++;
+ return *this;
+}
+
+ReturnValues & ReturnValues::operator|= (CountFilesSumBytes & in)
+{
+ mlSSTotal += in.mlBytes; // these are for sum totals
+ miSSFiles += in.miFiles;
+ miSSubDir++;
+ return *this;
+}
+
+ReturnValues & ReturnValues::operator+ (CountFilesSumBytes & in)
+{
+ mlTotal = in.mlBytes;
+ miCount = in.miFiles;
+ return *this;
+}
+
+ReturnValues & ReturnValues::operator! ()
+{
+ mlTotal = miCount = miSubDir = mlSTotal = miSFiles = miSSubDir =
+ mlSSTotal = miSSFiles = 0;
+ return *this;
+}
+
+ulnglng ReturnValues::operator++ ()
+{
+ ulnglng temp;
+
+ temp = mlTotal + mlSTotal + mlSSTotal;
+ return temp;
+}
+
+int ReturnValues::operator~ ()
+{
+ int temp;
+
+ temp = miCount + miSFiles + miSSFiles;
+ return temp;
+}
diff --git a/src/ReturnValues.h b/src/ReturnValues.h
new file mode 100644
index 0000000..1521fbe
--- a/dev/null
+++ b/src/ReturnValues.h
@@ -0,0 +1,30 @@
+// Class to return to the totals of files and bytes
+// at different levels of each of the subdirectories of the directory in question
+// Each SubDirectory Class has one ReturnSum and an array
+// of ReturnValues the number of subs long
+
+#if !defined(RETURNVALUES_H)
+#define RETURNVALUES_H
+#include "CountFilesSumBytes.h"
+class ReturnValues
+{
+public:ulnglng mlTotal;
+ int miCount;
+ int miSubDir;
+ ulnglng mlSTotal;
+ int miSFiles;
+ int miSSubDir;
+ ulnglng mlSSTotal;
+ int miSSFiles;
+ string msDirname;
+ ReturnValues ();
+ ReturnValues & operator+ (CountFilesSumBytes &);
+ ReturnValues & operator&= (CountFilesSumBytes &);
+ ReturnValues & operator|= (CountFilesSumBytes &);
+ ReturnValues & operator! ();
+ ulnglng operator++ ();
+ int operator~ ();
+};
+
+
+#endif // !defined(RETURNVALUES_H)
diff --git a/src/SubDir.cpp b/src/SubDir.cpp
new file mode 100644
index 0000000..9c920ab
--- a/dev/null
+++ b/src/SubDir.cpp
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include "SubDir.h"
+#include "ReturnValues.h"
+
+Subdir_var::Subdir_var ()
+{
+}
+
+SubDir::SubDir (string directname, string errstr, MountArray * mlist)
+{
+
+ Mlist = mlist;
+ string Dummy = errstr;
+
+ level = hilevel = 0;
+ !this->return_values; // ret_val_info = { NULL }
+
+ Svar[0] = new Subdir_var;
+ Svar[1] = new Subdir_var;
+
+ //strcpy( Svar[ level ]->cur_path, directname );
+ Svar[level]->cur_path = directname;
+ subdirinfo ();
+}
+
+void SubDir::subdirinfo ()
+{
+ DirString = Svar[level]->cur_path;
+ Svar[level]->pfid = new FilesInDir (DirString, Mlist);
+ if (Svar[level]->pfid->open) {
+ string EntryName;
+
+ while (Svar[level]->pfid->NextDir (EntryName)) {
+ if (Svar[level]->cur_path == "/")
+ Svar[level + 1]->cur_path = Svar[level]->cur_path + EntryName;
+ else
+ Svar[level + 1]->cur_path = Svar[level]->cur_path + "/" + EntryName;
+ if (level)
+ this->return_values |= Cfsb (Svar[level + 1]->cur_path); // op func for ad to ss
+ else
+ this->return_values &= Cfsb (Svar[level + 1]->cur_path); // op func for ad to s
+ level++;
+ if (level > hilevel) {
+ Svar[level + 1] = new Subdir_var;
+ hilevel++;
+ }
+ subdirinfo (); // it sure is wonderful a function can call itself
+ level--;
+ } //while
+ } // if opened
+ delete Svar[level]->pfid;
+}
+
+SubDir::~SubDir ()
+{
+ int c;
+
+ for (c = 0; c < hilevel + 2; c++)
+ delete Svar[c];
+}
diff --git a/src/SubDir.h b/src/SubDir.h
new file mode 100644
index 0000000..96ac394
--- a/dev/null
+++ b/src/SubDir.h
@@ -0,0 +1,35 @@
+#if !defined(SUBDIR_H)
+#define SUBDIR_H
+
+#include <strings.h>
+#include <string>
+#include <unistd.h>
+#include "ReturnValues.h"
+#include "Constants.h"
+#include "FilesInDir.h"
+#include "MountArray.h"
+using namespace std;
+
+class Subdir_var
+{
+public:
+ Subdir_var ();
+ string cur_path;
+ FilesInDir *pfid;
+};
+
+class SubDir:public CountFilesSumBytes
+{
+public:
+ ReturnValues return_values;
+ SubDir (string, string, MountArray *);
+ ~SubDir ();
+ void subdirinfo ();
+ int hilevel, level;
+ string DirString;
+ MountArray *Mlist;
+ Subdir_var *Svar[LEVELS];
+ struct stat Status;
+};
+
+#endif // #define SUBDIR_H
diff --git a/src/SubDirectory.cpp b/src/SubDirectory.cpp
new file mode 100644
index 0000000..ea94448
--- a/dev/null
+++ b/src/SubDirectory.cpp
@@ -0,0 +1,303 @@
+// SubDirectory.cpp : implementation of the SubDirectory class
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "Constants.h"
+#include "BitFlagg.h"
+#include "CountFilesSumBytes.h"
+#include "ReturnValues.h"
+#include "ReturnSum.h"
+#include "SubDir.h"
+#include "SubDirectory.h"
+#include "FilesInDir.h"
+
+SubDirectory::SubDirectory (string Dirname, Cnfg & Configg)
+{
+ msPathInput = Dirname;
+ msSubDirectname = Dirname;
+ process (Configg);
+}
+
+void SubDirectory::process (Cnfg & Configg)
+{
+ Mntlist = new MountArray (Configg.RecurseMounts);
+ string DebugAssist, Path_; // Path_ in SaveDirectory INfo
+ int CounterSaveDir = 0; // Counter for save Directory info
+
+ msErrorString = ""; //
+
+ FilesInDir *fid = new FilesInDir (msPathInput, Mntlist);
+
+ if (fid->open) {
+// Count the Directories CountDirectories
+ miCountDirs = fid->CountDirs ();
+ mpRetVal = new ReturnValues *[miCountDirs];
+ fid->rewind ();
+// miCountDirs is now the number of subdirectories in the starting directory
+ mpReturnSum = new ReturnSum;
+ mpCFSB = new CountFilesSumBytes;
+ *mpReturnSum += mpCFSB->Cfsb (msPathInput);
+ if (miCountDirs == 0) {
+ miNumberofLines = miCountDirs;
+ msHeader[1] += "No subdirectories to analyze";
+ } else // if count dirs > 0
+ { // Save the required information
+ string EntryName;
+
+ while (fid->NextDir (EntryName)) {
+ mpRetVal[CounterSaveDir] = new ReturnValues;
+ string fullpath;
+
+ if (msPathInput == "/")
+ fullpath = "/" + EntryName;
+ else
+ fullpath = msPathInput + "/" + EntryName;
+
+ // Search all of the Subdirectories of this Subdirectory
+ SubDir *pSubSubD = new SubDir (fullpath, msErrorString, Mntlist);
+
+ // Count Files and Bytes of this SubDirectory and add with all SubSubs
+ // Save in Return Array and add to return Sum
+
+ (*mpReturnSum) += (*mpRetVal[CounterSaveDir]) =
+ pSubSubD->return_values + mpCFSB->Cfsb (fullpath);
+ mpRetVal[CounterSaveDir]->msDirname = EntryName;
+
+ CounterSaveDir++;
+ delete pSubSubD;
+ } // while
+ } // else countdirs
+// End of Save the required information
+ delete mpCFSB;
+
+ SortDirectoryInfo ();
+ OutputDirList (); // output a list of the saved dir's
+ } // if else opendir
+ delete fid;
+}
+
+
+SubDirectory::~SubDirectory ()
+{
+ int counter;
+
+ for (counter = 0; counter < miCountDirs; counter++) {
+ delete mpRetVal[counter];
+ delete mpOutputString[counter];
+ }
+ delete mpRetVal;
+ delete mpOutputString;
+ delete mpReturnSum;
+ delete mBitFlag;
+ delete Mntlist;
+}
+
+void SubDirectory::SortDirectoryInfo ()
+{
+ int a, b;
+ ReturnValues buffer;
+
+ for (a = 1; a < miCountDirs; a++) {
+ for (b = 0; b < miCountDirs - 1; b++) {
+ if (++(*mpRetVal[b]) < ++(*mpRetVal[b + 1])) {
+ buffer = *mpRetVal[b];
+ *mpRetVal[b] = *mpRetVal[b + 1];
+ *mpRetVal[b + 1] = buffer;
+ }
+ }
+ }
+}
+
+//function to output Create String array
+
+void SubDirectory::OutputDirList ()
+{
+ int counter, files, totfiles;
+ double percent;
+ string stringg[4], StringTemp, tab, ttab;
+
+ tab = "\t";
+ ttab = "\t\t\t";
+ ulnglng sum;
+ ulnglng denom;
+ char StringConv[120], sc1[80], sc2[80], sc3[80];
+
+ mpOutputString = new string *[miCountDirs + 1];
+ for (counter = 0; counter < miCountDirs + 1; counter++) {
+ mpOutputString[counter] = new string;
+ *mpOutputString[counter] = "";
+ }
+ mBitFlag = new BitFlagg (miCountDirs);
+ miNumberofLines = miCountDirs + 1;
+
+ denom = mpReturnSum->mlNetTotal;
+
+ if (!denom) { // if( denom )
+ msErrorString = "Zero bytes; avoiding division by zero.";
+ percent = 0;
+ } else
+ percent = (100 * (double) mpReturnSum->mlBytes / (double) denom); //(double)
+
+ sprintf (StringConv, "%s has %lli Bytes in %i Files, with %i Subdirector",
+ msPathInput.c_str (), mpReturnSum->mlBytes, mpReturnSum->miFiles,
+ miCountDirs);
+ msHeader[0] = StringConv;
+ if (miCountDirs == 1)
+ msHeader[0] += "y";
+ else
+ msHeader[0] += "ies";
+ sprintf (StringConv, "\nwhich is %5.2f percent of total", percent);
+ stringg[3] = StringConv;
+ msHeader[0] += stringg[3];
+
+ totfiles = mpReturnSum->miFiles;
+ sprintf (StringConv,
+ " Subdirs This Directory 1 Deeper 2 - %i Deeper Totals",
+ LEVELS);
+ msHeader[2] = StringConv;
+ msHeader[3] =
+ " Name Bytes Files Dirs Bytes Files Dirs Bytes Files Files Bytes %";
+
+ for (counter = 0; counter < miCountDirs; counter++) {
+ ReturnValues *lrvp = mpRetVal[counter];
+
+ sum = ++(*lrvp);
+ files = ~(*lrvp);
+ totfiles += files;
+ if (sum > denom) {
+ int dummy;
+
+ dummy++;
+ }
+ if (!denom) {
+ msErrorString = "Zero bytes; avoiding division by zero.";
+ percent = 0;
+ } else
+ percent = (100 * (double) sum / (double) denom); //(double)
+ sprintf (StringConv, "%10.10s %7.7s %7i", lrvp->msDirname.c_str (),
+ conv (lrvp->mlTotal, sc1), lrvp->miCount);
+ StringTemp = StringConv;
+
+ if (lrvp->miSubDir) {
+ sprintf (StringConv, "%7i %7.7s %7i ", lrvp->miSubDir,
+ conv (lrvp->mlSTotal, sc2), lrvp->miSFiles);
+ } else {
+ sprintf (StringConv, "%24.24s", "");
+ }
+ StringTemp += StringConv;
+ if (lrvp->miSSubDir) {
+ sprintf (StringConv, "%7i %7.7s %7i ", lrvp->miSSubDir,
+ conv (lrvp->mlSSTotal, sc2), lrvp->miSSFiles);
+ } else
+ sprintf (StringConv, "%24.24s", "");
+ StringTemp += StringConv;
+
+ sprintf (StringConv, "%7i %7.7s %5.2f", files, conv (sum, sc2), percent);
+ StringTemp += StringConv;
+
+ if ((lrvp->miSSubDir) || (lrvp->miSubDir))
+ mBitFlag->Store (counter, TRUE);
+ else
+ mBitFlag->Store (counter, FALSE);
+ *mpOutputString[counter] = StringTemp;
+ }
+ msHeader[1] = msErrorString;
+ StringTemp = "";
+ sprintf (StringConv, "%10.10s %7.7s %7i", "Totals",
+ conv (mpReturnSum->mlTotal, sc1), mpReturnSum->miCount);
+ StringTemp = StringConv;
+ if ((mpReturnSum->miSubDir)) {
+ sprintf (StringConv, "%7i %7.7s %7i ", mpReturnSum->miSubDir,
+ conv (mpReturnSum->mlSTotal, sc2), mpReturnSum->miSFiles);
+ } else
+ sprintf (StringConv, "%24.24s", "");
+ StringTemp += StringConv;
+
+ if ((mpReturnSum->miSSubDir)) {
+ sprintf (StringConv, "%7i %7.7s %7i ", mpReturnSum->miSSubDir,
+ conv (mpReturnSum->mlSSTotal, sc2), mpReturnSum->miSSFiles);
+ } else
+ sprintf (StringConv, "%24.24s", "");
+ StringTemp += StringConv;
+
+ sprintf (StringConv, "%7i %7.7s", totfiles,
+ conv (mpReturnSum->mlNetTotal, sc3));
+ StringTemp += StringConv;
+
+ *mpOutputString[miCountDirs] = StringTemp;
+}
+
+char *SubDirectory::conv (ulnglng in, char *tstr)
+{
+ //double tera=1099511627776;
+ double tera = 1.0995116e12;
+
+ if (in < 1024) {
+ sprintf (tstr, "%5.1lli ", in);
+ }
+ if ((in >= 1024) && (in < 1048576)) {
+ double x = double (in) / 1024;
+
+ sprintf (tstr, "%5.1fK", x);
+ }
+ if ((in >= 1048576) && (in < 1073741824)) {
+ double x = double (in) / 1048576;
+
+ sprintf (tstr, "%5.1fM", x);
+ }
+ if ((in >= 1073741824) && (double (in) < tera)) {
+ double x = double (in) / 1073741824;
+
+ sprintf (tstr, "%5.1fG", x);
+ }
+ if (double (in) >= tera) {
+ double x = double (in) / tera;
+
+ sprintf (tstr, "%5.1fT", x);
+ }
+ return tstr;
+}
+
+char *SubDirectory::conv (int in, char *tstrr)
+{
+ ulnglng y;
+
+ y = (ulnglng) in;
+ conv (y, tstrr);
+ return tstrr;
+}
+
+/*char* SubDirectory::conv(ulnglng in,char* tstrr)
+{
+ ulnglng y;
+ y=(ulnglng)in;
+ conv(y,tstrr);
+ return tstrr;
+}*/
+
+/*void SubDirectory::check(int c){
+ ulnglng sumary[22];
+ float percentary[22];
+ int i;
+ ulnglng test=0;
+ for( i=0; i<c; i++){
+ ulnglng sumtst=0;
+ ulnglng sum = ++( *mpRetVal[i] );
+ sumary[i]=sum;
+ sumtst+=mpRetVal[i]->mlSSTotal;
+ sumtst+=mpRetVal[i]->mlSTotal;
+ sumtst+=mpRetVal[i]->mlTotal;
+ if( sumtst != sum ){
+ int whop=0;
+ whop++;
+ }
+ test+=sumtst;
+ percentary[i]=( 100 * (double)sumtst / (double)mpReturnSum->mlNetTotal ); //(double)
+ }
+ test+=mpReturnSum->mlBytes;
+ if( test != mpReturnSum->mlNetTotal ){
+ int whop=0;
+ whop++;
+ }
+ return;
+}*/
diff --git a/src/SubDirectory.h b/src/SubDirectory.h
new file mode 100644
index 0000000..6793237
--- a/dev/null
+++ b/src/SubDirectory.h
@@ -0,0 +1,40 @@
+// Subdirectory.h : interface of the Subdirectory class
+// This Class is The Meat of the Program
+// It Searches the subdirectories and contains the arrays
+// Which are displayed.
+
+#if !defined(SUBDIRECTORY_H)
+#define SUBDIRECTORY_H
+#include "Constants.h"
+#include <strings.h>
+#include <string>
+#include "ReturnSum.h"
+#include "BitFlagg.h"
+#include "MountArray.h"
+#include "Cnfg.h"
+
+class SubDirectory
+{
+public:
+ int miNumberofLines;
+ int miCountDirs;
+ string **mpOutputString;
+ MountArray *Mntlist;
+ ReturnValues **mpRetVal;
+ BitFlagg *mBitFlag;
+ ReturnSum *mpReturnSum;
+ CountFilesSumBytes *mpCFSB;
+ // functions
+ SubDirectory (string dirname, Cnfg &);
+ ~SubDirectory ();
+ void SortDirectoryInfo ();
+ void OutputDirList ();
+ void process (Cnfg &);
+ char *conv (ulnglng, char *);
+ //char* conv(ulnglng, char*);
+ char *conv (int, char *);
+ //void check(int);
+ string msErrorString, msPathInput, msHeader[4], msSubDirectname;
+};
+
+#endif // #define SUBDIRECTORY_H
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..abb2b35
--- a/dev/null
+++ b/src/main.cpp
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "main.h"
+
+int main (int argc, char *argv[], char *env[])
+{
+ string searchdir;
+ char *pwd = getenv ("PWD");
+
+ if (pwd) {
+ searchdir = pwd;
+ } else {
+ searchdir = "/home";
+ }
+ Cnfg *Config = new Cnfg (argc, argv, searchdir);
+
+ if (Config->Success == FALSE) {
+ printf ("Config error\n");
+ printf ("%s\n",Config->Error.c_str ());
+ return 1;
+ }
+ if (Config->RecurseMounts)
+ printf ("Recursion into new partitions is on\n");
+ else
+ printf ("Recursion into new partitions is off\n");
+ SubDirectory *Whipper = new SubDirectory (searchdir, *Config);
+
+ //printf( "For the Directory %s\n\n",Whipper->msSubDirectname.c_str());
+ for (int counter = 0; counter < 4; counter++)
+ printf ("%s\n", Whipper->msHeader[counter].c_str ());
+ for (int counter = 0; counter < Whipper->miCountDirs; counter++)
+ printf ("%s\n", Whipper->mpOutputString[counter]->c_str ());
+ printf ("%s\n", Whipper->mpOutputString[Whipper->miCountDirs]->c_str ());
+ delete Whipper;
+
+ return 0;
+}
diff --git a/src/main.h b/src/main.h
new file mode 100644
index 0000000..98245f2
--- a/dev/null
+++ b/src/main.h
@@ -0,0 +1,4 @@
+#include "SubDir.h"
+#include "CountFilesSumBytes.h"
+#include "SubDirectory.h"
+#include "Cnfg.h"