mirror of
				https://github.com/davidgiven/fluxengine.git
				synced 2025-10-24 11:11:02 -07:00 
			
		
		
		
	Copy documentation into the config definitions.
This commit is contained in:
		| @@ -2,12 +2,72 @@ | ||||
| #include <google/protobuf/text_format.h> | ||||
| #include <google/protobuf/io/zero_copy_stream_impl.h> | ||||
| #include <fstream> | ||||
| #include "fmt/format.h" | ||||
| #include <fmt/format.h> | ||||
| #include "tests/testproto.pb.h" | ||||
| #include "lib/config.pb.h" | ||||
| #include <sstream> | ||||
| #include <locale> | ||||
|  | ||||
| #define STRINGIFY(s) #s | ||||
|  | ||||
| static uint32_t readu8(std::string::iterator& it, std::string::iterator end) | ||||
| { | ||||
| 	int len; | ||||
|     uint32_t c = *it++; | ||||
|     if (c < 0x80) | ||||
|     { | ||||
|         /* Do nothing! */ | ||||
| 		len = 0; | ||||
|     } | ||||
|     else if (c < 0xc0) | ||||
|     { | ||||
|         /* Invalid character */ | ||||
|         c = -1; | ||||
| 		len = 0; | ||||
|     } | ||||
|     else if (c < 0xe0) | ||||
|     { | ||||
|         /* One trailing byte */ | ||||
|         c &= 0x1f; | ||||
| 		len = 1; | ||||
|     } | ||||
|     else if (c < 0xf0) | ||||
|     { | ||||
|         /* Two trailing bytes */ | ||||
|         c &= 0x0f; | ||||
| 		len = 2; | ||||
|     } | ||||
|     else if (c < 0xf8) | ||||
|     { | ||||
|         /* Three trailing bytes */ | ||||
|         c &= 0x07; | ||||
| 		len = 3; | ||||
|     } | ||||
|     else if (c < 0xfc) | ||||
|     { | ||||
|         /* Four trailing bytes */ | ||||
|         c &= 0x03; | ||||
| 		len = 4; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         /* Five trailing bytes */ | ||||
|         c &= 0x01; | ||||
| 		len = 5; | ||||
|     } | ||||
|  | ||||
| 	while (len) | ||||
| 	{ | ||||
| 		if (it == end) | ||||
| 			break; | ||||
|  | ||||
| 		uint8_t d = *it++; | ||||
| 		c <<= 6; | ||||
| 		c += d & 0x3f; | ||||
| 	} | ||||
|     return c; | ||||
| } | ||||
|  | ||||
| int main(int argc, const char* argv[]) | ||||
| { | ||||
| 	PROTO message; | ||||
| @@ -19,10 +79,37 @@ int main(int argc, const char* argv[]) | ||||
| 		exit(1); | ||||
| 	} | ||||
|  | ||||
|     google::protobuf::io::IstreamInputStream istream(&input); | ||||
|     if (!google::protobuf::TextFormat::Parse(&istream, &message)) | ||||
| 	std::stringstream ss; | ||||
| 	std::string s; | ||||
| 	while (std::getline(input, s, '\n')) | ||||
| 	{ | ||||
| 		if (s == "<<<") | ||||
| 		{ | ||||
| 			while (std::getline(input, s, '\n')) | ||||
| 			{ | ||||
| 				if (s == ">>>") | ||||
| 					break; | ||||
|  | ||||
| 				ss << '"'; | ||||
| 				auto it = s.begin(); | ||||
| 				for (;;) | ||||
| 				{ | ||||
| 					uint32_t u = readu8(it, s.end()); | ||||
| 					if (!u) | ||||
| 						break; | ||||
|  | ||||
| 					ss << fmt::format("\\u000{:02x}", u); | ||||
| 				} | ||||
| 				ss << "\\n\"\n"; | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 			ss << s << '\n'; | ||||
| 	} | ||||
|  | ||||
|     if (!google::protobuf::TextFormat::ParseFromString(ss.str(), &message)) | ||||
|     { | ||||
|         fprintf(stderr, "cannot parse text proto"); | ||||
|         fprintf(stderr, "cannot parse text proto: %s\n", argv[1]); | ||||
|         exit(1); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user