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
--- 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;
}