From: Bruno Haible Date: Wed, 3 May 2006 12:13:13 +0000 (+0000) Subject: Code simplification: use xasprintf. X-Git-Tag: v0.15~196 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=019d270c02816ce99e75545dab55c53291a670b3;p=thirdparty%2Fgettext.git Code simplification: use xasprintf. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 8db1b543e..617d21ccb 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,14 @@ +2006-04-30 Bruno Haible + + * 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 * msgfmt.c: Include xvasprintf.h. diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index 97b15e344..a73251976 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -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) diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c index 29ad6504b..b4d8f3fb6 100644 --- a/gettext-tools/src/write-java.c +++ b/gettext-tools/src/write-java.c @@ -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); } diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index 4e1631209..cacc7739c 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -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 "". */ - 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); diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index f03166aeb..54ebce54f 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -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;