34 #include <boost/foreach.hpp>
69 cout << VERSION <<
"\n";
79 "Usage: kea-msg-compiler [-h] [-v] [-d dir] <message-file>\n" <<
81 "-h Print this message and exit\n" <<
82 "-v Print the program version and exit\n" <<
83 "-d <dir> Place output files in given directory\n" <<
85 "<message-file> is the name of the input message file.\n";
101 string name = file.
name();
103 string sentinel_text = name +
"_" + ext.substr(1);
105 return (sentinel_text);
121 outstring.reserve(instring.size());
124 for (
size_t i = 0; i < instring.size(); ++i) {
125 if (instring[i] ==
'"') {
128 outstring += instring[i];
145 vector<string> ident;
148 i != dictionary.
end(); ++i) {
149 ident.push_back(i->first);
151 sort(ident.begin(), ident.end());
176 while ((dcolon = ns.find(
"::")) != string::npos) {
177 ns.replace(dcolon, 2,
":");
193 for (vector<string>::size_type i = 0; i < ns.size(); ++i) {
194 output <<
"namespace " << ns[i] <<
" {\n";
206 for (
int i = ns.size() - 1; i >= 0; --i) {
207 output <<
"} // namespace " << ns[i] <<
"\n";
230 const vector<string>& ns_components,
232 const char* output_directory) {
235 if (output_directory != NULL) {
240 string sentinel_text =
sentinel(header_file);
246 ofstream hfile(header_file.fullName().c_str());
258 "// File created from " << message_file.
fullName() <<
"\n" <<
260 "#ifndef " << sentinel_text <<
"\n" <<
261 "#define " << sentinel_text <<
"\n" <<
263 "#include <log/message_types.h>\n" <<
270 for (vector<string>::const_iterator j = idents.begin();
271 j != idents.end(); ++j) {
272 hfile <<
"extern const isc::log::MessageID " << *j <<
";\n";
279 hfile <<
"#endif // " << sentinel_text <<
"\n";
296 return (isalnum(c) ? c :
'_');
334 const vector<string>& ns_components,
336 const char* output_directory) {
339 if (output_directory) {
347 ofstream ccfile(program_file.fullName().c_str());
359 "// File created from " << message_file.
fullName() <<
"\n" <<
361 "#include <cstddef>\n" <<
362 "#include <log/message_types.h>\n" <<
363 "#include <log/message_initializer.h>\n" <<
371 for (vector<string>::const_iterator j = idents.begin();
372 j != idents.end(); ++j) {
373 ccfile <<
"extern const isc::log::MessageID " << *j <<
374 " = \"" << *j <<
"\";\n";
385 "const char* values[] = {\n";
389 for (vector<string>::const_iterator i = idents.begin();
390 i != idents.end(); ++i) {
391 ccfile <<
" \"" << *i <<
"\", \"" <<
400 "const isc::log::MessageInitializer initializer(values);\n" <<
402 "} // Anonymous namespace\n" <<
428 if (!duplicates.empty()) {
429 cout <<
"Error: the following duplicate IDs were found:\n";
431 sort(duplicates.begin(), duplicates.end());
432 MessageReader::MessageIDCollection::iterator new_end =
433 unique(duplicates.begin(), duplicates.end());
434 for (MessageReader::MessageIDCollection::iterator i = duplicates.begin();
436 cout <<
" " << *i <<
"\n";
449 const char* soptions =
"hvpd:";
454 const char *output_directory = NULL;
456 while ((opt = getopt(argc, argv, soptions)) != -1) {
459 output_directory = optarg;
477 if (optind < (argc - 1)) {
478 cout <<
"Error: excess arguments in command line\n";
481 }
else if (optind >= argc) {
482 cout <<
"Error: missing message file\n";
486 string message_file = argv[optind];
502 vector<string> ns_components =
517 string text = e.
id();
519 text += global->getText(e.
id());
522 for (
size_t i(0); i < args.size(); ++ i) {
530 cerr << text <<
"\n";
const isc::log::MessageID LOG_WRITE_ERROR
MessageIDCollection getNotAdded() const
Get Not-Added List.
virtual std::string getNamespace() const
Get Namespace.
Dictionary::const_iterator const_iterator
virtual void readFile(const std::string &file, Mode mode=ADD)
Read File.
void setDirectory(const std::string &new_directory)
Set directory for the file.
void writeProgramFile(const string &file, const vector< string > &ns_components, MessageDictionary &dictionary, const char *output_directory)
Write Program File.
std::string fullName() const
string sentinel(Filename &file)
Create Header Sentinel.
virtual const std::string & getText(const MessageID &ident) const
Get Message Text.
#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 replacePlaceholder(std::string &message, const string &arg, const unsigned placeholder)
The internal replacement routine.
std::string extension() const
void uppercase(std::string &text)
Uppercase String.
std::vector< std::string > arguments() const
Return Arguments.
string quoteString(const string &instring)
Quote String.
const isc::log::MessageID LOG_OPEN_OUTPUT_FAIL
const_iterator begin() const
Return begin() iterator of internal map.
MessageID id() const
Return Message ID.
void writeClosingNamespace(ostream &output, const vector< string > &ns)
Write Closing Namespace(s)
vector< string > tokens(const std::string &text, const std::string &delim, bool escape)
Split String into Tokens.
char replaceNonAlphaNum(char c)
Convert Non Alpha-Numeric Characters to Underscores.
void writeOpeningNamespace(ostream &output, const vector< string > &ns)
Write Opening Namespace(s)
boost::shared_ptr< MessageDictionary > MessageDictionaryPtr
Shared pointer to the MessageDictionary.
void writeHeaderFile(const string &file, const vector< string > &ns_components, MessageDictionary &dictionary, const char *output_directory)
Write Header File.
void errorDuplicates(MessageReader &reader)
Error and exit if there are duplicate entries.
vector< string > sortedIdentifiers(MessageDictionary &dictionary)
Sorted Identifiers.
void version()
Print Version.
vector< string > splitNamespace(string ns)
Split Namespace.
const_iterator end() const
Return end() iterator of internal map.
int main(int argc, char *argv[])
Main Program.
Class to Manipulate Filenames.
std::vector< std::string > MessageIDCollection
Visible collection types.