(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:
2023-11-09 10:57:11 +01:00
parent a54d70bed4
commit d1f5d9aa88
6 changed files with 124 additions and 26 deletions
+37 -4
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2022, Tomasz Sowa
* Copyright (c) 2022-2023, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,6 +33,7 @@
*/
#include <iostream>
#include "convert/strtoint.h"
#include "mainoptions/mainoptionsparser.h"
#include "pgmodeler.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;
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)
{
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("cmp", cmp);
functions.Insert("fil_max_size", fil_max_size);
parser.Directory(dir);
parser.SetBlocks(blocks);
@@ -237,9 +268,11 @@ int main(int argc, const char ** argv)
print("input-mode", input_mode);
print("input-file", input_file);
bool sort_tables = input_options.has_key(L"sort-tables");
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;
}
else