Warning, /sdk/cutehmi/external/recipes/i686-w64-mingw32/gettext/0005-improve-plural-rules-detection.patch is written in an unsupported language. File is not indexed.
0001 --- a/gettext-tools/src/cldr-plurals.c Sun Mar 20 09:37:53 2016 0002 +++ b/gettext-tools/src/cldr-plurals.c Tue Jul 12 09:31:21 2016 0003 @@ -44,12 +44,13 @@ 0004 extract_rules (FILE *fp, 0005 const char *real_filename, const char *logical_filename, 0006 const char *locale) 0007 { 0008 xmlDocPtr doc; 0009 - xmlNodePtr node, n; 0010 - size_t locale_length; 0011 + xmlNodePtr rootNode, pluralsNode, pluralRulesNode, n; 0012 + size_t locale_lengths[4]; 0013 + size_t locale_length, locale_lengths_count, locale_lengths_index; 0014 char *buffer = NULL, *p; 0015 size_t bufmax = 0; 0016 size_t buflen = 0; 0017 0018 doc = xmlReadFd (fileno (fp), logical_filename, NULL, 0019 @@ -58,101 +59,130 @@ 0020 | XML_PARSE_NOERROR 0021 | XML_PARSE_NOBLANKS); 0022 if (doc == NULL) 0023 error (EXIT_FAILURE, 0, _("memory exhausted")); 0024 0025 - node = xmlDocGetRootElement (doc); 0026 - if (!node || !xmlStrEqual (node->name, BAD_CAST "supplementalData")) 0027 + rootNode = xmlDocGetRootElement (doc); 0028 + if (!rootNode || !xmlStrEqual (rootNode->name, BAD_CAST "supplementalData")) 0029 { 0030 error_at_line (0, 0, 0031 logical_filename, 0032 - xmlGetLineNo (node), 0033 + xmlGetLineNo (rootNode), 0034 _("\ 0035 The root element must be <%s>"), 0036 "supplementalData"); 0037 goto out; 0038 } 0039 0040 - for (n = node->children; n; n = n->next) 0041 + for (pluralsNode = NULL, n = rootNode->children; n; n = n->next) 0042 { 0043 if (n->type == XML_ELEMENT_NODE 0044 && xmlStrEqual (n->name, BAD_CAST "plurals")) 0045 - break; 0046 + { 0047 + pluralsNode = n; 0048 + break; 0049 + } 0050 } 0051 - if (!n) 0052 + if (!pluralsNode) 0053 { 0054 error (0, 0, _("The element <%s> does not contain a <%s> element"), 0055 "supplementalData", "plurals"); 0056 goto out; 0057 } 0058 0059 - locale_length = strlen (locale); 0060 - for (n = n->children; n; n = n->next) 0061 + locale_lengths[0] = strlen (locale); 0062 + locale_lengths_count = 1; 0063 + for ( 0064 + locale_lengths_index = locale_lengths[0] - 1; 0065 + locale_lengths_index > 0 && locale_lengths_count < 4; 0066 + locale_lengths_index-- 0067 + ) 0068 + { 0069 + switch (locale[locale_lengths_index]) 0070 + { 0071 + case '.': 0072 + case '_': 0073 + case '-': 0074 + case '@': 0075 + locale_lengths[locale_lengths_count++] = locale_lengths_index; 0076 + break; 0077 + } 0078 + } 0079 + for ( 0080 + pluralRulesNode = NULL, locale_lengths_index = 0; 0081 + locale_lengths_index < locale_lengths_count; 0082 + locale_lengths_index++ 0083 + ) 0084 { 0085 - xmlChar *locales; 0086 xmlChar *cp; 0087 - xmlNodePtr n2; 0088 - bool found = false; 0089 - 0090 - if (n->type != XML_ELEMENT_NODE 0091 - || !xmlStrEqual (n->name, BAD_CAST "pluralRules")) 0092 - continue; 0093 - 0094 - if (!xmlHasProp (n, BAD_CAST "locales")) 0095 + xmlChar *locales; 0096 + locale_length = locale_lengths[locale_lengths_index]; 0097 + for (n = pluralsNode->children; n; n = n->next) 0098 { 0099 - error_at_line (0, 0, 0100 - logical_filename, 0101 - xmlGetLineNo (n), 0102 - _("\ 0103 -The element <%s> does not have attribute <%s>"), 0104 - "pluralRules", "locales"); 0105 - continue; 0106 - } 0107 + if (n->type != XML_ELEMENT_NODE 0108 + || !xmlStrEqual (n->name, BAD_CAST "pluralRules")) 0109 + continue; 0110 0111 - cp = locales = xmlGetProp (n, BAD_CAST "locales"); 0112 - while (*cp != '\0') 0113 - { 0114 - while (c_isspace (*cp)) 0115 - cp++; 0116 - if (xmlStrncmp (cp, BAD_CAST locale, locale_length) == 0 0117 - && (*(cp + locale_length) == '\0' 0118 - || c_isspace (*(cp + locale_length)))) 0119 + if (!xmlHasProp (n, BAD_CAST "locales")) 0120 { 0121 - found = true; 0122 - break; 0123 + error_at_line (0, 0, 0124 + logical_filename, 0125 + xmlGetLineNo (n), 0126 + _("\ 0127 + The element <%s> does not have attribute <%s>"), 0128 + "pluralRules", "locales"); 0129 + continue; 0130 } 0131 - while (*cp && !c_isspace (*cp)) 0132 - cp++; 0133 - } 0134 - xmlFree (locales); 0135 0136 - if (!found) 0137 - continue; 0138 + cp = locales = xmlGetProp (n, BAD_CAST "locales"); 0139 + while (*cp != '\0') 0140 + { 0141 + while (c_isspace (*cp)) 0142 + cp++; 0143 + if (xmlStrncmp (cp, BAD_CAST locale, locale_length) == 0 0144 + && (*(cp + locale_length) == '\0' 0145 + || c_isspace (*(cp + locale_length)))) 0146 + { 0147 + pluralRulesNode = n; 0148 + break; 0149 + } 0150 + while (*cp && !c_isspace (*cp)) 0151 + cp++; 0152 + } 0153 + xmlFree (locales); 0154 0155 - for (n2 = n->children; n2; n2 = n2->next) 0156 + if (pluralRulesNode) 0157 + break; 0158 + } 0159 + if (pluralRulesNode) 0160 + break; 0161 + } 0162 + if (pluralRulesNode) 0163 + { 0164 + for (n = pluralRulesNode->children; n; n = n->next) 0165 { 0166 xmlChar *count; 0167 xmlChar *content; 0168 size_t length; 0169 0170 - if (n2->type != XML_ELEMENT_NODE 0171 - || !xmlStrEqual (n2->name, BAD_CAST "pluralRule")) 0172 + if (n->type != XML_ELEMENT_NODE 0173 + || !xmlStrEqual (n->name, BAD_CAST "pluralRule")) 0174 continue; 0175 0176 - if (!xmlHasProp (n2, BAD_CAST "count")) 0177 + if (!xmlHasProp (n, BAD_CAST "count")) 0178 { 0179 error_at_line (0, 0, 0180 logical_filename, 0181 - xmlGetLineNo (n2), 0182 + xmlGetLineNo (n), 0183 _("\ 0184 The element <%s> does not have attribute <%s>"), 0185 "pluralRule", "count"); 0186 break; 0187 } 0188 0189 - count = xmlGetProp (n2, BAD_CAST "count"); 0190 - content = xmlNodeGetContent (n2); 0191 + count = xmlGetProp (n, BAD_CAST "count"); 0192 + content = xmlNodeGetContent (n); 0193 length = xmlStrlen (count) + strlen (": ") 0194 + xmlStrlen (content) + strlen ("; "); 0195 0196 if (buflen + length + 1 > bufmax) 0197 {