[llvm-commits] CVS: llvm/lib/Support/CommandLine.cpp
Reid Spencer
reid at x10sys.com
Wed Aug 23 00:10:21 PDT 2006
Changes in directory llvm/lib/Support:
CommandLine.cpp updated: 1.72 -> 1.73
---
Log message:
Make the ProgramName variable a std::string so we can eliminate the path
portion fo the program name via sys::Path().getLast(). This makes error
messages more readable since this is invariably used only in error
messages. Instead of:
/path/to/llvm/bin/directory/toolname: error message
we will now get:
toolname: error message
Also, since we always have a program name (even if its defaulted), don't
check to see if it is set or not when generating error messages. This
eliminates a bunch of constant strings, saving a little under 1K of data.
---
Diffs of the changes: (+14 -26)
CommandLine.cpp | 40 ++++++++++++++--------------------------
1 files changed, 14 insertions(+), 26 deletions(-)
Index: llvm/lib/Support/CommandLine.cpp
diff -u llvm/lib/Support/CommandLine.cpp:1.72 llvm/lib/Support/CommandLine.cpp:1.73
--- llvm/lib/Support/CommandLine.cpp:1.72 Sun Aug 20 21:04:43 2006
+++ llvm/lib/Support/CommandLine.cpp Wed Aug 23 02:10:06 2006
@@ -18,6 +18,7 @@
#include "llvm/Config/config.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/System/Path.h"
#include <algorithm>
#include <functional>
#include <map>
@@ -31,7 +32,7 @@
using namespace cl;
// Globals for name and overview of program
-static const char *ProgramName = "<premain>";
+static std::string ProgramName ( "<premain>" );
static const char *ProgramOverview = 0;
// This collects additional help to be printed.
@@ -289,7 +290,8 @@
assert((!getOpts().empty() || !getPositionalOpts().empty()) &&
"No options specified, or ParseCommandLineOptions called more"
" than once!");
- ProgramName = argv[0]; // Save this away safe and snug
+ sys::Path progname(argv[0]);
+ ProgramName = sys::Path(argv[0]).getLast();
ProgramOverview = Overview;
bool ErrorParsing = false;
@@ -448,11 +450,8 @@
}
if (Handler == 0) {
- if (ProgramName)
- std::cerr << ProgramName << ": Unknown command line argument '"
+ std::cerr << ProgramName << ": Unknown command line argument '"
<< argv[i] << "'. Try: '" << argv[0] << " --help'\n";
- else
- std::cerr << "Unknown command line argument '" << argv[i] << "'.\n";
ErrorParsing = true;
continue;
}
@@ -488,28 +487,18 @@
// Check and handle positional arguments now...
if (NumPositionalRequired > PositionalVals.size()) {
- if (ProgramName)
- std::cerr << ProgramName
- << ": Not enough positional command line arguments specified!\n"
- << "Must specify at least " << NumPositionalRequired
- << " positional arguments: See: " << argv[0] << " --help\n";
- else
- std::cerr << "Not enough positional command line arguments specified!\n"
- << "Must specify at least " << NumPositionalRequired
- << " positional arguments.";
+ 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;
} else if (!HasUnlimitedPositionals
&& PositionalVals.size() > PositionalOpts.size()) {
- if (ProgramName)
- std::cerr << ProgramName
- << ": Too many positional arguments specified!\n"
- << "Can specify at most " << PositionalOpts.size()
- << " positional arguments: See: " << argv[0] << " --help\n";
- else
- std::cerr << "Too many positional arguments specified!\n"
- << "Can specify at most " << PositionalOpts.size()
- << " positional arguments.\n";
+ std::cerr << ProgramName
+ << ": Too many positional arguments specified!\n"
+ << "Can specify at most " << PositionalOpts.size()
+ << " positional arguments: See: " << argv[0] << " --help\n";
ErrorParsing = true;
} else if (ConsumeAfterOpt == 0) {
@@ -616,8 +605,7 @@
if (ArgName[0] == 0)
std::cerr << HelpStr; // Be nice for positional arguments
else
- std::cerr << (ProgramName ? ProgramName : "***")
- << ": for the -" << ArgName;
+ std::cerr << ProgramName << ": for the -" << ArgName;
std::cerr << " option: " << Message << "\n";
return true;
More information about the llvm-commits
mailing list