diff options
author | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-04-16 19:31:40 +0000 |
---|---|---|
committer | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-04-16 19:31:40 +0000 |
commit | bb260d99eed1ba67a858c23a765f5273ab3740b7 (patch) | |
tree | b1c87f3ab56e1f674ec27429bf872c63017ed972 /ace | |
parent | 9a1fd6436ab841f4438554f88cdf3cf8678e3840 (diff) | |
download | ATCD-bb260d99eed1ba67a858c23a765f5273ab3740b7.tar.gz |
ChangeLogTag:Wed Apr 16 19:27:29 UTC 2003 Don Hinton <dhinton@drestystems.com>
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Configuration.cpp | 109 | ||||
-rw-r--r-- | ace/Configuration.h | 13 | ||||
-rw-r--r-- | ace/Configuration_Import_Export.cpp | 3 | ||||
-rw-r--r-- | ace/Get_Opt.cpp | 64 | ||||
-rw-r--r-- | ace/Get_Opt.h | 15 | ||||
-rw-r--r-- | ace/Global_Macros.h | 2 |
6 files changed, 157 insertions, 49 deletions
diff --git a/ace/Configuration.cpp b/ace/Configuration.cpp index e478e1c6eb3..c4ee9bc94e3 100644 --- a/ace/Configuration.cpp +++ b/ace/Configuration.cpp @@ -144,6 +144,8 @@ ACE_Configuration_Section_Key::operator= (const ACE_Configuration_Section_Key& r ////////////////////////////////////////////////////////////////////////////// +ACE_TCHAR ACE_Configuration::NULL_String_ = '\0'; + ACE_Configuration::ACE_Configuration (void) : root_ () { @@ -240,6 +242,14 @@ ACE_Configuration::validate_name (const ACE_TCHAR* name, int allow_path) return 0; } +int +ACE_Configuration::validate_value_name (const ACE_TCHAR* name) +{ + if (name == 0 || *name == this->NULL_String_) + return 0; + + return this->validate_name (name); +} const ACE_Configuration_Section_Key& ACE_Configuration::root_section (void) const @@ -474,6 +484,13 @@ int ACE_Configuration::operator== (const ACE_Configuration& rhs) const static const int ACE_DEFAULT_BUFSIZE = 256; +static ACE_TCHAR *temp_name (ACE_TCHAR *name) +{ + if (name && *name == this->NULL_String_) + return 0; + return name; +} + ACE_Section_Key_Win32::ACE_Section_Key_Win32 (HKEY hKey) : hKey_ (hKey) { @@ -714,7 +731,8 @@ ACE_Configuration_Win32Registry::set_string_value (const ACE_Configuration_Secti const ACE_TCHAR* name, const ACE_TString& value) { - if (validate_name (name)) + ACE_TCHAR *t_name = temp_name (name); + if (validate_value_name (t_name)) return -1; HKEY base_key; @@ -724,7 +742,7 @@ ACE_Configuration_Win32Registry::set_string_value (const ACE_Configuration_Secti DWORD len = ACE_static_cast (DWORD, value.length () + 1); len *= sizeof (ACE_TCHAR); if (ACE_TEXT_RegSetValueEx (base_key, - name, + t_name, 0, REG_SZ, (BYTE *) value.fast_rep (), @@ -740,7 +758,8 @@ ACE_Configuration_Win32Registry::set_integer_value (const ACE_Configuration_Sect const ACE_TCHAR* name, u_int value) { - if (validate_name (name)) + ACE_TCHAR *t_name = temp_name (name); + if (validate_value_name (t_name)) return -1; HKEY base_key; @@ -748,7 +767,7 @@ ACE_Configuration_Win32Registry::set_integer_value (const ACE_Configuration_Sect return -1; if (ACE_TEXT_RegSetValueEx (base_key, - name, + t_name, 0, REG_DWORD, (BYTE *) &value, @@ -764,7 +783,8 @@ ACE_Configuration_Win32Registry::set_binary_value (const ACE_Configuration_Secti const void* data, size_t length) { - if (validate_name (name)) + ACE_TCHAR *t_name = temp_name (name); + if (validate_value_name (t_name)) return -1; HKEY base_key; @@ -772,7 +792,7 @@ ACE_Configuration_Win32Registry::set_binary_value (const ACE_Configuration_Secti return -1; if (ACE_TEXT_RegSetValueEx (base_key, - name, + t_name, 0, REG_BINARY, (BYTE *) data, @@ -788,7 +808,8 @@ ACE_Configuration_Win32Registry::get_string_value (const ACE_Configuration_Secti const ACE_TCHAR* name, ACE_TString& value) { - if (validate_name (name)) + ACE_TCHAR *t_name = temp_name (name); + if (validate_value_name (t_name)) return -1; HKEY base_key; @@ -799,7 +820,7 @@ ACE_Configuration_Win32Registry::get_string_value (const ACE_Configuration_Secti DWORD buffer_length = 0; DWORD type; if (ACE_TEXT_RegQueryValueEx (base_key, - name, + t_name, 0, &type, (BYTE *) 0, @@ -820,7 +841,7 @@ ACE_Configuration_Win32Registry::get_string_value (const ACE_Configuration_Secti ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> buffer (temp); if (ACE_TEXT_RegQueryValueEx (base_key, - name, + t_name, 0, &type, (BYTE *) buffer.get (), @@ -838,7 +859,8 @@ ACE_Configuration_Win32Registry::get_integer_value (const ACE_Configuration_Sect const ACE_TCHAR* name, u_int& value) { - if (validate_name (name)) + ACE_TCHAR *t_name = temp_name (name); + if (validate_value_name (t_name)) return -1; HKEY base_key; @@ -848,7 +870,7 @@ ACE_Configuration_Win32Registry::get_integer_value (const ACE_Configuration_Sect DWORD length = sizeof (value); DWORD type; if (ACE_TEXT_RegQueryValueEx (base_key, - name, + t_name, 0, &type, (BYTE *) &value, @@ -870,7 +892,8 @@ ACE_Configuration_Win32Registry::get_binary_value (const ACE_Configuration_Secti void *&data, size_t &length) { - if (validate_name (name)) + ACE_TCHAR *t_name = temp_name (name); + if (validate_value_name (t_name)) return -1; HKEY base_key; @@ -881,7 +904,7 @@ ACE_Configuration_Win32Registry::get_binary_value (const ACE_Configuration_Secti DWORD buffer_length = 0; DWORD type; if (ACE_TEXT_RegQueryValueEx (base_key, - name, + t_name, 0, &type, (BYTE *) 0, @@ -899,7 +922,7 @@ ACE_Configuration_Win32Registry::get_binary_value (const ACE_Configuration_Secti ACE_NEW_RETURN (data, BYTE[length], -1); if (ACE_TEXT_RegQueryValueEx (base_key, - name, + t_name, 0, &type, (BYTE *) data, @@ -918,7 +941,8 @@ ACE_Configuration_Win32Registry::find_value (const ACE_Configuration_Section_Key const ACE_TCHAR* name, VALUETYPE& type_out) { - if (validate_name (name)) + ACE_TCHAR *t_name = temp_name (name); + if (validate_value_name (t_name)) return -1; HKEY base_key; @@ -928,7 +952,7 @@ ACE_Configuration_Win32Registry::find_value (const ACE_Configuration_Section_Key DWORD buffer_length=0; DWORD type; int result=ACE_TEXT_RegQueryValueEx (base_key, - name, + t_name, 0, &type, 0, @@ -958,14 +982,15 @@ int ACE_Configuration_Win32Registry::remove_value (const ACE_Configuration_Section_Key& key, const ACE_TCHAR* name) { - if (validate_name (name)) + ACE_TCHAR *t_name = temp_name (name); + if (validate_value_name (t_name)) return -1; HKEY base_key; if (load_key (key, base_key)) return -1; - if (ACE_TEXT_RegDeleteValue (base_key, name) != ERROR_SUCCESS) + if (ACE_TEXT_RegDeleteValue (base_key, t_name) != ERROR_SUCCESS) return -1; return 0; @@ -1797,7 +1822,8 @@ ACE_Configuration_Heap::set_string_value (const ACE_Configuration_Section_Key& k const ACE_TString& value) { ACE_ASSERT (this->allocator_); - if (validate_name (name)) + const ACE_TCHAR *t_name = name ? name : &this->NULL_String_; + if (validate_value_name (t_name)) return -1; ACE_TString section; @@ -1827,9 +1853,9 @@ ACE_Configuration_Heap::set_string_value (const ACE_Configuration_Section_Key& k else { // it doesn't exist, bind it - ACE_TCHAR* pers_name = - (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR)); - ACE_OS::strcpy (pers_name, name); + ACE_TCHAR* pers_name = + (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR)); + ACE_OS::strcpy (pers_name, t_name); ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR)); ACE_OS::strcpy (pers_value, value.fast_rep ()); @@ -1853,7 +1879,8 @@ ACE_Configuration_Heap::set_integer_value (const ACE_Configuration_Section_Key& u_int value) { ACE_ASSERT (this->allocator_); - if (validate_name (name)) + const ACE_TCHAR *t_name = name ? name : &this->NULL_String_; + if (validate_value_name (t_name)) return -1; // Get the section name from the key @@ -1880,8 +1907,8 @@ ACE_Configuration_Heap::set_integer_value (const ACE_Configuration_Section_Key& { // it doesn't exist, bind it ACE_TCHAR* pers_name = - (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR)); - ACE_OS::strcpy (pers_name, name); + (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR)); + ACE_OS::strcpy (pers_name, t_name); ACE_Configuration_ExtId item_name (pers_name); ACE_Configuration_Value_IntId item_value (value); if (section_int.value_hash_map_->bind (item_name, item_value, allocator_)) @@ -1902,7 +1929,8 @@ ACE_Configuration_Heap::set_binary_value (const ACE_Configuration_Section_Key& k size_t length) { ACE_ASSERT (this->allocator_); - if (validate_name (name)) + const ACE_TCHAR *t_name = name ? name : &this->NULL_String_; + if (validate_value_name (t_name)) return -1; // Get the section name from the key @@ -1934,8 +1962,8 @@ ACE_Configuration_Heap::set_binary_value (const ACE_Configuration_Section_Key& k { // it doesn't exist, bind it ACE_TCHAR* pers_name = - (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR)); - ACE_OS::strcpy (pers_name, name); + (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR)); + ACE_OS::strcpy (pers_name, t_name); ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length); ACE_OS::memcpy (pers_value, data, length); ACE_Configuration_ExtId item_name (pers_name); @@ -1958,7 +1986,8 @@ ACE_Configuration_Heap::get_string_value (const ACE_Configuration_Section_Key& k ACE_TString& value) { ACE_ASSERT (this->allocator_); - if (validate_name (name)) + const ACE_TCHAR *t_name = name ? name : &this->NULL_String_; + if (validate_value_name (t_name)) return -1; // Get the section name from the key @@ -1973,7 +2002,7 @@ ACE_Configuration_Heap::get_string_value (const ACE_Configuration_Section_Key& k return -1; // section does not exist // See if it exists first - ACE_Configuration_ExtId VExtId (name); + ACE_Configuration_ExtId VExtId (t_name); ACE_Configuration_Value_IntId VIntId; if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_)) return -1; // unknown value @@ -1997,10 +2026,9 @@ ACE_Configuration_Heap::get_integer_value (const ACE_Configuration_Section_Key& { ACE_ASSERT (this->allocator_); - if (this->validate_name (name) != 0) - { - return -1; - } + const ACE_TCHAR *t_name = name ? name : &this->NULL_String_; + if (validate_value_name (t_name)) + return -1; // Get the section name from the key ACE_TString section (0, 0, 0); @@ -2021,7 +2049,7 @@ ACE_Configuration_Heap::get_integer_value (const ACE_Configuration_Section_Key& // See if it exists first - ACE_Configuration_ExtId VExtId (name); + ACE_Configuration_ExtId VExtId (t_name); ACE_Configuration_Value_IntId VIntId; if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_) != 0) @@ -2048,7 +2076,8 @@ ACE_Configuration_Heap::get_binary_value (const ACE_Configuration_Section_Key& k size_t& length) { ACE_ASSERT (this->allocator_); - if (validate_name (name)) + const ACE_TCHAR *t_name = name ? name : &this->NULL_String_; + if (validate_value_name (t_name)) return -1; // Get the section name from the key @@ -2062,7 +2091,7 @@ ACE_Configuration_Heap::get_binary_value (const ACE_Configuration_Section_Key& k if (index_->find (ExtId, IntId, allocator_)) return -1; // section does not exist - ACE_Configuration_ExtId VExtId (name); + ACE_Configuration_ExtId VExtId (t_name); ACE_Configuration_Value_IntId VIntId; // See if it exists first if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_)) @@ -2088,7 +2117,8 @@ ACE_Configuration_Heap::find_value (const ACE_Configuration_Section_Key& key, VALUETYPE& type_out) { ACE_ASSERT (this->allocator_); - if (validate_name (name)) + const ACE_TCHAR *t_name = name ? name : &this->NULL_String_; + if (validate_value_name (t_name)) return -1; // Get the section name from the key @@ -2117,7 +2147,8 @@ ACE_Configuration_Heap::remove_value (const ACE_Configuration_Section_Key& key, const ACE_TCHAR* name) { ACE_ASSERT (this->allocator_); - if (validate_name (name)) + const ACE_TCHAR *t_name = name ? name : &this->NULL_String_; + if (validate_value_name (t_name)) return -1; // Get the section name from the key diff --git a/ace/Configuration.h b/ace/Configuration.h index 1932e84dcb5..aecbe08b3bd 100644 --- a/ace/Configuration.h +++ b/ace/Configuration.h @@ -402,6 +402,19 @@ protected: */ int validate_name (const ACE_TCHAR* name, int allow_path = 0); + /** + * Test to see if <name> is valid. The default value for a key can be + * unnamed, which means either <name> is == 0 or <name> == '\0` is + * valid. Otherwise, it calls validate_name() to test <name> for the + * same rules that apply to keys. + */ + int validate_value_name (const ACE_TCHAR* name); + + /** + * Represents the "NULL" string to simplify the internal logic. + */ + static ACE_TCHAR NULL_String_; + // Not used ACE_Configuration (const ACE_Configuration& rhs); ACE_Configuration& operator= (const ACE_Configuration& rhs); diff --git a/ace/Configuration_Import_Export.cpp b/ace/Configuration_Import_Export.cpp index cc128d45b93..8f7e9e47b4f 100644 --- a/ace/Configuration_Import_Export.cpp +++ b/ace/Configuration_Import_Export.cpp @@ -399,12 +399,13 @@ ACE_Ini_ImpExp::import_config (const ACE_TCHAR* filename) } *end++ = '\0'; ACE_TCHAR *name = this->squish (line); +#if 0 if (ACE_OS::strlen (name) == 0) // No name; just an '=' { ACE_OS::fclose (in); return -3; } - +#endif // Now find the start of the value ACE_TCHAR *value = this->squish (end); size_t value_len = ACE_OS::strlen (value); diff --git a/ace/Get_Opt.cpp b/ace/Get_Opt.cpp index 7b6a5511899..fad5cd4c245 100644 --- a/ace/Get_Opt.cpp +++ b/ace/Get_Opt.cpp @@ -228,6 +228,9 @@ ACE_Get_Opt::long_option_i (void) s++; size_t len = s - this->nextchar_; + // set last_option_ to nextchar_, up to the '='. + this->last_option (ACE_TString (this->nextchar_, len)); + size_t size = this->long_opts_.size (); u_int option_index = 0; for (option_index = 0; option_index < size ; option_index++) @@ -243,7 +246,7 @@ ACE_Get_Opt::long_option_i (void) hits += 1; if (len == ACE_OS::strlen(p->name_)) { - // And in fact, it an exact match, so let's use it. + // And in fact, it's an exact match, so let's use it. exact = 1; break; } @@ -282,7 +285,8 @@ ACE_Get_Opt::long_option_i (void) if (this->opterr) ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%s: long option `--%s' doesn't allow an argument\n"), + ACE_LIB_TEXT ("%s: long option `--%s' doesn't allow ") + ACE_LIB_TEXT ("an argument\n"), this->argv_[0], pfound->name_)); // The spec doesn't cover this, so we keep going and the program // doesn't know we ignored an argument if opt_err is off!!! @@ -301,7 +305,8 @@ ACE_Get_Opt::long_option_i (void) // All out of elements, so we have to punt... if (this->opterr) ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%s: long option '--%s' requires an argument\n"), + ACE_LIB_TEXT ("%s: long option '--%s' requires ") + ACE_LIB_TEXT ("an argument\n"), this->argv_[0], pfound->name_)); this->nextchar_ = 0; this->optopt_ = pfound->val_; // Remember matching short equiv @@ -340,8 +345,12 @@ ACE_Get_Opt::short_option_i (void) /* Look at and handle the next option-character. */ ACE_TCHAR opt = *this->nextchar_++; + // Set last_option_ to opt + this->last_option (opt); + ACE_TCHAR *oli = 0; - oli = ACE_const_cast (ACE_TCHAR*, ACE_OS::strchr (this->optstring_.c_str (), opt)); + oli = ACE_const_cast (ACE_TCHAR*, + ACE_OS::strchr (this->optstring_.c_str (), opt)); /* Increment `optind' when we start to process its last character. */ if (*this->nextchar_ == '\0') @@ -392,7 +401,8 @@ ACE_Get_Opt::short_option_i (void) // Ran out of arguments before finding required argument. if (this->opterr) ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%s: short option requires an argument -- %c\n"), + ACE_LIB_TEXT ("%s: short option requires ") + ACE_LIB_TEXT ("an argument -- %c\n"), this->argv_[0], opt)); opt = this->has_colon_ ? ':' : '?'; } @@ -471,7 +481,8 @@ ACE_Get_Opt::long_option (const ACE_TCHAR *name, // add it. ACE_TCHAR *s = 0; if ((s = ACE_const_cast (ACE_TCHAR*, - ACE_OS::strchr (this->optstring_.c_str (), short_option))) != 0) + ACE_OS::strchr (this->optstring_.c_str (), + short_option))) != 0) { // Short option exists, so verify the argument options if (s[1] == ':') @@ -554,13 +565,52 @@ ACE_Get_Opt::long_option (void) const return 0; } +const ACE_TCHAR* +ACE_Get_Opt::last_option (void) const +{ + return this->last_option_.c_str (); +} + +void +ACE_Get_Opt::last_option (const ACE_TString &last_option) +{ + this->last_option_ = last_option; +} + void ACE_Get_Opt::dump (void) const { ACE_TRACE ("ACE_Get_Opt::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n"))); + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n") + ACE_LIB_TEXT ("opstring_ = %s\n") + ACE_LIB_TEXT ("long_only_ = %d\n") + ACE_LIB_TEXT ("has_colon_ = %d\n") + ACE_LIB_TEXT ("last_option_ = %s\n") + ACE_LIB_TEXT ("nextchar_ = %s\n") + ACE_LIB_TEXT ("optopt_ = %c\n") + ACE_LIB_TEXT ("ordering_ = %d\n"), + this->optstring_.c_str (), + this->long_only_, + this->has_colon_, + this->last_option_.c_str (), + this->nextchar_, + this->optopt_, + this->ordering_)); + + // now loop through the + size_t size = this->long_opts_.size (); + for (u_int i = 0; i < size ; ++i) + { + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n") + ACE_LIB_TEXT ("long_option name_ = %s\n") + ACE_LIB_TEXT ("has_arg_ = %d\n") + ACE_LIB_TEXT ("val_ = %d\n"), + this->long_opts_[i]->name_, + this->long_opts_[i]->has_arg_, + this->long_opts_[i]->val_)); + } ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } diff --git a/ace/Get_Opt.h b/ace/Get_Opt.h index 18905b621f5..2ae325bab20 100644 --- a/ace/Get_Opt.h +++ b/ace/Get_Opt.h @@ -169,7 +169,7 @@ public: */ ACE_Get_Opt (int argc, ACE_TCHAR **argv, - const ACE_TCHAR *optstring, + const ACE_TCHAR *optstring = ACE_LIB_TEXT (""), int skip_args = 1, int report_errors = 0, int ordering = PERMUTE_ARGS, @@ -287,6 +287,12 @@ public: /// Accessor for the internal @c argv_ pointer. ACE_TCHAR **argv (void) const; + /// Accessor for the @c last_option that was processed. This allows + /// applications to know if the found option was a short or long + /// option, and is especially useful in cases where it was invalid + /// and the caller wants to print out the invalid value. + const ACE_TCHAR *last_option (void) const; + /// Dump the state of an object. void dump (void) const; @@ -398,6 +404,9 @@ private: /// Handles reordering <argv>-elements. int permute (void); + /// Set last_option. + void last_option (const ACE_TString &s); + /// Holds the option string. ACE_TString optstring_; @@ -409,6 +418,10 @@ private: /// arguments are missing. int has_colon_; + /// This is the last option, short or long, that was processed. This + /// is handy to have in cases where the option passed was invalid. + ACE_TString last_option_; + /** * The next char to be scanned in the option-element in which the * last option character we returned was found. This allows us to diff --git a/ace/Global_Macros.h b/ace/Global_Macros.h index 7c0f3403307..01df20a4d65 100644 --- a/ace/Global_Macros.h +++ b/ace/Global_Macros.h @@ -27,7 +27,7 @@ #endif /* ACE_LACKS_PRAGMA_ONCE */ // Start Global Macros -# define ACE_BEGIN_DUMP ACE_LIB_TEXT ("\n====\n(%P|%t|%x)") +# define ACE_BEGIN_DUMP ACE_LIB_TEXT ("\n====\n(%P|%t|%x)\n") # define ACE_END_DUMP ACE_LIB_TEXT ("====\n") # if defined (ACE_NDEBUG) |