commit cd98c3d1e55549e2c8fc932234887b0a9f301a81
parent e6778c95c2a44a183acacb4df20c9db5706352be
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date: Mon, 11 Jan 2021 04:19:31 +0100
lmerge: improve help printing
Diffstat:
1 file changed, 29 insertions(+), 16 deletions(-)
diff --git a/lmerge/src/lmerge.cpp b/lmerge/src/lmerge.cpp
@@ -28,6 +28,8 @@
#include <stdint.h>
#include <ctype.h>
+#include <unistd.h>
+
#include <algorithm>
#include <iterator>
@@ -342,24 +344,35 @@ bool allocate_markers(
void print_help( char const* pgm, FILE* target, opt_desc_t const* start, opt_desc_t const* end )
{
+ uint16_t w, h;
+ if( term_ch_size( &w, &h, STDOUT_FILENO ) )
+ {
+ w = 80;
+ fputs( "TODO: could not get terminal's size\n", stderr );
+ }
fputs( "Usage: ", target );
fputs( pgm, target );
- fputs( " [OPTIONS]\n"
- "Description:\n"
- "\tThis program reads stdin and when consecutive lines have specific fields all\n"
- "\tcontaining the same value, prints them replacing the newline character by\n"
- "\tthe 1st character in FIELD_SEP.\n"
- "\tFields are delimited by the FIELD_SEP environment variable. If not defined,\n"
- "\t\" \\t\" is used instead (see isblank(3)).\n"
- "\tFields to use are defined by the environment variable FIELDS, which only\n"
- "\tuse unsigned decimal integers separated by commas, other characters makes the\n"
- "\tvalue invalid.\n"
- "\tIf FIELDS is not defined or invalid, exits with an error.\n"
- "\tEmpty field indexes (\"1,,3\") are ignored (will resolve in \"1,3\").\n"
- "\tDo not work if input is not in line mode.\n"
- "\tLine separator is defined by ENTRY_SEP, or \"\\n\" if not defined.\n"
- "Options:\n"
- , target );
+ fputs( " [OPTIONS]\nDescription:\n", target );
+ char desc[] =
+ "This program reads stdin and when consecutive lines have specific "
+ "fields all containing the same value, prints them replacing the "
+ "newline character by the 1st character in FIELD_SEP.\n"
+ "Fields are delimited by the FIELD_SEP environment variable. If not "
+ "defined, \" \\t\" is used instead (see isblank(3)).\n"
+ "Fields to use are defined by the environment variable FIELDS, which "
+ "only use unsigned decimal integers separated by commas, other "
+ "characters makes the value invalid.\n"
+ "If FIELDS is not defined or invalid, exits with an error.\n"
+ "Empty field indexes (\"1,,3\") are ignored (will resolve in \"1,3\").\n"
+ "Do not work if input is not in line mode.\n"
+ "Line separator is defined by ENTRY_SEP, or \"\\n\" if not defined.\n"
+ ;
+ if( indent_txt( desc, std::end( desc ), 1, w, 8, target ) )
+ {
+ fputs( "TODO: handle indent_txt's errors\n", stderr );
+ }
+
+ fputs( "Options:\n", target );
print_opts( target, start, end );
}