source: trunk/src/emx/testcase/misc/codeset-1.c@ 2309

Last change on this file since 2309 was 1701, checked in by bird, 21 years ago

* empty log message *

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.5 KB
Line 
1#include <wctype.h>
2#include <wchar.h>
3#include <stdio.h>
4#include <locale.h>
5#include <errno.h>
6#include <stdlib.h>
7#include <string.h>
8#include <iconv.h>
9
10int main(int argc, char **argv)
11{
12 iconv_t ic;
13 wchar_t wc;
14 const char *pszLocale = setlocale(LC_ALL, argv[1]);
15 if (!pszLocale)
16 {
17 printf("setlocale failed errno=%d\n", errno);
18 return 1;
19 }
20 printf("pszLocale=%s\n", pszLocale);
21
22 ic = iconv_open("UCS-2",
23#ifdef __IBMC__
24 strchr(pszLocale, '.') + 1
25#else
26 ""
27#endif
28 );
29 if (ic == (iconv_t)-1)
30 {
31 printf("iconv_open failed errno=%d\n", errno);
32 return 1;
33 }
34
35 for (wc = 0; wc < 0xffff; wc++)
36 {
37 char ach[7] = {0};
38 int rc = wctomb(ach, wc);
39 if (rc > 0)
40 {
41 unsigned char achUni[8] = {0};
42 char *pszIn = ach;
43 size_t cbInLeft = rc;
44 char *pszOut = (char *)&achUni[0];
45 size_t cbOutLeft = sizeof(achUni);
46 int rc2 = iconv(ic, &pszIn, &cbInLeft, &pszOut, &cbOutLeft);
47 *pszOut = 0;
48
49 printf("wc: 0x%04x %6d - %2d -- mb: %02x %02x %02x -- %s %s %s %s -- UCS2: %2d - 0x%04x %6d\n",
50 wc, wc, rc, ach[0], ach[1], ach[2],
51 iswupper(wc) ? "U" : "u", iswlower(wc) ? "L" : "l", iswgraph(wc) ? "G" : "g", iswalpha(wc) ? "A" : "a",
52 rc2, *(int *)achUni, *(int *)achUni);
53 }
54 }
55
56 return 0;
57}
Note: See TracBrowser for help on using the repository browser.