Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Get_Opt.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // Get_Opt.cpp
00003 // $Id: Get_Opt.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $
00004 
00005 #include "ace/Get_Opt.h"
00006 #include "ace/Log_Msg.h"
00007 
00008 #if !defined (__ACE_INLINE__)
00009 #include "ace/Get_Opt.i"
00010 #endif /* __ACE_INLINE__ */
00011 
00012 ACE_RCSID(ace, Get_Opt, "$Id: Get_Opt.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $")
00013 
00014 /*
00015  * Copyright (c) 1987, 1993, 1994
00016  *      The Regents of the University of California.  All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions
00020  * are met:
00021  * 1. Redistributions of source code must retain the above copyright
00022  *    notice, this list of conditions and the following disclaimer.
00023  * 2. Redistributions in binary form must reproduce the above copyright
00024  *    notice, this list of conditions and the following disclaimer in the
00025  *    documentation and/or other materials provided with the distribution.
00026  * 3. All advertising materials mentioning features or use of this software
00027  *    must display the following acknowledgement:
00028  *      This product includes software developed by the University of
00029  *      California, Berkeley and its contributors.
00030  * 4. Neither the name of the University nor the names of its contributors
00031  *    may be used to endorse or promote products derived from this software
00032  *    without specific prior written permission.
00033  *
00034  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00035  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00036  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00037  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00038  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00039  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00040  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00041  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00042  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00043  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00044  * SUCH DAMAGE.
00045  */
00046 
00047 /*-
00048  * Copyright (c) 2000 The NetBSD Foundation, Inc.
00049  * All rights reserved.
00050  *
00051  * This code is derived from software contributed to The NetBSD Foundation
00052  * by Dieter Baron and Thomas Klausner.
00053  *
00054  * Redistribution and use in source and binary forms, with or without
00055  * modification, are permitted provided that the following conditions
00056  * are met:
00057  * 1. Redistributions of source code must retain the above copyright
00058  *    notice, this list of conditions and the following disclaimer.
00059  * 2. Redistributions in binary form must reproduce the above copyright
00060  *    notice, this list of conditions and the following disclaimer in the
00061  *    documentation and/or other materials provided with the distribution.
00062  * 3. All advertising materials mentioning features or use of this software
00063  *    must display the following acknowledgement:
00064  *        This product includes software developed by the NetBSD
00065  *        Foundation, Inc. and its contributors.
00066  * 4. Neither the name of The NetBSD Foundation nor the names of its
00067  *    contributors may be used to endorse or promote products derived
00068  *    from this software without specific prior written permission.
00069  *
00070  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
00071  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00072  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00073  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
00074  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00075  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00076  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00077  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00078  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00079  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00080  * POSSIBILITY OF SUCH DAMAGE.
00081  */
00082 
00083 ACE_ALLOC_HOOK_DEFINE(ACE_Get_Opt)
00084 
00085 ACE_Get_Opt::ACE_Get_Opt (int argc,
00086                           ACE_TCHAR **argv,
00087                           const ACE_TCHAR *optstring,
00088                           int skip,
00089                           int report_errors,
00090                           int ordering,
00091                           int long_only)
00092   : argc_ (argc),
00093     argv_ (argv),
00094     optind (skip),
00095     opterr (report_errors),
00096     optarg (0),
00097     optstring_ (optstring),
00098     long_only_ (long_only),
00099     has_colon_ (0),
00100     nextchar_ (0),
00101     optopt_ (0),
00102     ordering_ (ordering),
00103     nonopt_start_ (optind),
00104     nonopt_end_ (optind),
00105     long_option_ (0)
00106 {
00107   ACE_TRACE ("ACE_Get_Opt::ACE_Get_Opt");
00108 
00109   // First check to see if POSIXLY_CORRECT was set.
00110   if (ACE_OS::getenv (ACE_LIB_TEXT ("POSIXLY_CORRECT")) != 0)
00111     this->ordering_ = REQUIRE_ORDER;
00112 
00113   // Now, check to see if any or the following were passed at
00114   // the begining of optstring: '+' same as POSIXLY_CORRECT;
00115   // '-' turns off POSIXLY_CORRECT; or ':' which signifies we
00116   // should return ':' if a parameter is missing for an option.
00117   // We use a loop here, since a combination of "{+|-}:" in any
00118   // order should be legal.
00119   int done  = 0;
00120   int offset = 0;
00121   while (!done)
00122     {
00123       switch (optstring[offset++])
00124         {
00125         case '+':
00126           this->ordering_ = REQUIRE_ORDER;
00127           break;
00128         case '-':
00129           this->ordering_ = RETURN_IN_ORDER;
00130           break;
00131         case ':':
00132           this->has_colon_ = 1;
00133           break;
00134         default:
00135           // Quit as soon as we see something else...
00136           done = 1;
00137           break;
00138         }
00139     }
00140 }
00141 
00142 ACE_Get_Opt::~ACE_Get_Opt (void)
00143 {
00144   ACE_TRACE ("ACE_Get_Opt::~ACE_Get_Opt");
00145 
00146   size_t i = 0;
00147   size_t size = this->long_opts_.size ();
00148   ACE_Get_Opt_Long_Option *option = 0;
00149   for (i = 0; i < size; ++i)
00150     {
00151      int retval = this->long_opts_.get (option, i);
00152       if (retval != 0)
00153         {
00154           // Should never happen.
00155           retval = 0;
00156           continue;
00157         }
00158       if (option)
00159         {
00160           delete option;
00161           option = 0;
00162         }
00163     }
00164 }
00165 
00166 int
00167 ACE_Get_Opt::nextchar_i (void)
00168 {
00169   ACE_TRACE ("ACE_Get_Opt::nextchar_i");
00170 
00171   if (this->ordering_ == PERMUTE_ARGS)
00172     if (this->permute () == EOF)
00173       return EOF;
00174 
00175   // Update scanning pointer.
00176   if (this->optind >= this->argc_)
00177     {
00178       // We're done...
00179       this->nextchar_ = 0;
00180       return EOF;
00181     }
00182   else if (*(this->nextchar_ = this->argv_[this->optind]) != '-'
00183             || this->nextchar_[1] == '\0')
00184     {
00185       // We didn't get an option.
00186 
00187       if (this->ordering_ == REQUIRE_ORDER
00188           || this->ordering_ == PERMUTE_ARGS)
00189         // If we permuted or require the options to be in order, we're done.
00190         return EOF;
00191 
00192       // It must be RETURN_IN_ORDER...
00193       this->optarg = this->argv_[this->optind++];
00194       this->nextchar_ = 0;
00195       return 1;
00196     }
00197   else if (this->nextchar_[1] != 0
00198            && *++this->nextchar_ == '-'
00199            && this->nextchar_[1] == 0)
00200     {
00201       // Found "--" so we're done...
00202       ++this->optind;
00203       this->nextchar_ = 0;
00204       return EOF;
00205     }
00206 
00207   // If it's a long option, and we allow long options advance nextchar_.
00208   if (*this->nextchar_ == '-' && this->long_opts_.size () != 0)
00209     this->nextchar_++;
00210 
00211   return 0;
00212 }
00213 
00214 int
00215 ACE_Get_Opt::long_option_i (void)
00216 {
00217   ACE_TRACE ("ACE_Get_Opt::long_option_i");
00218 
00219   ACE_Get_Opt_Long_Option *p;
00220   ACE_TCHAR *s = this->nextchar_;
00221   int hits = 0;
00222   int exact = 0;
00223   ACE_Get_Opt_Long_Option *pfound = 0;
00224   int indfound = 0;
00225 
00226   // Advance to the end of the long option name so we can use
00227   // it to get the length for a string compare.
00228   while (*s && *s != '=')
00229     s++;
00230 
00231   size_t len = s - this->nextchar_;
00232   size_t size = this->long_opts_.size ();
00233   u_int option_index = 0;
00234   for (option_index = 0; option_index < size ; option_index++)
00235     {
00236       p = this->long_opts_[option_index];
00237       ACE_ASSERT (p);
00238 
00239       if (!ACE_OS::strncmp (p->name_, this->nextchar_, len))
00240         {
00241           // Got at least a partial match.
00242           pfound = p;
00243           indfound = option_index;
00244           hits += 1;
00245           if (len == ACE_OS::strlen(p->name_))
00246             {
00247               // And in fact, it an exact match, so let's use it.
00248               exact = 1;
00249               break;
00250             }
00251         }
00252     }
00253 
00254   if ((hits > 1) && !exact)
00255     {
00256       // Great, we found a match, but unfortunately we found more than
00257       // one and it wasn't exact.
00258       if (this->opterr)
00259         ACE_ERROR ((LM_ERROR,
00260                     ACE_LIB_TEXT ("%s: option `%s' is ambiguous\n"),
00261                     this->argv_[0], this->argv_[this->optind]));
00262       this->nextchar_ = 0;
00263       this->optind++;
00264       return '?';
00265     }
00266 
00267   if (pfound != 0)
00268     {
00269       // Okay, we found a good one (either a single hit or an exact match).
00270       option_index = indfound;
00271       this->optind++;
00272       if (*s)
00273         {
00274           // s must point to '=' which means there's an argument (well
00275           // close enough).
00276           if (pfound->has_arg_ != NO_ARG)
00277             // Good, we want an argument and here it is.
00278             this->optarg = ++s;
00279           else
00280             {
00281               // Whoops, we've got what looks like an argument, but we
00282               // don't want one.
00283               if (this->opterr)
00284                   ACE_ERROR
00285                     ((LM_ERROR,
00286                       ACE_LIB_TEXT ("%s: long option `--%s' doesn't allow an argument\n"),
00287                       this->argv_[0], pfound->name_));
00288               // The spec doesn't cover this, so we keep going and the program
00289               // doesn't know we ignored an argument if opt_err is off!!!
00290             }
00291         }
00292       else if (pfound->has_arg_ == ARG_REQUIRED)
00293         {
00294           // s didn't help us, but we need an argument. Note that
00295           // optional arguments for long options must use the "=" syntax,
00296           // so we won't get here in that case.
00297           if (this->optind < this->argc_)
00298             // We still have some elements left, so use the next one.
00299             this->optarg = this->argv_[this->optind++];
00300           else
00301             {
00302               // All out of elements, so we have to punt...
00303               if (this->opterr)
00304                 ACE_ERROR ((LM_ERROR,
00305                             ACE_LIB_TEXT ("%s: long option '--%s' requires an argument\n"),
00306                             this->argv_[0], pfound->name_));
00307               this->nextchar_ = 0;
00308               this->optopt_ = pfound->val_;   // Remember matching short equiv
00309               return this->has_colon_ ? ':' : '?';
00310             }
00311         }
00312       this->nextchar_ = 0;
00313       this->long_option_ = pfound;
00314       // Since val_ has to be either a valid short option or 0, this works
00315       // great.  If the user really wants to know if a long option was passed.
00316       this->optopt_ = pfound->val_;
00317       return pfound->val_;
00318     }
00319   if (!this->long_only_ || this->argv_[this->optind][1] == '-'
00320       || this->optstring_.find (*this->nextchar_) == ACE_TString::npos)
00321     {
00322       // Okay, we couldn't find a long option.  If it isn't long_only (which
00323       // means try the long first, and if not found try the short) or a long
00324       // signature was passed, e.g. "--", or it's not a short (not sure when
00325       // this could happen) it's an error.
00326       if (this->opterr)
00327         ACE_ERROR ((LM_ERROR,
00328                     ACE_LIB_TEXT ("%s: illegal long option '--%s'\n"),
00329                     this->argv_[0], this->nextchar_));
00330       this->nextchar_ = 0;
00331       this->optind++;
00332       return '?';
00333     }
00334   return this->short_option_i ();
00335 }
00336 
00337 int
00338 ACE_Get_Opt::short_option_i (void)
00339 {
00340   ACE_TRACE ("ACE_Get_Opt::short_option_i");
00341 
00342   /* Look at and handle the next option-character.  */
00343   ACE_TCHAR opt = *this->nextchar_++;
00344   ACE_TCHAR *oli = 0;
00345   oli = ACE_const_cast (ACE_TCHAR*, ACE_OS::strchr (this->optstring_.c_str (), opt));
00346 
00347   /* Increment `optind' when we start to process its last character.  */
00348   if (*this->nextchar_ == '\0')
00349     ++this->optind;
00350 
00351   if (oli == 0 || opt == ':')
00352     {
00353       if (this->opterr)
00354         ACE_ERROR ((LM_ERROR,
00355                     ACE_LIB_TEXT ("%s: illegal short option -- %c\n"),
00356                     this->argv_[0], opt));
00357       return '?';
00358     }
00359   if (opt == 'W' && oli[1] == ';')
00360     {
00361       if (this->nextchar_[0] == 0)
00362         this->nextchar_ = this->argv_[this->optind];
00363       return long_option_i ();
00364     }
00365   this->optopt_ = oli[0];      // Remember the option that matched
00366   if (oli[1] == ':')
00367     {
00368       if (oli[2] == ':')
00369         {
00370           // Takes an optional argument, and since short option args must
00371           // must follow directly in the same argument, a NULL nextchar_
00372           // means we didn't get one.
00373           if (*this->nextchar_ != '\0')
00374             {
00375               this->optarg = this->nextchar_;
00376               this->optind++;
00377             }
00378           else
00379             this->optarg = 0;
00380           this->nextchar_ = 0;
00381         }
00382       else
00383         {
00384           // Takes a required argument.
00385           if (*this->nextchar_ != '\0')
00386             {
00387               // Found argument in same argv-element.
00388               this->optarg = this->nextchar_;
00389               this->optind++;
00390             }
00391           else if (this->optind == this->argc_)
00392             {
00393               // Ran out of arguments before finding required argument.
00394               if (this->opterr)
00395                 ACE_ERROR ((LM_ERROR,
00396                             ACE_LIB_TEXT ("%s: short option requires an argument -- %c\n"),
00397                             this->argv_[0], opt));
00398               opt = this->has_colon_ ? ':' : '?';
00399             }
00400           else
00401             // Use the next argv-element as the argument.
00402             this->optarg = this->argv_[this->optind++];
00403           this->nextchar_ = 0;
00404         }
00405     }
00406   return opt;
00407 }
00408 
00409 int
00410 ACE_Get_Opt::operator () (void)
00411 {
00412   ACE_TRACE ("ACE_Get_Opt_Long::operator");
00413 
00414   // First of all, make sure we reinitialize any pointers..
00415   this->optarg = 0;
00416   this->long_option_ = 0;
00417 
00418   if (this->argv_ == 0)
00419     {
00420       // It can happen, e.g., on VxWorks.
00421       this->optind = 0;
00422       return -1;
00423     }
00424 
00425   // We check this because we can string short options together if the
00426   // preceding one doesn't take an argument.
00427   if (this->nextchar_ == 0 || *this->nextchar_ == '\0')
00428     {
00429       int retval = this->nextchar_i ();
00430       if (retval != 0)
00431         return retval;
00432     }
00433 
00434   if (((this->argv_[this->optind][0] == '-')
00435        && (this->argv_[this->optind][1] == '-')) || this->long_only_)
00436     return this->long_option_i ();
00437 
00438   return this->short_option_i ();
00439 }
00440 
00441 int
00442 ACE_Get_Opt::long_option (const ACE_TCHAR *name,
00443                           OPTION_ARG_MODE has_arg)
00444 {
00445   ACE_TRACE ("ACE_Get_Opt::long_option (const ACE_TCHAR *name, OPTION_ARG_MODE has_arg)");
00446   return this->long_option (name, 0, has_arg);
00447 }
00448 
00449 int
00450 ACE_Get_Opt::long_option (const ACE_TCHAR *name,
00451                           int short_option,
00452                           OPTION_ARG_MODE has_arg)
00453 {
00454   ACE_TRACE ("ACE_Get_Opt::long_option (const ACE_TCHAR *name, int short_option, OPTION_ARG_MODE has_arg)");
00455 
00456   // We only allow valid alpha-numeric characters as short options.
00457   // If short_options is not a valid alpha-numeric, we can still return it
00458   // when the long option is found, but won't allow the caller to pass it on
00459   // the command line (how could they?).  The special case is 0, but since
00460   // we always return it, we let the caller worry about that.
00461 #if defined (_MSC_VER) && (_MSC_VER >= 1300)
00462   // For MSVC 7.x, we need to prevent "illegal" character getting into
00463   // isalnum, otherwise, it will crash the program.
00464   if (short_option > 0 &&
00465       short_option < 256 &&
00466       isalnum (short_option) != 0)
00467 #else
00468   if (isalnum (short_option) != 0)
00469 #endif /* _MSC_VER && _MSC_VER >= 1300 */
00470     {
00471       // If the short_option already exists, make sure it matches, otherwise
00472       // add it.
00473       ACE_TCHAR *s = 0;
00474       if ((s = ACE_const_cast (ACE_TCHAR*,
00475                                ACE_OS::strchr (this->optstring_.c_str (), short_option))) != 0)
00476         {
00477           // Short option exists, so verify the argument options
00478           if (s[1] == ':')
00479             {
00480               if (s[2] == ':')
00481                 {
00482                   if (has_arg != ARG_OPTIONAL)
00483                     {
00484                       if (this->opterr)
00485                         ACE_ERROR
00486                           ((LM_ERROR,
00487                             ACE_LIB_TEXT ("Existing short option '%c' takes ")
00488                             ACE_LIB_TEXT ("optional argument; adding %s ")
00489                             ACE_LIB_TEXT ("requires ARG_OPTIONAL\n"),
00490                             short_option, name));
00491                       return -1;
00492                     }
00493                 }
00494               else
00495                 if (has_arg != ARG_REQUIRED)
00496                   {
00497                     if (this->opterr)
00498                       ACE_ERROR
00499                         ((LM_ERROR,
00500                           ACE_LIB_TEXT ("Existing short option '%c' requires ")
00501                           ACE_LIB_TEXT ("an argument; adding %s ")
00502                           ACE_LIB_TEXT ("requires ARG_REQUIRED\n"),
00503                           short_option, name));
00504                     return -1;
00505                   }
00506             }
00507           else if (has_arg != NO_ARG)
00508             {
00509               if (this->opterr)
00510                 ACE_ERROR
00511                   ((LM_ERROR,
00512                     ACE_LIB_TEXT ("Existing short option '%c' does not ")
00513                     ACE_LIB_TEXT ("accept an argument; adding %s ")
00514                     ACE_LIB_TEXT ("requires NO_ARG\n"),
00515                     short_option, name));
00516               return -1;
00517             }
00518         }
00519       else
00520         {
00521           // Didn't find short option, so add it...
00522           this->optstring_ += (ACE_TCHAR) short_option;
00523           if (has_arg == ARG_REQUIRED)
00524             this->optstring_ += ACE_LIB_TEXT (":");
00525           else if (has_arg == ARG_OPTIONAL)
00526             this->optstring_ += ACE_LIB_TEXT ("::");
00527         }
00528     }
00529 
00530   ACE_Get_Opt_Long_Option *option =
00531     new ACE_Get_Opt_Long_Option (name, has_arg, short_option);
00532 
00533   if (!option)
00534     return -1;
00535 
00536   // Add to array
00537   size_t size = this->long_opts_.size ();
00538   if (this->long_opts_.size (size + 1) != 0
00539       || this->long_opts_.set (option, size) != 0)
00540     {
00541       delete option;
00542       ACE_ERROR_RETURN
00543         ((LM_ERROR, ACE_LIB_TEXT ("Could not add long option to array.\n")),
00544          -1);
00545     }
00546   return 0;
00547 }
00548 
00549 const ACE_TCHAR*
00550 ACE_Get_Opt::long_option (void) const
00551 {
00552   ACE_TRACE ("ACE_Get_Opt::long_option (void)");
00553   if (this->long_option_)
00554     return this->long_option_->name_;
00555   return 0;
00556 }
00557 
00558 void
00559 ACE_Get_Opt::dump (void) const
00560 {
00561   ACE_TRACE ("ACE_Get_Opt::dump");
00562 
00563   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00564   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\n")));
00565   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00566 }
00567 
00568 void
00569 ACE_Get_Opt::permute_args (void)
00570 {
00571   ACE_TRACE ("ACE_Get_Opt::permute_args");
00572 
00573   int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
00574   ACE_TCHAR *swap;
00575   int opt_end = this->optind;
00576 
00577   nnonopts = this->nonopt_end_ - this->nonopt_start_;
00578   nopts = opt_end - this->nonopt_end_;
00579   ncycle = ACE::gcd (nnonopts, nopts);
00580   cyclelen = (opt_end - this->nonopt_start_) / ncycle;
00581 
00582   this->optind = this->optind - nnonopts;
00583 
00584   for (i = 0; i < ncycle; i++)
00585     {
00586       cstart = this->nonopt_end_ + i;
00587       pos = cstart;
00588       for (j = 0; j < cyclelen; j++)
00589         {
00590           if (pos >= this->nonopt_end_)
00591             pos -= nnonopts;
00592           else
00593             pos += nopts;
00594           swap = this->argv_[pos];
00595 
00596           ((ACE_TCHAR **)this->argv_)[pos] = argv_[cstart];
00597 
00598           ((ACE_TCHAR **)this->argv_)[cstart] = swap;
00599         }
00600     }
00601 }
00602 
00603 int
00604 ACE_Get_Opt::permute (void)
00605 {
00606   ACE_TRACE ("ACE_Get_Opt::permute");
00607 
00608   if (this->nonopt_start_ != this->nonopt_end_
00609       && this->nonopt_start_ != this->optind)
00610     this->permute_args ();
00611 
00612   this->nonopt_start_ = this->optind;
00613 
00614   // Skip over args untill we find the next option.
00615   while (this->optind < this->argc_
00616          && (this->argv_[this->optind][0] != '-'
00617              || this->argv_[this->optind][1] == '\0'))
00618     this->optind++;
00619 
00620   // Got an option, so mark this as the end of the non options.
00621   this->nonopt_end_ = this->optind;
00622 
00623   if (this->optind != this->argc_
00624       && ACE_OS::strcmp (this->argv_[this->optind],
00625                          ACE_LIB_TEXT ("--")) == 0)
00626     {
00627       // We found the marker for the end of the options.
00628       this->optind++;
00629 
00630       if (this->nonopt_start_ != this->nonopt_end_
00631           && this->nonopt_end_ != this->optind)
00632         this->permute_args ();
00633     }
00634 
00635   if (this->optind == this->argc_)
00636     {
00637       if (this->nonopt_start_ != this->nonopt_end_)
00638         this->optind = this->nonopt_start_;
00639       return EOF;
00640     }
00641   return 0;
00642 }
00643 
00644 ACE_Get_Opt::ACE_Get_Opt_Long_Option::ACE_Get_Opt_Long_Option (const ACE_TCHAR *name,
00645                                                                int has_arg,
00646                                                                int val)
00647   :  name_ (ACE::strnew(name)),
00648      has_arg_ (has_arg),
00649      val_ (val)
00650 {}
00651 
00652 ACE_Get_Opt::ACE_Get_Opt_Long_Option::~ACE_Get_Opt_Long_Option (void)
00653 {
00654   delete [] ACE_const_cast (ACE_TCHAR*, this->name_);
00655 }
00656 
00657 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00658 template class ACE_Array<ACE_Get_Opt::ACE_Get_Opt_Long_Option *>;
00659 template class ACE_Array_Base<ACE_Get_Opt::ACE_Get_Opt_Long_Option *>;
00660 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00661 #pragma instantiate ACE_Array<ACE_Get_Opt::ACE_Get_Opt_Long_Option *>
00662 #pragma instantiate ACE_Array_Base<ACE_Get_Opt::ACE_Get_Opt_Long_Option *>
00663 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

Generated on Mon Jun 16 11:19:45 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002