Basic zip file support.
continuous-integration/drone/push Build is passing Details

Dumping the TOC works.
This commit is contained in:
tastytea 2021-05-21 01:56:37 +02:00
parent 031e2f0db6
commit 222f802015
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
7 changed files with 114 additions and 11 deletions

View File

@ -26,7 +26,7 @@ steps:
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qq build-essential cmake clang
- apt-get install -qq catch libboost-all-dev gettext
- apt-get install -qq catch libboost-all-dev gettext libarchive-dev
- rm -rf build && mkdir -p build && cd build
- cmake -G "Unix Makefiles" -DWITH_TESTS=YES ..
- make VERBOSE=1
@ -42,10 +42,10 @@ steps:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: Download CMake 3.12 installer
- name: Download CMake 3.17 installer
image: plugins/download
settings:
source: https://cmake.org/files/v3.12/cmake-3.12.0-Linux-x86_64.sh
source: https://cmake.org/files/v3.17/cmake-3.17.0-Linux-x86_64.sh
destination: cmake_installer.sh
- name: GCC 7 / clang 6
@ -61,7 +61,7 @@ steps:
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qq build-essential clang
- apt-get install -qq catch libboost-all-dev gettext
- apt-get install -qq catch libboost-all-dev gettext libarchive-dev
- sh cmake_installer.sh --skip-license --exclude-subdir --prefix=/usr/local
- rm -rf build && mkdir -p build && cd build
- cmake -G "Unix Makefiles" -DWITH_TESTS=YES ..

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12...3.18)
cmake_minimum_required(VERSION 3.17...3.18)
# Global build options.
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build.")
@ -24,6 +24,7 @@ include(cmake/debug_flags.cmake)
find_package(Boost 1.65.0 REQUIRED COMPONENTS program_options locale)
find_package(Gettext REQUIRED)
find_package(Filesystem REQUIRED COMPONENTS Final Experimental)
find_package(LibArchive REQUIRED)
add_subdirectory(src)

View File

@ -11,6 +11,7 @@
:uri-catch: https://github.com/catchorg/Catch2
:uri-boost: https://www.boost.org/
:uri-gettext: https://www.gnu.org/software/gettext/
:uri-libarchive: https://www.libarchive.org/
*{project}* is a search tool for EPUB ebooks.
@ -36,9 +37,10 @@ image::https://repology.org/badge/vertical-allrepos/epubgrep.svg[]
* Tested OS: Linux
* C\++ compiler with C++17 support (tested: link:{uri-gcc}[GCC] 7/10,
link:{uri-clang}[clang] 6/11)
* link:{uri-cmake}[CMake] (at least: 3.12)
* link:{uri-cmake}[CMake] (at least: 3.17)
* link:{uri-boost}[Boost] (tested: 1.75.0 / 1.65.0)
* link:{uri-gettext}[gettext] (tested: 0.21 / 0.19)
* link:{uri-libarchive}[libarchive] (tested: 3.5 / 3.2)
* Optional
** Tests: link:{uri-catch}[Catch] (tested: 2.13 / 1.10)

View File

@ -14,7 +14,7 @@ unset(headers_src)
target_link_libraries(${PROJECT_NAME}
Boost::program_options Boost::locale
std::filesystem)
std::filesystem LibArchive::LibArchive)
target_include_directories(${PROJECT_NAME}
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")

View File

@ -15,6 +15,7 @@
*/
#include "options.hpp"
#include "zip.hpp"
#include <boost/locale/generator.hpp>
#include <boost/locale/message.hpp>
@ -64,13 +65,16 @@ int main(int argc, char *argv[])
cout << "perl-regexp: " << vm.count("perl-regexp") << '\n';
cout << "ignore-case: " << vm.count("ignore-case") << '\n';
if (vm.count("input") > 0)
if (vm.count("input-file") > 0)
{
cout << "\nINPUT FILES: ";
for (const auto &input : vm["input"].as<std::vector<std::string>>())
for (const auto &file : vm["input-file"].as<std::vector<std::string>>())
{
cout << input << " ";
cout << " " << file << ":\n";
for (const auto &entry : epubgrep::zip::list(file))
{
cout << " " << entry << '\n';
}
}
cout << '\n';
}
}

64
src/zip.cpp Normal file
View File

@ -0,0 +1,64 @@
/* This file is part of epubgrep.
* Copyright © 2021 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received zipfile copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "zip.hpp"
#include "fs-compat.hpp"
#include <archive.h>
#include <archive_entry.h>
#include <string>
#include <vector>
namespace epubgrep::zip
{
std::vector<std::string> list(const fs::path &filepath)
{
struct archive *zipfile{};
struct archive_entry *entry{};
int result{};
std::vector<std::string> toc;
zipfile = archive_read_new();
archive_read_support_filter_all(zipfile);
archive_read_support_format_all(zipfile);
result = archive_read_open_filename(zipfile, filepath.c_str(), 10240);
if (result != ARCHIVE_OK)
{
// NOLINTNEXTLINE
throw "Zip file not okay. 🙁";
}
while (archive_read_next_header(zipfile, &entry) == ARCHIVE_OK)
{
toc.emplace_back(archive_entry_pathname(entry));
archive_read_data_skip(zipfile);
}
result = archive_read_free(zipfile);
if (result != ARCHIVE_OK)
{
// NOLINTNEXTLINE
throw "Error closing zipfile. 🙁";
}
return toc;
}
} // namespace epubgrep::zip

32
src/zip.hpp Normal file
View File

@ -0,0 +1,32 @@
/* This file is part of epubgrep.
* Copyright © 2021 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EPUBGREP_ZIP_HPP
#define EPUBGREP_ZIP_HPP
#include "fs-compat.hpp"
#include <string>
#include <vector>
namespace epubgrep::zip
{
std::vector<std::string> list(const fs::path &filepath);
} // namespace epubgrep::zip
#endif // EPUBGREP_ZIP_HPP