Args.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2002  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "pent_include.h"
00020 
00021 #include "Args.h"
00022 
00023 using std::endl;
00024 using std::string;
00025 #ifndef UNDER_CE
00026 using std::strtol;
00027 using std::strtoul;
00028 #endif
00029 
00030 void Args::process(const sint32 argc, const char * const * const argv)
00031 {
00032         for(sint32 i=1; i<argc; ++i)
00033         {
00034                 for(uint32 j=0; (j<options.size()) && (i<argc); ++j)
00035                 {
00036                         switch(options[j].valuetype)
00037                         {
00038                                 case Option::no_type:
00039                                         continue;
00040                                 case Option::type_bool:
00041                                         if(options[j].option==argv[i])
00042                                                 *(options[j]._bool_val)=options[j]._bool_default;
00043                                         break;
00044                                 case Option::type_str:
00045                                 {
00046                                         if(options[j].option==argv[i])
00047                                         {
00048                                                 // We want the _next_ argument
00049                                                 if(++i>=argc)
00050                                                 {
00051                                                         perr << "Data not specified for argument '" << options[j].option << "'. Using default." << endl;
00052                                                         break;
00053                                                 }
00054                                                 *(options[j]._str_val)=argv[i];
00055                                         }
00056                                         break;
00057                                 }
00058                                 case Option::type_sint:
00059                                 {
00060                                         if(options[j].option==argv[i])
00061                                         {
00062                                                 // We want the _next_ argument
00063                                                 if(++i>=argc)
00064                                                 {
00065                                                         perr << "Data not specified for argument '" << options[j].option << "'. Using default." << endl;
00066                                                         break;
00067                                                 }
00068                                                 *(options[j]._sint_val)=strtol(argv[i],0,10);
00069                                         }
00070                                         break;
00071                                 }
00072                                 case Option::type_uint:
00073                                 {
00074                                         if(options[j].option==argv[i])
00075                                         {
00076                                                 // We want the _next_ argument
00077                                                 if(++i>=argc)
00078                                                 {
00079                                                         perr << "Data not specified for argument '" << options[j].option << "'. Using default." << endl;
00080                                                         break;
00081                                                 }
00082                                                 *(options[j]._uint_val)=strtoul(argv[i],0,10);
00083                                         }
00084                                         break;
00085                                 }
00086                         }
00087                 }
00088         }
00089 }

Generated on Fri Jul 27 22:27:09 2007 for pentagram by  doxygen 1.4.7