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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set et sw=2 ts=2: */
/***************************************************************************
* macrotool_dump.cc
*
* Mon Jul 6 08:37:22 CEST 2009
* Copyright 2009 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
/*
* This file is part of Pracro.
*
* Pracro is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Pracro is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Pracro; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "macrotool_dump.h"
#include "macrotool_util.h"
#include "debug.h"
#include "macroparser.h"
#include "templateparser.h"
#include <vector>
#include <map>
#include <set>
#include <config.h>
#include "configuration.h"
struct _macro {
std::string name;
std::string title;
std::set<std::string> templates;
std::string file;
std::string version;
};
struct _template {
std::string name;
std::string title;
std::vector<std::string> macros;
std::string file;
std::string version;
};
static const char usage_str[] =
" help Prints this helptext.\n"
" macros Writes macro names, versions, filenames, titles and template references to stdout.\n"
" templates Writes template names, versions, filenames, titles and macro references to stdout.\n"
;
static std::map<std::string, struct _macro> macroList()
{
std::map<std::string, struct _macro> macros;
std::vector<std::string> macrofiles = getMacros();
std::vector<std::string>::iterator mfs = macrofiles.begin();
while(mfs != macrofiles.end()) {
//std::string name = mfs->substr(0, mfs->length() - 4);
MacroParser parser(Conf::xml_basedir + "/macros/" + *mfs);
parser.parse();
Macro *macro = parser.getMacro();
std::string key = macro->attributes["name"];// + "-" + macro->attributes["version"];
macros[key].name = macro->attributes["name"];
macros[key].file = *mfs;
macros[key].title = macro->widgets.attributes["caption"];
macros[key].version = macro->attributes["version"];
mfs++;
}
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);
TemplateParser parser(Conf::xml_basedir + "/templates/" + *tfs);
parser.parse();
Template *t = parser.getTemplate();
std::vector<Macro>::iterator ms = t->macros.begin();
while(ms != t->macros.end()) {
if(ms->attributes.find("header") == ms->attributes.end())
macros[ms->attributes["name"]].templates.insert(templ);
ms++;
}
tfs++;
}
return macros;
}
static void dump_macros()
{
std::map<std::string, struct _macro> macros = macroList();
macros[""].title = "Title:";
macros[""].file = "File:";
macros[""].version = "Version:";
macros[""].name = "Macro:";
macros[""].templates.insert("Templates:");
size_t name_sz = 0;
size_t version_sz = 0;
size_t file_sz = 0;
size_t title_sz = 0;
std::map<std::string, struct _macro>::iterator ms = macros.begin();
while(ms != macros.end()) {
if(ms->second.name.length() > name_sz) name_sz = ms->second.name.length();
if(ms->second.version.length() > version_sz) version_sz = ms->second.version.length();
if(ms->second.file.length() > file_sz) file_sz = ms->second.file.length();
if(ms->second.title.length() > title_sz) title_sz = ms->second.title.length();
ms++;
}
ms = macros.begin();
while(ms != macros.end()) {
printcolumn(ms->second.name, name_sz);
printcolumn(ms->second.version, version_sz);
printcolumn(ms->second.file, file_sz);
printcolumn(ms->second.title, title_sz);
std::set<std::string>::iterator ts = ms->second.templates.begin();
while(ts != ms->second.templates.end()) {
if(ts != ms->second.templates.begin()) printf(", ");
printf("%s", ts->c_str() );
ts++;
}
printf("\n");
ms++;
}
}
static std::map<std::string, struct _template> templateList()
{
std::map<std::string, struct _template> templates;
std::vector<std::string> templatefiles = getTemplates();
std::vector<std::string>::iterator tfs = templatefiles.begin();
while(tfs != templatefiles.end()) {
TemplateParser parser(Conf::xml_basedir + "/templates/" + *tfs);
parser.parse();
Template *t = parser.getTemplate();
std::string key = t->attributes["name"];
templates[key].file = *tfs;
templates[key].name = t->attributes["name"];
templates[key].title = t->attributes["title"];
templates[key].version = t->attributes["version"];
std::vector<Macro>::iterator ms = t->macros.begin();
while(ms != t->macros.end()) {
if(ms->attributes.find("header") == ms->attributes.end())
templates[key].macros.push_back(ms->attributes["name"]);
ms++;
}
tfs++;
}
return templates;
}
static void dump_templates()
{
std::map<std::string, struct _template> templates = templateList();
templates[""].title = "Title:";
templates[""].file = "File:";
templates[""].version = "Version:";
templates[""].name = "Template:";
size_t name_sz = 0;
size_t version_sz = 0;
size_t file_sz = 0;
size_t title_sz = 0;
std::map<std::string, struct _template>::iterator ts = templates.begin();
while(ts != templates.end()) {
if(ts->second.name.length() > name_sz) name_sz = ts->second.name.length();
if(ts->second.version.length() > version_sz) version_sz = ts->second.version.length();
if(ts->second.file.length() > file_sz) file_sz = ts->second.file.length();
if(ts->second.title.length() > title_sz) title_sz = ts->second.title.length();
ts++;
}
ts = templates.begin();
while(ts != templates.end()) {
printcolumn(ts->second.name, name_sz);
printcolumn(ts->second.version, version_sz);
printcolumn(ts->second.file, file_sz);
printcolumn(ts->second.title, title_sz);
printf("\n");
std::vector<std::string>::iterator ms = ts->second.macros.begin();
while(ms != ts->second.macros.end()) {
printf("\t%s\n", ms->c_str() );
ms++;
}
printf("\n");
ts++;
}
}
void macrotool_dump(std::vector<std::string> params)
{
if(params.size() < 1) {
printf(usage_str);
return;
}
PRACRO_DEBUG(fieldnames, "dump: %s\n", params[0].c_str());
if(params[0] == "macros") {
if(params.size() != 1) {
printf("The command 'macro' doen't take any parameters.\n");
printf(usage_str);
return;
}
dump_macros();
return;
}
if(params[0] == "templates") {
if(params.size() != 1) {
printf("The command 'templates' doen't take any parameters.\n");
printf(usage_str);
return;
}
dump_templates();
return;
}
if(params[0] == "help") {
printf(usage_str);
return;
}
printf("Unknown command '%s'\n", params[0].c_str());
printf(usage_str);
return;
}
|