diff --git a/Makefile b/Makefile index 222d2f4..0171423 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,11 @@ CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17 ifeq ($(DEBUG),true) CXXFLAGS += -g endif +ifeq ($(STATIC),true) + LDFLAGS += -l:libztd.a +else + LDFLAGS += -lztd +endif $(shell mkdir -p $(ODIR)) $(shell mkdir -p $(BINDIR)) diff --git a/README.md b/README.md index 9214e2f..dce710e 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ Map midi signals coming from ALSA midi devices to shell commands -Soft dependencies: alsa-utils -Hard dependencies: aseqdump +Dependencies: alsa-utils , [ztd](https://github.com/zawwz/ztd) ## Installing diff --git a/include/Filedat.hpp b/include/Filedat.hpp deleted file mode 100644 index f626aaa..0000000 --- a/include/Filedat.hpp +++ /dev/null @@ -1,191 +0,0 @@ -#ifndef FILEDAT_H -#define FILEDAT_H - -#include -#include -#include -#include -#include - -#include - -class format_error : public std::exception -{ -public: - format_error(const std::string& what, const std::string& origin, const std::string& data, int where) { desc=what; index=where; filename=origin; sdat=data; } - - const char * what () const throw () {return desc.c_str();} - const int where () const throw () {return index;} - const char * data() const throw () {return sdat.c_str();} - const char * origin() const throw () {return filename.c_str();} -private: - std::string desc; - int index; - std::string filename; - std::string sdat; -}; - -void printErrorIndex(const char* in, const int index, const std::string& message, const std::string& origin); -inline void printFormatException(format_error& exc) { printErrorIndex(exc.data(), exc.where(), exc.what(), exc.origin()); } - -class Filedat; - -class AbstractChunk -{ -public: - enum typeEnum { none, val, chunk, list}; - - typeEnum type() { return m_type; } - - AbstractChunk() { m_type=AbstractChunk::none; } - virtual ~AbstractChunk() {} - -protected: - typeEnum m_type; -}; - -class Chunk -{ -public: - Chunk() { m_achunk=nullptr; } - - Chunk(const char* in) - { m_achunk=nullptr; set(in, strlen(in), 0, nullptr); } - Chunk(std::string const& in) - { m_achunk=nullptr; set(in, 0, nullptr); } - Chunk(const char* in, const int in_size, int offset=0, Filedat* data=nullptr) - { m_achunk=nullptr; set(in, in_size, offset, data); } - Chunk(std::string const& in, int offset=0, Filedat* data=nullptr) - { m_achunk=nullptr; set(in, offset, data); } - - Chunk(Chunk const& in) { m_achunk=nullptr; set(in); } - - void clear() { if(m_achunk!=nullptr) delete m_achunk; m_achunk=nullptr; } - ~Chunk() { clear(); } - - Filedat* parent() const { return m_parent; } - int offset() const { return m_offset; } - - void set(const char* in, const int in_size, int offset=0, Filedat* data=nullptr); - void set(std::string const& in, int offset=0, Filedat* data=nullptr) { this->set(in.c_str(), in.size(), offset, data); } - - void set(Chunk const& in) { this->set(in.strval(), in.offset(), in.parent()); } // TODO - - std::string strval(unsigned int alignment=0, std::string const& aligner="\t") const; - - - void addToChunk(std::string const& name, Chunk const& val); //adds if datachunk - void addToChunk(std::vector> const& vec); //adds if datachunk - void addToList(Chunk const& val); //adds if list - void addToList(std::vector const& vec); //adds if list - inline void add(std::string const& name, Chunk const& val) { addToChunk(name, val); } //adds if datachunk - inline void add(std::pair const& pair) { add(pair.first, pair.second); } //adds if datachunk - inline void add(std::vector> const& vec) { addToChunk(vec); } //adds if datachunk - inline void add(Chunk const& val) { addToList(val); } //adds if list - inline void add(std::vector const& vec) { addToList(vec); } //adds if list - // void concatenate(Chunk const& chk); //concatenates chunks - - Chunk copy() const { return Chunk(*this); } - Chunk* pcopy() const { return new Chunk(*this); } - - AbstractChunk* getp() const { return m_achunk; } - AbstractChunk::typeEnum type() const { if(m_achunk!=nullptr) return m_achunk->type(); else return AbstractChunk::none; } - int listSize() const; - - Chunk* subChunkPtr(std::string const& a) const; //datachunk - Chunk* subChunkPtr(unsigned int a) const; //chunklist - Chunk& subChunkRef(std::string const& a) const; //datachunk - Chunk& subChunkRef(unsigned int a) const; //chunklist - - Chunk& operator[](std::string const& a) const { return subChunkRef(a); } - Chunk& operator[](unsigned int a) const { return subChunkRef(a); } - Chunk& operator=(Chunk const& a) { set(a); return *this; } - inline Chunk& operator+=(std::pair const& a) { add(a); return *this; } - inline Chunk& operator+=(std::vector> const& a) { add(a); return *this; } - inline Chunk& operator+=(Chunk const& a) { add(a); return *this; } - inline Chunk& operator+=(std::vector const& a) { add(a); return *this; } - // inline bool operator*=(Chunk const& a) { concatenate(a); } - - //add operator+ and operator* - - -protected: - Filedat* m_parent; - int m_offset; - - AbstractChunk* m_achunk; -}; - -std::ostream& operator<<(std::ostream& stream, Chunk const& a); - -class DataVal : public AbstractChunk -{ -public: - DataVal() { m_type=AbstractChunk::val; } - virtual ~DataVal() {} - - std::string val; -}; - -class DataChunk : public AbstractChunk -{ -public: - DataChunk() { m_type=AbstractChunk::chunk; } - virtual ~DataChunk(); - - std::map values; - -}; - -class ChunkList : public AbstractChunk -{ -public: - ChunkList() { m_type=AbstractChunk::list; } - virtual ~ChunkList(); - - std::vector list; -}; - -class Filedat -{ -public: - Filedat(); - Filedat(std::string const& in); - virtual ~Filedat(); - - bool readTest() const; - - void import_file(const std::string& path=""); - void import_stdin(); - void import_string(const std::string& data); - bool export_file(std::string const& path="", std::string const& aligner="\t") const; - - void clear(); - - inline std::string filePath() const { return m_filePath; } - inline void setFilePath(std::string const& in) { m_filePath=in; } - - std::string strval(std::string const& aligner="\t") const; - - inline Chunk* pchunk() const { return m_dataChunk; } - inline Chunk& chunk() const { return *m_dataChunk; } - - inline Chunk* pdata() const { return m_dataChunk; } - inline Chunk& data() const { return *m_dataChunk; } - - inline const std::string& stringdata() const { return m_data; } - inline const char* c_data() const { return m_data.c_str(); } - - inline Chunk& operator[](const std::string& index) { return m_dataChunk->subChunkRef(index); } - inline Chunk& operator[](const int index) { return m_dataChunk->subChunkRef(index); } - -private: - //functions - void generateChunk(); - //attributes - std::string m_filePath; - std::string m_data; - Chunk* m_dataChunk; -}; - -#endif //FILEDAT_H diff --git a/include/device.hpp b/include/device.hpp index 6240533..212802b 100644 --- a/include/device.hpp +++ b/include/device.hpp @@ -6,7 +6,7 @@ #include #include "command.hpp" -#include "Filedat.hpp" +#include void sh(std::string const& string); @@ -19,8 +19,8 @@ public: bool start_loop(); void run_signal(char* buff); - bool import_chunk(Chunk const& ch); - Chunk export_chunk(); + bool import_chunk(ztd::chunkdat const& ch); + ztd::chunkdat export_chunk(); std::string name; int client_id; diff --git a/include/options.hpp b/include/options.hpp deleted file mode 100644 index 40a83d3..0000000 --- a/include/options.hpp +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef OPTIONS_H -#define OPTIONS_H - -//DUPLICATES NOT HANDLED: takes last one -//NO ORDER: no way to know options order -//RETURNS TRANSITIONAL STATE IF ERROR - -#include -#include -#include - - -// Turn argc/argv into a vector -std::vector argVector(int argc, char** argv); - -class Option -{ -public: - /* CTOR/DTOR */ - //ctors - Option(); - Option(char c, bool arg, std::string helptext="", std::string argname="arg"); - Option(std::string const& str, bool arg, std::string helptext="", std::string argname="arg"); - Option(char c, std::string const& str, bool arg, std::string helptext="", std::string argname="arg"); - //dtors - virtual ~Option(); - - /* FUNCTIONS */ - - // Print command help. Puts leftpad spaces before printing, and rightpad space until help - void printHelp(int leftpad, int rightpad); - - /* PROPERTIES */ - - bool shortDef; // has a char definition - char charName; - - bool longDef; // has a string definition - std::string strName; - - bool takesArgument; // option takes an argument - - std::string help_text; // text to display in printHelp - std::string arg_name; // name of the argument to display in printHelp - - /* PROCESSING STATUS */ - - bool activated; // option was activated - - std::string argument; // argument of the option - -}; - -class OptionSet -{ -public: - /* CTOR/DTOR */ - OptionSet(); - virtual ~OptionSet(); - - /* PROPERTIES */ - - // Stream on which errors are sent. Default stderr - std::ostream* errStream; - - /* FUNCTIONS */ - - /*CREATION FUNCTIONS*/ - //Adding an option. Refer to Option ctors - void addOption(Option opt) { m_options.push_back(opt); } - - /*PRINT FUNCTIONS*/ - // Print command help. Puts leftpad spaces before each line, and rightpad space until help - void printHelp(int leftpad=2, int rightpad=25); - - /*QUERY FUNCTIONS*/ - // Find an option with its charname - Option* findOption(char c); - // Find an option with its stringname - Option* findOption(std::string const& str); - - /*PROCESSING FUNCTIONS*/ - // Process through options. - // pair.first : vector with arguments that were not identified as options - // pair.second : bool indicating status. True if no error encountered, false if errors - std::pair,bool> getOptions(std::vector input); - std::pair,bool> getOptions(int argc, char** argv) { return getOptions(argVector(argc, argv)); } - -private: - std::vector