From 35b825a84cdeae0e1c90042b469c47b519b76c23 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Wed, 28 Nov 2018 21:39:35 +0000 Subject: [PATCH] Format options help into indented paragraphs --- argparse/argparse.c | 25 ++++++++++++++++++++++++- examples/main.c | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/argparse/argparse.c b/argparse/argparse.c index f53184bab1..82bdc7d3d0 100644 --- a/argparse/argparse.c +++ b/argparse/argparse.c @@ -368,7 +368,30 @@ argparse_usage(struct argparse *self) fputc('\n', stdout); pad = usage_opts_width; } - fprintf(stdout, "%*s%s\n", pad + 2, "", options->help); + if (options->help != NULL && strlen(options->help) > 0) { + char *str = strdup(options->help); + char *token = strtok(str, " "); + fprintf(stdout, "%*s%s ", pad + 2, "", token); + int count = strlen(token); + int dangling = 1; + while ((token = strtok(NULL, " ")) != NULL) { + if (count == 0) { + fprintf(stdout, "%*s", (int)pos + pad + 2, ""); + dangling = 1; + } + printf("%s ", token); + count += strlen(token); + if (count > 30) { + count = 0; + fprintf(stdout, "\n"); + dangling = 0; + } + } + if (dangling) fprintf(stdout, "\n"); + } else { + fprintf(stdout, "\n"); + } + } // print epilog diff --git a/examples/main.c b/examples/main.c index 1147794d8b..b35cd7e54d 100644 --- a/examples/main.c +++ b/examples/main.c @@ -198,7 +198,7 @@ int main(int argc, char *argv[]) { "Pin runners using processor affinity.", NULL, 0, 0), OPT_BOOLEAN('d', "dry-run", &dry_run, "Dry run. Read the parameter file, allocates memory but " - "does not read the particles from ICs.\t\nExits before the " + "does not read the particles from ICs. Exits before the " "start of time integration. Checks the validity of " "parameters and IC files as well as memory limits.", NULL, 0, 0), -- GitLab