src/AwkHandler.h
branchv_0
changeset 19 e4558df9ba2d
parent 18 2ac59242d0cb
child 20 f937ad57351f
equal deleted inserted replaced
18:2ac59242d0cb 19:e4558df9ba2d
   139 		}
   139 		}
   140 
   140 
   141 		currentAttributeIndex = 0;
   141 		currentAttributeIndex = 0;
   142 		currentReaderMetadata.clear();
   142 		currentReaderMetadata.clear();
   143 		currentWriterMetadata.clear();
   143 		currentWriterMetadata.clear();
       
   144 		currentRelationConfiguration = nullptr;
   144 	}
   145 	}
   145 
   146 
   146 	string_t a2v(const string_t& attributeName) {
   147 	string_t a2v(const string_t& attributeName) {
   147 		// FIXME: escape reserved names; prefix with _ ?
   148 		// FIXME: escape reserved names; prefix with _ ?
   148 		// cat awkgram.y | awk -v FS='\\{"|",' -v ORS='|' '/static const struct token tokentab/, /\};/ { if (/^\{/) { print $2} }'
   149 		// cat awkgram.y | awk -v FS='\\{"|",' -v ORS='|' '/static const struct token tokentab/, /\};/ { if (/^\{/) { print $2} }'
   172 	void startRelation(string_t name, vector<AttributeMetadata> attributes) override {
   173 	void startRelation(string_t name, vector<AttributeMetadata> attributes) override {
   173 		cleanUp();
   174 		cleanUp();
   174 
   175 
   175 		currentReaderMetadata = attributes;
   176 		currentReaderMetadata = attributes;
   176 
   177 
   177 		currentRelationConfiguration = nullptr;
       
   178 		for (int i = 0; i < configuration.relationConfigurations.size(); i++) {
   178 		for (int i = 0; i < configuration.relationConfigurations.size(); i++) {
   179 			if (regex_match(name, wregex(configuration.relationConfigurations[i].relation))) {
   179 			if (regex_match(name, wregex(configuration.relationConfigurations[i].relation))) {
   180 				currentRelationConfiguration = &configuration.relationConfigurations[i];
   180 				currentRelationConfiguration = &configuration.relationConfigurations[i];
   181 				break; // it there are multiple matches, only the first configuration is used
   181 				break; // it there are multiple matches, only the first configuration is used
   182 			}
   182 			}
   260 					locale::global(locale("")); // needed for processing unicode texts, otherwise getline() stopped working on first line with non-ascii characters; TODO: move somewhere else?
   260 					locale::global(locale("")); // needed for processing unicode texts, otherwise getline() stopped working on first line with non-ascii characters; TODO: move somewhere else?
   261 
   261 
   262 					__gnu_cxx::stdio_filebuf<wchar_t> awkOutputReaderBuffer(awkOutputReaderFD, std::ios::in);
   262 					__gnu_cxx::stdio_filebuf<wchar_t> awkOutputReaderBuffer(awkOutputReaderFD, std::ios::in);
   263 					std::wistream awkOutputReader(&awkOutputReaderBuffer);
   263 					std::wistream awkOutputReader(&awkOutputReaderBuffer);
   264 
   264 
   265 					// FIXME: currentWriterMetadata
   265 					if (currentRelationConfiguration->drop) {
   266 					relationalWriter->startRelation(name,{
   266 						// TODO: omit whole this process and pipe AWK output to /dev/null?
   267 						{L"message", writer::TypeId::STRING},
   267 					} else {
   268 					}, true);
   268 						// FIXME: currentWriterMetadata
       
   269 						relationalWriter->startRelation(name,{
       
   270 							{L"message", writer::TypeId::STRING},
       
   271 						}, true);
       
   272 					}
   269 
   273 
   270 					for (string_t line; getline(awkOutputReader, line).good();) {
   274 					for (string_t line; getline(awkOutputReader, line).good();) {
   271 						relationalWriter->writeAttribute(line);
   275 						if (currentRelationConfiguration->drop) {
       
   276 							// just eat the lines from the AWK
       
   277 						} else {
       
   278 							relationalWriter->writeAttribute(line);
       
   279 						}
   272 					}
   280 					}
   273 
   281 
   274 					closeOrThrow(awkOutputReaderFD);
   282 					closeOrThrow(awkOutputReaderFD);
   275 					exit(0);
   283 					exit(0);
   276 				} else {
   284 				} else {