Diagnostic map tweaks for "Database does not exist"
[yaz-moved-to-github.git] / src / diag_map.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2012 Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file diag_map.c
7  * \brief Implements SRU/Z39.50 diagnostic mappings
8  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <stdlib.h>
14 #include <assert.h>
15 #include <yaz/srw.h>
16
17 /* bib1:srw */
18 static int bib1_srw_map[] = {
19     1, 1,
20     2, 2,
21     3, 48,
22     4, 35,
23     5, 12,
24     6, 38,
25     7, 30,
26     8, 32,
27     9, 29,
28     10, 10,
29     11, 12,
30     11, 23,
31     12, 60,
32     13, 61,
33     13, 62,
34     14, 63,
35     14, 64,
36     14, 65,
37     15, 68,
38     15, 69,
39     16, 70,
40     17, 70,
41     18, 50,
42     19, 55,
43     20, 56, 
44     21, 52,
45     22, 50,
46     23, 3,
47     24, 66,
48     25, 66,
49     26, 66,
50     27, 51,
51     28, 52,
52     29, 52,
53     30, 51,
54     31, 57,
55     32, 58,
56     33, 59,
57     100, 1, /* bad map */
58     101, 3,
59     102, 3,
60     103, 3,
61     104, 3,
62     105, 3, 
63     106, 66,
64     107, 11,
65     108, 10,
66     108, 13,
67     108, 14,
68     108, 25,
69     108, 26,
70     108, 27,
71     108, 45,
72         
73     109, 235,
74     110, 37,
75     111, 1,
76     112, 58,
77     113, 10,
78     114, 16,
79     115, 16,
80     116, 16,
81     117, 19,
82     117, 20,
83     118, 22,
84     119, 32,
85     119, 31,
86     120, 28,
87     121, 15,
88     122, 32,
89     123, 22,
90     123, 17,
91     123, 18,
92     124, 24,
93     125, 36,
94     126, 36, 
95     127, 36,
96     128, 51,
97     129, 39,
98     130, 43,
99     131, 40,
100     132, 42,
101     201, 44,
102     201, 33,
103     201, 34,
104     202, 41,
105     203, 43,
106     205, 1,  /* bad map */
107     206, 1,  /* bad map */
108     207, 89,
109     208, 1,  /* bad map */
110     209, 80,
111     210, 80,
112     210, 81,
113     211, 84,
114     212, 85,
115     213, 92,
116     214, 90,
117     215, 91,
118     216, 92,
119     217, 63,
120     218, 1,  /* bad map */
121     219, 1,  /* bad map */
122     220, 1,  /* bad map */
123     221, 1,  /* bad map */
124     222, 3,
125     223, 1,  /* bad map */
126     224, 1,  /* bad map */
127     225, 1,  /* bad map */
128     226, 1,  /* bad map */
129     227, 66,
130     228, 1,  /* bad map */
131     229, 36,
132     230, 83,
133     231, 89,
134     232, 1,
135     233, 1, /* bad map */
136     234, 1, /* bad map */
137     235, 235,
138     236, 3, 
139     237, 82,
140     238, 67,
141     239, 66,
142     240, 1, /* bad map */
143     241, 1, /* bad map */
144     242, 70,
145     243, 1, /* bad map */
146     244, 66,
147     245, 10,
148     246, 10,
149     247, 10,
150     1001, 1, /* bad map */
151     1002, 1, /* bad map */
152     1003, 1, /* bad map */
153     1004, 1, /* bad map */
154     1005, 1, /* bad map */
155     1006, 1, /* bad map */
156     1007, 100,
157     1008, 1, 
158     1009, 1,
159     1010, 3,
160     1011, 3,
161     1012, 3,
162     1013, 3,
163     1014, 3,
164     1015, 3,
165     1015, 3,
166     1016, 3,
167     1017, 3,
168     1018, 2,
169     1019, 2,
170     1020, 2,
171     1021, 3,
172     1022, 3,
173     1023, 3,
174     1024, 16,
175     1025, 3,
176     1026, 64,
177     1027, 1,
178     1028, 65,
179     1029, 1,
180     1040, 1,
181     /* 1041-1065 */
182     1066, 66,
183     1066, 67,
184     0
185 };
186
187 /*
188  * This array contains overrides for when the first occurrence of a
189  * particular SRW error in the array above does not correspond with
190  * the best back-translation of that SRW error.
191  */
192 static int srw_bib1_map[] = {
193     10, 108,
194     66, 238,
195     235, 235,
196     /* No doubt there are many more */
197     0
198 };
199
200
201 int yaz_diag_bib1_to_srw (int code)
202 {
203     const int *p = bib1_srw_map;
204     while (*p)
205     {
206         if (code == p[0])
207             return p[1];
208         p += 2;
209     }
210     return 1;
211 }
212
213 int yaz_diag_srw_to_bib1(int code)
214 {
215     /* Check explicit reverse-map first */
216     const int *p = srw_bib1_map;
217     while (*p)
218     {
219         if (code == p[0])
220             return p[1];
221         p += 2;
222     }
223
224     /* Fall back on reverse lookup in main map */
225     p = bib1_srw_map;
226     while (*p)
227     {
228         if (code == p[1])
229             return p[0];
230         p += 2;
231     }
232     return 1;
233 }
234
235 /*
236  * Local variables:
237  * c-basic-offset: 4
238  * c-file-style: "Stroustrup"
239  * indent-tabs-mode: nil
240  * End:
241  * vim: shiftwidth=4 tabstop=8 expandtab
242  */
243