tCommandLineData Struct Reference

entry point for command line parsing More...

#include <tCommandLine.h>

Collaboration diagram for tCommandLineData:

Collaboration graph
[legend]

List of all members.

Public Member Functions

bool Analyse (int argc, char **argv)
 analyse the command line
bool Execute ()
 execute the parsed commands
 tCommandLineData ()
 constructor

Public Attributes

tStringprogramVersion_
tString name_

Private Attributes

bool doc_
 flag indicating whether documentation should be printed


Detailed Description

entry point for command line parsing

Definition at line 42 of file tCommandLine.h.


Constructor & Destructor Documentation

tCommandLineData::tCommandLineData (  )  [inline]

constructor

Definition at line 51 of file tCommandLine.h.

References NULL, and programVersion_.

00052             : doc_(false)
00053     {
00054         programVersion_ = NULL;
00055     }


Member Function Documentation

bool tCommandLineData::Analyse ( int  argc,
char **  argv 
)

analyse the command line

Definition at line 79 of file tCommandLine.cpp.

References tCommandLineParser::Advance(), tCommandLineAnalyzer::Analyze(), commandLineAnalyzer, tCommandLineParser::Current(), doc_, tCommandLineParser::End(), free, tCommandLineParser::GetSwitch(), tCommandLineAnalyzer::Help(), tCommandLineAnalyzer::Initialize(), tString::Len(), name_, tListItem< T >::Next(), programVersion_, QUIT, quitWithMessagePrepare(), tASSERT, and tERR_MESSAGE.

Referenced by main().

00080 {
00081 #ifdef DEBUG_X
00082 #ifdef WIN32
00083 #define getcwd _getcwd
00084 #endif
00085 
00086     char * cwd = getcwd(0,0);
00087     tERR_MESSAGE( "Executable: " << argv[0] << ", CWD: " << cwd );
00088     free( cwd );
00089 #endif
00090 
00091     tCommandLineParser parser( argc, argv );
00092     {
00093         tASSERT( programVersion_ );
00094 
00095         char const * run = parser.Current();
00096         while (*run)
00097         {
00098             if (*run == '\\' || *run == '/')
00099                 name_ = run+1;
00100             run++;
00101         }
00102 
00103         if ( name_.Len() <= 3 )
00104         {
00105             name_ = "Armagetron";
00106         }
00107     }
00108 
00109 
00110     // initialize third party analyzers
00111     {
00112         tCommandLineAnalyzer * commandLineAnalyzer = s_commandLineAnalyzerAnchor;
00113         while ( commandLineAnalyzer )
00114         {
00115             commandLineAnalyzer->Initialize( parser );
00116             commandLineAnalyzer = commandLineAnalyzer->Next();
00117         }
00118     }
00119 
00120     parser.Advance();
00121 
00122     //std::cout << "config loaded\n";
00123 
00124 #ifndef WIN32   
00125 #define HELPAVAIL
00126 #endif
00127 #ifdef DEDICATED  
00128 #define HELPAVAIL
00129 #endif
00130 
00131     while ( !parser.End() )
00132     {
00133         if ( parser.GetSwitch( "--help", "-h" ) )
00134         {
00135             {
00136                 std::ostringstream s;
00137                 s << "\n\nUsage: " << name_ << " [Arguments]\n\n"
00138                 << "Possible arguments:\n\n";
00139                 s << "-h, --help                   : print this message\n";
00140 #ifdef HELPAVAIL
00141                 s << "--doc                        : print documentation for all console commands\n";
00142 #endif
00143                 s << "-v, --version                : print version number\n\n";
00144 
00145                 // ask third party analyzers
00146                 tCommandLineAnalyzer * commandLineAnalyzer = s_commandLineAnalyzerAnchor;
00147                 while ( commandLineAnalyzer )
00148                 {
00149                     commandLineAnalyzer->Help( s );
00150                     commandLineAnalyzer = commandLineAnalyzer->Next();
00151                     s << "\n";
00152                 }
00153 
00154                 s << "\n";
00155 
00156                 name_.Clear();
00157                 quitWithMessagePrepare( s.str().c_str() );
00158             }
00159 
00160             return false;
00161             // exit(0);
00162         }
00163 #ifdef HELPAVAIL
00164         else if ( parser.GetSwitch( "--doc") )
00165         {
00166             doc_ = true;
00167         }
00168 #endif
00169         else if ( parser.GetSwitch( "--version", "-v") )
00170         {
00171             QUIT( "This is " << name_ << " version " << *programVersion_ << ".\n" );
00172         }
00173         else
00174         {
00175             // let the registered command line anelyzers have a go
00176             tCommandLineAnalyzer * commandLineAnalyzer = s_commandLineAnalyzerAnchor;
00177             bool success = false;
00178             while ( commandLineAnalyzer )
00179             {
00180                 if ( success = commandLineAnalyzer->Analyze( parser ) )
00181                     break;
00182                 commandLineAnalyzer = commandLineAnalyzer->Next();
00183             }
00184             if ( success )
00185                 continue;
00186 
00187             QUIT( "\n\nUnknown command line option " << parser.Current() << ". Type " << name_ << " -h to get a list of possible options.\n\n" );
00188         }
00189     }
00190 
00191     return true;
00192 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tCommandLineData::Execute (  ) 

execute the parsed commands

Definition at line 194 of file tCommandLine.cpp.

References doc_, and tConfItemBase::DocAll().

Referenced by main().

00195 {
00196     tString name;
00197 
00198     if ( doc_ )
00199     {
00200         std::cout << "Available console commands/config file settings:\n\n";
00201         tConfItemBase::DocAll( std::cout );
00202 
00203         return false;
00204         // QUIT("\n");
00205     }
00206 
00207     return true;
00208 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tString* tCommandLineData::programVersion_

Definition at line 44 of file tCommandLine.h.

Referenced by Analyse(), main(), and tCommandLineData().

tString tCommandLineData::name_

Definition at line 45 of file tCommandLine.h.

Referenced by Analyse().

bool tCommandLineData::doc_ [private]

flag indicating whether documentation should be printed

Definition at line 58 of file tCommandLine.h.

Referenced by Analyse(), and Execute().


The documentation for this struct was generated from the following files:
Generated on Sat Mar 15 23:55:09 2008 for Armagetron Advanced by  doxygen 1.5.4