diff options
author | Adrian Kummerlaender | 2016-04-02 22:25:50 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2016-04-02 22:25:50 +0200 |
commit | 182ee7769f167f54b4952177d9226c4941e67275 (patch) | |
tree | 36d0e7637299f4f8fd375bd00b73cc13eb1ccafa | |
parent | a5a81425f4e656ecf0e867e114863b1b208e90b0 (diff) | |
download | justify-182ee7769f167f54b4952177d9226c4941e67275.tar justify-182ee7769f167f54b4952177d9226c4941e67275.tar.gz justify-182ee7769f167f54b4952177d9226c4941e67275.tar.bz2 justify-182ee7769f167f54b4952177d9226c4941e67275.tar.lz justify-182ee7769f167f54b4952177d9226c4941e67275.tar.xz justify-182ee7769f167f54b4952177d9226c4941e67275.tar.zst justify-182ee7769f167f54b4952177d9226c4941e67275.zip |
Implement support for user-defined line length
-rw-r--r-- | justify.cc | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -1,15 +1,32 @@ +#include <string> #include <iostream> #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; } |