Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  RISC oriented string functions designed to access memory
  28. *               as aligned 32- or 64-bit words whenever possible.
  29. *
  30. ****************************************************************************/
  31.  
  32.  
  33. #ifndef _RISCSTR_H_INCLUDED
  34. #define _RISCSTR_H_INCLUDED
  35.  
  36.  
  37. /*
  38.  * Determine if we're building RISC versions of string/memory routines.
  39.  */
  40.  
  41. #if defined(__AXP__) || defined(__PPC__)
  42.     #define __RISCSTR__
  43. #endif
  44.  
  45. #ifdef __RISCSTR__              /* do nothing if not RISC target */
  46.  
  47.  
  48. #include "variety.h"
  49. #include "widechar.h"
  50. #include <string.h>
  51. #include <wchar.h>
  52. #include "watcom.h"
  53.  
  54.  
  55. /*
  56.  * Choose between 32- and 64-bit words.
  57.  */
  58.  
  59. #define USE_INT64               0       /* no 64-bit stuff for now */
  60.  
  61. #ifndef USE_INT64
  62.     #ifdef __AXP__
  63.         #define USE_INT64       1
  64.     #else
  65.         #define USE_INT64       0
  66.     #endif
  67. #endif
  68.  
  69. #if USE_INT64
  70.     #define INT                 __int64
  71.     #define UINT                unsigned __int64
  72. #else
  73.     #define INT                 int
  74.     #define UINT                uint_32
  75. #endif
  76.  
  77. #define BYTES_PER_WORD          ( sizeof( UINT ) )
  78. #define INT_SIZE                ( BYTES_PER_WORD * 8 )
  79. #define CHARS_PER_WORD          ( BYTES_PER_WORD / CHARSIZE )
  80.  
  81. #define MOD_BYTES_PER_WORD(__n) ( (__n) & (BYTES_PER_WORD-1) )
  82.  
  83.  
  84.  
  85. /*
  86.  * Macros to mask off a single character.
  87.  */
  88.  
  89. #if USE_INT64
  90.     #define BYTE1               ( _riscdata->byteMasks[0].val )
  91.     #define BYTE2               ( _riscdata->byteMasks[1].val )
  92.     #define BYTE3               ( _riscdata->byteMasks[2].val )
  93.     #define BYTE4               ( _riscdata->byteMasks[3].val )
  94.     #define BYTE5               ( _riscdata->byteMasks[4].val )
  95.     #define BYTE6               ( _riscdata->byteMasks[5].val )
  96.     #define BYTE7               ( _riscdata->byteMasks[6].val )
  97.     #define BYTE8               ( _riscdata->byteMasks[7].val )
  98. #else
  99.     #define BYTE1               ( 0x000000FF )
  100.     #define BYTE2               ( 0x0000FF00 )
  101.     #define BYTE3               ( 0x00FF0000 )
  102.     #define BYTE4               ( 0xFF000000 )
  103. #endif
  104.  
  105. #ifdef __WIDECHAR__
  106.     #define CHR1MASK            ( BYTE1 | BYTE2 )
  107.     #define CHR2MASK            ( BYTE3 | BYTE4 )
  108. #else
  109.     #define CHR1MASK            ( BYTE1 )
  110.     #define CHR2MASK            ( BYTE2 )
  111.     #define CHR3MASK            ( BYTE3 )
  112.     #define CHR4MASK            ( BYTE4 )
  113. #endif
  114.  
  115.  
  116. #ifdef __WIDECHAR__
  117.     #define CHR1(__w)           ( (__w) & CHR1MASK )
  118.     #define CHR2(__w)           ( (__w) & CHR2MASK )
  119. #else
  120.     #define CHR1(__w)           ( (__w) & BYTE1 )
  121.     #define CHR2(__w)           ( (__w) & BYTE2 )
  122.     #define CHR3(__w)           ( (__w) & BYTE3 )
  123.     #define CHR4(__w)           ( (__w) & BYTE4 )
  124.     #if USE_INT64
  125.         #define CHR5(__w)       ( (__w) & BYTE5 )
  126.         #define CHR6(__w)       ( (__w) & BYTE6 )
  127.         #define CHR7(__w)       ( (__w) & BYTE7 )
  128.         #define CHR8(__w)       ( (__w) & BYTE8 )
  129.     #endif
  130. #endif
  131.  
  132.  
  133.  
  134. /*
  135.  * Macros for extracting the first characters in a word.
  136.  */
  137.  
  138. #if USE_INT64
  139.     #define FRONT_BYTES(__n)    ( _riscdata->frontCharsMasks[(__n)].val )
  140.     #define FRONT_CHRS(__w,__o) ( (__w) & FRONT_BYTES_riscdata[(__o)].val )
  141. #else
  142. //    extern UINT __FRONT_BYTES[];
  143. //    #define FRONT_BYTES               __FRONT_BYTES
  144.     #define FRONT_BYTES         ( _riscdata->frontCharsMasks )
  145.     #define FRONT_CHRS(__w,__o) ( (__w) & FRONT_BYTES[(__o)] )
  146. #endif
  147.  
  148.  
  149.  
  150. /*
  151.  * Macros for ignoring the first characters in a word.
  152.  */
  153.  
  154. #if USE_INT64
  155.     #define SKIP_CHRS_MASKS(__n)    ( _riscdata->skipCharsMasks[(__n)].val )
  156.     #define SKIP_CHRS(__w,__o)      ( (__w) & SKIP_CHRS_MASKS(__o) )
  157. #else
  158. //    extern UINT __SKIP_CHRS_MASKS[];
  159. //    #define SKIP_CHRS_MASKS           __SKIP_CHRS_MASKS
  160.     #define SKIP_CHRS_MASKS(__n)    ( _riscdata->skipCharsMasks[(__n)] )
  161.     #define SKIP_CHRS(__w,__o)      ( (__w) & SKIP_CHRS_MASKS(__o) )
  162. #endif
  163.  
  164.  
  165.  
  166. /*
  167.  * Macros for checking if a word contains a null byte.
  168.  */
  169.  
  170. #if USE_INT64
  171.     #define SUB_M               ( _riscdata->_01Mask.val )
  172.     #define NIL_M               ( _riscdata->_80Mask.val )
  173.     #define SUB_MASK(__n)       ( _riscdata->subMasks[(__n)].val )
  174. #else
  175.     #ifdef __WIDECHAR__
  176.         #define SUB_M           ( 0x00010001 )
  177.         #define NIL_M           ( 0x80008000 )
  178.     #else
  179.         #define SUB_M           ( 0x01010101 )
  180.         #define NIL_M           ( 0x80808080 )
  181.     #endif
  182. //    extern UINT __SubMask[];
  183. //    #define SUB_MASK          __SubMask
  184.     #define SUB_MASK(__n)       ( _riscdata->subMasks[(__n)] )
  185. #endif
  186.  
  187. #define GOT_NIL(__w)            ( ( (~(__w)) & ((__w) - SUB_M) ) & NIL_M )
  188.  
  189. #ifdef __WIDECHAR__
  190.     #define OFFSET_GOT_NIL(__w,__o) ( ( (~(__w)) & ((__w) - SUB_MASK((__o)/CHARSIZE)) ) & NIL_M )
  191. #else
  192.     #define OFFSET_GOT_NIL(__w,__o) ( ( (~(__w)) & ((__w) - SUB_MASK(__o)) ) & NIL_M )
  193. #endif
  194.  
  195.  
  196.  
  197. /*
  198.  * Some handy pointer manipulation macros.
  199.  */
  200.  
  201. #define ROUND(__p)              ( (UINT*) ( (UINT)(__p) & (-sizeof(UINT)) ) )
  202.  
  203. #define OFFSET(__p)             ( ((unsigned int)(__p)) & (sizeof(UINT)-1) )
  204.  
  205.  
  206.  
  207. /*
  208.  * Macros for uppercase and lowercase stuff.
  209.  */
  210.  
  211. #ifdef __WIDECHAR__
  212.     #define CHR1_A              ( 0x00000041 )
  213.     #define CHR2_A              ( 0x00410000 )
  214.  
  215.     #define CHR1_Z              ( 0x0000005A )
  216.     #define CHR2_Z              ( 0x005A0000 )
  217.  
  218.     #define CHR1_A2a(s)         ( s | 0x00000020 )
  219.     #define CHR2_A2a(s)         ( s | 0x00200000 )
  220. #else
  221.     #define CHR1_A              ( 0x00000041 )
  222.     #define CHR2_A              ( 0x00004100 )
  223.     #define CHR3_A              ( 0x00410000 )
  224.     #define CHR4_A              ( 0x41000000 )
  225.  
  226.     #define CHR1_Z              ( 0x0000005A )
  227.     #define CHR2_Z              ( 0x00005A00 )
  228.     #define CHR3_Z              ( 0x005A0000 )
  229.     #define CHR4_Z              ( 0x5A000000 )
  230.  
  231.     #define CHR1_A2a(s)         ( s | 0x00000020 )
  232.     #define CHR2_A2a(s)         ( s | 0x00002000 )
  233.     #define CHR3_A2a(s)         ( s | 0x00200000 )
  234.     #define CHR4_A2a(s)         ( s | 0x20000000 )
  235. #endif
  236.  
  237. #ifdef __WIDECHAR__
  238.     #define TO_LOW_CHR1(s) ( ( (s>=CHR1_A) && (s<=CHR1_Z) ) ? CHR1_A2a(s) : s )
  239.     #define TO_LOW_CHR2(s) ( ( (s>=CHR2_A) && (s<=CHR2_Z) ) ? CHR2_A2a(s) : s )
  240. #else
  241.     #define TO_LOW_CHR1(s) ( ( (s>=CHR1_A) && (s<=CHR1_Z) ) ? CHR1_A2a(s) : s )
  242.     #define TO_LOW_CHR2(s) ( ( (s>=CHR2_A) && (s<=CHR2_Z) ) ? CHR2_A2a(s) : s )
  243.     #define TO_LOW_CHR3(s) ( ( (s>=CHR3_A) && (s<=CHR3_Z) ) ? CHR3_A2a(s) : s )
  244.     #define TO_LOW_CHR4(s) ( ( (s>=CHR4_A) && (s<=CHR4_Z) ) ? CHR4_A2a(s) : s )
  245. #endif
  246.  
  247.  
  248. #ifdef __WIDECHAR__
  249.     #define CHR1_a              ( 0x00000061 )
  250.     #define CHR2_a              ( 0x00610000 )
  251.  
  252.     #define CHR1_z              ( 0x0000007A )
  253.     #define CHR2_z              ( 0x007A0000 )
  254.  
  255.     #define CHR1_a2A(s)         ( s & 0x000000DF )
  256.     #define CHR2_a2A(s)         ( s & 0x00DF0000 )
  257. #else
  258.     #define CHR1_a              ( 0x00000061 )
  259.     #define CHR2_a              ( 0x00006100 )
  260.     #define CHR3_a              ( 0x00610000 )
  261.     #define CHR4_a              ( 0x61000000 )
  262.  
  263.     #define CHR1_z              ( 0x0000007A )
  264.     #define CHR2_z              ( 0x00007A00 )
  265.     #define CHR3_z              ( 0x007A0000 )
  266.     #define CHR4_z              ( 0x7A000000 )
  267.  
  268.     #define CHR1_a2A(s)         ( s & 0x000000DF )
  269.     #define CHR2_a2A(s)         ( s & 0x0000DF00 )
  270.     #define CHR3_a2A(s)         ( s & 0x00DF0000 )
  271.     #define CHR4_a2A(s)         ( s & 0xDF000000 )
  272. #endif
  273.  
  274. #ifdef __WIDECHAR__
  275.     #define TO_UPR_CHR1(s) ( ( (s>=CHR1_a) && (s<=CHR1_z) ) ? CHR1_a2A(s) : s )
  276.     #define TO_UPR_CHR2(s) ( ( (s>=CHR2_a) && (s<=CHR2_z) ) ? CHR2_a2A(s) : s )
  277. #else
  278.     #define TO_UPR_CHR1(s) ( ( (s>=CHR1_a) && (s<=CHR1_z) ) ? CHR1_a2A(s) : s )
  279.     #define TO_UPR_CHR2(s) ( ( (s>=CHR2_a) && (s<=CHR2_z) ) ? CHR2_a2A(s) : s )
  280.     #define TO_UPR_CHR3(s) ( ( (s>=CHR3_a) && (s<=CHR3_z) ) ? CHR3_a2A(s) : s )
  281.     #define TO_UPR_CHR4(s) ( ( (s>=CHR4_a) && (s<=CHR4_z) ) ? CHR4_a2A(s) : s )
  282. #endif
  283.  
  284.  
  285.  
  286. /*
  287.  * Tweak characters within a word.
  288.  */
  289.  
  290. #ifdef __WIDECHAR__
  291.     #define REVERSE_CHARS(__w)  ( (CHR1(__w)<<16) | (CHR2(__w)>>16) )
  292. #else
  293.     #define REVERSE_CHARS(__w)  ( (CHR1(__w)<<24) | (CHR2(__w)<<8) |    \
  294.                                   (CHR3(__w)>>8)  | (CHR4(__w)>>24) )
  295. #endif
  296.  
  297. #define SWAP_BYTES(__w)         ( (((__w)&BYTE1)<<8) | (((__w)&BYTE2)>>8) | \
  298.                                   (((__w)&BYTE3)<<8) | (((__w)&BYTE4)>>8) )
  299.  
  300.  
  301.  
  302. /*
  303.  * Data used by the RISC string functions.
  304.  */
  305.  
  306. struct __F_NAME(__RISC_StrData,__wRISC_StrData) {
  307. #if USE_INT64
  308.     unsigned_64         byteMasks[8];
  309.     unsigned_64         frontCharsMasks[8];
  310.     unsigned_64         skipCharsMasks[8];
  311.     unsigned_64         _01Mask;
  312.     unsigned_64         _80Mask;
  313.     unsigned_64         subMasks[8];
  314. #else
  315.     #ifdef __WIDECHAR__
  316.         uint_32         frontCharsMasks[2];
  317.         uint_32         skipCharsMasks[2];
  318.         uint_32         subMasks[2];
  319.     #else
  320.         uint_32         frontCharsMasks[4];
  321.         uint_32         skipCharsMasks[4];
  322.         uint_32         subMasks[4];
  323.     #endif
  324. #endif
  325. };
  326.  
  327.  
  328. #ifdef __WIDECHAR__
  329.     extern struct __wRISC_StrData   __wRISC_StringData;
  330.     #define RISC_DATA_LOCALREF  struct __wRISC_StrData *_riscdata = &__wRISC_StringData
  331. #else
  332.     extern struct __RISC_StrData    __RISC_StringData;
  333.     #define RISC_DATA_LOCALREF  struct __RISC_StrData *_riscdata = &__RISC_StringData
  334. #endif
  335.  
  336.  
  337.  
  338. /*
  339.  * Prototype functions called by the RISC-oriented string functions.
  340.  */
  341.  
  342. _WCRTLINK extern wchar_t *  __simple_wcschr( const wchar_t *str, wint_t ch );
  343. _WCRTLINK extern int        __simple_wcscmp( const wchar_t *s1, const wchar_t *s2 );
  344. _WCRTLINK extern wchar_t *  __simple_wcscpy( wchar_t *dest, const wchar_t *src );
  345. _WCRTLINK extern int        __simple__wcsicmp( const wchar_t *s1, const wchar_t *s2 );
  346. _WCRTLINK extern size_t     __simple_wcslen( const wchar_t *str );
  347. _WCRTLINK extern wchar_t *  __simple__wcslwr( wchar_t *str );
  348. _WCRTLINK extern int        __simple_wcsncmp( const wchar_t *s1, const wchar_t *s2, size_t n );
  349. _WCRTLINK extern wchar_t *  __simple_wcsncpy( wchar_t *dest, const wchar_t *src, size_t n );
  350. _WCRTLINK extern int        __simple__wcsnicmp( const wchar_t *s1, const wchar_t *s2, size_t n );
  351. _WCRTLINK extern wchar_t *  __simple__wcsnset( wchar_t *str, int ch, size_t n );
  352. _WCRTLINK extern wchar_t *  __simple_wcsrchr( const wchar_t *str, wint_t ch );
  353. _WCRTLINK extern wchar_t *  __simple__wcsset( wchar_t *str, wchar_t ch );
  354. _WCRTLINK extern wchar_t *  __simple__wcsupr( wchar_t *str );
  355.  
  356.  
  357. #endif          /* #ifdef __RISCSTR__ */
  358.  
  359. #endif
  360.