#include "ace/Get_Opt.h"
#include "ace/ACE.h"
#include "ace/Log_Msg.h"
#include "ace/SString.h"
#include "ace/OS_Memory.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_ctype.h"
#include "ace/OS_NS_stdlib.h"
Go to the source code of this file.
Functions | |
ACE_RCSID (ace, Get_Opt,"$Id: Get_Opt.cpp 81840 2008-06-05 13:46:45Z sma $") 1 ACE_Get_Opt |
ACE_RCSID | ( | ace | , | |
Get_Opt | , | |||
"$Id: Get_Opt.cpp 81840 2008-06-05 13:46:45Z sma $" | ||||
) |
Definition at line 17 of file Get_Opt.cpp.
: Get_Opt.cpp 81840 2008-06-05 13:46:45Z sma $") /* * Copyright (c) 1987, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Dieter Baron and Thomas Klausner. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_ALLOC_HOOK_DEFINE(ACE_Get_Opt) #ifdef ACE_USES_WCHAR void ACE_Get_Opt::ACE_Get_Opt_Init (const ACE_TCHAR *optstring) #else ACE_Get_Opt::ACE_Get_Opt (int argc, ACE_TCHAR **argv, const ACE_TCHAR *optstring, int skip, int report_errors, int ordering, int long_only) : argc_ (argc), argv_ (argv), optind (skip), opterr (report_errors), optarg (0), optstring_ (0), long_only_ (long_only), has_colon_ (0), last_option_ (0), nextchar_ (0), optopt_ (0), ordering_ (ordering), nonopt_start_ (optind), nonopt_end_ (optind), long_option_ (0) #endif { ACE_TRACE ("ACE_Get_Opt::ACE_Get_Opt"); ACE_NEW (this->optstring_, ACE_TString (optstring)); ACE_NEW (this->last_option_, ACE_TString (ACE_TEXT (""))); // First check to see if POSIXLY_CORRECT was set. // Win32 is the only platform capable of wide-char env var. #if defined (ACE_WIN32) const ACE_TCHAR *env_check = ACE_TEXT ("POSIXLY_CORRECT"); #else const char *env_check = "POSIXLY_CORRECT"; #endif if (ACE_OS::getenv (env_check) != 0) this->ordering_ = REQUIRE_ORDER; // Now, check to see if any or the following were passed at // the begining of optstring: '+' same as POSIXLY_CORRECT; // '-' turns off POSIXLY_CORRECT; or ':' which signifies we // should return ':' if a parameter is missing for an option. // We use a loop here, since a combination of "{+|-}:" in any // order should be legal. int done = 0; int offset = 0; while (!done) { switch (optstring[offset++]) { case '+': this->ordering_ = REQUIRE_ORDER; break; case '-': this->ordering_ = RETURN_IN_ORDER; break; case ':': this->has_colon_ = 1; break; default: // Quit as soon as we see something else... done = 1; break; } } }