summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxhe <xw897002528@gmail.com>2018-01-23 00:48:37 +0800
committerxhe <xw897002528@gmail.com>2018-01-23 00:48:37 +0800
commit11e4f3cde9559538e8f35f4dc4f53333b96f3512 (patch)
tree226aea46983f8f8fc3c8435d6e2a12484bf71481
parentce43a617386ef0e9ed57f7d46a537c3bae157082 (diff)
downloadgettext-tiny-11e4f3cde9559538e8f35f4dc4f53333b96f3512.tar.gz
msgmerge: escape texts before output
Texts passed to process are unescaped automatically by lib, but what we need to output is escaped texts. Or msgfmt cant work with them correctly.
-rw-r--r--src/msgmerge.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/msgmerge.c b/src/msgmerge.c
index bcd9045..d639c73 100644
--- a/src/msgmerge.c
+++ b/src/msgmerge.c
@@ -40,28 +40,33 @@ struct fiLes {
enum po_entry prev_type;
};
+char convbuf[16384];
/* currently we only output input strings as output strings
* i.e. there is no translation lookup at all */
int process_line_callback(struct po_info* info, void* user) {
+ // escape what is unescaped automatically by lib
+ memset(convbuf, 0, sizeof(convbuf));
+ escape(info->text, convbuf, sizeof(convbuf));
+
struct fiLes* file = (struct fiLes*) user;
switch (info->type) {
case pe_msgid:
file->plural_count = 1;
- fprintf(file->out, "\nmsgid \"%s\"\n", info->text);
+ fprintf(file->out, "\nmsgid \"%s\"\n", convbuf);
file->prev_type = info->type;
break;
case pe_ctxt:
- fprintf(file->out, "msgctxt \"%s\"\n", info->text);
+ fprintf(file->out, "msgctxt \"%s\"\n", convbuf);
break;
case pe_plural:
- fprintf(file->out, "msgid_plural \"%s\"\n", info->text);
+ fprintf(file->out, "msgid_plural \"%s\"\n", convbuf);
file->prev_type = info->type;
break;
case pe_msgstr:
if (file->prev_type == pe_plural) {
- fprintf(file->out, "msgstr[%d] \"%s\"\n", file->plural_count++, info->text);
+ fprintf(file->out, "msgstr[%d] \"%s\"\n", file->plural_count++, convbuf);
} else {
- fprintf(file->out, "msgstr \"%s\"\n", info->text);
+ fprintf(file->out, "msgstr \"%s\"\n", convbuf);
}
break;
}