(winixcli): add a --sort-tables option

while here:
- add a fil_max_size filter for putting a space if the inner stream is greater than x characters
This commit is contained in:
Tomasz Sowa 2023-11-09 10:57:11 +01:00
parent a54d70bed4
commit d1f5d9aa88
Signed by: tomasz.sowa
GPG Key ID: 662CC1438638588B
6 changed files with 124 additions and 26 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
*.so *.so
winixd/winix winixd/winix
winixcli/src/winix winixcli/src/winix
winixcli/m
.clangd .clangd
.qtc_clangd/ .qtc_clangd/
winix.cflags winix.cflags

View File

@ -12,9 +12,17 @@ ifndef CXX
CXX = g++ CXX = g++
endif endif
ifndef ADDITIONAL_CXXFLAGS
ADDITIONAL_CXXFLAGS=-O2
endif
ifndef ADDITIONAL_LDFLAGS
ADDITIONAL_LDFLAGS=-s
endif
ifndef CXXFLAGS ifndef CXXFLAGS
# /usr/include/postgresql is in Linux distros (Alpine) # /usr/include/postgresql is in Linux distros (Alpine)
CXXFLAGS = -Wall -pedantic -O2 -std=c++20 \ CXXFLAGS = -Wall -pedantic -std=c++20 $(ADDITIONAL_CXXFLAGS) \
-I/usr/local/include \ -I/usr/local/include \
-I/usr/include/postgresql \ -I/usr/include/postgresql \
-I$(GLOBAL_WORKING_DIR)/winix/winixcli \ -I$(GLOBAL_WORKING_DIR)/winix/winixcli \
@ -25,15 +33,13 @@ CXXFLAGS = -Wall -pedantic -O2 -std=c++20 \
$(WINIX_NEEDED_MACROS) $(WINIX_NEEDED_MACROS)
endif endif
LDFLAGS = -L/usr/local/lib $(ADDITIONAL_LDFLAGS)
ifndef LDFLAGS
LDFLAGS = -L/usr/local/lib -s
endif
export CXX export CXX
export CXXFLAGS export CXXFLAGS
export LDFLAGS export LDFLAGS
export GLOBAL_WORKING_DIR
export WINIX_NEEDED_MACROS export WINIX_NEEDED_MACROS

View File

