EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
eve-xmlpktgen.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24 */
25 
26 #include "eve-xmlpktgen.h"
27 
28 #include "XMLPacketGen.h"
29 
30 void usage();
31 
32 int main( int argc, char* argv[] )
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 }
132 
133 void usage()
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 }
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.
int main(int argc, char *argv[])
XML Packet Generator class.
Definition: XMLPacketGen.h:45
void usage()