summaryrefslogtreecommitdiff
path: root/ACE/ace/ARGV.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/ace/ARGV.cpp')
-rw-r--r--ACE/ace/ARGV.cpp138
1 files changed, 41 insertions, 97 deletions
diff --git a/ACE/ace/ARGV.cpp b/ACE/ace/ARGV.cpp
index 6117ded088a..8ef7d441afb 100644
--- a/ACE/ace/ARGV.cpp
+++ b/ACE/ace/ARGV.cpp
@@ -17,25 +17,10 @@ ACE_RCSID(ace, ARGV, "$Id$")
// Open versioned namespace, if enabled by the user.
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
-ACE_ALLOC_HOOK_DEFINE (ACE_ARGV_Queue_Entry)
ACE_ALLOC_HOOK_DEFINE (ACE_ARGV)
template <typename CHAR_TYPE>
void
-ACE_ARGV_Queue_Entry_T<CHAR_TYPE>::dump (void) const
-{
-#if defined (ACE_HAS_DUMP)
- ACE_TRACE ("ACE_ARGV_Queue_Entry_T::dump");
-
- ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("arg_ = %s"), this->arg_));
- ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("quote_arg_ = %d"), (int)this->quote_arg_));
- ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
-#endif /* ACE_HAS_DUMP */
-}
-
-template <typename CHAR_TYPE>
-void
ACE_ARGV_T<CHAR_TYPE>::dump (void) const
{
#if defined (ACE_HAS_DUMP)
@@ -76,6 +61,13 @@ ACE_ARGV_T<CHAR_TYPE>::string_to_argv (void)
}
template <typename CHAR_TYPE>
+int
+ACE_ARGV_T<CHAR_TYPE>::argv_to_string (CHAR_TYPE **argv, CHAR_TYPE *&buf)
+{
+ return ACE_OS::argv_to_string (argv, buf);
+}
+
+template <typename CHAR_TYPE>
ACE_ARGV_T<CHAR_TYPE>::ACE_ARGV_T (const CHAR_TYPE buf[],
bool substitute_env_args)
: substitute_env_args_ (substitute_env_args),
@@ -105,8 +97,7 @@ ACE_ARGV_T<CHAR_TYPE>::ACE_ARGV_T (const CHAR_TYPE buf[],
template <typename CHAR_TYPE>
ACE_ARGV_T<CHAR_TYPE>::ACE_ARGV_T (CHAR_TYPE *argv[],
- bool substitute_env_args,
- bool quote_arg)
+ bool substitute_env_args)
: substitute_env_args_ (substitute_env_args),
iterative_ (false),
argc_ (0),
@@ -120,17 +111,13 @@ ACE_ARGV_T<CHAR_TYPE>::ACE_ARGV_T (CHAR_TYPE *argv[],
if (argv == 0 || argv[0] == 0)
return;
- this->argc_ = ACE_OS::argv_to_string (argv,
- this->buf_,
- substitute_env_args,
- quote_arg);
+ this->argc_ = ACE_OS::argv_to_string (argv, this->buf_, substitute_env_args);
}
template <typename CHAR_TYPE>
ACE_ARGV_T<CHAR_TYPE>::ACE_ARGV_T (CHAR_TYPE *first_argv[],
CHAR_TYPE *second_argv[],
- bool substitute_env_args,
- bool quote_args)
+ bool substitute_env_args)
: substitute_env_args_ (substitute_env_args),
iterative_ (false),
argc_ (0),
@@ -141,29 +128,17 @@ ACE_ARGV_T<CHAR_TYPE>::ACE_ARGV_T (CHAR_TYPE *first_argv[],
{
ACE_TRACE ("ACE_ARGV_T::ACE_ARGV_T CHAR_TYPE*[] + CHAR_TYPE *[] to CHAR_TYPE[]");
- int first_argc = 0;
- int second_argc = 0;
+ int first_argc;
+ int second_argc;
- CHAR_TYPE *first_buf = 0;
- CHAR_TYPE *second_buf = 0;
+ CHAR_TYPE *first_buf;
+ CHAR_TYPE *second_buf;
// convert the first argv to a string
- if (first_argv != 0 && first_argv[0] != 0)
- {
- first_argc = ACE_OS::argv_to_string (first_argv,
- first_buf,
- substitute_env_args,
- quote_args);
- }
+ first_argc = this->argv_to_string (first_argv, first_buf);
// convert the second argv to a string
- if (second_argv != 0 && second_argv[0] != 0)
- {
- second_argc = ACE_OS::argv_to_string (second_argv,
- second_buf,
- substitute_env_args,
- quote_args);
- }
+ second_argc = this->argv_to_string (second_argv, second_buf);
// Add the number of arguments in both the argvs.
this->argc_ = first_argc + second_argc;
@@ -182,7 +157,9 @@ ACE_ARGV_T<CHAR_TYPE>::ACE_ARGV_T (CHAR_TYPE *first_argv[],
ACE_OS::strcat (this->buf_, second_buf);
// Delete the first and second buffers
+
delete [] first_buf;
+
delete [] second_buf;
}
@@ -203,7 +180,7 @@ ACE_ARGV_T<CHAR_TYPE>::ACE_ARGV_T (bool substitute_env_args)
template <typename CHAR_TYPE>
int
-ACE_ARGV_T<CHAR_TYPE>::add (const CHAR_TYPE *next_arg, bool quote_arg)
+ACE_ARGV_T<CHAR_TYPE>::add (const CHAR_TYPE *next_arg)
{
// Only allow this to work in the "iterative" verion -- the
// ACE_ARGVs created with the one argument constructor.
@@ -213,25 +190,14 @@ ACE_ARGV_T<CHAR_TYPE>::add (const CHAR_TYPE *next_arg, bool quote_arg)
return -1;
}
- this->length_ += ACE_OS::strlen (next_arg);
- if (quote_arg && ACE_OS::strchr (next_arg, ' ') != 0)
- {
- this->length_ += 2;
- if (ACE_OS::strchr (next_arg, '"') != 0)
- for (const CHAR_TYPE * p = next_arg; *p != '\0'; ++p)
- if (*p == '"') ++this->length_;
- }
- else
- {
- quote_arg = false;
- }
-
// Put the new argument at the end of the queue.
- if (this->queue_.enqueue_tail (ACE_ARGV_Queue_Entry_T<CHAR_TYPE> (next_arg, quote_arg)) == -1)
+ if (this->queue_.enqueue_tail (const_cast <CHAR_TYPE *> (next_arg)) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_LIB_TEXT ("Can't add more to ARGV queue")),
-1);
+ this->length_ += ACE_OS::strlen (next_arg);
+
this->argc_++;
// Wipe argv_ and buf_ away so that they will be recreated if the
@@ -253,10 +219,10 @@ ACE_ARGV_T<CHAR_TYPE>::add (const CHAR_TYPE *next_arg, bool quote_arg)
template <typename CHAR_TYPE>
int
-ACE_ARGV_T<CHAR_TYPE>::add (CHAR_TYPE *argv[], bool quote_args)
+ACE_ARGV_T<CHAR_TYPE>::add (CHAR_TYPE *argv[])
{
for (int i = 0; argv[i] != 0; i++)
- if (this->add (argv[i], quote_args) == -1)
+ if (this->add (argv[i]) == -1)
return -1;
return 0;
@@ -297,58 +263,36 @@ ACE_ARGV_T<CHAR_TYPE>::create_buf_from_queue (void)
-1);
// Get an iterator over the queue
- ACE_Unbounded_Queue_Iterator<ACE_ARGV_Queue_Entry_T<CHAR_TYPE> > iter (this->queue_);
+ ACE_Unbounded_Queue_Iterator<CHAR_TYPE *> iter (this->queue_);
- ACE_ARGV_Queue_Entry_T<CHAR_TYPE> *arg = 0;
+ CHAR_TYPE **arg = 0;
CHAR_TYPE *ptr = this->buf_;
size_t len;
+ int more = 0;
while (!iter.done ())
{
// Get next argument from the queue.
iter.next (arg);
- iter.advance ();
-
- if (arg->quote_arg_)
- {
- *ptr++ = '"';
- if (ACE_OS::strchr (arg->arg_, '"') != 0)
- {
- for (const CHAR_TYPE * p = arg->arg_; *p != '\0'; ++p)
- {
- if (*p == '"') *ptr++ = '\\';
- *ptr++ = *p;
- }
- }
- else
- {
- len = ACE_OS::strlen (arg->arg_);
- // Copy the argument into buf_
- ACE_OS::memcpy ((void *) ptr,
- (const void *) (arg->arg_),
- len * sizeof (CHAR_TYPE));
- // Move the pointer down.
- ptr += len;
- }
- *ptr++ = '"';
- }
- else
- {
- len = ACE_OS::strlen (arg->arg_);
- // Copy the argument into buf_
- ACE_OS::memcpy ((void *) ptr,
- (const void *) (arg->arg_),
- len * sizeof (CHAR_TYPE));
- // Move the pointer down.
- ptr += len;
- }
+
+ more = iter.advance ();
+
+ len = ACE_OS::strlen (*arg);
+
+ // Copy the argument into buf_
+ ACE_OS::memcpy ((void *) ptr,
+ (const void *) (*arg),
+ len * sizeof (CHAR_TYPE));
+ // Move the pointer down.
+ ptr += len;
// Put in an argument separating space.
- *ptr++ = ' ';
+ if (more != 0)
+ *ptr++ = ' ';
}
// Put in the NUL terminator
- ptr[-1] = '\0';
+ *ptr = '\0';
return 0;
}