summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2023-11-02 14:55:30 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2023-11-03 13:03:25 (GMT)
commitab7284679428197cc5d0e891db6f2ee1d00a6c6d (patch)
tree2adb2903e5ddd6a0c7db2511234398acf3e64c66 /Source/cmcmd.cxx
parent0f02655bb01346cab483761bd75fa8dc6cbfe7f1 (diff)
downloadCMake-ab7284679428197cc5d0e891db6f2ee1d00a6c6d.zip
CMake-ab7284679428197cc5d0e891db6f2ee1d00a6c6d.tar.gz
CMake-ab7284679428197cc5d0e891db6f2ee1d00a6c6d.tar.bz2
cmake -E cat: Add ability to print standard input
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx18
1 files changed, 14 insertions, 4 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 43a945f..93b0086 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -203,11 +203,16 @@ bool cmTarFilesFrom(std::string const& file, std::vector<std::string>& files)
void cmCatFile(const std::string& fileToAppend)
{
#ifdef _WIN32
+ _setmode(fileno(stdin), _O_BINARY);
_setmode(fileno(stdout), _O_BINARY);
#endif
- cmsys::ifstream source(fileToAppend.c_str(),
- (std::ios::binary | std::ios::in));
- std::cout << source.rdbuf();
+ std::streambuf* buf = std::cin.rdbuf();
+ cmsys::ifstream source;
+ if (fileToAppend != "-") {
+ source.open(fileToAppend.c_str(), (std::ios::binary | std::ios::in));
+ buf = source.rdbuf();
+ }
+ std::cout << buf;
}
bool cmRemoveDirectory(const std::string& dir, bool recursive = true)
@@ -1147,7 +1152,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
int return_value = 0;
bool doing_options = true;
for (auto const& arg : cmMakeRange(args).advance(2)) {
- if (doing_options && cmHasLiteralPrefix(arg, "-")) {
+ if (arg == "-") {
+ doing_options = false;
+ // Destroy console buffers to drop cout/cerr encoding transform.
+ consoleBuf.reset();
+ cmCatFile(arg);
+ } else if (doing_options && cmHasLiteralPrefix(arg, "-")) {
if (arg == "--") {
doing_options = false;
} else {