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.

259 lines
7.0 KiB

  1. //============================================================================
  2. // Copyright (C) Microsoft Corporation, 1997 - 1999
  3. //
  4. // File: tfschar.h
  5. //
  6. // String functions that are used in general for TFS code.
  7. //
  8. // History:
  9. //
  10. // 05/28/97 Kenn Takara Created.
  11. //
  12. // Declarations for some common code/macros.
  13. //============================================================================
  14. #ifndef _TFSCHAR_H
  15. #define _TFSCHAR_H
  16. #if _MSC_VER >= 1000 // VC 5.0 or later
  17. #pragma once
  18. #endif
  19. #ifndef _STD_H
  20. #include "std.h"
  21. #endif
  22. //$ Win95: kennt, the list of Unicode-enabled functions on Win95 will
  23. // have to be checked. Does lstrlenW work, but lstrcpyW doesn't? (that's
  24. // what the ATL versions of the functions imply).
  25. /*---------------------------------------------------------------------------
  26. String copy functions
  27. ---------------------------------------------------------------------------*/
  28. // Baisc conversion functions
  29. TFSCORE_API(LPSTR) StrCpyAFromW(LPSTR psz, LPCWSTR pswz);
  30. TFSCORE_API(LPWSTR) StrCpyWFromA(LPWSTR pswz, LPCSTR psz);
  31. TFSCORE_API(LPSTR) StrnCpyAFromW(LPSTR psz, LPCWSTR pswz, int iMax);
  32. TFSCORE_API(LPWSTR) StrnCpyWFromA(LPWSTR pswz, LPCSTR psz, int iMax);
  33. #define StrCpy lstrcpy
  34. #define StrnCpy lstrcpyn
  35. #define StrCpyW lstrcpyW
  36. #define StrCpyA lstrcpyA
  37. #define StrnCpyW lstrcpynW
  38. #define StrnCpyA lstrcpynA
  39. #define StrCpyOle StrCpyW
  40. #define StrnCpyOle StrnCpyW
  41. #ifdef _UNICODE
  42. #define StrCpyAFromT StrCpyAFromW
  43. #define StrCpyTFromA StrCpyWFromA
  44. #define StrCpyTFromW lstrcpy
  45. #define StrCpyWFromT lstrcpy
  46. #define StrnCpyAFromT StrnCpyAFromW
  47. #define StrnCpyTFromA StrnCpyWFromA
  48. #define StrnCpyTFromW lstrcpyn
  49. #define StrnCpyWFromT lstrcpyn
  50. #else
  51. #define StrCpyAFromT lstrcpy
  52. #define StrCpyTFromA lstrcpy
  53. #define StrCpyTFromW StrCpyAFromW
  54. #define StrCpyWFromT StrCpyWFromA
  55. #define StrnCpyAFromT lstrcpyn
  56. #define StrnCpyTFromA lstrcpyn
  57. #define StrnCpyTFromW StrnCpyAFromW
  58. #define StrnCpyWFromT StrnCpyWFromA
  59. #endif
  60. #define StrCpyOleFromT StrCpyWFromT
  61. #define StrCpyTFromOle StrCpyTFromW
  62. #define StrCpyOleFromA StrCpyWFromA
  63. #define StrCpyAFromOle StrCpyAFromW
  64. #define StrCpyWFromOle StrCpyW
  65. #define StrCpyOleFromW StrCpyW
  66. #define StrnCpyOleFromT StrnCpyWFromT
  67. #define StrnCpyTFromOle StrnCpyTFromW
  68. #define StrnCpyOleFromA StrnCpyWFromA
  69. #define StrnCpyAFromOle StrnCpyAFromW
  70. #define StrnCpyOleFromW StrnCpyW
  71. #define StrnCpyWFromOle StrnCpyW
  72. /*---------------------------------------------------------------------------
  73. String length functions
  74. ---------------------------------------------------------------------------*/
  75. #define StrLen lstrlen
  76. #define StrLenA lstrlenA
  77. #define StrLenW lstrlenW
  78. #define StrLenOle StrLenW
  79. //
  80. // CbStrLenA() is inaccurate for DBCS strings! It will return the
  81. // incorrect number of bytes needed.
  82. //
  83. #define CbStrLenA(psz) ((StrLenA(psz)+1)*sizeof(char))
  84. #define CbStrLenW(psz) ((StrLenW(psz)+1)*sizeof(WCHAR))
  85. #ifdef _UNICODE
  86. #define CbStrLen(psz) CbStrLenW(psz)
  87. #else
  88. #define CbStrLen(psz) CbStrLenA(psz)
  89. #endif
  90. // Given a number of characters, this it the minimal number of TCHARs
  91. // that needs to be allocated to hold the string
  92. #define MinTCharNeededForCch(ch) ((ch) * (2/sizeof(TCHAR)))
  93. #define MinCbNeededForCch(ch) (sizeof(TCHAR)*MinTCharNeededForCch(ch))
  94. // Given a cb (count of bytes) this is the maximal number of characters
  95. // that can be in this string
  96. #define MaxCchFromCb(cb) ((cb) / sizeof(TCHAR))
  97. #ifdef _UNICODE
  98. // Given a cb, this is the minimum number of chars found in this string
  99. // MinCchFromCb
  100. #define MinCchFromCb(cb) ((cb) / sizeof(WCHAR))
  101. #else
  102. // Number of characters is only half due to DBCS
  103. #define MinCchFromCb(cb) ((cb) / (2*sizeof(char)))
  104. #endif
  105. /*---------------------------------------------------------------------------
  106. String dup functions
  107. The returned string from these functions must be freed using delete!
  108. ---------------------------------------------------------------------------*/
  109. TFSCORE_API(LPSTR) StrDupA( LPCSTR psz );
  110. TFSCORE_API(LPWSTR) StrDupW( LPCWSTR pws );
  111. TFSCORE_API(LPSTR) StrDupAFromW( LPCWSTR pwsz );
  112. TFSCORE_API(LPWSTR) StrDupWFromA( LPCSTR psz );
  113. #ifdef _UNICODE
  114. #define StrDup StrDupW
  115. #define StrDupTFromW StrDupW
  116. #define StrDupWFromT StrDupW
  117. #define StrDupTFromA StrDupWFromA
  118. #define StrDupAFromT StrDupAFromW
  119. #define StrDupOleFromA StrDupWFromA
  120. #define StrDupAFromOle StrDupAFromW
  121. #define StrDupOleFromW StrDupW
  122. #define StrDupWFromOle StrDupW
  123. #define StrDupOleFromT StrDupOleFromW
  124. #define StrDupTFromOle StrDupWFromOle
  125. #else
  126. #define StrDup StrDupA
  127. #define StrDupTFromA StrDupA
  128. #define StrDupAFromT StrDupA
  129. #define StrDupTFromW StrDupAFromW
  130. #define StrDupWFromT StrDupWFromT
  131. #define StrDupOleFromA StrDupWFromA
  132. #define StrDupAFromOle StrDupAFromW
  133. #define StrDupOleFromW StrDupW
  134. #define StrDupWFromOle StrDupW
  135. #define StrDupOleFromT StrDupOleFromA
  136. #define StrDupTFromOle StrDupAFromOle
  137. #endif
  138. // AllocaStrDup
  139. // AllocaStrDupA
  140. // AllocaStrDupW
  141. //
  142. // These functions will dup a string on the STACK.
  143. //
  144. #define AllocaStrDupA(lpa) (\
  145. ((LPCSTR)lpa == NULL) ? NULL : (\
  146. StrCpyA((LPSTR) alloca(CbStrLenA(lpa)*2), lpa)))
  147. #define AllocaStrDupW(lpw) (\
  148. ((LPCWSTR)lpw == NULL) ? NULL : (\
  149. StrCpyW((LPWSTR) alloca(CbStrLenW(lpw)), lpw)))
  150. #ifdef _UNICODE
  151. #define AllocaStrDup AllocaStrDupW
  152. #else
  153. #define AllocaStrDup AllocaStrDupA
  154. #endif
  155. /*---------------------------------------------------------------------------
  156. String comparison functions
  157. ---------------------------------------------------------------------------*/
  158. #define StrCmpA lstrcmpA
  159. #define StrCmpW lstrcmpW
  160. #define StrCmpOle StrCmpW
  161. TFSCORE_API(int) StrnCmpA(LPCSTR psz1, LPCSTR psz2, int nLen);
  162. TFSCORE_API(int) StrnCmpW(LPCWSTR pswz1, LPCWSTR pswz2, int nLen);
  163. #define StriCmpA lstrcmpiA
  164. #define StriCmpW lstrcmpiW
  165. #define StriCmpOle StriCmpW
  166. TFSCORE_API(int) StrniCmpA(LPCSTR psz1, LPCSTR psz2, int nLen);
  167. TFSCORE_API(int) StrniCmpW(LPCWSTR pswz1, LPCWSTR pswz2, int nLen);
  168. #ifdef _UNICODE
  169. #define StrCmp StrCmpW
  170. #define StrnCmp StrnCmpW
  171. #define StriCmp StriCmpW
  172. #define StrniCmp StrniCmpW
  173. #else
  174. #define StrCmp StrCmpA
  175. #define StrnCmp StrnCmpA
  176. #define StriCmp StriCmpA
  177. #define StrniCmp StrniCmpA
  178. #endif
  179. /*---------------------------------------------------------------------------
  180. String concatenation routines
  181. ---------------------------------------------------------------------------*/
  182. #define StrCatW lstrcatW
  183. #define StrCatA lstrcatA
  184. #ifdef _UNICODE
  185. #define StrCat StrCatW
  186. #else
  187. #define StrCat StrCatA
  188. #endif
  189. /*---------------------------------------------------------------------------
  190. Local conversion routines (conversions performed on stack!)
  191. ---------------------------------------------------------------------------*/
  192. // Make sure MFC's afxconv.h hasn't already been loaded to do this
  193. #include "atlconv.h"
  194. #endif // _TFSCHAR_H