diff --git a/reactos/lib/msvcrt/mbstring/hanzen.c b/reactos/lib/msvcrt/mbstring/hanzen.c new file mode 100644 index 00000000000..f640d4e2f11 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/hanzen.c @@ -0,0 +1,101 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/hanzen.c + * PURPOSE: Multibyte conversion routines formerly called hantozen and zentohan + * PROGRAMER: Boudewijn Dekker, Taiji Yamada + * UPDATE HISTORY: + Modified from Taiji Yamada japanese code system utilities + * 12/04/99: Created + */ + +#include + +static unsigned short han_to_zen_ascii_table[0x5f] = { + 0x8140, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193, 0x8195, 0x8166, + 0x8169, 0x816a, 0x8196, 0x817b, 0x8143, 0x817c, 0x8144, 0x815e, + 0x824f, 0x8250, 0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256, + 0x8257, 0x8258, 0x8146, 0x8147, 0x8183, 0x8181, 0x8184, 0x8148, + 0x8197, 0x8260, 0x8261, 0x8262, 0x8263, 0x8264, 0x8265, 0x8266, + 0x8267, 0x8268, 0x8269, 0x826a, 0x826b, 0x826c, 0x826d, 0x826e, + 0x826f, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274, 0x8275, 0x8276, + 0x8277, 0x8278, 0x8279, 0x816d, 0x818f, 0x816e, 0x814f, 0x8151, + 0x8165, 0x8281, 0x8282, 0x8283, 0x8284, 0x8285, 0x8286, 0x8287, + 0x8288, 0x8289, 0x828a, 0x828b, 0x828c, 0x828d, 0x828e, 0x828f, + 0x8290, 0x8291, 0x8292, 0x8293, 0x8294, 0x8295, 0x8296, 0x8297, + 0x8298, 0x8299, 0x829a, 0x816f, 0x8162, 0x8170, 0x8150 +}; +static unsigned short han_to_zen_kana_table[0x40] = { + 0x8140, 0x8142, 0x8175, 0x8176, 0x8141, 0x8145, 0x8392, 0x8340, + 0x8342, 0x8344, 0x8346, 0x8348, 0x8383, 0x8385, 0x8387, 0x8362, + 0x815b, 0x8341, 0x8343, 0x8345, 0x8347, 0x8349, 0x834a, 0x834c, + 0x834e, 0x8350, 0x8352, 0x8354, 0x8356, 0x8358, 0x835a, 0x835c, + 0x835e, 0x8360, 0x8363, 0x8365, 0x8367, 0x8369, 0x836a, 0x836b, + 0x836c, 0x836d, 0x836e, 0x8371, 0x8374, 0x8377, 0x837a, 0x837d, + 0x837e, 0x8380, 0x8381, 0x8382, 0x8384, 0x8386, 0x8388, 0x8389, + 0x838a, 0x838b, 0x838c, 0x838d, 0x838f, 0x8393, 0x814a, 0x814b +}; +static unsigned char zen_to_han_kana_table[0x8396-0x8340+1] = { + 0xa7, 0xb1, 0xa8, 0xb2, 0xa9, 0xb3, 0xaa, 0xb4, + 0xab, 0xb5, 0xb6, 0xb6, 0xb7, 0xb7, 0xb8, 0xb8, + 0xb9, 0xb9, 0xba, 0xba, 0xbb, 0xbb, 0xbc, 0xbc, + 0xbd, 0xbd, 0xbe, 0xbe, 0xbf, 0xbf, 0xc0, 0xc0, + 0xc1, 0xc1, 0xaf, 0xc2, 0xc2, 0xc3, 0xc3, 0xc4, + 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xca, + 0xca, 0xcb, 0xcb, 0xcb, 0xcc, 0xcc, 0xcc, 0xcd, + 0xcd, 0xcd, 0xce, 0xce, 0xce, 0xcf, 0xd0, 0, + 0xd1, 0xd2, 0xd3, 0xac, 0xd4, 0xad, 0xd5, 0xae, + 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdc, + 0xb2, 0xb4, 0xa6, 0xdd, 0xb3, 0xb6, 0xb9 +}; +#define ZTOH_SYMBOLS 9 +static unsigned short zen_to_han_symbol_table_1[ZTOH_SYMBOLS] = { + 0x8142, 0x8175, 0x8176, 0x8141, 0x8145, 0x815b, 0x814a, 0x814b +}; +static unsigned char zen_to_han_symbol_table_2[ZTOH_SYMBOLS] = { + 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xb0, 0xde, 0xdf +}; +#define ISKANA(c) ((c) >= 0xa1 && (c) <= 0xdf) +#define JISHIRA(c) ((c) >= 0x829f && (c) <= 0x82f1) +#define JISKANA(c) ((c) >= 0x8340 && (c) <= 0x8396 && (c) != 0x837f) +#define JTOKANA(c) ((c) <= 0x82dd ? (c) + 0xa1 : (c) + 0xa2) + + +unsigned short _mbbtombc(unsigned short c) +{ + if (c >= 0x20 && c <= 0x7e) { + return han_to_zen_ascii_table[c - 0x20]; + } else if (ISKANA(c)) { + return han_to_zen_kana_table[c - 0xa0]; + } + return c; +} + + +unsigned short _mbctombb(unsigned short c) +{ + int i; + unsigned short *p; + + if (JISKANA(c)) { + return zen_to_han_kana_table[c - 0x8340]; + } else if (JISHIRA(c)) { + c = JTOKANA(c); + return zen_to_han_kana_table[c - 0x8340]; + } else if (c <= 0x8396) { + for (i = 0x20, p = han_to_zen_ascii_table; i <= 0x7e; i++, p++) { + if (*p == c) { + return i; + } + } + for (i = 0; i < ZTOH_SYMBOLS; i++) { + if (zen_to_han_symbol_table_1[i] == c) { + return zen_to_han_symbol_table_2[i]; + } + } + } + return c; +} + + + diff --git a/reactos/lib/msvcrt/mbstring/ischira.c b/reactos/lib/msvcrt/mbstring/ischira.c new file mode 100644 index 00000000000..bb37baf683d --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ischira.c @@ -0,0 +1,32 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/ischira.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include +#include + +int _ismbchira( unsigned int c ) +{ + return ((c>=0x829F) && (c<=0x82F1)); +} + +int _ismbckata( unsigned int c ) +{ + return ((c>=0x8340) && (c<=0x8396)); +} + +unsigned int _mbctohira( unsigned int c ) +{ + return c; +} + +unsigned int _mbctokata( unsigned int c ) +{ + return c; +} diff --git a/reactos/lib/msvcrt/mbstring/iskana.c b/reactos/lib/msvcrt/mbstring/iskana.c new file mode 100644 index 00000000000..ef6908fa4bc --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/iskana.c @@ -0,0 +1,17 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/hanzen.c + * PURPOSE: Checks for kana character + * PROGRAMER: Boudewijn Dekker, Taiji Yamada + * UPDATE HISTORY: + Modified from Taiji Yamada japanese code system utilities + * 12/04/99: Created + */ +#include +#include + +int _ismbbkana(unsigned char c) +{ + return ((_jctype+1)[(unsigned char)(c)] & (_KNJ_M|_KNJ_P)); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/iskmoji.c b/reactos/lib/msvcrt/mbstring/iskmoji.c new file mode 100644 index 00000000000..a8cc1745bf8 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/iskmoji.c @@ -0,0 +1,6 @@ +#include + +int _ismbbkalpha(unsigned char c) +{ + return (0xA7 <= c <= 0xDF); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/iskpun.c b/reactos/lib/msvcrt/mbstring/iskpun.c new file mode 100644 index 00000000000..e0d97c727fb --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/iskpun.c @@ -0,0 +1,15 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/iskpun.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include + +int _ismbbkpunct( unsigned int c ) +{ + return ((_jctype+1)[(unsigned char)(c)] & (_KNJ_P)); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/islead.c b/reactos/lib/msvcrt/mbstring/islead.c new file mode 100644 index 00000000000..d5560cf4b5d --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/islead.c @@ -0,0 +1,8 @@ +#include +#include + +int isleadbyte(char *mbstr) +{ + return 0; + //return IsDBCSLeadByteEx(0,*c); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/islwr.c b/reactos/lib/msvcrt/mbstring/islwr.c new file mode 100644 index 00000000000..01c9cf43092 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/islwr.c @@ -0,0 +1,23 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsncmp.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include +#include + +// code page 952 only +int _ismbclower( unsigned int c ) +{ + if ((c & 0xFF00) != 0) { + if ( c >= 0x829A && c<= 0x829A ) + return 1; + } + + return islower(c); +} diff --git a/reactos/lib/msvcrt/mbstring/ismbal.c b/reactos/lib/msvcrt/mbstring/ismbal.c new file mode 100644 index 00000000000..9b3b65bf8ad --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismbal.c @@ -0,0 +1,16 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/hanzen.c + * PURPOSE: Checks for alphabetic multibyte character + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include +#include + +int _ismbbalpha(unsigned char c) +{ + return (isalpha(c) || _ismbbkalnum(c)); +} diff --git a/reactos/lib/msvcrt/mbstring/ismbaln.c b/reactos/lib/msvcrt/mbstring/ismbaln.c new file mode 100644 index 00000000000..01509c6e4b0 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismbaln.c @@ -0,0 +1,8 @@ +#include +#include + + +int _ismbbalnum(unsigned char c) +{ + return (isalnum(c) || _ismbbkalnum(c)); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/ismbc.c b/reactos/lib/msvcrt/mbstring/ismbc.c new file mode 100644 index 00000000000..cae3463de46 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismbc.c @@ -0,0 +1,105 @@ +#include + +int _ismbbalpha(unsigned char c); +int _ismbbalnum(unsigned char c); + +int _ismbcalnum( unsigned int c ) +{ + if ((c & 0xFF00) != 0) { + // true multibyte character + return 0; + } + else + return _ismbbalnum(c); + + return 0; +} + +int _ismbcalpha( unsigned int c ) +{ + if ((c & 0xFF00) != 0) { + // true multibyte character + return 0; + } + else + return _ismbbalpha(c); + + return 0; +} + +int _ismbcdigit( unsigned int c ) +{ + if ((c & 0xFF00) != 0) { + // true multibyte character + return 0; + } + else + return 0; +// return _ismbbdigit(c); + + return 0; +} + +int _ismbcprint( unsigned int c ) +{ + if ((c & 0xFF00) != 0) { + // true multibyte character + return 0; + } + else + return 0; +// return _ismbbdigit(c); + + return 0; +} + +int _ismbcsymbol( unsigned int c ) +{ + if ((c & 0xFF00) != 0) { + // true multibyte character + return 0; + } + else + return 0; +// return _ismbbdigit(c); + + return 0; +} + +int _ismbcspace( unsigned int c ) +{ + if ((c & 0xFF00) != 0) { + // true multibyte character + return 0; + } + else + return 0; +// return _ismbbdigit(c); + + return 0; +} +int _ismbclegal(unsigned int c) +{ + if ((c & 0xFF00) != 0) { + return _ismbblead(c>>8) && _ismbbtrail(c&0xFF); + } + else + return _ismbbtrail(c&0xFF); + + return 0; +} + +int _ismbcl0(unsigned int c) +{ + return 0; +} + +int _ismbcl1(unsigned int c) +{ + return 0; +} + +int _ismbcl2(unsigned int c) +{ + return 0; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/ismbgra.c b/reactos/lib/msvcrt/mbstring/ismbgra.c new file mode 100644 index 00000000000..ca458d60a65 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismbgra.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int _ismbbgraph(unsigned char c) +{ + return (isgraph(c) || _ismbbkana(c)); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/ismbkaln.c b/reactos/lib/msvcrt/mbstring/ismbkaln.c new file mode 100644 index 00000000000..8a5d639d105 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismbkaln.c @@ -0,0 +1,16 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/iskpun.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include +#include + +int _ismbbkalnum( unsigned int c ) +{ + return ((_jctype+1)[(unsigned char)(c)] & (_KNJ_P)); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/ismblead.c b/reactos/lib/msvcrt/mbstring/ismblead.c new file mode 100644 index 00000000000..f15f3ec6248 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismblead.c @@ -0,0 +1,59 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/ismblead.c + * PURPOSE: Checks for a lead byte + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * Modified from Taiji Yamada japanese code system utilities + * 12/04/99: Created + */ + +#include +#include +#include + +size_t _mbclen2(const unsigned int s); + +char _jctype[257] = { +/*-1*/ ___, +/*0x*/ ___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,___, +/*1x*/ ___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,___, +/*2x*/ ___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,___, +/*3x*/ ___,___,___,___,___,___,___,___,___,___,___,___,___,___,___,___, +/*4x*/ __2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2, +/*5x*/ __2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2, +/*6x*/ __2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2, +/*7x*/ __2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,__2,___, +/*8x*/ __2,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12, +/*9x*/ _12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12, +/*Ax*/ __2,_P2,_P2,_P2,_P2,_P2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2, +/*Bx*/ _M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2, +/*Cx*/ _M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2, +/*Dx*/ _M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2,_M2, +/*Ex*/ _12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12, +/*Fx*/ _12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,_12,___,___,___ +}; + +char *_mbctype = _jctype; +int _ismbblead(unsigned int c) +{ + return ((_jctype+1)[(unsigned char)(c)] & _KNJ_1); +} +//int _ismbblead(unsigned int byte) +//{ +// +// return (int)IsDBCSLeadByte(byte) +//} + +int _ismbslead( const unsigned char *str, const unsigned char *t) +{ + unsigned char *s = (unsigned char *)str; + while(*s != 0 && s != t) + { + + s+= _mbclen2(*s); + } + return _ismbblead( *s); +} + diff --git a/reactos/lib/msvcrt/mbstring/ismbpri.c b/reactos/lib/msvcrt/mbstring/ismbpri.c new file mode 100644 index 00000000000..c6d9bf6bf9c --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismbpri.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int _ismbbprint(unsigned char c) +{ + return (isprint(c) || _ismbbkana(c)); +} diff --git a/reactos/lib/msvcrt/mbstring/ismbpun.c b/reactos/lib/msvcrt/mbstring/ismbpun.c new file mode 100644 index 00000000000..15edc80ffd7 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismbpun.c @@ -0,0 +1,13 @@ + + //iskana() :(0xA1 <= c <= 0xDF) + //iskpun() :(0xA1 <= c <= 0xA6) + //iskmoji() :(0xA7 <= c <= 0xDF) +#include +#include +#include + +int _ismbbpunct(unsigned char c) +{ +// (0xA1 <= c <= 0xA6) + return (ispunct(c) || _ismbbkana(c)); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/ismbtrl.c b/reactos/lib/msvcrt/mbstring/ismbtrl.c new file mode 100644 index 00000000000..067005a6756 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/ismbtrl.c @@ -0,0 +1,39 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/ismbtrail.c + * PURPOSE: Checks for a trailing byte + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include +#include + +size_t _mbclen2(const unsigned int s); + +// iskanji2() : (0x40 <= c <= 0x7E 0x80 <= c <= 0xFC) + +int _ismbbtrail(unsigned int c) +{ + return ((_jctype+1)[(unsigned char)(c)] & _KNJ_2); +} + +//int _ismbbtrail( unsigned int b) +//{ +// return ((b >= 0x40 && b <= 0x7e ) || (b >= 0x80 && b <= 0xfc ) ); +//} + + +int _ismbstrail( const unsigned char *str, const unsigned char *t) +{ + unsigned char *s = (unsigned char *)str; + while(*s != 0 && s != t) + { + + s+= _mbclen2(*s); + } + + return _ismbbtrail(*s); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/isuppr.c b/reactos/lib/msvcrt/mbstring/isuppr.c new file mode 100644 index 00000000000..110b9a828a0 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/isuppr.c @@ -0,0 +1,23 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsncmp.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include +#include + +// code page 952 only +int _ismbcupper( unsigned int c ) +{ + if ((c & 0xFF00) != 0) { + if ( c >= 0x8260 && c<= 0x8279 ) + return 1; + } + + return isupper(c); +} diff --git a/reactos/lib/msvcrt/mbstring/jistojms.c b/reactos/lib/msvcrt/mbstring/jistojms.c new file mode 100644 index 00000000000..188905bbc85 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/jistojms.c @@ -0,0 +1,24 @@ +#include + +unsigned short _mbcjistojms(unsigned short c) +{ + int c1, c2; + + c2 = (unsigned char)c; + c1 = c >> 8; + if (c1 >= 0x21 && c1 <= 0x7e && c2 >= 0x21 && c2 <= 0x7e) { + if (c1 & 0x01) { + c2 += 0x1f; + if (c2 >= 0x7f) + c2 ++; + } else { + c2 += 0x7e; + } + c1 += 0xe1; + c1 >>= 1; + if (c1 >= 0xa0) + c1 += 0x40; + return ((c1 << 8) | c2); + } + return 0; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/jmstojis.c b/reactos/lib/msvcrt/mbstring/jmstojis.c new file mode 100644 index 00000000000..d53888e4aca --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/jmstojis.c @@ -0,0 +1,25 @@ +#include + +unsigned short _mbcjmstojis(unsigned short c) +{ + int c1, c2; + + c2 = (unsigned char)c; + c1 = c >> 8; + if (c1 < 0xf0 && _ismbblead(c1) && _ismbbtrail(c2)) { + if (c1 >= 0xe0) + c1 -= 0x40; + c1 -= 0x70; + c1 <<= 1; + if (c2 < 0x9f) { + c1 --; + c2 -= 0x1f; + if (c2 >= (0x80-0x1f)) + c2 --; + } else { + c2 -= 0x7e; + } + return ((c1 << 8) | c2); + } + return 0; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbbtype.c b/reactos/lib/msvcrt/mbstring/mbbtype.c new file mode 100644 index 00000000000..85e605abef4 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbbtype.c @@ -0,0 +1,48 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbbtype.c + * PURPOSE: Determines the type of a multibyte character + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include +#include + +int _mbbtype(unsigned char c , int type) +{ + if (type == 1) + { + if ((c >= 0x40 && c <= 0x7e) || (c >= 0x80 && c <= 0xfc)) + { + return _MBC_TRAIL; + } + else if ((c >= 0x20 && c >= 0x7E) || (c >= 0xA1 && c <= 0xDF) || + (c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFC)) + return _MBC_ILLEGAL; + else + return 0; + } + else + { + if ((c >= 0x20 && c <= 0x7E) || (c >= 0xA1 && c <= 0xDF )) + return _MBC_SINGLE; + else if ((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFC)) + return _MBC_LEAD; + else if ((c >= 0x20 && c >= 0x7E) || (c >= 0xA1 && c <= 0xDF) || + (c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFC)) + return _MBC_ILLEGAL; + else + return 0; + } + return 0; +} + +int _mbsbtype( const unsigned char *str, size_t n ) +{ + if (str == NULL) + return -1; + return _mbbtype(*(str+n),1); +} diff --git a/reactos/lib/msvcrt/mbstring/mbccpy.c b/reactos/lib/msvcrt/mbstring/mbccpy.c new file mode 100644 index 00000000000..7dcb2887256 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbccpy.c @@ -0,0 +1,12 @@ +#include +#include + +size_t _mbclen2(const unsigned int s); + +void _mbccpy(unsigned char *dst, const unsigned char *src) +{ + if (!_ismbblead(*src) ) + return; + + memcpy(dst,src,_mbclen2(*src)); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbclen.c b/reactos/lib/msvcrt/mbstring/mbclen.c new file mode 100644 index 00000000000..389aa07cee7 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbclen.c @@ -0,0 +1,30 @@ + +#include +#include + + +size_t _mbclen(const unsigned char *s) +{ + return (_ismbblead(*s>>8) && _ismbbtrail(*s&0x00FF)) ? 2 : 1; +} + +size_t _mbclen2(const unsigned int s) +{ + return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1; +} + +// assume MB_CUR_MAX == 2 +int mblen( const char *s, size_t count ) +{ + size_t l; + if ( s == NULL ) + return 0; + + l = _mbclen(s); + if ( l < count ) + return -1; + return l; +} + + + diff --git a/reactos/lib/msvcrt/mbstring/mbscat.c b/reactos/lib/msvcrt/mbstring/mbscat.c new file mode 100644 index 00000000000..0ab0872299d --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbscat.c @@ -0,0 +1,6 @@ +#include + +unsigned char * _mbscat(unsigned char *dst, const unsigned char *src) +{ + return strcat(dst,src); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbschr.c b/reactos/lib/msvcrt/mbstring/mbschr.c new file mode 100644 index 00000000000..33b6d49b319 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbschr.c @@ -0,0 +1,6 @@ +#include + +unsigned char * _mbschr(const unsigned char *str, unsigned int c) +{ + return strchr(str,c); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbscmp.c b/reactos/lib/msvcrt/mbstring/mbscmp.c new file mode 100644 index 00000000000..86c05c24fe9 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbscmp.c @@ -0,0 +1,7 @@ +#include +#include + +int _mbscmp(const unsigned char *str1, const unsigned char *str2) +{ + return strcmp(str1,str2); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbscoll.c b/reactos/lib/msvcrt/mbstring/mbscoll.c new file mode 100644 index 00000000000..dad12be050b --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbscoll.c @@ -0,0 +1,97 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbscoll.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +int colldif(unsigned short c1, unsigned short c2); + +int _mbscoll(const unsigned char *str1, const unsigned char *str2) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + int l1, l2; + + while ( *s1 != 0 ) { + + if (*s1 == 0) + break; + + l1 = _ismbblead(*s1); + l2 = _ismbblead(*s2); + if ( !l1 && !l2 ) { + + if (*s1 != *s2) + return colldif(*s1, *s2); + else { + s1 += 1; + s2 += 1; + } + } + else if ( l1 && l2 ){ + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + if ( *short_s1 != *short_s2 ) + return colldif(*short_s1, *short_s2); + else { + s1 += 2; + s2 += 2; + + } + } + else + return colldif(*s1, *s2); + } ; + return 0; +} + +#if 0 +int _mbsbcoll(const unsigned char *str1, const unsigned char *str2) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + int l1, l2; + + + while ( *s1 != 0 ) { + + + l1 = _ismbblead(*s1); + l2 = _ismbblead(*s2); + if ( !l1 && !l2 ) { + + if (*s1 != *s2) + return colldif(*s1, *s2); + else { + s1 += 1; + s2 += 1; + } + } + else if ( l1 && l2 ){ + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + if ( *short_s1 != *short_s2 ) + return colldif(*short_s1, *short_s2); + else { + s1 += 2; + s2 += 2; + } + } + else + return colldif(*s1, *s2); + } ; + return 0; +} +#endif diff --git a/reactos/lib/msvcrt/mbstring/mbscpy.c b/reactos/lib/msvcrt/mbstring/mbscpy.c new file mode 100644 index 00000000000..c29b10e5931 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbscpy.c @@ -0,0 +1,7 @@ +#include +#include + +unsigned char * _mbscpy(unsigned char *dst, const unsigned char *str) +{ + return strcpy(dst,str); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbscspn.c b/reactos/lib/msvcrt/mbstring/mbscspn.c new file mode 100644 index 00000000000..46783ee21fc --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbscspn.c @@ -0,0 +1,19 @@ +#include + +// not correct +size_t _mbscspn(const unsigned char *s1, const unsigned char *s2) +{ + const char *p, *spanp; + char c, sc; + + for (p = s1;;) + { + c = *p++; + spanp = s2; + do { + if ((sc = *spanp++) == c) + return (size_t)(p - 1) - (size_t)s1; + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/reactos/lib/msvcrt/mbstring/mbsdec.c b/reactos/lib/msvcrt/mbstring/mbsdec.c new file mode 100644 index 00000000000..ba94cf6f862 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsdec.c @@ -0,0 +1,14 @@ +#include + +unsigned char * _mbsdec(const unsigned char *str, const unsigned char *cur) +{ + unsigned char *s = (unsigned char *)cur; + if ( str >= cur ) + return NULL; + + s--; + if (_ismbblead(*(s-1)) ) + s--; + + return s; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsdup.c b/reactos/lib/msvcrt/mbstring/mbsdup.c new file mode 100644 index 00000000000..9195f389b21 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsdup.c @@ -0,0 +1,25 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/hanzen.c + * PURPOSE: Duplicates a multi byte string + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + Modified from DJGPP strdup + * 12/04/99: Created + */ + +#include +#include + +unsigned char * _mbsdup(const unsigned char *_s) +{ + char *rv; + if (_s == 0) + return 0; + rv = (char *)malloc(_mbslen(_s) + 1); + if (rv == 0) + return 0; + _mbscpy(rv, _s); + return rv; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsicmp.c b/reactos/lib/msvcrt/mbstring/mbsicmp.c new file mode 100644 index 00000000000..dbd861f584d --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsicmp.c @@ -0,0 +1,62 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsicmp.c + * PURPOSE: Duplicates a multi byte string + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include +#include +#include + +int _mbsicmp(const unsigned char *str1, const unsigned char *str2) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + int l1, l2; + + do { + + if (*s1 == 0) + break; + + l1 = _ismbblead(*s1); + l2 = _ismbblead(*s2); + if ( !l1 && !l2 ) { + + if (toupper(*s1) != toupper(*s2)) + return toupper(*s1) - toupper(*s2); + else { + s1 += 1; + s2 += 1; + } + } + else if ( l1 && l2 ){ + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + if ( _mbctoupper(*short_s1) != _mbctoupper(*short_s2 )) + return _mbctoupper(*short_s1) - _mbctoupper(*short_s2); + else { + s1 += 2; + s2 += 2; + } + } + else + return *s1 - *s2; + } while (*s1 != 0); + return 0; + + while (toupper(*s1) == toupper(*s2)) + { + if (*s1 == 0) + return 0; + s1++; + s2++; + } + return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)(s2)); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsicoll.c b/reactos/lib/msvcrt/mbstring/mbsicoll.c new file mode 100644 index 00000000000..32020cc8348 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsicoll.c @@ -0,0 +1,55 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/iskpun.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include +#include +#include + +int colldif(unsigned short c1, unsigned short c2); +int _mbsicoll(const unsigned char *str1, const unsigned char *str2) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + int l1, l2; + + while ( *s1 != 0 ) { + + if (*s1 == 0) + break; + + l1 = _ismbblead(*s1); + l2 = _ismbblead(*s2); + if ( !l1 && !l2 ) { + + if (toupper(*s1) != toupper(*s2)) + return colldif(*s1, *s2); + else { + s1 += 1; + s2 += 1; + } + } + else if ( l1 && l2 ){ + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + if ( _mbctoupper(*short_s1) != _mbctoupper(*short_s2 )) + return colldif(*short_s1, *short_s2); + else { + s1 += 2; + s2 += 2; + + } + } + else + return colldif(*s1, *s2); + } ; + return 0; +} diff --git a/reactos/lib/msvcrt/mbstring/mbsinc.c b/reactos/lib/msvcrt/mbstring/mbsinc.c new file mode 100644 index 00000000000..30e42e9e22d --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsinc.c @@ -0,0 +1,10 @@ +#include + +unsigned char * _mbsinc(const unsigned char *s) +{ + unsigned char *c = (unsigned char *)s; + if (_ismbblead(*s) ) + c++; + c++; + return c; +} diff --git a/reactos/lib/msvcrt/mbstring/mbslen.c b/reactos/lib/msvcrt/mbstring/mbslen.c new file mode 100644 index 00000000000..f656819c1c6 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbslen.c @@ -0,0 +1,15 @@ +#include + +size_t _mbclen2(const unsigned int s); + +size_t _mbslen(const unsigned char *str) +{ + int i = 0; + unsigned char *s; + + if (str == 0) + return 0; + + for (s = (unsigned char *)str; *s; s+=_mbclen2(*s),i++); + return i; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbslwr.c b/reactos/lib/msvcrt/mbstring/mbslwr.c new file mode 100644 index 00000000000..0b405fdb054 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbslwr.c @@ -0,0 +1,45 @@ +#include +#include + +unsigned int _mbbtolower(unsigned int c) +{ + if (!_ismbblead(c) ) + return tolower(c); + return c; +} + +// code page 952 +#define CASE_DIFF (0x8281 - 0x8260) + +unsigned int _mbctolower(unsigned int c) +{ + if ((c & 0xFF00) != 0) + { + // true multibyte case conversion needed + if (_ismbclower(c)) + return c + CASE_DIFF; + } + else + return _mbbtolower(c); + + return 0; +} + +unsigned char * _mbslwr(unsigned char *x) +{ + unsigned char *y=x; + + while (*y) + { + if (!_ismbblead(*y)) + { + *y = tolower(*y); + } + else + { + *y=_mbctolower(*(unsigned short *)y); + y++; + } + } + return x; +} diff --git a/reactos/lib/msvcrt/mbstring/mbsncat.c b/reactos/lib/msvcrt/mbstring/mbsncat.c new file mode 100644 index 00000000000..22bee368174 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsncat.c @@ -0,0 +1,58 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsset.c + * PURPOSE: Concatenate two multi byte string to maximum of n characters or bytes + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include +#include + +size_t _mbclen2(const unsigned int s); + +unsigned char * _mbsncat(unsigned char *dst, const unsigned char *src, size_t n) +{ + char *d = (char *)dst; + char *s = (char *)src; + if (n != 0) { + d = dst + strlen(dst); // get the end of string + d += _mbclen2(*d); // move 1 or 2 up + + do { + if ((*d++ = *s++) == 0) + { + while (--n != 0) + *d++ = 0; + break; + } + if (!_ismbblead(*s) ) + n--; + } while (n > 0); + } + return dst; +} + +unsigned char * _mbsnbcat(unsigned char *dst, const unsigned char *src, size_t n) +{ + char *d; + char *s = (char *)src; + if (n != 0) { + d = dst + strlen(dst); // get the end of string + d += _mbclen2(*d); // move 1 or 2 up + + do { + if ((*d++ = *s++) == 0) + { + while (--n != 0) + *d++ = 0; + break; + } + if ( !(n==1 && _ismbblead(*s)) ) + n--; + } while (n > 0); + } + return dst; +} diff --git a/reactos/lib/msvcrt/mbstring/mbsnccnt.c b/reactos/lib/msvcrt/mbstring/mbsnccnt.c new file mode 100644 index 00000000000..d1052b2f308 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsnccnt.c @@ -0,0 +1,29 @@ +#include + +size_t _mbsnccnt(const unsigned char *str, size_t n) +{ + unsigned char *s = (unsigned char *)str; + size_t cnt = 0; + while(*s != 0 && n > 0) { + if (_ismbblead(*s) ) + s++; + else + n--; + s++; + cnt++; + } + + return cnt; +} + +size_t _mbsnbcnt(const unsigned char *str, size_t n) +{ + unsigned char *s = (unsigned char *)str; + while(*s != 0 && n > 0) { + if (!_ismbblead(*s) ) + n--; + s++; + } + + return (size_t)(s - str); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsncmp.c b/reactos/lib/msvcrt/mbstring/mbsncmp.c new file mode 100644 index 00000000000..9e3fc8e60c7 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsncmp.c @@ -0,0 +1,103 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsncmp.c + * PURPOSE: Compares two strings to a maximum of n bytes or characters + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +int _mbsncmp(const unsigned char *str1, const unsigned char *str2, size_t n) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + int l1, l2; + + if (n == 0) + return 0; + do { + + if (*s1 == 0) + break; + + l1 = _ismbblead(*s1); + l2 = _ismbblead(*s2); + if ( !l1 && !l2 ) { + + if (*s1 != *s2) + return *s1 - *s2; + else { + s1 += 1; + s2 += 1; + n--; + } + } + else if ( l1 && l2 ){ + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + if ( *short_s1 != *short_s2 ) + return *short_s1 - *short_s2; + else { + s1 += 2; + s2 += 2; + n--; + + } + } + else + return *s1 - *s2; + } while (n > 0); + return 0; +} + +int _mbsnbcmp(const unsigned char *str1, const unsigned char *str2, size_t n) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + int l1, l2; + + if (n == 0) + return 0; + do { + + if (*s1 == 0) + break; + + l1 = _ismbblead(*s1); + l2 = _ismbblead(*s2); + if ( !l1 && !l2 ) { + + if (*s1 != *s2) + return *s1 - *s2; + else { + s1 += 1; + s2 += 1; + n--; + } + } + else if ( l1 && l2 ){ + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + if ( *short_s1 != *short_s2 ) + return *short_s1 - *short_s2; + else { + s1 += 2; + s2 += 2; + n-=2; + + } + } + else + return *s1 - *s2; + } while (n > 0); + return 0; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsncoll.c b/reactos/lib/msvcrt/mbstring/mbsncoll.c new file mode 100644 index 00000000000..41573d6a832 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsncoll.c @@ -0,0 +1,109 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsncoll.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include + +int colldif(unsigned short c1, unsigned short c2); + +int _mbsncoll(const unsigned char *str1, const unsigned char *str2, size_t n) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + int l1, l2; + + if (n == 0) + return 0; + do { + + if (*s1 == 0) + break; + + l1 = _ismbblead(*s1); + l2 = _ismbblead(*s2); + if ( !l1 && !l2 ) { + + if (*s1 != *s2) + return colldif(*s1, *s2); + else { + s1 += 1; + s2 += 1; + n--; + } + } + else if ( l1 && l2 ){ + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + if ( *short_s1 != *short_s2 ) + return colldif(*short_s1, *short_s2); + else { + s1 += 2; + s2 += 2; + n--; + + } + } + else + return colldif(*s1, *s2); + } while (n > 0); + return 0; +} + +int _mbsnbcoll(const unsigned char *str1, const unsigned char *str2, size_t n) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + int l1, l2; + + if (n == 0) + return 0; + do { + + if (*s1 == 0) + break; + + l1 = _ismbblead(*s1); + l2 = _ismbblead(*s2); + if ( !l1 && !l2 ) { + + if (*s1 != *s2) + return colldif(*s1, *s2); + else { + s1 += 1; + s2 += 1; + n--; + } + } + else if ( l1 && l2 ){ + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + if ( *short_s1 != *short_s2 ) + return colldif(*short_s1, *short_s2); + else { + s1 += 2; + s2 += 2; + n-=2; + + } + } + else + return colldif(*s1, *s2); + } while (n > 0); + return 0; +} + +int colldif(unsigned short c1, unsigned short c2) +{ + return c1 - c2; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsncpy.c b/reactos/lib/msvcrt/mbstring/mbsncpy.c new file mode 100644 index 00000000000..dfce6489312 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsncpy.c @@ -0,0 +1,77 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsncpy.c + * PURPOSE: Copies a string to a maximum of n bytes or characters + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +unsigned char *_mbsncpy(unsigned char *str1, const unsigned char *str2, size_t n) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + if (n == 0) + return 0; + do { + + if (*s2 == 0) + break; + + if ( !_ismbblead(*s2) ) { + + *s1 = *s2; + s1 += 1; + s2 += 1; + n--; + } + else { + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + *short_s1 = *short_s2; + s1 += 2; + s2 += 2; + n--; + } + } while (n > 0); + return str1; +} + +unsigned char * _mbsnbcpy(unsigned char *str1, const unsigned char *str2, size_t n) +{ + unsigned char *s1 = (unsigned char *)str1; + unsigned char *s2 = (unsigned char *)str2; + + unsigned short *short_s1, *short_s2; + + if (n == 0) + return 0; + do { + + if (*s2 == 0) + break; + + if ( !_ismbblead(*s2) ) { + + *s1 = *s2; + s1 += 1; + s2 += 1; + n--; + } + else { + short_s1 = (unsigned short *)s1; + short_s2 = (unsigned short *)s2; + *short_s1 = *short_s2; + s1 += 2; + s2 += 2; + n-=2; + } + } while (n > 0); + return str1; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsnextc.c b/reactos/lib/msvcrt/mbstring/mbsnextc.c new file mode 100644 index 00000000000..9a1f825c46e --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsnextc.c @@ -0,0 +1,16 @@ +#include + +unsigned int _mbsnextc (const unsigned char *src) +{ + unsigned char *char_src = (unsigned char *)src; + unsigned short *short_src = (unsigned short *)src; + + if (src == NULL) + return 0; + + if (!_ismbblead(*src)) + return *char_src; + else + return *short_src; + return 0; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsnicmp.c b/reactos/lib/msvcrt/mbstring/mbsnicmp.c new file mode 100644 index 00000000000..7b54513dd17 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsnicmp.c @@ -0,0 +1,39 @@ +#include + +size_t _mbclen2(const unsigned int s); +unsigned int _mbbtoupper(unsigned int c); + +int _mbsnicmp(const unsigned char *s1, const unsigned char *s2, size_t n) +{ + if (n == 0) + return 0; + do { + if (_mbbtoupper(*s1) != _mbbtoupper(*s2)) + return _mbbtoupper(*(unsigned const char *)s1) - _mbbtoupper(*(unsigned const char *)s2); + s1 += _mbclen2(*s1); + s2 += _mbclen2(*s2); + + if (*s1 == 0) + break; + if (!_ismbblead(*s1)) + n--; + } while (n > 0); + return 0; +} + +int _mbsnbicmp(const unsigned char *s1, const unsigned char *s2, size_t n) +{ + if (n == 0) + return 0; + do { + if (_mbbtoupper(*s1) != _mbbtoupper(*s2)) + return _mbbtoupper(*(unsigned const char *)s1) - _mbbtoupper(*(unsigned const char *)s2); + s1 += _mbclen2(*s1); + s2 += _mbclen2(*s2); + + if (*s1 == 0) + break; + n--; + } while (n > 0); + return 0; +} diff --git a/reactos/lib/msvcrt/mbstring/mbsnicoll.c b/reactos/lib/msvcrt/mbstring/mbsnicoll.c new file mode 100644 index 00000000000..e79e5d29b78 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsnicoll.c @@ -0,0 +1,11 @@ +#include + +int _mbsnicoll(const unsigned char *s1, const unsigned char *s2, size_t n) +{ + return 0; +} + +int _mbsnbicoll(const unsigned char *s1, const unsigned char *s2, size_t n) +{ + return 0; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsninc.c b/reactos/lib/msvcrt/mbstring/mbsninc.c new file mode 100644 index 00000000000..09c5e4c41e1 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsninc.c @@ -0,0 +1,13 @@ +#include + +unsigned char * _mbsninc(const unsigned char *str, size_t n) +{ + unsigned char *s = (unsigned char *)str; + while(*s != 0 && n > 0) { + if (!_ismbblead(*s) ) + n--; + s++; + } + + return s; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsnset.c b/reactos/lib/msvcrt/mbstring/mbsnset.c new file mode 100644 index 00000000000..b762eef0aa0 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsnset.c @@ -0,0 +1,64 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsset.c + * PURPOSE: Fills a string with a multibyte character + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include + +size_t _mbclen2(const unsigned int s); + +unsigned char * _mbsnset(unsigned char *src, unsigned int val, size_t count) +{ + unsigned char *char_src = (unsigned char *)src; + unsigned short *short_src = (unsigned short *)src; + + if ( _mbclen2(val) == 1 ) { + + while(count > 0) { + *char_src = val; + char_src++; + count--; + } + *char_src = 0; + } + else { + while(count > 0) { + *short_src = val; + short_src++; + count-=2; + } + *short_src = 0; + } + + return src; +} + +unsigned char * _mbsnbset(unsigned char *src, unsigned int val, size_t count) +{ + unsigned char *char_src = (unsigned char *)src; + unsigned short *short_src = (unsigned short *)src; + + if ( _mbclen2(val) == 1 ) { + + while(count > 0) { + *char_src = val; + char_src++; + count--; + } + *char_src = 0; + } + else { + while(count > 0) { + *short_src = val; + short_src++; + count-=2; + } + *short_src = 0; + } + + return src; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbspbrk.c b/reactos/lib/msvcrt/mbstring/mbspbrk.c new file mode 100644 index 00000000000..f9566e7dd26 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbspbrk.c @@ -0,0 +1,16 @@ +#include + +// not correct +unsigned char * _mbspbrk(const unsigned char *s1, const unsigned char *s2) +{ + const char *scanp; + int c, sc; + + while ((c = *s1++) != 0) + { + for (scanp = s2; (sc = *scanp++) != 0;) + if (sc == c) + return (unsigned char *)((char *)s1 - (char *)1); + } + return 0; +} diff --git a/reactos/lib/msvcrt/mbstring/mbsrchr.c b/reactos/lib/msvcrt/mbstring/mbsrchr.c new file mode 100644 index 00000000000..3a2a8d61a29 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsrchr.c @@ -0,0 +1,30 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/mbstring/mbsrchr.c + * PURPOSE: Searches for a character in reverse + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ + +#include + +size_t _mbclen2(const unsigned int s); + +unsigned char * _mbsrchr(const unsigned char *src, unsigned int val) +{ + char *s = (char *)src; + short cc = val; + const char *sp=(char *)0; + + while (*s) + { + if (*(short *)s == cc) + sp = s; + s+= _mbclen2(*s); + } + if (cc == 0) + sp = s; + return (char *)sp; +} diff --git a/reactos/lib/msvcrt/mbstring/mbsrev.c b/reactos/lib/msvcrt/mbstring/mbsrev.c new file mode 100644 index 00000000000..bb372fd68eb --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsrev.c @@ -0,0 +1,28 @@ +#include + +unsigned char * _mbsrev(unsigned char *s) +{ + unsigned char *e; + unsigned char a; + e=s; + while (*e) { + if ( _ismbblead(*e) ) { + a = *e; + *e = *++e; + if ( *e == 0 ) + break; + *e = a; + } + e++; + } + while (s + +size_t _mbclen2(const unsigned int s); + +unsigned char * _mbsset(unsigned char *src, unsigned int c) +{ + unsigned char *char_src = src; + unsigned short *short_src = (unsigned short *)src; + + if ( _mbclen2(c) == 1 ) { + + while(*char_src != 0) { + *char_src = c; + char_src++; + } + *char_src = 0; + } + else { + while(*short_src != 0) { + *short_src = c; + short_src++; + } + *short_src = 0; + } + + return src; +} diff --git a/reactos/lib/msvcrt/mbstring/mbsspn.c b/reactos/lib/msvcrt/mbstring/mbsspn.c new file mode 100644 index 00000000000..796d90fc74c --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsspn.c @@ -0,0 +1,16 @@ +#include + +// not correct +size_t _mbsspn(const unsigned char *s1, const unsigned char *s2) +{ + const char *p = s1, *spanp; + char c, sc; + + cont: + c = *p++; + for (spanp = s2; (sc = *spanp++) != 0;) + if (sc == c) + goto cont; + return (size_t)(p - 1) - (size_t)s1; +// - (char *)s1); +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsspnp.c b/reactos/lib/msvcrt/mbstring/mbsspnp.c new file mode 100644 index 00000000000..7329ba5e35c --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsspnp.c @@ -0,0 +1,15 @@ +#include + +// not correct +unsigned char * _mbsspnp(const unsigned char *s1, const unsigned char *s2) +{ + const char *p = s1, *spanp; + char c, sc; + + cont: + c = *p++; + for (spanp = s2; (sc = *spanp++) != 0;) + if (sc == c) + goto cont; + return (unsigned char *)p; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsstr.c b/reactos/lib/msvcrt/mbstring/mbsstr.c new file mode 100644 index 00000000000..9af8248386d --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsstr.c @@ -0,0 +1,20 @@ +#include +#include + +unsigned char *_mbsstr(const unsigned char *src1,const unsigned char *src2) +{ + int len; + + if (src2 ==NULL || *src2 == 0) + return (unsigned char *)src1; + + len = _mbstrlen(src2); + + while(*src1) + { + if ((*src1 == *src2) && (_mbsncmp(src1,src2,len) == 0)) + return (unsigned char *)src1; + src1 = (unsigned char *)_mbsinc(src1); + } + return NULL; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbstok.c b/reactos/lib/msvcrt/mbstring/mbstok.c new file mode 100644 index 00000000000..84e0104e5a2 --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbstok.c @@ -0,0 +1,53 @@ +#include + +unsigned char * _mbstok(unsigned char *s, const unsigned char *delim) +{ + const char *spanp; + int c, sc; + char *tok; + static char *last; + + + if (s == NULL && (s = last) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += strspn(s, delim), sort of). + */ + cont: + c = *s; + s = _mbsinc(s); + + for (spanp = delim; (sc = *spanp) != 0; spanp = _mbsinc(spanp)) { + if (c == sc) + goto cont; + } + + if (c == 0) { /* no non-delimiter characters */ + last = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s; + s = _mbsinc(s); + spanp = delim; + do { + if ((sc = *spanp) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + last = s; + return (tok); + } + spanp = _mbsinc(spanp); + } while (sc != 0); + } + /* NOTREACHED */ +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbstrlen.c b/reactos/lib/msvcrt/mbstring/mbstrlen.c new file mode 100644 index 00000000000..ad9631c176a --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbstrlen.c @@ -0,0 +1,16 @@ +#include +#include + +size_t _mbstrlen( const char *string ) +{ + char *s = (char *)string; + size_t i = 0; + + while ( *s != 0 ) { + if ( _ismbblead(*s) ) + s++; + s++; + i++; + } + return i; +} \ No newline at end of file diff --git a/reactos/lib/msvcrt/mbstring/mbsupr.c b/reactos/lib/msvcrt/mbstring/mbsupr.c new file mode 100644 index 00000000000..3c937164b6f --- /dev/null +++ b/reactos/lib/msvcrt/mbstring/mbsupr.c @@ -0,0 +1,50 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/msvcrt/mbstring/mbsupr.c + * PURPOSE: + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 12/04/99: Created + */ +#include +#include + +unsigned int _mbbtoupper(unsigned int c) +{ + if (!_ismbblead(c) ) + return toupper(c); + + return c; +} + +// codepage 952 +#define CASE_DIFF (0x8281 - 0x8260) + +unsigned int _mbctoupper(unsigned int c) +{ + + if ((c & 0xFF00) != 0) { +// true multibyte case conversion needed + if ( _ismbcupper(c) ) + return c + CASE_DIFF; + + } else + return _mbbtoupper(c); + + return 0; +} + +unsigned char * _mbsupr(unsigned char *x) +{ + unsigned char *y=x; + while (*y) { + if (!_ismbblead(*y) ) + *y = toupper(*y); + else { + *y=_mbctoupper(*(unsigned short *)y); + y++; + } + } + return x; +} \ No newline at end of file