Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

555 lines
14 KiB

  1. /***
  2. *tchar.h - definitions for generic international text functions
  3. *
  4. * Copyright (c) 1991-1993, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Definitions for generic international functions, mostly defines
  8. * which map string/formatted-io/ctype functions to char, wchar_t, or
  9. * MBCS versions. To be used for compatibility between single-byte,
  10. * multi-byte and Unicode text models.
  11. *
  12. *
  13. *
  14. ****/
  15. #ifndef _INC_TCHAR
  16. #ifdef _MSC_VER
  17. #pragma warning(disable:4505) /* disable unwanted C++ /W4 warning */
  18. /* #pragma warning(default:4505) */ /* use this to reenable, if necessary */
  19. #endif /* _MSC_VER */
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* No Model-independent functions under Win32 */
  24. #define __far
  25. /* Default for Win32 is no inlining. Define _USE_INLINING to overide */
  26. #ifndef _USE_INLINING
  27. #define _NO_INLINING
  28. #endif
  29. /* No model-independent string functions for Win32 */
  30. #define _ftcscat _tcscat
  31. #define _ftcschr _tcschr
  32. #define _ftcscmp _tcscmp
  33. #define _ftcscpy _tcscpy
  34. #define _ftcscspn _tcscspn
  35. #define _ftcslen _tcslen
  36. #define _ftcsncat _tcsncat
  37. #define _ftcsncmp _tcsncmp
  38. #define _ftcsncpy _tcsncpy
  39. #define _ftcspbrk _tcspbrk
  40. #define _ftcsrchr _tcsrchr
  41. #define _ftcsspn _tcsspn
  42. #define _ftcsstr _tcsstr
  43. #define _ftcstok _tcstok
  44. #define _ftcsdup _tcsdup
  45. #define _ftcsicmp _tcsicmp
  46. #define _ftcsnicmp _tcsnicmp
  47. #define _ftcsnset _tcsnset
  48. #define _ftcsrev _tcsrev
  49. #define _ftcsset _tcsset
  50. /* Redundant "logical-character" mappings */
  51. #define _ftcsclen _tcsclen
  52. #define _ftcsnccat _tcsnccat
  53. #define _ftcsnccpy _tcsnccpy
  54. #define _ftcsnccmp _tcsnccmp
  55. #define _ftcsncicmp _tcsncicmp
  56. #define _ftcsncset _tcsncset
  57. #define _ftcsdec _tcsdec
  58. #define _ftcsinc _tcsinc
  59. #define _ftcsnbcnt _tcsncnt
  60. #define _ftcsnccnt _tcsncnt
  61. #define _ftcsnextc _tcsnextc
  62. #define _ftcsninc _tcsninc
  63. #define _ftcsspnp _tcsspnp
  64. #define _ftcslwr _tcslwr
  65. #define _ftcsupr _tcsupr
  66. #define _ftclen _tclen
  67. #define _ftccpy _tccpy
  68. #define _ftccmp _tccmp
  69. #ifdef _UNICODE
  70. #ifndef _WCTYPE_T_DEFINED
  71. typedef wchar_t wint_t;
  72. typedef wchar_t wctype_t;
  73. #define _WCTYPE_T_DEFINED
  74. #endif
  75. #ifndef __TCHAR_DEFINED
  76. typedef wchar_t _TCHAR;
  77. typedef wint_t _TINT;
  78. #define __TCHAR_DEFINED
  79. #endif
  80. #ifndef _TCHAR_DEFINED
  81. #if !__STDC__
  82. typedef wchar_t TCHAR;
  83. #endif
  84. #define _TCHAR_DEFINED
  85. #endif
  86. #define _TEOF WEOF
  87. #define __T(x) L ## x
  88. /* Formatted i/o */
  89. #define _tprintf wprintf
  90. #define _ftprintf fwprintf
  91. #define _stprintf swprintf
  92. #define _sntprintf _snwprintf
  93. #define _vtprintf vwprintf
  94. #define _vftprintf vfwprintf
  95. #define _vstprintf vswprintf
  96. #define _vsntprintf _vsnwprintf
  97. #define _tscanf wscanf
  98. #define _ftscanf fwscanf
  99. #define _stscanf swscanf
  100. /* Unformatted i/o */
  101. #define _fgettc fgetwc
  102. #define _fgettchar _fgetwchar
  103. #define _fgetts fgetws
  104. #define _fputtc fputwc
  105. #define _fputtchar _fputwchar
  106. #define _fputts fputws
  107. #define _gettc getwc
  108. #define _gettchar getwchar
  109. #define _puttc putwc
  110. #define _puttchar putwchar
  111. #define _ungettc ungetwc
  112. /* String conversion functions */
  113. #define _tcstod wcstod
  114. #define _tcstol wcstol
  115. #define _tcstoul wcstoul
  116. /* String functions */
  117. #define _tcscat wcscat
  118. #define _tcschr wcschr
  119. #define _tcscmp wcscmp
  120. #define _tcscpy wcscpy
  121. #define _tcscspn wcscspn
  122. #define _tcslen wcslen
  123. #define _tcsncat wcsncat
  124. #define _tcsncmp wcsncmp
  125. #define _tcsncpy wcsncpy
  126. #define _tcspbrk wcspbrk
  127. #define _tcsrchr wcsrchr
  128. #define _tcsspn wcsspn
  129. #define _tcsstr wcsstr
  130. #define _tcstok wcstok
  131. #define _tcsdup _wcsdup
  132. #define _tcsicmp _wcsicmp
  133. #define _tcsnicmp _wcsnicmp
  134. #define _tcsnset _wcsnset
  135. #define _tcsrev _wcsrev
  136. #define _tcsset _wcsset
  137. /* Redundant "logical-character" mappings */
  138. #define _tcsclen wcslen
  139. #define _tcsnccat wcsncat
  140. #define _tcsnccpy wcsncpy
  141. #define _tcsnccmp wcsncmp
  142. #define _tcsncicmp _wcsnicmp
  143. #define _tcsncset _wcsnset
  144. #define _tcsdec _wcsdec
  145. #define _tcsinc _wcsinc
  146. #define _tcsnbcnt _wcsncnt
  147. #define _tcsnccnt _wcsncnt
  148. #define _tcsnextc _wcsnextc
  149. #define _tcsninc _wcsninc
  150. #define _tcsspnp _wcsspnp
  151. #define _tcslwr _wcslwr
  152. #define _tcsupr _wcsupr
  153. #define _tcsxfrm wcsxfrm
  154. #define _tcscoll wcscoll
  155. #define _tcsicoll _wcsicoll
  156. #if !__STDC__ || defined(_NO_INLINING)
  157. #define _tclen(_pc) (1)
  158. #define _tccpy(_pc1,_cpc2) ((*(_pc1) = *(_cpc2)))
  159. #define _tccmp(_cpc1,_cpc2) ((*(_cpc1))-(*(_cpc2)))
  160. #else
  161. __inline size_t _tclen(const wchar_t *_cpc) { return (_cpc,1); }
  162. __inline void _tccpy(wchar_t *_pc1, const wchar_t *_cpc2) { *_pc1 = (wchar_t)*_cpc2; }
  163. __inline int _tccmp(const wchar_t *_cpc1, const wchar_t *_cpc2) { return (int) ((*_cpc1)-(*_cpc2)); }
  164. #endif
  165. /* ctype functions */
  166. #define _istalpha iswalpha
  167. #define _istupper iswupper
  168. #define _istlower iswlower
  169. #define _istdigit iswdigit
  170. #define _istxdigit iswxdigit
  171. #define _istspace iswspace
  172. #define _istpunct iswpunct
  173. #define _istalnum iswalnum
  174. #define _istprint iswprint
  175. #define _istgraph iswgraph
  176. #define _istcntrl iswcntrl
  177. #define _istascii iswascii
  178. #define _totupper towupper
  179. #define _totlower towlower
  180. #define _istlegal (1)
  181. #if !__STDC__ || defined(_NO_INLINING)
  182. #define _wcsdec(_cpc, _pc) ((_pc)-1)
  183. #define _wcsinc(_pc) ((_pc)+1)
  184. #define _wcsnextc(_cpc) ((unsigned int) *(_cpc))
  185. #define _wcsninc(_pc, _sz) (((_pc)+(_sz)))
  186. #define _wcsncnt(_cpc, _sz) ((wcslen(_cpc)>_sz) ? _sz : wcslen(_cpc))
  187. #define _wcsspnp(_cpc1, _cpc2) ((*((_cpc1)+wcsspn(_cpc1,_cpc2))) ? ((_cpc1)+wcsspn(_cpc1,_cpc2)) : NULL)
  188. #else
  189. __inline wchar_t * _wcsdec(const wchar_t * _cpc, const wchar_t * _pc) { return (wchar_t *)(_cpc,(_pc-1)); }
  190. __inline wchar_t * _wcsinc(const wchar_t * _pc) { return (wchar_t *)(_pc+1); }
  191. __inline unsigned int _wcsnextc(const wchar_t * _cpc) { return (unsigned int)*_cpc; }
  192. __inline wchar_t * _wcsninc(const wchar_t * _pc, size_t _sz) { return (wchar_t *)(_pc+_sz); }
  193. __inline size_t _wcsncnt( const wchar_t * _cpc, size_t _sz) { size_t len; len = wcslen(_cpc); return (len>_sz) ? _sz : len; }
  194. __inline wchar_t * _wcsspnp( const wchar_t * _cpc1, const wchar_t * _cpc2) { return (*(_cpc1 += wcsspn(_cpc1,_cpc2))!='\0') ? (wchar_t*)_cpc1 : NULL; }
  195. #endif
  196. #else /* ndef _UNICODE */
  197. #if !defined(_CHAR_UNSIGNED) && !defined(_JWARNING_DEFINED)
  198. /* #pragma message("TCHAR.H: Warning: The /J option is recommended for international compilation") */
  199. #define _JWARNING_DEFINED
  200. #endif
  201. #include <string.h>
  202. #define __T(x) x
  203. /* Formatted i/o */
  204. #define _tprintf printf
  205. #define _ftprintf fprintf
  206. #define _stprintf sprintf
  207. #define _sntprintf _snprintf
  208. #define _vtprintf vprintf
  209. #define _vftprintf vfprintf
  210. #define _vstprintf vsprintf
  211. #define _vsntprintf _vsnprintf
  212. #define _tscanf scanf
  213. #define _ftscanf fscanf
  214. #define _stscanf sscanf
  215. /* Unformatted i/o */
  216. #define _fgettc(_f) (_TINT)fgetc((_f))
  217. #define _fgettchar (_TINT)_fgetchar
  218. #define _fgetts(_s,_i,_f) fgets((_s),(_i),(_f))
  219. #define _fputtc(_i,_f) (_TINT)fputc((int)(_i),(_f))
  220. #define _fputtchar(_i) (_TINT)_fputchar((int)(_i))
  221. #define _fputts(_s,_f) (_TINT)fputs((_s),(_f))
  222. #define _gettc(_f) (_TINT)getc((_f))
  223. #define _gettchar (_TINT)getchar
  224. #define _puttc(_i,_f) (_TINT)putc((int)(_i),(_f))
  225. #define _puttchar(_i) (_TINT)putchar((int)(_i))
  226. #define _ungettc(_i,_f) (_TINT)ungetc((int)(_i),(_f))
  227. /* String conversion functions */
  228. #define _tcstod strtod
  229. #define _tcstol strtol
  230. #define _tcstoul strtoul
  231. #ifdef _MBCS
  232. #ifndef __TCHAR_DEFINED
  233. typedef char _TCHAR;
  234. typedef unsigned int _TINT;
  235. #define __TCHAR_DEFINED
  236. #endif
  237. #ifndef _TCHAR_DEFINED
  238. #if !__STDC__
  239. typedef char TCHAR;
  240. #endif
  241. #define _TCHAR_DEFINED
  242. #endif
  243. #define _TEOF EOF
  244. #include <mbstring.h>
  245. /* Helper macros for MB casts */
  246. #define _MB(_s) ((unsigned char *)(_s))
  247. #define _CMB(_s) ((const unsigned char *)(_s))
  248. /* String functions */
  249. #define _tcscat(_s1,_s2) (_TCHAR*)_mbscat(_MB(_s1),_CMB(_s2))
  250. #define _tcschr(_s,_i) (_TCHAR*)_mbschr(_CMB(_s),(_i))
  251. #define _tcscmp(_s1,_s2) _mbscmp(_CMB(_s1),_CMB(_s2))
  252. #define _tcscpy(_s1,_s2) (_TCHAR*)_mbscpy(_MB(_s1),_CMB(_s2))
  253. #define _tcscspn(_s1,_s2) _mbscspn(_CMB(_s1),_CMB(_s2))
  254. #define _tcslen(_s) strlen((_s))
  255. #define _tcsncat(_s1,_s2,_n) (_TCHAR*)_mbsnbcat(_MB(_s1),_CMB(_s2),(_n))
  256. #define _tcsncmp(_s1,_s2,_n) _mbsnbcmp(_CMB(_s1),_CMB(_s2),(_n))
  257. #define _tcsncpy(_s1,_s2,_n) (_TCHAR*)_mbsnbcpy(_MB(_s1),_CMB(_s2),(_n))
  258. #define _tcspbrk(_s1,_s2) (_TCHAR*)_mbspbrk(_CMB(_s1),_CMB(_s2))
  259. #define _tcsrchr(_s,_i) (_TCHAR*)_mbsrchr(_CMB(_s),(_i))
  260. #define _tcsspn(_s1,_s2) _mbsspn(_CMB(_s1),_CMB(_s2))
  261. #define _tcsstr(_s1,_s2) (_TCHAR*)_mbsstr(_CMB(_s1),_CMB(_s2))
  262. #define _tcstok(_s1,_s2) (_TCHAR*)_mbstok(_MB(_s1),_CMB(_s2))
  263. #define _tcsdup(_s) (_TCHAR*)_mbsdup(_CMB(_s))
  264. #define _tcsicmp(_s1,_s2) _mbsicmp(_CMB(_s1),_CMB(_s2))
  265. #define _tcsnicmp(_s1,_s2,_n) _mbsnbicmp(_CMB(_s1),_CMB(_s2),(_n))
  266. #define _tcsnset(_s,_i,_n) (_TCHAR*)_mbsnbset(_MB(_s),(_i),(_n))
  267. #define _tcsrev(_s) (_TCHAR*)_mbsrev(_MB(_s))
  268. #define _tcsset(_s,_i) (_TCHAR*)_mbsset(_MB(_s),(_i))
  269. /* "logical-character" mappings */
  270. #define _tcsclen(_s) _mbslen(_MB(_s))
  271. #define _tcsnccat(_s1,_s2,_n) (_TCHAR*)_mbsncat(_MB(_s1),_CMB(_s2),(_n))
  272. #define _tcsnccpy(_s1,_s2,_n) (_TCHAR*)_mbsncpy(_MB(_s1),_CMB(_s2),(_n))
  273. #define _tcsnccmp(_s1,_s2,_n) _mbsncmp(_CMB(_s1),_CMB(_s2),(_n))
  274. #define _tcsncicmp(_s1,_s2,_n) _mbsnicmp(_CMB(_s1),_CMB(_s2),(_n))
  275. #define _tcsncset(_s,_i,_n) (_TCHAR*)_mbsnset(_MB(_s),(_i),(_n))
  276. /* MBCS-specific mappings */
  277. #define _tcsdec(_s1,_s2) (_TCHAR*)_mbsdec(_CMB(_s1),_CMB(_s2))
  278. #define _tcsinc(_s) (_TCHAR*)_mbsinc(_CMB(_s))
  279. #define _tcsnbcnt(_s,_n) _mbsnbcnt(_CMB(_s),(_n))
  280. #define _tcsnccnt(_s,_n) _mbsnccnt(_CMB(_s),(_n))
  281. #define _tcsnextc(_s) _mbsnextc(_CMB(_s))
  282. #define _tcsninc(_s,_n) (_TCHAR*)_mbsninc(_CMB(_s),(_n))
  283. #define _tcsspnp(_s1,_s2) (_TCHAR*)_mbsspnp(_CMB(_s1),_CMB(_s2))
  284. #define _tcslwr(_s) (_TCHAR*)_mbslwr(_MB(_s))
  285. #define _tcsupr(_s) (_TCHAR*)_mbsupr(_MB(_s))
  286. #define _tcsxfrm(_d,_s,_n) (strncpy((_d),(_s),(_n)),strlen((_s)))
  287. #define _tcscoll _tcscmp
  288. #define _tcsicoll _tcsicmp
  289. #define _tclen(_s) _mbclen(_CMB(_s))
  290. #define _tccpy(_s1,_s2) _mbccpy(_MB(_s1),_CMB(_s2))
  291. #define _tccmp(_s1,_s2) _tcsnccmp((_s1),(_s2),1)
  292. /* ctype functions */
  293. #define _istalpha _ismbcalpha
  294. #define _istupper _ismbcupper
  295. #define _istlower _ismbclower
  296. #define _istdigit _ismbcdigit
  297. #define _istxdigit _isxdigit
  298. #define _istspace _ismbcspace
  299. #define _istprint _ismbcprint
  300. #define _istcntrl _iscntrl
  301. #define _istascii _isascii
  302. #define _totupper _mbctoupper
  303. #define _totlower _mbctolower
  304. #define _istlegal _ismbclegal
  305. #else /* !_MBCS */
  306. #ifndef __TCHAR_DEFINED
  307. typedef char _TCHAR;
  308. typedef int _TINT;
  309. #define __TCHAR_DEFINED
  310. #endif
  311. #ifndef _TCHAR_DEFINED
  312. #if !__STDC__
  313. typedef char TCHAR;
  314. #endif
  315. #define _TCHAR_DEFINED
  316. #endif
  317. #define _TEOF EOF
  318. /* String functions */
  319. #define _tcscat strcat
  320. #define _tcschr strchr
  321. #define _tcscmp strcmp
  322. #define _tcscpy strcpy
  323. #define _tcscspn strcspn
  324. #define _tcslen strlen
  325. #define _tcsncat strncat
  326. #define _tcsncmp strncmp
  327. #define _tcsncpy strncpy
  328. #define _tcspbrk strpbrk
  329. #define _tcsrchr strrchr
  330. #define _tcsspn strspn
  331. #define _tcsstr strstr
  332. #define _tcstok strtok
  333. #define _tcsdup _strdup
  334. #define _tcsicmp _stricmp
  335. #define _tcsnicmp _strnicmp
  336. #define _tcsnset _strnset
  337. #define _tcsrev _strrev
  338. #define _tcsset _strset
  339. /* "logical-character" mappings */
  340. #define _tcsclen strlen
  341. #define _tcsnccat strncat
  342. #define _tcsnccpy strncpy
  343. #define _tcsnccmp strncmp
  344. #define _tcsncicmp _strnicmp
  345. #define _tcsncset _strnset
  346. /* MBCS-specific functions */
  347. #define _tcsdec _strdec
  348. #define _tcsinc _strinc
  349. #define _tcsnbcnt _strncnt
  350. #define _tcsnccnt _strncnt
  351. #define _tcsnextc _strnextc
  352. #define _tcsninc _strninc
  353. #define _tcsspnp _strspnp
  354. #define _tcslwr _strlwr
  355. #define _tcsupr _strupr
  356. #define _tcsxfrm strxfrm
  357. #define _tcscoll strcoll
  358. #define _tcsicoll _stricoll
  359. #if !__STDC__ || defined(_NO_INLINING)
  360. #define _tclen(_pc) (1)
  361. #define _tccpy(_pc1,_cpc2) (*(_pc1) = *(_cpc2))
  362. #define _tccmp(_cpc1,_cpc2) (((unsigned char)*(_cpc1))-((unsigned char)*(_cpc2)))
  363. #else
  364. __inline size_t _tclen(const char *_cpc) { return (_cpc,1); }
  365. __inline void _tccpy(char *_pc1, const char *_cpc2) { *_pc1 = *_cpc2; }
  366. __inline int _tccmp(const char *_cpc1, const char *_cpc2) { return (int) (((unsigned char)*_cpc1)-((unsigned char)*_cpc2)); }
  367. #endif
  368. /* ctype-functions */
  369. #define _istalpha isalpha
  370. #define _istupper isupper
  371. #define _istlower islower
  372. #define _istdigit isdigit
  373. #define _istxdigit isxdigit
  374. #define _istspace isspace
  375. #define _istpunct ispunct
  376. #define _istalnum isalnum
  377. #define _istprint isprint
  378. #define _istgraph isgraph
  379. #define _istcntrl iscntrl
  380. #define _istascii isascii
  381. #define _totupper toupper
  382. #define _totlower tolower
  383. #define _istlegal (1)
  384. /* the following is optional if functional versions are available */
  385. /* define NULL pointer value */
  386. #ifndef NULL
  387. #ifdef __cplusplus
  388. #define NULL 0
  389. #else
  390. #define NULL ((void *)0)
  391. #endif
  392. #endif
  393. #if !__STDC__ || defined(_NO_INLINING)
  394. #define _strdec(_cpc, _pc) ((_pc)-1)
  395. #define _strinc(_pc) ((_pc)+1)
  396. #define _strnextc(_cpc) ((unsigned int) *(_cpc))
  397. #define _strninc(_pc, _sz) (((_pc)+(_sz)))
  398. #define _strncnt(_cpc, _sz) ((strlen(_cpc)>_sz) ? _sz : strlen(_cpc))
  399. #define _strspnp(_cpc1, _cpc2) ((*((_cpc1)+strspn(_cpc1,_cpc2))) ? ((_cpc1)+strspn(_cpc1,_cpc2)) : NULL)
  400. #else /* __STDC__ */
  401. __inline char * _strdec(const char * _cpc, const char * _pc) { return (char *)(_cpc,(_pc-1)); }
  402. __inline char * _strinc(const char * _pc) { return (char *)(_pc+1); }
  403. __inline unsigned int _strnextc(const char * _cpc) { return (unsigned int)*_cpc; }
  404. __inline char * _strninc(const char * _pc, size_t _sz) { return (char *)(_pc+_sz); }
  405. __inline size_t _strncnt( const char * _cpc, size_t _sz) { size_t len; len = strlen(_cpc); return (len>_sz) ? _sz : len; }
  406. __inline char * _strspnp( const char * _cpc1, const char * _cpc2) { return (*(_cpc1 += strspn(_cpc1,_cpc2))!='\0') ? (char*)_cpc1 : NULL; }
  407. #endif /* __STDC__ */
  408. #endif /* _MBCS */
  409. #endif /* _UNICODE */
  410. /* Generic text macros to be used with string literals and character constants.
  411. Will also allow symbolic constants that resolve to same. */
  412. #define _T(x) __T(x)
  413. #define _TEXT(x) __T(x)
  414. #ifdef __cplusplus
  415. }
  416. #endif
  417. #define _INC_TCHAR
  418. #endif /* _INC_TCHAR */