diff --git a/Makefile b/Makefile index cc45027..31ecafd 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ ODIR_SHARED=obj_so NAME = libztd CC=g++ -CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17 -O2 +CXXFLAGS= -I$(IDIR) -Wall -std=c++17 -O2 $(shell mkdir -p $(ODIR)) $(shell mkdir -p $(ODIR_SHARED)) @@ -41,9 +41,9 @@ static: $(OBJ) shared: $(OBJ_SHARED) $(CC) -shared -o libztd.so $^ -install: all +install: mkdir -p $(INSTALL)/usr/lib - mv libztd.a libztd.so $(INSTALL)/usr/lib + cp libztd.a libztd.so $(INSTALL)/usr/lib mkdir -p $(INSTALL)/usr/include/ztd cp -r include/* $(INSTALL)/usr/include/ztd diff --git a/include/filedat.hpp b/include/filedat.hpp index f6f13ec..7cb20bb 100644 --- a/include/filedat.hpp +++ b/include/filedat.hpp @@ -209,6 +209,8 @@ namespace ztd //! @brief Erase index from list void erase(const unsigned int index); + std::vector getlist(); + std::map getmap(); //! @brief Create a copy of the chunk inline chunkdat copy() const { return chunkdat(*this); } diff --git a/include/shell.hpp b/include/shell.hpp index 3f81da2..5d8cd8a 100644 --- a/include/shell.hpp +++ b/include/shell.hpp @@ -131,7 +131,7 @@ namespace ztd inline int pclose2(FILE* fd, pid_t pid) { return eclose(fd, pid); } - /// exec extensions + // exec extensions //! @brief Execute a binary and retrieve its outputs /*! @@ -139,8 +139,9 @@ namespace ztd @param args Arguments given to the binary */ std::pair exec(std::string const& bin, std::vector const& args); - template + //! @brief Variadic call of exec() + template std::pair exec(std::string const& bin, Args... args) { std::vector rargs = { static_cast(args)...}; return exec(bin, rargs); } //! @brief Execute string as a binary file @@ -149,6 +150,7 @@ namespace ztd @param args Arguments given to the file */ std::pair script(std::string const& data, std::vector const& args); + //! @brief Variadic call of script() template std::pair script(std::string const& data, Args... args) { std::vector rargs = { static_cast(args)...}; return script(data, rargs); } diff --git a/src/filedat.cpp b/src/filedat.cpp index cd3ee4a..eaebb3c 100644 --- a/src/filedat.cpp +++ b/src/filedat.cpp @@ -73,14 +73,19 @@ std::string ztd::filedat::removeComments(std::string str) uint32_t i=0; while(i < str.size()) { - if( str[i] == '"') // double quotes + if( str[i] == '\\') + { + //skip checking char + i++; + } + else if( str[i] == '"') // double quotes { uint32_t j=i; i++; while(i < str.size() && str[i]!='"') // until end of quote { if(i+1 < str.size() && str[i] == '\\' && str[i+1] == '"') //escaped quote - i++; //ignore backslash + i++; //ignore backslash i++; // add char and increment } @@ -275,12 +280,12 @@ static std::tuple _getstrval(const std while(i < str.size() && str[i]!='"') // until end of quote { if(i+1 < str.size() && str[i] == '\\' && str[i+1] == '"') //escaped quote - i++; //ignore backslash + i++; //ignore backslash val.push_back(str[i++]); // add char and increment } if(i >= str.size()) // quote didn't end - throw ztd::format_error("Double quote doesn't close", "", str, j); + throw ztd::format_error("Double quote doesn't close", "", str, j); i++; } else if( str[i] == '\'') // single quotes @@ -290,12 +295,12 @@ static std::tuple _getstrval(const std while(i < str.size() && str[i]!='\'') // until end of quote { if(i+1 < str.size() && str[i] == '\\' && str[i+1] == '\'') //escaped quote - i++; //ignore backslash + i++; //ignore backslash val += str[i++]; // add char } if(i >= str.size()) // quote didn't end - throw ztd::format_error("Single quote doesn't close", "", str, j); + throw ztd::format_error("Single quote doesn't close", "", str, j); i++; } if(str[i] == '{') // {} map @@ -830,6 +835,31 @@ void ztd::chunkdat::erase(const unsigned int index) } } +std::vector ztd::chunkdat::getlist() +{ + if(this->type()!=ztd::chunk_abstract::list) + { + if(m_parent != nullptr) + throw ztd::format_error("chunkdat isn't a list", m_parent->filePath(), m_parent->im_data(), m_offset ); + else + throw ztd::format_error("chunkdat isn't a list", "", this->strval(), -1); + } + ztd::chunk_list* cl = dynamic_cast(m_achunk); + return cl->list; +} +std::map ztd::chunkdat::getmap() +{ + if(this->type()!=ztd::chunk_abstract::map) + { + if(m_parent != nullptr) + throw ztd::format_error("chunkdat isn't a map", m_parent->filePath(), m_parent->im_data(), m_offset ); + else + throw ztd::format_error("chunkdat isn't a map", "", this->strval(), -1); + } + ztd::chunk_map* dc = dynamic_cast(m_achunk); + return dc->values; +} + std::string ztd::chunkdat::strval(unsigned int alignment, std::string const& aligner) const { if(this->type()==ztd::chunk_abstract::string) @@ -941,26 +971,18 @@ ztd::chunkdat& ztd::chunkdat::subChunkRef(std::string const& in) const if(this->type()!=ztd::chunk_abstract::map) { if(m_parent != nullptr) - { throw ztd::format_error("chunkdat isn't a map", m_parent->filePath(), m_parent->im_data(), m_offset ); - } else - { throw ztd::format_error("chunkdat isn't a map", "", this->strval(), -1); - } } ztd::chunk_map* dc = dynamic_cast(m_achunk); auto fi = dc->values.find(in); if(fi == dc->values.end()) { if(m_parent != nullptr) - { throw ztd::format_error("Map doesn't have '" + in + "' flag", m_parent->filePath(), m_parent->im_data(), m_offset ); - } else - { throw ztd::format_error("Map doesn't have '" + in + "' flag", "", this->strval(), -1); - } } return *fi->second; } @@ -970,25 +992,17 @@ ztd::chunkdat& ztd::chunkdat::subChunkRef(const unsigned int a) const if(this->type()!=ztd::chunk_abstract::list) { if(m_parent != nullptr) - { throw ztd::format_error("chunkdat isn't a list", m_parent->filePath(), m_parent->im_data(), m_offset ); - } else - { throw ztd::format_error("chunkdat isn't a list", "", this->strval(), -1); - } } ztd::chunk_list* cl = dynamic_cast(m_achunk); if(a >= cl->list.size()) { if(m_parent != nullptr) - { throw ztd::format_error("List size is below " + std::to_string(a), m_parent->filePath(), m_parent->im_data(), m_offset ); - } else - { throw ztd::format_error("List size is below " + std::to_string(a), "", this->strval(), -1); - } } return *cl->list[a]; }