diff --git a/CMakeLists.txt b/CMakeLists.txt index 61ebde3..42095ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,14 @@ cmake_minimum_required (VERSION 2.6) project(cookiebot) +set(CMAKE_BUILD_TYPE DEBUG) +set(CMAKE_C_FLAGS_DEBUG "-O0 -g3 -pg -std=c99") +set(CMAKE_C_FLAGS_MINSIZEREL "-Os -std=c99") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O0 -g -std=c99") +set(CMAKE_C_FLAGS_RELEASE "-O3 -std=c99") +set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -pg -std=gnu++14") +set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -std=gnu++14") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O0 -g -std=gnu++14") +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -std=gnu++14") set (cookiebot_VERSION_MAJOR 0) set (cookiebot_VERSION_MINOR 0) find_package (ZLIB) @@ -25,6 +34,7 @@ configure_file ( "${PROJECT_BINARY_DIR}/cookiebot_conf.h" ) include_directories("${PROJECT_BINARY_DIR}") +include_directories("${PROJECT_SOURCE_DIR}/include") if (MOD_GZIP) set(EXTRA_LIBS ${EXTRA_LIBS} z) endif (MOD_GZIP) @@ -34,5 +44,6 @@ endif (MOD_BZ2) if (MOD_XZ) set(EXTRA_LIBS ${EXTRA_LIBS} lzma) endif (MOD_XZ) -add_executable(cookiebot cookiebot.cpp) + +add_executable(cookiebot cookiebot.cpp module_storage.cpp) target_link_libraries (cookiebot ${EXTRA_LIBS}) diff --git a/cookiebot.cpp b/cookiebot.cpp index ddc8f64..92c394d 100644 --- a/cookiebot.cpp +++ b/cookiebot.cpp @@ -1,9 +1,20 @@ #include #include #include +#include #include "cookiebot_conf.h" +#include int main (int argc, char *argv[]) { - +#ifdef USE_GZIP + printf("I use GZip\n"); +#endif +#ifdef USE_BZIP2 + printf("I use BZip2\n"); +#endif +#ifdef USE_XZ + printf("I use XZ\n"); +#endif + std::cout << getModuleStorage("test.gz") << std::endl; return 0; } diff --git a/cookiebot_conf.h.in b/cookiebot_conf.h.in index 64baff2..3c2a663 100644 --- a/cookiebot_conf.h.in +++ b/cookiebot_conf.h.in @@ -1,2 +1,7 @@ #define VERSION_MAJOR @cookiebot_VERSION_MAJOR@ #define VERSION_MINOR @cookiebot_VERSION_MINOR@ +#define ON 1 +#define OFF 0 +#define USE_GZIP @MOD_GZIP@ +#define USE_BZIP2 @MOD_BZ2@ +#define USE_XZ @MOD_XZ@ diff --git a/include/module_storage.hpp b/include/module_storage.hpp new file mode 100644 index 0000000..130bff4 --- /dev/null +++ b/include/module_storage.hpp @@ -0,0 +1,5 @@ +#ifndef __MODULE_STORAGE_HPP +#define __MODULE_STORAGE_HPP +#include +auto getModuleStorage(std::string filename) -> std::string; +#endif /* end of include guard: __MODULE_STORAGE_HPP */ diff --git a/module_storage.cpp b/module_storage.cpp new file mode 100644 index 0000000..2118e99 --- /dev/null +++ b/module_storage.cpp @@ -0,0 +1,42 @@ + +#define CHUNK 16384 +#include +#include +#include +#include +#include "cookiebot_conf.h" +#include +#if USE_GZIP == ON +#include +#endif +auto getModuleStorage(std::string filename) -> std::string { + std::string::size_type idx; + idx = filename.rfind('.'); + + if(idx != std::string::npos) + { + std::string extension = filename.substr(idx+1); +#if USE_GZIP == ON + if(extension=="gz") { + FILE *out; + out=fopen(filename.substr(0,idx).c_str(), "wb"); + struct gzFile_s *file = gzopen(filename.c_str(),"rb"); + size_t len=1024*1024; + gzrewind(file); + uint8_t *buf=new uint8_t[len]; + gzread(file, (void*)buf, len); + std::cout << buf << std::endl; + fwrite((void*)buf, len, 1, out); + gzclose(file); + fclose(out); + delete[] buf; + return filename.substr(0,idx); + } +#endif + return filename; + } + else + { + return nullptr; + } +}