# HG changeset patch # User František Kučera # Date 1558647352 -7200 # Node ID cf57e8c78492454e894d24ee87cb98735b246dcf # Parent 13a1e11347975b97ff31a72a2b8295192146047c add option: --debug-variable-mapping diff -r 13a1e1134797 -r cf57e8c78492 src/AwkHandler.h --- a/src/AwkHandler.h Wed May 22 19:26:10 2019 +0200 +++ b/src/AwkHandler.h Thu May 23 23:35:52 2019 +0200 @@ -226,6 +226,18 @@ closeOrThrow(awkOutputReaderFD); } + void debugVariableMapping(const string_t& relationName) { + relationalWriter->startRelation(relationName + L".variableMapping",{ + {L"attribute", writer::TypeId::STRING}, + {L"variable", writer::TypeId::STRING}, + }, true); + + for (std::pair m : currenVariablesMapping) { + relationalWriter->writeAttribute(m.first); + relationalWriter->writeAttribute(m.second); + } + } + public: /** @@ -370,6 +382,8 @@ // Writer child process closeOrThrow(awkInputWriterFD); + if (currentRelationConfiguration->debugVariableMapping) debugVariableMapping(name); + if (currentRelationConfiguration->drop) { // TODO: omit whole this process and pipe AWK output to /dev/null? } else { diff -r 13a1e1134797 -r cf57e8c78492 src/CLIParser.h --- a/src/CLIParser.h Wed May 22 19:26:10 2019 +0200 +++ b/src/CLIParser.h Thu May 23 23:35:52 2019 +0200 @@ -31,7 +31,7 @@ /** * This tr-awk CLI options are inspired by tr-guile options. - * These configurations are independent and might diverge, but when possible, the should share same option names and same logic for common parts. + * These configurations are independent and might diverge, but when possible, they should share same option names and same logic for common parts. */ class CLIParser { private: @@ -64,6 +64,7 @@ static const string_t OPTION_OUTPUT_ATTRIBUTE; static const string_t OPTION_INPUT_ATTRIBUTES_APPEND; static const string_t OPTION_INPUT_ATTRIBUTES_PREPEND; + static const string_t OPTION_DEBUG_VARIABLE_MAPPING; static const string_t OPTION_BEFORE_RECORDS; static const string_t OPTION_AFTER_RECORDS; static const string_t OPTION_FOR_EACH; @@ -83,6 +84,7 @@ else if (option == OPTION_DROP) currentRelation.drop = true; else if (option == OPTION_INPUT_ATTRIBUTES_APPEND) currentRelation.inputAttributesAppend = true; else if (option == OPTION_INPUT_ATTRIBUTES_PREPEND) currentRelation.inputAttributesPrepend = true; + else if (option == OPTION_DEBUG_VARIABLE_MAPPING) currentRelation.debugVariableMapping = true; else if (option == OPTION_RELATION) { addRelation(c, currentRelation); // previous relation currentRelation.relation = readNext(arguments, i); @@ -113,6 +115,7 @@ const string_t CLIParser::OPTION_OUTPUT_ATTRIBUTE = L"--output-attribute"; const string_t CLIParser::OPTION_INPUT_ATTRIBUTES_APPEND = L"--input-attributes-append"; const string_t CLIParser::OPTION_INPUT_ATTRIBUTES_PREPEND = L"--input-attributes-prepend"; +const string_t CLIParser::OPTION_DEBUG_VARIABLE_MAPPING = L"--debug-variable-mapping"; const string_t CLIParser::OPTION_BEFORE_RECORDS = L"--before-records"; const string_t CLIParser::OPTION_AFTER_RECORDS = L"--after-records"; const string_t CLIParser::OPTION_FOR_EACH = L"--for-each"; diff -r 13a1e1134797 -r cf57e8c78492 src/Configuration.h --- a/src/Configuration.h Wed May 22 19:26:10 2019 +0200 +++ b/src/Configuration.h Thu May 23 23:35:52 2019 +0200 @@ -47,6 +47,11 @@ relpipe::writer::string_t awkForEach; /** + * If true, additional relation will be generated: mapping between relpipe attribute names and AWK variable names + */ + bool debugVariableMapping = false; + + /** * If true, AWK code will be executed, but no output will be generated. */ bool drop = false;