PageRenderTime 242ms CodeModel.GetById 120ms app.highlight 4ms RepoModel.GetById 117ms app.codeStats 0ms

/mordor/examples/cat.cpp

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