diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-11-17 22:19:25 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-11-18 12:01:11 +0200 |
commit | bc2a36294a31e7e65004b129e2c8a5057e5f9bac (patch) | |
tree | e341d23b0d3683c33b0837dee1512f8e3aefd8f5 /src/gdbmshell.c | |
parent | 9b4ef43adf31250682625f8b482e659ea1e11413 (diff) | |
download | gdbm-bc2a36294a31e7e65004b129e2c8a5057e5f9bac.tar.gz |
Word wrapping output functions for gdbm apps
* src/Makefile.am (libgdbmapp_a_SOURCES): Add wordwrap.c
* src/wordwrap.c: New file.
* tests/Makefile.am: Add t_wordwrap and wordspit.at
* tests/testsuite.at: Add new test.
* tests/t_wordwrap.c: New file.
* src/gdbmshell.c (help_handler): Use wordwrap functions.
* src/parseopt.c: Rewrite help output using wordwrap.
Add support for the ARGP_HELP_FMT environment variable.
Make sure no empty strings are ever passed to gettext.
Diffstat (limited to 'src/gdbmshell.c')
-rw-r--r-- | src/gdbmshell.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/gdbmshell.c b/src/gdbmshell.c index 45e3f9f..08042ce 100644 --- a/src/gdbmshell.c +++ b/src/gdbmshell.c @@ -2415,34 +2415,34 @@ help_handler (struct command_param *param GDBM_ARG_UNUSED, struct command_environ *cenv) { struct command *cmd; - FILE *fp = cenv->fp; + WORDWRAP_FILE wf; + + fflush (cenv->fp); + wf = wordwrap_fdopen (fileno (cenv->fp)); for (cmd = command_tab; cmd->name; cmd++) { int i; int n; - int optoff; - - n = fprintf (fp, " %s", cmd->name); - optoff = n; - + + wordwrap_set_left_margin (wf, 1); + wordwrap_set_right_margin (wf, 0); + n = strlen (cmd->name); + wordwrap_write (wf, cmd->name, n); + + wordwrap_set_left_margin (wf, n + 2); for (i = 0; i < NARGS && cmd->args[i].name; i++) { - if (n >= CMDCOLS) - { - fputc ('\n', fp); - n = fprintf (fp, "%*.*s", optoff, optoff, ""); - } - n += fprintf (fp, " %s", gettext (cmd->args[i].name)); + wordwrap_printf (wf, " %s", gettext (cmd->args[i].name)); } - if (n < CMDCOLS) - fprintf (fp, "%*.s", CMDCOLS-n, ""); - else - fprintf (fp, "\n%*.*s", CMDCOLS, CMDCOLS, ""); - fprintf (fp, " %s", gettext (cmd->doc)); - fputc ('\n', fp); + wordwrap_set_right_margin (wf, 0); + wordwrap_set_left_margin (wf, CMDCOLS); + + wordwrap_printf (wf, " %s", gettext (cmd->doc)); + wordwrap_flush (wf); } + wordwrap_close (wf); return 0; } |