1 /* Copyright (C) 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* Create a table from Unicode to CHARSET.
21 This is a good test for CHARSET's iconv() module, in particular the
22 TO_LOOP BODY macro. */
31 main (int argc
, char *argv
[])
38 fprintf (stderr
, "Usage: tst-table-to charset\n");
43 cd
= iconv_open (charset
, "UCS-2");
44 if (cd
== (iconv_t
)(-1))
46 perror ("iconv_open");
52 unsigned char buf
[10];
54 for (i
= 0; i
< 0x10000; i
++)
56 unsigned short in
= i
;
57 const char *inbuf
= (const char *) &in
;
58 size_t inbytesleft
= sizeof (unsigned short);
59 char *outbuf
= (char *) buf
;
60 size_t outbytesleft
= sizeof (buf
);
61 size_t result
= iconv (cd
,
62 (char **) &inbuf
, &inbytesleft
,
63 &outbuf
, &outbytesleft
);
64 if (result
== (size_t)(-1))
68 int saved_errno
= errno
;
69 fprintf (stderr
, "0x%02X: iconv error: ", i
);
75 else if (result
== 0) /* ignore conversions with transliteration */
78 if (inbytesleft
!= 0 || outbytesleft
== sizeof (buf
))
80 fprintf (stderr
, "0x%02X: inbytes = %ld, outbytes = %ld\n", i
,
81 (long) (sizeof (unsigned short) - inbytesleft
),
82 (long) (sizeof (buf
) - outbytesleft
));
85 jmax
= sizeof (buf
) - outbytesleft
;
87 for (j
= 0; j
< jmax
; j
++)
88 printf ("%02X", buf
[j
]);
89 printf ("\t0x%04X\n", i
);
94 if (iconv_close (cd
) < 0)
96 perror ("iconv_close");
100 if (ferror (stdin
) || fflush (stdout
) || ferror (stdout
))
102 fprintf (stderr
, "I/O error\n");