8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-29 06:43:03 +01:00
firebird-mirror/src/intl/lc_ascii.c

639 lines
13 KiB
C
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: InterBase International support
* MODULE: lc_ascii.c
* DESCRIPTION: Language Drivers in the binary collation family.
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
2003-02-17 11:37:42 +01:00
#include "firebird.h"
2001-05-23 15:26:42 +02:00
#include "../intl/ldcommon.h"
extern USHORT famasc_key_length();
extern USHORT famasc_string_to_key();
extern SSHORT famasc_compare();
extern USHORT famasc_to_upper();
extern SSHORT famasc_str_to_upper();
extern USHORT famasc_to_lower();
extern SSHORT LC_DOS_nc_mbtowc();
#define FAMILY_ASCII(id_number, name, charset, country) \
cache->texttype_version = IB_LANGDRV_VERSION; \
cache->texttype_type = (id_number); \
cache->texttype_character_set = (charset); \
cache->texttype_country = (country); \
cache->texttype_bytes_per_char = 1; \
cache->texttype_fn_init = (FPTR_SHORT) (name); \
2001-05-23 15:26:42 +02:00
cache->texttype_fn_key_length = famasc_key_length; \
cache->texttype_fn_string_to_key = famasc_string_to_key; \
cache->texttype_fn_compare = famasc_compare; \
cache->texttype_fn_to_upper = famasc_to_upper; \
cache->texttype_fn_to_lower = famasc_to_lower; \
cache->texttype_fn_str_to_upper = famasc_str_to_upper; \
cache->texttype_fn_mbtowc = LC_DOS_nc_mbtowc; \
cache->texttype_collation_table = (BYTE *) NULL; \
cache->texttype_toupper_table = (BYTE *) NULL; \
cache->texttype_tolower_table = (BYTE *) NULL; \
cache->texttype_compress_table = (BYTE *) NULL; \
cache->texttype_expand_table = (BYTE *) NULL; \
cache->texttype_name = (SCHAR *) POSIX;
TEXTTYPE_ENTRY(DOS101_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS437";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, DOS101_init, CS_DOS_437, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(DOS107_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS865";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, DOS107_init, CS_DOS_865, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(DOS160_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS850";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, DOS160_init, CS_DOS_850, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(ISO88591_cp_init)
2001-05-23 15:26:42 +02:00
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, ISO88591_cp_init, CS_ISO8859_1, CC_C);
2001-05-23 15:26:42 +02:00
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY (ISO88592_cp_init)
2002-06-29 19:37:21 +02:00
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_2";
2002-06-29 19:37:21 +02:00
FAMILY_ASCII (parm1, ISO88592_cp_init, CS_ISO8859_2, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY (ISO88593_cp_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_3";
FAMILY_ASCII (parm1, ISO88593_cp_init, CS_ISO8859_3, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY (ISO88594_cp_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_4";
FAMILY_ASCII (parm1, ISO88594_cp_init, CS_ISO8859_4, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY (ISO88595_cp_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_5";
FAMILY_ASCII (parm1, ISO88595_cp_init, CS_ISO8859_5, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY (ISO88596_cp_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_6";
FAMILY_ASCII (parm1, ISO88596_cp_init, CS_ISO8859_6, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY (ISO88597_cp_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_7";
FAMILY_ASCII (parm1, ISO88597_cp_init, CS_ISO8859_7, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY (ISO88598_cp_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_8";
FAMILY_ASCII (parm1, ISO88598_cp_init, CS_ISO8859_8, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY (ISO88599_cp_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_9";
FAMILY_ASCII (parm1, ISO88599_cp_init, CS_ISO8859_9, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY (ISO885913_cp_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_13";
FAMILY_ASCII (parm1, ISO885913_cp_init, CS_ISO8859_13, CC_C);
2002-06-29 19:37:21 +02:00
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(DOS852_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS852";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, DOS852_c0_init, CS_DOS_852, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(DOS857_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS857";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, DOS857_c0_init, CS_DOS_857, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(DOS860_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS860";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, DOS860_c0_init, CS_DOS_860, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(DOS861_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS861";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, DOS861_c0_init, CS_DOS_861, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(DOS863_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS863";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, DOS863_c0_init, CS_DOS_863, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(DOS737_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS737";
FAMILY_ASCII(parm1, DOS737_c0_init, CS_DOS_737, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(DOS775_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS775";
FAMILY_ASCII(parm1, DOS775_c0_init, CS_DOS_775, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(DOS858_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS858";
FAMILY_ASCII(parm1, DOS858_c0_init, CS_DOS_858, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(DOS862_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS862";
FAMILY_ASCII(parm1, DOS862_c0_init, CS_DOS_862, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(DOS864_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS864";
FAMILY_ASCII(parm1, DOS864_c0_init, CS_DOS_864, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(DOS866_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS866";
FAMILY_ASCII(parm1, DOS866_c0_init, CS_DOS_866, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(DOS869_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.DOS869";
FAMILY_ASCII(parm1, DOS869_c0_init, CS_DOS_869, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(CYRL_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.CYRL";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, CYRL_c0_init, CS_CYRL, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(WIN1250_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, WIN1250_c0_init, CS_WIN1250, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(WIN1251_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, WIN1251_c0_init, CS_WIN1251, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(WIN1252_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, WIN1252_c0_init, CS_WIN1252, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(WIN1253_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, WIN1253_c0_init, CS_WIN1253, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(WIN1254_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, WIN1254_c0_init, CS_WIN1254, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(WIN1255_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_5";
FAMILY_ASCII(parm1, WIN1255_c0_init, CS_WIN1255, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(WIN1256_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
FAMILY_ASCII(parm1, WIN1256_c0_init, CS_WIN1256, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
TEXTTYPE_ENTRY(WIN1257_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
FAMILY_ASCII(parm1, WIN1257_c0_init, CS_WIN1257, CC_C);
TEXTTYPE_RETURN;
}
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
TEXTTYPE_ENTRY(NEXT_c0_init)
{
2003-02-13 10:58:19 +01:00
static const ASCII POSIX[] = "C.ISO8859_1";
2001-05-23 15:26:42 +02:00
FAMILY_ASCII(parm1, NEXT_c0_init, CS_NEXT, CC_C);
TEXTTYPE_RETURN;
}
2003-01-23 04:28:45 +01:00
#include "../intl/collations/undef.h"
2001-05-23 15:26:42 +02:00
#undef FAMILY_ASCII
/*
* Generic base for InterBase 4.0 Language Driver - ASCII family (binary
* 8 bit sorting)
*/
#define LANGASCII_MAX_KEY (MAX_KEY)
#define ASCII_SPACE 32 /* ASCII code for space */
#define ASCII_UPPER_A 65 /* ASCII code for 'A' */
#define ASCII_LOWER_A (ASCII_UPPER_A + 32) /* ASCII code for 'a' */
#define ASCII_UPPER_Z 90 /* ASCII code for 'Z' */
#define ASCII_LOWER_Z (ASCII_UPPER_Z + 32) /* ASCII code for 'z' */
#define ASCII7_UPPER(ch) \
((((UCHAR) (ch) >= (UCHAR) ASCII_LOWER_A) && ((UCHAR) (ch) <= (UCHAR) ASCII_LOWER_Z)) \
? (UCHAR) ((ch)-ASCII_LOWER_A+ASCII_UPPER_A) \
: (UCHAR) (ch))
#define ASCII7_LOWER(ch) \
((((UCHAR) (ch) >= (UCHAR) ASCII_UPPER_A) && ((UCHAR) (ch) <= (UCHAR) ASCII_UPPER_Z)) \
? (UCHAR) ((ch)-ASCII_UPPER_A+ASCII_LOWER_A) \
: (UCHAR) (ch))
/*
* key_length (in_len)
*
* For an input string of (in_len) bytes, return the maximum
* key buffer length.
*
* This is used for index buffer allocation within the
* Engine.
*/
USHORT famasc_key_length(TEXTTYPE obj, USHORT inLen)
2001-05-23 15:26:42 +02:00
{
/* assert (inLen <= LANGASCII_MAX_KEY); - possible upper logic error if true */
return (MIN(inLen, LANGASCII_MAX_KEY));
}
/*
*
* Convert a user string to a sequence that will collate bytewise.
*
* For ASCII type collation (codepoint collation) this mearly
* involves stripping the space character off the key.
*
* RETURN:
* Length, in bytes, of returned key
*/
USHORT famasc_string_to_key(TEXTTYPE obj, USHORT iInLen, BYTE *pInChar, USHORT iOutLen, BYTE *pOutChar
, USHORT partial)
2001-05-23 15:26:42 +02:00
{
BYTE *outbuff;
BYTE *inbuff;
assert(pOutChar != NULL);
assert(pInChar != NULL);
assert(iInLen <= LANGASCII_MAX_KEY);
assert(iOutLen <= LANGASCII_MAX_KEY);
assert(iOutLen >= famasc_key_length(obj, iInLen));
/* point inbuff at last character */
inbuff = pInChar + iInLen - 1;
/* skip backwards over all spaces & reset input length */
while ((inbuff >= pInChar) && (*inbuff == ASCII_SPACE))
inbuff--;
iInLen = (inbuff - pInChar + 1);
outbuff = pOutChar;
while (iInLen-- && iOutLen--) {
*outbuff++ = *pInChar++;
}
return (outbuff - pOutChar);
}
static SSHORT all_spaces(BYTE *s, SSHORT len)
2001-05-23 15:26:42 +02:00
{
assert(s != NULL);
while (len-- > 0)
if (*s++ != ASCII_SPACE)
return FALSE;
return TRUE;
}
SSHORT famasc_compare(TEXTTYPE obj, USHORT l1, BYTE *s1, USHORT l2, BYTE *s2)
2001-05-23 15:26:42 +02:00
{
USHORT len;
USHORT i;
assert(obj != NULL);
assert(s1 != NULL);
assert(s2 != NULL);
len = MIN(l1, l2);
for (i = 0; i < len; i++) {
if (s1[i] == s2[i])
continue;
else if (all_spaces(&s1[i], (SSHORT) (l1 - i)))
2001-05-23 15:26:42 +02:00
return -1;
else if (all_spaces(&s2[i], (SSHORT) (l2 - i)))
2001-05-23 15:26:42 +02:00
return 1;
else if (s1[i] < s2[i])
return -1;
else
return 1;
}
if (l1 > len) {
if (all_spaces(&s1[len], (SSHORT) (l1 - len)))
2001-05-23 15:26:42 +02:00
return 0;
return 1;
}
if (l2 > len) {
if (all_spaces(&s2[len], (SSHORT) (l2 - len)))
2001-05-23 15:26:42 +02:00
return 0;
return -1;
}
return (0);
}
USHORT famasc_to_upper(TEXTTYPE obj, BYTE ch)
2001-05-23 15:26:42 +02:00
{
return ((USHORT) ASCII7_UPPER(ch));
}
SSHORT famasc_str_to_upper(TEXTTYPE obj, USHORT iLen, BYTE *pStr, USHORT iOutLen, BYTE *pOutStr)
2001-05-23 15:26:42 +02:00
{
BYTE *p;
assert(pStr != NULL);
assert(pOutStr != NULL);
assert(iLen <= 32000); /* almost certainly an error */
assert(iOutLen <= 32000); /* almost certainly an error */
assert(iOutLen >= iLen);
p = pOutStr;
while (iLen && iOutLen) {
*pOutStr++ = ASCII7_UPPER(*pStr);
pStr++;
iLen--;
iOutLen--;
};
if (iLen != 0)
return (-1);
return (pOutStr - p);
}
USHORT famasc_to_lower(TEXTTYPE obj, BYTE ch)
2001-05-23 15:26:42 +02:00
{
return (ASCII7_LOWER(ch));
}
#undef ASCII_LOWER
#undef ASCII_UPPER
#undef ASCII_LOWER_Z
#undef ASCII_UPPER_Z
#undef ASCII_LOWER_A
#undef ASCII_UPPER_A
#undef ASCII_SPACE
#undef LANGASCII_MAX_KEY