PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/mordor/examples/cat.cpp

http://github.com/mozy/mordor
C++ | 42 lines | 36 code | 5 blank | 1 comment | 6 complexity | 372ec2d2c7fb94837e4810612621bc94 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. // Copyright (c) 2009 - Mozy, Inc.
  2. #include "mordor/predef.h"
  3. #include <iostream>
  4. #include "mordor/config.h"
  5. #include "mordor/main.h"
  6. #include "mordor/streams/file.h"
  7. #include "mordor/streams/std.h"
  8. #include "mordor/streams/transfer.h"
  9. #include "mordor/workerpool.h"
  10. using namespace Mordor;
  11. MORDOR_MAIN(int argc, const char * const argv[])
  12. {
  13. try {
  14. Config::loadFromEnvironment();
  15. StdoutStream stdoutStream;
  16. WorkerPool pool(2);
  17. if (argc == 1) {
  18. argc = 2;
  19. const char * const hyphen[] = { "", "-" };
  20. argv = hyphen;
  21. }
  22. for (int i = 1; i < argc; ++i) {
  23. Stream::ptr inStream;
  24. std::string arg(argv[i]);
  25. if (arg == "-") {
  26. inStream.reset(new StdinStream());
  27. } else {
  28. inStream.reset(new FileStream(arg, FileStream::READ));
  29. }
  30. transferStream(inStream, stdoutStream);
  31. }
  32. } catch (...) {
  33. std::cerr << boost::current_exception_diagnostic_information()
  34. << std::endl;
  35. }
  36. return 0;
  37. }