Leaked source code of windows server 2003
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.

178 lines
4.9 KiB

  1. /*
  2. *---------------------------------------------------------------------------
  3. *
  4. * Microsoft Windows
  5. * Copyright (C) Microsoft Corporation, 1992 - 1996.
  6. *
  7. * File: tchar.h
  8. *
  9. * Contents: Mapping between wide characters and normal character types
  10. * for functions used in the reference implementation
  11. *----------------------------------------------------------------------------
  12. */
  13. #ifndef __TCHAR_DEFINED
  14. #define __TCHAR_DEFINED
  15. #include "ref.hxx"
  16. #include "wchar.h"
  17. #ifdef _UNICODE
  18. typedef WCHAR TCHAR;
  19. #define OLESTR(str) L##str
  20. #else /* _UNICODE */
  21. typedef char TCHAR;
  22. #define OLESTR(str) str
  23. #endif /* _UNICODE */
  24. typedef TCHAR * LPTSTR;
  25. typedef TCHAR OLECHAR, *LPOLECHAR, *LPOLESTR;
  26. /* Define some macros to handle declaration of strings with literals */
  27. /* Since we stray from the default 4 byte wchar_t in UNIX, we have to
  28. to something different than the usual L"ssd" literals */
  29. /* #define DECLARE_OLESTR(ocsName, len, contents) \ */
  30. /* LPOLESTR ocsName[len]=OLESTR(contents) */
  31. /* #else */
  32. #ifdef _UNICODE
  33. #define DECLARE_OLESTR(ocsName, pchContents) \
  34. OLECHAR ocsName[sizeof(pchContents)+1]; \
  35. _tbstowcs(ocsName, pchContents, sizeof(pchContents)+1)
  36. #define INIT_OLESTR(ocsName, pchContents) \
  37. _tbstowcs(ocsName, pchContents, sizeof(pchContents)+1)
  38. #define DECLARE_CONST_OLESTR(cocsName, pchContents) \
  39. OLECHAR temp##cocsName[sizeof(pchContents)+1]; \
  40. _tbstowcs(temp##cocsName, pchContents, sizeof(pchContents)+1); \
  41. const LPOLESTR cocsName = temp##cocsName
  42. #else /* non _UNICODE */
  43. #define DECLARE_OLESTR(ocsName, pchContents) \
  44. OLECHAR ocsName[]=pchContents
  45. #define INIT_OLESTR(ocsName, pchContents) \
  46. strcpy(ocsName, pchContents);
  47. #define DECLARE_CONST_OLESTR(ocsName, pchContents) \
  48. const LPOLESTR ocsName=pchContents
  49. #endif /* _UNICODE */
  50. #define DECLARE_WIDESTR(wcsName, pchContents) \
  51. WCHAR wcsName[sizeof(pchContents)+1]; \
  52. _tbstowcs(wcsName, pchContents, sizeof(pchContents)+1)
  53. #ifndef _UNICODE /*---- non unicode ------ */
  54. #define _tcscpy strcpy
  55. #define _tcscmp strcmp
  56. #define _tcslen strlen
  57. #define _tcsnicmp _strnicmp
  58. #define _tcscat strcat
  59. #define _itot _itoa
  60. #define _T(str) str
  61. #ifdef _WIN32
  62. /* Io functions */
  63. #define _tfopen fopen
  64. #define _tunlink _unlink
  65. #define _tfullpath _fullpath
  66. #define _tstat _stat
  67. #else /* _WIN32 */
  68. #define _tfopen fopen
  69. #define _tunlink unlink /* T-types mapping */
  70. #define _unlink unlink /* non-win32 mapping */
  71. #define _stat stat
  72. #define _tstat stat
  73. #define _strnicmp(s1,s2,n) strncasecmp(s1,s2,n)
  74. /* note that we assume there is enough space in this case */
  75. #define _tfullpath(longname, shortname, len) realpath(shortname, longname)
  76. #define _fullpath(longname, shortname, len) realpath(shortname, longname)
  77. #endif /* _MSC_VER */
  78. /* copying wchar/char and TCHAR */
  79. #ifdef _MSC_VER
  80. #define WTOT(T, W, count) wcstombs(T, W, count)
  81. #define TTOW(T, W, count) mbstowcs(W, T, count)
  82. #else /* _MSC_VER */
  83. #define WTOT(T, W, count) wcstosbs(T, W, count)
  84. #define TTOW(T, W, count) sbstowcs(W, T, count)
  85. #endif /* _MSC_VER */
  86. #define STOT(S, T, count) strcpy(T, S)
  87. #define TTOS(T, S, count) strcpy(S, T)
  88. #else /* _UNICODE ---- unicode ------ */
  89. /* NOTE: unicode APIs on non win32 systems are not tested or implemented */
  90. #define _tcscpy wcscpy
  91. #define _tcscmp wcscmp
  92. #define _tcslen wcslen
  93. #define _tcscat wcscat
  94. #define _tcsnicmp wcsnicmp
  95. #define _itot _itow
  96. #define _T(str) L##str
  97. /* Io functions */
  98. #define _tfopen _wfopen
  99. #define _tunlink _wunlink
  100. #define _tfullpath _wfullpath
  101. #define _tstat _wstat
  102. #ifdef _UNIX /* map win32 I/O API's to other O.S. */
  103. #define _unlink unlink
  104. #define _fullpath(longname, shortname, len) realpath(shortname, longname)
  105. #define _stat stat
  106. #define _strnicmp(s1,s2,n) strncasecmp(s1,s2,n)
  107. #endif
  108. /* converting between wchar and TCHAR */
  109. #define WTOT(T, W, count) wcsncpy(T, W, count)
  110. #define TTOW(T, W, count) wcsncpy(W, T, count)
  111. /* converting between a char and TCHAR */
  112. #define WTOT(T, W, count) wcsncpy(T, W, count)
  113. #define TTOW(T, W, count) wcsncpy(W, T, count)
  114. #define STOT(S, T, count) _tbstowcs(T, S, count)
  115. #define TTOS(T, S, count) _wcstotbs(S, T, count)
  116. #endif /* #ifndef _UNICODE, #else ... */
  117. #ifndef _WIN32 /* others */
  118. #define _tbstowcs sbstowcs
  119. #define _wcstotbs wcstosbs
  120. #else /* _WIN32 */
  121. #define _tbstowcs mbstowcs
  122. #define _wcstotbs wcstombs
  123. #endif /* _WIN32 */
  124. #ifndef _MSC_VER
  125. #include <assert.h>
  126. inline void _itoa(int v, char* string, int radix)
  127. {
  128. if (radix!=10) assert(FALSE); /* only handle base 10 */
  129. sprintf(string, "%d", v);
  130. }
  131. #endif /* _MSC_VER */
  132. #endif /* #ifndef __TCHAR_DEFINED */