ignore cql2pqf and cql2xcql
[yaz-moved-to-github.git] / util / tsticonv.c
1 /*
2  * Copyright (c) 2002-2003, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: tsticonv.c,v 1.1 2003-04-23 20:34:08 adam Exp $
6  */
7
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <errno.h>
13 #include <string.h>
14 #include <ctype.h>
15
16 #include <yaz/yaz-util.h>
17
18 const char *buf[] = {
19         "ax" ,
20         "\330",
21         "eneb\346r",
22         0 };
23
24 static dconvert(int mandatory, const char *tmpcode)
25 {
26     int i;
27     yaz_iconv_t cd;
28     for (i = 0; buf[i]; i++)
29     {
30         int j;
31         size_t r;
32         char *inbuf = (char*) buf[i];
33         size_t inbytesleft = strlen(inbuf);
34         char outbuf0[24];
35         char outbuf1[10];
36         char *outbuf = outbuf0;
37         size_t outbytesleft = sizeof(outbuf0);
38
39         cd = yaz_iconv_open(tmpcode, "ISO-8859-1");
40         if (!cd)
41         {
42             if (!mandatory)
43                 return;
44             printf ("tsticonv 1\n");
45             exit(1);
46         }
47         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
48         if (r == (size_t)(-1))
49         {
50             int e = yaz_iconv_error(cd);
51
52             printf ("tsticonv 2 e=%d\n", e);
53             exit(2);
54         }
55         yaz_iconv_close(cd);
56         
57         cd = yaz_iconv_open("ISO-8859-1", tmpcode);
58         if (!cd)
59         {
60             if (!mandatory)
61                 return;
62             printf ("tsticonv 3\n");
63             exit(3);
64         }
65         inbuf = outbuf0;
66         inbytesleft = sizeof(outbuf0) - outbytesleft;
67
68         outbuf = outbuf1;
69         outbytesleft = sizeof(outbuf1);
70         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
71         if (r == (size_t)(-1)) {
72             int e = yaz_iconv_error(cd);
73
74             printf ("tsticonv 4 e=%d\n", e);
75             exit(4);
76         }
77         if (strlen(buf[i]) == (sizeof(outbuf1) - outbytesleft) &&
78             memcmp(outbuf1, buf[i], strlen(buf[i])))
79         {
80             printf ("tsticonv 5\n");
81             exit(5);
82         }
83         yaz_iconv_close(cd);
84     }
85 }
86         
87 int main (int argc, char **argv)
88 {
89     dconvert(1, "UTF-8");
90     dconvert(1, "ISO-8859-1");
91     dconvert(1, "UCS4");
92     dconvert(0, "CP865");
93     exit (0);
94 }