EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
eve-xmlpktgen.cpp File Reference
#include "eve-xmlpktgen.h"
#include "XMLPacketGen.h"
Include dependency graph for eve-xmlpktgen.cpp:

Go to the source code of this file.

Functions

void usage ()
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 32 of file eve-xmlpktgen.cpp.

References XMLParser::ParseFile(), XMLPacketGen::SetHeaderFile(), XMLPacketGen::SetSourceFile(), sLog, and usage().

33 {
34 #if defined( HAVE_CRTDBG_H ) && !defined( NDEBUG )
35  // Under Visual Studio setup memory leak detection
36  _CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) );
37 #endif /* defined( HAVE_CRTDBG_H ) && !defined( NDEBUG ) */
38 
39  // skip first argument, not interested
40  --argc;
41  ++argv;
42 
43  std::string dirInclude = ".";
44  std::string dirSource = ".";
45 
46  // parse options
47  for(; 0 < argc; --argc, ++argv )
48  {
49  if( '-' != argv[0][0] )
50  // end of options
51  break;
52 
53  switch( argv[0][1] )
54  {
55  /* include dir */
56  case 'I':
57  if( 1 < argc )
58  {
59  // consume next argument
60  dirInclude = argv[1];
61  --argc, ++argv;
62  }
63  else
64  {
65  sLog.Error( "XMLPktGen", "Error parsing options: no parameter for include dir" );
66  return -1;
67  }
68  break;
69 
70  /* source dir */
71  case 'S':
72  if( 1 < argc )
73  {
74  // consume next argument
75  dirSource = argv[1];
76  --argc, ++argv;
77  }
78  else
79  {
80  sLog.Error( "XMLPktGen", "Error parsing options: no parameter for source dir" );
81  return -1;
82  }
83  break;
84 
85  /* help */
86  case 'h':
87  usage();
88  return 0;
89 
90  /* error */
91  default:
92  sLog.Error( "XMLPktGen", "Unknown option '%c'", argv[0][1] );
93  return -1;
94  }
95  }
96 
97  if( 0 == argc )
98  {
99  sLog.Error( "XMLPktGen", "Error processing files: no files given" );
100  return -1;
101  }
102 
103  // process files
104  XMLPacketGen gen;
105  for(; 0 < argc; --argc, ++argv )
106  {
107  std::string name = *argv;
108 
109  // locate a slash
110  size_t slash = name.rfind( '/' );
111  if( std::string::npos == slash )
112  slash = name.rfind( '\\' );
113  if( std::string::npos == slash )
114  slash = -1;
115 
116  // locate a dot
117  size_t dot = name.rfind( '.' );
118  if( slash > dot || std::string::npos == dot )
119  dot = name.length();
120 
121  name = name.substr( slash + 1, dot - slash - 1 );
122 
123  gen.SetHeaderFile( ( dirInclude + '/' + name + ".h" ).c_str() );
124  gen.SetSourceFile( ( dirSource + '/' + name + ".cpp" ).c_str() );
125 
126  if( !gen.ParseFile( *argv ) )
127  return -1;
128  }
129 
130  return 0;
131 }
bool ParseFile(const char *file)
Parses file using registered parsers.
Definition: XMLParser.cpp:44
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
void SetHeaderFile(const char *header)
Sets header file.
void SetSourceFile(const char *source)
Sets source file.
XML Packet Generator class.
Definition: XMLPacketGen.h:45
void usage()

Here is the call graph for this function:

void usage ( )

Definition at line 133 of file eve-xmlpktgen.cpp.

Referenced by Command_spawn(), and main().

134 {
135  printf( "Usage: eve-xmlpktgen [OPTIONS] FILE [FILE [...]]\n"
136  "\n"
137  "Options:\n"
138  " -I directory Output header files to directory\n"
139  " -S directory Output source files to directory\n"
140  " -h Show this help and exit\n"
141  );
142 }

Here is the caller graph for this function: