From d1b34452618d36eb486ff18b16f5d94acc6eeb07 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 4 Feb 2016 15:34:54 +0200 Subject: Add support for multiple values in *-file options, add final newline --- odb/generator.cxx | 29 ++++++++++++++++++++++++++--- odb/options.cli | 26 +++++++++++++------------- 2 files changed, 39 insertions(+), 16 deletions(-) (limited to 'odb') diff --git a/odb/generator.cxx b/odb/generator.cxx index fcbc7ee..c255b02 100644 --- a/odb/generator.cxx +++ b/odb/generator.cxx @@ -91,7 +91,21 @@ namespace { ifstream ifs; open (ifs, file); - os << ifs.rdbuf (); + + // getline() will set the failbit if it failed to extract anything, + // not even the delimiter and eofbit if it reached eof before seeing + // the delimiter. + // + // We used to just do: + // + // os << ifs.rdbuf (); + // + // But that has some drawbacks: it won't end with a newline if the file + // doesn't end with one. There were also some issues with Windows newlines + // (we ended up doubling them). + // + for (string s; getline (ifs, s); ) + os << s << endl; } // Append prologue/interlude/epilogue. @@ -100,7 +114,7 @@ namespace append_logue (ostream& os, database db, database_map > const& text, - database_map const& file, + database_map > const& file, char const* begin_comment, char const* end_comment) { @@ -110,10 +124,19 @@ namespace if (t || f) { os << begin_comment << endl; + if (t) append (os, text[db]); + if (f) - append (os, path (file[db])); + { + strings const& fs (file[db]); + + for (strings::const_iterator i (fs.begin ()); + i != fs.end (); ++i) + append (os, path (*i)); + } + os << end_comment << endl << endl; } diff --git a/odb/options.cli b/odb/options.cli index cf511d7..3dbb3f8 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -554,42 +554,42 @@ class options // Prologue files. // - database_map --hxx-prologue-file + database_map > --hxx-prologue-file { "", "Insert the content of at the beginning of the generated C++ header file." }; - database_map --ixx-prologue-file + database_map > --ixx-prologue-file { "", "Insert the content of at the beginning of the generated C++ inline file." }; - database_map --cxx-prologue-file + database_map > --cxx-prologue-file { "", "Insert the content of at the beginning of the generated C++ source file." }; - database_map --schema-prologue-file + database_map > --schema-prologue-file { "", "Insert the content of at the beginning of the generated schema C++ source file." }; - database_map --sql-prologue-file + database_map > --sql-prologue-file { "", "Insert the content of at the beginning of the generated database schema file." }; - database_map --migration-prologue-file + database_map > --migration-prologue-file { "", "Insert the content of file at the beginning of the generated database @@ -598,7 +598,7 @@ class options // Interlude files. // - database_map --sql-interlude-file + database_map > --sql-interlude-file { "", "Insert the content of after all the \cb{DROP} and before any @@ -607,42 +607,42 @@ class options // Epilogue files. // - database_map --hxx-epilogue-file + database_map > --hxx-epilogue-file { "", "Insert the content of at the end of the generated C++ header file." }; - database_map --ixx-epilogue-file + database_map > --ixx-epilogue-file { "", "Insert the content of at the end of the generated C++ inline file." }; - database_map --cxx-epilogue-file + database_map > --cxx-epilogue-file { "", "Insert the content of at the end of the generated C++ source file." }; - database_map --schema-epilogue-file + database_map > --schema-epilogue-file { "", "Insert the content of at the end of the generated schema C++ source file." }; - database_map --sql-epilogue-file + database_map > --sql-epilogue-file { "", "Insert the content of at the end of the generated database schema file." }; - database_map --migration-epilogue-file + database_map > --migration-epilogue-file { "", "Insert the content of file at the end of the generated database -- cgit v1.1