2 * Conversion table for CP850 charset also known as IBM850.
4 * Copyright (C) Alexander Bokovoy 2003
5 * Conversion tables are generated using GNU libc 2.2.5's
6 * localedata/charmaps/IBM850 table and iconvdata/gen-8bit-gap.sh script
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 static const uint16 to_ucs2[256] = {
290 static const struct gap from_idx[] = {
291 /* start, end, idx */
292 { 0x0000, 0x007f, 0 },
293 { 0x00a0, 0x00ff, -32 },
294 { 0x0131, 0x0131, -81 },
295 { 0x0192, 0x0192, -177 },
296 { 0x2017, 0x2017, -7989 },
297 { 0x2500, 0x2502, -9245 },
298 { 0x250c, 0x251c, -9254 },
299 { 0x2524, 0x2524, -9261 },
300 { 0x252c, 0x252c, -9268 },
301 { 0x2534, 0x2534, -9275 },
302 { 0x253c, 0x253c, -9282 },
303 { 0x2550, 0x256c, -9301 },
304 { 0x2580, 0x2588, -9320 },
305 { 0x2591, 0x2593, -9328 },
306 { 0x25a0, 0x25a0, -9340 },
307 { 0xffff, 0xffff, 0 }
309 static const unsigned char from_ucs2[] = {
311 '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
312 '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
313 '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
314 '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f',
315 '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27',
316 '\x28', '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f',
317 '\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37',
318 '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x3e', '\x3f',
319 '\x40', '\x41', '\x42', '\x43', '\x44', '\x45', '\x46', '\x47',
320 '\x48', '\x49', '\x4a', '\x4b', '\x4c', '\x4d', '\x4e', '\x4f',
321 '\x50', '\x51', '\x52', '\x53', '\x54', '\x55', '\x56', '\x57',
322 '\x58', '\x59', '\x5a', '\x5b', '\x5c', '\x5d', '\x5e', '\x5f',
323 '\x60', '\x61', '\x62', '\x63', '\x64', '\x65', '\x66', '\x67',
324 '\x68', '\x69', '\x6a', '\x6b', '\x6c', '\x6d', '\x6e', '\x6f',
325 '\x70', '\x71', '\x72', '\x73', '\x74', '\x75', '\x76', '\x77',
326 '\x78', '\x79', '\x7a', '\x7b', '\x7c', '\x7d', '\x7e', '\x7f',
327 '\xff', '\xad', '\xbd', '\x9c', '\xcf', '\xbe', '\xdd', '\xf5',
328 '\xf9', '\xb8', '\xa6', '\xae', '\xaa', '\xf0', '\xa9', '\xee',
329 '\xf8', '\xf1', '\xfd', '\xfc', '\xef', '\xe6', '\xf4', '\xfa',
330 '\xf7', '\xfb', '\xa7', '\xaf', '\xac', '\xab', '\xf3', '\xa8',
331 '\xb7', '\xb5', '\xb6', '\xc7', '\x8e', '\x8f', '\x92', '\x80',
332 '\xd4', '\x90', '\xd2', '\xd3', '\xde', '\xd6', '\xd7', '\xd8',
333 '\xd1', '\xa5', '\xe3', '\xe0', '\xe2', '\xe5', '\x99', '\x9e',
334 '\x9d', '\xeb', '\xe9', '\xea', '\x9a', '\xed', '\xe8', '\xe1',
335 '\x85', '\xa0', '\x83', '\xc6', '\x84', '\x86', '\x91', '\x87',
336 '\x8a', '\x82', '\x88', '\x89', '\x8d', '\xa1', '\x8c', '\x8b',
337 '\xd0', '\xa4', '\x95', '\xa2', '\x93', '\xe4', '\x94', '\xf6',
338 '\x9b', '\x97', '\xa3', '\x96', '\x81', '\xec', '\xe7', '\x98',
339 '\xd5', '\x9f', '\xf2', '\xc4', '\x00', '\xb3', '\xda', '\x00',
340 '\x00', '\x00', '\xbf', '\x00', '\x00', '\x00', '\xc0', '\x00',
341 '\x00', '\x00', '\xd9', '\x00', '\x00', '\x00', '\xc3', '\xb4',
342 '\xc2', '\xc1', '\xc5', '\xcd', '\xba', '\x00', '\x00', '\xc9',
343 '\x00', '\x00', '\xbb', '\x00', '\x00', '\xc8', '\x00', '\x00',
344 '\xbc', '\x00', '\x00', '\xcc', '\x00', '\x00', '\xb9', '\x00',
345 '\x00', '\xcb', '\x00', '\x00', '\xca', '\x00', '\x00', '\xce',
346 '\xdf', '\x00', '\x00', '\x00', '\xdc', '\x00', '\x00', '\x00',
347 '\xdb', '\xb0', '\xb1', '\xb2', '\xfe',
351 static size_t CP850_push(void *cd, char **inbuf, size_t *inbytesleft,
352 char **outbuf, size_t *outbytesleft)
354 while (*inbytesleft >= 2 && *outbytesleft >= 1) {
358 uint16 ch = SVAL(*inbuf,0);
360 for (i=0; from_idx[i].start != 0xffff; i++) {
361 if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) {
362 ((unsigned char*)(*outbuf))[0] = from_ucs2[from_idx[i].idx+ch];
364 (*outbytesleft) -= 1;
378 if (*inbytesleft == 1) {
383 if (*inbytesleft > 1) {
391 static size_t CP850_pull(void *cd, char **inbuf, size_t *inbytesleft,
392 char **outbuf, size_t *outbytesleft)
394 while (*inbytesleft >= 1 && *outbytesleft >= 2) {
395 *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]];
397 (*outbytesleft) -= 2;
402 if (*inbytesleft > 0) {
410 struct charset_functions CP850_functions = {"CP850", CP850_pull, CP850_push};
412 NTSTATUS charset_CP850_init(void)
414 return smb_register_charset(&CP850_functions);