-
Notifications
You must be signed in to change notification settings - Fork 30
/
kwsStyle.cxx
812 lines (710 loc) · 22.7 KB
/
kwsStyle.cxx
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
/*========================================================================
Program: KWStyle - Kitware Style Checker
Module: kwsStyle.cxx
Copyright (c) Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "kwsParser.h"
#include "kwsGenerator.h"
#include "metaCommand.h"
#include <iostream>
#include <fstream>
#include <kwssys/Directory.hxx>
#include <kwssys/SystemTools.hxx>
#include <kwssys/Glob.hxx>
#include <cmath>
#include <string.h>
#include <sstream>
#include "kwsXMLReader.h"
#include <vector>
#include "KWStyleConfigure.h"
#if defined(WIN32) && !defined(__CYGWIN__)
#include <direct.h> // mkdir needs it
#endif
struct kwsFeature{
std::string name;
std::string value;
std::string filename;
bool enable;
};
// List of features to check
static std::vector<kwsFeature> features;
static std::vector<kwsFeature> overwriteFeatures;
static void AddFeature(const char* name,const char* value,bool enable)
{
kwsFeature f;
f.name = name;
f.value = value;
f.enable = enable;
f.filename = "";
features.push_back(f);
}
static void ChangeFeature(const char* name,const char* value)
{
auto it = features.begin();
while(it != features.end())
{
if(!strcmp((*it).name.c_str(),name))
{
(*it).value = value;
return;
}
++it;
}
}
static void DisableFeature(const char* name)
{
auto it = features.begin();
while(it != features.end())
{
if(!strcmp((*it).name.c_str(),name))
{
(*it).enable = false;
return;
}
++it;
}
}
/** Remove files */
static void RemoveFile(const char* regEx,std::vector<std::string> & filenames)
{
kwssys::RegularExpression regex(regEx);
auto it = filenames.begin();
while(it != filenames.end())
{
if(regex.find((*it).c_str()))
{
it = filenames.erase(it);
}
else
{
++it;
}
}
}
int main(int argc, const char **argv)
{
double time0 = kwssys::SystemTools::GetTime();
MetaCommand command;
command.SetVersion(KWSTYLE_VERSION_STRING);
// Check if -cvs is defined and put MetaCommand in quiet mode
/*for(int j=0;j<argc;j++)
{
if(!strcmp(argv[j],"-cvs"))
{
command.SetVerbose(false);
}
}*/
command.SetOption("directory","d",false,"Specify a directory");
command.SetOption("recursive","R",false,"Associated with -d recurse through directories");
command.SetOption("verbose","v",false,"Display errors");
command.SetOption("quiteverbose","qv",false,"Display less information");
command.SetOption("lesshtml","lesshtml",false,"Display less HTML");
command.SetOption("vim","vim",false,"Generate errors as VIM format");
command.SetOption("msvc","msvc",false,"Generate errors as MSVC format");
command.SetOption("gcc","gcc",false,"Generate errors as GCC format");
command.SetOption("html","html",false,"Generate the HTML report");
command.AddOptionField("html","filename",MetaCommand::STRING,false);
command.SetOption("cvs","cvs",false,"Using KWStyle as a cvs precommit script");
command.SetOption("exporthtml","exporthtml",false,"Export the HTML report online");
command.SetOption("xml","xml",false,"Read a XML configure file");
command.AddOptionField("xml","filename",MetaCommand::STRING,false);
command.SetOption("exportxml","exportxml",false,"Write output the report as a simple XML");
command.AddOptionField("exportxml","filename",MetaCommand::STRING,false);
command.SetOption("overwrite","o",false,"Overwrite rules file");
command.AddOptionField("overwrite","filename",MetaCommand::STRING,false);
command.SetOption("dirfile","D",false,"Specify a file listing all the directories");
command.SetOption("basedirectory","B",false,"Specify the base directory of the file");
command.AddOptionField("basedirectory","filename",MetaCommand::STRING,false);
command.SetOption("blacklist","b",false,"Specify a black list of words");
command.AddOptionField("blacklist","filename",MetaCommand::STRING,false);
command.SetOption("dart","dart",false,"Write out files to be send to the dart server");
command.AddOptionField("dart","filename",MetaCommand::STRING,true);
command.AddOptionField("dart","maxerror",MetaCommand::INT,false,"-1");
command.AddOptionField("dart","group",MetaCommand::INT,false,"0");
command.SetOption("kwsurl","kwsurl",false,"Specify the base url of the KWStyle HTML report");
command.AddOptionField("kwsurl","url",MetaCommand::STRING,true);
command.SetOption("fixFile","fix",false,"Write out a fixed version of the parsed file");
command.AddField("infile","input filename",MetaCommand::STRING,true);
// Parsing
if(!command.Parse(argc,argv))
{
return 1;
}
// Add the features
AddFeature("Header","dummyheader.h,false,true",true); // should be first
AddFeature("LineLength","80",true);
AddFeature("DeclarationOrder","0,1,2",true);
AddFeature("Typedefs","[A-Z],true",true);
AddFeature("InternalVariables","m_[A-Z],true",true);
AddFeature("Variables","this->[A-Z]",true);
AddFeature("Struct","[a-z]",true);
AddFeature("SemicolonSpace","0",true);
AddFeature("EndOfFileNewLine","",true);
AddFeature("Tabs","",true);
AddFeature("Spaces","3",true);
AddFeature("Comments","/**, *, */,true,true,true",true);
AddFeature("Indent","kws::SPACE,2,true,true",true);
AddFeature("Namespace","itk",true);
AddFeature("NameOfClass","[NameOfClass],itk",true);
AddFeature("IfNDefDefine","__[NameOfClass]_[Extension]",true);
AddFeature("EmptyLines","2",true);
AddFeature("Template","T",true);
AddFeature("Operator","1,1",true);
AddFeature("StatementPerLine","1",true);
AddFeature("VariablePerLine","1",true);
AddFeature("BadCharacters","true",true);
AddFeature("MemberFunctions","*",true);
AddFeature("Functions","*",true);
AddFeature("UsingDirectives", "true", true);
AddFeature("RelativePathInInclude", "true", true);
AddFeature("IfWhileForUntil","",true);
AddFeature("Comma","",true);
AddFeature("Parenthesis","",true);
std::string xmlFile = "KWStyle.xml";
// If we should look the definition from the xml file
if(command.GetOptionWasSet("xml"))
{
xmlFile = command.GetValueAsString("xml","filename");
}
// Initialize the configuration parameters
std::string blacklist = "";
std::string overwrite = "";
std::string recursive = "";
std::string verbose = "";
std::string htmlDirectory = "";
std::string lessHTML = "";
std::string filesToCheck = "";
std::string directoryToCheck = "";
std::string fileToCheck = "";
std::string fixedFile = "";
if (!xmlFile.empty()) {
kws::XMLReader reader;
if(reader.Open(xmlFile.c_str()))
{
auto it = features.begin();
while(it != features.end())
{
std::string val = reader.GetValue((*it).name.c_str());
if(!val.empty())
{
ChangeFeature((*it).name.c_str(),val.c_str());
}
else
{
DisableFeature((*it).name.c_str());
}
++it;
}
// Read the current configuration
blacklist = reader.GetValue("BlackList");
overwrite = reader.GetValue("OverwriteFile");
verbose = reader.GetValue("Verbose");
if(!verbose.empty() && verbose[0] != '1')
{
verbose = "";
}
recursive = reader.GetValue("Recursive");
if(!recursive.empty() && recursive[0] != '1')
{
recursive = "";
}
htmlDirectory = reader.GetValue("HTMLDirectory");
lessHTML = reader.GetValue("LessHTML");
filesToCheck = reader.GetValue("Files");
directoryToCheck = reader.GetValue("Directory");
fileToCheck = reader.GetValue("File");
reader.Close();
}
else
{
std::cout << "Cannot open configuration file: " << xmlFile.c_str() << std::endl;
}
}
if(command.GetOptionWasSet("blacklist"))
{
blacklist = command.GetValueAsString("blacklist","filename");
}
if(!blacklist.empty())
{
AddFeature("BlackList",blacklist.c_str(),true);
}
// If we should look at some overwritten rules
if(command.GetOptionWasSet("overwrite"))
{
overwrite = command.GetValueAsString("overwrite","filename");
}
if(!overwrite.empty())
{
// Read the file
std::ifstream file;
file.open(overwrite.c_str(), std::ios::binary | std::ios::in);
if(!file.is_open())
{
std::cout << "Cannot open overwrite file: " << overwrite.c_str() << std::endl;
return 0;
}
file.seekg(0,std::ios::end);
std::streamsize fileSize = file.tellg();
file.seekg(0,std::ios::beg);
char* buf = new char[fileSize+1];
file.read(buf, fileSize);
buf[fileSize] = 0;
std::string buffer(buf);
buffer.resize(static_cast<size_t>(fileSize));
delete [] buf;
size_t start = 0;
auto pos = buffer.find("\n", start);
do
{
std::string line = "";
if(pos == std::string::npos)
{
line = buffer.substr(start,buffer.length()- start);
pos = static_cast<size_t>(fileSize); // we stop
}
else
{
line = buffer.substr(start,pos-start);
start = pos+1;
}
if(line.size() < 2)
{
break;
}
auto p = line.find(" ");
if (p != std::string::npos) {
kwsFeature f;
f.filename = line.substr(0, p);
size_t p1 = p;
p = line.find(" ",p + 1);
if (p != std::string::npos) {
f.name = line.substr(p1 + 1,p - p1 - 1);
}
p1 = p;
p = line.find(" ",p+1);
std::string enablestring = line.substr(p1+1,p-p1-1);
f.enable = enablestring.find("Enable") != std::string::npos;
p1 = p;
p = line.find("\n",p+1);
if(p != std::string::npos)
{
f.value = line.substr( p1+1,p-p1-1);
}
overwriteFeatures.push_back(f);
}
if(static_cast<std::streamsize>(pos) != fileSize)
{
pos = buffer.find("\n",start);
}
} while(static_cast<std::streamsize>(pos) < fileSize);
file.close();
}
std::string inputFilename = command.GetValueAsString("infile");
if (!fileToCheck.empty()) {
inputFilename = fileToCheck;
}
if(command.GetOptionWasSet("recursive"))
{
recursive = "1";
}
// if the -D command is used
if(command.GetOptionWasSet("dirfile"))
{
filesToCheck = inputFilename;
}
if(command.GetValueAsString("directory").length() > 0)
{
directoryToCheck = inputFilename;
if(directoryToCheck[directoryToCheck.size()-1] != '/')
{
directoryToCheck += '/';
}
}
std::vector<std::string> filenames;
std::vector<kws::Parser> m_Parsers;
// if the -d command is used
if (!directoryToCheck.empty()) {
kwssys::Glob glob;
if (!recursive.empty()) {
glob.RecurseOn();
}
std::string globoption = directoryToCheck.c_str();
if(kwssys::SystemTools::FileExists(directoryToCheck.c_str()))
{
globoption += "*.*";
}
glob.FindFiles(globoption.c_str());
filenames = glob.GetFiles();
} else if (!filesToCheck.empty()) {
// Read the file
std::ifstream file;
file.open(filesToCheck.c_str(), std::ios::binary | std::ios::in);
if(!file.is_open())
{
std::cout << "Cannot open description files: " << filesToCheck.c_str() << std::endl;
return 0;
}
file.seekg(0,std::ios::end);
std::streamsize fileSize = file.tellg();
file.seekg(0,std::ios::beg);
char* buf = new char[fileSize+1];
file.read(buf,fileSize);
buf[fileSize] = 0;
std::string buffer(buf);
buffer.resize(static_cast<size_t>(fileSize));
delete [] buf;
size_t start = 0;
size_t pos = buffer.find("\n",start);
size_t posr = buffer.find("\r",start);
if(posr == std::string::npos)
{
posr = pos;
}
// Define a parser to find if we are between quotes
kws::Parser helperParser;
do
{
std::string dirname = "";
if(pos == std::string::npos)
{
dirname = buffer.substr(start,buffer.length()- start);
pos = static_cast<size_t>(fileSize); // we stop
}
else
{
dirname = buffer.substr( start ,posr - start);
start = pos+1;
}
if(dirname.size() < 2)
{
break;
}
auto space = dirname.find(" ");
while (space != std::string::npos &&
helperParser.IsBetweenQuote(space, false, dirname)) {
space = dirname.find(" ",space + 1);
}
// if we should remove the file
if(dirname.find("-f",0) != std::string::npos)
{
std::string fileToRemove = dirname.substr(3,dirname.size()-3);
RemoveFile(fileToRemove.c_str(),filenames);
}
else if(kwssys::SystemTools::FileExists(dirname.c_str()))
{
filenames.push_back(dirname);
}
else // we add a directory
{
kwssys::Glob glob;
if(dirname.find("[R]",0) != std::string::npos)
{
glob.RecurseOn();
}
auto localspace = dirname.find(" ");
while (localspace != std::string::npos &&
helperParser.IsBetweenQuote(localspace, false, dirname)) {
localspace =
dirname.find(" ", localspace + 1);
}
if(localspace != std::string::npos)
{
dirname = dirname.substr(0,localspace);
}
// Remove quotes if any
if(!dirname.empty() && dirname[0] == '"')
{
dirname = dirname.substr(1,dirname.size()-2);
}
std::string globoption = dirname.c_str();
glob.FindFiles(globoption.c_str());
std::vector<std::string> globfiles = glob.GetFiles();
std::vector<std::string>::const_iterator itglob = globfiles.begin();
while(itglob != globfiles.end())
{
filenames.push_back(*itglob);
++itglob;
}
}
if(static_cast<std::streamsize>(pos) != fileSize)
{
pos = buffer.find("\n", start);
posr = buffer.find("\r", start);
if(posr == std::string::npos)
{
posr = pos;
}
}
} while(static_cast<std::streamsize>(pos) < fileSize);
file.close();
} else {
filenames.push_back(inputFilename);
}
// sort the filenames
std::sort(filenames.begin(), filenames.end());
// if the -cvs command is used
// WARNING this option should be last because its position is used
// to determine the filenames.
/*if(command.GetOptionWasSet("cvs"))
{
filenames.clear();
int cvspos = 0;
int i=0;
// Look for the position of the cvs command
for(i=0;i<argc;i++)
{
if(!strcmp(argv[i],"-cvs"))
{
cvspos = i;
break;
}
}
cvspos++;
std::string cvsdir = argv[cvspos];
cvspos++;
for(i=cvspos;i<argc;i++)
{
std::string filename = argv[i];
if((filename.substr(filename.size()-4,4) == ".hxx")
|| (filename.substr(filename.size()-4,4) == ".txx")
|| (filename.substr(filename.size()-4,4) == ".cxx")
|| (filename.substr(filename.size()-2,2) == ".h")
)
{
filenames.push_back(filename);
}
}
}*/
std::vector<std::string>::const_iterator it = filenames.begin();
size_t nerrors = 0;
while(it != filenames.end())
{
if(!command.GetOptionWasSet("quiteverbose") &&
!command.GetOptionWasSet("exporthtml") &&
!command.GetOptionWasSet("vim") && !command.GetOptionWasSet("msvc")
&& !command.GetOptionWasSet("gcc")
)
{
std::cout << "Processing " << (*it).c_str() << std::endl;
}
// We open the file
std::ifstream file;
file.open((*it).c_str(), std::ios::binary | std::ios::in);
if(!file.is_open())
{
std::cout << "Cannot open file: " << (*it).c_str() << std::endl;
// When removing a file with CVS we should return 0 otherwise it fails
if(command.GetOptionWasSet("cvs"))
{
return 0;
}
return 1;
}
file.seekg(0,std::ios::end);
std::streamsize fileSize = file.tellg();
file.seekg(0,std::ios::beg);
char* buf = new char[fileSize+1];
file.read(buf, fileSize);
buf[fileSize] = 0;
std::string buffer(buf);
buffer.resize( static_cast<size_t>(fileSize));
delete [] buf;
file.close();
kws::Parser parser;
parser.SetFilename((*it).c_str());
parser.SetBuffer(buffer);
// Ask the parser to generate a corrected version of the file
if(command.GetOptionWasSet("fixFile"))
{
parser.SetFixFile(true);
}
auto itf = features.begin();
while (itf != features.end()) {
// Check if we have a match in the list of overwriteFeatures
bool checked = false;
auto itof = overwriteFeatures.begin();
while (itof != overwriteFeatures.end()) {
// Allow for for regex expression within overwrite files
kwssys::RegularExpression regex((*itof).filename.c_str());
if (regex.find((*it).c_str()) &&
(!strcmp((*itof).name.c_str(), (*itf).name.c_str()))) {
if ((*itof).enable) {
parser.Check((*itof).name.c_str(), (*itof).value.c_str());
}
if((*itof).name == "LineLength" && !((*itof).enable))
{
std::cout << "Cannot disable LineLength check. It computes internal parameters" << std::endl;
}
else
{
checked = true;
}
}
++itof;
}
if(!checked && (*itf).enable)
{
parser.Check((*itf).name.c_str(),(*itf).value.c_str());
}
++itf;
}
if(command.GetOptionWasSet("verbose"))
{
verbose = "1";
}
// If we should display the error
if(!verbose.empty()
&& !command.GetOptionWasSet("msvc")
&& !command.GetOptionWasSet("vim")
&& !command.GetOptionWasSet("gcc")
)
{
std::cout << parser.GetLastErrors().c_str() << std::endl;
std::cout << parser.GetLastWarnings().c_str() << std::endl;
}
if(command.GetOptionWasSet("vim"))
{
// Format the string for vim
const kws::Parser::ErrorVectorType errors = parser.GetErrors();
auto eit = errors.begin();
while(eit != errors.end())
{
std::cout << (*it).c_str() << ":" << (*eit).line << ":"
<< (*eit).description << std::endl;
++eit;
}
}
else if(command.GetOptionWasSet("msvc"))
{
// Format the string for Visual Studio
const kws::Parser::ErrorVectorType errors = parser.GetErrors();
auto eit = errors.begin();
while(eit != errors.end())
{
std::cout << (*it).c_str() << "(" << (*eit).line << ") : error " << (*eit).number << ":"
<< (*eit).description << std::endl;
++eit;
}
const kws::Parser::WarningVectorType warnings = parser.GetWarnings();
auto wit = warnings.begin();
while(wit != warnings.end())
{
std::cout << (*it).c_str() << "(" << (*wit).line << ") : warning " << (*wit).number << ":"
<< (*wit).description << std::endl;
++wit;
}
}
else if(command.GetOptionWasSet("gcc"))
{
// Format the string for Visual Studio
const kws::Parser::ErrorVectorType errors = parser.GetErrors();
auto eit = errors.begin();
while(eit != errors.end())
{
std::cout << (*it).c_str() << ":" << (*eit).line << ": error: "
<< (*eit).description << std::endl;
++eit;
}
const kws::Parser::WarningVectorType warnings = parser.GetWarnings();
auto wit = warnings.begin();
while(wit != warnings.end())
{
std::cout << (*it).c_str() << ":" << (*wit).line << ": warning: "
<< (*wit).description << std::endl;
++wit;
}
}
if(command.GetOptionWasSet("cvs"))
{
std::cout << parser.GetLastErrors().c_str() << std::endl;
if (!parser.GetErrors().empty()) {
return 1;
}
}
nerrors += parser.GetErrors().size();
parser.GenerateFixedFile();
m_Parsers.push_back(parser);
++it;
} // end filenames
if(command.GetOptionWasSet("html"))
{
htmlDirectory = command.GetValueAsString("html","filename");
}
// If we should generate the HTML file
if(!htmlDirectory.empty())
{
kws::Generator generator;
generator.SetParser(&m_Parsers);
if(command.GetOptionWasSet("xml"))
{
std::string xml = command.GetValueAsString("xml","filename");
generator.ReadConfigurationFile(xml.c_str());
}
bool showNoErrors = false;
if (!lessHTML.empty()) {
if(lessHTML[0] == '1')
{
showNoErrors = true;
}
}
if(command.GetOptionWasSet("lesshtml"))
{
showNoErrors = true;
}
generator.GenerateHTML(htmlDirectory.c_str(), !showNoErrors);
}
// If we should export the html report
if(command.GetOptionWasSet("exporthtml"))
{
kws::Generator generator;
if(command.GetOptionWasSet("xml"))
{
std::string xml = command.GetValueAsString("xml", "filename");
generator.ReadConfigurationFile(xml.c_str());
}
generator.SetParser(&m_Parsers);
generator.ExportHTML(std::cout);
}
if(command.GetOptionWasSet("exportxml"))
{
const std::string outputxmlFile = command.GetValueAsString("exportxml","filename");
kws::Generator generator;
generator.SetParser(&m_Parsers);
generator.ExportXML(outputxmlFile.c_str());
}
// If we should generate dart files
if(command.GetOptionWasSet("dart"))
{
std::string dart = command.GetValueAsString("dart", "filename");
int maxerror = command.GetValueAsInt("dart", "maxerror");
bool grouperrors = command.GetValueAsBool("dart", "group");
kws::Generator generator;
if(command.GetOptionWasSet("xml"))
{
std::string xml = command.GetValueAsString("xml", "filename");
generator.ReadConfigurationFile(xml.c_str());
}
generator.SetParser(&m_Parsers);
std::string url = "";
if(command.GetOptionWasSet("kwsurl"))
{
url = command.GetValueAsString("kwsurl","url");
}
std::string baseDirectory = "";
if(command.GetOptionWasSet("basedirectory"))
{
baseDirectory = command.GetValueAsString("basedirectory","filename");
}
generator.GenerateDart(dart.c_str(),maxerror,grouperrors,url,time0,baseDirectory.c_str());
}
// If we have errors we return false
if(nerrors > 0)
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}