1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543
|
/* GNU gettext - internationalization aids
Copyright (C) 1995-1998, 2000-2009 Free Software Foundation, Inc.
This file was written by Peter Miller <millerp@canb.auug.org.au>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <alloca.h>
/* Specification. */
#include "write-po.h"
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_ICONV
# include <iconv.h>
#endif
#include "c-ctype.h"
#include "po-charset.h"
#include "format.h"
#include "unilbrk.h"
#include "msgl-ascii.h"
#include "write-catalog.h"
#include "xalloc.h"
#include "xmalloca.h"
#include "c-strstr.h"
#include "ostream.h"
#ifdef GETTEXTDATADIR
# include "styled-ostream.h"
#endif
#include "xvasprintf.h"
#include "po-xerror.h"
#include "gettext.h"
/* Our regular abbreviation. */
#define _(str) gettext (str)
#if HAVE_DECL_PUTC_UNLOCKED
# undef putc
# define putc putc_unlocked
#endif
/* =================== Putting together a #, flags line. =================== */
/* Convert IS_FORMAT in the context of programming language LANG to a flag
string for use in #, flags. */
const char *
make_format_description_string (enum is_format is_format, const char *lang,
bool debug)
{
static char result[100];
switch (is_format)
{
case possible:
if (debug)
{
sprintf (result, "possible-%s-format", lang);
break;
}
/* FALLTHROUGH */
case yes_according_to_context:
case yes:
sprintf (result, "%s-format", lang);
break;
case no:
sprintf (result, "no-%s-format", lang);
break;
default:
/* The others have already been filtered out by significant_format_p. */
abort ();
}
return result;
}
/* Return true if IS_FORMAT is worth mentioning in a #, flags list. */
bool
significant_format_p (enum is_format is_format)
{
return is_format != undecided && is_format != impossible;
}
/* Return true if one of IS_FORMAT is worth mentioning in a #, flags list. */
static bool
has_significant_format_p (const enum is_format is_format[NFORMATS])
{
size_t i;
for (i = 0; i < NFORMATS; i++)
if (significant_format_p (is_format[i]))
return true;
return false;
}
/* Convert a RANGE to a freshly allocated string for use in #, flags. */
char *
make_range_description_string (struct argument_range range)
{
return xasprintf ("range: %d..%d", range.min, range.max);
}
/* Convert a wrapping flag DO_WRAP to a string for use in #, flags. */
static const char *
make_c_width_description_string (enum is_wrap do_wrap)
{
const char *result = NULL;
switch (do_wrap)
{
case yes:
result = "wrap";
break;
case no:
result = "no-wrap";
break;
default:
abort ();
}
return result;
}
/* ========================== Styling primitives. ========================== */
/* When compiled in src, enable styling support.
When compiled in libgettextpo, don't enable styling support. */
#ifdef GETTEXTDATADIR
/* Return true if the stream is an instance of styled_ostream_t. */
static inline bool
is_stylable (ostream_t stream)
{
return IS_INSTANCE (stream, ostream, styled_ostream);
}
/* Start a run of text belonging to a given CSS class. */
static void
begin_css_class (ostream_t stream, const char *classname)
{
if (is_stylable (stream))
styled_ostream_begin_use_class ((styled_ostream_t) stream, classname);
}
/* End a run of text belonging to a given CSS class. */
static void
end_css_class (ostream_t stream, const char *classname)
{
if (is_stylable (stream))
styled_ostream_end_use_class ((styled_ostream_t) stream, classname);
}
#else
#define is_stylable(stream) false
#define begin_css_class(stream,classname) /* empty */
#define end_css_class(stream,classname) /* empty */
#endif
/* CSS classes at message level. */
static const char class_header[] = "header";
static const char class_translated[] = "translated";
static const char class_untranslated[] = "untranslated";
static const char class_fuzzy[] = "fuzzy";
static const char class_obsolete[] = "obsolete";
/* CSS classes describing the parts of a message. */
static const char class_comment[] = "comment";
static const char class_translator_comment[] = "translator-comment";
static const char class_extracted_comment[] = "extracted-comment";
static const char class_reference_comment[] = "reference-comment";
static const char class_reference[] = "reference";
static const char class_flag_comment[] = "flag-comment";
static const char class_flag[] = "flag";
static const char class_fuzzy_flag[] = "fuzzy-flag";
static const char class_previous_comment[] = "previous-comment";
static const char class_previous[] = "previous";
static const char class_msgid[] = "msgid";
static const char class_msgstr[] = "msgstr";
static const char class_keyword[] = "keyword";
static const char class_string[] = "string";
/* CSS classes for the contents of strings. */
static const char class_text[] = "text";
static const char class_escape_sequence[] = "escape-sequence";
static const char class_format_directive[] = "format-directive";
static const char class_invalid_format_directive[] = "invalid-format-directive";
#if 0
static const char class_added[] = "added";
static const char class_changed[] = "changed";
static const char class_removed[] = "removed";
#endif
/* Per-character attributes. */
enum
{
ATTR_ESCAPE_SEQUENCE = 1 << 0,
/* The following two are exclusive. */
ATTR_FORMAT_DIRECTIVE = 1 << 1,
ATTR_INVALID_FORMAT_DIRECTIVE = 1 << 2
};
/* ================ Output parts of a message, as comments. ================ */
/* Output mp->comment as a set of comment lines. */
void
message_print_comment (const message_ty *mp, ostream_t stream)
{
if (mp->comment != NULL)
{
size_t j;
begin_css_class (stream, class_translator_comment);
for (j = 0; j < mp->comment->nitems; ++j)
{
const char *s = mp->comment->item[j];
do
{
const char *e;
ostream_write_str (stream, "#");
if (*s != '\0')
ostream_write_str (stream, " ");
e = strchr (s, '\n');
if (e == NULL)
{
ostream_write_str (stream, s);
s = NULL;
}
else
{
ostream_write_mem (stream, s, e - s);
s = e + 1;
}
ostream_write_str (stream, "\n");
}
while (s != NULL);
}
end_css_class (stream, class_translator_comment);
}
}
/* Output mp->comment_dot as a set of comment lines. */
void
message_print_comment_dot (const message_ty *mp, ostream_t stream)
{
if (mp->comment_dot != NULL)
{
size_t j;
begin_css_class (stream, class_extracted_comment);
for (j = 0; j < mp->comment_dot->nitems; ++j)
{
const char *s = mp->comment_dot->item[j];
ostream_write_str (stream, "#.");
if (*s != '\0')
ostream_write_str (stream, " ");
ostream_write_str (stream, s);
ostream_write_str (stream, "\n");
}
end_css_class (stream, class_extracted_comment);
}
}
/* Output mp->filepos as a set of comment lines. */
void
message_print_comment_filepos (const message_ty *mp, ostream_t stream,
bool uniforum, size_t page_width)
{
if (mp->filepos_count != 0)
{
begin_css_class (stream, class_reference_comment);
if (uniforum)
{
size_t j;
for (j = 0; j < mp->filepos_count; ++j)
{
lex_pos_ty *pp = &mp->filepos[j];
const char *cp = pp->file_name;
char *str;
while (cp[0] == '.' && cp[1] == '/')
cp += 2;
ostream_write_str (stream, "# ");
begin_css_class (stream, class_reference);
/* There are two Sun formats to choose from: SunOS and
Solaris. Use the Solaris form here. */
str = xasprintf ("File: %s, line: %ld",
cp, (long) pp->line_number);
ostream_write_str (stream, str);
end_css_class (stream, class_reference);
ostream_write_str (stream, "\n");
free (str);
}
}
else
{
size_t column;
size_t j;
ostream_write_str (stream, "#:");
column = 2;
for (j = 0; j < mp->filepos_count; ++j)
{
lex_pos_ty *pp;
char buffer[21];
const char *cp;
size_t len;
pp = &mp->filepos[j];
cp = pp->file_name;
while (cp[0] == '.' && cp[1] == '/')
cp += 2;
/* Some xgettext input formats, like RST, lack line numbers. */
if (pp->line_number == (size_t)(-1))
buffer[0] = '\0';
else
sprintf (buffer, ":%ld", (long) pp->line_number);
len = strlen (cp) + strlen (buffer) + 1;
if (column > 2 && column + len >= page_width)
{
ostream_write_str (stream, "\n#:");
column = 2;
}
ostream_write_str (stream, " ");
begin_css_class (stream, class_reference);
ostream_write_str (stream, cp);
ostream_write_str (stream, buffer);
end_css_class (stream, class_reference);
column += len;
}
ostream_write_str (stream, "\n");
}
end_css_class (stream, class_reference_comment);
}
}
/* Output mp->is_fuzzy, mp->is_format, mp->range, mp->do_wrap as a comment
line. */
void
message_print_comment_flags (const message_ty *mp, ostream_t stream, bool debug)
{
if ((mp->is_fuzzy && mp->msgstr[0] != '\0')
|| has_significant_format_p (mp->is_format)
|| has_range_p (mp->range)
|| mp->do_wrap == no)
{
bool first_flag = true;
size_t i;
begin_css_class (stream, class_flag_comment);
ostream_write_str (stream, "#,");
/* We don't print the fuzzy flag if the msgstr is empty. This
might be introduced by the user but we want to normalize the
output. */
if (mp->is_fuzzy && mp->msgstr[0] != '\0')
{
ostream_write_str (stream, " ");
begin_css_class (stream, class_flag);
begin_css_class (stream, class_fuzzy_flag);
ostream_write_str (stream, "fuzzy");
end_css_class (stream, class_fuzzy_flag);
end_css_class (stream, class_flag);
first_flag = false;
}
for (i = 0; i < NFORMATS; i++)
if (significant_format_p (mp->is_format[i]))
{
if (!first_flag)
ostream_write_str (stream, ",");
ostream_write_str (stream, " ");
begin_css_class (stream, class_flag);
ostream_write_str (stream,
make_format_description_string (mp->is_format[i],
format_language[i],
debug));
end_css_class (stream, class_flag);
first_flag = false;
}
if (has_range_p (mp->range))
{
char *string;
if (!first_flag)
ostream_write_str (stream, ",");
ostream_write_str (stream, " ");
begin_css_class (stream, class_flag);
string = make_range_description_string (mp->range);
ostream_write_str (stream, string);
free (string);
end_css_class (stream, class_flag);
first_flag = false;
}
if (mp->do_wrap == no)
{
if (!first_flag)
ostream_write_str (stream, ",");
ostream_write_str (stream, " ");
begin_css_class (stream, class_flag);
ostream_write_str (stream,
make_c_width_description_string (mp->do_wrap));
end_css_class (stream, class_flag);
first_flag = false;
}
ostream_write_str (stream, "\n");
end_css_class (stream, class_flag_comment);
}
}
/* ========= Some parameters for use by 'msgdomain_list_print_po'. ========= */
/* This variable controls the extent to which the page width applies.
True means it applies to message strings and file reference lines.
False means it applies to file reference lines only. */
static bool wrap_strings = true;
void
message_page_width_ignore ()
{
wrap_strings = false;
}
/* These three variables control the output style of the message_print
function. Interface functions for them are to be used. */
static bool indent = false;
static bool uniforum = false;
static bool escape = false;
void
message_print_style_indent ()
{
indent = true;
}
void
message_print_style_uniforum ()
{
uniforum = true;
}
void
message_print_style_escape (bool flag)
{
escape = flag;
}
/* =============== msgdomain_list_print_po() and subroutines. =============== */
/* A version of memcpy optimized for the case n <= 1. */
static inline void
memcpy_small (void *dst, const void *src, size_t n)
{
if (n > 0)
{
char *q = (char *) dst;
const char *p = (const char *) src;
*q = *p;
if (--n > 0)
do *++q = *++p; while (--n > 0);
}
}
/* A version of memset optimized for the case n <= 1. */
static inline void
memset_small (void *dst, char c, size_t n)
{
if (n > 0)
{
char *p = (char *) dst;
*p = c;
if (--n > 0)
do *++p = c; while (--n > 0);
}
}
static void
wrap (const message_ty *mp, ostream_t stream,
const char *line_prefix, int extra_indent, const char *css_class,
const char *name, const char *value,
enum is_wrap do_wrap, size_t page_width,
const char *charset)
{
const char *canon_charset;
char *fmtdir;
char *fmtdirattr;
const char *s;
bool first_line;
#if HAVE_ICONV
const char *envval;
iconv_t conv;
#endif
bool weird_cjk;
canon_charset = po_charset_canonicalize (charset);
#if HAVE_ICONV
/* The old Solaris/openwin msgfmt and GNU msgfmt <= 0.10.35 don't know
about multibyte encodings, and require a spurious backslash after
every multibyte character whose last byte is 0x5C. Some programs,
like vim, distribute PO files in this broken format. It is important
for such programs that GNU msgmerge continues to support this old
PO file format when the Makefile requests it. */
envval = getenv ("OLD_PO_FILE_OUTPUT");
if (envval != NULL && *envval != '\0')
/* Write a PO file in old format, with extraneous backslashes. */
conv = (iconv_t)(-1);
else
if (canon_charset == NULL)
/* Invalid PO file encoding. */
conv = (iconv_t)(-1);
else
/* Avoid glibc-2.1 bug with EUC-KR. */
# if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION
if (strcmp (canon_charset, "EUC-KR") == 0)
conv = (iconv_t)(-1);
else
# endif
/* Avoid Solaris 2.9 bug with GB2312, EUC-TW, BIG5, BIG5-HKSCS, GBK,
GB18030. */
# if defined __sun && !defined _LIBICONV_VERSION
if ( strcmp (canon_charset, "GB2312") == 0
|| strcmp (canon_charset, "EUC-TW") == 0
|| strcmp (canon_charset, "BIG5") == 0
|| strcmp (canon_charset, "BIG5-HKSCS") == 0
|| strcmp (canon_charset, "GBK") == 0
|| strcmp (canon_charset, "GB18030") == 0)
conv = (iconv_t)(-1);
else
# endif
/* Use iconv() to parse multibyte characters. */
conv = iconv_open ("UTF-8", canon_charset);
if (conv != (iconv_t)(-1))
weird_cjk = false;
else
#endif
if (canon_charset == NULL)
weird_cjk = false;
else
weird_cjk = po_is_charset_weird_cjk (canon_charset);
if (canon_charset == NULL)
canon_charset = po_charset_ascii;
/* Determine the extent of format string directives. */
fmtdir = NULL;
fmtdirattr = NULL;
if (value[0] != '\0')
{
bool is_msgstr =
(strlen (name) >= 6 && memcmp (name, "msgstr", 6) == 0);
/* or equivalent: = (css_class == class_msgstr) */
size_t i;
for (i = 0; i < NFORMATS; i++)
if (possible_format_p (mp->is_format[i]))
{
size_t len = strlen (value);
struct formatstring_parser *parser = formatstring_parsers[i];
char *invalid_reason = NULL;
void *descr;
const char *fdp;
const char *fd_end;
char *fdap;
fmtdir = XCALLOC (len, char);
descr = parser->parse (value, is_msgstr, fmtdir, &invalid_reason);
if (descr != NULL)
parser->free (descr);
/* Locate the FMTDIR_* bits and transform the array to an array
of attributes. */
fmtdirattr = XCALLOC (len, char);
fd_end = fmtdir + len;
for (fdp = fmtdir, fdap = fmtdirattr; fdp < fd_end; fdp++, fdap++)
if (*fdp & FMTDIR_START)
{
const char *fdq;
for (fdq = fdp; fdq < fd_end; fdq++)
if (*fdq & (FMTDIR_END | FMTDIR_ERROR))
break;
if (!(fdq < fd_end))
/* The ->parse method has determined the start of a
formatstring directive but not stored a bit indicating
its end. It is a bug in the ->parse method. */
abort ();
if (*fdq & FMTDIR_ERROR)
memset (fdap, ATTR_INVALID_FORMAT_DIRECTIVE, fdq - fdp + 1);
else
memset (fdap, ATTR_FORMAT_DIRECTIVE, fdq - fdp + 1);
fdap += fdq - fdp;
fdp = fdq;
}
else
*fdap = 0;
break;
}
}
/* Loop over the '\n' delimited portions of value. */
s = value;
first_line = true;
do
{
/* The usual escapes, as defined by the ANSI C Standard. */
# define is_escape(c) \
((c) == '\a' || (c) == '\b' || (c) == '\f' || (c) == '\n' \
|| (c) == '\r' || (c) == '\t' || (c) == '\v')
const char *es;
const char *ep;
size_t portion_len;
char *portion;
char *overrides;
char *attributes;
char *linebreaks;
char *pp;
char *op;
char *ap;
int startcol, startcol_after_break, width;
size_t i;
for (es = s; *es != '\0'; )
if (*es++ == '\n')
break;
/* Expand escape sequences in each portion. */
for (ep = s, portion_len = 0; ep < es; ep++)
{
char c = *ep;
if (is_escape (c))
portion_len += 2;
else if (escape && !c_isprint ((unsigned char) c))
portion_len += 4;
else if (c == '\\' || c == '"')
portion_len += 2;
else
{
#if HAVE_ICONV
if (conv != (iconv_t)(-1))
{
/* Skip over a complete multi-byte character. Don't
interpret the second byte of a multi-byte character as
ASCII. This is needed for the BIG5, BIG5-HKSCS, GBK,
GB18030, SHIFT_JIS, JOHAB encodings. */
char scratchbuf[64];
const char *inptr = ep;
size_t insize;
char *outptr = &scratchbuf[0];
size_t outsize = sizeof (scratchbuf);
size_t res;
res = (size_t)(-1);
for (insize = 1; inptr + insize <= es; insize++)
{
res = iconv (conv,
(ICONV_CONST char **) &inptr, &insize,
&outptr, &outsize);
if (!(res == (size_t)(-1) && errno == EINVAL))
break;
/* We expect that no input bytes have been consumed
so far. */
if (inptr != ep)
abort ();
}
if (res == (size_t)(-1))
{
if (errno == EILSEQ)
{
po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false,
_("invalid multibyte sequence"));
continue;
}
else
abort ();
}
insize = inptr - ep;
portion_len += insize;
ep += insize - 1;
}
else
#endif
{
if (weird_cjk
/* Special handling of encodings with CJK structure. */
&& ep + 2 <= es
&& (unsigned char) ep[0] >= 0x80
&& (unsigned char) ep[1] >= 0x30)
{
portion_len += 2;
ep += 1;
}
else
portion_len += 1;
}
}
}
portion = XNMALLOC (portion_len, char);
overrides = XNMALLOC (portion_len, char);
attributes = XNMALLOC (portion_len, char);
for (ep = s, pp = portion, op = overrides, ap = attributes; ep < es; ep++)
{
char c = *ep;
char attr = (fmtdirattr != NULL ? fmtdirattr[ep - value] : 0);
char brk = UC_BREAK_UNDEFINED;
/* Don't break inside format directives. */
if (attr == ATTR_FORMAT_DIRECTIVE
&& (fmtdir[ep - value] & FMTDIR_START) == 0)
brk = UC_BREAK_PROHIBITED;
if (is_escape (c))
{
switch (c)
{
case '\a': c = 'a'; break;
case '\b': c = 'b'; break;
case '\f': c = 'f'; break;
case '\n': c = 'n'; break;
case '\r': c = 'r'; break;
case '\t': c = 't'; break;
case '\v': c = 'v'; break;
default: abort ();
}
*pp++ = '\\';
*pp++ = c;
*op++ = brk;
*op++ = UC_BREAK_PROHIBITED;
*ap++ = attr | ATTR_ESCAPE_SEQUENCE;
*ap++ = attr | ATTR_ESCAPE_SEQUENCE;
/* We warn about any use of escape sequences beside
'\n' and '\t'. */
if (c != 'n' && c != 't')
{
char *error_message =
xasprintf (_("\
internationalized messages should not contain the `\\%c' escape sequence"),
c);
po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, false,
error_message);
free (error_message);
}
}
else if (escape && !c_isprint ((unsigned char) c))
{
*pp++ = '\\';
*pp++ = '0' + (((unsigned char) c >> 6) & 7);
*pp++ = '0' + (((unsigned char) c >> 3) & 7);
*pp++ = '0' + ((unsigned char) c & 7);
*op++ = brk;
*op++ = UC_BREAK_PROHIBITED;
*op++ = UC_BREAK_PROHIBITED;
*op++ = UC_BREAK_PROHIBITED;
*ap++ = attr | ATTR_ESCAPE_SEQUENCE;
*ap++ = attr | ATTR_ESCAPE_SEQUENCE;
*ap++ = attr | ATTR_ESCAPE_SEQUENCE;
*ap++ = attr | ATTR_ESCAPE_SEQUENCE;
}
else if (c == '\\' || c == '"')
{
*pp++ = '\\';
*pp++ = c;
*op++ = brk;
*op++ = UC_BREAK_PROHIBITED;
*ap++ = attr | ATTR_ESCAPE_SEQUENCE;
*ap++ = attr | ATTR_ESCAPE_SEQUENCE;
}
else
{
#if HAVE_ICONV
if (conv != (iconv_t)(-1))
{
/* Copy a complete multi-byte character. Don't
interpret the second byte of a multi-byte character as
ASCII. This is needed for the BIG5, BIG5-HKSCS, GBK,
GB18030, SHIFT_JIS, JOHAB encodings. */
char scratchbuf[64];
const char *inptr = ep;
size_t insize;
char *outptr = &scratchbuf[0];
size_t outsize = sizeof (scratchbuf);
size_t res;
res = (size_t)(-1);
for (insize = 1; inptr + insize <= es; insize++)
{
res = iconv (conv,
(ICONV_CONST char **) &inptr, &insize,
&outptr, &outsize);
if (!(res == (size_t)(-1) && errno == EINVAL))
break;
/* We expect that no input bytes have been consumed
so far. */
if (inptr != ep)
abort ();
}
if (res == (size_t)(-1))
{
if (errno == EILSEQ)
{
po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0,
false, _("invalid multibyte sequence"));
continue;
}
else
abort ();
}
insize = inptr - ep;
memcpy_small (pp, ep, insize);
pp += insize;
*op = brk;
memset_small (op + 1, UC_BREAK_PROHIBITED, insize - 1);
op += insize;
memset_small (ap, attr, insize);
ap += insize;
ep += insize - 1;
}
else
#endif
{
if (weird_cjk
/* Special handling of encodings with CJK structure. */
&& ep + 2 <= es
&& (unsigned char) c >= 0x80
&& (unsigned char) ep[1] >= 0x30)
{
*pp++ = c;
ep += 1;
*pp++ = *ep;
*op++ = brk;
*op++ = UC_BREAK_PROHIBITED;
*ap++ = attr;
*ap++ = attr;
}
else
{
*pp++ = c;
*op++ = brk;
*ap++ = attr;
}
}
}
}
/* Don't break immediately before the "\n" at the end. */
if (es > s && es[-1] == '\n')
overrides[portion_len - 2] = UC_BREAK_PROHIBITED;
linebreaks = XNMALLOC (portion_len, char);
/* Subsequent lines after a break are all indented.
See INDENT-S. */
startcol_after_break = (line_prefix ? strlen (line_prefix) : 0);
if (indent)
startcol_after_break = (startcol_after_break + extra_indent + 8) & ~7;
startcol_after_break++;
/* The line width. Allow room for the closing quote character. */
width = (wrap_strings && do_wrap != no ? page_width : INT_MAX) - 1;
/* Adjust for indentation of subsequent lines. */
width -= startcol_after_break;
recompute:
/* The line starts with different things depending on whether it
is the first line, and if we are using the indented style.
See INDENT-F. */
startcol = (line_prefix ? strlen (line_prefix) : 0);
if (first_line)
{
startcol += strlen (name);
if (indent)
startcol = (startcol + extra_indent + 8) & ~7;
else
startcol++;
}
else
{
if (indent)
startcol = (startcol + extra_indent + 8) & ~7;
}
/* Allow room for the opening quote character. */
startcol++;
/* Adjust for indentation of subsequent lines. */
startcol -= startcol_after_break;
/* Do line breaking on the portion. */
ulc_width_linebreaks (portion, portion_len, width, startcol, 0,
overrides, canon_charset, linebreaks);
/* If this is the first line, and we are not using the indented
style, and the line would wrap, then use an empty first line
and restart. */
if (first_line && !indent
&& portion_len > 0
&& (*es != '\0'
|| startcol > width
|| memchr (linebreaks, UC_BREAK_POSSIBLE, portion_len) != NULL))
{
if (line_prefix != NULL)
ostream_write_str (stream, line_prefix);
begin_css_class (stream, css_class);
begin_css_class (stream, class_keyword);
ostream_write_str (stream, name);
end_css_class (stream, class_keyword);
ostream_write_str (stream, " ");
begin_css_class (stream, class_string);
ostream_write_str (stream, "\"\"");
end_css_class (stream, class_string);
end_css_class (stream, css_class);
ostream_write_str (stream, "\n");
first_line = false;
/* Recompute startcol and linebreaks. */
goto recompute;
}
/* Print the beginning of the line. This will depend on whether
this is the first line, and if the indented style is being
used. INDENT-F. */
{
int currcol = 0;
if (line_prefix != NULL)
{
ostream_write_str (stream, line_prefix);
currcol = strlen (line_prefix);
}
begin_css_class (stream, css_class);
if (first_line)
{
begin_css_class (stream, class_keyword);
ostream_write_str (stream, name);
currcol += strlen (name);
end_css_class (stream, class_keyword);
if (indent)
{
if (extra_indent > 0)
ostream_write_mem (stream, " ", extra_indent);
currcol += extra_indent;
ostream_write_mem (stream, " ", 8 - (currcol & 7));
currcol = (currcol + 8) & ~7;
}
else
{
ostream_write_str (stream, " ");
currcol++;
}
first_line = false;
}
else
{
if (indent)
{
if (extra_indent > 0)
ostream_write_mem (stream, " ", extra_indent);
currcol += extra_indent;
ostream_write_mem (stream, " ", 8 - (currcol & 7));
currcol = (currcol + 8) & ~7;
}
}
}
/* Print the portion itself, with linebreaks where necessary. */
{
char currattr = 0;
begin_css_class (stream, class_string);
ostream_write_str (stream, "\"");
begin_css_class (stream, class_text);
for (i = 0; i < portion_len; i++)
{
if (linebreaks[i] == UC_BREAK_POSSIBLE)
{
int currcol;
/* Change currattr so that it becomes 0. */
if (currattr & ATTR_ESCAPE_SEQUENCE)
{
end_css_class (stream, class_escape_sequence);
currattr &= ~ATTR_ESCAPE_SEQUENCE;
}
if (currattr & ATTR_FORMAT_DIRECTIVE)
{
end_css_class (stream, class_format_directive);
currattr &= ~ATTR_FORMAT_DIRECTIVE;
}
else if (currattr & ATTR_INVALID_FORMAT_DIRECTIVE)
{
end_css_class (stream, class_invalid_format_directive);
currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE;
}
if (!(currattr == 0))
abort ();
end_css_class (stream, class_text);
ostream_write_str (stream, "\"");
end_css_class (stream, class_string);
end_css_class (stream, css_class);
ostream_write_str (stream, "\n");
currcol = 0;
/* INDENT-S. */
if (line_prefix != NULL)
{
ostream_write_str (stream, line_prefix);
currcol = strlen (line_prefix);
}
begin_css_class (stream, css_class);
if (indent)
{
ostream_write_mem (stream, " ", 8 - (currcol & 7));
currcol = (currcol + 8) & ~7;
}
begin_css_class (stream, class_string);
ostream_write_str (stream, "\"");
begin_css_class (stream, class_text);
}
/* Change currattr so that it matches attributes[i]. */
if (attributes[i] != currattr)
{
/* class_escape_sequence occurs inside class_format_directive
and class_invalid_format_directive, so clear it first. */
if (currattr & ATTR_ESCAPE_SEQUENCE)
{
end_css_class (stream, class_escape_sequence);
currattr &= ~ATTR_ESCAPE_SEQUENCE;
}
if (~attributes[i] & currattr & ATTR_FORMAT_DIRECTIVE)
{
end_css_class (stream, class_format_directive);
currattr &= ~ATTR_FORMAT_DIRECTIVE;
}
else if (~attributes[i] & currattr & ATTR_INVALID_FORMAT_DIRECTIVE)
{
end_css_class (stream, class_invalid_format_directive);
currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE;
}
if (attributes[i] & ~currattr & ATTR_FORMAT_DIRECTIVE)
{
begin_css_class (stream, class_format_directive);
currattr |= ATTR_FORMAT_DIRECTIVE;
}
else if (attributes[i] & ~currattr & ATTR_INVALID_FORMAT_DIRECTIVE)
{
begin_css_class (stream, class_invalid_format_directive);
currattr |= ATTR_INVALID_FORMAT_DIRECTIVE;
}
/* class_escape_sequence occurs inside class_format_directive
and class_invalid_format_directive, so set it last. */
if (attributes[i] & ~currattr & ATTR_ESCAPE_SEQUENCE)
{
begin_css_class (stream, class_escape_sequence);
currattr |= ATTR_ESCAPE_SEQUENCE;
}
}
ostream_write_mem (stream, &portion[i], 1);
}
/* Change currattr so that it becomes 0. */
if (currattr & ATTR_ESCAPE_SEQUENCE)
{
end_css_class (stream, class_escape_sequence);
currattr &= ~ATTR_ESCAPE_SEQUENCE;
}
if (currattr & ATTR_FORMAT_DIRECTIVE)
{
end_css_class (stream, class_format_directive);
currattr &= ~ATTR_FORMAT_DIRECTIVE;
}
else if (currattr & ATTR_INVALID_FORMAT_DIRECTIVE)
{
end_css_class (stream, class_invalid_format_directive);
currattr &= ~ATTR_INVALID_FORMAT_DIRECTIVE;
}
if (!(currattr == 0))
abort ();
end_css_class (stream, class_text);
ostream_write_str (stream, "\"");
end_css_class (stream, class_string);
end_css_class (stream, css_class);
ostream_write_str (stream, "\n");
}
free (linebreaks);
free (attributes);
free (overrides);
free (portion);
s = es;
# undef is_escape
}
while (*s);
if (fmtdirattr != NULL)
free (fmtdirattr);
if (fmtdir != NULL)
free (fmtdir);
#if HAVE_ICONV
if (conv != (iconv_t)(-1))
iconv_close (conv);
#endif
}
static void
print_blank_line (ostream_t stream)
{
if (uniforum)
{
begin_css_class (stream, class_comment);
ostream_write_str (stream, "#\n");
end_css_class (stream, class_comment);
}
else
ostream_write_str (stream, "\n");
}
static void
message_print (const message_ty *mp, ostream_t stream,
const char *charset, size_t page_width, bool blank_line,
bool debug)
{
int extra_indent;
/* Separate messages with a blank line. Uniforum doesn't like blank
lines, so use an empty comment (unless there already is one). */
if (blank_line && (!uniforum
|| mp->comment == NULL
|| mp->comment->nitems == 0
|| mp->comment->item[0][0] != '\0'))
print_blank_line (stream);
if (is_header (mp))
begin_css_class (stream, class_header);
else if (mp->msgstr[0] == '\0')
begin_css_class (stream, class_untranslated);
else if (mp->is_fuzzy)
begin_css_class (stream, class_fuzzy);
else
begin_css_class (stream, class_translated);
begin_css_class (stream, class_comment);
/* Print translator comment if available. */
message_print_comment (mp, stream);
/* Print xgettext extracted comments. */
message_print_comment_dot (mp, stream);
/* Print the file position comments. This will help a human who is
trying to navigate the sources. There is no problem of getting
repeated positions, because duplicates are checked for. */
message_print_comment_filepos (mp, stream, uniforum, page_width);
/* Print flag information in special comment. */
message_print_comment_flags (mp, stream, debug);
/* Print the previous msgid. This helps the translator when the msgid has
only slightly changed. */
begin_css_class (stream, class_previous_comment);
if (mp->prev_msgctxt != NULL)
wrap (mp, stream, "#| ", 0, class_previous, "msgctxt", mp->prev_msgctxt,
mp->do_wrap, page_width, charset);
if (mp->prev_msgid != NULL)
wrap (mp, stream, "#| ", 0, class_previous, "msgid", mp->prev_msgid,
mp->do_wrap, page_width, charset);
if (mp->prev_msgid_plural != NULL)
wrap (mp, stream, "#| ", 0, class_previous, "msgid_plural",
mp->prev_msgid_plural, mp->do_wrap, page_width, charset);
end_css_class (stream, class_previous_comment);
extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
|| mp->prev_msgid_plural != NULL
? 3
: 0);
end_css_class (stream, class_comment);
/* Print each of the message components. Wrap them nicely so they
are as readable as possible. If there is no recorded msgstr for
this domain, emit an empty string. */
if (mp->msgctxt != NULL && !is_ascii_string (mp->msgctxt)
&& po_charset_canonicalize (charset) != po_charset_utf8)
{
char *warning_message =
xasprintf (_("\
The following msgctxt contains non-ASCII characters.\n\
This will cause problems to translators who use a character encoding\n\
different from yours. Consider using a pure ASCII msgctxt instead.\n\
%s\n"), mp->msgctxt);
po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message);
free (warning_message);
}
if (!is_ascii_string (mp->msgid)
&& po_charset_canonicalize (charset) != po_charset_utf8)
{
char *warning_message =
xasprintf (_("\
The following msgid contains non-ASCII characters.\n\
This will cause problems to translators who use a character encoding\n\
different from yours. Consider using a pure ASCII msgid instead.\n\
%s\n"), mp->msgid);
po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message);
free (warning_message);
}
if (mp->msgctxt != NULL)
wrap (mp, stream, NULL, extra_indent, class_msgid, "msgctxt", mp->msgctxt,
mp->do_wrap, page_width, charset);
wrap (mp, stream, NULL, extra_indent, class_msgid, "msgid", mp->msgid,
mp->do_wrap, page_width, charset);
if (mp->msgid_plural != NULL)
wrap (mp, stream, NULL, extra_indent, class_msgid, "msgid_plural",
mp->msgid_plural, mp->do_wrap, page_width, charset);
if (mp->msgid_plural == NULL)
wrap (mp, stream, NULL, extra_indent, class_msgstr, "msgstr", mp->msgstr,
mp->do_wrap, page_width, charset);
else
{
char prefix_buf[20];
unsigned int i;
const char *p;
for (p = mp->msgstr, i = 0;
p < mp->msgstr + mp->msgstr_len;
p += strlen (p) + 1, i++)
{
sprintf (prefix_buf, "msgstr[%u]", i);
wrap (mp, stream, NULL, extra_indent, class_msgstr, prefix_buf, p,
mp->do_wrap, page_width, charset);
}
}
if (is_header (mp))
end_css_class (stream, class_header);
else if (mp->msgstr[0] == '\0')
end_css_class (stream, class_untranslated);
else if (mp->is_fuzzy)
end_css_class (stream, class_fuzzy);
else
end_css_class (stream, class_translated);
}
static void
message_print_obsolete (const message_ty *mp, ostream_t stream,
const char *charset, size_t page_width, bool blank_line)
{
int extra_indent;
/* If msgstr is the empty string we print nothing. */
if (mp->msgstr[0] == '\0')
return;
/* Separate messages with a blank line. Uniforum doesn't like blank
lines, so use an empty comment (unless there already is one). */
if (blank_line)
print_blank_line (stream);
begin_css_class (stream, class_obsolete);
begin_css_class (stream, class_comment);
/* Print translator comment if available. */
message_print_comment (mp, stream);
/* Print xgettext extracted comments (normally empty). */
message_print_comment_dot (mp, stream);
/* Print the file position comments (normally empty). */
message_print_comment_filepos (mp, stream, uniforum, page_width);
/* Print flag information in special comment. */
if (mp->is_fuzzy)
{
bool first = true;
ostream_write_str (stream, "#,");
if (mp->is_fuzzy)
{
ostream_write_str (stream, " fuzzy");
first = false;
}
ostream_write_str (stream, "\n");
}
/* Print the previous msgid. This helps the translator when the msgid has
only slightly changed. */
begin_css_class (stream, class_previous_comment);
if (mp->prev_msgctxt != NULL)
wrap (mp, stream, "#~| ", 0, class_previous, "msgctxt", mp->prev_msgctxt,
mp->do_wrap, page_width, charset);
if (mp->prev_msgid != NULL)
wrap (mp, stream, "#~| ", 0, class_previous, "msgid", mp->prev_msgid,
mp->do_wrap, page_width, charset);
if (mp->prev_msgid_plural != NULL)
wrap (mp, stream, "#~| ", 0, class_previous, "msgid_plural",
mp->prev_msgid_plural, mp->do_wrap, page_width, charset);
end_css_class (stream, class_previous_comment);
extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
|| mp->prev_msgid_plural != NULL
? 1
: 0);
end_css_class (stream, class_comment);
/* Print each of the message components. Wrap them nicely so they
are as readable as possible. */
if (mp->msgctxt != NULL && !is_ascii_string (mp->msgctxt)
&& po_charset_canonicalize (charset) != po_charset_utf8)
{
char *warning_message =
xasprintf (_("\
The following msgctxt contains non-ASCII characters.\n\
This will cause problems to translators who use a character encoding\n\
different from yours. Consider using a pure ASCII msgctxt instead.\n\
%s\n"), mp->msgctxt);
po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message);
free (warning_message);
}
if (!is_ascii_string (mp->msgid)
&& po_charset_canonicalize (charset) != po_charset_utf8)
{
char *warning_message =
xasprintf (_("\
The following msgid contains non-ASCII characters.\n\
This will cause problems to translators who use a character encoding\n\
different from yours. Consider using a pure ASCII msgid instead.\n\
%s\n"), mp->msgid);
po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message);
free (warning_message);
}
if (mp->msgctxt != NULL)
wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgctxt", mp->msgctxt,
mp->do_wrap, page_width, charset);
wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgid", mp->msgid,
mp->do_wrap, page_width, charset);
if (mp->msgid_plural != NULL)
wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgid_plural",
mp->msgid_plural, mp->do_wrap, page_width, charset);
if (mp->msgid_plural == NULL)
wrap (mp, stream, "#~ ", extra_indent, class_msgstr, "msgstr", mp->msgstr,
mp->do_wrap, page_width, charset);
else
{
char prefix_buf[20];
unsigned int i;
const char *p;
for (p = mp->msgstr, i = 0;
p < mp->msgstr + mp->msgstr_len;
p += strlen (p) + 1, i++)
{
sprintf (prefix_buf, "msgstr[%u]", i);
wrap (mp, stream, "#~ ", extra_indent, class_msgstr, prefix_buf, p,
mp->do_wrap, page_width, charset);
}
}
end_css_class (stream, class_obsolete);
}
static void
msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream,
size_t page_width, bool debug)
{
size_t j, k;
bool blank_line;
/* Write out the messages for each domain. */
blank_line = false;
for (k = 0; k < mdlp->nitems; k++)
{
message_list_ty *mlp;
const char *header;
const char *charset;
char *allocated_charset;
/* If the first domain is the default, don't bother emitting
the domain name, because it is the default. */
if (!(k == 0
&& strcmp (mdlp->item[k]->domain, MESSAGE_DOMAIN_DEFAULT) == 0))
{
if (blank_line)
print_blank_line (stream);
begin_css_class (stream, class_keyword);
ostream_write_str (stream, "domain");
end_css_class (stream, class_keyword);
ostream_write_str (stream, " ");
begin_css_class (stream, class_string);
ostream_write_str (stream, "\"");
begin_css_class (stream, class_text);
ostream_write_str (stream, mdlp->item[k]->domain);
end_css_class (stream, class_text);
ostream_write_str (stream, "\"");
end_css_class (stream, class_string);
ostream_write_str (stream, "\n");
blank_line = true;
}
mlp = mdlp->item[k]->messages;
/* Search the header entry. */
header = NULL;
for (j = 0; j < mlp->nitems; ++j)
if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
{
header = mlp->item[j]->msgstr;
break;
}
/* Extract the charset name. */
charset = "ASCII";
allocated_charset = NULL;
if (header != NULL)
{
const char *charsetstr = c_strstr (header, "charset=");
if (charsetstr != NULL)
{
size_t len;
charsetstr += strlen ("charset=");
len = strcspn (charsetstr, " \t\n");
allocated_charset = (char *) xmalloca (len + 1);
memcpy (allocated_charset, charsetstr, len);
allocated_charset[len] = '\0';
charset = allocated_charset;
/* Treat the dummy default value as if it were absent. */
if (strcmp (charset, "CHARSET") == 0)
charset = "ASCII";
}
}
/* Write out each of the messages for this domain. */
for (j = 0; j < mlp->nitems; ++j)
if (!mlp->item[j]->obsolete)
{
message_print (mlp->item[j], stream, charset, page_width,
blank_line, debug);
blank_line = true;
}
/* Write out each of the obsolete messages for this domain. */
for (j = 0; j < mlp->nitems; ++j)
if (mlp->item[j]->obsolete)
{
message_print_obsolete (mlp->item[j], stream, charset, page_width,
blank_line);
blank_line = true;
}
if (allocated_charset != NULL)
freea (allocated_charset);
}
}
/* Describes a PO file in .po syntax. */
const struct catalog_output_format output_format_po =
{
msgdomain_list_print_po, /* print */
false, /* requires_utf8 */
true, /* supports_color */
true, /* supports_multiple_domains */
true, /* supports_contexts */
true, /* supports_plurals */
true, /* sorts_obsoletes_to_end */
false, /* alternative_is_po */
false /* alternative_is_java_class */
};
|