diff -r 000000000000 -r 8615122f8c02 src/ENVCommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ENVCommand.h Sun Apr 24 00:39:48 2022 +0200 @@ -0,0 +1,57 @@ +/** + * Relational pipes + * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include +#include + +extern char** environ; + +namespace relpipe { +namespace in { +namespace env { + +class ENVCommand { +private: + + std::wstring_convert> convertor; // TODO: support also other encodings and use platform encoding as default + +public: + + void process(std::shared_ptr writer) { + writer->startRelation(L"env",{ + {L"name", relpipe::writer::TypeId::STRING}, + {L"value", relpipe::writer::TypeId::STRING}, + }, true); + + for (char** e = environ; *e; e++) { + std::string entry = *e; + + size_t split = entry.find("="); + std::string name = entry.substr(0, split); + std::string value = entry.substr(split + 1); + + writer->writeAttribute(convertor.from_bytes(name)); + writer->writeAttribute(convertor.from_bytes(value)); + } + } +}; + +} +} +}