From 070411f5abd50014565a8c5bbe83a400b42b0ac2 Mon Sep 17 00:00:00 2001 From: Hrvoje Zeba Date: Fri, 26 Jul 2019 15:01:46 -0400 Subject: [PATCH] Added a new function arg_dstr_catc for appending char types and use it in arg_print_formatted_ds() --- src/arg_dstr.c | 5 +++++ src/argtable3.c | 2 +- src/argtable3.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/arg_dstr.c b/src/arg_dstr.c index b69134a..c57a27e 100644 --- a/src/arg_dstr.c +++ b/src/arg_dstr.c @@ -177,6 +177,11 @@ void arg_dstr_cat(arg_dstr_t ds, const char* str) { strncat(ds->data, str, strlen(str)); } +void arg_dstr_catc(arg_dstr_t ds, char c) { + setup_append_buf(ds, 2); + strncat(ds->data, &c, 1); +} + /* * The logic of the `arg_dstr_catf` function is adapted from the `bformat` * function in The Better String Library by Paul Hsieh. Here is the copyright diff --git a/src/argtable3.c b/src/argtable3.c index 1f9fc32..c4b2c56 100644 --- a/src/argtable3.c +++ b/src/argtable3.c @@ -917,7 +917,7 @@ static void arg_print_formatted_ds(arg_dstr_t ds, const unsigned lmargin, const /* Output line of text */ while (line_start < line_end) { char c = *(text + line_start); - arg_dstr_cat(ds, &c); + arg_dstr_catc(ds, c); line_start++; } arg_dstr_cat(ds, "\n"); diff --git a/src/argtable3.h b/src/argtable3.h index 08a363f..2042538 100644 --- a/src/argtable3.h +++ b/src/argtable3.h @@ -243,6 +243,7 @@ ARG_EXTERN void arg_dstr_reset(arg_dstr_t ds); ARG_EXTERN void arg_dstr_free(arg_dstr_t ds); ARG_EXTERN void arg_dstr_set(arg_dstr_t ds, char* str, arg_dstr_freefn* free_proc); ARG_EXTERN void arg_dstr_cat(arg_dstr_t ds, const char* str); +ARG_EXTERN void arg_dstr_catc(arg_dstr_t ds, char c); ARG_EXTERN void arg_dstr_catf(arg_dstr_t ds, const char* fmt, ...); ARG_EXTERN char* arg_dstr_cstr(arg_dstr_t ds);