8#include <kea_version.h>
69 cout << VERSION <<
"\n";
74 cout << VERSION <<
" (" << SOURCE_OF_INSTALLATION <<
")\n";
84 "Usage: kea-msg-compiler [-h] [-v] [-d dir] <message-file>\n" <<
86 "-h Print this message and exit\n" <<
87 "-v Print the program version and exit\n" <<
88 "-d <dir> Place output files in given directory\n" <<
90 "<message-file> is the name of the input message file.\n";
105 string name =
file.stem();
106 string ext =
file.extension();
107 string sentinel_text = name +
"_" + ext.substr(1);
109 return (sentinel_text);
125 outstring.reserve(instring.size());
128 for (
size_t i = 0; i < instring.size(); ++i) {
129 if (instring[i] ==
'"') {
132 outstring += instring[i];
149 vector<string> ident;
151 for (
auto const& i : dictionary) {
152 ident.push_back(i.first);
154 sort(ident.begin(), ident.end());
179 while ((dcolon = ns.find(
"::")) != string::npos) {
180 ns.replace(dcolon, 2,
":");
196 for (vector<string>::size_type i = 0; i < ns.size(); ++i) {
197 output <<
"namespace " << ns[i] <<
" {\n";
209 for (
int i = ns.size() - 1; i >= 0; --i) {
210 output <<
"} // namespace " << ns[i] <<
"\n";
233 const vector<string>& ns_components,
235 const char* output_directory) {
238 if (output_directory != NULL) {
243 string sentinel_text =
sentinel(header_file);
249 ofstream hfile(header_file.
str());
261 "// File created from " << message_file.
str() <<
"\n" <<
263 "#ifndef " << sentinel_text <<
"\n" <<
264 "#define " << sentinel_text <<
"\n" <<
266 "#include <log/message_types.h>\n" <<
273 for (
auto const& j : idents) {
274 hfile <<
"extern const isc::log::MessageID " << j <<
";\n";
281 hfile <<
"#endif // " << sentinel_text <<
"\n";
298 return (isalnum(c) ? c :
'_');
336 const vector<string>& ns_components,
338 const char* output_directory) {
341 if (output_directory) {
349 ofstream ccfile(program_file.
str());
361 "// File created from " << message_file.
str() <<
"\n" <<
363 "#include <cstddef>\n" <<
364 "#include <log/message_types.h>\n" <<
365 "#include <log/message_initializer.h>\n" <<
373 for (
auto const& j : idents) {
374 ccfile <<
"extern const isc::log::MessageID " << j <<
375 " = \"" << j <<
"\";\n";
386 "const char* values[] = {\n";
390 for (
auto const& i : idents) {
399 "const isc::log::MessageInitializer initializer(values);\n" <<
401 "} // Anonymous namespace\n" <<
427 if (!duplicates.empty()) {
428 cout <<
"Error: the following duplicate IDs were found:\n";
430 sort(duplicates.begin(), duplicates.end());
431 MessageReader::MessageIDCollection::iterator new_end =
432 unique(duplicates.begin(), duplicates.end());
433 duplicates.erase(new_end, duplicates.end());
434 for (
auto const& i : duplicates) {
435 cout <<
" " << i <<
"\n";
448 const char* soptions =
"hvVpd:";
453 const char *output_directory = NULL;
455 while ((opt = getopt(argc, argv, soptions)) != -1) {
458 output_directory = optarg;
480 if (optind < (argc - 1)) {
481 cout <<
"Error: excess arguments in command line\n";
484 }
else if (optind >= argc) {
485 cout <<
"Error: missing message file\n";
489 string message_file = argv[optind];
505 vector<string> ns_components =
519 string text = e.
id();
521 text += global->getText(e.
id());
524 for (
size_t i(0); i < args.size(); ++ i) {
532 cerr << text <<
"\n";
535 }
catch (
const std::exception& ex) {
536 cerr <<
"Fatal error: " << ex.what() <<
"\n";
540 cerr <<
"Fatal error\n";
static const MessageDictionaryPtr & globalDictionary()
Return Global Dictionary.
virtual const std::string & getText(const MessageID &ident) const
Get Message Text.
std::vector< std::string > arguments() const
Return Arguments.
MessageID id() const
Return Message ID.
std::vector< std::string > MessageIDCollection
Visible collection types.
MessageIDCollection getNotAdded() const
Get Not-Added List.
virtual std::string getNamespace() const
Get Namespace.
virtual void readFile(const std::string &file, Mode mode=ADD)
Read File.
#define isc_throw_4(type, stream, param1, param2, param3, param4)
Similar as isc_throw, but allows the exception to have four additional parameters (the stream/text go...
void writeHeaderFile(const string &file, const vector< string > &ns_components, MessageDictionary &dictionary, const char *output_directory)
Write Header File.
int main(int argc, char *argv[])
Main Program.
char replaceNonAlphaNum(char c)
Convert Non Alpha-Numeric Characters to Underscores.
vector< string > splitNamespace(string ns)
Split Namespace.
void writeClosingNamespace(ostream &output, const vector< string > &ns)
Write Closing Namespace(s)
void writeProgramFile(const string &file, const vector< string > &ns_components, MessageDictionary &dictionary, const char *output_directory)
Write Program File.
void writeOpeningNamespace(ostream &output, const vector< string > &ns)
Write Opening Namespace(s)
void version()
Print Version.
string quoteString(const string &instring)
Quote String.
vector< string > sortedIdentifiers(MessageDictionary &dictionary)
Sorted Identifiers.
string sentinel(Path &file)
Create Header Sentinel.
void errorDuplicates(MessageReader &reader)
Error and exit if there are duplicate entries.
const isc::log::MessageID LOG_OPEN_OUTPUT_FAIL
void replacePlaceholder(std::string &message, const string &arg, const unsigned placeholder)
The internal replacement routine.
boost::shared_ptr< MessageDictionary > MessageDictionaryPtr
Shared pointer to the MessageDictionary.
const isc::log::MessageID LOG_WRITE_ERROR
vector< string > tokens(const string &text, const string &delim, bool escape)
Split string into tokens.
void uppercase(string &text)
Convert string to uppercase.
Path & replaceParentPath(std::string const &replacement=std::string())
Trims {replacement} and replaces this instance's parent path with it.
std::string str() const
Get the path in textual format.