[Pkg-gnupg-commit] [gnupg2] 62/132: common: Simplify format_text.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed May 17 03:07:42 UTC 2017


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gnupg2.

commit 7b4edf14bb16fbe786e55b829a208960396ce8df
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Wed Apr 12 14:47:30 2017 +0900

    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 at fsij.org>
---
 common/stringhelp.c   |  9 ++++-----
 common/stringhelp.h   |  2 +-
 common/t-stringhelp.c |  2 +-
 g10/gpgcompose.c      |  2 +-
 g10/tofu.c            | 10 +++++-----
 5 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/common/stringhelp.c b/common/stringhelp.c
index bea1466..509d327 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 3852d0f..a643f35 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 a105ad1..869ca56 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",
diff --git a/g10/gpgcompose.c b/g10/gpgcompose.c
index d585502..071d6bf 100644
--- a/g10/gpgcompose.c
+++ b/g10/gpgcompose.c
@@ -305,7 +305,7 @@ show_help (struct option options[])
 
       if (! option)
         space = 72;
-      formatted = format_text (tmp, 0, space, space + 4);
+      formatted = format_text (tmp, space, space + 4);
 
       if (tmp != help)
         xfree (tmp);
diff --git a/g10/tofu.c b/g10/tofu.c
index 9f83fa4..4e12905 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -1355,7 +1355,7 @@ format_conflict_msg_part1 (int policy, strlist_t conflict_set,
   es_fputc (0, fp);
   if (es_fclose_snatch (fp, (void **)&tmpstr, NULL))
     log_fatal ("error snatching memory stream\n");
-  text = format_text (tmpstr, 0, 72, 80);
+  text = format_text (tmpstr, 72, 80);
   es_free (tmpstr);
 
   return text;
@@ -1913,7 +1913,7 @@ ask_about_binding (ctrl_t ctrl,
       /* TRANSLATORS: Please translate the text found in the source
        * file below.  We don't directly internationalize that text so
        * that we can tweak it without breaking translations.  */
-      char *text = _("TOFU detected a binding conflict");
+      const char *text = _("TOFU detected a binding conflict");
       char *textbuf;
       if (!strcmp (text, "TOFU detected a binding conflict"))
         {
@@ -1926,7 +1926,7 @@ ask_about_binding (ctrl_t ctrl,
             "attack!  Before accepting this association, you should talk to or "
             "call the person to make sure this new key is legitimate.";
         }
-      textbuf = format_text (text, 0, 72, 80);
+      textbuf = format_text (text, 72, 80);
       es_fprintf (fp, "\n%s\n", textbuf);
       xfree (textbuf);
     }
@@ -3190,7 +3190,7 @@ show_statistics (tofu_dbs_t dbs,
         es_fputc (0, fp);
         if (es_fclose_snatch (fp, (void **) &tmpmsg, NULL))
           log_fatal ("error snatching memory stream\n");
-        msg = format_text (tmpmsg, 0, 72, 80);
+        msg = format_text (tmpmsg, 72, 80);
         es_free (tmpmsg);
 
         /* Print a status line but suppress the trailing LF.
@@ -3265,7 +3265,7 @@ show_warning (const char *fingerprint, strlist_t user_id_list)
       strlist_length (user_id_list)),
      set_policy_command);
 
-  text = format_text (tmpmsg, 0, 72, 80);
+  text = format_text (tmpmsg, 72, 80);
   xfree (tmpmsg);
   log_string (GPGRT_LOG_INFO, text);
   xfree (text);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list