add option: --debug-variable-mapping v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 23 May 2019 23:35:52 +0200
branchv_0
changeset 26 cf57e8c78492
parent 25 13a1e1134797
child 27 86d8bbc99e7b
add option: --debug-variable-mapping
src/AwkHandler.h
src/CLIParser.h
src/Configuration.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<string_t, string_t> 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 {
--- 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";
--- 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;