diff --git a/main.cpp b/main.cpp index 5baaa9c..ffbcd23 100644 --- a/main.cpp +++ b/main.cpp @@ -15,7 +15,7 @@ int main(int argc, char** argv) { // GENERAL VARIABLES //count the types of all items - std::map typecount{ + std::map typecount{ {tarconstant::typeFile, 0}, {tarconstant::typeDir, 0}, {tarconstant::typeSym, 0}, {tarconstant::typeHard, 0}, {tarconstant::typeOther, 0} }; @@ -30,6 +30,10 @@ int main(int argc, char** argv) { // Getting name from argument lists on startup. Trivial and errorprone. Placeholder for now. std::string archiveFilename(argv[1]); + for (int i = 0; i < argc; i++){ + std::cout << argv[i] << '\n'; + } + //Open tar File. std::ifstream file(archiveFilename, std::ios::binary); if(!file) { @@ -70,11 +74,9 @@ int main(int argc, char** argv) { delete[] headbuffer; } file.close(); - std::cout << "Archive size: " << std::filesystem::file_size(archiveFilename) << " Bytes"<< '\n'; - std::cout << "Size of all items: " << sizeof_allfiles << " Bytes" << '\n' << '\n'; - for (auto &i : typecount) { - std::cout << i.first <<": " << i.second << '\n'; - } + + tar::consolestats(typecount, std::filesystem::file_size(archiveFilename), sizeof_allfiles); + return 0; } diff --git a/tarfunc.cpp b/tarfunc.cpp index 0c15b95..138d200 100644 --- a/tarfunc.cpp +++ b/tarfunc.cpp @@ -7,6 +7,8 @@ #include "tarconst.h" #include #include +#include +#include // checks if a valid modern tar file - ustar bool tar::validTar(std::istream &file) { @@ -57,4 +59,12 @@ std::string tar::getitemtype(char &n) { default: return tarconstant::typeOther; } +} + +void tar::consolestats (std::map &typecount, uintmax_t tarfilesize, uintmax_t sizeofall) { + std::cout << "Archive size: " << tarfilesize << " Bytes"<< '\n'; + std::cout << "Size of all items: " << sizeofall << " Bytes" << '\n' << '\n'; + for (auto &i : typecount) { + std::cout << i.first <<": " << i.second << '\n'; + } } \ No newline at end of file diff --git a/tarfunc.h b/tarfunc.h index bd43a40..bc3b668 100644 --- a/tarfunc.h +++ b/tarfunc.h @@ -4,6 +4,8 @@ */ #include +#include +#include #ifndef TARSTATS___TARFUNC_H @@ -20,6 +22,8 @@ namespace tar { // gets type of an item std::string getitemtype(char &n); +// + void consolestats (std::map &typecount, uintmax_t tarfilesize, uintmax_t sizeofall); }