[llvm-commits] CVS: llvm/lib/Support/CommandLine.cpp
Reid Spencer
reid at x10sys.com
Tue Aug 31 21:41:39 PDT 2004
Changes in directory llvm/lib/Support:
CommandLine.cpp updated: 1.48 -> 1.49
---
Log message:
Make CommandLine prefix error output with the name of the program.
---
Diffs of the changes: (+20 -13)
Index: llvm/lib/Support/CommandLine.cpp
diff -u llvm/lib/Support/CommandLine.cpp:1.48 llvm/lib/Support/CommandLine.cpp:1.49
--- llvm/lib/Support/CommandLine.cpp:1.48 Fri Aug 13 14:47:30 2004
+++ llvm/lib/Support/CommandLine.cpp Tue Aug 31 23:41:28 2004
@@ -29,6 +29,10 @@
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 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 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 @@
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 @@
}
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 @@
// 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 @@
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;
}
More information about the llvm-commits
mailing list