From a80f78c36d32bd3c3b531a54a1a5073f27f2c81f Mon Sep 17 00:00:00 2001 From: Marcel Nowicki Date: Fri, 11 Feb 2022 03:28:13 +0100 Subject: [PATCH] this added some small refinements as well as first forays in working with gz files. Added zlib.h. Checked if valid gz file via mgic number. --- CMakeLists.txt | 3 +++ main.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e344acd..f4790f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,10 @@ cmake_minimum_required(VERSION 3.21) project(Tarstats__) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -std=c++20") add_executable(tarstats_pp main.cpp tarconst.h tarfunc.cpp tarfunc.h) +target_link_libraries(tarstats_pp) + diff --git a/main.cpp b/main.cpp index 0eebabb..81d1fec 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,7 @@ #include #include "tarconst.h" #include "tarfunc.h" +#include "zlib.h" int main(int argc, char** argv) { // Trivial check for arguments. @@ -26,6 +27,7 @@ int main(int argc, char** argv) { } bool toFile = false; bool toJSON = false; + bool g = false; std::vector archiveFilename {}; for (auto i : cmdparam) { @@ -44,6 +46,9 @@ int main(int argc, char** argv) { case 'h': tar::printhelp(); return 9; + case 'g': + g = true; + break; case '-': break; default: @@ -55,6 +60,17 @@ int main(int argc, char** argv) { } } + if (g) { + std::ifstream test("test4.tar.gz", std::ios::binary); + char x; + test.seekg(1); + test.read((&x), 1); + test.close(); + if (x == '\213') + std::cout << "success" << std::endl; + return 0; + } + for (auto &archiveName : archiveFilename) { //count the types of all items std::map typecount{