]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Code simplification: use xasprintf.
authorBruno Haible <bruno@clisp.org>
Wed, 3 May 2006 12:13:13 +0000 (12:13 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:13 +0000 (12:13 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/msginit.c
gettext-tools/src/write-java.c
gettext-tools/src/x-c.c
gettext-tools/src/xgettext.c

index 8db1b543ef4ea1e9c7f89d34008dc1d2d6007607..617d21ccb25b8e910a26b096426509dbcf34604b 100644 (file)
@@ -1,3 +1,14 @@
+2006-04-30  Bruno Haible  <bruno@clisp.org>
+
+       * msginit.c (main): Simplify by use of xasprintf().
+       * write-java.c: Include xvasprintf.h.
+       (msgdomain_write_java): Simplify by use of xasprintf().
+       * x-c.c: Include xvasprintf.h.
+       (phase8a_get): Simplify by use of xasprintf().
+       * xgettext.c: Don't include stpcpy.h.
+       (remember_a_message, remember_a_message_plural): Simplify by use of
+       xasprintf().
+
 2006-04-30  Bruno Haible  <bruno@clisp.org>
 
        * msgfmt.c: Include xvasprintf.h.
index 97b15e34474ca0350f9197c181ea12a014d1a90b..a73251976a70627639c8882f9ed58c1976c13a46 100644 (file)
@@ -313,11 +313,7 @@ file.  This is necessary so you can test your translations.\n")));
   /* Default output file name is CATALOGNAME.po.  */
   if (output_file == NULL)
     {
-      size_t cnlen = strlen (catalogname);
-
-      output_file = (char *) xmalloc (cnlen + 3 + 1);
-      memcpy (output_file, catalogname, cnlen);
-      memcpy (output_file + cnlen, ".po", 3 + 1);
+      output_file = xasprintf ("%s.po", catalogname);
 
       /* But don't overwrite existing PO files.  */
       if (access (output_file, F_OK) == 0)
index 29ad6504b5c735e2b56ab1238620a81028d8e577..b4d8f3fb6a10bc305fb0219b7ef97186838f1f42 100644 (file)
@@ -66,6 +66,7 @@
 #include "c-ctype.h"
 #include "error.h"
 #include "xerror.h"
+#include "xvasprintf.h"
 #include "javacomp.h"
 #include "message.h"
 #include "msgfmt.h"
@@ -948,11 +949,7 @@ but the Java ResourceBundle format doesn't support contexts\n")));
     }
 
   if (locale_name != NULL)
-    {
-      class_name =
-       (char *) xmalloc (strlen (resource_name) + 1 + strlen (locale_name) + 1);
-      sprintf (class_name, "%s_%s", resource_name, locale_name);
-    }
+    class_name = xasprintf ("%s_%s", resource_name, locale_name);
   else
     class_name = xstrdup (resource_name);
 
@@ -979,8 +976,7 @@ but the Java ResourceBundle format doesn't support contexts\n")));
 
     if (locale_name != NULL)
       {
-       char *suffix = (char *) xmalloc (1 + strlen (locale_name) + 5 + 1);
-       sprintf (suffix, "_%s.java", locale_name);
+       char *suffix = xasprintf ("_%s.java", locale_name);
        java_file_name = concatenated_pathname (last_dir, p, suffix);
        free (suffix);
       }
index 4e1631209d9ad35901011a05ddbc707682262e97..cacc7739c35f912b466925bb09c01503edb65eed 100644 (file)
@@ -33,6 +33,7 @@
 #include "error.h"
 #include "error-progname.h"
 #include "xalloc.h"
+#include "xvasprintf.h"
 #include "exit.h"
 #include "hash.h"
 #include "gettext.h"
@@ -1445,12 +1446,7 @@ phase8a_get (token_ty *tp)
   if (tp->type == token_type_name && is_inttypes_macro (tp->string))
     {
       /* Turn PRIdXXX into "<PRIdXXX>".  */
-      size_t len = strlen (tp->string);
-      char *new_string = (char *) xmalloc (len + 3);
-      new_string[0] = '<';
-      memcpy (new_string + 1, tp->string, len);
-      new_string[len + 1] = '>';
-      new_string[len + 2] = '\0';
+      char *new_string = xasprintf ("<%s>", tp->string);
       free (tp->string);
       tp->string = new_string;
       tp->comment = add_reference (savable_comment);
index f03166aeb3fb89fbaf61aa74550e142a3bfc8842..54ebce54f4953d77e0a0826d5672c382588710d0 100644 (file)
@@ -51,7 +51,6 @@
 #include "exit.h"
 #include "pathname.h"
 #include "c-strcase.h"
-#include "stpcpy.h"
 #include "open-po.h"
 #include "read-po-abstract.h"
 #include "message.h"
@@ -2040,13 +2039,7 @@ meta information, not the empty string.\n")));
       /* Construct the msgstr from the prefix and suffix, otherwise use the
         empty string.  */
       if (msgstr_prefix)
-       {
-         msgstr = (char *) xmalloc (strlen (msgstr_prefix)
-                                    + strlen (msgid)
-                                    + strlen (msgstr_suffix) + 1);
-         stpcpy (stpcpy (stpcpy (msgstr, msgstr_prefix), msgid),
-                 msgstr_suffix);
-       }
+       msgstr = xasprintf ("%s%s%s", msgstr_prefix, msgid, msgstr_suffix);
       else
        msgstr = "";
 
@@ -2245,13 +2238,8 @@ remember_a_message_plural (message_ty *mp, char *string,
         otherwise use the empty string.  The translator will have to
         provide additional plural forms.  */
       if (msgstr_prefix)
-       {
-         msgstr1 = (char *) xmalloc (strlen (msgstr_prefix)
-                                     + strlen (msgid_plural)
-                                     + strlen (msgstr_suffix) + 1);
-         stpcpy (stpcpy (stpcpy (msgstr1, msgstr_prefix), msgid_plural),
-                 msgstr_suffix);
-       }
+       msgstr1 =
+         xasprintf ("%s%s%s", msgstr_prefix, msgid_plural, msgstr_suffix);
       else
        msgstr1 = "";
       msgstr1_len = strlen (msgstr1) + 1;