record filtering in Guile v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 20 Jan 2019 01:23:34 +0100
branchv_0
changeset 2 7fb4d2c70e8c
parent 1 9179406ab3b3
child 3 d4d0e50f54da
record filtering in Guile try: relpipe-in-fstab | relpipe-tr-guile 'fstab' '(= pass 2)' | relpipe-out-tabular relpipe-in-fstab | relpipe-tr-guile 'fstab' '(equal? mount_point "/")' | relpipe-out-tabular
src/GuileHandler.h
--- a/src/GuileHandler.h	Sun Jan 20 01:02:40 2019 +0100
+++ b/src/GuileHandler.h	Sun Jan 20 01:23:34 2019 +0100
@@ -68,11 +68,11 @@
 	SCM toGuileString(const string_t& value) {
 		return scm_from_locale_string(convertor.to_bytes(value).c_str());
 	}
-	
+
 	SCM toGuileInteger(const string_t& value) {
 		return scm_from_uint64(stoul(value));
 	}
-	
+
 	SCM toGuileBoolean(const string_t& value) {
 		return value == L"true" ? SCM_BOOL_T : SCM_BOOL_F;
 	}
@@ -129,28 +129,13 @@
 
 	void attribute(const string_t& value) override {
 		if (filterCurrentRelation) {
-			// TODO: evaluate condition and updates in Guile
 			currentRecord[currentAttributeIndex] = value;
-			includeCurrentRecord = false;
-
-			// TODO: remove, just a demo code
-			defineGuileVariable(L"hello", TypeId::STRING, L"world");
-			defineGuileVariable(L"a", TypeId::INTEGER, L"123");
-			defineGuileVariable(L"b", TypeId::INTEGER, L"456");
-			defineGuileVariable(L"tr", TypeId::BOOLEAN, L"true");
-			defineGuileVariable(L"fa", TypeId::BOOLEAN, L"false");
-
-			//integer_t guileResult = scm_to_uint64(scm_eval_string(toGuileString(guileCode)));
-			//std::wcerr << "result from Guile: " << guileResult << std::endl;
-			
-			includeCurrentRecord = scm_to_bool(scm_eval_string(toGuileString(guileCode)));
-			//scm_shell(0, nullptr);
-			// --------
-			
-
+			defineGuileVariable(currentMetadata[currentAttributeIndex].getAttributeName(), currentMetadata[currentAttributeIndex].getTypeId(), value);
 			currentAttributeIndex++;
 
 			if (currentAttributeIndex > 0 && currentAttributeIndex % currentMetadata.size() == 0) {
+				// TODO: support also updates in Guile
+				includeCurrentRecord = scm_to_bool(scm_eval_string(toGuileString(guileCode)));
 				if (includeCurrentRecord) for (string_t v : currentRecord) relationalWriter->writeAttribute(v);
 				includeCurrentRecord = false;
 			}