[go: up one dir, main page]

Menu

[r60]: / trunk / src / main.cpp  Maximize  Restore  History

Download this file

172 lines (139 with data), 5.1 kB

  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
//
// Fontaine
//
//
// (c) 2009 by Edward H. Trager <ed.trager@gmail.com>
// All Rights Reserved.
// Released under GPL v. 2.0 or later.
//
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <set>
#include <vector>
#include "Utf8String.h"
#include "FontLibrary.h"
#include "FontFace.h"
#include "CLP.h" // Command line processor
#include "Warning.h"
#include "Message.h"
//
// For reporting:
//
#include "MLR.h"
#include "XMLR.h"
#include "JSONR.h"
#include "TEXTR.h"
#include "XHTMLR.h"
#include "FXHTMLR.h"
//
// MAIN
//
int main(int argc, const char *argv[]){
//
// Command line processor:
//
CLP clp("Fontaine","1.01",L("Copyright ⓒ 2014 by Edward H. Trager. All Rights Reserved. Released under GPL v. 2 or later."),"http://www.unifont.org","fontaine [option]... [font file]...\n");
//
// Set up command line switches:
//
clp.addSwitch("--json" , "-J" , "Produce output report in JSON format. (default)");
clp.addSwitch("--text" , "-T" , "Produce output report in plain text format.");
clp.addSwitch("--xhtml" , "-H" , "Produce output report in XHTML format.");
clp.addSwitch("--fxhtml" , "-Y" , "Produce output report in FANCY XHTML format.");
clp.addSwitch("--xml" , "-X" , "Produce output report in XML format.");
clp.addSwitch("--show-missing" , "-M" , "Report which Unicode values are missing from fragmentary and partially-supported orthographies. (default)");
clp.addSwitch("--show-fragmentary", "-R" , "Report orthographies for which the font provides only fragmentary support.");
clp.addSwitch("--show-partial" , "-P" , "Report orthographies for which the font provides only partial support");
clp.addSwitch("--show-full" , "-F" , "Report orthographies for which the font provides full support");
clp.addSwitch("--hide-missing" , "-m" , "Don't report which Unicode values are missing from fragmentary and partially-supported orthographies.");
clp.addSwitch("--hide-fragmentary", "-r" , "Don't report orthographies for which the font provides only fragmentary support.");
clp.addSwitch("--hide-partial" , "-p" , "Don't report orthographies for which the font provides only partial support");
clp.addSwitch("--hide-full" , "-f" , "Don't report orthographies for which the font provides full support");
clp.addSwitch("--version" , "-v" , "Print version and exit");
clp.addSwitch("--help" , "-h" , "Print help and exit");
//
// Parse command line arguments:
//
if(clp.parse(argc,argv)){
// No error, process the switches
if(clp.hasSwitchSet("--help")){
clp.printHelp();
return 0;
}
if(clp.hasSwitchSet("--version")){
clp.printCopyrightNotice();
return 0;
}
////////////////////
//
// MAIN PROCESSING:
//
////////////////////
//
// These are the arguments left over after stripping off command line arguments:
//
std::vector<std::string> arguments = clp.getArguments();
FontLibrary myLibrary;
////////////////////////////////////////////////////////////
//
// The report object:
//
// Can only have one report, so we only instantiate the first
// one ...
//
////////////////////////////////////////////////////////////
MLR *mlr;
unsigned int reportCount=0;
if (clp.hasSwitchSet("--text" ) ) mlr = new TEXTR();
else if (clp.hasSwitchSet("--xhtml") ) mlr = new XHTMLR();
else if (clp.hasSwitchSet("--fxhtml")) mlr = new FXHTMLR();
else if (clp.hasSwitchSet("--xml" ) ) mlr = new XMLR();
else {
//
// Always maintain JSON as the last option
// so that it will be the default option as well:
//
// if (clp.hasSwitchSet("--json" ) ) ...
//
mlr = new JSONR();
}
mlr->startRoot();
mlr->startList("fonts");
//
// Read font disk files:
//
for(unsigned i=0;i<arguments.size();i++){
//
// instantiate a FontFace object using the font file name:
//
FontFace myFace(myLibrary,arguments[i].c_str());
//
// The options are currently set in the FontFace object --
// -- this could change to a more elegant design in the future ...
//
if (clp.hasSwitchSet("--show-missing")) myFace.setReportOnMissing(true);
else if (clp.hasSwitchSet("--hide-missing")) myFace.setReportOnMissing(false);
if (clp.hasSwitchSet("--show-fragmentary")) myFace.setReportOnFragmentary(true);
else if (clp.hasSwitchSet("--hide-fragmentary")) myFace.setReportOnFragmentary(false);
if (clp.hasSwitchSet("--show-partial")) myFace.setReportOnPartial(true);
else if (clp.hasSwitchSet("--hide-partial")) myFace.setReportOnPartial(false);
if (clp.hasSwitchSet("--show-full")) myFace.setReportOnFull(true);
else if (clp.hasSwitchSet("--hide-full")) myFace.setReportOnFull(false);
//
// non-const method that calls methods
// on mlr to prepare the report:
//
myFace.fillReport(mlr);
}
mlr->endList("fonts");
mlr->endRoot();
//
// Print the report:
//
std::cout << mlr->getReport();
delete mlr;
}
return 0;
}