Fix PR743: emit -help output of a tool to cout, not cerr.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28010 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-04-28 05:36:25 +00:00
parent 020c41f21e
commit a0de843535

View File

@ -690,10 +690,10 @@ unsigned alias::getOptionWidth() const {
return std::strlen(ArgStr)+6; return std::strlen(ArgStr)+6;
} }
// Print out the option for the alias... // Print out the option for the alias.
void alias::printOptionInfo(unsigned GlobalWidth) const { void alias::printOptionInfo(unsigned GlobalWidth) const {
unsigned L = std::strlen(ArgStr); unsigned L = std::strlen(ArgStr);
std::cerr << " -" << ArgStr << std::string(GlobalWidth-L-6, ' ') << " - " std::cout << " -" << ArgStr << std::string(GlobalWidth-L-6, ' ') << " - "
<< HelpStr << "\n"; << HelpStr << "\n";
} }
@ -720,12 +720,12 @@ unsigned basic_parser_impl::getOptionWidth(const Option &O) const {
// //
void basic_parser_impl::printOptionInfo(const Option &O, void basic_parser_impl::printOptionInfo(const Option &O,
unsigned GlobalWidth) const { unsigned GlobalWidth) const {
std::cerr << " -" << O.ArgStr; std::cout << " -" << O.ArgStr;
if (const char *ValName = getValueName()) if (const char *ValName = getValueName())
std::cerr << "=<" << getValueStr(O, ValName) << ">"; std::cout << "=<" << getValueStr(O, ValName) << ">";
std::cerr << std::string(GlobalWidth-getOptionWidth(O), ' ') << " - " std::cout << std::string(GlobalWidth-getOptionWidth(O), ' ') << " - "
<< O.HelpStr << "\n"; << O.HelpStr << "\n";
} }
@ -842,20 +842,20 @@ void generic_parser_base::printOptionInfo(const Option &O,
unsigned GlobalWidth) const { unsigned GlobalWidth) const {
if (O.hasArgStr()) { if (O.hasArgStr()) {
unsigned L = std::strlen(O.ArgStr); unsigned L = std::strlen(O.ArgStr);
std::cerr << " -" << O.ArgStr << std::string(GlobalWidth-L-6, ' ') std::cout << " -" << O.ArgStr << std::string(GlobalWidth-L-6, ' ')
<< " - " << O.HelpStr << "\n"; << " - " << O.HelpStr << "\n";
for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
unsigned NumSpaces = GlobalWidth-strlen(getOption(i))-8; unsigned NumSpaces = GlobalWidth-strlen(getOption(i))-8;
std::cerr << " =" << getOption(i) << std::string(NumSpaces, ' ') std::cout << " =" << getOption(i) << std::string(NumSpaces, ' ')
<< " - " << getDescription(i) << "\n"; << " - " << getDescription(i) << "\n";
} }
} else { } else {
if (O.HelpStr[0]) if (O.HelpStr[0])
std::cerr << " " << O.HelpStr << "\n"; std::cout << " " << O.HelpStr << "\n";
for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
unsigned L = std::strlen(getOption(i)); unsigned L = std::strlen(getOption(i));
std::cerr << " -" << getOption(i) << std::string(GlobalWidth-L-8, ' ') std::cout << " -" << getOption(i) << std::string(GlobalWidth-L-8, ' ')
<< " - " << getDescription(i) << "\n"; << " - " << getDescription(i) << "\n";
} }
} }
@ -909,9 +909,9 @@ public:
} }
if (ProgramOverview) if (ProgramOverview)
std::cerr << "OVERVIEW:" << ProgramOverview << "\n"; std::cout << "OVERVIEW:" << ProgramOverview << "\n";
std::cerr << "USAGE: " << ProgramName << " [options]"; std::cout << "USAGE: " << ProgramName << " [options]";
// Print out the positional options... // Print out the positional options...
std::vector<Option*> &PosOpts = getPositionalOpts(); std::vector<Option*> &PosOpts = getPositionalOpts();
@ -921,28 +921,28 @@ public:
for (unsigned i = CAOpt != 0, e = PosOpts.size(); i != e; ++i) { for (unsigned i = CAOpt != 0, e = PosOpts.size(); i != e; ++i) {
if (PosOpts[i]->ArgStr[0]) if (PosOpts[i]->ArgStr[0])
std::cerr << " --" << PosOpts[i]->ArgStr; std::cout << " --" << PosOpts[i]->ArgStr;
std::cerr << " " << PosOpts[i]->HelpStr; std::cout << " " << PosOpts[i]->HelpStr;
} }
// Print the consume after option info if it exists... // Print the consume after option info if it exists...
if (CAOpt) std::cerr << " " << CAOpt->HelpStr; if (CAOpt) std::cout << " " << CAOpt->HelpStr;
std::cerr << "\n\n"; std::cout << "\n\n";
// Compute the maximum argument length... // Compute the maximum argument length...
MaxArgLen = 0; MaxArgLen = 0;
for (unsigned i = 0, e = Options.size(); i != e; ++i) for (unsigned i = 0, e = Options.size(); i != e; ++i)
MaxArgLen = std::max(MaxArgLen, Options[i].second->getOptionWidth()); MaxArgLen = std::max(MaxArgLen, Options[i].second->getOptionWidth());
std::cerr << "OPTIONS:\n"; std::cout << "OPTIONS:\n";
for (unsigned i = 0, e = Options.size(); i != e; ++i) for (unsigned i = 0, e = Options.size(); i != e; ++i)
Options[i].second->printOptionInfo(MaxArgLen); Options[i].second->printOptionInfo(MaxArgLen);
// Print any extra help the user has declared. // Print any extra help the user has declared.
for (std::vector<const char *>::iterator I = MoreHelp().begin(), for (std::vector<const char *>::iterator I = MoreHelp().begin(),
E = MoreHelp().end(); I != E; ++I) E = MoreHelp().end(); I != E; ++I)
std::cerr << *I; std::cout << *I;
MoreHelp().clear(); MoreHelp().clear();
// Halt the program since help information was printed // Halt the program since help information was printed
@ -955,12 +955,12 @@ class VersionPrinter {
public: public:
void operator=(bool OptionWasSpecified) { void operator=(bool OptionWasSpecified) {
if (OptionWasSpecified) { if (OptionWasSpecified) {
std::cerr << "Low Level Virtual Machine (" << PACKAGE_NAME << ") " std::cout << "Low Level Virtual Machine (" << PACKAGE_NAME << ") "
<< PACKAGE_VERSION << " (see http://llvm.org/)"; << PACKAGE_VERSION << " (see http://llvm.org/)";
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << " DEBUG BUILD\n"; std::cout << " ASSERTIONS ENABLED\n";
#else #else
std::cerr << "\n"; std::cout << "\n";
#endif #endif
getOpts().clear(); // Don't bother making option dtors remove from map. getOpts().clear(); // Don't bother making option dtors remove from map.
exit(1); exit(1);