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 >
C/C++ Source or Header  |  1996-07-29  |  13KB  |  458 lines

  1. /*****************************************************************************
  2.  ***   $Source: /rcs/crcs/general/vnls.h,v $
  3.  ***   Checked int by: $Author: clement $
  4.  ***   $Date: 1996/07/03 15:09:07 $
  5.  ***   $Revision: 1.32 $
  6.  *****************************************************************************
  7.  ***                                       ***
  8.  ***         Copyright (c) 1994, Visual Edge Software Ltd.           ***
  9.  ***         Copyright (c) 1994, International Business Machines Corp. ***
  10.  ***                                       ***
  11.  ***   All rights reserved.  This notice is  intended  as  a  precaution   ***
  12.  ***   against    inadvertent publication, and shall not be deemed to con-   ***
  13.  ***   stitute an acknowledgment that publication has  occurred  nor  to   ***
  14.  ***   imply  any  waiver  of confidentiality.    The year included in the   ***
  15.  ***   notice is the year of the creation of the work.               ***
  16.  ***                                       ***
  17.  *****************************************************************************/
  18.  
  19. #ifndef VNLS_H
  20. #define VNLS_H
  21.  
  22. #include <strutil.h>
  23. #include <stdlib.h>
  24. #include <vlocale.h>
  25.  
  26. #include <string.h>
  27. #include <ctype.h>
  28.  
  29. #if defined(_OS2)
  30. #include <wchar.h>
  31. #include <wcstr.h>
  32. #endif
  33.  
  34. #if !defined(__GNUC__) && !defined(VSYS_WIN16) && !defined(_OS2) && !defined(sun4) && !defined(VSYS_MAC)
  35. #define XOPEN_CTYPE
  36. #endif
  37.  
  38. #if !defined(__GNUC__) && !defined(VSYS_WIN16) && !defined(sun4) && !defined(__sgi) && !defined(VSYS_MAC)
  39. #define XOPEN_NLS
  40. #endif
  41.  
  42. #if defined(hp700v9) && defined __cplusplus
  43. /* Due to a bug in the HP header file wchar.h we need to wrap it for C++ */
  44. extern "C"
  45. {
  46. #endif
  47.  
  48. #ifdef __sgi
  49. #include <ctype.h>
  50. #include <widec.h>
  51. #include <wctype.h>
  52. #endif
  53.  
  54. #if defined(XOPEN_NLS) && defined(XOPEN_CTYPE)
  55. #ifdef sun4
  56. #include <sys/stdtypes.h>
  57. #else
  58. #ifndef __sgi
  59. #include <wchar.h>
  60. #endif
  61. #endif
  62. #endif
  63.  
  64. #if defined(hp700v9) && defined __cplusplus
  65. }
  66. #endif
  67.  
  68. /* all platforms except HP and CenterLine compiler */
  69. #if !defined(hp700v9) && !defined(__CLCC__)
  70. #define SUPPORT_WCHAR_CONST
  71. #endif
  72.  
  73. #ifdef SUPPORT_WCHAR_CONST
  74. #define VWCHAR(a) L##a
  75. #else
  76. #define VWCHAR(a) ((wchar_t)a)
  77. #endif
  78.  
  79. #if defined(NT)
  80. #define NATIVE_UNICODE
  81. #define NATIVE_WIDE
  82. #endif
  83.  
  84. #ifdef LC_MESSAGES
  85. #    define VnLocaleName()    (setlocale(LC_MESSAGES, 0))
  86. #else
  87. #    define VnLocaleName()    (setlocale(LC_COLLATE, 0))
  88. #endif
  89.  
  90. #ifdef VSYS_OS2
  91. #undef VnLocaleName
  92. #define VnLocaleName() RunTimeLocaleName()
  93. #endif /* VSYS_OS2 */
  94.  
  95. /*
  96.  *   VnLangName() will query for and return a short language name.
  97.  */
  98. #ifdef __cplusplus
  99. extern "C"
  100. {
  101. #endif
  102.  
  103. VFUNCDECL(int)        VnLangName(char *aBuffer, int aSize);
  104.  
  105. #ifdef VSYS_OS2
  106. /* function which returns country code defined by OS/2 */
  107. VFUNCDECL(char*)      RunTimeLocaleName();
  108. #endif
  109.  
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113.  
  114.  
  115. #ifdef VSYS_OS2
  116. #ifdef MB_CUR_MAX
  117. #undef MB_CUR_MAX
  118. #endif
  119. #define MB_CUR_MAX __mb_cur_max
  120. #ifdef __cplusplus
  121. extern "C"
  122. {
  123. #endif
  124.  
  125.     VDATADECL(unsigned short) __mb_cur_max;
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif
  130.  
  131. /*===========================================================================
  132.   Support for the non-NLS-aware G++ compiler
  133.   ---------------------------------------------------------------------------*/
  134.  
  135. #ifdef __cplusplus
  136. extern "C"
  137. {
  138. #endif
  139.  
  140. #if defined(__GNUC__) && defined(__cplusplus) && defined(sun4)
  141.  
  142. /* These functions should be in stdlib.h but are not when using G++ */
  143.  
  144. #define MB_CUR_MAX _mb_cur_max
  145. #define mblen(s, n) mbtowc((wchar_t *)0, s, n)
  146.  
  147.     extern unsigned _mb_cur_max;
  148.  
  149.     extern int    mbtowc(wchar_t *pwc, const char *s, size_t n);
  150.     extern int    wctomb(char *s, wchar_t wchar);
  151.     extern size_t    mbstowcs(wchar_t *pwcs, const char *s, size_t n);
  152.     extern size_t    wcstombs(char *s, const wchar_t *pwcs, size_t n);
  153.  
  154. #endif /* __GNUC__ && __cplusplus && sun4 */
  155.  
  156. #if !defined(XOPEN_CTYPE)
  157.  
  158. #    define iswalpha(c)    (isascii(c) ? isalpha(c) :  1)
  159. #    define iswupper(c)    (isascii(c) ? isupper(c) :  0)
  160. #    define iswlower(c)    (isascii(c) ? islower(c) :  1)
  161. #    define iswdigit(c)    (isascii(c) ? isdigit(c) :  0)
  162. #    define iswxdigit(c)    (isascii(c) ? isxdigit(c) : 0)
  163. #    define iswalnum(c)    (isascii(c) ? isalnum(c) :  1)
  164. #    define iswspace(c)    (isascii(c) ? isspace(c) :  0)
  165. #    define iswprint(c)    (isascii(c) ? isprint(c) :  1)
  166. #    define iswgraph(c)    (isascii(c) ? isgraph(c) :  1)
  167. #    define iswpunct(c)    (isascii(c) ? ispunct(c) :  0)
  168. #    define iswcntrl(c)    (isascii(c) ? iscntrl(c) :  0)
  169.  
  170. #    ifdef VSYS_WIN16
  171.  
  172.         VFUNCDECL(wchar_t) towlower(wchar_t);
  173.         VFUNCDECL(wchar_t) towupper(wchar_t);
  174.         VFUNCDECL(struct lconv *) localeconv();
  175.  
  176. #    else /* !VSYS_WIN16 */
  177. #        define towlower(c)    (isascii(c) ? (wchar_t)tolower(c) : c)
  178. #        define towupper(c)    (isascii(c) ? (wchar_t)toupper(c) : c)
  179. #    endif /* VSYS_WIN16 */
  180.  
  181. #endif /* XOPEN_CTYPE */
  182.  
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186.  
  187. #if !defined(XOPEN_NLS)
  188.  
  189. /*===========================================================================
  190.   Support for the non X/Open platforms.
  191.   These routines are implemented in vnls.cc.
  192.   ---------------------------------------------------------------------------*/
  193.  
  194. #ifdef __cplusplus
  195. extern "C"
  196. {
  197. #endif
  198.  
  199.     VFUNCDECL(wchar_t *) wcscat(wchar_t *, const wchar_t *);
  200.     VFUNCDECL(wchar_t *) wcsncat(wchar_t *, const wchar_t *, size_t);
  201.  
  202.     VFUNCDECL(wchar_t *) wcscpy(wchar_t *, const wchar_t *);
  203.     VFUNCDECL(wchar_t *) wcsncpy(wchar_t *, const wchar_t *, size_t);
  204.  
  205.     VFUNCDECL(wchar_t *) wcschr(const wchar_t *, wchar_t);
  206.     VFUNCDECL(wchar_t *) wcsrchr(const wchar_t *, wchar_t);
  207.  
  208.     VFUNCDECL(size_t)    wcslen(const wchar_t *);
  209.  
  210.     VFUNCDECL(int)         wcscmp(const wchar_t *, const wchar_t *);
  211.     VFUNCDECL(int)         wcsncmp(const wchar_t *, const wchar_t *, size_t);
  212.  
  213.     VFUNCDECL(int)         wcscoll(const wchar_t *, const wchar_t *);
  214.  
  215.     VFUNCDECL(wchar_t *) wcswcs(const wchar_t *, const wchar_t *);
  216.     VFUNCDECL(wchar_t *) wcspbrk(const wchar_t *, const wchar_t *);
  217.  
  218. /*    These standard XOPEN NLS functions are not currently implemented
  219.  *    for non XOPEN aware platforms.    Feel free to implement them
  220.  *    as needed...
  221.  *
  222.  *    VFUNCDECL(size_t)    wcsspn(const wchar_t *, const wchar_t *);
  223.  *    VFUNCDECL(size_t)    wcscspn(const wchar_t *, const wchar_t *);
  224.  *
  225.  *
  226.  *    VFUNCDECL(wchar_t *) wcstok(wchar_t *, const wchar_t *);
  227.  *
  228.  *    VFUNCDECL(size_t)    wcsxfrm(wchar_t *, const wchar_t *, size_t);
  229.  *
  230.  *    VFUNCDECL(int)         wcswidth(const wchar_t *, size_t);
  231.  *    VFUNCDECL(int)         wcwidth(wchar_t);
  232.  */
  233.  
  234. #ifdef __cplusplus
  235. }
  236. #endif
  237.  
  238. #endif /* XOPEN_NLS */
  239.  
  240. /*===========================================================================
  241.   Generic routines for conversion between C strings and Wide strings.
  242.   ---------------------------------------------------------------------------*/
  243.  
  244. #ifdef __cplusplus
  245. /****************************************************************************
  246.  * This function returns the length (in bytes) of the next multi-byte
  247.  * character.
  248.  * If the character found at 'str' is invalid OR if the character found
  249.  * at 'str' is the NULL character, a length of 1 is returned.
  250.  ****************************************************************************/
  251. VINLINEDEF(int) VnSafeCharLen(const char *str)
  252. {
  253.     int charLen = mblen(str, MB_CUR_MAX);
  254.  
  255.     return (charLen < 1) ? 1 : charLen;
  256. }
  257.  
  258. /****************************************************************************
  259.  * This function returns the address of the next multi-byte character.
  260.  * If the character found at 'str' is invalid OR if the character found
  261.  * at 'str' is the NULL character, 'str+1' is returned.
  262.  ****************************************************************************/
  263. VINLINEDEF(char*) VnSafeNextChar(const char *str)
  264. {
  265.     int charLen = mblen(str, MB_CUR_MAX);
  266.  
  267.     return (char*) ((charLen < 1) ? (str+1) : (str+charLen));
  268. }
  269. #endif /* __cplusplus */
  270.  
  271.  
  272. /****************************************************************************
  273.  * This macro returns the length of the next multi-byte character.
  274.  * If the character found at 'str' is invalid, -1 is returned.
  275.  * If the character found at 'str' is the NULL character, 0 is returned.
  276.  ****************************************************************************/
  277. #ifdef __cplusplus
  278.  
  279.     inline int VnCharLen(const char *str)
  280.     {
  281.         return mblen(str, MB_CUR_MAX);
  282.     }
  283.  
  284. #else /* __cplusplus */
  285.  
  286. #define VnCharLen(str)    mblen(str, MB_CUR_MAX)
  287.  
  288. #endif /* __cplusplus */
  289.  
  290.  
  291.  
  292.  
  293. /****************************************************************************
  294.  * This macro returns the address of the next multi-byte character.
  295.  * There is absolutely no error checking made by this macro.
  296.  * If the character found at 'str' is invalid, the address is one byte less.
  297.  * If the character found at 'str' is the NULL character, the address does
  298.  *    not change.
  299.  * In C++, we use an inline macro which protects us from an argument that
  300.  *    make use of the ++ operator (i.e. calling VnNextChar(myString++))
  301.  *    This protection cannot be provided for C code.
  302.  * In the C macro, the reason we put 'str' between parenthesis is for the
  303.  *    case where 'str' would be an expression. And the reason why we cast
  304.  *    this expression to char* is to make sure the addition is made on a
  305.  *    byte unit. For instance, if 'str' would be of type 'short*' for a
  306.  *    reason or another, and if VnCharLen would return 3, you would not get
  307.  *    the address of 'str' + 3, but really the address + 6.
  308.  ****************************************************************************/
  309. #ifdef __cplusplus
  310.  
  311.     inline char* VnNextChar(const char *str)
  312.     {
  313.         return (char*) (str + VnCharLen(str));
  314.     }
  315.  
  316. #else /* __cplusplus */
  317.  
  318. #    define VnNextChar(str) (((char*)(str)) + VnCharLen(str))
  319.  
  320. #endif /* __cplusplus */
  321.  
  322.  
  323.  
  324.  
  325. #ifdef __cplusplus
  326. extern "C"
  327. {
  328. #endif
  329.  
  330.     /* Return pointer to temporary memory for converted string */
  331.  
  332.     VFUNCDECL(char *)    VeWideToChar(const wchar_t *str);
  333.     VFUNCDECL(wchar_t *)    VeCharToWide(const char *str);
  334.  
  335.     /* Return a newly allocated buffer in the converted form */
  336.  
  337.     VFUNCDECL(char *)    VeCreateCharFromWide(const wchar_t *str);
  338.     VFUNCDECL(wchar_t *)    VeCreateWideFromChar(const char *str);
  339.  
  340.     /* Return pointer to temporary memory for converted string */
  341.  
  342.     VFUNCDECL(char *)    VeConvertWideToChar(
  343.                         char        *dest,
  344.                         const wchar_t    *src,
  345.                         size_t        blen);
  346.  
  347.     VFUNCDECL(wchar_t *)    VeConvertCharToWide(
  348.                         wchar_t     *dest,
  349.                         const char    *src,
  350.                         size_t        blen);
  351.  
  352.     VFUNCDECL(int) VwcNIEqual(    const wchar_t    *a,
  353.                     const wchar_t    *b,
  354.                     unsigned int    len);
  355.  
  356.     VFUNCDECL(int) VwcIEqual(    const wchar_t    *a,
  357.                     const wchar_t    *b);
  358.  
  359.     VFUNCDECL(int) VwcNEqual(    const wchar_t    *a,
  360.                     const wchar_t    *b,
  361.                     unsigned int    len);
  362.  
  363.     VFUNCDECL(int) VwcEqual(    const wchar_t    *a,
  364.                     const wchar_t    *b);
  365.  
  366.     VFUNCDECL(int) VwcICmp(     const wchar_t    *a,
  367.                     const wchar_t    *b);
  368.  
  369.     VFUNCDECL(wchar_t*) VwcCopy(    const wchar_t    *src);
  370.  
  371. #ifdef __cplusplus
  372. }
  373. #endif
  374.  
  375. #if defined(NATIVE_WIDE)
  376.  
  377. #    define VnCharToNative(str)    VeCharToWide(str)
  378. #    define VnWideToNative(str)    (str)
  379.  
  380. #    define VnNativeToChar(str)    VeWideToChar(str)
  381. #    define VnNativeToWide(str)    (str)
  382.  
  383. typedef wchar_t VTNativeChar;
  384.  
  385. #else /* NATIVE_WIDE */
  386.  
  387. #    define VnCharToNative(str)    (str)
  388. #    define VnWideToNative(str)    VeWideToChar(str)
  389.  
  390. #    define VnNativeToChar(str)    (str)
  391. #    define VnNativeToWide(str)    VeCharToWide(str)
  392.  
  393. typedef char VTNativeChar;
  394.  
  395. #endif /* NATIVE_WIDE */
  396.  
  397. /*===========================================================================
  398.  * Define a constant for an empty wide character string.
  399.  *---------------------------------------------------------------------------*/
  400.  
  401. static const wchar_t kVwcConstEmpty[] = { (wchar_t)0 };
  402.  
  403. #define kVwcEmpty    ((wchar_t *)kVwcConstEmpty)
  404.  
  405. /*===========================================================================
  406.  * Japanese sort
  407.  *---------------------------------------------------------------------------*/
  408. #ifndef __vwcstr_hpp__
  409. #define __vwcstr_hpp__
  410.  
  411. #ifdef __cplusplus
  412.  
  413. class VwcCharTable;
  414. extern "C"
  415. {
  416.  
  417. //
  418. // VeVwcscmp:
  419. // Compares two strings (mixture of SBCS and MBCS) according
  420. // to the order specified in the file named DATA_FILE.
  421. // Returns: -1 when str1 < str2
  422. //        0  when str1 = str2
  423. //        1  when str1 > str2
  424. //
  425.  
  426. #endif
  427.  
  428. VFUNCDECL(int) VeVwcscmp(const char* str1, const char* str2);
  429.  
  430. #ifdef __cplusplus
  431.  
  432. }    // for extern "C" {
  433.  
  434. //
  435. // VwcCharTable:
  436. // Used by the vwcscmp finction.
  437. //
  438. class VwcCharTable { // Table for the user-specified order.
  439.    private:
  440.       static VwcCharTable* _table;
  441.       struct Subtable {
  442.      unsigned long from;
  443.      unsigned long to;
  444.      unsigned long* order;
  445.       };
  446.       Subtable* subtable;
  447.       int nSubtables;
  448.       VwcCharTable(); // Disables users to call ctor.
  449.    public:
  450.       ~VwcCharTable();
  451.       static VwcCharTable* table(); // Use this for creation.
  452.       unsigned long operator[](unsigned long index);
  453. };
  454. #endif /* __cplusplus */
  455. #endif /* __vwcstr_hpp__ */
  456.  
  457. #endif /* VNLS_H */
  458.