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/digest.h>
25#include <interfaces/generator/exceptions.h>
26#include <interfaces/generator/parser.h>
27#include <interfaces/generator/tolua_generator.h>
28#include <utils/system/argparser.h>
29#include <utils/system/file.h>
30
31#include <iostream>
32#include <string>
33#include <vector>
34
35using namespace std;
36using namespace fawkes;
37
38int
39main(int argc, char **argv)
40{
41 int rv = 0;
42 ArgumentParser *argp = new ArgumentParser(argc, argv, "hd:v");
43
44 const vector<const char *> &items = argp->items();
45 if (items.size() == 0 || argp->has_arg("h")) {
46 cout << "Fawkes Interface generator - Usage Instructions" << endl
47 << "==============================================================================="
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
95 CppInterfaceGenerator *cppigen =
97 iparse->getInterfaceName(),
98 prefix,
99 iparse->getInterfaceAuthor(),
100 iparse->getInterfaceYear(),
101 iparse->getInterfaceCreationDate(),
102 iparse->getDataComment(),
103 idigest->get_hash(),
104 idigest->get_hash_size(),
105 iparse->getConstants(),
106 iparse->getEnumConstants(),
107 iparse->getDataFields(),
108 iparse->getPseudoMaps(),
109 iparse->getMessages());
110
111 ToLuaInterfaceGenerator *toluaigen =
113 iparse->getInterfaceName(),
114 prefix,
115 iparse->getInterfaceAuthor(),
116 iparse->getInterfaceYear(),
117 iparse->getInterfaceCreationDate(),
118 iparse->getDataComment(),
119 idigest->get_hash(),
120 idigest->get_hash_size(),
121 iparse->getConstants(),
122 iparse->getEnumConstants(),
123 iparse->getDataFields(),
124 iparse->getPseudoMaps(),
125 iparse->getMessages());
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: " << e.what_no_backtrace() << endl;
137 rv = -1;
138 }
139 }
140 }
141
142 delete argp;
143
144 return rv;
145}
Generator that transforms input from the InterfaceParser into valid C++ classes.
Definition: cpp_generator.h:37
void generate()
Generator cpp and h files.
Interface digest generator.
Definition: digest.h:30
const unsigned char * get_hash()
Get hash.
Definition: digest.cpp:93
size_t get_hash_size()
Get hash size.
Definition: digest.cpp:102
Parser used to get information out of interface template.
Definition: parser.h:40
std::vector< InterfaceField > getDataFields()
Get data fields.
Definition: parser.cpp:733
void print()
Print parsed data.
Definition: parser.cpp:328
std::vector< InterfaceEnumConstant > getEnumConstants()
Get enum constants.
Definition: parser.cpp:723
std::vector< InterfaceConstant > getConstants()
Get constants.
Definition: parser.cpp:713
std::string getInterfaceCreationDate()
Get interface creation date as string Only valid after parse().
Definition: parser.cpp:703
std::string getInterfaceAuthor()
Get interface author.
Definition: parser.cpp:683
std::string getInterfaceYear()
Get interface copyright year.
Definition: parser.cpp:693
void parse()
Parse config.
Definition: parser.cpp:335
std::string getDataComment()
Get data comment.
Definition: parser.cpp:753
std::string getInterfaceName()
Get interface name.
Definition: parser.cpp:673
std::vector< InterfaceMessage > getMessages()
Get messages.
Definition: parser.cpp:763
std::vector< InterfacePseudoMap > getPseudoMaps(xmlpp::Node *node, std::vector< InterfaceField > &fields)
Get parsed pseudo maps.
Definition: parser.cpp:126
Generator that transforms input from the InterfaceParser into valid ToLua++ package file.
void generate()
Generator cpp and h files.
Parse command line arguments.
Definition: argparser.h:64
const std::vector< const char * > & items() const
Get non-option items.
Definition: argparser.cpp:447
const char * arg(const char *argn)
Get argument value.
Definition: argparser.cpp:177
bool has_arg(const char *argn)
Check if argument has been supplied.
Definition: argparser.cpp:165
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual const char * what_no_backtrace() const noexcept
Get primary string (does not implicitly print the back trace).
Definition: exception.cpp:663
Fawkes library namespace.