From e83031c84de410cb19c96a4084b95f26619ce5a9 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Thu, 28 Aug 2003 17:16:27 +0000 Subject: Refactor charset plugins a bit and add CP437 module. Now all 8-bit charsets with gaps (not all symbols defined) could be produced through one macro -- SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CHARSETNAME) within source file with three charset tables. Full source code for such modules can be generated by source/script/gen-8bit-gap.sh script which was taken from GNU libc and changed slightly to follow our data types and structure. (This used to be commit 37042c7bc0f349370e93e4bed37d8fa371013247) --- source3/modules/CP850.c | 76 ++----------------------------------------------- 1 file changed, 3 insertions(+), 73 deletions(-) (limited to 'source3/modules/CP850.c') diff --git a/source3/modules/CP850.c b/source3/modules/CP850.c index 1805a1e11b..0adfd24def 100644 --- a/source3/modules/CP850.c +++ b/source3/modules/CP850.c @@ -2,8 +2,9 @@ * Conversion table for CP850 charset also known as IBM850. * * Copyright (C) Alexander Bokovoy 2003 + * * Conversion tables are generated using GNU libc 2.2.5's - * localedata/charmaps/IBM850 table and iconvdata/gen-8bit-gap.sh script + * localedata/charmaps/IBM850 table and source/script/gen-8bit-gap.sh script * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,13 +23,6 @@ #include "includes.h" -struct gap -{ - uint16 start; - uint16 end; - int32 idx; -}; - static const uint16 to_ucs2[256] = { [0x01] = 0x0001, [0x02] = 0x0002, @@ -347,69 +341,5 @@ static const unsigned char from_ucs2[] = { '\xdb', '\xb0', '\xb1', '\xb2', '\xfe', }; +SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CP850) -static size_t CP850_push(void *cd, char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) -{ - while (*inbytesleft >= 2 && *outbytesleft >= 1) { - int i; - int done = 0; - - uint16 ch = SVAL(*inbuf,0); - - for (i=0; from_idx[i].start != 0xffff; i++) { - if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) { - ((unsigned char*)(*outbuf))[0] = from_ucs2[from_idx[i].idx+ch]; - (*inbytesleft) -= 2; - (*outbytesleft) -= 1; - (*inbuf) += 2; - (*outbuf) += 1; - done = 1; - break; - } - } - if (!done) { - errno = EINVAL; - return -1; - } - - } - - if (*inbytesleft == 1) { - errno = EINVAL; - return -1; - } - - if (*inbytesleft > 1) { - errno = E2BIG; - return -1; - } - - return 0; -} - -static size_t CP850_pull(void *cd, char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) -{ - while (*inbytesleft >= 1 && *outbytesleft >= 2) { - *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]]; - (*inbytesleft) -= 1; - (*outbytesleft) -= 2; - (*inbuf) += 1; - (*outbuf) += 2; - } - - if (*inbytesleft > 0) { - errno = E2BIG; - return -1; - } - - return 0; -} - -struct charset_functions CP850_functions = {"CP850", CP850_pull, CP850_push}; - -NTSTATUS charset_CP850_init(void) -{ - return smb_register_charset(&CP850_functions); -} -- cgit