view modules/unicode/generator/cat/cat.cpp @ 525:17a733c5661a

Unicode: resurrection
author David Demelier <markand@malikania.fr>
date Wed, 01 Jun 2016 17:13:26 +0200
parents
children f48bb09bccc7
line wrap: on
line source

/*
 * cccat.cpp -- very basic cat replacement for portability
 *
 * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>

int main(int argc, char **argv)
{
	-- argc;
	++ argv;

	if (argc < 2) {
		std::cerr << "usage: cat output file1 [files...]" << std::endl;
		return 1;
	}

	std::ofstream output(argv[0]);

	for (int i = 1; i < argc; ++i) {
		std::ifstream input(argv[i]);
		std::string line;

		while (std::getline(input, line))
			output << line << "\n";
	}

	return 0;
}