 |
Kea
1.5.0
|
Go to the documentation of this file.
34 #include <boost/foreach.hpp>
70 cout << VERSION <<
"\n";
80 "Usage: kea-msg-compiler [-h] [-v] [-d dir] <message-file>\n" <<
82 "-h Print this message and exit\n" <<
83 "-v Print the program version and exit\n" <<
84 "-d <dir> Place output files in given directory\n" <<
86 "<message-file> is the name of the input message file.\n";
103 timeinfo = localtime(&curtime);
106 strftime(buffer, 80,
"%a %b %d %Y %H:%M", timeinfo);
108 return (std::string(buffer));
125 string name = file.
name();
127 string sentinel_text = name +
"_" + ext.substr(1);
129 return (sentinel_text);
146 outstring.reserve(instring.size());
149 for (
size_t i = 0; i < instring.size(); ++i) {
150 if (instring[i] ==
'"') {
153 outstring += instring[i];
171 vector<string> ident;
174 i != dictionary.
end(); ++i) {
175 ident.push_back(i->first);
177 sort(ident.begin(), ident.end());
203 while ((dcolon = ns.find(
"::")) != string::npos) {
204 ns.replace(dcolon, 2,
":");
221 for (vector<string>::size_type i = 0; i < ns.size(); ++i) {
222 output <<
"namespace " << ns[i] <<
" {\n";
235 for (
int i = ns.size() - 1; i >= 0; --i) {
236 output <<
"} // namespace " << ns[i] <<
"\n";
264 if (output_directory != NULL) {
269 string sentinel_text =
sentinel(header_file);
275 ofstream hfile(header_file.
fullName().c_str());
287 "// File created from " << message_file.
fullName() <<
" on " <<
290 "#ifndef " << sentinel_text <<
"\n" <<
291 "#define " << sentinel_text <<
"\n" <<
293 "#include <log/message_types.h>\n" <<
300 for (vector<string>::const_iterator j = idents.begin();
301 j != idents.end(); ++j) {
302 hfile <<
"extern const isc::log::MessageID " << *j <<
";\n";
309 hfile <<
"#endif // " << sentinel_text <<
"\n";
328 return (isalnum(c) ? c :
'_');
368 const char* output_directory)
372 if (output_directory) {
380 ofstream ccfile(program_file.
fullName().c_str());
392 "// File created from " << message_file.
fullName() <<
" on " <<
395 "#include <cstddef>\n" <<
396 "#include <log/message_types.h>\n" <<
397 "#include <log/message_initializer.h>\n" <<
405 for (vector<string>::const_iterator j = idents.begin();
406 j != idents.end(); ++j) {
407 ccfile <<
"extern const isc::log::MessageID " << *j <<
408 " = \"" << *j <<
"\";\n";
419 "const char* values[] = {\n";
423 for (vector<string>::const_iterator i = idents.begin();
424 i != idents.end(); ++i) {
425 ccfile <<
" \"" << *i <<
"\", \"" <<
435 "const isc::log::MessageInitializer initializer(values);\n" <<
437 "} // Anonymous namespace\n" <<
465 if (!duplicates.empty()) {
466 cout <<
"Error: the following duplicate IDs were found:\n";
468 sort(duplicates.begin(), duplicates.end());
469 MessageReader::MessageIDCollection::iterator new_end =
470 unique(duplicates.begin(), duplicates.end());
471 for (MessageReader::MessageIDCollection::iterator i = duplicates.begin();
473 cout <<
" " << *i <<
"\n";
488 const char* soptions =
"hvpd:";
493 const char *output_directory = NULL;
495 while ((opt = getopt(argc, argv, soptions)) != -1) {
498 output_directory = optarg;
516 if (optind < (argc - 1)) {
517 cout <<
"Error: excess arguments in command line\n";
520 }
else if (optind >= argc) {
521 cout <<
"Error: missing message file\n";
525 string message_file = argv[optind];
541 vector<string> ns_components =
556 string text = e.
id();
558 text += global->getText(e.
id());
561 for (
size_t i(0); i < args.size(); ++ i) {
569 cerr << text <<
"\n";
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.
const_iterator end() const
Return end() iterator of internal map.
int main(int argc, char *argv[])
Main Program.
string sentinel(Filename &file)
Create Header Sentinel.
Class to Manipulate Filenames.
string quoteString(const string &instring)
Quote String.
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 errorDuplicates(MessageReader &reader)
Error and exit if there are duplicate entries.
virtual void readFile(const std::string &file, Mode mode=ADD)
Read File.
void setDirectory(const std::string &new_directory)
Set directory for the file.
std::vector< std::string > arguments() const
Return Arguments.
void replacePlaceholder(string *message, const string &arg, const unsigned placeholder)
The internal replacement routine.
virtual const std::string & getText(const MessageID &ident) const
Get Message Text.
MessageID id() const
Return Message ID.
#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.
boost::shared_ptr< MessageDictionary > MessageDictionaryPtr
Shared pointer to the MessageDictionary.
std::string fullName() const
const isc::log::MessageID LOG_OPEN_OUTPUT_FAIL
virtual std::string getNamespace() const
Get Namespace.
string currentTime()
Create Time.
MessageIDCollection getNotAdded() const
Get Not-Added List.
const isc::log::MessageID LOG_WRITE_ERROR
std::string useAsDefault(const std::string &name) const
Use as Default and Substitute into String.
void writeClosingNamespace(ostream &output, const vector< string > &ns)
Write Closing Namespace(s)
void version()
Print Version.
std::vector< std::string > MessageIDCollection
Visible collection types.
vector< string > splitNamespace(string ns)
Split Namespace.
void uppercase(std::string &text)
Uppercase String.
std::string extension() const
Dictionary::const_iterator const_iterator
vector< string > sortedIdentifiers(MessageDictionary &dictionary)
Sorted Identifiers.
const_iterator begin() const
Return begin() iterator of internal map.