diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-09-01 04:41:28 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-09-01 04:41:28 +0000 |
commit | e1cc150a8e6b451e42b04b04ffb41596e01bbef5 (patch) | |
tree | d2a25010d6011da90120dbd41238fa51b519e0ae /lib/Support | |
parent | d808bcaefe573140d851271d7a90df7f8a7c98fc (diff) | |
download | external_llvm-e1cc150a8e6b451e42b04b04ffb41596e01bbef5.zip external_llvm-e1cc150a8e6b451e42b04b04ffb41596e01bbef5.tar.gz external_llvm-e1cc150a8e6b451e42b04b04ffb41596e01bbef5.tar.bz2 |
Make CommandLine prefix error output with the name of the program.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16129 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/CommandLine.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 13de27e..3bc9cbf 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -29,6 +29,10 @@ using namespace llvm; using namespace cl; +// Globals for name and overview of program +static const char *ProgramName = "<unknown>"; +static const char *ProgramOverview = 0; + //===----------------------------------------------------------------------===// // Basic, shared command line option processing machinery... // @@ -57,8 +61,8 @@ static std::vector<Option*> &getPositionalOpts() { static void AddArgument(const char *ArgName, Option *Opt) { if (getOption(ArgName)) { - std::cerr << "CommandLine Error: Argument '" << ArgName - << "' defined more than once!\n"; + std::cerr << ProgramName << ": CommandLine Error: Argument '" + << ArgName << "' defined more than once!\n"; } else { // Add argument to the argument map! getOpts()[ArgName] = Opt; @@ -83,9 +87,6 @@ static void RemoveArgument(const char *ArgName, Option *Opt) { } } -static const char *ProgramName = 0; -static const char *ProgramOverview = 0; - static inline bool ProvideOption(Option *Handler, const char *ArgName, const char *Value, int argc, char **argv, int &i) { @@ -105,9 +106,14 @@ static inline bool ProvideOption(Option *Handler, const char *ArgName, return Handler->error(" does not allow a value! '" + std::string(Value) + "' specified."); break; - case ValueOptional: break; - default: std::cerr << "Bad ValueMask flag! CommandLine usage error:" - << Handler->getValueExpectedFlag() << "\n"; abort(); + case ValueOptional: + break; + default: + std::cerr << ProgramName + << ": Bad ValueMask flag! CommandLine usage error:" + << Handler->getValueExpectedFlag() << "\n"; + abort(); + break; } // Run the handler now! @@ -432,8 +438,8 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, } if (Handler == 0) { - std::cerr << "Unknown command line argument '" << argv[i] << "'. Try: '" - << argv[0] << " --help'\n"; + std::cerr << ProgramName << ": Unknown command line argument '" << argv[i] + << "'. Try: '" << argv[0] << " --help'\n"; ErrorParsing = true; continue; } @@ -469,7 +475,8 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, // Check and handle positional arguments now... if (NumPositionalRequired > PositionalVals.size()) { - std::cerr << "Not enough positional command line arguments specified!\n" + std::cerr << ProgramName + << ": Not enough positional command line arguments specified!\n" << "Must specify at least " << NumPositionalRequired << " positional arguments: See: " << argv[0] << " --help\n"; ErrorParsing = true; @@ -575,8 +582,8 @@ bool Option::error(std::string Message, const char *ArgName) { if (ArgName[0] == 0) std::cerr << HelpStr; // Be nice for positional arguments else - std::cerr << "-" << ArgName; - std::cerr << " option" << Message << "\n"; + std::cerr << ProgramName << ": for the -" << ArgName; + std::cerr << " option: " << Message << "\n"; return true; } |