From 54a5b4458c72e7276eb6947205a41c6df8ecc79d Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Tue, 19 May 2009 10:21:23 +0000 Subject: --- ACE/contrib/FaCE/CE_ARGV.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++ ACE/contrib/FaCE/CE_ARGV.h | 90 ++++++++++++++++++++++++++++++++ ACE/contrib/FaCE/CE_ARGV2.CPP | 118 ------------------------------------------ ACE/contrib/FaCE/CE_ARGV2.H | 90 -------------------------------- 4 files changed, 208 insertions(+), 208 deletions(-) create mode 100644 ACE/contrib/FaCE/CE_ARGV.cpp create mode 100644 ACE/contrib/FaCE/CE_ARGV.h delete mode 100644 ACE/contrib/FaCE/CE_ARGV2.CPP delete mode 100644 ACE/contrib/FaCE/CE_ARGV2.H (limited to 'ACE/contrib') diff --git a/ACE/contrib/FaCE/CE_ARGV.cpp b/ACE/contrib/FaCE/CE_ARGV.cpp new file mode 100644 index 00000000000..6b97a30b640 --- /dev/null +++ b/ACE/contrib/FaCE/CE_ARGV.cpp @@ -0,0 +1,118 @@ +// $Id$ + +#include "CE_ARGV.H" + + +CE_ARGV::CE_ARGV(wchar_t* cmdLine) +: ce_argv_(0) +, ce_argc_(0) +{ + const wchar_t* dummyArgv = L"root"; // dummy for the first argv + const wchar_t* separator = L" "; // blank space is a separator + + int formattedCmdLineLength = wcslen(dummyArgv) + + wcslen(separator) + + 1; // 1 is for the NULL at the end + + if (wcslen(cmdLine) > 0) { + formattedCmdLineLength += wcslen(cmdLine); + formattedCmdLineLength += wcslen(separator); + } + + // formattedCmdLine will have dummyArgv and a separator at the beginning of cmdLine + // and a separator at the end to generalize format and reduce the amount of code + wchar_t* formattedCmdLine = 0; + formattedCmdLine = new wchar_t[formattedCmdLineLength]; + + wcscpy(formattedCmdLine, dummyArgv); + wcscat(formattedCmdLine, separator); + + int max_possible_argc = 1; // start with 1 because of the dummyArgv at the beginning + + if (wcslen(cmdLine) > 0) { + int formattedPos = wcslen(formattedCmdLine); + int cmdLineLength = wcslen(cmdLine); + + // Inside of this for loop, it does same thing as strcat except it + // checks and puts only one single white space between two argv entries. + for (int i = 0; i < cmdLineLength; ++i) { + if (iswspace(cmdLine[i]) != 0) { + ++max_possible_argc; // counting the number of white spaces + } + + formattedCmdLine[formattedPos++] = cmdLine[i]; + + if (iswspace(cmdLine[i]) != 0) { + // make sure there is only one white space between two argv entries. + while ((i < cmdLineLength) && (iswspace(cmdLine[i + 1]) != 0)) { + ++i; + } + } + } + + formattedCmdLine[formattedPos] = 0; + wcscat(formattedCmdLine, separator); // make sure formattedCmdLine ends with a blank + } + + int formattedCmdLength = wcslen(formattedCmdLine); + + bool insideQuotation = false; + int* argv_strlen = 0; + int entry_size = 0; + argv_strlen = new int[max_possible_argc]; + + // determine argc + for (int i = 0; i < formattedCmdLength; ++i) { + if (formattedCmdLine[i] == '\\') { + ++i; // ignore the following character + ++entry_size; + } + else if (formattedCmdLine[i] == '"') { + insideQuotation = !insideQuotation; + } + else if ((!insideQuotation) && (iswspace(formattedCmdLine[i]) != 0)) { + // new argv entry end found + argv_strlen[ce_argc_++] = entry_size; // cache the size of this entry + entry_size = 0; + } + else { + ++entry_size; + } + } + + ce_argv_ = new wchar_t*[ce_argc_ + 1]; + ce_argv_[ce_argc_] = 0; // Last command line entry is a NULL. + + for (int j = 0, cmdLinePos = 0; j < ce_argc_; ++j, ++cmdLinePos) { + int length = argv_strlen[j]; + + ce_argv_[j] = new wchar_t[length + 1]; + ce_argv_[j][length] = 0; // string termination null + + if (iswspace(formattedCmdLine[cmdLinePos]) != 0) { + // This is where prior argv has trailing '"' at the end. + ++cmdLinePos; + } + + for (int n = 0; n < length; ++n, ++cmdLinePos) { + if ((formattedCmdLine[cmdLinePos] == '\\') || (formattedCmdLine[cmdLinePos] == '"')) { + ++cmdLinePos; + } + + ce_argv_[j][n] = formattedCmdLine[cmdLinePos]; + } + } + + delete argv_strlen; + delete formattedCmdLine; +} + + +CE_ARGV::~CE_ARGV(void) +{ + for (int i = 0; i < ce_argc_; ++i) { + delete [] ce_argv_[i]; + } + + delete [] ce_argv_; +} diff --git a/ACE/contrib/FaCE/CE_ARGV.h b/ACE/contrib/FaCE/CE_ARGV.h new file mode 100644 index 00000000000..716887ae1a8 --- /dev/null +++ b/ACE/contrib/FaCE/CE_ARGV.h @@ -0,0 +1,90 @@ +// -*- C++ -*- +//============================================================================= +/** + * @file CE_ARGV.H + * + * $Id$ + * + * @author Si Mong Park + */ +//============================================================================= + +#ifndef CE_ARGV_H +#define CE_ARGV_H + +#include + + +/** + * @class CE_ARGV + * + * @brief This class is to hash input parameters, argc and argv, for WinCE platform. + * + * Since WinCE only supports wchar_t as an input from OS, some implementation detail, + * especially for CORBA spec, will not support wchar_t (wchar_t) type parameter. + * Moreover, WinCE's input parameter type is totally different than any other OS; + * all command line parameters will be stored in a single wide-character string with + * each unit parameter divided by blank space, and it does not provide the name of + * executable (generally known as argv[0]). + * This class is to convert CE's command line parameters and simulate as in the same + * manner as other general platforms, adding 'root' as a first argc, which is for the + * name of executable in other OS. + */ +class CE_ARGV +{ +public: + /** + * Ctor accepts CE command line as a parameter. + */ + CE_ARGV(wchar_t* cmdLine); + + /** + * Default Dtor that deletes any memory allocated for the converted string. + */ + ~CE_ARGV(void); + + /** + * Returns the number of command line parameters, same as argc on Unix. + */ + int argc(void); + + /** + * Returns the 'char**' that contains the converted command line parameters. + */ + wchar_t** const argv(void); + +private: + /** + * Copy Ctor is not allowed. + */ + CE_ARGV(void); + + /** + * Copy Ctor is not allowed. + */ + CE_ARGV(CE_ARGV&); + + /** + * Pointer of converted command line parameters. + */ + wchar_t** ce_argv_; + + /** + * Integer that is same as argc on other OS's. + */ + int ce_argc_; +}; + + +inline int CE_ARGV::argc() +{ + return ce_argc_; +} + + +inline wchar_t** const CE_ARGV::argv() +{ + return ce_argv_; +} + +#endif // CE_ARGV_H diff --git a/ACE/contrib/FaCE/CE_ARGV2.CPP b/ACE/contrib/FaCE/CE_ARGV2.CPP deleted file mode 100644 index 6b97a30b640..00000000000 --- a/ACE/contrib/FaCE/CE_ARGV2.CPP +++ /dev/null @@ -1,118 +0,0 @@ -// $Id$ - -#include "CE_ARGV.H" - - -CE_ARGV::CE_ARGV(wchar_t* cmdLine) -: ce_argv_(0) -, ce_argc_(0) -{ - const wchar_t* dummyArgv = L"root"; // dummy for the first argv - const wchar_t* separator = L" "; // blank space is a separator - - int formattedCmdLineLength = wcslen(dummyArgv) + - wcslen(separator) + - 1; // 1 is for the NULL at the end - - if (wcslen(cmdLine) > 0) { - formattedCmdLineLength += wcslen(cmdLine); - formattedCmdLineLength += wcslen(separator); - } - - // formattedCmdLine will have dummyArgv and a separator at the beginning of cmdLine - // and a separator at the end to generalize format and reduce the amount of code - wchar_t* formattedCmdLine = 0; - formattedCmdLine = new wchar_t[formattedCmdLineLength]; - - wcscpy(formattedCmdLine, dummyArgv); - wcscat(formattedCmdLine, separator); - - int max_possible_argc = 1; // start with 1 because of the dummyArgv at the beginning - - if (wcslen(cmdLine) > 0) { - int formattedPos = wcslen(formattedCmdLine); - int cmdLineLength = wcslen(cmdLine); - - // Inside of this for loop, it does same thing as strcat except it - // checks and puts only one single white space between two argv entries. - for (int i = 0; i < cmdLineLength; ++i) { - if (iswspace(cmdLine[i]) != 0) { - ++max_possible_argc; // counting the number of white spaces - } - - formattedCmdLine[formattedPos++] = cmdLine[i]; - - if (iswspace(cmdLine[i]) != 0) { - // make sure there is only one white space between two argv entries. - while ((i < cmdLineLength) && (iswspace(cmdLine[i + 1]) != 0)) { - ++i; - } - } - } - - formattedCmdLine[formattedPos] = 0; - wcscat(formattedCmdLine, separator); // make sure formattedCmdLine ends with a blank - } - - int formattedCmdLength = wcslen(formattedCmdLine); - - bool insideQuotation = false; - int* argv_strlen = 0; - int entry_size = 0; - argv_strlen = new int[max_possible_argc]; - - // determine argc - for (int i = 0; i < formattedCmdLength; ++i) { - if (formattedCmdLine[i] == '\\') { - ++i; // ignore the following character - ++entry_size; - } - else if (formattedCmdLine[i] == '"') { - insideQuotation = !insideQuotation; - } - else if ((!insideQuotation) && (iswspace(formattedCmdLine[i]) != 0)) { - // new argv entry end found - argv_strlen[ce_argc_++] = entry_size; // cache the size of this entry - entry_size = 0; - } - else { - ++entry_size; - } - } - - ce_argv_ = new wchar_t*[ce_argc_ + 1]; - ce_argv_[ce_argc_] = 0; // Last command line entry is a NULL. - - for (int j = 0, cmdLinePos = 0; j < ce_argc_; ++j, ++cmdLinePos) { - int length = argv_strlen[j]; - - ce_argv_[j] = new wchar_t[length + 1]; - ce_argv_[j][length] = 0; // string termination null - - if (iswspace(formattedCmdLine[cmdLinePos]) != 0) { - // This is where prior argv has trailing '"' at the end. - ++cmdLinePos; - } - - for (int n = 0; n < length; ++n, ++cmdLinePos) { - if ((formattedCmdLine[cmdLinePos] == '\\') || (formattedCmdLine[cmdLinePos] == '"')) { - ++cmdLinePos; - } - - ce_argv_[j][n] = formattedCmdLine[cmdLinePos]; - } - } - - delete argv_strlen; - delete formattedCmdLine; -} - - -CE_ARGV::~CE_ARGV(void) -{ - for (int i = 0; i < ce_argc_; ++i) { - delete [] ce_argv_[i]; - } - - delete [] ce_argv_; -} diff --git a/ACE/contrib/FaCE/CE_ARGV2.H b/ACE/contrib/FaCE/CE_ARGV2.H deleted file mode 100644 index 716887ae1a8..00000000000 --- a/ACE/contrib/FaCE/CE_ARGV2.H +++ /dev/null @@ -1,90 +0,0 @@ -// -*- C++ -*- -//============================================================================= -/** - * @file CE_ARGV.H - * - * $Id$ - * - * @author Si Mong Park - */ -//============================================================================= - -#ifndef CE_ARGV_H -#define CE_ARGV_H - -#include - - -/** - * @class CE_ARGV - * - * @brief This class is to hash input parameters, argc and argv, for WinCE platform. - * - * Since WinCE only supports wchar_t as an input from OS, some implementation detail, - * especially for CORBA spec, will not support wchar_t (wchar_t) type parameter. - * Moreover, WinCE's input parameter type is totally different than any other OS; - * all command line parameters will be stored in a single wide-character string with - * each unit parameter divided by blank space, and it does not provide the name of - * executable (generally known as argv[0]). - * This class is to convert CE's command line parameters and simulate as in the same - * manner as other general platforms, adding 'root' as a first argc, which is for the - * name of executable in other OS. - */ -class CE_ARGV -{ -public: - /** - * Ctor accepts CE command line as a parameter. - */ - CE_ARGV(wchar_t* cmdLine); - - /** - * Default Dtor that deletes any memory allocated for the converted string. - */ - ~CE_ARGV(void); - - /** - * Returns the number of command line parameters, same as argc on Unix. - */ - int argc(void); - - /** - * Returns the 'char**' that contains the converted command line parameters. - */ - wchar_t** const argv(void); - -private: - /** - * Copy Ctor is not allowed. - */ - CE_ARGV(void); - - /** - * Copy Ctor is not allowed. - */ - CE_ARGV(CE_ARGV&); - - /** - * Pointer of converted command line parameters. - */ - wchar_t** ce_argv_; - - /** - * Integer that is same as argc on other OS's. - */ - int ce_argc_; -}; - - -inline int CE_ARGV::argc() -{ - return ce_argc_; -} - - -inline wchar_t** const CE_ARGV::argv() -{ - return ce_argv_; -} - -#endif // CE_ARGV_H -- cgit v1.2.1