diff --git a/configure b/configure deleted file mode 100755 index e984c6134..000000000 --- a/configure +++ /dev/null @@ -1,78 +0,0 @@ -# Anticonf (tm) script by Jeroen Ooms, Jim Hester (2017) -# This script will query 'pkg-config' for the required cflags and ldflags. -# If pkg-config is unavailable or does not find the library, try setting -# INCLUDE_DIR and LIB_DIR manually via e.g: -# R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib' - -# Library settings -PKG_CONFIG_NAME="libarchive" -PKG_DEB_NAME="libarchive-dev" -PKG_RPM_NAME="libarchive-devel" -PKG_CSW_NAME="libarchive_dev" -PKG_BREW_NAME="libarchive" -PKG_TEST_HEADER="" -PKG_LIBS=-larchive - -# Use pkg-config if available -pkg-config ${PKG_CONFIG_NAME} --atleast-version=1.0 2>/dev/null -if [ $? -eq 0 ]; then - PKGCONFIG_CFLAGS=`pkg-config --cflags ${PKG_CONFIG_NAME}` - PKGCONFIG_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}` -fi - -# Note that cflags may be empty in case of success -if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then - echo "Found INCLUDE_DIR and/or LIB_DIR!" - PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS" - PKG_LIBS="-L$LIB_DIR $PKG_LIBS" -elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then - echo "Found pkg-config cflags and libs!" - PKG_CFLAGS=${PKGCONFIG_CFLAGS} - PKG_LIBS=${PKGCONFIG_LIBS} -elif [ `uname` = "Darwin" ]; then - test ! "$CI" && brew --version 2>/dev/null - if [ $? -eq 0 ]; then - BREWDIR=`brew --prefix` - PKG_CFLAGS="-I$BREWDIR/opt/libarchive/include" - PKG_LIBS="-L$BREWDIR/opt/libarchive/lib $PKG_LIBS" - else - curl -sfL "https://autobrew.github.io/scripts/$PKG_BREW_NAME" > autobrew - . ./autobrew - fi -fi - -# Find compiler -CXX20=`${R_HOME}/bin/R CMD config CXX20` -CXX20FLAGS=`${R_HOME}/bin/R CMD config CXX20FLAGS` -CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS` - -# For debugging -echo "PKG_CFLAGS=$PKG_CFLAGS" -echo "PKG_LIBS=$PKG_LIBS" - -# Test configuration -echo "#include $PKG_TEST_HEADER" | ${CXX20} ${CPPFLAGS} ${PKG_CFLAGS} ${CXX20FLAGS} -E -xc++ - > /dev/null - -# Customize the error -if [ $? -ne 0 ]; then - echo "--------------------------- [ANTICONF] --------------------------------" - echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:" - echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu, etc)" - echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)" - echo " * csw: $PKG_CSW_NAME (Solaris)" - echo " * brew: $PKG_BREW_NAME (Mac OSX)" - echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your" - echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config" - echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:" - echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'" - echo "-------------------------- [ERROR MESSAGE] ---------------------------" - cat configure.log - echo "--------------------------------------------------------------------" - exit 1 -fi - -# Write to Makevars -sed -e "s|@PKG_CXXFLAGS@|$PKG_CFLAGS|" -e "s|@PKG_LIBS@|$PKG_LIBS|" src/Makevars.in > src/Makevars - -# Success -exit 0 diff --git a/src/Makevars b/src/Makevars index f3cae4a92..92da27d01 100644 --- a/src/Makevars +++ b/src/Makevars @@ -1,9 +1,7 @@ -#PKG_CPPFLAGS = -I. -I../inst/include/pugixml -Ixlcpp -DXLCPP_EXPORT PKG_CXXFLAGS = -I. -Ixlcpp -I../inst/include/pugixml -DXLCPP_EXPORT -#PKG_LIBS=-Lpugixml -Lcfbf -L/usr/lib -larchive -L/usr/lib -lfmt -PKG_LIBS = -larchive -Lpugixml -Lxlcpp +PKG_LIBS = -Lpugixml -Lxlcpp PKGROOT = ./xlcpp @@ -15,24 +13,23 @@ OBJECTS = decrypt.o \ styles_xml.o \ write_file.o \ $(PKGROOT)/aes.o \ - $(PKGROOT)/b64.o \ - $(PKGROOT)/cfbf.o \ - $(PKGROOT)/mmap.o \ - $(PKGROOT)/sha1.o \ - $(PKGROOT)/sha512.o \ - $(PKGROOT)/xlcpp.o \ - $(PKGROOT)/xml-reader.o \ - RcppExports.o - + $(PKGROOT)/b64.o \ + $(PKGROOT)/cfbf.o \ + $(PKGROOT)/mmap.o \ + $(PKGROOT)/sha1.o \ + $(PKGROOT)/sha512.o \ + $(PKGROOT)/xlcpp.o \ + $(PKGROOT)/xml-reader.o \ + RcppExports.o XLCPP = $(PKGROOT)/aes.cpp \ - $(PKGROOT)/b64.cpp \ - $(PKGROOT)/cfbf.cpp \ - $(PKGROOT)/mmap.cpp \ - $(PKGROOT)/sha1.cpp \ - $(PKGROOT)/sha512.cpp \ - $(PKGROOT)/xml-reader.cpp \ - $(PKGROOT)/xlcpp.cpp + $(PKGROOT)/b64.cpp \ + $(PKGROOT)/cfbf.cpp \ + $(PKGROOT)/mmap.cpp \ + $(PKGROOT)/sha1.cpp \ + $(PKGROOT)/sha512.cpp \ + $(PKGROOT)/xml-reader.cpp \ + $(PKGROOT)/xlcpp.cpp PUGIXML = ../inst/include/pugixml/pugixml.cpp diff --git a/src/Makevars.in b/src/Makevars.in deleted file mode 100644 index 4da22aace..000000000 --- a/src/Makevars.in +++ /dev/null @@ -1,39 +0,0 @@ - -#PKG_CPPFLAGS = -I. -I../inst/include/pugixml -Ixlcpp -DXLCPP_EXPORT -PKG_CXXFLAGS = @PKG_CXXFLAGS@ -I. -Ixlcpp -I../inst/include/pugixml -DXLCPP_EXPORT - -#PKG_LIBS=-Lpugixml -Lcfbf -L/usr/lib -larchive -L/usr/lib -lfmt -PKG_LIBS = @PKG_LIBS@ -Lpugixml -Lxlcpp - -PKGROOT = ./xlcpp - -OBJECTS = decrypt.o \ - helper_functions.o \ - load_workbook.o \ - pugi.o \ - strings_xml.o \ - styles_xml.o \ - write_file.o \ - $(PKGROOT)/aes.o \ - $(PKGROOT)/b64.o \ - $(PKGROOT)/cfbf.o \ - $(PKGROOT)/mmap.o \ - $(PKGROOT)/sha1.o \ - $(PKGROOT)/sha512.o \ - $(PKGROOT)/xlcpp.o \ - $(PKGROOT)/xml-reader.o \ - RcppExports.o - - -XLCPP = $(PKGROOT)/aes.cpp \ - $(PKGROOT)/b64.cpp \ - $(PKGROOT)/cfbf.cpp \ - $(PKGROOT)/mmap.cpp \ - $(PKGROOT)/sha1.cpp \ - $(PKGROOT)/sha512.cpp \ - $(PKGROOT)/xml-reader.cpp \ - $(PKGROOT)/xlcpp.cpp - -PUGIXML = ../inst/include/pugixml/pugixml.cpp - -# CXX_STD=CXX20 diff --git a/src/xlcpp/xlcpp-pimpl.h b/src/xlcpp/xlcpp-pimpl.h index f3325d12a..c2a3a03c8 100644 --- a/src/xlcpp/xlcpp-pimpl.h +++ b/src/xlcpp/xlcpp-pimpl.h @@ -11,8 +11,8 @@ #include #include #include -#include -#include +// #include +// #include namespace xlcpp { @@ -33,8 +33,8 @@ class workbook_pimpl { workbook_pimpl(std::span sv, std::string_view password, std::string_view outfile); std::string data() const; - void write_archive(struct archive* a) const; - la_ssize_t write_callback(struct archive* a, const void* buffer, size_t length) const; + // void write_archive(struct archive* a) const; + // la_ssize_t write_callback(struct archive* a, const void* buffer, size_t length) const; void load_archive(struct archive* a); #ifdef _WIN32 @@ -53,32 +53,34 @@ class workbook_pimpl { void load_from_memory(std::span sv, std::string_view password, std::string_view outfile); }; +}; // end namespace xlcpp + + enum class xml_node { - unknown, - text, - whitespace, - element, - end_element, - processing_instruction, - comment, - cdata + unknown, + text, + whitespace, + element, + end_element, + processing_instruction, + comment, + cdata }; - class xml_enc_string_view { public: - xml_enc_string_view() { } - xml_enc_string_view(std::string_view sv) : sv(sv) { } + xml_enc_string_view() { } + xml_enc_string_view(std::string_view sv) : sv(sv) { } - bool empty() const noexcept { - return sv.empty(); - } + bool empty() const noexcept { + return sv.empty(); + } - std::string decode() const; - bool cmp(std::string_view str) const; + std::string decode() const; + bool cmp(std::string_view str) const; private: - std::string_view sv; + std::string_view sv; }; using ns_list = std::vector>; @@ -104,24 +106,24 @@ class xml_reader { std::vector namespaces; }; -class archive_read_closer { -public: - typedef archive* pointer; - - void operator()(archive* a) { - archive_read_free(a); - } -}; - -using archive_read_t = std::unique_ptr; - -class archive_write_closer { -public: - typedef archive* pointer; - - void operator()(archive* a) { - archive_write_free(a); - } -}; - -using archive_write_t = std::unique_ptr; +// class archive_read_closer { +// public: +// typedef archive* pointer; +// +// void operator()(archive* a) { +// archive_read_free(a); +// } +// }; +// +// using archive_read_t = std::unique_ptr; +// +// class archive_write_closer { +// public: +// typedef archive* pointer; +// +// void operator()(archive* a) { +// archive_write_free(a); +// } +// }; +// +// using archive_write_t = std::unique_ptr; diff --git a/src/xlcpp/xlcpp.cpp b/src/xlcpp/xlcpp.cpp index 62bfd58a2..da5f831b8 100644 --- a/src/xlcpp/xlcpp.cpp +++ b/src/xlcpp/xlcpp.cpp @@ -7,15 +7,13 @@ #include "mmap.h" #include "cfbf.h" #include "utf16.h" -#include -#include #include #include #include -#ifdef _WIN32 -#include -#endif +// #ifdef _WIN32 +// #include +// #endif // #define FMT_HEADER_ONLY // #include @@ -70,17 +68,17 @@ __inline string utf16_to_utf8(const u16string_view& s) { #endif workbook_pimpl::workbook_pimpl(const filesystem::path& fn, string_view password, string_view outfile) { -#ifdef _WIN32 - unique_handle hup{CreateFileW((LPCWSTR)fn.u16string().c_str(), FILE_READ_DATA | DELETE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, nullptr)}; - if (hup.get() == INVALID_HANDLE_VALUE) - throw last_error("CreateFile", GetLastError()); -#else +// #ifdef _WIN32 +// unique_handle hup{CreateFileW((LPCWSTR)fn.u16string().c_str(), FILE_READ_DATA | DELETE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, +// FILE_ATTRIBUTE_NORMAL, nullptr)}; +// if (hup.get() == INVALID_HANDLE_VALUE) +// throw last_error("CreateFile", GetLastError()); +// #else unique_handle hup{open(fn.string().c_str(), O_RDONLY)}; if (hup.get() == -1) Rcpp::stop("open failed (errno = {})", errno); -#endif +// #endif mmap m(hup.get()); diff --git a/src/xlcpp/xml-reader.cpp b/src/xlcpp/xml-reader.cpp index 4bf09c521..8549af33f 100644 --- a/src/xlcpp/xml-reader.cpp +++ b/src/xlcpp/xml-reader.cpp @@ -336,3 +336,63 @@ static string esc_char(string_view s) { return string{string_view(t, 4)}; } } + +string xml_enc_string_view::decode() const { + auto v = sv; + string s; + + s.reserve(v.length()); + + while (!v.empty()) { + if (v.front() == '&') { + v.remove_prefix(1); + + if (v.starts_with("amp;")) { + s += "&"; + v.remove_prefix(4); + } else if (v.starts_with("lt;")) { + s += "<"; + v.remove_prefix(3); + } else if (v.starts_with("gt;")) { + s += ">"; + v.remove_prefix(3); + } else if (v.starts_with("quot;")) { + s += "\""; + v.remove_prefix(5); + } else if (v.starts_with("apos;")) { + s += "'"; + v.remove_prefix(5); + } else if (v.starts_with("#")) { + string_view bit; + + v.remove_prefix(1); + + auto sc = v.find_first_of(';'); + if (sc == string::npos) { + bit = v; + v = ""; + } else { + bit = v.substr(0, sc); + v.remove_prefix(sc + 1); + } + + s += esc_char(bit); + } else + s += "&"; + } else { + s += v.front(); + v.remove_prefix(1); + } + } + + return s; +} + +bool xml_enc_string_view::cmp(string_view str) const { + for (auto c : sv) { + if (c == '&') + return decode() == str; + } + + return sv == str; +}