diff --git a/cmake-build-debug/.ninja_deps b/cmake-build-debug/.ninja_deps index f29c0ac..bbec6b2 100644 Binary files a/cmake-build-debug/.ninja_deps and b/cmake-build-debug/.ninja_deps differ diff --git a/cmake-build-debug/.ninja_log b/cmake-build-debug/.ninja_log index d24f904..504a416 100644 --- a/cmake-build-debug/.ninja_log +++ b/cmake-build-debug/.ninja_log @@ -9,3 +9,21 @@ 434 493 1644015948036364707 Tarstats__ f7cfe02335deb4e2 0 427 1644016477076983653 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 427 493 1644016477140983588 Tarstats__ f7cfe02335deb4e2 +0 538 1644147062140655424 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +538 602 1644147062204655425 Tarstats__ f7cfe02335deb4e2 +1 615 1644148034020627712 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +616 678 1644148034080630244 Tarstats__ f7cfe02335deb4e2 +1 629 1644148143958504291 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +629 692 1644148144022504164 Tarstats__ f7cfe02335deb4e2 +1 622 1644148949596376843 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +622 687 1644148949660376224 Tarstats__ f7cfe02335deb4e2 +0 681 1644149569239272180 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +681 748 1644149569303272155 Tarstats__ f7cfe02335deb4e2 +1 638 1644149631123177220 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +639 705 1644149631187177051 Tarstats__ f7cfe02335deb4e2 +1 619 1644149687714975354 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +619 683 1644149687778975068 Tarstats__ f7cfe02335deb4e2 +1 635 1644149729622762080 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +636 703 1644149729686761716 Tarstats__ f7cfe02335deb4e2 +1 622 1644149788698378263 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8 +622 689 1644149788762377798 Tarstats__ f7cfe02335deb4e2 diff --git a/cmake-build-debug/CMakeFiles/Tarstats__.dir/main.cpp.o b/cmake-build-debug/CMakeFiles/Tarstats__.dir/main.cpp.o index 1cc6c9e..b6a81b7 100644 Binary files a/cmake-build-debug/CMakeFiles/Tarstats__.dir/main.cpp.o and b/cmake-build-debug/CMakeFiles/Tarstats__.dir/main.cpp.o differ diff --git a/cmake-build-debug/Tarstats__ b/cmake-build-debug/Tarstats__ index c516a2c..8372a63 100755 Binary files a/cmake-build-debug/Tarstats__ and b/cmake-build-debug/Tarstats__ differ diff --git a/cmake-build-debug/Testing/Temporary/LastTest.log b/cmake-build-debug/Testing/Temporary/LastTest.log index 30ca981..bb227e1 100644 --- a/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Feb 05 00:14 CET +Start testing: Feb 06 13:16 CET ---------------------------------------------------------- -End testing: Feb 05 00:14 CET +End testing: Feb 06 13:16 CET diff --git a/main.cpp b/main.cpp index 40d0d76..2f1d694 100644 --- a/main.cpp +++ b/main.cpp @@ -1,26 +1,75 @@ #include #include #include +#include +#include -int main() { - std::ifstream datei("test.tar", std::ios::binary); - if(!datei) - std::cout << "Fehler beim Oeffnen der Datei" << std::endl; - int headersize = 512; - char* headbuffer = new char[headersize]; - datei.read(headbuffer, headersize); - std::string filename{}; - for (int i = 0; i <= 99; i++) - { - if (headbuffer[i] != '\0') - filename.push_back(headbuffer[i]); + +int main(int argc, char** argv) { + + // Trivial check for arguments. Errorprone and has to be changed. + if (argc < 2) { + std::cout << "Please enter filename" << std::endl; + return 9; } - std::cout << filename << std::endl; + // Getting name from argument lists on startup. Trivial and errorprone. Placeholder for now. + std::string archiveFilename(argv[1]); - std::string filename2(&headbuffer[0], 100); - std::cout << filename2 << std::endl; + //Open tar File. + std::ifstream datei(archiveFilename, std::ios::binary); + if(!datei) + std::cout << "Error opening file" << std::endl; + + // Tar spec is working with continous 512 byte size blocks. Header is 512 bytes. + int headersize = 512; + + //Read header of first item in tar archive + char* headbuffer = new char[headersize]; + datei.read(headbuffer, headersize); + + // Read name of the next item + std::string itemname(&headbuffer[0], 100); + std::erase(itemname, '\0'); + + // Read type of item + std::string itemtype{}; + switch (headbuffer[156]){ + case '0': case '\0': + itemtype = "FILE"; + break; + case '1': + itemtype = "HARDLINK"; + break; + case '2': + itemtype = "SYMLINK"; + break; + case '5': + itemtype = "DIRECTORY"; + break; + default: + itemtype = "OTHER"; + break; + } + + + + + // Read size of the next file + long double filesize{}; + int power = 10; + std::string asciifilesize(&headbuffer[124], 11); + for (auto i : asciifilesize) { + int value = i - '0'; + filesize += value * std::pow(8,power); + power--; + } + + //Printing to stdout + std::cout << itemname << std::endl; + std::cout << itemtype << std::endl; + std::cout << filesize << " Bytes" << std::endl; return 0; }