1 /* ----------------------------------------------------------------------------
2  * $ gcc -Wall -o sample sample.c -L. -lunijp
3  * ------------------------------------------------------------------------- */
4 #include "unijp.h"
5 #include <errno.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 
test_conv(const char * text_utf8,uj_charcode_t ocode)10 int test_conv(const char* text_utf8, uj_charcode_t ocode)
11 {
12   uj_charcode_t icode = ujc_utf8;
13   size_t in_bytes;
14   unijp_t* uj;
15   uj_uint8* obuf;
16   uj_size_t obuf_len;
17 
18   in_bytes = strlen(text_utf8);
19   uj = uj_new((uj_uint8*)text_utf8, in_bytes, icode);
20   if( uj==NULL )
21   {
22     fprintf(stderr, "uj_new: %s: %s\n", "-", strerror(errno));
23     return 1;
24   }
25   obuf = uj_conv(uj, ocode, &obuf_len);
26   if( obuf==NULL )
27   {
28     fprintf(stderr, "uj_conv: %s: %s\n", "-", strerror(errno));
29     return 1;
30   }
31 
32   printf("sjis result: %s\n", obuf);
33   free(obuf);
34   uj_delete(uj);
35 
36   return 0;
37 }
38 
main()39 int main()
40 {
41   int r;
42   const char* text_utf8 = "テスト";
43 
44   r = test_conv(text_utf8, ujc_sjis);
45 
46   return r;
47 }
48 
49 /* ----------------------------------------------------------------------------
50  * End of File.
51  * ------------------------------------------------------------------------- */
52