322 awkScript << std::endl; |
322 awkScript << std::endl; |
323 |
323 |
324 awkScript << L"END {" << std::endl; |
324 awkScript << L"END {" << std::endl; |
325 awkScript << currentRelationConfiguration->awkAfterRecords << std::endl; |
325 awkScript << currentRelationConfiguration->awkAfterRecords << std::endl; |
326 awkScript << L"};" << std::endl; |
326 awkScript << L"};" << std::endl; |
327 awkScript << std::endl; |
327 |
328 |
328 awkScript << LR"AWK( |
329 awkScript << L"function _escape(value) {" << std::endl; |
329 function _escape(value, i) { |
330 // FIXME: escape function |
330 result = ""; |
331 awkScript << L"return value;" << std::endl; |
331 split(value, chars, ""); |
332 awkScript << L"};" << std::endl; |
332 for (i = 1; i <= length(chars); i++) { |
333 awkScript << std::endl; |
333 ch = chars[i]; |
334 |
334 if (ch == "\\") { ch = "\\\\"; } |
335 awkScript << L"function _unescape(value) {" << std::endl; |
335 else if (ch == "\t") { ch = "\\t"; } |
336 // FIXME: unescape function |
336 else if (ch == "\n") { ch = "\\n"; } |
337 awkScript << L"return value;" << std::endl; |
337 result = result ch; |
338 awkScript << L"};" << std::endl; |
338 } |
|
339 return result; |
|
340 }; |
|
341 |
|
342 function _unescape(value, i) { |
|
343 result = ""; |
|
344 split(value, chars, ""); |
|
345 for (i = 1; i <= length(chars); i++) { |
|
346 ch = chars[i]; |
|
347 if (ch == "\\") { |
|
348 ch = chars[++i]; |
|
349 if (ch == "\\") { ch = "\\"; } |
|
350 else if (ch == "t") { ch = "\t"; } |
|
351 else if (ch == "n") { ch = "\n"; } |
|
352 else { |
|
353 printf("Unsupported escape sequence: %s\n", ch) > "/dev/stderr"; |
|
354 exit 70; |
|
355 } |
|
356 } |
|
357 result = result ch; |
|
358 } |
|
359 return result; |
|
360 }; |
|
361 )AWK"; |
|
362 |
339 awkScript << std::endl; |
363 awkScript << std::endl; |
340 |
364 |
341 awkScript << L"function _readVariables() {" << std::endl; |
365 awkScript << L"function _readVariables() {" << std::endl; |
342 for (int i = 0; i < currentReaderMetadata.size(); i++) awkScript << a2v(currentReaderMetadata[i].getAttributeName()) << L"=_unescape($" << (i + 1) << L");" << std::endl; |
366 for (int i = 0; i < currentReaderMetadata.size(); i++) awkScript << a2v(currentReaderMetadata[i].getAttributeName()) << L"=_unescape($" << (i + 1) << L");" << std::endl; |
343 awkScript << L"};" << std::endl; |
367 awkScript << L"};" << std::endl; |