diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-02-19 04:38:05 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-02-19 04:38:05 +0000 |
commit | 176b195f89af6b2c9e4b5a2f1d282093845502ea (patch) | |
tree | dd77299599499137eeebc812bb8e8014daa20fac | |
parent | a2ae0d5b3bac5e52e882058c2b76b48dfc58000a (diff) | |
download | ATCD-176b195f89af6b2c9e4b5a2f1d282093845502ea.tar.gz |
.
-rw-r--r-- | ChangeLog-99b | 18 | ||||
-rw-r--r-- | ace/ACE.cpp | 10 | ||||
-rw-r--r-- | ace/ACE.h | 2 | ||||
-rw-r--r-- | ace/ARGV.cpp | 130 | ||||
-rw-r--r-- | ace/ARGV.h | 3 | ||||
-rw-r--r-- | ace/ARGV.i | 2 | ||||
-rw-r--r-- | ace/OS.cpp | 173 | ||||
-rw-r--r-- | ace/OS.h | 5 | ||||
-rw-r--r-- | ace/OS.i | 22 |
9 files changed, 206 insertions, 159 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b index f05762951cc..371bc3f7b19 100644 --- a/ChangeLog-99b +++ b/ChangeLog-99b @@ -1,3 +1,21 @@ +Thu Feb 18 21:10:45 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + + * ace/OS.cpp (string_to_argv): We no longer have to special case + for WinCE since this logic has been moved into + ACE_OS::strenvdup(). + + * ace/ACE.cpp: Implemented ACE::strenvdup() using + ACE_OS::strenvdup(). + + * ace/OS: Move the implementation of strenvdup() from ACE to + ACE_OS to remove another dependency from the OS wrappers. + + * ace/ARGV.cpp (string_to_argv): Rewrote this method to use the + new ACE_OS::string_to_argv(). + + * ace/OS.h: Added a string_to_argv() method to ACE_OS to remove + the dependency on ACE_ARGV. + Thu Feb 18 19:21:03 1999 James CE Johnson <jcej@chiroptera.tragus.org> * docs/tutorials/005/client_handler.cpp: Replaced the leading '_' diff --git a/ace/ACE.cpp b/ace/ACE.cpp index 9852fcd8386..2287a07f95b 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -563,21 +563,13 @@ ACE::strrepl (char *s, char search, char replace) return replaced; } -#if !defined (ACE_HAS_WINCE) char * ACE::strenvdup (const char *str) { ACE_TRACE ("ACE::strenvdup"); - char *temp; - - if (str[0] == '$' - && (temp = ACE_OS::getenv (&str[1])) != 0) - return ACE_OS::strdup (temp); - else - return ACE_OS::strdup (str); + return ACE_OS::strenvdup (str); } -#endif /* ACE_HAS_WINCE */ /* diff --git a/ace/ACE.h b/ace/ACE.h index 60d0d7417c5..080428bf1cc 100644 --- a/ace/ACE.h +++ b/ace/ACE.h @@ -452,7 +452,7 @@ public: // Return a dynamically allocated duplicate of <str>, substituting // the environment variable if <str[0] == '$'>. Note that the // pointer is allocated with <ACE_OS::malloc> and must be freed by - // <ACE_OS::free> + // <ACE_OS::free>. #endif /* ACE_HAS_WINCE */ static char *strecpy (char *des, const char *src); diff --git a/ace/ARGV.cpp b/ace/ARGV.cpp index a16fcb61a12..43b8535bcf8 100644 --- a/ace/ARGV.cpp +++ b/ace/ARGV.cpp @@ -40,134 +40,14 @@ ACE_ARGV::string_to_argv (void) { ACE_TRACE ("ACE_ARGV::string_to_argv"); - // Reset the number of arguments - this->argc_ = 0; - - if (this->buf_ == 0) - return -1; - - ASYS_TCHAR *cp = this->buf_; - - // First pass: count arguments. - - // '#' is the start-comment token.. - while (*cp != '\0' && *cp != '#') - { - // Skip whitespace.. - while (ACE_OS::ace_isspace (*cp)) - cp++; - - // Increment count and move to next whitespace.. - if (*cp != '\0') - this->argc_++; - - // Grok quotes.... - if (*cp == '\'' || *cp == '"') - { - ASYS_TCHAR quote = *cp; - - // Scan past the string.. - for (cp++; *cp != '\0' && *cp != quote; cp++) - continue; - - // '\0' implies unmatched quote.. - if (*cp == '\0') - { - ACE_ERROR ((LM_ERROR, - ASYS_TEXT ("unmatched %c detected\n"), quote)); - this->argc_--; - break; - } - else - cp++; - } - else // Skip over non-whitespace.... - while (*cp != '\0' && !ACE_OS::ace_isspace (*cp)) - cp++; - } - - // Second pass: copy arguments. - ASYS_TCHAR arg[ACE_DEFAULT_ARGV_BUFSIZ]; - ASYS_TCHAR *argp = arg; - - // Make sure that the buffer we're copying into is always large - // enough. - if (cp - this->buf_ >= ACE_DEFAULT_ARGV_BUFSIZ) - ACE_NEW_RETURN (argp, - ASYS_TCHAR[cp - this->buf_ + 1], - -1); - - // Make a new argv vector of argc + 1 elements. - ACE_NEW_RETURN (this->argv_, - ASYS_TCHAR *[this->argc_ + 1], - -1); - - ASYS_TCHAR *ptr = this->buf_; - - for (size_t i = 0; i < this->argc_; i++) - { - // Skip whitespace.. - while (ACE_OS::ace_isspace (*ptr)) - ptr++; - - // Copy next argument and move to next whitespace.. - if (*ptr == '\'' || *ptr == '"') - { - ASYS_TCHAR quote = *ptr++; - - for (cp = argp; - *ptr != '\0' && *ptr != quote; - ptr++, cp++) - { - // @@ We can probably remove this since we ensure it's - // big enough earlier! - ACE_ASSERT (unsigned (cp - argp) < ACE_DEFAULT_ARGV_BUFSIZ); - *cp = *ptr; - } - - *cp = '\0'; - if (*ptr == quote) - ptr++; - } - else - { - for (cp = arg; - *ptr && !ACE_OS::ace_isspace (*ptr); - ptr++, cp++) - { - // @@ We can probably remove this since we ensure it's - // big enough earlier! - ACE_ASSERT (unsigned (cp - argp) < ACE_DEFAULT_ARGV_BUFSIZ); - *cp = *ptr; - } - - *cp = '\0'; - } - - // Check for environment variable substitution here. -#if !defined (ACE_HAS_WINCE) - // WinCE doesn't have environment variables so we just skip it. - if (this->substitute_env_args_) - ACE_ALLOCATOR_RETURN (this->argv_[i], - ACE::strenvdup (arg), - -1); - else -#endif /* !ACE_HAS_WINCE */ - ACE_ALLOCATOR_RETURN (this->argv_[i], - ACE_OS::strdup (arg), - -1); - } - - if (argp != arg) - delete [] argp; - - this->argv_[this->argc_] = 0; - - return 0; + return ACE_OS::string_to_argv (this->buf_, + this->argc_, + this->argv_, + this->substitute_env_args_); } int -ACE_ARGV::argv_to_string (ASYS_TCHAR **argv,ASYS_TCHAR *&buf) +ACE_ARGV::argv_to_string (ASYS_TCHAR **argv, ASYS_TCHAR *&buf) { if (argv == 0 || argv[0] == 0) return 0; diff --git a/ace/ARGV.h b/ace/ARGV.h index 9edebe6c1e7..eb4a9593e47 100644 --- a/ace/ARGV.h +++ b/ace/ARGV.h @@ -33,7 +33,8 @@ class ACE_Export ACE_ARGV // environment variable substitutions if necessary. public: // = Initialization and termination. - ACE_ARGV (const ASYS_TCHAR buf[], int substitute_env_args = 1); + ACE_ARGV (const ASYS_TCHAR buf[], + int substitute_env_args = 1); // Converts <buf> into an <argv>-style vector of strings. If // <substitute_env_args> is enabled then we'll substitute the // environment variables for each $ENV encountered in the string. diff --git a/ace/ARGV.i b/ace/ARGV.i index f9fc1e73f12..3619a4e742c 100644 --- a/ace/ARGV.i +++ b/ace/ARGV.i @@ -26,7 +26,7 @@ ACE_ARGV::buf (void) if (this->buf_ == 0 && this->state_ == ITERATIVE) this->create_buf_from_queue (); - return (const ASYS_TCHAR *)this->buf_; + return (const ASYS_TCHAR *) this->buf_; } // Return the arguments in an entry-per-argument array diff --git a/ace/OS.cpp b/ace/OS.cpp index 99327afd9f5..e5040bc759d 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -5,10 +5,6 @@ #include "ace/SString.h" #include "ace/Sched_Params.h" -#if defined (ACE_WIN32) -# include "ace/ARGV.h" -#endif /* ACE_WIN32 */ - // Perhaps we should *always* include ace/OS.i in order to make sure // we can always link against the OS symbols? #if !defined (ACE_HAS_INLINED_OSCALLS) @@ -2136,8 +2132,8 @@ ACE_Thread_Adapter::invoke (void) { // Not spawned by ACE_Thread_Manager, use the old buggy // version. You should seriously consider using - // ACE_Thread_Manager to spawn threads. The following - // code is know to cause some problem. + // ACE_Thread_Manager to spawn threads. The following code + // is know to cause some problem. CWinThread *pThread = ::AfxGetThread (); if (!pThread || pThread->m_nThreadID != ACE_OS::thr_self ()) @@ -2689,10 +2685,11 @@ ACE_OS::thr_create (ACE_THR_FUNC func, if (ACE_BIT_ENABLED (flags, THR_DETACHED)) { # if defined (HPUX_10) - // HP-UX DCE threads' pthread_detach will smash thr_id if it's just given - // as an argument. This will cause ACE_Thread_Manager (if it's doing this - // create) to lose track of the new thread since the ID will be passed back - // equal to 0. So give pthread_detach a junker to scribble on. + // HP-UX DCE threads' pthread_detach will smash thr_id if it's + // just given as an argument. This will cause ACE_Thread_Manager + // (if it's doing this create) to lose track of the new thread + // since the ID will be passed back equal to 0. So give + // pthread_detach a junker to scribble on. ACE_thread_t junker; cma_handle_assign(thr_id, &junker); ::pthread_detach (&junker); @@ -3047,12 +3044,13 @@ ACE_OS::thr_create (ACE_THR_FUNC func, if (! thr_id_provided && thr_id) { if (*thr_id && (*thr_id)[0] == ACE_THR_ID_ALLOCATED) - // *thr_id was allocated by the Thread_Manager. - // ::taskTcb (int tid) returns the address of the WIND_TCB - // (task control block). According to the ::taskSpawn() + // *thr_id was allocated by the Thread_Manager. ::taskTcb + // (int tid) returns the address of the WIND_TCB (task + // control block). According to the ::taskSpawn() // documentation, the name of the new task is stored at // pStackBase, but is that of the current task? If so, it - // might be a bit quicker than this extraction of the tcb . . . + // might be a bit quicker than this extraction of the tcb + // . . . ACE_OS::strncpy (*thr_id + 1, ::taskTcb (tid)->name, 10); else // *thr_id was not allocated by the Thread_Manager. @@ -3122,9 +3120,10 @@ ACE_OS::thr_exit (void *status) } else { - // Not spawned by ACE_Thread_Manager, use the old buggy version. - // You should seriously consider using ACE_Thread_Manager to spawn threads. - // The following code is know to cause some problem. + // Not spawned by ACE_Thread_Manager, use the old buggy + // version. You should seriously consider using + // ACE_Thread_Manager to spawn threads. The following code is + // know to cause some problem. CWinThread *pThread = ::AfxGetThread (); if (!pThread || pThread->m_nThreadID != ACE_OS::thr_self ()) ::_endthreadex ((DWORD) status); @@ -3487,6 +3486,134 @@ ACE_OS::thr_key_detach (void *inst) # endif /* ACE_WIN32 || ACE_HAS_TSS_EMULATION */ } +int +ACE_OS::string_to_argv (ASYS_TCHAR *buf, + size_t &argc, + ASYS_TCHAR **&argv, + int substitute_env_args) +{ + // Reset the number of arguments + argc = 0; + + if (buf == 0) + return -1; + + ASYS_TCHAR *cp = buf; + + // First pass: count arguments. + + // '#' is the start-comment token.. + while (*cp != '\0' && *cp != '#') + { + // Skip whitespace.. + while (ACE_OS::ace_isspace (*cp)) + cp++; + + // Increment count and move to next whitespace.. + if (*cp != '\0') + argc++; + + // Grok quotes.... + if (*cp == '\'' || *cp == '"') + { + ASYS_TCHAR quote = *cp; + + // Scan past the string.. + for (cp++; *cp != '\0' && *cp != quote; cp++) + continue; + + // '\0' implies unmatched quote.. + if (*cp == '\0') + { + ACE_ERROR ((LM_ERROR, + ASYS_TEXT ("unmatched %c detected\n"), + quote)); + argc--; + break; + } + else + cp++; + } + else // Skip over non-whitespace.... + while (*cp != '\0' && !ACE_OS::ace_isspace (*cp)) + cp++; + } + + // Second pass: copy arguments. + ASYS_TCHAR arg[ACE_DEFAULT_ARGV_BUFSIZ]; + ASYS_TCHAR *argp = arg; + + // Make sure that the buffer we're copying into is always large + // enough. + if (cp - buf >= ACE_DEFAULT_ARGV_BUFSIZ) + ACE_NEW_RETURN (argp, + ASYS_TCHAR[cp - buf + 1], + -1); + + // Make a new argv vector of argc + 1 elements. + ACE_NEW_RETURN (argv, + ASYS_TCHAR *[argc + 1], + -1); + + ASYS_TCHAR *ptr = buf; + + for (size_t i = 0; i < argc; i++) + { + // Skip whitespace.. + while (ACE_OS::ace_isspace (*ptr)) + ptr++; + + // Copy next argument and move to next whitespace.. + if (*ptr == '\'' || *ptr == '"') + { + ASYS_TCHAR quote = *ptr++; + + for (cp = argp; + *ptr != '\0' && *ptr != quote; + ptr++, cp++) + { + // @@ We can probably remove this since we ensure it's + // big enough earlier! + ACE_ASSERT (unsigned (cp - argp) < ACE_DEFAULT_ARGV_BUFSIZ); + *cp = *ptr; + } + + *cp = '\0'; + if (*ptr == quote) + ptr++; + } + else + { + for (cp = arg; + *ptr && !ACE_OS::ace_isspace (*ptr); + ptr++, cp++) + { + // @@ We can probably remove this since we ensure it's + // big enough earlier! + ACE_ASSERT (u_int (cp - argp) < ACE_DEFAULT_ARGV_BUFSIZ); + *cp = *ptr; + } + + *cp = '\0'; + } + + // Check for environment variable substitution here. + if (substitute_env_args) + ACE_ALLOCATOR_RETURN (argv[i], + ACE_OS::strenvdup (arg), + -1); + else + ACE_ALLOCATOR_RETURN (argv[i], + ACE_OS::strdup (arg), + -1); + } + + if (argp != arg) + delete [] argp; + + argv[argc] = 0; +} + // Create a contiguous command-line argument buffer with each arg // separated by spaces. @@ -3494,18 +3621,20 @@ pid_t ACE_OS::fork_exec (ASYS_TCHAR *argv[]) { # if defined (ACE_WIN32) - ACE_ARGV argv_buf (argv); + ACE_TCHAR *buf = ACE_OS::string_to_argv (argv); - if (argv_buf.buf () != 0) + if (buf != 0) { PROCESS_INFORMATION process_info; # if !defined (ACE_HAS_WINCE) STARTUPINFO startup_info; - ACE_OS::memset ((void *) &startup_info, 0, sizeof startup_info); + ACE_OS::memset ((void *) &startup_info, + 0, + sizeof startup_info); startup_info.cb = sizeof startup_info; if (::CreateProcess (0, - (LPTSTR) ACE_WIDE_STRING (argv_buf.buf ()), + (LPTSTR) ACE_WIDE_STRING (buf), 0, // No process attributes. 0, // No thread attributes. TRUE, // Allow handle inheritance. @@ -3517,7 +3646,7 @@ ACE_OS::fork_exec (ASYS_TCHAR *argv[]) &process_info)) # else if (::CreateProcess (0, - (LPTSTR) ACE_WIDE_STRING (argv_buf.buf ()), + (LPTSTR) ACE_WIDE_STRING (buf), 0, // No process attributes. 0, // No thread attributes. FALSE, // Can's inherit handles on CE @@ -4459,6 +4459,10 @@ public: static int getopt (int argc, char *const *argv, const char *optstring); + static int string_to_argv (ASYS_TCHAR *buf, + size_t &argc, + ASYS_TCHAR **&argv, + int substitute_env_args = 1); static long sysconf (int); // = A set of wrappers for condition variables. @@ -5234,6 +5238,7 @@ public: const char *t, size_t len); static char *strdup (const char *s); // Uses malloc + static char *strenvdup (const char *str); static size_t strlen (const char *s); static char *strncpy (char *s, const char *t, @@ -10918,3 +10918,25 @@ ACE_OS::fopen_mode_to_open_mode_converter (char x, int &hmode) } } #endif /* ACE_WIN32 */ + +// Return a dynamically allocated duplicate of <str>, substituting the +// environment variable if <str[0] == '$'>. Note that the pointer is +// allocated with <ACE_OS::malloc> and must be freed by +// <ACE_OS::free>. + +char * +ACE_OS::strenvdup (const char *str) +{ +#if defined (ACE_HAS_WINCE) + // WinCE doesn't have environment variables so we just skip it. + return ACE_OS::strdup (str); +#else + char *temp; + + if (str[0] == '$' + && (temp = ACE_OS::getenv (&str[1])) != 0) + return ACE_OS::strdup (temp); + else + return ACE_OS::strdup (str); +#endif /* ACE_HAS_WINCE */ +} |