summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxhe <xw897002528@gmail.com>2018-01-23 12:48:59 +0800
committerxhe <xw897002528@gmail.com>2018-01-23 12:48:59 +0800
commite22565a69ec395f4b3e531e207b0f0b80d5cacd6 (patch)
treec0f3c7971c6e435cfb4dd7908eeea36a9494af59
parent11e4f3cde9559538e8f35f4dc4f53333b96f3512 (diff)
downloadgettext-tiny-e22565a69ec395f4b3e531e207b0f0b80d5cacd6.tar.gz
msgmerge: a better solution to escape texts
https://github.com/sabotage-linux/gettext-tiny/commit/11e4f3cde9559538e8f35f4dc4f53333b96f3512. As rofl0r said, a global buffer is a bit ugly. I moved it to the struct fiLes. And i missed out that escape() dont need a clean, zero filled buffer at all.
-rw-r--r--src/msgmerge.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/msgmerge.c b/src/msgmerge.c
index d639c73..2a5e041 100644
--- a/src/msgmerge.c
+++ b/src/msgmerge.c
@@ -37,36 +37,35 @@ struct fiLes {
FILE *pot;
FILE *compend;
int plural_count;
+ char convbuf[16384];
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;
+
+ // escape what is unescaped automatically by lib
+ escape(info->text, file->convbuf, sizeof(file->convbuf));
switch (info->type) {
case pe_msgid:
file->plural_count = 1;
- fprintf(file->out, "\nmsgid \"%s\"\n", convbuf);
+ fprintf(file->out, "\nmsgid \"%s\"\n", file->convbuf);
file->prev_type = info->type;
break;
case pe_ctxt:
- fprintf(file->out, "msgctxt \"%s\"\n", convbuf);
+ fprintf(file->out, "msgctxt \"%s\"\n", file->convbuf);
break;
case pe_plural:
- fprintf(file->out, "msgid_plural \"%s\"\n", convbuf);
+ fprintf(file->out, "msgid_plural \"%s\"\n", file->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++, convbuf);
+ fprintf(file->out, "msgstr[%d] \"%s\"\n", file->plural_count++, file->convbuf);
} else {
- fprintf(file->out, "msgstr \"%s\"\n", convbuf);
+ fprintf(file->out, "msgstr \"%s\"\n", file->convbuf);
}
break;
}