@ -1,13 +1,15 @@
# DO NOT DELETE # DO NOT DELETE
./main.o: ../../../pikotools/src/mainoptions/mainoptionsparser.h ./main.o: ../../../pikotools/src/convert/strtoint.h
./main.o: ../../../pikotools/src/convert/text.h misc.h
./main.o: ../../../pikotools/src/space/space.h ./main.o: ../../../pikotools/src/space/space.h
./main.o: ../../../pikotools/src/textstream/types.h ./main.o: ../../../pikotools/src/textstream/types.h
./main.o: ../../../pikotools/src/convert/inttostr.h ./main.o: ../../../pikotools/src/convert/inttostr.h
./main.o: ../../../pikotools/src/utf8/utf8.h ./main.o: ../../../pikotools/src/utf8/utf8.h
./main.o: ../../../pikotools/src/textstream/stream.h ./main.o: ../../../pikotools/src/textstream/stream.h
./main.o: ../../../pikotools/src/utf8/utf8_templates.h ./main.o: ../../../pikotools/src/utf8/utf8_templates.h
./main.o: ../../../pikotools/src/utf8/utf8_private.h pgmodeler.h misc.h ./main.o: ../../../pikotools/src/utf8/utf8_private.h
./main.o: ../../../pikotools/src/mainoptions/mainoptionsparser.h pgmodeler.h
./main.o: ../../../ezc/src/ezc.h ../../../ezc/src/version.h ./main.o: ../../../ezc/src/ezc.h ../../../ezc/src/version.h
./main.o: ../../../ezc/src/generator.h ../../../ezc/src/blocks.h ./main.o: ../../../ezc/src/generator.h ../../../ezc/src/blocks.h
./main.o: ../../../ezc/src/item.h ../../../ezc/src/cache.h ./main.o: ../../../ezc/src/item.h ../../../ezc/src/cache.h
@ -28,10 +30,10 @@
./main.o: ../../../morm/src/modelconnector.h ../../../morm/src/clearer.h ./main.o: ../../../morm/src/modelconnector.h ../../../morm/src/clearer.h
./main.o: ../../../morm/src/ft.h ../../../morm/src/dbconnector.h ./main.o: ../../../morm/src/ft.h ../../../morm/src/dbconnector.h
./main.o: ../../../morm/src/queryresult.h ../../../morm/src/flatconnector.h ./main.o: ../../../morm/src/queryresult.h ../../../morm/src/flatconnector.h
./main.o: ../../../morm/src/dbexpression.h ../../../morm/src/baseexpression.h ./main.o: ../../../morm/src/export.h ../../../morm/src/dbexpression.h
./main.o: ../../../morm/src/morm_types.h ../../../morm/src/modelenv.h ./main.o: ../../../morm/src/baseexpression.h ../../../morm/src/morm_types.h
./main.o: ../../../morm/src/modeldata.h ../../../morm/src/cursorhelper.h ./main.o: ../../../morm/src/modelenv.h ../../../morm/src/modeldata.h
./main.o: ../../../morm/src/finderhelper.h ./main.o: ../../../morm/src/cursorhelper.h ../../../morm/src/finderhelper.h
./main.o: ../../../morm/src/fieldvaluehelper.h ../../../morm/src/select.h ./main.o: ../../../morm/src/fieldvaluehelper.h ../../../morm/src/select.h
./main.o: ../../../pikotools/src/convert/text.h ./main.o: ../../../pikotools/src/convert/text.h
./main.o: ../../../morm/src/flatexpression.h ../../../ezc/src/patternparser.h ./main.o: ../../../morm/src/flatexpression.h ../../../ezc/src/patternparser.h

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2022, Tomasz Sowa * Copyright (c) 2022-2023, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -33,6 +33,7 @@
*/ */
#include <iostream> #include <iostream>
#include "convert/strtoint.h"
#include "mainoptions/mainoptionsparser.h" #include "mainoptions/mainoptionsparser.h"
#include "pgmodeler.h" #include "pgmodeler.h"
#include "misc.h" #include "misc.h"
@ -60,10 +61,10 @@ std::wstring get_param(const pt::Space::TableType * input_mode)
} }
bool use_pgmodeler(const std::wstring & input_file, const pt::Space & input_options, pt::Space & schema) bool use_pgmodeler(const std::wstring & input_file, const pt::Space & input_options, pt::Space & schema, bool sort_tables)
{ {
PGModeler pgmodeler; PGModeler pgmodeler;
return pgmodeler.parse(input_file, schema); return pgmodeler.parse(input_file, schema, sort_tables);
} }
@ -125,6 +126,35 @@ void fil_tex(Ezc::FunInfo<MyStream> & env)
} }
} }
void fil_max_size(Ezc::FunInfo<MyStream> & env)
{
auto i = env.in.begin();
size_t max_len = pt::to_ul(env.par);
size_t len = 0;
for( ; i != env.in.end() ; ++i)
{
if( len >= max_len )
{
env.out << ' ';
len = 0;
}
if( pt::is_white(*i) )
{
len = 0;
}
else
{
len += 1;
}
env.out << *i;
}
}
void cmp(Ezc::FunInfo<MyStream> & env) void cmp(Ezc::FunInfo<MyStream> & env)
{ {
if( env.params.size() >= 2 ) if( env.params.size() >= 2 )
@ -176,6 +206,7 @@ bool generate(const pt::Space & input_options, pt::Space & schema)
functions.Insert("fil_tex", fil_tex); functions.Insert("fil_tex", fil_tex);
functions.Insert("cmp", cmp); functions.Insert("cmp", cmp);
functions.Insert("fil_max_size", fil_max_size);
parser.Directory(dir); parser.Directory(dir);
parser.SetBlocks(blocks); parser.SetBlocks(blocks);
@ -237,9 +268,11 @@ int main(int argc, const char ** argv)
print("input-mode", input_mode); print("input-mode", input_mode);
print("input-file", input_file); print("input-file", input_file);
bool sort_tables = input_options.has_key(L"sort-tables");
if( input_mode == L"pgmodeler" ) if( input_mode == L"pgmodeler" )
{ {
if( !use_pgmodeler(input_file, input_options, schema) ) if( !use_pgmodeler(input_file, input_options, schema, sort_tables) )
return 3; return 3;
} }
else else

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2022, Tomasz Sowa * Copyright (c) 2022-2023, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -53,7 +53,7 @@ PGModeler::~PGModeler()
bool PGModeler::parse(const std::wstring & input_file, pt::Space & schema) bool PGModeler::parse(const std::wstring & input_file, pt::Space & schema, bool sort_tables)
{ {
schema.clear(); schema.clear();
pt::HTMLParser parser; pt::HTMLParser parser;
@ -74,23 +74,77 @@ bool PGModeler::parse(const std::wstring & input_file, pt::Space & schema)
} }
else else
{ {
parse(schema); if( sort_tables )
make_sort_tables(schema);
} }
return true; return true;
} }
bool PGModeler::parse(pt::Space & schema)
std::pair<const std::wstring*, const std::wstring*> PGModeler::get_schema_table_names(const pt::Space & table)
{ {
std::string tmp; const pt::Space * schema = table.get_space(L"schema");
const std::wstring * schema_name = nullptr;
const std::wstring * table_name = nullptr;
// schema.serialize_to_json_to(tmp, true); if( schema )
// std::cout << tmp << std::endl; {
const pt::Space * attr = schema->get_space(L"attr");
return true; if( attr )
{
schema_name = attr->get_wstr(L"name");
}
}
const pt::Space * attr = table.get_space(L"attr");
if( attr )
{
table_name = attr->get_wstr(L"name");
}
return std::make_pair(schema_name, table_name);
} }
void PGModeler::make_sort_tables(pt::Space & schema)
{
pt::Space * dbmodel = schema.get_space(L"dbmodel");
if( dbmodel )
{
pt::Space::TableType * table = dbmodel->get_table(L"table");
if( table )
{
std::sort(table->begin(), table->end(), [](const pt::Space * t1, const pt::Space * t2) -> bool {
auto t1_names = get_schema_table_names(*t1);
auto t2_names = get_schema_table_names(*t2);
if( t1_names.first && t2_names.second && t2_names.first && t2_names.second )
{
if( *t1_names.first != *t2_names.first )
{
return *t1_names.first < *t2_names.first;
}
else
{
return *t1_names.second < *t2_names.second;
}
}
else
{
return false;
}
});
}
}
}
} }

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2022, Tomasz Sowa * Copyright (c) 2022-2023, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -49,12 +49,14 @@ public:
PGModeler(); PGModeler();
~PGModeler(); ~PGModeler();
bool parse(const std::wstring & input_file, pt::Space & schema); bool parse(const std::wstring & input_file, pt::Space & schema, bool sort_tables);
private: private:
bool parse(pt::Space & schema); void make_sort_tables(pt::Space & schema);
static std::pair<const std::wstring *, const std::wstring *> get_schema_table_names(const pt::Space & table);
}; };