diff options
author | Brad Pitcher <bradpitcher@gmail.com> | 2011-11-01 18:29:29 (GMT) |
---|---|---|
committer | Brad Pitcher <bradpitcher@gmail.com> | 2011-11-01 18:29:29 (GMT) |
commit | 0eacddfd8148f14ee0ddfe2eb66b82774c88afbe (patch) | |
tree | 6982ea59564090ea858d12d86d3699e83887f1f9 /tests/echotest.cc | |
parent | ea7e4988d44249946b620d5973b230cf1a0606ca (diff) | |
parent | e2caf3726d68ff1fef63113519049abffc0563af (diff) |
merge master
Diffstat (limited to 'tests/echotest.cc')
-rw-r--r-- | tests/echotest.cc | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tests/echotest.cc b/tests/echotest.cc index 4811c7c..046f883 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -37,10 +37,13 @@ #include <QFile> #include <QDir> #include <QSet> +#ifndef _MSC_VER #include <getopt.h> +#endif #include <assert.h> #include <iostream> #include <sstream> +#include <fstream> using std::string; @@ -49,22 +52,29 @@ QString currentdir; QString examplesdir; QString librarydir; -static void stdout_handler(const QString &msg, void *userdata) { - std::cout << msg.toUtf8().data() << std::endl; +static void outfile_handler(const std::string &msg, void *userdata) { + std::ostream *str = static_cast<std::ostream*>(userdata); + *str << msg << std::endl; } int main(int argc, char **argv) { - if (argc != 2) { - fprintf(stderr, "Usage: %s <file.scad>\n", argv[0]); + if (argc != 3) { + fprintf(stderr, "Usage: %s <file.scad> <output.txt>\n", argv[0]); exit(1); } const char *filename = argv[1]; + const char *outfile = argv[2]; int rc = 0; - set_output_handler(&stdout_handler, NULL); + std::ofstream ofile(outfile); + if (!ofile.good()) { + std::cerr << "Unable to open output file\n"; + return 0; + } + set_output_handler(&outfile_handler, &ofile); initialize_builtin_functions(); initialize_builtin_modules(); @@ -144,5 +154,6 @@ int main(int argc, char **argv) destroy_builtin_functions(); destroy_builtin_modules(); + ofile.close(); return rc; } |