From ff8e9e6b3286825fd8ca831c93512760d41e3410 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 18 Jan 2022 19:40:57 +0100 Subject: [PATCH 1/4] start working on winixcli winixcli can now read a PGModeler file and is able to generate a template through ezc winixcli parameters: --input-mode pgmodeler (only one parameter at the moment) --input-file file (pgmodeler file) --templates-dir dir_path (a path to templates directory) --template file (template file) --- winixcli/Makefile | 25 ++++ winixcli/src/Makefile | 58 +++++++++ winixcli/src/Makefile.dep | 5 + winixcli/src/main.cpp | 247 +++++++++++++++++++++++++++++++++++++ winixcli/src/misc.cpp | 65 ++++++++++ winixcli/src/misc.h | 54 ++++++++ winixcli/src/pgmodeler.cpp | 96 ++++++++++++++ winixcli/src/pgmodeler.h | 64 ++++++++++ 8 files changed, 614 insertions(+) create mode 100644 winixcli/Makefile create mode 100644 winixcli/src/Makefile create mode 100644 winixcli/src/Makefile.dep create mode 100644 winixcli/src/main.cpp create mode 100644 winixcli/src/misc.cpp create mode 100644 winixcli/src/misc.h create mode 100644 winixcli/src/pgmodeler.cpp create mode 100644 winixcli/src/pgmodeler.h diff --git a/winixcli/Makefile b/winixcli/Makefile new file mode 100644 index 0000000..ebe418c --- /dev/null +++ b/winixcli/Makefile @@ -0,0 +1,25 @@ + + +export CXX +export CXXFLAGS +export LDFLAGS + + +all: src + + +src: FORCE + $(MAKE) -C src + + +clean: FORCE + $(MAKE) -C src clean + + +depend: FORCE + $(MAKE) -C src depend + + + +FORCE: + diff --git a/winixcli/src/Makefile b/winixcli/src/Makefile new file mode 100644 index 0000000..7d7ea37 --- /dev/null +++ b/winixcli/src/Makefile @@ -0,0 +1,58 @@ +sourcefiles:=$(shell find . -name "*.cpp") +objfiles:=$(patsubst %.cpp,%.o,$(sourcefiles)) +GLOBAL_WORKING_DIR := $(shell pwd)/../../.. + + +CXX = g++10 +CXXFLAGS = -Wall -pedantic -O0 -g -std=c++20 -I$(GLOBAL_WORKING_DIR)/pikotools/src -I$(GLOBAL_WORKING_DIR)/ezc/src -I$(GLOBAL_WORKING_DIR)/morm/src -I/usr/local/include -DEZC_HAS_MORM_LIBRARY -DMORM_HAS_EZC_LIBRARY +LDFLAGS = -L/usr/local/lib + + +export CXX +export CXXFLAGS +export LDFLAGS + + +progname = winix + + +all: $(progname) + + +$(progname): $(objfiles) pikotools morm ezc + $(CXX) -o $(progname) $(CXXFLAGS) $(LDFLAGS) $(objfiles) $(GLOBAL_WORKING_DIR)/ezc/src/ezc.a $(GLOBAL_WORKING_DIR)/morm/src/morm.a $(GLOBAL_WORKING_DIR)/pikotools/src/pikotools.a + + +%.o: %.cpp + $(CXX) -c $(CXXFLAGS) -o $@ $< + + +.PHONY: pikotools +.PHONY: morm +.PHONY: ezc + + +pikotools: + $(MAKE) -C ../../../pikotools + +morm: + $(MAKE) -C ../../../morm/src + +ezc: + $(MAKE) -C ../../../ezc/src + + +clean: + rm -f $(objfiles) + rm -f $(progname) + $(MAKE) -C ../../../pikotools clean + $(MAKE) -C ../../../morm/src clean + $(MAKE) -C ../../../ezc/src clean + + +depend: + makedepend -Y. -f- $(sourcefiles) > Makefile.dep + + +-include Makefile.dep + diff --git a/winixcli/src/Makefile.dep b/winixcli/src/Makefile.dep new file mode 100644 index 0000000..cde5776 --- /dev/null +++ b/winixcli/src/Makefile.dep @@ -0,0 +1,5 @@ +# DO NOT DELETE + +./main.o: pgmodeler.h misc.h +./pgmodeler.o: pgmodeler.h misc.h +./misc.o: misc.h diff --git a/winixcli/src/main.cpp b/winixcli/src/main.cpp new file mode 100644 index 0000000..16c17e7 --- /dev/null +++ b/winixcli/src/main.cpp @@ -0,0 +1,247 @@ +/* + * This file is a part of Winix + * and is distributed under the 2-Clause BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2022, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include "mainoptions/mainoptionsparser.h" +#include "pgmodeler.h" +#include "misc.h" +#include "ezc.h" + + +namespace Winix +{ + + +// make a static method in MainOptionsParser? +std::wstring get_param(const pt::Space::TableType * input_mode) +{ + if( input_mode && input_mode->size() > 0 ) + { + pt::Space * first_par = (*input_mode)[0]; + + if( first_par->is_table() && first_par->table_size() > 0 ) + { + return first_par->value.value_table.front()->to_wstr(); + } + } + + return std::wstring(); +} + + +bool use_pgmodeler(const std::wstring & input_file, const pt::Space & input_options, pt::Space & schema) +{ + PGModeler pgmodeler; + return pgmodeler.parse(input_file, schema); +} + + + +typedef pt::WTextStream MyStream; + + + + +// move me to a better place +void esc_tex(wchar_t c, pt::WTextStream & str) +{ + if( c == '$' ) + str << L"\\$"; + else + if( c == '#' ) + str << L"\\#"; + else + if( c == '%' ) + str << L"\\%"; + else + if( c == '&' ) + str << L"\\&"; + else + if( c == '\\' ) + str << L"$\\backslash$"; + else + if( c == '{' ) + str << L"$\\{$"; + else + if( c == '}' ) + str << L"$\\}$"; + else + if( c == '^' ) + str << L""; // !! IMPROVE ME add \char with specific code + else + if( c == '_' ) + str << L"\\_"; + else + if( c == '~' ) + str << L""; // !! IMPROVE ME add \char with specific code + else + if( c == '-' ) + str << L"{-}"; + else + if( c != 0 ) + str << c; + +} + + + + +void fil_tex(Ezc::FunInfo & env) +{ + auto i = env.in.begin(); + + for( ; i != env.in.end() ; ++i) + { + esc_tex(*i, env.out); + } +} + + + +bool generate(const pt::Space & input_options, pt::Space & schema) +{ + pt::WTextStream log_buffer; + pt::FileLog file_log; + pt::Log log; + + file_log.init(L"log.txt", true, 4, true); + log.set_file_log(&file_log); + log.set_log_buffer(&log_buffer); + + Ezc::Pattern pattern; + Ezc::PatternParser parser; + Ezc::Functions functions; + Ezc::Blocks blocks; + Ezc::Models models; + + std::wstring dir = get_param(input_options.get_table(L"templates-dir")); + std::wstring template_file = get_param(input_options.get_table(L"template")); + + if( dir.empty() ) + { + std::cerr << "you have to set the templates directory with --templates-dir parameter" << std::endl; + return false; + } + + if( template_file.empty() ) + { + std::cerr << "you have to set the template file name with --template_file parameter" << std::endl; + return false; + } + + functions.Insert("fil_tex", fil_tex); + + parser.Directory(dir); + parser.SetBlocks(blocks); + parser.SetLogger(&log); + parser.ParseFile(template_file, pattern); + + models.Add(L"schema", schema); + + Ezc::Generator generator; + + generator.SetPattern(pattern); + generator.SetFunctions(functions); + generator.SetModels(models); + + MyStream str; + generator.SetLogger(log); + generator.Generate(str); + + std::string tmp; + str.to_str(tmp); + std::cout << tmp << std::endl; + + log << pt::Log::logsave; + return true; +} + + + + + +} // namespace Winix + + + + +int main(int argc, const char ** argv) +{ + using namespace Winix; + + pt::MainOptionsParser parser; + pt::Space input_options, args, schema; + + args.add(L"input-mode", 1); + args.add(L"input-file", 1); + args.add(L"templates-dir", 1); + args.add(L"template", 1); + + pt::MainOptionsParser::Status status = parser.parse(argc, argv, input_options, args); + + std::wstring input_mode = get_param(input_options.get_table(L"input-mode")); + std::wstring input_file = get_param(input_options.get_table(L"input-file")); + + if( input_mode.empty() ) + { + std::cout << "you have to use --input-mode parameter" << std::endl; + return 1; + } + + print("input-mode", input_mode); + print("input-file", input_file); + + if( input_mode == L"pgmodeler" ) + { + if( !use_pgmodeler(input_file, input_options, schema) ) + return 3; + } + else + { + std::cerr << "unknown --input-mode parameter, available are: pgmodeler" << std::endl; + return 2; + } + + generate(input_options, schema); + + + // for debug purposes +// std::string tmp; +// tmp = input_options.serialize_to_json_str(true); +// std::cout << tmp << std::endl; + +} + + + diff --git a/winixcli/src/misc.cpp b/winixcli/src/misc.cpp new file mode 100644 index 0000000..dc5157a --- /dev/null +++ b/winixcli/src/misc.cpp @@ -0,0 +1,65 @@ +/* + * This file is a part of Winix + * and is distributed under the 2-Clause BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2022, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include "misc.h" + +namespace Winix +{ + + +void print_nonl(const char * msg, const std::wstring & str) +{ + std::string str_utf8; + pt::wide_to_utf8(str, str_utf8); + std::cerr << msg << ": " << str_utf8; +} + + +void print(const char * msg, const std::wstring & str) +{ + print_nonl(msg, str); + std::cerr << std::endl; +} + + +void print(const char * msg, const std::wstring & str, int val) +{ + print_nonl(msg, str); + std::cerr << ":" << val << std::endl; +} + + +} + diff --git a/winixcli/src/misc.h b/winixcli/src/misc.h new file mode 100644 index 0000000..f549d9b --- /dev/null +++ b/winixcli/src/misc.h @@ -0,0 +1,54 @@ +/* + * This file is a part of Winix + * and is distributed under the 2-Clause BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2022, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef headerfile_winixcli_src_misc +#define headerfile_winixcli_src_misc + +#include "space/space.h" + + +namespace Winix +{ + +void print_nonl(const char * msg, const std::wstring & str); +void print(const char * msg, const std::wstring & str); +void print(const char * msg, const std::wstring & str, int val); + + + +} + + +#endif + diff --git a/winixcli/src/pgmodeler.cpp b/winixcli/src/pgmodeler.cpp new file mode 100644 index 0000000..6208196 --- /dev/null +++ b/winixcli/src/pgmodeler.cpp @@ -0,0 +1,96 @@ +/* + * This file is a part of Winix + * and is distributed under the 2-Clause BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2022, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "pgmodeler.h" +#include "html/htmlparser.h" +#include "misc.h" + + + +namespace Winix +{ + + +PGModeler::PGModeler() +{ +} + +PGModeler::~PGModeler() +{ +} + + + + +bool PGModeler::parse(const std::wstring & input_file, pt::Space & schema) +{ + schema.clear(); + pt::HTMLParser parser; + + pt::HTMLParser::Status status = parser.parse_xml_file(input_file, schema, true, true); + + if( status == pt::HTMLParser::Status::cant_open_file ) + { + print("cannot open the input file", input_file); + return false; + } + else + if( status == pt::HTMLParser::Status::syntax_error ) + { + print("syntax error", input_file, parser.get_last_parsed_line()); + schema.clear(); + return false; + } + else + { + parse(schema); + } + + return true; +} + + +bool PGModeler::parse(pt::Space & schema) +{ + std::string tmp; + +// schema.serialize_to_json_to(tmp, true); +// std::cout << tmp << std::endl; + + return true; +} + + +} + diff --git a/winixcli/src/pgmodeler.h b/winixcli/src/pgmodeler.h new file mode 100644 index 0000000..33edfd8 --- /dev/null +++ b/winixcli/src/pgmodeler.h @@ -0,0 +1,64 @@ +/* + * This file is a part of Winix + * and is distributed under the 2-Clause BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2022, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef headerfile_winixcli_src_pgmodeler +#define headerfile_winixcli_src_pgmodeler + +#include "space/space.h" + + +namespace Winix +{ + + +class PGModeler +{ +public: + + PGModeler(); + ~PGModeler(); + + bool parse(const std::wstring & input_file, pt::Space & schema); + + +private: + + bool parse(pt::Space & schema); + +}; + + +} + +#endif From 1d6d29e24d197e1721498496d54a7f28bb626dbc Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 18 Jan 2022 19:46:12 +0100 Subject: [PATCH 2/4] add winixcli/src/winix to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d011c30..57235b7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.o *.so winixd/winix +winixcli/src/winix From 944560dd2bdac8c5f467d37eaac048920eacf2ed Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 19 Jan 2022 15:47:11 +0100 Subject: [PATCH 3/4] update uikit to 3.10.1 --- winixd/html/index_head_adder.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winixd/html/index_head_adder.html b/winixd/html/index_head_adder.html index 3cc2bde..89c28af 100644 --- a/winixd/html/index_head_adder.html +++ b/winixd/html/index_head_adder.html @@ -9,7 +9,7 @@ [def? winix_set_viewport true] [def? winix_load_uikit true] -[def? winix_uikit_version "3.9.4"] [# "3.9.4-scope" ] +[def? winix_uikit_version "3.10.1"] [# "3.10.1-scope" ] [def? winix_load_htmx true] From b615dc7e6e41cd4cd2696592cb2f354bbd53f16f Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 22 Jan 2022 04:35:42 +0100 Subject: [PATCH 4/4] add cmp ezc function --- winixcli/src/main.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/winixcli/src/main.cpp b/winixcli/src/main.cpp index 16c17e7..5ea3384 100644 --- a/winixcli/src/main.cpp +++ b/winixcli/src/main.cpp @@ -115,8 +115,6 @@ void esc_tex(wchar_t c, pt::WTextStream & str) } - - void fil_tex(Ezc::FunInfo & env) { auto i = env.in.begin(); @@ -127,6 +125,22 @@ void fil_tex(Ezc::FunInfo & env) } } +void cmp(Ezc::FunInfo & env) +{ + if( env.params.size() >= 2 ) + { + env.res = true; + + for(size_t a=0 ; a < env.params.size() - 1 ; ++a) + { + if( env.params[a].str != env.params[a+1].str ) + { + env.res = false; + break; + } + } + } +} bool generate(const pt::Space & input_options, pt::Space & schema) @@ -161,6 +175,7 @@ bool generate(const pt::Space & input_options, pt::Space & schema) } functions.Insert("fil_tex", fil_tex); + functions.Insert("cmp", cmp); parser.Directory(dir); parser.SetBlocks(blocks);