88 else if (curr !=
next) {
95 if (ret_str[0] ==
'"' && ret_str[curr - 1] ==
'"') {
96 return ret_str.
substr(1, curr - 2);
98 return ret_str.
substr(0, curr);
104 for (i = 0; i <
sizeof(value); i++) {
105 bytes[i] = char((value >> (
int(i) * 8)) & 0xff);
113 memcpy(bytes, msg.c_str(), size);
129 Item(
const MapItem &other) : key(other.key), value(other.value) {}
130 Item(
const Item &other) : key(other.key), value(other.value) {}
133 this->key = other.key;
134 this->value = other.value;
142 for (
const auto message_items_iter : messages.
items()) {
143 items.
append(Item(message_items_iter));
145 std::sort(items.
begin(), items.
end(), [](
const Item &a,
const Item &
b) ->
bool {
146 return a.key < b.key;
149 Offset *offsets = MEM_cnew_array<Offset>(num_keys, __func__);
153 for (
int i = 0; i < num_keys; i++) {
160 tot_keys_len += off.
key_len + 1;
164 tot_vals_len += off.
val_len + 1;
169 const uint32_t idx_keystart = 7 * 4;
170 const uint32_t idx_valstart = idx_keystart + 8 * num_keys;
172 const uint32_t keystart = idx_valstart + 8 * num_keys;
174 const uint32_t valstart = keystart + tot_keys_len;
177 *r_output_size = valstart + tot_vals_len;
178 char *output = MEM_cnew_array<char>(*r_output_size, __func__);
180 char *ik = output + idx_keystart;
181 char *iv = output + idx_valstart;
182 char *k = output + keystart;
183 char *
v = output + valstart;
195 for (
int i = 0; i < num_keys; i++) {
196 const Offset &off = offsets[i];
231 if (msg.
ctxt.empty()) {
232 msgkey = std::move(msg.
id);
236 msgkey = msg.
ctxt +
"\x04" + msg.
id;
239 messages.
add(std::move(msgkey), std::move(msg.
str));
244static int make(
const char *input_file_name,
const char *output_file_name)
248 const char *msgctxt_kw =
"msgctxt";
249 const char *msgid_kw =
"msgid";
250 const char *msgid_plural_kw =
"msgid_plural";
251 const char *msgstr_kw =
"msgstr";
252 const size_t msgctxt_len = strlen(msgctxt_kw);
253 const size_t msgid_len = strlen(msgid_kw);
254 const size_t msgid_plural_len = strlen(msgid_plural_kw);
255 const size_t msgstr_len = strlen(msgstr_kw);
260 bool is_plural =
false;
268 for (
int lno = 1; ifl; ifl = ifl->
next, lno++) {
269 std::string line =
static_cast<char *
>(ifl->
link);
274 const bool is_comment = (
l[0] ==
'#');
288 if (
l.startswith(msgctxt_kw)) {
294 printf(
"msgctxt not at start of new message on %s:%d\n", input_file_name, lno);
298 l =
l.substr(msgctxt_len);
301 else if (
l.startswith(msgid_plural_kw)) {
304 printf(
"msgid_plural not preceded by msgid on %s:%d\n", input_file_name, lno);
307 l =
l.substr(msgid_plural_len);
311 else if (
l.startswith(msgid_kw)) {
319 l =
l.substr(msgid_len);
322 else if (
l.startswith(msgstr_kw)) {
323 l =
l.substr(msgstr_len);
328 printf(
"plural without msgid_plural on %s:%d\n", input_file_name, lno);
331 int64_t close_bracket_idx =
l.find(
']');
333 printf(
"Syntax error on %s:%d\n", input_file_name, lno);
336 l =
l.substr(close_bracket_idx + 1);
337 if (!msg.str.empty()) {
343 printf(
"indexed msgstr required for plural on %s:%d\n", input_file_name, lno);
369 printf(
"Syntax error on %s:%d\n", input_file_name, lno);
382 char *output =
generate(messages, &output_size);
384 FILE *fp =
BLI_fopen(output_file_name,
"wb");
385 fwrite(output, 1, output_size, fp);
396 printf(
"Usage: %s <input.po> <output.mo>\n", argv[0]);
399 const char *input_file = argv[1];
400 const char *output_file = argv[2];
402 return make(input_file, output_file);
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
struct LinkNode * BLI_file_read_as_lines(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_file_free_lines(struct LinkNode *lines)
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
bool add(const Key &key, const Value &value)
ItemIterator items() const
static constexpr int64_t not_found
constexpr StringRef substr(int64_t start, int64_t size) const
void append(const T &value)
local_group_size(16, 16) .push_constant(Type b
void MEM_freeN(void *vmemh)
BLI_INLINE size_t uint32_to_bytes(const int value, char *bytes)
static void clear(Message &msg)
static int make(const char *input_file_name, const char *output_file_name)
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
static char * generate(blender::Map< std::string, std::string > &messages, size_t *r_output_size)
static blender::StringRef unescape(std::string &str)
BLI_INLINE size_t msg_to_bytes(const std::string &msg, char *bytes, uint32_t size)