diff --git a/AI.md b/AI.md index 24c98d6..e22a644 100644 --- a/AI.md +++ b/AI.md @@ -2496,3 +2496,34 @@ logs/archives are usually copied or uploaded later by a normal desktop user. installed as public API. No MARS callsites are switched yet; this is a prerequisite for replacing the older hand-written MARS Unicode/string code piece by piece with NSS-compatible primitives. + +- `0413` switches the NSS case-map globals to the external + `third_party/unicodeTables` submodule (`TAB/unicodeTables.c`). That submodule + is project-managed and currently tracks master; it generates `NSSUniToLower[]` + and `NSSUniToUpper[]` from Unicode UCD data instead of copying Novell + `shared/sdk/unitables/*.tab` files. Any future Unicode/codepage tables belong + there first, then MARS-NWE consumes the generated output. + +- `0414` and `0415` import NSS UTF-8 conversion helpers that need no tables: + single-character UTF-8 decode (`utf8ToUniChar.c`, `utf8LenToUniChar.c`) and + whole-string UTF-8/Unicode conversion (`uni2utf.c`, `utf2uni.c`). + +- `0416` imports NSS Unicode parser/override helpers (`unicodeParse.c`) and + `getNssUnicodeVersion.c`. It also exports `NSSUnicodeFF` and + `NSSUnicodeMacFF` as temporary 0xff sentinel values. Keep those on the same + table/runtime watchlist as the case maps; the final values should come from + DOS/Mac codepage tables or derived converter startup, not from private MARS + conversion state. + +- `0417` imports `getMacCodePageName.c` and exports NSS Unicode startup/shutdown + entry points plus `MacintoshCodePageName`. The name remains NULL until real + Mac/DOS codepage table/runtime support is imported via the Unicode tables + submodule. + +- `0418` imports the NSS byte/Unicode and Mac byte/Unicode conversion entry + points (`ByteToUnicode.c`, `LenByteToUnicode.c`, `MacByteToUnicode.c`, + `LenMacByteToUnicode.c`, `UnicodeToByte.c`, `UnicodeToMacByte.c`, + `UnicodeToUntermByte.c`, `UnicodeToUntermMacByte.c`) directly into + `libnwcore`. The NSS converter state globals are present but intentionally + empty, so these APIs return `zERR_UNICODE_INVALID_CONVERSION_TYPE` until the + real codepage tables/runtime are added from `mars-unicode-tables`. diff --git a/include/core/xUnicode.h b/include/core/xUnicode.h index 860a919..cca5b10 100644 --- a/include/core/xUnicode.h +++ b/include/core/xUnicode.h @@ -299,7 +299,7 @@ extern STATUS LB_UTF8LenToUniChar( #define NSS_UNI_CONVERSION_RAW 2 /* No wildCard handling, noMap -> [xxxx] */ #define NSS_UNI_CONVERSION_WILD_DOS 3 /* Default NSS converter type with default wildcard handling, DOS FF handling */ -#ifdef _NSS_INTERNAL_ +#if defined(_NSS_INTERNAL_) || defined(MARS_NWE_NWCORE_UNICODE) # define NSS_UNI_CONVERSION_LAST_DEFINED 3 /* Highest Number of pre-defined types */ # define NSS_UNI_CONVERSION_COUNT 16 /* Max registerable converter types */ diff --git a/src/core/ByteToUnicode.c b/src/core/ByteToUnicode.c new file mode 100644 index 0000000..e044116 --- /dev/null +++ b/src/core/ByteToUnicode.c @@ -0,0 +1,140 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routine to convert ascii to unicode_t + | + | 9/14/01: Instead of calling system routines for unicode conversion, NSS + | has created is own set of conversion functions that are MP safe and fast. ++-------------------------------------------------------------------------*/ +#include +#include +#include + + +/************************************************************************** + * This converts a NULL terminated ASCII string into a NULL terminated + * UNICODE string. This guarentees a null terminated UNICODE string, even + * if there is an error. + ***************************************************************************/ +STATUS LB_ByteToUnicode( + NINT conversionType, /* type of conversion to do */ + unicode_t *unicodeOutput, /* Buffer for resulting Unicode*/ + NINT outputBufferLen, /* Length of output buffer in unicode characters*/ + CONST char *byteInput, /* Buffer for input bytes*/ + NINT *retActualLength) /* may be NULL, returns length of unicode_t string*/ +{ + BYTE *p; + unicode_t *u; + STATUS status; + unicode_t *singleByteToUnicode; + unicode_t *doubleByteToUnicode; + + + if ((conversionType > NSS_UNI_CONVERSION_COUNT) || + (conversionType < 1) || + (!NSSUnicodeConverterDefined[conversionType])) + { + status = zERR_UNICODE_INVALID_CONVERSION_TYPE; + goto error; + } + zASSERT(NSSSingleByteToUnicodeTable[conversionType] != NULL); + zASSERT(outputBufferLen > 0); + singleByteToUnicode = NSSSingleByteToUnicodeTable[conversionType]; + doubleByteToUnicode = NSSDoubleByteToUnicodeTable[conversionType]; + + u = unicodeOutput; + --outputBufferLen; /* leave a space for null terminator */ + + for (p = (BYTE *)byteInput; *p; ++p) + { + if (outputBufferLen == 0) + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + *u = singleByteToUnicode[*p]; + + if (!*u) /* check if a single byte is a valid unicode */ + { + if (*(p + 1)) + { + *u = doubleByteToUnicode[*p * 256 + *(p + 1)]; + } + if (!*u) /* check if double bytes is a valid unicode */ + { + /* FF is a weird beast. In the LONG namespace, it can be + * a beginning of a double byte wildcard sequence, or it can + * be a single byte character. If we get to this error point, + * and the character is a single byte FF, just manually + * translate it as a single byte. + */ + if ((*p == 0xFF) && + (!IS_INVALID_UNICODE_CHAR(NSSUnicodeFF))) + { + *u = NSSUnicodeFF; + --p; /* decrement because we are only skipping one char */ + } + else + { +// zASSERT("Invalid byte characters" == NULL); + status = zERR_UNICODE_NON_MAPPABLE_CHAR; + goto error; + } + } + ++p; + } + ++u; + --outputBufferLen; + } + if (retActualLength) + { + /* + * This returns number of unicode characters (not bytes). Since + * the pointers are pointers to unicode_t this works without dividing + * by sizeof(unicode_t) + */ + *retActualLength = u - unicodeOutput; + } + *u = 0; + + return zOK; + +error: + if (retActualLength) + { + *retActualLength = 0; + } + *unicodeOutput = 0; /* return NULL string */ + return status; +} diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1836059..cabe463 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -101,6 +101,14 @@ configure_file( COPYONLY) set(NWCORE_IMPORTED_NSS_SOURCES + ByteToUnicode.c + LenByteToUnicode.c + LenMacByteToUnicode.c + MacByteToUnicode.c + UnicodeToByte.c + UnicodeToMacByte.c + UnicodeToUntermByte.c + UnicodeToUntermMacByte.c bitmap.c bit.c crc.c diff --git a/src/core/LenByteToUnicode.c b/src/core/LenByteToUnicode.c new file mode 100644 index 0000000..f7cd575 --- /dev/null +++ b/src/core/LenByteToUnicode.c @@ -0,0 +1,141 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routine to convert ascii to unicode_t + | + | 9/14/01: Instead of calling system routines for unicode conversion, NSS + | has created is own set of conversion functions that are MP safe and fast. + +-------------------------------------------------------------------------*/ +#include +#include +#include + +/************************************************************************** + * This will convert an unterminated ASCII string with a length into a + * NULL terminated UNICODE string. This guarentees a null terminated + * string, even if there is an error. + ***************************************************************************/ +STATUS LB_LenByteToUnicode( + NINT conversionType, /* type of conversion to do */ + unicode_t *unicodeOutput, /* Buffer for resulting Unicode*/ + NINT outputBufferLen, /* Length of output buffer*/ + CONST char *byteInput, /* Buffer for input bytes*/ + NINT inLength, /* length of input string */ + NINT *retActualLength) /* may be NULL, return unicode_t string length*/ +{ + unicode_t *u; + BYTE *p; + STATUS status; + unicode_t *singleByteToUnicode; + unicode_t *doubleByteToUnicode; + + if ((conversionType > NSS_UNI_CONVERSION_COUNT) || + (conversionType < 1) || + (!NSSUnicodeConverterDefined[conversionType])) + { + status = zERR_UNICODE_INVALID_CONVERSION_TYPE; + goto error; + } + zASSERT(NSSSingleByteToUnicodeTable[conversionType] != NULL); + singleByteToUnicode = NSSSingleByteToUnicodeTable[conversionType]; + doubleByteToUnicode = NSSDoubleByteToUnicodeTable[conversionType]; + + p = (BYTE *)byteInput; + u = unicodeOutput; + --outputBufferLen; /* leave a space for null terminator */ + + for (;inLength; --inLength) + { + if (outputBufferLen == 0) + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + *u = singleByteToUnicode[*p]; + + if (!*u) /* check if a single byte is a valid unicode */ + { + if (inLength >= 2) + { + *u = doubleByteToUnicode[*p * 256 + *(p + 1)]; + } + if (!*u) /* check if double bytes is a valid unicode */ + { + /* FF is a weird beast. In the LONG namespace, it can be + * a beginning of a double byte wildcard sequence, or it can + * be a single byte character. If we get to this error point, + * and the character is a single byte FF, just manually + * translate it as a single byte. + */ + if ((*p == 0xFF) && + (!IS_INVALID_UNICODE_CHAR(NSSUnicodeFF))) + { + *u = NSSUnicodeFF; + --p; /* decrement because we are only skipping one char */ + ++inLength; /*increment because only skipping one char */ + } + else + { + zASSERT("Invalid byte characters" == NULL); + status = zERR_UNICODE_NON_MAPPABLE_CHAR; + goto error; + } + } + ++p; + --inLength; + } + ++p; + ++u; + --outputBufferLen; + } + if (retActualLength) + { + /* + * This returns number of unicode characters (not bytes). Since + * the pointers are pointers to unicode_t this works without dividing + * by sizeof(unicode_t) + */ + *retActualLength = u - unicodeOutput; + } + *u = 0; + return zOK; + +error: + if (retActualLength) + { + *retActualLength = 0; + } + *unicodeOutput = 0; /* return NULL string */ + return status; +} diff --git a/src/core/LenMacByteToUnicode.c b/src/core/LenMacByteToUnicode.c new file mode 100644 index 0000000..eb0b9f2 --- /dev/null +++ b/src/core/LenMacByteToUnicode.c @@ -0,0 +1,137 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routine to convert MAC ascii to unicode_t + | + +-------------------------------------------------------------------------*/ +#include +#include +#include + +/************************************************************************** + * This will convert an unterminated ASCII string with a length into a + * NULL terminated UNICODE string. This guarentees a null terminated + * string, even if there is an error. + ***************************************************************************/ +STATUS LB_LenMacByteToUnicode( + NINT conversionType, /* type of conversion to do */ + unicode_t *unicodeOutput, /* Buffer for resulting Unicode*/ + NINT outputBufferLen, /* Length of output buffer*/ + CONST char *byteInput, /* Buffer for input bytes*/ + NINT inLength, /* length of input string */ + NINT *retActualLength) /* may be NULL, return unicode_t string length*/ +{ + unicode_t *u; + BYTE *p; + STATUS status; + unicode_t *singleByteToUnicode; + unicode_t *doubleByteToUnicode; + + if (conversionType != NSS_UNI_CONVERSION_RAW) + { + status = zERR_UNICODE_INVALID_CONVERSION_TYPE; + goto error; + } + zASSERT(NSSMacSingleByteToUnicodeTable != NULL); + singleByteToUnicode = NSSMacSingleByteToUnicodeTable; + doubleByteToUnicode = NSSMacDoubleByteToUnicodeTable; + + p = (BYTE *)byteInput; + u = unicodeOutput; + --outputBufferLen; /* leave a space for null terminator */ + + for (;inLength; --inLength) + { + if (outputBufferLen == 0) + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + *u = singleByteToUnicode[*p]; + + if (!*u) /* check if a single byte is a valid unicode */ + { + if (inLength >= 2) + { + *u = doubleByteToUnicode[*p * 256 + *(p + 1)]; + } + if (!*u) /* check if double bytes is a valid unicode */ + { + /* FF is a weird beast. In the LONG namespace, it can be + * a beginning of a double byte wildcard sequence, or it can + * be a single byte character. If we get to this error point, + * and the character is a single byte FF, just manually + * translate it as a single byte. + */ + if ((*p == 0xFF) && + (!IS_INVALID_UNICODE_CHAR(NSSUnicodeMacFF))) + { + *u = NSSUnicodeMacFF; + --p; /* decrement because we are only skipping one char */ + ++inLength; /*increment because only skipping one char */ + } + else + { + zASSERT("Invalid byte characters" == NULL); + status = zERR_UNICODE_NON_MAPPABLE_CHAR; + goto error; + } + } + ++p; + --inLength; + } + ++p; + ++u; + --outputBufferLen; + } + if (retActualLength) + { + /* + * This returns number of unicode characters (not bytes). Since + * the pointers are pointers to unicode_t this works without dividing + * by sizeof(unicode_t) + */ + *retActualLength = u - unicodeOutput; + } + *u = 0; + return zOK; + +error: + if (retActualLength) + { + *retActualLength = 0; + } + *unicodeOutput = 0; /* return NULL string */ + return status; +} diff --git a/src/core/MacByteToUnicode.c b/src/core/MacByteToUnicode.c new file mode 100644 index 0000000..cb590ce --- /dev/null +++ b/src/core/MacByteToUnicode.c @@ -0,0 +1,136 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routine to convert MAC ascii to unicode_t + | ++-------------------------------------------------------------------------*/ +#include +#include +#include + + +/************************************************************************** + * This converts a NULL terminated ASCII string into a NULL terminated + * UNICODE string. This guarentees a null terminated UNICODE string, even + * if there is an error. + ***************************************************************************/ +STATUS LB_MacByteToUnicode( + NINT conversionType, /* type of conversion to do */ + unicode_t *unicodeOutput, /* Buffer for resulting Unicode*/ + NINT outputBufferLen, /* Length of output buffer in unicode characters*/ + CONST char *byteInput, /* Buffer for input bytes*/ + NINT *retActualLength) /* may be NULL, returns length of unicode_t string*/ +{ + BYTE *p; + unicode_t *u; + STATUS status; + unicode_t *singleByteToUnicode; + unicode_t *doubleByteToUnicode; + + + if (conversionType != NSS_UNI_CONVERSION_RAW) + { + status = zERR_UNICODE_INVALID_CONVERSION_TYPE; + goto error; + } + zASSERT(NSSMacSingleByteToUnicodeTable != NULL); + zASSERT(outputBufferLen > 0); + singleByteToUnicode = NSSMacSingleByteToUnicodeTable; + doubleByteToUnicode = NSSMacDoubleByteToUnicodeTable; + + u = unicodeOutput; + --outputBufferLen; /* leave a space for null terminator */ + + for (p = (BYTE *)byteInput; *p; ++p) + { + if (outputBufferLen == 0) + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + *u = singleByteToUnicode[*p]; + + if (!*u) /* check if a single byte is a valid unicode */ + { + if (*(p + 1)) + { + *u = doubleByteToUnicode[*p * 256 + *(p + 1)]; + } + if (!*u) /* check if double bytes is a valid unicode */ + { + /* FF is a weird beast. In the LONG namespace, it can be + * a beginning of a double byte wildcard sequence, or it can + * be a single byte character. If we get to this error point, + * and the character is a single byte FF, just manually + * translate it as a single byte. + */ + if ((*p == 0xFF) && + (!IS_INVALID_UNICODE_CHAR(NSSUnicodeMacFF))) + { + *u = NSSUnicodeMacFF; + --p; /* decrement because we are only skipping one char */ + } + else + { +// zASSERT("Invalid byte characters" == NULL); + status = zERR_UNICODE_NON_MAPPABLE_CHAR; + goto error; + } + } + ++p; + } + ++u; + --outputBufferLen; + } + if (retActualLength) + { + /* + * This returns number of unicode characters (not bytes). Since + * the pointers are pointers to unicode_t this works without dividing + * by sizeof(unicode_t) + */ + *retActualLength = u - unicodeOutput; + } + *u = 0; + + return zOK; + +error: + if (retActualLength) + { + *retActualLength = 0; + } + *unicodeOutput = 0; /* return NULL string */ + return status; +} diff --git a/src/core/UnicodeToByte.c b/src/core/UnicodeToByte.c new file mode 100644 index 0000000..26a0e28 --- /dev/null +++ b/src/core/UnicodeToByte.c @@ -0,0 +1,122 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routine to convert ascii to unicode_t + | + | 9/14/01: Instead of calling system routines for unicode conversion, NSS + | has created is own set of conversion functions that are MP safe and fast. + +-------------------------------------------------------------------------*/ +#include +#include +#include + + +/************************************************************************** + * This converts a NULL terminated UNICODE string into a NULL terminated + * ASCII string. This gurantees a null terminated ascii string even if + * an error occurs. + ***************************************************************************/ +STATUS LB_UnicodeToByte( + NINT conversionType, + char *byteOutput, + NINT outputBufferLen, + CONST unicode_t *unicodeInput, + NINT *retActualLength) +{ + BYTE *p; + unicode_t *u; + BYTE *unicodeToByte; + STATUS status; + + if ((conversionType > NSS_UNI_CONVERSION_COUNT) || + (conversionType < 1) || + (!NSSUnicodeConverterDefined[conversionType])) + { + status = zERR_UNICODE_INVALID_CONVERSION_TYPE; + goto error; + } + zASSERT(NSSUnicodeToByteTable[conversionType] != NULL); + zASSERT(outputBufferLen > 0); + unicodeToByte = NSSUnicodeToByteTable[conversionType]; + + p = (BYTE *)byteOutput; + --outputBufferLen; /* leave a space for null terminator */ + + for (u = unicodeInput; *u; u++) + { + if (outputBufferLen == 0) + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + if (!IS_UNICODE_MAPPABLE_TO_ASCII(*u)) + { +// zASSERT("Invalid unicode characters" == NULL); + status = zERR_UNICODE_NON_MAPPABLE_CHAR; + goto error; + } + + *p++ = unicodeToByte[*u * 2]; + --outputBufferLen; + + if (IS_UNICODE_DOUBLE_BYTE_ASCII(*u)) + { + if (outputBufferLen) + { + *p++ = unicodeToByte[*u * 2 + 1]; + --outputBufferLen; + } + else + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + } + + } + if (retActualLength) + { + *retActualLength = (NINT)(p - (BYTE *)byteOutput); + } + *p = '\0'; + return zOK; + +error: + *byteOutput = '\0'; /* return NULL string */ + if (retActualLength) + { + *retActualLength = 0; + } + return status; +} diff --git a/src/core/UnicodeToMacByte.c b/src/core/UnicodeToMacByte.c new file mode 100644 index 0000000..03913d1 --- /dev/null +++ b/src/core/UnicodeToMacByte.c @@ -0,0 +1,120 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routine to convert ascii to unicode_t + | + | 9/14/01: Instead of calling system routines for unicode conversion, NSS + | has created is own set of conversion functions that are MP safe and fast. + +-------------------------------------------------------------------------*/ +#include +#include +#include + + +/************************************************************************** + * This converts a NULL terminated UNICODE string into a NULL terminated + * ASCII string. This gurantees a null terminated ascii string even if + * an error occurs. + ***************************************************************************/ +STATUS LB_UnicodeToMacByte( + NINT conversionType, + char *byteOutput, + NINT outputBufferLen, + CONST unicode_t *unicodeInput, + NINT *retActualLength) +{ + BYTE *p; + unicode_t *u; + BYTE *unicodeToByte; + STATUS status; + + if (conversionType != NSS_UNI_CONVERSION_RAW) + { + status = zERR_UNICODE_INVALID_CONVERSION_TYPE; + goto error; + } + zASSERT(NSSMacUnicodeToByteTable != NULL); + zASSERT(outputBufferLen > 0); + unicodeToByte = NSSMacUnicodeToByteTable; + + p = (BYTE *)byteOutput; + --outputBufferLen; /* leave a space for null terminator */ + + for (u = unicodeInput; *u; u++) + { + if (outputBufferLen == 0) + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + if (!IS_UNICODE_MAPPABLE_TO_MAC_ASCII(*u)) + { +// zASSERT("Invalid unicode characters" == NULL); + status = zERR_UNICODE_NON_MAPPABLE_CHAR; + goto error; + } + + *p++ = unicodeToByte[*u * 2]; + --outputBufferLen; + + if (IS_UNICODE_DOUBLE_BYTE_MAC_ASCII(*u)) + { + if (outputBufferLen) + { + *p++ = unicodeToByte[*u * 2 + 1]; + --outputBufferLen; + } + else + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + } + + } + if (retActualLength) + { + *retActualLength = (NINT)(p - (BYTE *)byteOutput); + } + *p = '\0'; + return zOK; + +error: + *byteOutput = '\0'; /* return NULL string */ + if (retActualLength) + { + *retActualLength = 0; + } + return status; +} diff --git a/src/core/UnicodeToUntermByte.c b/src/core/UnicodeToUntermByte.c new file mode 100644 index 0000000..7b275d4 --- /dev/null +++ b/src/core/UnicodeToUntermByte.c @@ -0,0 +1,115 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routine to convert ascii to unicode_t + | + | 9/14/01: Instead of calling system routines for unicode conversion, NSS + | has created is own set of conversion functions that are MP safe and fast. + +-------------------------------------------------------------------------*/ +#include +#include +#include + + +/************************************************************************** + * Converts a NULL terminated unicode_t string into an unterminated + * (meaning no NULL) ASCII string with a return length. This is used + * internally to handle length preceded strings. + ***************************************************************************/ +STATUS LB_UnicodeToUntermByte( + NINT conversionType, + char *byteOutput, + NINT outputBufferLen, + CONST unicode_t *unicodeInput, + NINT *retActualLength) +{ + BYTE *p; + unicode_t *u; + BYTE *unicodeToByte; + STATUS status; + + if ((conversionType > NSS_UNI_CONVERSION_COUNT) || + (conversionType < 1) || + (!NSSUnicodeConverterDefined[conversionType])) + { + status = zERR_UNICODE_INVALID_CONVERSION_TYPE; + goto error; + } + zASSERT(NSSUnicodeToByteTable[conversionType] != NULL); + zASSERT(retActualLength != NULL); + unicodeToByte = NSSUnicodeToByteTable[conversionType]; + + p = (BYTE *)byteOutput; + + for (u = unicodeInput; *u; ++u) + { + zASSERT(((signed)outputBufferLen) >= 0); + if (outputBufferLen == 0) + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + if (!IS_UNICODE_MAPPABLE_TO_ASCII(*u)) + { + zASSERT("Invalid unicode characters" == NULL); + status = zERR_UNICODE_NON_MAPPABLE_CHAR; + goto error; + } + + *p++ = unicodeToByte[*u * 2]; + --outputBufferLen; + + if (IS_UNICODE_DOUBLE_BYTE_ASCII(*u)) + { + if (outputBufferLen) + { + *p++ = unicodeToByte[*u * 2 + 1]; + --outputBufferLen; + } + else + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + } + } + *retActualLength = (NINT)(p - (BYTE *)byteOutput); + + return zOK; + +error: + *retActualLength = 0; + *byteOutput = 0; /* return NULL string */ + return status; +} diff --git a/src/core/UnicodeToUntermMacByte.c b/src/core/UnicodeToUntermMacByte.c new file mode 100644 index 0000000..96ace75 --- /dev/null +++ b/src/core/UnicodeToUntermMacByte.c @@ -0,0 +1,111 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routine to convert MAC ascii to unicode_t + | + +-------------------------------------------------------------------------*/ +#include +#include +#include + + +/************************************************************************** + * Converts a NULL terminated unicode_t string into an unterminated + * (meaning no NULL) ASCII string with a return length. This is used + * internally to handle length preceded strings. + ***************************************************************************/ +STATUS LB_UnicodeToUntermMacByte( + NINT conversionType, + char *byteOutput, + NINT outputBufferLen, + CONST unicode_t *unicodeInput, + NINT *retActualLength) +{ + BYTE *p; + unicode_t *u; + BYTE *unicodeToByte; + STATUS status; + + if (conversionType != NSS_UNI_CONVERSION_RAW) + { + status = zERR_UNICODE_INVALID_CONVERSION_TYPE; + goto error; + } + zASSERT(NSSMacUnicodeToByteTable != NULL); + zASSERT(retActualLength != NULL); + unicodeToByte = NSSMacUnicodeToByteTable; + + p = (BYTE *)byteOutput; + + for (u = unicodeInput; *u; ++u) + { + zASSERT(((signed)outputBufferLen) >= 0); + if (outputBufferLen == 0) + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + if (!IS_UNICODE_MAPPABLE_TO_MAC_ASCII(*u)) + { + zASSERT("Invalid unicode characters" == NULL); + status = zERR_UNICODE_NON_MAPPABLE_CHAR; + goto error; + } + + *p++ = unicodeToByte[*u * 2]; + --outputBufferLen; + + if (IS_UNICODE_DOUBLE_BYTE_MAC_ASCII(*u)) + { + if (outputBufferLen) + { + *p++ = unicodeToByte[*u * 2 + 1]; + --outputBufferLen; + } + else + { + status = zERR_BUFFER_TOO_SMALL; + goto error; + } + } + } + *retActualLength = (NINT)(p - (BYTE *)byteOutput); + + return zOK; + +error: + *retActualLength = 0; + *byteOutput = 0; /* return NULL string */ + return status; +} diff --git a/src/core/unicodeInit.c b/src/core/unicodeInit.c index 4a3c8ec..00815b3 100644 --- a/src/core/unicodeInit.c +++ b/src/core/unicodeInit.c @@ -43,6 +43,27 @@ unicode_t NSSUnicodeMacFF = ASCII_WILDCARD_BREAK; */ BYTE *MacintoshCodePageName = NULL; +/* + * Converter runtime storage imported from NSS unicodeInit.c. The full NSS + * codepage startup has not been imported yet, so these tables intentionally + * remain empty/undefined until a later patch wires DOS/Mac codepage data from + * the external unicodeTables submodule. Imported conversion entry points then + * return zERR_UNICODE_INVALID_CONVERSION_TYPE instead of using private MARS + * conversion state. + */ +BOOL NSSUnicodeConverterDefined[NSS_UNI_CONVERSION_COUNT] = {FALSE}; +UNI_OverrideByte2UniFunc_t NSSUnicodeOverrideByte2Uni[NSS_UNI_CONVERSION_COUNT] = {0}; +UNI_OverrideUni2ByteFunc_t NSSUnicodeOverrideUni2Byte[NSS_UNI_CONVERSION_COUNT] = {0}; +unicode_t *NSSSingleByteToUnicodeTable[NSS_UNI_CONVERSION_COUNT] = {0}; +unicode_t *NSSDoubleByteToUnicodeTable[NSS_UNI_CONVERSION_COUNT] = {0}; +unicode_t *NSSMacSingleByteToUnicodeTable = NULL; +unicode_t *NSSMacDoubleByteToUnicodeTable = NULL; +BYTE *NSSUnicodeToByteTable[NSS_UNI_CONVERSION_COUNT] = {0}; +BYTE *NSSMacUnicodeToByteTable = NULL; +NINT NSSUnicodeMappableToAsciiBitMap[(0x10000 + BITS_PER_NINT - 1) / BITS_PER_NINT] = {0}; +NINT NSSUnicodeIsDoubleByteAsciiBitMap[(0x10000 + BITS_PER_NINT - 1) / BITS_PER_NINT] = {0}; +NINT NSSUnicodeMappableToMacAsciiBitMap[(0x10000 + BITS_PER_NINT - 1) / BITS_PER_NINT] = {0}; +NINT NSSUnicodeIsDoubleByteMacAsciiBitMap[(0x10000 + BITS_PER_NINT - 1) / BITS_PER_NINT] = {0}; /* * NSS normally fills NSSUniToLower[]/NSSUniToUpper[] during