summaryrefslogtreecommitdiff
path: root/support/lib
diff options
context:
space:
mode:
Diffstat (limited to 'support/lib')
-rw-r--r--support/lib/Support/Makefile5
-rw-r--r--support/lib/Support/ProgramOption.cpp114
-rw-r--r--support/lib/Support/ProgramOptions.cpp243
3 files changed, 0 insertions, 362 deletions
diff --git a/support/lib/Support/Makefile b/support/lib/Support/Makefile
index 7a41c62b04..c7eb8adcb1 100644
--- a/support/lib/Support/Makefile
+++ b/support/lib/Support/Makefile
@@ -4,9 +4,4 @@ DIRS =
LIBRARYNAME = support
-## List source files in link order
-Source = \
- ProgramOption.o \
- ProgramOptions.o
-
include $(LEVEL)/Makefile.common
diff --git a/support/lib/Support/ProgramOption.cpp b/support/lib/Support/ProgramOption.cpp
deleted file mode 100644
index 6b391bc714..0000000000
--- a/support/lib/Support/ProgramOption.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-// $Id$
-//***************************************************************************
-//
-// File:
-// ProgramOption.C
-//
-// Purpose:
-// General representations for a program option.
-//
-// History:
-// 08/08/95 - adve - created in the dHPF compiler
-// 11/26/96 - adve - EvalOpt now returns #args consumed, or -1 for error
-// 07/15/01 - vadve - Copied to LLVM system and modified
-//
-//**************************************************************************/
-
-#include "llvm/Support/ProgramOption.h"
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-//**************************************************************************/
-
-StringOption::StringOption(const string &_argString,
- const string &_helpMesg,
- const string &_initValue,
- bool _append)
- : ProgramOption(_argString, _helpMesg),
- value(_initValue),
- append(_append)
-{}
-
-int StringOption::EvalOpt(const string &optarg) {
- if (optarg == (char*) NULL)
- return -1; // flag the error
-
- if (this->append)
- value += optarg;
- else
- value = optarg;
-
- optionSpecified = true;
- return 1; // one additional argument consumed
-}
-
-
-//**************************************************************************/
-
-FlagOption::FlagOption(const string &_argString,
- const string &_helpMesg,
- bool _initValue)
- : ProgramOption(_argString, _helpMesg, 0),
- value(_initValue)
-{}
-
-int FlagOption::EvalOpt(const string &optarg) {
- if (optarg == "0") {
- value = false;
- return 1; // one additional argument consumed
- }
- else {
- value = true;
- return 0; // zero ... consumed
- }
-}
-
-//**************************************************************************/
-
-RealValuedOption::RealValuedOption(const string &_argString,
- const string &_helpMesg,
- double _initValue)
- : ProgramOption(_argString, _helpMesg),
- value(_initValue)
-{}
-
-int RealValuedOption::EvalOpt(const string &optarg) {
- if (optarg == "") return -1;
-
- char* lastCharScanned = NULL;
- value = strtod(optarg.c_str(), &lastCharScanned);
- if (! (*lastCharScanned == '\0')) // look for incorrect or partially
- return -1; // correct numerical argument
-
- optionSpecified = true;
- return 1;
-}
-
-string RealValuedOption::GetTextValue() const {
- char buffer[40];
- sprintf(buffer, "%f", value);
- return buffer;
-}
-
-//**************************************************************************/
-
-IntegerValuedOption::IntegerValuedOption(const string &_argString,
- const string &_helpMesg,
- int _initValue)
- : RealValuedOption(_argString, _helpMesg, (double) _initValue)
-{}
-
-int IntegerValuedOption::Value() const {
- double realValue = RealValuedOption::Value();
- assert(realValue == (int) realValue);
- return (int) realValue;
-}
-
-string IntegerValuedOption::GetTextValue() const {
- char buffer[40];
- sprintf(buffer, "%d", Value());
- return buffer;
-}
-
-
diff --git a/support/lib/Support/ProgramOptions.cpp b/support/lib/Support/ProgramOptions.cpp
deleted file mode 100644
index fc50ddcbbb..0000000000
--- a/support/lib/Support/ProgramOptions.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-// $Id$
-//***************************************************************************
-//
-// File:
-// ProgramOptions.C
-//
-// Purpose:
-// General options processing for any program.
-//
-// History:
-// 08/08/95 - adve - created in the dHPF compiler
-// 10/10/96 - mpal, dbaker - converted to const member functions.
-// 11/26/96 - adve - fixed to handle options that consume 0+ arguments
-// 07/15/01 - vadve - Copied to LLVM system and modified
-//
-//**************************************************************************/
-
-//************************** System Include Files **************************/
-
-#include <iostream.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <math.h>
-#include <string>
-#ifndef MAXINT
-#define MAXINT ((1 << sizeof(int)-1) - 1)
-#endif
-
-//*************************** User Include Files ***************************/
-
-#include "llvm/Support/ProgramOptions.h"
-#include "llvm/Support/ProgramOption.h"
-
-
-//************************** Method Definitions ****************************/
-
-ProgramOptions::ProgramOptions(int _argc,
- const char* _argv[],
- const char* _envp[])
- : optionRegistry(),
- argc(_argc),
- argv(_argv),
- envp(_envp),
- argsConsumed(0)
-{}
-
-string ProgramOptions::StringOptionValue(const string &optString) const {
- const StringOption* handler = (const StringOption*)OptionHandler(optString);
- return (handler == NULL) ? string("") : handler->Value();
-}
-
-bool
-ProgramOptions::FlagOptionValue(const string &optString) const
-{
- const FlagOption* handler = (const FlagOption*) OptionHandler(optString);
- return (handler == NULL) ? false : handler->Value();
-}
-
-double
-ProgramOptions::RealOptionValue(const string &optString) const
-{
- const RealValuedOption* handler =
- (const RealValuedOption*) OptionHandler(optString);
- return (handler == NULL) ? MAXFLOAT : handler->Value();
-}
-
-int
-ProgramOptions::IntOptionValue(const string &optString) const
-{
- const IntegerValuedOption* handler =
- (const IntegerValuedOption*) OptionHandler(optString);
- return (handler == NULL) ? MAXINT : handler->Value();
-}
-
-bool
-ProgramOptions::OptionSpecified(const string &optString) const
-{
- const ProgramOption* handler = OptionHandler(optString);
- return handler->OptionSpecified();
-}
-
-const char*
-ProgramOptions::ProgramName() const
-{
- return argv[0];
-}
-
-int
-ProgramOptions::NumberOfOtherOptions() const
-{
- return argc - argsConsumed;
-}
-
-const char*
-ProgramOptions::OtherOption(int i) const
-{
- i += argsConsumed;
- assert(i >= 0 && i < argc);
- return argv[i];
-}
-
-const char**
-ProgramOptions::GetOriginalArgs() const
-{
- return argv;
-}
-
-vector<string>
-ProgramOptions::GetDescription() const
-{
- vector<string> optDesc;
-
- if (optDesc.size() < (unsigned) argc)
- {
- for (hash_map<string,ProgramOption*>::const_iterator iter=optionRegistry.begin();
- ! (iter == optionRegistry.end());
- ++iter)
- {
- const ProgramOption* handler = iter->second;
- optDesc.push_back(handler->ArgString()); // 1st
- optDesc.push_back(handler->HelpMesg()); // 2nd
- optDesc.push_back(handler->GetTextValue()); // 3rd
- }
- }
-
- return optDesc;
-}
-
-void
-ProgramOptions::Register(ProgramOption* option)
-{
- optionRegistry[option->ArgString()] = option;
-}
-
-//----------------------------------------------------------------------
-// function ProgramOptions::ParseArgs
-//
-// Parse command-line options until you run out of options or see
-// an unrecognized option. `getopt' is a standard package to do this,
-// but incredibly, it limited to single-letter options.
-//
-// -- Each option can consume zero or one additional arguments of argv
-// -- "--" can be used to mark the end of options
-// so that a program argument can also start with "-".
-//---------------------------------------------------------------------/
-
-void
-ProgramOptions::ParseArgs(int argc,
- const char* argv[],
- const char* envp[])
-{
- if (argc == 0) {
- Usage();
- }
- // consume the program name
- argsConsumed = 1;
-
- while (argsConsumed < argc)
- {
- const char* arg = argv[argsConsumed];
- if (arg[0] == '-')
- {
- if (strcmp(arg, "--") == 0) { // "--" marks end of options
- argsConsumed++; // consume and
- break; // discontinue the for loop
- }
- ProgramOption* handler = OptionHandler(arg+1);
- if (handler == NULL) {
- cerr << "Unrecognized option: " << arg+1 << endl;
- Usage();
- }
-
- if (argc - argsConsumed < handler->MinExpectedArgs()) {
- cerr << "Option " << (char*) arg+1 << " needs "
- << handler->MinExpectedArgs() << " arguments" << endl;
- Usage();
- }
-
- argsConsumed++; // consumed the option
-
- const char* nextArg = (argsConsumed < argc)? argv[argsConsumed]
- : "";
- int numAdditionalArgsConsumed = handler->EvalOpt(nextArg);
- if (numAdditionalArgsConsumed < 0)
- Usage();
- argsConsumed += numAdditionalArgsConsumed;
- }
- else
- {
- break; // quit the while loop
- }
- }
-
- ParseExtraArgs();
-}
-
-void
-ProgramOptions::PrintArgs(ostream& stream) const
-{
- for (int i = 0; i < argc; i++) {
- stream << argv[i] << " ";
- }
- stream << endl;
-}
-
-
-void
-ProgramOptions::PrintOptions(ostream& stream) const
-{
- stream << "OPTIONS:" << endl;
- stream << "\tUse argument 0 to turn OFF a flag option: "
- << "-<flag_opt> 0" << endl << endl;
-
- for (hash_map<string,ProgramOption*>::const_iterator iter = optionRegistry.begin();
- iter != optionRegistry.end(); ++iter) {
- const ProgramOption* handler = (*iter).second;
-
- stream << "\t-" << handler->ArgString();
-
- const char* const showarg = " <arg>";
- int i = 1;
- for (i=1; i <= handler->MinExpectedArgs(); i++)
- stream << showarg;
-
- int numCharsPrinted = 1 + handler->ArgString().length()
- + 6 * handler->MinExpectedArgs();
- for (i=1; i > numCharsPrinted / 8; i--)
- stream << "\t";
-
- stream << "\t" << handler->HelpMesg()
- << endl;
- }
-}
-
-void
-ProgramOptions::Usage() const
-{
- PrintUsage(cerr);
- exit(1);
-}
-
-
-//**************************************************************************/