diff options
| author | Chris Lattner <sabre@nondot.org> | 2001-07-22 03:57:31 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2001-07-22 03:57:31 +0000 | 
| commit | 5f4b44652f628b56e920ff275ced897ddd80fb58 (patch) | |
| tree | cdef3ef9777e328696d52ef7d12a1686b8c61811 /llvm/support/lib | |
| parent | 6f555812549d7076154f781ed00cb7d1fdd0a30e (diff) | |
| download | bcm5719-llvm-5f4b44652f628b56e920ff275ced897ddd80fb58.tar.gz bcm5719-llvm-5f4b44652f628b56e920ff275ced897ddd80fb58.zip | |
Convert from using C style char*'s to strings.
Look ma, no strdups
llvm-svn: 265
Diffstat (limited to 'llvm/support/lib')
| -rw-r--r-- | llvm/support/lib/Support/ProgramOption.cpp | 68 | ||||
| -rw-r--r-- | llvm/support/lib/Support/ProgramOptions.cpp | 21 | 
2 files changed, 31 insertions, 58 deletions
| diff --git a/llvm/support/lib/Support/ProgramOption.cpp b/llvm/support/lib/Support/ProgramOption.cpp index 2fa987941be..6b391bc7145 100644 --- a/llvm/support/lib/Support/ProgramOption.cpp +++ b/llvm/support/lib/Support/ProgramOption.cpp @@ -14,36 +14,23 @@  //  //**************************************************************************/ -//************************** System Include Files **************************/ - +#include "llvm/Support/ProgramOption.h"  #include <assert.h>  #include <stdlib.h>  #include <stdio.h> -#include <string> - -//*************************** User Include Files ***************************/ - -#include "llvm/Support/ProgramOption.h" - -//********************** Local Variable Definitions ************************/ - -//************************ Class Implementations ***************************/ -  //**************************************************************************/ -StringOption::StringOption(const char* _argString, -			   const char* _helpMesg, -			   const char* _initValue,  +StringOption::StringOption(const string &_argString, +			   const string &_helpMesg, +			   const string &_initValue,   			   bool _append)    : ProgramOption(_argString, _helpMesg),      value(_initValue),      append(_append)   {} -int -StringOption::EvalOpt(const char* optarg) -{ +int StringOption::EvalOpt(const string &optarg) {    if (optarg == (char*) NULL)      return -1;			// flag the error @@ -59,17 +46,15 @@ StringOption::EvalOpt(const char* optarg)  //**************************************************************************/ -FlagOption::FlagOption(const char* _argString, -		       const char* _helpMesg, +FlagOption::FlagOption(const string &_argString, +		       const string &_helpMesg,  		       bool _initValue)    : ProgramOption(_argString, _helpMesg, 0),      value(_initValue)  {} -int -FlagOption::EvalOpt(const char* optarg) -{ -  if (strcmp(optarg, "0") == 0) { +int FlagOption::EvalOpt(const string &optarg) { +  if (optarg == "0") {      value = false;      return 1;				// one additional argument consumed    } @@ -81,21 +66,18 @@ FlagOption::EvalOpt(const char* optarg)  //**************************************************************************/ -RealValuedOption::RealValuedOption(const char* _argString, -				   const char* _helpMesg, +RealValuedOption::RealValuedOption(const string &_argString, +				   const string &_helpMesg,  				   double _initValue)    : ProgramOption(_argString, _helpMesg),      value(_initValue)  {} -int -RealValuedOption::EvalOpt(const char* optarg) -{ -  if (optarg == (char*) NULL) -    return -1; +int RealValuedOption::EvalOpt(const string &optarg) { +  if (optarg == "") return -1;    char* lastCharScanned = NULL; -  value = strtod(optarg, &lastCharScanned); +  value = strtod(optarg.c_str(), &lastCharScanned);    if (! (*lastCharScanned == '\0'))	// look for incorrect or partially      return -1;				// correct numerical argument @@ -103,36 +85,30 @@ RealValuedOption::EvalOpt(const char* optarg)    return 1;  } -char* -RealValuedOption::GetTextValue() const -{ +string RealValuedOption::GetTextValue() const {    char buffer[40];    sprintf(buffer, "%f", value); -  return strdup(buffer); +  return buffer;  }  //**************************************************************************/ -IntegerValuedOption::IntegerValuedOption(const char* _argString, -					 const char* _helpMesg, +IntegerValuedOption::IntegerValuedOption(const string &_argString, +					 const string &_helpMesg,  					 int _initValue)    : RealValuedOption(_argString, _helpMesg, (double) _initValue)  {} -int -IntegerValuedOption::Value() const -{ +int IntegerValuedOption::Value() const {    double realValue = RealValuedOption::Value();    assert(realValue == (int) realValue);    return (int) realValue;  } -char* -IntegerValuedOption::GetTextValue() const -{ +string IntegerValuedOption::GetTextValue() const {    char buffer[40];    sprintf(buffer, "%d", Value()); -  return strdup(buffer); +  return buffer;  } -//**************************************************************************/ + diff --git a/llvm/support/lib/Support/ProgramOptions.cpp b/llvm/support/lib/Support/ProgramOptions.cpp index 08fe3fd8a43..fc50ddcbbb3 100644 --- a/llvm/support/lib/Support/ProgramOptions.cpp +++ b/llvm/support/lib/Support/ProgramOptions.cpp @@ -19,7 +19,6 @@  #include <iostream.h>  #include <assert.h> -#include <string.h>  #include <stdlib.h>  #include <math.h>  #include <string> @@ -45,22 +44,20 @@ ProgramOptions::ProgramOptions(int _argc,      argsConsumed(0)  {} -const char* -ProgramOptions::StringOptionValue(const char* optString) const -{ -    const StringOption* handler = (const StringOption*) OptionHandler(optString); -    return (handler == NULL) ? NULL : handler->Value(); +string ProgramOptions::StringOptionValue(const string &optString) const { +    const StringOption* handler = (const StringOption*)OptionHandler(optString); +    return (handler == NULL) ? string("") : handler->Value();  }  bool -ProgramOptions::FlagOptionValue(const char* optString) const +ProgramOptions::FlagOptionValue(const string &optString) const  {      const FlagOption* handler = (const FlagOption*) OptionHandler(optString);      return (handler == NULL) ? false : handler->Value();  }  double -ProgramOptions::RealOptionValue(const char* optString) const +ProgramOptions::RealOptionValue(const string &optString) const  {      const RealValuedOption* handler =  	(const RealValuedOption*) OptionHandler(optString); @@ -68,7 +65,7 @@ ProgramOptions::RealOptionValue(const char* optString) const  }  int -ProgramOptions::IntOptionValue(const char* optString) const +ProgramOptions::IntOptionValue(const string &optString) const  {      const IntegerValuedOption* handler =  	(const IntegerValuedOption*) OptionHandler(optString); @@ -76,7 +73,7 @@ ProgramOptions::IntOptionValue(const char* optString) const  }  bool -ProgramOptions::OptionSpecified(const char* optString) const +ProgramOptions::OptionSpecified(const string &optString) const  {      const ProgramOption* handler = OptionHandler(optString);      return handler->OptionSpecified(); @@ -225,8 +222,8 @@ ProgramOptions::PrintOptions(ostream& stream) const        for (i=1; i <= handler->MinExpectedArgs(); i++)  	stream << showarg;  -      int numCharsPrinted = 1 + strlen(handler->ArgString()) -	+ strlen(showarg) * handler->MinExpectedArgs(); +      int numCharsPrinted = 1 + handler->ArgString().length() +	+ 6 * handler->MinExpectedArgs();        for (i=1; i > numCharsPrinted / 8; i--)  	stream << "\t"; | 

