home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 November
/
VPR9611B.ISO
/
vabasic
/
ntclnt.exe
/
DISK8
/
data.8
/
datab
/
INCLUDE
/
VNLS.H
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-29
|
13KB
|
458 lines
/*****************************************************************************
*** $Source: /rcs/crcs/general/vnls.h,v $
*** Checked int by: $Author: clement $
*** $Date: 1996/07/03 15:09:07 $
*** $Revision: 1.32 $
*****************************************************************************
*** ***
*** Copyright (c) 1994, Visual Edge Software Ltd. ***
*** Copyright (c) 1994, International Business Machines Corp. ***
*** ***
*** All rights reserved. This notice is intended as a precaution ***
*** against inadvertent publication, and shall not be deemed to con- ***
*** stitute an acknowledgment that publication has occurred nor to ***
*** imply any waiver of confidentiality. The year included in the ***
*** notice is the year of the creation of the work. ***
*** ***
*****************************************************************************/
#ifndef VNLS_H
#define VNLS_H
#include <strutil.h>
#include <stdlib.h>
#include <vlocale.h>
#include <string.h>
#include <ctype.h>
#if defined(_OS2)
#include <wchar.h>
#include <wcstr.h>
#endif
#if !defined(__GNUC__) && !defined(VSYS_WIN16) && !defined(_OS2) && !defined(sun4) && !defined(VSYS_MAC)
#define XOPEN_CTYPE
#endif
#if !defined(__GNUC__) && !defined(VSYS_WIN16) && !defined(sun4) && !defined(__sgi) && !defined(VSYS_MAC)
#define XOPEN_NLS
#endif
#if defined(hp700v9) && defined __cplusplus
/* Due to a bug in the HP header file wchar.h we need to wrap it for C++ */
extern "C"
{
#endif
#ifdef __sgi
#include <ctype.h>
#include <widec.h>
#include <wctype.h>
#endif
#if defined(XOPEN_NLS) && defined(XOPEN_CTYPE)
#ifdef sun4
#include <sys/stdtypes.h>
#else
#ifndef __sgi
#include <wchar.h>
#endif
#endif
#endif
#if defined(hp700v9) && defined __cplusplus
}
#endif
/* all platforms except HP and CenterLine compiler */
#if !defined(hp700v9) && !defined(__CLCC__)
#define SUPPORT_WCHAR_CONST
#endif
#ifdef SUPPORT_WCHAR_CONST
#define VWCHAR(a) L##a
#else
#define VWCHAR(a) ((wchar_t)a)
#endif
#if defined(NT)
#define NATIVE_UNICODE
#define NATIVE_WIDE
#endif
#ifdef LC_MESSAGES
# define VnLocaleName() (setlocale(LC_MESSAGES, 0))
#else
# define VnLocaleName() (setlocale(LC_COLLATE, 0))
#endif
#ifdef VSYS_OS2
#undef VnLocaleName
#define VnLocaleName() RunTimeLocaleName()
#endif /* VSYS_OS2 */
/*
* VnLangName() will query for and return a short language name.
*/
#ifdef __cplusplus
extern "C"
{
#endif
VFUNCDECL(int) VnLangName(char *aBuffer, int aSize);
#ifdef VSYS_OS2
/* function which returns country code defined by OS/2 */
VFUNCDECL(char*) RunTimeLocaleName();
#endif
#ifdef __cplusplus
}
#endif
#ifdef VSYS_OS2
#ifdef MB_CUR_MAX
#undef MB_CUR_MAX
#endif
#define MB_CUR_MAX __mb_cur_max
#ifdef __cplusplus
extern "C"
{
#endif
VDATADECL(unsigned short) __mb_cur_max;
#ifdef __cplusplus
}
#endif
#endif
/*===========================================================================
Support for the non-NLS-aware G++ compiler
---------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"
{
#endif
#if defined(__GNUC__) && defined(__cplusplus) && defined(sun4)
/* These functions should be in stdlib.h but are not when using G++ */
#define MB_CUR_MAX _mb_cur_max
#define mblen(s, n) mbtowc((wchar_t *)0, s, n)
extern unsigned _mb_cur_max;
extern int mbtowc(wchar_t *pwc, const char *s, size_t n);
extern int wctomb(char *s, wchar_t wchar);
extern size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);
extern size_t wcstombs(char *s, const wchar_t *pwcs, size_t n);
#endif /* __GNUC__ && __cplusplus && sun4 */
#if !defined(XOPEN_CTYPE)
# define iswalpha(c) (isascii(c) ? isalpha(c) : 1)
# define iswupper(c) (isascii(c) ? isupper(c) : 0)
# define iswlower(c) (isascii(c) ? islower(c) : 1)
# define iswdigit(c) (isascii(c) ? isdigit(c) : 0)
# define iswxdigit(c) (isascii(c) ? isxdigit(c) : 0)
# define iswalnum(c) (isascii(c) ? isalnum(c) : 1)
# define iswspace(c) (isascii(c) ? isspace(c) : 0)
# define iswprint(c) (isascii(c) ? isprint(c) : 1)
# define iswgraph(c) (isascii(c) ? isgraph(c) : 1)
# define iswpunct(c) (isascii(c) ? ispunct(c) : 0)
# define iswcntrl(c) (isascii(c) ? iscntrl(c) : 0)
# ifdef VSYS_WIN16
VFUNCDECL(wchar_t) towlower(wchar_t);
VFUNCDECL(wchar_t) towupper(wchar_t);
VFUNCDECL(struct lconv *) localeconv();
# else /* !VSYS_WIN16 */
# define towlower(c) (isascii(c) ? (wchar_t)tolower(c) : c)
# define towupper(c) (isascii(c) ? (wchar_t)toupper(c) : c)
# endif /* VSYS_WIN16 */
#endif /* XOPEN_CTYPE */
#ifdef __cplusplus
}
#endif
#if !defined(XOPEN_NLS)
/*===========================================================================
Support for the non X/Open platforms.
These routines are implemented in vnls.cc.
---------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"
{
#endif
VFUNCDECL(wchar_t *) wcscat(wchar_t *, const wchar_t *);
VFUNCDECL(wchar_t *) wcsncat(wchar_t *, const wchar_t *, size_t);
VFUNCDECL(wchar_t *) wcscpy(wchar_t *, const wchar_t *);
VFUNCDECL(wchar_t *) wcsncpy(wchar_t *, const wchar_t *, size_t);
VFUNCDECL(wchar_t *) wcschr(const wchar_t *, wchar_t);
VFUNCDECL(wchar_t *) wcsrchr(const wchar_t *, wchar_t);
VFUNCDECL(size_t) wcslen(const wchar_t *);
VFUNCDECL(int) wcscmp(const wchar_t *, const wchar_t *);
VFUNCDECL(int) wcsncmp(const wchar_t *, const wchar_t *, size_t);
VFUNCDECL(int) wcscoll(const wchar_t *, const wchar_t *);
VFUNCDECL(wchar_t *) wcswcs(const wchar_t *, const wchar_t *);
VFUNCDECL(wchar_t *) wcspbrk(const wchar_t *, const wchar_t *);
/* These standard XOPEN NLS functions are not currently implemented
* for non XOPEN aware platforms. Feel free to implement them
* as needed...
*
* VFUNCDECL(size_t) wcsspn(const wchar_t *, const wchar_t *);
* VFUNCDECL(size_t) wcscspn(const wchar_t *, const wchar_t *);
*
*
* VFUNCDECL(wchar_t *) wcstok(wchar_t *, const wchar_t *);
*
* VFUNCDECL(size_t) wcsxfrm(wchar_t *, const wchar_t *, size_t);
*
* VFUNCDECL(int) wcswidth(const wchar_t *, size_t);
* VFUNCDECL(int) wcwidth(wchar_t);
*/
#ifdef __cplusplus
}
#endif
#endif /* XOPEN_NLS */
/*===========================================================================
Generic routines for conversion between C strings and Wide strings.
---------------------------------------------------------------------------*/
#ifdef __cplusplus
/****************************************************************************
* This function returns the length (in bytes) of the next multi-byte
* character.
* If the character found at 'str' is invalid OR if the character found
* at 'str' is the NULL character, a length of 1 is returned.
****************************************************************************/
VINLINEDEF(int) VnSafeCharLen(const char *str)
{
int charLen = mblen(str, MB_CUR_MAX);
return (charLen < 1) ? 1 : charLen;
}
/****************************************************************************
* This function returns the address of the next multi-byte character.
* If the character found at 'str' is invalid OR if the character found
* at 'str' is the NULL character, 'str+1' is returned.
****************************************************************************/
VINLINEDEF(char*) VnSafeNextChar(const char *str)
{
int charLen = mblen(str, MB_CUR_MAX);
return (char*) ((charLen < 1) ? (str+1) : (str+charLen));
}
#endif /* __cplusplus */
/****************************************************************************
* This macro returns the length of the next multi-byte character.
* If the character found at 'str' is invalid, -1 is returned.
* If the character found at 'str' is the NULL character, 0 is returned.
****************************************************************************/
#ifdef __cplusplus
inline int VnCharLen(const char *str)
{
return mblen(str, MB_CUR_MAX);
}
#else /* __cplusplus */
#define VnCharLen(str) mblen(str, MB_CUR_MAX)
#endif /* __cplusplus */
/****************************************************************************
* This macro returns the address of the next multi-byte character.
* There is absolutely no error checking made by this macro.
* If the character found at 'str' is invalid, the address is one byte less.
* If the character found at 'str' is the NULL character, the address does
* not change.
* In C++, we use an inline macro which protects us from an argument that
* make use of the ++ operator (i.e. calling VnNextChar(myString++))
* This protection cannot be provided for C code.
* In the C macro, the reason we put 'str' between parenthesis is for the
* case where 'str' would be an expression. And the reason why we cast
* this expression to char* is to make sure the addition is made on a
* byte unit. For instance, if 'str' would be of type 'short*' for a
* reason or another, and if VnCharLen would return 3, you would not get
* the address of 'str' + 3, but really the address + 6.
****************************************************************************/
#ifdef __cplusplus
inline char* VnNextChar(const char *str)
{
return (char*) (str + VnCharLen(str));
}
#else /* __cplusplus */
# define VnNextChar(str) (((char*)(str)) + VnCharLen(str))
#endif /* __cplusplus */
#ifdef __cplusplus
extern "C"
{
#endif
/* Return pointer to temporary memory for converted string */
VFUNCDECL(char *) VeWideToChar(const wchar_t *str);
VFUNCDECL(wchar_t *) VeCharToWide(const char *str);
/* Return a newly allocated buffer in the converted form */
VFUNCDECL(char *) VeCreateCharFromWide(const wchar_t *str);
VFUNCDECL(wchar_t *) VeCreateWideFromChar(const char *str);
/* Return pointer to temporary memory for converted string */
VFUNCDECL(char *) VeConvertWideToChar(
char *dest,
const wchar_t *src,
size_t blen);
VFUNCDECL(wchar_t *) VeConvertCharToWide(
wchar_t *dest,
const char *src,
size_t blen);
VFUNCDECL(int) VwcNIEqual( const wchar_t *a,
const wchar_t *b,
unsigned int len);
VFUNCDECL(int) VwcIEqual( const wchar_t *a,
const wchar_t *b);
VFUNCDECL(int) VwcNEqual( const wchar_t *a,
const wchar_t *b,
unsigned int len);
VFUNCDECL(int) VwcEqual( const wchar_t *a,
const wchar_t *b);
VFUNCDECL(int) VwcICmp( const wchar_t *a,
const wchar_t *b);
VFUNCDECL(wchar_t*) VwcCopy( const wchar_t *src);
#ifdef __cplusplus
}
#endif
#if defined(NATIVE_WIDE)
# define VnCharToNative(str) VeCharToWide(str)
# define VnWideToNative(str) (str)
# define VnNativeToChar(str) VeWideToChar(str)
# define VnNativeToWide(str) (str)
typedef wchar_t VTNativeChar;
#else /* NATIVE_WIDE */
# define VnCharToNative(str) (str)
# define VnWideToNative(str) VeWideToChar(str)
# define VnNativeToChar(str) (str)
# define VnNativeToWide(str) VeCharToWide(str)
typedef char VTNativeChar;
#endif /* NATIVE_WIDE */
/*===========================================================================
* Define a constant for an empty wide character string.
*---------------------------------------------------------------------------*/
static const wchar_t kVwcConstEmpty[] = { (wchar_t)0 };
#define kVwcEmpty ((wchar_t *)kVwcConstEmpty)
/*===========================================================================
* Japanese sort
*---------------------------------------------------------------------------*/
#ifndef __vwcstr_hpp__
#define __vwcstr_hpp__
#ifdef __cplusplus
class VwcCharTable;
extern "C"
{
//
// VeVwcscmp:
// Compares two strings (mixture of SBCS and MBCS) according
// to the order specified in the file named DATA_FILE.
// Returns: -1 when str1 < str2
// 0 when str1 = str2
// 1 when str1 > str2
//
#endif
VFUNCDECL(int) VeVwcscmp(const char* str1, const char* str2);
#ifdef __cplusplus
} // for extern "C" {
//
// VwcCharTable:
// Used by the vwcscmp finction.
//
class VwcCharTable { // Table for the user-specified order.
private:
static VwcCharTable* _table;
struct Subtable {
unsigned long from;
unsigned long to;
unsigned long* order;
};
Subtable* subtable;
int nSubtables;
VwcCharTable(); // Disables users to call ctor.
public:
~VwcCharTable();
static VwcCharTable* table(); // Use this for creation.
unsigned long operator[](unsigned long index);
};
#endif /* __cplusplus */
#endif /* __vwcstr_hpp__ */
#endif /* VNLS_H */