aboutsummaryrefslogtreecommitdiff
path: root/justify.cc
blob: b20496c5ccba6724a696f8ba6b6ca98a1ad9a87f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <string>
#include <iostream>

#include "line_accumulator.h"

int main(int argc, char* argv[]) {
	std::cout.sync_with_stdio(false);
	std::cin.sync_with_stdio(false);

	std::uint8_t max_line_length = 60;

	if ( argc == 2 ) {
		const int user_length = std::stoi(argv[1]);

		if ( user_length > 1 && user_length < 256 ) {
			max_line_length = user_length;
		} else {
			std::cerr << "Invalid line length.\n";

			return -1;
		}
	}

	justify::LineAccumulator acc{max_line_length};
	std::string              token;

	while ( std::cin >> token ) {
		acc(token);
	}

	return 0;
}