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.

299 lines
10 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. tstr.h
  5. Abstract:
  6. This include file contains manifests and macros to be used to integrate
  7. the TCHAR and LPTSTR definitions
  8. Note that our naming convention is that a "size" indicates a number of
  9. bytes whereas a "length" indicates a number of characters.
  10. Author:
  11. Richard Firth (rfirth) 02-Apr-1991
  12. Environment:
  13. Portable (Win/32).
  14. Requires ANSI C extensions: slash-slash comments, long external names,
  15. _ultoa() routine.
  16. Revision History:
  17. 22-May-1991 Danl
  18. Added STRSIZE macro
  19. 19-May-1991 JohnRo
  20. Changed some parm names to make things easier to read.
  21. 15-May-1991 rfirth
  22. Added TCHAR_SPACE and MAKE_TCHAR() macro
  23. 15-Jul-1991 RFirth
  24. Added STRING_SPACE_REQD() and DOWN_LEVEL_STRSIZE
  25. 05-Aug-1991 JohnRo
  26. Added MEMCPY macro.
  27. 19-Aug-1991 JohnRo
  28. Added character type stuff: ISDIGIT(), TOUPPER(), etc.
  29. 20-Aug-1991 JohnRo
  30. Changed strnicmp to _strnicmp to keep PC-LINT happy. Ditto stricmp.
  31. 13-Sep-1991 JohnRo
  32. Need UNICODE STRSIZE() too.
  33. 13-Sep-1991 JohnRo
  34. Added UNICODE STRCMP() and various others.
  35. 18-Oct-1991 JohnRo
  36. Added NetpCopy routines and WCSSIZE().
  37. 26-Nov-1991 JohnRo
  38. Added NetpNCopy routines (like strncpy but do conversions as well).
  39. 09-Dec-1991 rfirth
  40. Added STRREV
  41. 03-Jan-1992 JohnRo
  42. Added NetpAlloc{type}From{type} routines and macros.
  43. 09-Jan-1992 JohnRo
  44. Added ATOL() macro and wtol() routine.
  45. Ditto ULTOA() macro and ultow() routine.
  46. 16-Jan-1992 Danl
  47. Cut this info from \net\inc\tstring.h
  48. 30-Jan-1992 JohnRo
  49. Added STRSTR().
  50. Use _wcsupr() instead of wcsupr() to keep PC-LINT happy.
  51. Added STRCMPI() and STRNCMPI().
  52. Fixed a few definitions which were missing MAKE_STR_FUNCTION etc.
  53. 14-Mar-1992 JohnRo
  54. Avoid compiler warnings using WCSSIZE(), MEMCPY(), etc.
  55. Added TCHAR_TAB.
  56. 09-Apr-1992 JohnRo
  57. Prepare for WCHAR.H (_wcsicmp vs _wcscmpi, etc).
  58. --*/
  59. #ifndef _TSTR_H_INCLUDED
  60. #define _TSTR_H_INCLUDED
  61. #include <ctype.h> // isdigit(), iswdigit() eventually, etc.
  62. #include <stdlib.h> // atol(), _ultoa().
  63. #include <string.h> // memcpy(), strlen(), etc.
  64. #include <wchar.h>
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. LPWSTR
  69. ultow (
  70. IN DWORD Value,
  71. OUT LPWSTR Area,
  72. IN DWORD Radix
  73. );
  74. LONG
  75. wtol (
  76. IN LPWSTR Src
  77. );
  78. #ifdef LM20_COMPATIBLE
  79. #define MAKE_STR_FUNCTION(s) s##f
  80. #else
  81. #define MAKE_STR_FUNCTION(s) s
  82. #endif
  83. #if defined(UNICODE)
  84. //
  85. // function macro prototypes
  86. //
  87. #define ATOL(Src) (LONG)MAKE_STR_FUNCTION(wtol)(Src)
  88. #define ISALNUM(tchar) iswalnum(tchar) // locale-dependent.
  89. #define ISALPHA(tchar) iswalpha(tchar) // locale-dependent.
  90. #define ISCNTRL(tchar) iswcntrl(tchar) // locale-dependent.
  91. #define ISDIGIT(tchar) iswdigit(tchar)
  92. #define ISGRAPH(tchar) iswgraph(tchar) // locale-dependent.
  93. #define ISLOWER(tchar) iswlower(tchar) // locale-dependent.
  94. #define ISPRINT(tchar) iswprint(tchar) // locale-dependent.
  95. #define ISPUNCT(tchar) iswpunct(tchar) // locale-dependent.
  96. #define ISSPACE(tchar) iswspace(tchar) // locale-dependent.
  97. #define ISUPPER(tchar) iswupper(tchar) // locale-dependent.
  98. #define ISXDIGIT(tchar) iswxdigit(tchar)
  99. #define STRCAT(dest, src) (LPTSTR)MAKE_STR_FUNCTION(wcscat)((dest), (src))
  100. #define STRCHR(s1, c) (LPTSTR)MAKE_STR_FUNCTION(wcschr)((s1), (c))
  101. #define STRCPY(dest, src) (LPTSTR)MAKE_STR_FUNCTION(wcscpy)((dest), (src))
  102. #define STRCSPN(s, c) (DWORD)MAKE_STR_FUNCTION(wcscspn)((s), (c))
  103. // STRLEN: Get character count of s.
  104. #define STRLEN(s) (DWORD)MAKE_STR_FUNCTION(wcslen)(s)
  105. #define STRNCAT(dest, src, n) \
  106. (LPTSTR)MAKE_STR_FUNCTION(wcsncat)((dest), (src), (n))
  107. #define STRNCPY(dest, src, n) \
  108. (LPTSTR)MAKE_STR_FUNCTION(wcsncpy)((dest), (src), (n))
  109. #define STRSPN(s1, s2) (DWORD)MAKE_STR_FUNCTION(wcsspn)((s1), (s2))
  110. #define STRRCHR (LPTSTR)MAKE_STR_FUNCTION(wcsrchr)
  111. #define STRSTR (LPTSTR)MAKE_STR_FUNCTION(wcswcs)
  112. #define STRUPR(s) (LPTSTR)MAKE_STR_FUNCTION(_wcsupr)(s)
  113. // these don't have formal parameters because we want to take the address of
  114. // the mapped function in certain cases. Modify as appropriate.
  115. // Note that for these functions, lengths are in characters.
  116. // compare functions: len is maximum number of characters being compared.
  117. #define STRCMP (LONG)MAKE_STR_FUNCTION(wcscmp)
  118. #define STRCMPI (LONG)MAKE_STR_FUNCTION(_wcsicmp)
  119. #define STRICMP (LONG)MAKE_STR_FUNCTION(_wcsicmp)
  120. #define STRNCMP (LONG)MAKE_STR_FUNCTION(wcsncmp)
  121. #define STRNCMPI (LONG)MAKE_STR_FUNCTION(_wcsnicmp)
  122. #define STRNICMP (LONG)MAKE_STR_FUNCTION(_wcsnicmp)
  123. #define TOLOWER(tchar) towlower(tchar) // locale-dependent.
  124. #define TOUPPER(tchar) towupper(tchar) // locale-dependent.
  125. #define ULTOA(Value,Result,Radix) \
  126. (LPTSTR)MAKE_STR_FUNCTION(ultow)( (Value), (Result), (Radix) )
  127. //
  128. // manifests
  129. //
  130. #define _CHAR_TYPE WCHAR
  131. #else // not UNICODE
  132. //
  133. // function macro prototypes
  134. //
  135. #define ATOL(Src) (LONG)MAKE_STR_FUNCTION(atol)(Src)
  136. #define ISALNUM(tchar) isalnum(tchar) // locale-dependent.
  137. #define ISALPHA(tchar) isalpha(tchar) // locale-dependent.
  138. #define ISCNTRL(tchar) iscntrl(tchar) // locale-dependent.
  139. #define ISDIGIT(tchar) isdigit(tchar)
  140. #define ISGRAPH(tchar) isgraph(tchar) // locale-dependent.
  141. #define ISLOWER(tchar) islower(tchar) // locale-dependent.
  142. #define ISPRINT(tchar) isprint(tchar) // locale-dependent.
  143. #define ISPUNCT(tchar) ispunct(tchar) // locale-dependent.
  144. #define ISSPACE(tchar) isspace(tchar) // locale-dependent.
  145. #define ISUPPER(tchar) isupper(tchar) // locale-dependent.
  146. #define ISXDIGIT(tchar) isxdigit(tchar)
  147. #define STRCAT(dest, src) (LPTSTR)MAKE_STR_FUNCTION(strcat)((dest), (src))
  148. #define STRNCAT(dest, src, n) \
  149. (LPTSTR)MAKE_STR_FUNCTION(strncat)((dest), (src), (n))
  150. // STRLEN: Get character count of s.
  151. #define STRLEN(s) (DWORD)MAKE_STR_FUNCTION(strlen)(s)
  152. #define STRSPN(s1, s2) (DWORD)MAKE_STR_FUNCTION(strspn)((s1), (s2))
  153. #define STRCSPN(s, c) (DWORD)MAKE_STR_FUNCTION(strcspn)((s), (c))
  154. #define STRCPY(dest, src) (LPTSTR)MAKE_STR_FUNCTION(strcpy)((dest), (src))
  155. #define STRNCPY(dest, src, n) \
  156. (LPTSTR)MAKE_STR_FUNCTION(strncpy)((dest), (src), (n))
  157. #define STRCHR(s1, c) (LPTSTR)MAKE_STR_FUNCTION(strchr)((s1), (c))
  158. #define STRRCHR (LPTSTR)MAKE_STR_FUNCTION(strrchr)
  159. #define STRSTR (LPTSTR)MAKE_STR_FUNCTION(strstr)
  160. #define STRUPR(s) (LPTSTR)MAKE_STR_FUNCTION(strupr)(s)
  161. #define STRREV(s) (LPTSTR)MAKE_STR_FUNCTION(strrev)(s)
  162. // these don't have formal parameters because we want to take the address of
  163. // the mapped function in certain cases. Modify as appropriate.
  164. // Note that for these functions, lengths are in characters.
  165. // compare functions: len is maximum number of characters being compared.
  166. #define STRCMP (LONG)MAKE_STR_FUNCTION(strcmp)
  167. #define STRCMPI (LONG)MAKE_STR_FUNCTION(_stricmp)
  168. #define STRICMP (LONG)MAKE_STR_FUNCTION(_stricmp)
  169. #define STRNCMP (LONG)MAKE_STR_FUNCTION(strncmp)
  170. #define STRNCMPI (LONG)MAKE_STR_FUNCTION(_strnicmp)
  171. #define STRNICMP (LONG)MAKE_STR_FUNCTION(_strnicmp)
  172. #define TOLOWER(tchar) tolower(tchar) // locale-dependent.
  173. #define TOUPPER(tchar) toupper(tchar) // locale-dependent.
  174. #define ULTOA(Value,Result,Radix) \
  175. (LPTSTR)MAKE_STR_FUNCTION(_ultoa)( (Value), (Result), (Radix) )
  176. //
  177. // manifests
  178. //
  179. #define _CHAR_TYPE TCHAR
  180. #endif // not UNICODE
  181. //
  182. // For the memory routines, the counts are always BYTE counts.
  183. //
  184. #define MEMCPY MAKE_STR_FUNCTION(memcpy)
  185. #define MEMMOVE MAKE_STR_FUNCTION(memmove)
  186. //
  187. // These are used to determine the number of bytes (including the NUL
  188. // terminator) in a string. This will generally be used when
  189. // calculating the size of a string for allocation purposes.
  190. //
  191. #define STRSIZE(p) ((STRLEN(p)+1) * sizeof(TCHAR))
  192. #define WCSSIZE(s) ((MAKE_STR_FUNCTION(wcslen)(s)+1) * sizeof(WCHAR))
  193. //
  194. // character literals (both types)
  195. //
  196. #define TCHAR_EOS ((_CHAR_TYPE)'\0')
  197. #define TCHAR_STAR ((_CHAR_TYPE)'*')
  198. #define TCHAR_BACKSLASH ((_CHAR_TYPE)'\\')
  199. #define TCHAR_FWDSLASH ((_CHAR_TYPE)'/')
  200. #define TCHAR_COLON ((_CHAR_TYPE)':')
  201. #define TCHAR_DOT ((_CHAR_TYPE)'.')
  202. #define TCHAR_SPACE ((_CHAR_TYPE)' ')
  203. #define TCHAR_TAB ((_CHAR_TYPE)'\t')
  204. //
  205. // General purpose macro for casting character types to whatever type in vogue
  206. // (as defined in this file)
  207. //
  208. #define MAKE_TCHAR(c) ((_CHAR_TYPE)(c))
  209. //
  210. // IS_PATH_SEPARATOR
  211. //
  212. // lifted from curdir.c and changed to use TCHAR_ character literals, checks
  213. // if a character is a path separator i.e. is a member of the set [\/]
  214. //
  215. #define IS_PATH_SEPARATOR(ch) ((ch == TCHAR_BACKSLASH) || (ch == TCHAR_FWDSLASH))
  216. //
  217. // The following 2 macros lifted from I_Net canonicalization files
  218. //
  219. #define IS_DRIVE(c) ISALPHA(c)
  220. #define IS_NON_ZERO_DIGIT(c) (((c) >= MAKE_TCHAR('1')) && ((c) <= MAKE_TCHAR('9')))
  221. //
  222. // STRING_SPACE_REQD returns a number (of bytes) corresponding to the space
  223. // required in which (n) characters can be accomodated
  224. //
  225. #define STRING_SPACE_REQD(n) ((n) * sizeof(_CHAR_TYPE))
  226. //
  227. // DOWN_LEVEL_STRLEN returns the number of single-byte characters necessary to
  228. // store a converted _CHAR_TYPE string. This will be WCHAR (or wchar_t) if
  229. // UNICODE is defined or CHAR (or char) otherwise
  230. //
  231. #define DOWN_LEVEL_STRSIZE(n) ((n) / sizeof(_CHAR_TYPE))
  232. #ifdef __cplusplus
  233. }
  234. #endif
  235. #endif // _TSTR_H_INCLUDED