summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2017-04-12 07:47:30 +0200
committerNIIBE Yutaka <gniibe@fsij.org>2017-04-12 07:47:30 +0200
commit7b4edf14bb16fbe786e55b829a208960396ce8df (patch)
tree96cb9123e8f42a7400143e27b3fd301f8bdb1acf /common
parentgpgscm: Fix test program. (diff)
downloadgnupg2-7b4edf14bb16fbe786e55b829a208960396ce8df.tar.xz
gnupg2-7b4edf14bb16fbe786e55b829a208960396ce8df.zip
common: Simplify format_text.
* common/stringhelp.c (format_text): Don't allow IN_PLACE formatting. * common/stringhelp.h: Change the API with no IN_PLACE. * common/t-stringhelp.c (test_format_text): Follow the change. * g10/gpgcompose.c (show_help): Likewise. * g10/tofu.c (format_conflict_msg_part1, ask_about_binding) (show_statistics, show_warning): Likewise. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'common')
-rw-r--r--common/stringhelp.c9
-rw-r--r--common/stringhelp.h2
-rw-r--r--common/t-stringhelp.c2
3 files changed, 6 insertions, 7 deletions
diff --git a/common/stringhelp.c b/common/stringhelp.c
index bea146647..509d327b0 100644
--- a/common/stringhelp.c
+++ b/common/stringhelp.c
@@ -1443,11 +1443,10 @@ compare_version_strings (const char *my_version, const char *req_version)
/* Format a string so that it fits within about TARGET_COLS columns.
- If IN_PLACE is 0, then TEXT is copied to a new buffer, which is
- returned. Otherwise, TEXT is modified in place and returned.
+ TEXT_IN is copied to a new buffer, which is returned.
Normally, target_cols will be 72 and max_cols is 80. */
char *
-format_text (char *text, int in_place, int target_cols, int max_cols)
+format_text (const char *text_in, int target_cols, int max_cols)
{
const int do_debug = 0;
@@ -1459,9 +1458,9 @@ format_text (char *text, int in_place, int target_cols, int max_cols)
char *last_space = NULL;
int last_space_cols = 0;
int copied_last_space = 0;
+ char *text;
- if (! in_place)
- text = xstrdup (text);
+ text = xstrdup (text_in);
p = line = text;
while (1)
diff --git a/common/stringhelp.h b/common/stringhelp.h
index 3852d0fe3..a643f359f 100644
--- a/common/stringhelp.h
+++ b/common/stringhelp.h
@@ -155,7 +155,7 @@ int split_fields (char *string, char **array, int arraysize);
int compare_version_strings (const char *my_version, const char *req_version);
/* Format a string so that it fits within about TARGET_COLS columns. */
-char *format_text (char *text, int in_place, int target_cols, int max_cols);
+char *format_text (const char *text, int target_cols, int max_cols);
/*-- mapstrings.c --*/
diff --git a/common/t-stringhelp.c b/common/t-stringhelp.c
index a105ad1bc..869ca56f0 100644
--- a/common/t-stringhelp.c
+++ b/common/t-stringhelp.c
@@ -885,7 +885,7 @@ test_format_text (void)
{
struct test *test = &tests[i];
char *result =
- format_text (test->input, 0, test->target_cols, test->max_cols);
+ format_text (test->input, test->target_cols, test->max_cols);
if (strcmp (result, test->expected) != 0)
{
printf ("%s: Test #%d failed.\nExpected: '%s'\nResult: '%s'\n",