Refactor.

* gettext-tools/src/msgl-header.h (header_set_charset): New declaration.
* gettext-tools/src/msgl-header.c (header_set_charset): New function.
* gettext-tools/src/msgl-iconv.c: Include msgl-header.h.
(iconv_message_list_internal): Use header_set_charset.
* gettext-tools/src/x-po.c: Include msgl-header.h.
(extract): Use header_set_charset.
* gettext-tools/src/FILES: Update.
This commit is contained in:
Bruno Haible 2024-10-15 15:42:46 +02:00
parent b286a63d8b
commit 3769eb40d6
5 changed files with 40 additions and 35 deletions

View File

@ -123,6 +123,10 @@ xerror-handler.c
| Reading of a .desktop file, returning a list-of-messages.
+-------------- Reading PO files
msgl-header.h
msgl-header.c
Message list header manipulation.
msgl-iconv.h
msgl-iconv.c
Convert a list-of-messages to another character encoding.
@ -150,10 +154,6 @@ msgl-charset.c
|
+-------------- The 'msgmerge' program
msgl-header.h
msgl-header.c
Message list header manipulation.
msgcomm.c Main source for the 'msgcomm' program.
msgattrib.c Main source for the 'msgattrib' program.
msgcat.c Main source for the 'msgcat' program.

View File

@ -1,5 +1,5 @@
/* Message list header manipulation.
Copyright (C) 2007, 2016-2017 Free Software Foundation, Inc.
Copyright (C) 2007-2024 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2007.
This program is free software: you can redistribute it and/or modify
@ -30,6 +30,28 @@
#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
void
header_set_charset (message_ty *header_mp, const char *charsetstr,
const char *value)
{
const char *msgstr = header_mp->msgstr;
size_t len, len1, len2, len3;
char *new_msgstr;
len = strcspn (charsetstr, " \t\n");
len1 = charsetstr - msgstr;
len2 = strlen (value);
len3 = (msgstr + strlen (msgstr)) - (charsetstr + len);
new_msgstr = XNMALLOC (len1 + len2 + len3 + 1, char);
memcpy (new_msgstr, msgstr, len1);
memcpy (new_msgstr + len1, value, len2);
memcpy (new_msgstr + len1 + len2, charsetstr + len, len3 + 1);
header_mp->msgstr = new_msgstr;
header_mp->msgstr_len = len1 + len2 + len3 + 1;
}
/* The known fields in their usual order. */
static const struct
{

View File

@ -1,5 +1,5 @@
/* Message list header manipulation.
Copyright (C) 2007, 2016 Free Software Foundation, Inc.
Copyright (C) 2007-2024 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2007.
This program is free software: you can redistribute it and/or modify
@ -26,6 +26,14 @@ extern "C" {
#endif
/* Set the 'charset' value in the 'Content-Type:' field to the given value.
HEADER_MP is a message that satisfies the is_header() predicate.
CHARSETSTR is a pointer into its msgstr, right after the "charset=" substring.
VALUE is the new charset value. */
extern void
header_set_charset (message_ty *header_mp, const char *charsetstr,
const char *value);
/* Set the given field to the given value.
The FIELD name ends in a colon.
The VALUE will have a space prepended and a newline appended by this

View File

@ -38,6 +38,7 @@
#include "string-desc.h"
#include "message.h"
#include "po-charset.h"
#include "msgl-header.h"
#include "xstriconv.h"
#include "xstriconveh.h"
#include "msgl-ascii.h"
@ -289,21 +290,7 @@ iconv_message_list_internal (message_list_ty *mlp,
freea (charset);
if (update_header)
{
size_t len1, len2, len3;
char *new_header;
len1 = charsetstr - header;
len2 = strlen (canon_to_code);
len3 = (header + strlen (header)) - (charsetstr + len);
new_header = XNMALLOC (len1 + len2 + len3 + 1, char);
memcpy (new_header, header, len1);
memcpy (new_header + len1, canon_to_code, len2);
memcpy (new_header + len1 + len2, charsetstr + len,
len3 + 1);
mlp->item[j]->msgstr = new_header;
mlp->item[j]->msgstr_len = len1 + len2 + len3 + 1;
}
header_set_charset (mlp->item[j], charsetstr, canon_to_code);
}
}
}

View File

@ -39,6 +39,7 @@
#include "read-po.h"
#include "read-properties.h"
#include "read-stringtable.h"
#include "msgl-header.h"
#include "msgl-iconv.h"
#include "msgl-ascii.h"
#include "po-charset.h"
@ -188,21 +189,8 @@ extract (FILE *fp,
if (charsetstr != NULL)
{
size_t len, len1, len2, len3;
char *new_header;
charsetstr += strlen ("charset=");
len = strcspn (charsetstr, " \t\n");
len1 = charsetstr - header;
len2 = strlen (header_charset);
len3 = (header + strlen (header)) - (charsetstr + len);
new_header = XNMALLOC (len1 + len2 + len3 + 1, char);
memcpy (new_header, header, len1);
memcpy (new_header + len1, header_charset, len2);
memcpy (new_header + len1 + len2, charsetstr + len, len3 + 1);
mp->msgstr = new_header;
mp->msgstr_len = len1 + len2 + len3 + 1;
header_set_charset (mp, charsetstr, header_charset);
}
}
}