From adf0dace0f8312ae49a5262601f61d1d77ccafbc Mon Sep 17 00:00:00 2001 From: spencer-lunarg Date: Sun, 3 Nov 2024 04:21:13 -0500 Subject: [PATCH] Add redirect for stdout to a file --- main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.cpp b/main.cpp index 52e7548..029be1d 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,7 @@ */ #include +#include #if defined(WIN32) #define _CRTDBG_MAP_ALLOC #include @@ -40,6 +41,7 @@ void PrintUsage() { << std::endl << "Options:" << std::endl << " --help Display this message" << std::endl + << " -o,--output Print output to file. [default: stdout]" << std::endl << " -y,--yaml Format output as YAML. [default: disabled]" << std::endl << " -v VERBOSITY Specify output verbosity (YAML output " "only):" @@ -80,6 +82,7 @@ void PrintUsage() { int main(int argn, char** argv) { ArgParser arg_parser; arg_parser.AddFlag("h", "help", ""); + arg_parser.AddOptionString("o", "output", ""); arg_parser.AddFlag("y", "yaml", ""); arg_parser.AddOptionInt("v", "verbosity", "", 0); arg_parser.AddFlag("e", "entrypoint", ""); @@ -97,6 +100,10 @@ int main(int argn, char** argv) { return EXIT_SUCCESS; } + std::string output_file; + arg_parser.GetString("o", "output", &output_file); + FILE* output_fp = output_file.empty() ? NULL : freopen(output_file.c_str(), "w", stdout); + bool output_as_yaml = arg_parser.GetFlag("y", "yaml"); int yaml_verbosity = 0; @@ -189,5 +196,8 @@ int main(int argn, char** argv) { } } + if (output_fp) { + fclose(output_fp); + } return EXIT_SUCCESS; }