From 3ce0ea8fd8b6b02acc5828cbc90f113a3cf33207 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 31 May 2003 21:47:16 +0000 Subject: [PATCH] Add support for: -o - git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6485 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/as/as.cpp | 18 +++++++++++------- tools/dis/dis.cpp | 16 +++++++++------- tools/llvm-as/as.cpp | 18 +++++++++++------- tools/llvm-as/llvm-as.cpp | 18 +++++++++++------- tools/llvm-dis/dis.cpp | 16 +++++++++------- tools/llvm-dis/llvm-dis.cpp | 16 +++++++++------- 6 files changed, 60 insertions(+), 42 deletions(-) diff --git a/tools/as/as.cpp b/tools/as/as.cpp index d1f7406dff3..58605420200 100644 --- a/tools/as/as.cpp +++ b/tools/as/as.cpp @@ -53,14 +53,18 @@ int main(int argc, char **argv) { if (DumpAsm) std::cerr << "Here's the assembly:\n" << M.get(); if (OutputFilename != "") { // Specified an output filename? - if (!Force && std::ifstream(OutputFilename.c_str())) { - // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename - << "': file exists!\n" - << "Use -f command line argument to force output\n"; - return 1; + if (OutputFilename != "-") { // Not stdout? + if (!Force && std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + std::cerr << argv[0] << ": error opening '" << OutputFilename + << "': file exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); + } else { // Specified stdout + Out = &std::cout; } - Out = new std::ofstream(OutputFilename.c_str()); } else { if (InputFilename == "-") { OutputFilename = "-"; diff --git a/tools/dis/dis.cpp b/tools/dis/dis.cpp index b52354e7127..bf46fe62e3f 100644 --- a/tools/dis/dis.cpp +++ b/tools/dis/dis.cpp @@ -31,7 +31,7 @@ static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); static cl::opt -OutputFilename("o", cl::desc("Override output filename"), +OutputFilename("o", cl::desc("Override output filename"), cl::value_desc("filename")); static cl::opt @@ -60,12 +60,14 @@ int main(int argc, char **argv) { } if (OutputFilename != "") { // Specified an output filename? - if (!Force && std::ifstream(OutputFilename.c_str())) { - // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename - << "': file exists! Sending to standard output.\n"; - } else { - Out = new std::ofstream(OutputFilename.c_str()); + if (OutputFilename != "-") { // Not stdout? + if (!Force && std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + std::cerr << argv[0] << ": error opening '" << OutputFilename + << "': file exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } } else { if (InputFilename == "-") { diff --git a/tools/llvm-as/as.cpp b/tools/llvm-as/as.cpp index d1f7406dff3..58605420200 100644 --- a/tools/llvm-as/as.cpp +++ b/tools/llvm-as/as.cpp @@ -53,14 +53,18 @@ int main(int argc, char **argv) { if (DumpAsm) std::cerr << "Here's the assembly:\n" << M.get(); if (OutputFilename != "") { // Specified an output filename? - if (!Force && std::ifstream(OutputFilename.c_str())) { - // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename - << "': file exists!\n" - << "Use -f command line argument to force output\n"; - return 1; + if (OutputFilename != "-") { // Not stdout? + if (!Force && std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + std::cerr << argv[0] << ": error opening '" << OutputFilename + << "': file exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); + } else { // Specified stdout + Out = &std::cout; } - Out = new std::ofstream(OutputFilename.c_str()); } else { if (InputFilename == "-") { OutputFilename = "-"; diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index d1f7406dff3..58605420200 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -53,14 +53,18 @@ int main(int argc, char **argv) { if (DumpAsm) std::cerr << "Here's the assembly:\n" << M.get(); if (OutputFilename != "") { // Specified an output filename? - if (!Force && std::ifstream(OutputFilename.c_str())) { - // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename - << "': file exists!\n" - << "Use -f command line argument to force output\n"; - return 1; + if (OutputFilename != "-") { // Not stdout? + if (!Force && std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + std::cerr << argv[0] << ": error opening '" << OutputFilename + << "': file exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); + } else { // Specified stdout + Out = &std::cout; } - Out = new std::ofstream(OutputFilename.c_str()); } else { if (InputFilename == "-") { OutputFilename = "-"; diff --git a/tools/llvm-dis/dis.cpp b/tools/llvm-dis/dis.cpp index b52354e7127..bf46fe62e3f 100644 --- a/tools/llvm-dis/dis.cpp +++ b/tools/llvm-dis/dis.cpp @@ -31,7 +31,7 @@ static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); static cl::opt -OutputFilename("o", cl::desc("Override output filename"), +OutputFilename("o", cl::desc("Override output filename"), cl::value_desc("filename")); static cl::opt @@ -60,12 +60,14 @@ int main(int argc, char **argv) { } if (OutputFilename != "") { // Specified an output filename? - if (!Force && std::ifstream(OutputFilename.c_str())) { - // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename - << "': file exists! Sending to standard output.\n"; - } else { - Out = new std::ofstream(OutputFilename.c_str()); + if (OutputFilename != "-") { // Not stdout? + if (!Force && std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + std::cerr << argv[0] << ": error opening '" << OutputFilename + << "': file exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } } else { if (InputFilename == "-") { diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index b52354e7127..bf46fe62e3f 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -31,7 +31,7 @@ static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); static cl::opt -OutputFilename("o", cl::desc("Override output filename"), +OutputFilename("o", cl::desc("Override output filename"), cl::value_desc("filename")); static cl::opt @@ -60,12 +60,14 @@ int main(int argc, char **argv) { } if (OutputFilename != "") { // Specified an output filename? - if (!Force && std::ifstream(OutputFilename.c_str())) { - // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename - << "': file exists! Sending to standard output.\n"; - } else { - Out = new std::ofstream(OutputFilename.c_str()); + if (OutputFilename != "-") { // Not stdout? + if (!Force && std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + std::cerr << argv[0] << ": error opening '" << OutputFilename + << "': file exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } } else { if (InputFilename == "-") { -- 2.34.1