1
1
/* Reading Java .properties files.
2
Copyright (C) 2003, 2005-2007 Free Software Foundation, Inc.
2
Copyright (C) 2003, 2005-2007, 2009 Free Software Foundation, Inc.
3
3
Written by Bruno Haible <bruno@clisp.org>, 2003.
5
5
This program is free software: you can redistribute it and/or modify
86
const char *errno_description = strerror (errno);
87
po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
89
xasprintf (_("error while reading \"%s\""),
86
const char *errno_description = strerror (errno);
87
po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
89
xasprintf (_("error while reading \"%s\""),
197
197
int c2 = phase3_getc ();
212
for (i = 0; i < 4; i++)
214
int c1 = phase3_getc ();
216
if (c1 >= '0' && c1 <= '9')
217
n = (n << 4) + (c1 - '0');
218
else if (c1 >= 'A' && c1 <= 'F')
219
n = (n << 4) + (c1 - 'A' + 10);
220
else if (c1 >= 'a' && c1 <= 'f')
221
n = (n << 4) + (c1 - 'a' + 10);
225
po_xerror (PO_SEVERITY_ERROR, NULL,
226
real_file_name, gram_pos.line_number, (size_t)(-1),
227
false, _("warning: invalid \\uxxxx syntax for Unicode character"));
212
for (i = 0; i < 4; i++)
214
int c1 = phase3_getc ();
216
if (c1 >= '0' && c1 <= '9')
217
n = (n << 4) + (c1 - '0');
218
else if (c1 >= 'A' && c1 <= 'F')
219
n = (n << 4) + (c1 - 'A' + 10);
220
else if (c1 >= 'a' && c1 <= 'f')
221
n = (n << 4) + (c1 - 'a' + 10);
225
po_xerror (PO_SEVERITY_ERROR, NULL,
226
real_file_name, gram_pos.line_number, (size_t)(-1),
227
false, _("warning: invalid \\uxxxx syntax for Unicode character"));
254
254
const char *str_limit = str + length;
256
256
while (str < str_limit)
258
unsigned int uc = (unsigned char) *str++;
259
int n = u8_uctomb (q, uc, 6);
258
unsigned int uc = (unsigned char) *str++;
259
int n = u8_uctomb (q, uc, 6);
264
264
assert (q - utf8_string <= 2 * length);
281
281
while (*p != '\0')
283
283
if (p[0] == '\\' && p[1] == 'u')
288
for (i = 0; i < 4; i++)
290
int c1 = (unsigned char) p[2 + i];
292
if (c1 >= '0' && c1 <= '9')
293
n = (n << 4) + (c1 - '0');
294
else if (c1 >= 'A' && c1 <= 'F')
295
n = (n << 4) + (c1 - 'A' + 10);
296
else if (c1 >= 'a' && c1 <= 'f')
297
n = (n << 4) + (c1 - 'a' + 10);
306
if (n >= 0xd800 && n < 0xdc00)
308
if (p[6] == '\\' && p[7] == 'u')
312
for (i = 0; i < 4; i++)
314
int c1 = (unsigned char) p[8 + i];
316
if (c1 >= '0' && c1 <= '9')
317
m = (m << 4) + (c1 - '0');
318
else if (c1 >= 'A' && c1 <= 'F')
319
m = (m << 4) + (c1 - 'A' + 10);
320
else if (c1 >= 'a' && c1 <= 'f')
321
m = (m << 4) + (c1 - 'a' + 10);
326
if (i == 4 && (m >= 0xdc00 && m < 0xe000))
328
/* Combine two UTF-16 words to a character. */
329
uc = 0x10000 + ((n - 0xd800) << 10) + (m - 0xdc00);
344
q += u8_uctomb (q, uc, 6);
288
for (i = 0; i < 4; i++)
290
int c1 = (unsigned char) p[2 + i];
292
if (c1 >= '0' && c1 <= '9')
293
n = (n << 4) + (c1 - '0');
294
else if (c1 >= 'A' && c1 <= 'F')
295
n = (n << 4) + (c1 - 'A' + 10);
296
else if (c1 >= 'a' && c1 <= 'f')
297
n = (n << 4) + (c1 - 'a' + 10);
306
if (n >= 0xd800 && n < 0xdc00)
308
if (p[6] == '\\' && p[7] == 'u')
312
for (i = 0; i < 4; i++)
314
int c1 = (unsigned char) p[8 + i];
316
if (c1 >= '0' && c1 <= '9')
317
m = (m << 4) + (c1 - '0');
318
else if (c1 >= 'A' && c1 <= 'F')
319
m = (m << 4) + (c1 - 'A' + 10);
320
else if (c1 >= 'a' && c1 <= 'f')
321
m = (m << 4) + (c1 - 'a' + 10);
326
if (i == 4 && (m >= 0xdc00 && m < 0xe000))
328
/* Combine two UTF-16 words to a character. */
329
uc = 0x10000 + ((n - 0xd800) << 10) + (m - 0xdc00);
344
q += u8_uctomb (q, uc, 6);
349
*q++ = (unsigned char) *p++;
349
*q++ = (unsigned char) *p++;
389
389
if (in_key && (c == '=' || c == ':'
390
|| c == ' ' || c == '\t' || c == '\r' || c == '\f'))
392
/* Skip whitespace after the string. */
393
while (c == ' ' || c == '\t' || c == '\r' || c == '\f')
395
/* Skip '=' or ':' separator. */
396
if (!(c == '=' || c == ':'))
390
|| c == ' ' || c == '\t' || c == '\r' || c == '\f'))
392
/* Skip whitespace after the string. */
393
while (c == ' ' || c == '\t' || c == '\r' || c == '\f')
395
/* Skip '=' or ':' separator. */
396
if (!(c == '=' || c == ':'))
401
401
phase3_ungetc (c);
403
403
/* Read the next UTF-16 codepoint. */
404
404
c = phase4_getuc ();
407
407
/* Append it to the buffer. */
408
408
if (buflen >= bufmax)
411
buffer = xrealloc (buffer, bufmax * sizeof (unsigned short));
411
buffer = xrealloc (buffer, bufmax * sizeof (unsigned short));
413
413
buffer[buflen++] = c;
415
415
c = phase3_getc ();
416
416
if (c == EOF || c == '\n')
424
424
/* Now convert from UTF-16 to UTF-8. */
431
431
utf8_string = XNMALLOC (3 * buflen + 1, unsigned char);
432
432
for (pos = 0, q = utf8_string; pos < buflen; )
437
pos += u16_mbtouc (&uc, buffer + pos, buflen - pos);
438
n = u8_uctomb (q, uc, 6);
437
pos += u16_mbtouc (&uc, buffer + pos, buflen - pos);
438
n = u8_uctomb (q, uc, 6);
443
443
assert (q - utf8_string <= 3 * buflen);
451
451
abstract_catalog_reader_class_ty methods. */
453
453
properties_parse (abstract_catalog_reader_ty *this, FILE *file,
454
const char *real_filename, const char *logical_filename)
454
const char *real_filename, const char *logical_filename)
457
457
real_file_name = real_filename;
467
467
c = phase2_getc ();
476
476
else if (c == '!')
478
/* For compatibility with write-properties.c, we treat '!' not
479
followed by space as a fuzzy or untranslated message. */
480
int c2 = phase2_getc ();
481
if (c2 == ' ' || c2 == '\n' || c2 == EOF)
478
/* For compatibility with write-properties.c, we treat '!' not
479
followed by space as a fuzzy or untranslated message. */
480
int c2 = phase2_getc ();
481
if (c2 == ' ' || c2 == '\n' || c2 == EOF)
492
/* A comment line. */
494
static size_t bufmax;
495
static size_t buflen;
502
if (buflen >= bufmax)
505
buffer = xrealloc (buffer, bufmax);
508
if (c == EOF || c == '\n')
511
buffer[buflen++] = c;
513
buffer[buflen] = '\0';
515
po_callback_comment_dispatcher (conv_from_java (conv_from_iso_8859_1 (buffer)));
492
/* A comment line. */
494
static size_t bufmax;
495
static size_t buflen;
502
if (buflen >= bufmax)
505
buffer = xrealloc (buffer, bufmax);
508
if (c == EOF || c == '\n')
511
buffer[buflen++] = c;
513
buffer[buflen] = '\0';
515
po_callback_comment_dispatcher (conv_from_java (conv_from_iso_8859_1 (buffer)));
519
/* A key/value pair. */
521
lex_pos_ty msgid_pos;
523
msgid_pos = gram_pos;
524
msgid = read_escaped_string (true);
526
/* Skip blank line. */
531
lex_pos_ty msgstr_pos;
534
msgstr_pos = gram_pos;
535
msgstr = read_escaped_string (false);
537
msgstr = xstrdup ("");
539
/* Be sure to make the message fuzzy if it was commented out
540
and if it is not already header/fuzzy/untranslated. */
541
force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0');
543
po_callback_message (NULL, msgid, &msgid_pos, NULL,
544
msgstr, strlen (msgstr) + 1, &msgstr_pos,
519
/* A key/value pair. */
521
lex_pos_ty msgid_pos;
523
msgid_pos = gram_pos;
524
msgid = read_escaped_string (true);
526
/* Skip blank line. */
531
lex_pos_ty msgstr_pos;
534
msgstr_pos = gram_pos;
535
msgstr = read_escaped_string (false);
537
msgstr = xstrdup ("");
539
/* Be sure to make the message fuzzy if it was commented out
540
and if it is not already header/fuzzy/untranslated. */
541
force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0');
543
po_callback_message (NULL, msgid, &msgid_pos, NULL,
544
msgstr, strlen (msgstr) + 1, &msgstr_pos,