mf: Set preferred media types for nodes.
[wine.git] / tools / wrc / utils.c
bloba1e07b85b215e9915b2d495b940b9bd5218343aa
1 /*
2 * Utility routines
4 * Copyright 1998 Bertho A. Stultiens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <stdarg.h>
28 #include <string.h>
29 #include <ctype.h>
31 #include "wrc.h"
32 #include "utils.h"
33 #include "parser.h"
35 /* #define WANT_NEAR_INDICATION */
37 #ifdef WANT_NEAR_INDICATION
38 void make_print(char *str)
40 while(*str)
42 if(!isprint(*str))
43 *str = ' ';
44 str++;
47 #endif
49 static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
51 fprintf(stderr, "%s:%d:%d: %s: ", input_name ? input_name : "stdin", line_number, char_number, t);
52 vfprintf(stderr, s, ap);
53 #ifdef WANT_NEAR_INDICATION
55 char *cpy;
56 if(n)
58 cpy = xstrdup(n);
59 make_print(cpy);
60 fprintf(stderr, " near '%s'", cpy);
61 free(cpy);
64 #endif
68 int parser_error(const char *s, ...)
70 va_list ap;
71 va_start(ap, s);
72 generic_msg(s, "Error", parser_text, ap);
73 fputc( '\n', stderr );
74 va_end(ap);
75 exit(1);
76 return 1;
79 int parser_warning(const char *s, ...)
81 va_list ap;
82 va_start(ap, s);
83 generic_msg(s, "Warning", parser_text, ap);
84 va_end(ap);
85 return 0;
88 void internal_error(const char *file, int line, const char *s, ...)
90 va_list ap;
91 va_start(ap, s);
92 fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
93 vfprintf(stderr, s, ap);
94 va_end(ap);
95 exit(3);
98 void fatal_perror( const char *msg, ... )
100 va_list valist;
101 va_start( valist, msg );
102 fprintf(stderr, "Error: ");
103 vfprintf( stderr, msg, valist );
104 perror( " " );
105 va_end( valist );
106 exit(2);
109 void error(const char *s, ...)
111 va_list ap;
112 va_start(ap, s);
113 fprintf(stderr, "Error: ");
114 vfprintf(stderr, s, ap);
115 va_end(ap);
116 exit(2);
119 void warning(const char *s, ...)
121 va_list ap;
122 va_start(ap, s);
123 fprintf(stderr, "Warning: ");
124 vfprintf(stderr, s, ap);
125 va_end(ap);
128 void chat(const char *s, ...)
130 if(debuglevel & DEBUGLEVEL_CHAT)
132 va_list ap;
133 va_start(ap, s);
134 fprintf(stderr, "FYI: ");
135 vfprintf(stderr, s, ap);
136 va_end(ap);
140 char *dup_basename(const char *name, const char *ext)
142 int namelen;
143 int extlen = strlen(ext);
144 char *base;
145 char *slash;
147 if(!name)
148 name = "wrc.tab";
150 slash = strrchr(name, '/');
151 if (slash)
152 name = slash + 1;
154 namelen = strlen(name);
156 /* +4 for later extension and +1 for '\0' */
157 base = xmalloc(namelen +4 +1);
158 strcpy(base, name);
159 if(!strcasecmp(name + namelen-extlen, ext))
161 base[namelen - extlen] = '\0';
163 return base;
166 void *xmalloc(size_t size)
168 void *res;
170 assert(size > 0);
171 res = malloc(size);
172 if(res == NULL)
174 error("Virtual memory exhausted.\n");
176 memset(res, 0x55, size);
177 return res;
181 void *xrealloc(void *p, size_t size)
183 void *res;
185 assert(size > 0);
186 res = realloc(p, size);
187 if(res == NULL)
189 error("Virtual memory exhausted.\n");
191 return res;
194 char *strmake( const char* fmt, ... )
196 int n;
197 size_t size = 100;
198 va_list ap;
200 for (;;)
202 char *p = xmalloc( size );
203 va_start( ap, fmt );
204 n = vsnprintf( p, size, fmt, ap );
205 va_end( ap );
206 if (n == -1) size *= 2;
207 else if ((size_t)n >= size) size = n + 1;
208 else return p;
209 free( p );
213 char *xstrdup(const char *str)
215 char *s;
217 assert(str != NULL);
218 s = xmalloc(strlen(str)+1);
219 return strcpy(s, str);
222 int compare_striA( const char *str1, const char *str2 )
224 for (;;)
226 /* only the A-Z range is case-insensitive */
227 char ch1 = (*str1 >= 'a' && *str1 <= 'z') ? *str1 + 'A' - 'a' : *str1;
228 char ch2 = (*str2 >= 'a' && *str2 <= 'z') ? *str2 + 'A' - 'a' : *str2;
229 if (!ch1 || ch1 != ch2) return ch1 - ch2;
230 str1++;
231 str2++;
235 int compare_striW( const WCHAR *str1, const WCHAR *str2 )
237 for (;;)
239 /* only the A-Z range is case-insensitive */
240 WCHAR ch1 = (*str1 >= 'a' && *str1 <= 'z') ? *str1 + 'A' - 'a' : *str1;
241 WCHAR ch2 = (*str2 >= 'a' && *str2 <= 'z') ? *str2 + 'A' - 'a' : *str2;
242 if (!ch1 || ch1 != ch2) return ch1 - ch2;
243 str1++;
244 str2++;
249 *****************************************************************************
250 * Function : compare_name_id
251 * Syntax : int compare_name_id(const name_id_t *n1, const name_id_t *n2)
252 * Input :
253 * Output :
254 * Description :
255 * Remarks :
256 *****************************************************************************
258 int compare_name_id(const name_id_t *n1, const name_id_t *n2)
260 if(n1->type == name_ord && n2->type == name_ord)
262 return n1->name.i_name - n2->name.i_name;
264 else if(n1->type == name_str && n2->type == name_str)
266 if(n1->name.s_name->type == str_char
267 && n2->name.s_name->type == str_char)
269 return compare_striA(n1->name.s_name->str.cstr, n2->name.s_name->str.cstr);
271 else if(n1->name.s_name->type == str_unicode
272 && n2->name.s_name->type == str_unicode)
274 return compare_striW(n1->name.s_name->str.wstr, n2->name.s_name->str.wstr);
276 else
278 internal_error(__FILE__, __LINE__, "Can't yet compare strings of mixed type\n");
281 else if(n1->type == name_ord && n2->type == name_str)
282 return 1;
283 else if(n1->type == name_str && n2->type == name_ord)
284 return -1;
285 else
286 internal_error(__FILE__, __LINE__, "Comparing name-ids with unknown types (%d, %d)\n",
287 n1->type, n2->type);
289 return 0; /* Keep the compiler happy */
292 #ifdef _WIN32
294 int is_valid_codepage(int id)
296 return IsValidCodePage( id );
299 int wrc_mbstowcs( int codepage, int flags, const char *src, int srclen, WCHAR *dst, int dstlen )
301 return MultiByteToWideChar( codepage, flags, src, srclen, dst, dstlen );
304 int wrc_wcstombs( int codepage, int flags, const WCHAR *src, int srclen, char *dst, int dstlen )
306 return WideCharToMultiByte( codepage, flags, src, srclen, dst, dstlen, NULL, NULL );
309 #else /* _WIN32 */
311 #include "wine/unicode.h"
313 int is_valid_codepage(int cp)
315 return cp == CP_UTF8 || wine_cp_get_table(cp);
318 int wrc_mbstowcs( int codepage, int flags, const char *src, int srclen, WCHAR *dst, int dstlen )
320 if (codepage == CP_UTF8) return wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
321 return wine_cp_mbstowcs( wine_cp_get_table( codepage ), flags, src, srclen, dst, dstlen );
324 int wrc_wcstombs( int codepage, int flags, const WCHAR *src, int srclen, char *dst, int dstlen )
326 if (codepage == CP_UTF8) return wine_utf8_wcstombs( flags, src, srclen, dst, dstlen );
327 return wine_cp_wcstombs( wine_cp_get_table( codepage ), flags, src, srclen, dst, dstlen, NULL, NULL );
330 #endif /* _WIN32 */
332 string_t *convert_string(const string_t *str, enum str_e type, int codepage)
334 string_t *ret = xmalloc(sizeof(*ret));
335 int res;
337 ret->loc = str->loc;
339 if (!codepage && str->type != type)
340 parser_error( "Current language is Unicode only, cannot convert string" );
342 if((str->type == str_char) && (type == str_unicode))
344 ret->type = str_unicode;
345 ret->size = wrc_mbstowcs( codepage, 0, str->str.cstr, str->size, NULL, 0 );
346 ret->str.wstr = xmalloc( (ret->size+1) * sizeof(WCHAR) );
347 res = wrc_mbstowcs( codepage, MB_ERR_INVALID_CHARS, str->str.cstr, str->size,
348 ret->str.wstr, ret->size );
349 if (res == -2)
350 parser_error( "Invalid character in string '%.*s' for codepage %u",
351 str->size, str->str.cstr, codepage );
352 ret->str.wstr[ret->size] = 0;
354 else if((str->type == str_unicode) && (type == str_char))
356 ret->type = str_char;
357 ret->size = wrc_wcstombs( codepage, 0, str->str.wstr, str->size, NULL, 0 );
358 ret->str.cstr = xmalloc( ret->size + 1 );
359 wrc_wcstombs( codepage, 0, str->str.wstr, str->size, ret->str.cstr, ret->size );
360 ret->str.cstr[ret->size] = 0;
362 else if(str->type == str_unicode)
364 ret->type = str_unicode;
365 ret->size = str->size;
366 ret->str.wstr = xmalloc(sizeof(WCHAR)*(ret->size+1));
367 memcpy( ret->str.wstr, str->str.wstr, ret->size * sizeof(WCHAR) );
368 ret->str.wstr[ret->size] = 0;
370 else /* str->type == str_char */
372 ret->type = str_char;
373 ret->size = str->size;
374 ret->str.cstr = xmalloc( ret->size + 1 );
375 memcpy( ret->str.cstr, str->str.cstr, ret->size );
376 ret->str.cstr[ret->size] = 0;
378 return ret;
382 void free_string(string_t *str)
384 if (str->type == str_unicode) free( str->str.wstr );
385 else free( str->str.cstr );
386 free( str );
389 /* check if the string is valid utf8 despite a different codepage being in use */
390 int check_valid_utf8( const string_t *str, int codepage )
392 unsigned int i;
394 if (!check_utf8) return 0;
395 if (!codepage) return 0;
396 if (codepage == CP_UTF8) return 0;
397 if (!is_valid_codepage( codepage )) return 0;
399 for (i = 0; i < str->size; i++)
401 if ((unsigned char)str->str.cstr[i] >= 0xf5) goto done;
402 if ((unsigned char)str->str.cstr[i] >= 0xc2) break;
403 if ((unsigned char)str->str.cstr[i] >= 0x80) goto done;
405 if (i == str->size) return 0; /* no 8-bit chars at all */
407 if (wrc_mbstowcs( CP_UTF8, MB_ERR_INVALID_CHARS, str->str.cstr, str->size, NULL, 0 ) >= 0) return 1;
409 done:
410 check_utf8 = 0; /* at least one 8-bit non-utf8 string found, stop checking */
411 return 0;
414 int check_unicode_conversion( const string_t *str_a, const string_t *str_w, int codepage )
416 int ok;
417 string_t *teststr = convert_string( str_w, str_char, codepage );
419 ok = (teststr->size == str_a->size && !memcmp( teststr->str.cstr, str_a->str.cstr, str_a->size ));
421 if (!ok)
423 int i;
425 fprintf( stderr, "Source: %s", str_a->str.cstr );
426 for (i = 0; i < str_a->size; i++)
427 fprintf( stderr, " %02x", (unsigned char)str_a->str.cstr[i] );
428 fprintf( stderr, "\nUnicode: " );
429 for (i = 0; i < str_w->size; i++)
430 fprintf( stderr, " %04x", str_w->str.wstr[i] );
431 fprintf( stderr, "\nBack: %s", teststr->str.cstr );
432 for (i = 0; i < teststr->size; i++)
433 fprintf( stderr, " %02x", (unsigned char)teststr->str.cstr[i] );
434 fprintf( stderr, "\n" );
436 free_string( teststr );
437 return ok;
441 struct lang2cp
443 unsigned short lang;
444 unsigned short sublang;
445 unsigned int cp;
448 /* language to codepage conversion table */
449 /* specific sublanguages need only be specified if their codepage */
450 /* differs from the default (SUBLANG_NEUTRAL) */
451 static const struct lang2cp lang2cps[] =
453 { LANG_AFRIKAANS, SUBLANG_NEUTRAL, 1252 },
454 { LANG_ALBANIAN, SUBLANG_NEUTRAL, 1250 },
455 { LANG_ALSATIAN, SUBLANG_NEUTRAL, 1252 },
456 { LANG_AMHARIC, SUBLANG_NEUTRAL, 0 },
457 { LANG_ARABIC, SUBLANG_NEUTRAL, 1256 },
458 { LANG_ARMENIAN, SUBLANG_NEUTRAL, 0 },
459 { LANG_ASSAMESE, SUBLANG_NEUTRAL, 0 },
460 { LANG_ASTURIAN, SUBLANG_NEUTRAL, 1252 },
461 { LANG_AZERI, SUBLANG_NEUTRAL, 1254 },
462 { LANG_AZERI, SUBLANG_AZERI_CYRILLIC, 1251 },
463 { LANG_BASHKIR, SUBLANG_NEUTRAL, 1251 },
464 { LANG_BASQUE, SUBLANG_NEUTRAL, 1252 },
465 { LANG_BELARUSIAN, SUBLANG_NEUTRAL, 1251 },
466 { LANG_BENGALI, SUBLANG_NEUTRAL, 0 },
467 { LANG_BOSNIAN, SUBLANG_NEUTRAL, 1250 },
468 { LANG_BOSNIAN, SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC, 1251 },
469 { LANG_BRETON, SUBLANG_NEUTRAL, 1252 },
470 { LANG_BULGARIAN, SUBLANG_NEUTRAL, 1251 },
471 { LANG_CATALAN, SUBLANG_NEUTRAL, 1252 },
472 { LANG_CHINESE, SUBLANG_NEUTRAL, 950 },
473 { LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED, 936 },
474 { LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE, 936 },
475 #ifdef LANG_CORNISH
476 { LANG_CORNISH, SUBLANG_NEUTRAL, 1252 },
477 #endif /* LANG_CORNISH */
478 { LANG_CORSICAN, SUBLANG_NEUTRAL, 1252 },
479 { LANG_CROATIAN, SUBLANG_NEUTRAL, 1250 },
480 { LANG_CZECH, SUBLANG_NEUTRAL, 1250 },
481 { LANG_DANISH, SUBLANG_NEUTRAL, 1252 },
482 { LANG_DARI, SUBLANG_NEUTRAL, 1256 },
483 { LANG_DIVEHI, SUBLANG_NEUTRAL, 0 },
484 { LANG_DUTCH, SUBLANG_NEUTRAL, 1252 },
485 { LANG_ENGLISH, SUBLANG_NEUTRAL, 1252 },
486 #ifdef LANG_ESPERANTO
487 { LANG_ESPERANTO, SUBLANG_NEUTRAL, 1252 },
488 #endif /* LANG_ESPERANTO */
489 { LANG_ESTONIAN, SUBLANG_NEUTRAL, 1257 },
490 { LANG_FAEROESE, SUBLANG_NEUTRAL, 1252 },
491 { LANG_FILIPINO, SUBLANG_NEUTRAL, 1252 },
492 { LANG_FINNISH, SUBLANG_NEUTRAL, 1252 },
493 { LANG_FRENCH, SUBLANG_NEUTRAL, 1252 },
494 { LANG_FRISIAN, SUBLANG_NEUTRAL, 1252 },
495 #ifdef LANG_MANX_GAELIC
496 { LANG_MANX_GAELIC, SUBLANG_NEUTRAL, 1252 },
497 #endif /* LANG_MANX_GAELIC */
498 { LANG_GALICIAN, SUBLANG_NEUTRAL, 1252 },
499 { LANG_GEORGIAN, SUBLANG_NEUTRAL, 0 },
500 { LANG_GERMAN, SUBLANG_NEUTRAL, 1252 },
501 { LANG_GREEK, SUBLANG_NEUTRAL, 1253 },
502 { LANG_GREENLANDIC, SUBLANG_NEUTRAL, 1252 },
503 { LANG_GUJARATI, SUBLANG_NEUTRAL, 0 },
504 { LANG_HAUSA, SUBLANG_NEUTRAL, 1252 },
505 { LANG_HEBREW, SUBLANG_NEUTRAL, 1255 },
506 { LANG_HINDI, SUBLANG_NEUTRAL, 0 },
507 { LANG_HUNGARIAN, SUBLANG_NEUTRAL, 1250 },
508 { LANG_ICELANDIC, SUBLANG_NEUTRAL, 1252 },
509 { LANG_IGBO, SUBLANG_NEUTRAL, 1252 },
510 { LANG_INDONESIAN, SUBLANG_NEUTRAL, 1252 },
511 { LANG_INUKTITUT, SUBLANG_NEUTRAL, 0 },
512 { LANG_INUKTITUT, SUBLANG_INUKTITUT_CANADA_LATIN, 0 },
513 { LANG_INVARIANT, SUBLANG_NEUTRAL, 0 },
514 { LANG_IRISH, SUBLANG_NEUTRAL, 1252 },
515 { LANG_ITALIAN, SUBLANG_NEUTRAL, 1252 },
516 { LANG_JAPANESE, SUBLANG_NEUTRAL, 932 },
517 { LANG_KANNADA, SUBLANG_NEUTRAL, 0 },
518 { LANG_KAZAK, SUBLANG_NEUTRAL, 1251 },
519 { LANG_KHMER, SUBLANG_NEUTRAL, 0 },
520 { LANG_KICHE, SUBLANG_NEUTRAL, 1252 },
521 { LANG_KINYARWANDA, SUBLANG_NEUTRAL, 1252 },
522 { LANG_KONKANI, SUBLANG_NEUTRAL, 0 },
523 { LANG_KOREAN, SUBLANG_NEUTRAL, 949 },
524 { LANG_KYRGYZ, SUBLANG_NEUTRAL, 1251 },
525 { LANG_LAO, SUBLANG_NEUTRAL, 0 },
526 { LANG_LATVIAN, SUBLANG_NEUTRAL, 1257 },
527 { LANG_LITHUANIAN, SUBLANG_NEUTRAL, 1257 },
528 { LANG_LOWER_SORBIAN, SUBLANG_NEUTRAL, 1252 },
529 { LANG_LUXEMBOURGISH, SUBLANG_NEUTRAL, 1252 },
530 { LANG_MACEDONIAN, SUBLANG_NEUTRAL, 1251 },
531 { LANG_MALAY, SUBLANG_NEUTRAL, 1252 },
532 { LANG_MALAYALAM, SUBLANG_NEUTRAL, 0 },
533 { LANG_MALTESE, SUBLANG_NEUTRAL, 0 },
534 { LANG_MAORI, SUBLANG_NEUTRAL, 0 },
535 { LANG_MAPUDUNGUN, SUBLANG_NEUTRAL, 1252 },
536 { LANG_MARATHI, SUBLANG_NEUTRAL, 0 },
537 { LANG_MOHAWK, SUBLANG_NEUTRAL, 1252 },
538 { LANG_MONGOLIAN, SUBLANG_NEUTRAL, 1251 },
539 { LANG_NEPALI, SUBLANG_NEUTRAL, 0 },
540 { LANG_NEUTRAL, SUBLANG_NEUTRAL, 1252 },
541 { LANG_NORWEGIAN, SUBLANG_NEUTRAL, 1252 },
542 { LANG_OCCITAN, SUBLANG_NEUTRAL, 1252 },
543 { LANG_ORIYA, SUBLANG_NEUTRAL, 0 },
544 { LANG_PASHTO, SUBLANG_NEUTRAL, 0 },
545 { LANG_PERSIAN, SUBLANG_NEUTRAL, 1256 },
546 { LANG_POLISH, SUBLANG_NEUTRAL, 1250 },
547 { LANG_PORTUGUESE, SUBLANG_NEUTRAL, 1252 },
548 { LANG_PUNJABI, SUBLANG_NEUTRAL, 0 },
549 { LANG_QUECHUA, SUBLANG_NEUTRAL, 1252 },
550 { LANG_ROMANIAN, SUBLANG_NEUTRAL, 1250 },
551 { LANG_ROMANSH, SUBLANG_NEUTRAL, 1252 },
552 { LANG_RUSSIAN, SUBLANG_NEUTRAL, 1251 },
553 { LANG_SAMI, SUBLANG_NEUTRAL, 1252 },
554 { LANG_SANSKRIT, SUBLANG_NEUTRAL, 0 },
555 { LANG_SCOTTISH_GAELIC,SUBLANG_NEUTRAL, 1252 },
556 { LANG_SERBIAN, SUBLANG_NEUTRAL, 1250 },
557 { LANG_SERBIAN, SUBLANG_SERBIAN_CYRILLIC, 1251 },
558 { LANG_SINHALESE, SUBLANG_NEUTRAL, 0 },
559 { LANG_SLOVAK, SUBLANG_NEUTRAL, 1250 },
560 { LANG_SLOVENIAN, SUBLANG_NEUTRAL, 1250 },
561 { LANG_SOTHO, SUBLANG_NEUTRAL, 1252 },
562 { LANG_SPANISH, SUBLANG_NEUTRAL, 1252 },
563 { LANG_SWAHILI, SUBLANG_NEUTRAL, 1252 },
564 { LANG_SWEDISH, SUBLANG_NEUTRAL, 1252 },
565 { LANG_SYRIAC, SUBLANG_NEUTRAL, 0 },
566 { LANG_TAJIK, SUBLANG_NEUTRAL, 1251 },
567 { LANG_TAMAZIGHT, SUBLANG_NEUTRAL, 1252 },
568 { LANG_TAMIL, SUBLANG_NEUTRAL, 0 },
569 { LANG_TATAR, SUBLANG_NEUTRAL, 1251 },
570 { LANG_TELUGU, SUBLANG_NEUTRAL, 0 },
571 { LANG_THAI, SUBLANG_NEUTRAL, 874 },
572 { LANG_TIBETAN, SUBLANG_NEUTRAL, 0 },
573 { LANG_TSWANA, SUBLANG_NEUTRAL, 1252 },
574 { LANG_TURKISH, SUBLANG_NEUTRAL, 1254 },
575 { LANG_TURKMEN, SUBLANG_NEUTRAL, 1250 },
576 { LANG_UIGHUR, SUBLANG_NEUTRAL, 1256 },
577 { LANG_UKRAINIAN, SUBLANG_NEUTRAL, 1251 },
578 { LANG_UPPER_SORBIAN, SUBLANG_NEUTRAL, 1252 },
579 { LANG_URDU, SUBLANG_NEUTRAL, 1256 },
580 { LANG_UZBEK, SUBLANG_NEUTRAL, 1254 },
581 { LANG_UZBEK, SUBLANG_UZBEK_CYRILLIC, 1251 },
582 { LANG_VIETNAMESE, SUBLANG_NEUTRAL, 1258 },
583 #ifdef LANG_WALON
584 { LANG_WALON, SUBLANG_NEUTRAL, 1252 },
585 #endif /* LANG_WALON */
586 { LANG_WELSH, SUBLANG_NEUTRAL, 1252 },
587 { LANG_WOLOF, SUBLANG_NEUTRAL, 1252 },
588 { LANG_XHOSA, SUBLANG_NEUTRAL, 1252 },
589 { LANG_YAKUT, SUBLANG_NEUTRAL, 1251 },
590 { LANG_YI, SUBLANG_NEUTRAL, 0 },
591 { LANG_YORUBA, SUBLANG_NEUTRAL, 1252 },
592 { LANG_ZULU, SUBLANG_NEUTRAL, 1252 }
595 int get_language_codepage( unsigned short lang, unsigned short sublang )
597 unsigned int i;
598 int cp = -1, defcp = -1;
600 for (i = 0; i < ARRAY_SIZE(lang2cps); i++)
602 if (lang2cps[i].lang != lang) continue;
603 if (lang2cps[i].sublang == sublang)
605 cp = lang2cps[i].cp;
606 break;
608 if (lang2cps[i].sublang == SUBLANG_NEUTRAL) defcp = lang2cps[i].cp;
611 if (cp == -1) cp = defcp;
612 assert( cp <= 0 || is_valid_codepage(cp) );
613 return cp;