Merge branch 'cli' into ajax

This commit is contained in:
Tomasz Sowa 2022-02-08 14:01:50 +01:00
commit 2033168db2
10 changed files with 631 additions and 1 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
*.o *.o
*.so *.so
winixd/winix winixd/winix
winixcli/src/winix

25
winixcli/Makefile Normal file
View File

@ -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:

58
winixcli/src/Makefile Normal file
View File

@ -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

View File

@ -0,0 +1,5 @@
# DO NOT DELETE
./main.o: pgmodeler.h misc.h
./pgmodeler.o: pgmodeler.h misc.h
./misc.o: misc.h

262
winixcli/src/main.cpp Normal file
View File

@ -0,0 +1,262 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* 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 <iostream>
#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<MyStream> & env)
{
auto i = env.in.begin();
for( ; i != env.in.end() ; ++i)
{
esc_tex(*i, env.out);
}
}
void cmp(Ezc::FunInfo<MyStream> & 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)
{
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<MyStream> 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);
functions.Insert("cmp", cmp);
parser.Directory(dir);
parser.SetBlocks(blocks);
parser.SetLogger(&log);
parser.ParseFile(template_file, pattern);
models.Add(L"schema", schema);
Ezc::Generator<MyStream, true, false> 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;
}

65
winixcli/src/misc.cpp Normal file
View File

@ -0,0 +1,65 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* 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 <iostream>
#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;
}
}

54
winixcli/src/misc.h Normal file
View File

@ -0,0 +1,54 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* 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

View File

@ -0,0 +1,96 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* 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;
}
}

64
winixcli/src/pgmodeler.h Normal file
View File

@ -0,0 +1,64 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* 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

View File

@ -9,7 +9,7 @@
[def? winix_set_viewport true] [def? winix_set_viewport true]
[def? winix_load_uikit 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] [def? winix_load_htmx true]