From 182ee7769f167f54b4952177d9226c4941e67275 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 2 Apr 2016 22:25:50 +0200 Subject: Implement support for user-defined line length --- justify.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/justify.cc b/justify.cc index 73a3a3b..b20496c 100644 --- a/justify.cc +++ b/justify.cc @@ -1,15 +1,32 @@ +#include #include #include "line_accumulator.h" -int main() { +int main(int argc, char* argv[]) { std::cout.sync_with_stdio(false); std::cin.sync_with_stdio(false); - justify::LineAccumulator acc{60}; + 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; } -- cgit v1.2.3