Fawkes API  Fawkes Development Version
main.cpp
1 
2 /***************************************************************************
3  * main.cpp - Interface generator main app
4  *
5  * Generated: Tue Oct 10 17:42:05 2006
6  * Copyright 2006 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <interfaces/generator/cpp_generator.h>
24 #include <interfaces/generator/tolua_generator.h>
25 #include <interfaces/generator/parser.h>
26 #include <interfaces/generator/digest.h>
27 #include <interfaces/generator/exceptions.h>
28 
29 #include <utils/system/argparser.h>
30 #include <utils/system/file.h>
31 
32 #include <iostream>
33 #include <vector>
34 #include <string>
35 
36 using namespace std;
37 using namespace fawkes;
38 
39 int
40 main(int argc, char **argv)
41 {
42  int rv = 0;
43  ArgumentParser *argp = new ArgumentParser(argc, argv, "hd:v");
44 
45  const vector<const char *> & items = argp->items();
46  if ( items.size() == 0 || argp->has_arg("h") ) {
47  cout << "Fawkes Interface generator - Usage Instructions" << endl
48  << "===============================================================================" << endl
49  << "Usage: " << argv[0] << " [-h] [-d dir] [-v] config.xml [config2.xml...]" << endl
50  << "where [options] is one or more of:" << endl
51  << " -h These help instructions" << endl
52  << " -d dir Directory where to write generated files" << endl
53  << " -v Verbose console output." << endl
54  << endl;
55  } else {
56  string dir = ".";
57  if ( argp->has_arg("d") ) {
58  dir = argp->arg("d");
59  }
60 
61  for ( vector<const char *>::const_iterator i = items.begin(); i != items.end(); ++i) {
62  string s = *i;
63  string prefix;
64  size_t pos;
65 
66  if ( ( pos = s.find_last_of (".")) != string::npos ) {
67  prefix = s.substr(0, pos);
68  } else {
69  prefix = s;
70  }
71  s = prefix;
72  if ( ( pos = s.find_last_of ("/")) != string::npos ) {
73  prefix = s.substr(pos + 1);
74  } else {
75  prefix = s;
76  }
77 
78  if ( ! File::exists( *i ) ) {
79  cout << "File " << *i << " does not exist" << endl;
80  continue;
81  } else if (! File::is_regular( *i ) ) {
82  cout << *i << " is not a regular file" << endl;
83  continue;
84  }
85 
86  try {
87  InterfaceParser *iparse = new InterfaceParser(*i);
88  iparse->parse();
89  if ( argp->has_arg("v") ) {
90  iparse->print();
91  }
92 
93  InterfaceDigest *idigest = new InterfaceDigest(*i);
94 
96  iparse->getInterfaceName(),
97  prefix,
98  iparse->getInterfaceAuthor(),
99  iparse->getInterfaceYear(),
100  iparse->getInterfaceCreationDate(),
101  iparse->getDataComment(),
102  idigest->get_hash(),
103  idigest->get_hash_size(),
104  iparse->getConstants(),
105  iparse->getEnumConstants(),
106  iparse->getDataFields(),
107  iparse->getPseudoMaps(),
108  iparse->getMessages()
109  );
110 
112  iparse->getInterfaceName(),
113  prefix,
114  iparse->getInterfaceAuthor(),
115  iparse->getInterfaceYear(),
116  iparse->getInterfaceCreationDate(),
117  iparse->getDataComment(),
118  idigest->get_hash(),
119  idigest->get_hash_size(),
120  iparse->getConstants(),
121  iparse->getEnumConstants(),
122  iparse->getDataFields(),
123  iparse->getPseudoMaps(),
124  iparse->getMessages()
125  );
126 
127  cppigen->generate();
128  toluaigen->generate();
129 
130  delete cppigen;
131  delete toluaigen;
132 
133  delete iparse;
134  delete idigest;
135  } catch (Exception &e) {
136  cout << "Generating the interface failed." << endl;
137  e.print_trace();
138  rv = -1;
139  }
140  }
141  }
142 
143  delete argp;
144 
145  return rv;
146 }
const char * arg(const char *argn)
Get argument value.
Definition: argparser.cpp:182
const std::vector< const char *> & items() const
Get non-option items.
Definition: argparser.cpp:462
void parse()
Parse config.
Definition: parser.cpp:339
Fawkes library namespace.
const unsigned char * get_hash()
Get hash.
Definition: digest.cpp:96
STL namespace.
Parse command line arguments.
Definition: argparser.h:66
void generate()
Generator cpp and h files.
Parser used to get information out of interface template.
Definition: parser.h:39
void print()
Print parsed data.
Definition: parser.cpp:331
std::string getInterfaceAuthor()
Get interface author.
Definition: parser.cpp:670
std::string getDataComment()
Get data comment.
Definition: parser.cpp:747
Base class for exceptions in Fawkes.
Definition: exception.h:36
size_t get_hash_size()
Get hash size.
Definition: digest.cpp:106
Generator that transforms input from the InterfaceParser into valid C++ classes.
Definition: cpp_generator.h:36
Generator that transforms input from the InterfaceParser into valid ToLua++ package file...
std::vector< InterfaceMessage > getMessages()
Get messages.
Definition: parser.cpp:758
std::vector< InterfaceField > getDataFields()
Get data fields.
Definition: parser.cpp:725
std::string getInterfaceCreationDate()
Get interface creation date as string Only valid after parse().
Definition: parser.cpp:692
void print_trace()
Prints trace to stderr.
Definition: exception.cpp:619
std::vector< InterfacePseudoMap > getPseudoMaps(xmlpp::Node *node, std::vector< InterfaceField > &fields)
Get parsed pseudo maps.
Definition: parser.cpp:130
std::string getInterfaceName()
Get interface name.
Definition: parser.cpp:659
Interface digest generator.
Definition: digest.h:29
std::vector< InterfaceEnumConstant > getEnumConstants()
Get enum constants.
Definition: parser.cpp:714
bool has_arg(const char *argn)
Check if argument has been supplied.
Definition: argparser.cpp:169
std::string getInterfaceYear()
Get interface copyright year.
Definition: parser.cpp:681
std::vector< InterfaceConstant > getConstants()
Get constants.
Definition: parser.cpp:703