src/AwkHandler.h
branchv_0
changeset 12 8844ebce8fb4
parent 11 f515d14794e0
child 13 b74001992ec3
equal deleted inserted replaced
11:f515d14794e0 12:8844ebce8fb4
   149 			closeOrThrow(awkOutputReaderFD);
   149 			closeOrThrow(awkOutputReaderFD);
   150 
   150 
   151 			redirectFD(awkInputReaderFD, STDIN_FILENO);
   151 			redirectFD(awkInputReaderFD, STDIN_FILENO);
   152 			redirectFD(awkOutputWriterFD, STDOUT_FILENO);
   152 			redirectFD(awkOutputWriterFD, STDOUT_FILENO);
   153 
   153 
       
   154 			// AWK script:
   154 			std::wstringstream awkScript;
   155 			std::wstringstream awkScript;
   155 			awkScript << L"BEGIN {" << std::endl;
   156 			awkScript << L"BEGIN {" << std::endl;
   156 			awkScript << L"FS=\"\\t\";" << std::endl;
   157 			awkScript << L"FS=\"\\t\";" << std::endl;
   157 			awkScript << L"};" << std::endl;
   158 			awkScript << L"};" << std::endl;
   158 
   159 
   160 			// awkScript << … << std::endl;
   161 			// awkScript << … << std::endl;
   161 			awkScript << L"};" << std::endl;
   162 			awkScript << L"};" << std::endl;
   162 
   163 
   163 			awkScript << L"{print \"AWK says: line \" NR \" '\" $0 \"' has \" NF \" fields; first field is '\" $1 \"'\";}" << std::endl;
   164 			awkScript << L"{print \"AWK says: line \" NR \" '\" $0 \"' has \" NF \" fields; first field is '\" $1 \"'\";}" << std::endl;
   164 
   165 
       
   166 			// CLI arguments:
   165 			std::vector<std::string> args;
   167 			std::vector<std::string> args;
   166 			args.push_back("awk");
   168 			args.push_back("awk");
       
   169 
       
   170 			for (auto d : configuration.definitions) {
       
   171 				args.push_back("-v");
       
   172 				args.push_back(convertor.to_bytes(a2v(d.name) + L"=" + d.value));
       
   173 			}
   167 			args.push_back(convertor.to_bytes(awkScript.str()));
   174 			args.push_back(convertor.to_bytes(awkScript.str()));
   168 
   175 
   169 			// Runs AWK program found on $PATH → user can plug-in a custom implementation or a wrapper, but this can be also bit dangerous (however AWK itself is dangerous).
   176 			// Runs AWK program found on $PATH → user can plug-in a custom implementation or a wrapper, but this can be also bit dangerous (however AWK itself is dangerous).
   170 			execp(args);
   177 			execp(args);
   171 		} else {
   178 		} else {