1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
#include "fieldnamescanner.h"
#include <stdio.h>
#include "util.h"
#include "macroparser.h"
#include "templateparser.h"
#include "configuration.h"
#include "exception.h"
#include "macrolist.h"
#include <hugin.hpp>
fieldnames_t getFields(Widget &widget)
{
fieldnames_t fieldnames;
if(widget.attributes.find("name") != widget.attributes.end()) {
fieldnames.push_back(widget.attributes["name"]);
}
std::vector< Widget >::iterator i = widget.widgets.begin();
while(i != widget.widgets.end()) {
fieldnames_t f = getFields(*i);
fieldnames.insert(fieldnames.end(), f.begin(), f.end());
i++;
}
return fieldnames;
}
templates_t scanfieldnames(Environment &env, std::set<std::string> &filter)
{
templates_t templates;
std::vector<std::string> templatefiles = getTemplates();
std::vector<std::string>::iterator tfs = templatefiles.begin();
while(tfs != templatefiles.end()) {
std::string templ = tfs->substr(0, tfs->length() - 4);
fieldnames_t fieldnames;
DEBUG(scanner, "%s:\n", tfs->c_str());
TemplateParser parser(Conf::xml_basedir + "/templates/" + *tfs);
try {
parser.parse();
Template *t = parser.getTemplate();
if(!t) ERR(scanner, "Missing template!\n");
std::vector<Macro>::iterator ms = t->macros.begin();
while(ms != t->macros.end()) {
if(ms->isHeader == false) {
std::string macro = ms->name;
DEBUG(scanner, "Name '%s'\n", macro.c_str());
std::string macrofile = env.macrolist.getLatestVersion(macro);
DEBUG(scanner, "File '%s'\n", macrofile.c_str());
MacroParser parser(macrofile);
try {
parser.parse();
Macro *m = parser.getMacro();
fieldnames_t f = getFields(m->widgets);
fieldnames.insert(fieldnames.end(), f.begin(), f.end());
} catch( Exception &e ) {
ERR(scanner, "Error reading macro: %s: %s\n",
macrofile.c_str(), e.what());
}
}
ms++;
}
} catch( Exception &e ) {
ERR(scanner, "Error reading template: %s: %s\n", tfs->c_str(), e.what());
}
fieldnames_t nodubs;
fieldnames_t::iterator fi = fieldnames.begin();
while(fi != fieldnames.end()) {
bool hasdub = false;
fieldnames_t::iterator di = nodubs.begin();
while(di != nodubs.end()) {
if(*di == *fi) {
hasdub = true;
break;
}
di++;
}
if(!hasdub && filter.find(*fi) != filter.end()) nodubs.push_back(*fi);
fi++;
}
templates[templ] = nodubs;
tfs++;
}
return templates;
}
#ifdef TEST_FIELDNAMESCANNER
#include "test.h"
TEST_BEGIN;
TEST_TRUE(false, "No tests yet!");
TEST_END;
#endif
|