use strict;

my $ns  = shift @ARGV;
my $var = shift @ARGV;
my $out = shift @ARGV;
my $cmd = "$ENV{cxx} -std=c++17 -x c++ -c -o $out -";

open OUT, "|$cmd" or die "error starting $cmd";

print OUT "#include <string_view>\n#include <string>\n";
print OUT "namespace divine::str::${ns}\n{\n";
print OUT "extern const std::string_view str_" . s,[/+. -],_,gr . ";\n" for ( @ARGV );
print OUT "}\n\n";
print OUT "namespace divine::str\n{\n";
print OUT "struct stringtable { std::string n; std::string_view c; };\n";
print OUT "stringtable ${var}"."[] = { \n";
print OUT "  { \"$_\", ${ns}::str_" . s,[/+. -],_,gr . " },\n" for ( @ARGV );
print OUT '  { "", "" }' . "\n};\n";
print OUT "}\n";

close OUT or die "error running $cmd: $!";
