version 1.13, 2001/07/10 22:31:23
|
version 1.14, 2001/12/13 14:54:50
|
|
|
// | // |
// Author: Bob Blair (bblair@bmc.com) | // Author: Bob Blair (bblair@bmc.com) |
// | // |
// Modified By: |
// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
Optarg::Value(String &s) const { s = _value; } | Optarg::Value(String &s) const { s = _value; } |
| |
// Fill in a caller-provided int with the integer conversion of the value. | // Fill in a caller-provided int with the integer conversion of the value. |
void |
void Optarg::Value (int &i) const throw (IncompatibleTypes) |
Optarg::Value(int &i) const |
{ |
|
_CString cs(_value); |
|
const char* s = cs; |
|
Boolean valid = true; |
|
Uint32 j; |
|
for (j = 0; j < strlen (s); j++) |
|
{ |
|
if ((!isdigit (s [j])) && (!isspace (s [j])) && (s [j] != '+') && |
|
(s [j] != '-')) |
|
{ |
|
valid = false; |
|
break; |
|
} |
|
} |
|
if (valid) |
|
{ |
|
if (!(sscanf (s, "%d", &i))) |
{ | { |
i = (int)atoi(_CString(_value)); |
throw IncompatibleTypes (); |
|
} |
|
} |
|
else |
|
{ |
|
throw IncompatibleTypes (); |
|
} |
} | } |
| |
// Fill in a caller-provided unsigned int | // Fill in a caller-provided unsigned int |
void |
void Optarg::Value (unsigned int &i) const throw (IncompatibleTypes) |
Optarg::Value(unsigned int &i) const { |
{ |
i = (unsigned int)atoi(_CString(_value)); |
_CString cs(_value); |
|
const char* s = cs; |
|
Boolean valid = true; |
|
Uint32 j; |
|
|
|
for (j = 0; j < strlen (s); j++) |
|
{ |
|
if ((!isdigit (s [j])) && (!isspace (s [j]))) |
|
{ |
|
valid = false; |
|
break; |
|
} |
|
} |
|
if (valid) |
|
{ |
|
if (!(sscanf (s, "%u", &i))) |
|
{ |
|
throw IncompatibleTypes (); |
|
} |
|
} |
|
else |
|
{ |
|
throw IncompatibleTypes (); |
|
} |
} | } |
| |
// Fill in a call-provided unsigned int | // Fill in a call-provided unsigned int |
void | void |
Optarg::Value(long &l) const { | Optarg::Value(long &l) const { |
l = (long)atoi(_CString(_value)); |
_CString cs(_value); |
|
l = (long)atoi(cs); |
} | } |
| |
// Fill in a caller-provided long | // Fill in a caller-provided long |
void | void |
Optarg::Value(unsigned long &l) const { | Optarg::Value(unsigned long &l) const { |
l = (unsigned long)atoi(_CString(_value)); |
_CString cs(_value); |
|
l = (unsigned long)atoi(cs); |
} | } |
| |
// Ditto unsigned long | // Ditto unsigned long |
void | void |
Optarg::Value(double &d) const { | Optarg::Value(double &d) const { |
d = (double)atof(_CString(_value)); |
_CString cs(_value); |
|
d = (double)atof(cs); |
} | } |
| |
//-------------------------------------------------------------------- | //-------------------------------------------------------------------- |
|
|
return false; | return false; |
} | } |
| |
|
/** |
|
In the valid option definition string, following an option, |
|
indicates that the preceding option takes a required argument. |
|
*/ |
|
const char getoopt::GETOPT_ARGUMENT_DESIGNATOR = ':'; |
|
|
//-------------------------------------------------------------------- | //-------------------------------------------------------------------- |
// Routines for parsing the command line | // Routines for parsing the command line |
//-------------------------------------------------------------------- | //-------------------------------------------------------------------- |