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.

297 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. // Don't #define memmove to RtlMoveMemory for wchar.h
  65. // because the protoypes don't match.
  66. #pragma push_macro("memmove")
  67. #undef memmove
  68. #include <wchar.h>
  69. #pragma pop_macro("memmove")
  70. LPWSTR
  71. ultow (
  72. IN DWORD Value,
  73. OUT LPWSTR Area,
  74. IN DWORD Radix
  75. );
  76. LONG
  77. wtol (
  78. IN LPWSTR Src
  79. );
  80. #ifdef LM20_COMPATIBLE
  81. #define MAKE_STR_FUNCTION(s) s##f
  82. #else
  83. #define MAKE_STR_FUNCTION(s) s
  84. #endif
  85. #if defined(UNICODE)
  86. //
  87. // function macro prototypes
  88. //
  89. #define ATOL(Src) (LONG)MAKE_STR_FUNCTION(wtol)(Src)
  90. #define ISALNUM(tchar) iswalnum(tchar) // locale-dependent.
  91. #define ISALPHA(tchar) iswalpha(tchar) // locale-dependent.
  92. #define ISCNTRL(tchar) iswcntrl(tchar) // locale-dependent.
  93. #define ISDIGIT(tchar) iswdigit(tchar)
  94. #define ISGRAPH(tchar) iswgraph(tchar) // locale-dependent.
  95. #define ISLOWER(tchar) iswlower(tchar) // locale-dependent.
  96. #define ISPRINT(tchar) iswprint(tchar) // locale-dependent.
  97. #define ISPUNCT(tchar) iswpunct(tchar) // locale-dependent.
  98. #define ISSPACE(tchar) iswspace(tchar) // locale-dependent.
  99. #define ISUPPER(tchar) iswupper(tchar) // locale-dependent.
  100. #define ISXDIGIT(tchar) iswxdigit(tchar)
  101. #define STRCAT(dest, src) (LPTSTR)MAKE_STR_FUNCTION(wcscat)((dest), (src))
  102. #define STRCHR(s1, c) (LPTSTR)MAKE_STR_FUNCTION(wcschr)((s1), (c))
  103. #define STRCPY(dest, src) (LPTSTR)MAKE_STR_FUNCTION(wcscpy)((dest), (src))
  104. #define STRCSPN(s, c) (DWORD)MAKE_STR_FUNCTION(wcscspn)((s), (c))
  105. // STRLEN: Get character count of s.
  106. #define STRLEN(s) (DWORD)MAKE_STR_FUNCTION(wcslen)(s)
  107. #define STRNCAT(dest, src, n) \
  108. (LPTSTR)MAKE_STR_FUNCTION(wcsncat)((dest), (src), (n))
  109. #define STRNCPY(dest, src, n) \
  110. (LPTSTR)MAKE_STR_FUNCTION(wcsncpy)((dest), (src), (n))
  111. #define STRSPN(s1, s2) (DWORD)MAKE_STR_FUNCTION(wcsspn)((s1), (s2))
  112. #define STRRCHR (LPTSTR)MAKE_STR_FUNCTION(wcsrchr)
  113. #define STRSTR (LPTSTR)MAKE_STR_FUNCTION(wcswcs)
  114. #define STRUPR(s) (LPTSTR)MAKE_STR_FUNCTION(_wcsupr)(s)
  115. // these don't have formal parameters because we want to take the address of
  116. // the mapped function in certain cases. Modify as appropriate.
  117. // Note that for these functions, lengths are in characters.
  118. // compare functions: len is maximum number of characters being compared.
  119. #define STRCMP (LONG)MAKE_STR_FUNCTION(wcscmp)
  120. #define STRCMPI (LONG)MAKE_STR_FUNCTION(_wcsicmp)
  121. #define STRICMP (LONG)MAKE_STR_FUNCTION(_wcsicmp)
  122. #define STRNCMP (LONG)MAKE_STR_FUNCTION(wcsncmp)
  123. #define STRNCMPI (LONG)MAKE_STR_FUNCTION(_wcsnicmp)
  124. #define STRNICMP (LONG)MAKE_STR_FUNCTION(_wcsnicmp)
  125. #define TOLOWER(tchar) towlower(tchar) // locale-dependent.
  126. #define TOUPPER(tchar) towupper(tchar) // locale-dependent.
  127. #define ULTOA(Value,Result,Radix) \
  128. (LPTSTR)MAKE_STR_FUNCTION(ultow)( (Value), (Result), (Radix) )
  129. //
  130. // manifests
  131. //
  132. #define _CHAR_TYPE WCHAR
  133. #else // not UNICODE
  134. //
  135. // function macro prototypes
  136. //
  137. #define ATOL(Src) (LONG)MAKE_STR_FUNCTION(atol)(Src)
  138. #define ISALNUM(tchar) isalnum(tchar) // locale-dependent.
  139. #define ISALPHA(tchar) isalpha(tchar) // locale-dependent.
  140. #define ISCNTRL(tchar) iscntrl(tchar) // locale-dependent.
  141. #define ISDIGIT(tchar) isdigit(tchar)
  142. #define ISGRAPH(tchar) isgraph(tchar) // locale-dependent.
  143. #define ISLOWER(tchar) islower(tchar) // locale-dependent.
  144. #define ISPRINT(tchar) isprint(tchar) // locale-dependent.
  145. #define ISPUNCT(tchar) ispunct(tchar) // locale-dependent.
  146. #define ISSPACE(tchar) isspace(tchar) // locale-dependent.
  147. #define ISUPPER(tchar) isupper(tchar) // locale-dependent.
  148. #define ISXDIGIT(tchar) isxdigit(tchar)
  149. #define STRCAT(dest, src) (LPTSTR)MAKE_STR_FUNCTION(strcat)((dest), (src))
  150. #define STRNCAT(dest, src, n) \
  151. (LPTSTR)MAKE_STR_FUNCTION(strncat)((dest), (src), (n))
  152. // STRLEN: Get character count of s.
  153. #define STRLEN(s) (DWORD)MAKE_STR_FUNCTION(strlen)(s)
  154. #define STRSPN(s1, s2) (DWORD)MAKE_STR_FUNCTION(strspn)((s1), (s2))
  155. #define STRCSPN(s, c) (DWORD)MAKE_STR_FUNCTION(strcspn)((s), (c))
  156. #define STRCPY(dest, src) (LPTSTR)MAKE_STR_FUNCTION(strcpy)((dest), (src))
  157. #define STRNCPY(dest, src, n) \
  158. (LPTSTR)MAKE_STR_FUNCTION(strncpy)((dest), (src), (n))
  159. #define STRCHR(s1, c) (LPTSTR)MAKE_STR_FUNCTION(strchr)((s1), (c))
  160. #define STRRCHR (LPTSTR)MAKE_STR_FUNCTION(strrchr)
  161. #define STRSTR (LPTSTR)MAKE_STR_FUNCTION(strstr)
  162. #define STRUPR(s) (LPTSTR)MAKE_STR_FUNCTION(strupr)(s)
  163. #define STRREV(s) (LPTSTR)MAKE_STR_FUNCTION(strrev)(s)
  164. // these don't have formal parameters because we want to take the address of
  165. // the mapped function in certain cases. Modify as appropriate.
  166. // Note that for these functions, lengths are in characters.
  167. // compare functions: len is maximum number of characters being compared.
  168. #define STRCMP (LONG)MAKE_STR_FUNCTION(lstrcmp)
  169. #define STRCMPI (LONG)MAKE_STR_FUNCTION(lstrcmpi)
  170. #define STRICMP (LONG)MAKE_STR_FUNCTION(lstrcmpi)
  171. #define STRNCMP (LONG)MAKE_STR_FUNCTION(strncmp)
  172. #define STRNCMPI (LONG)MAKE_STR_FUNCTION(_strnicmp)
  173. #define STRNICMP (LONG)MAKE_STR_FUNCTION(_strnicmp)
  174. #define TOLOWER(tchar) tolower(tchar) // locale-dependent.
  175. #define TOUPPER(tchar) toupper(tchar) // locale-dependent.
  176. #define ULTOA(Value,Result,Radix) \
  177. (LPTSTR)MAKE_STR_FUNCTION(_ultoa)( (Value), (Result), (Radix) )
  178. //
  179. // manifests
  180. //
  181. #define _CHAR_TYPE TCHAR
  182. #endif // not UNICODE
  183. //
  184. // For the memory routines, the counts are always BYTE counts.
  185. //
  186. #define MEMCPY MAKE_STR_FUNCTION(memcpy)
  187. #define MEMMOVE MAKE_STR_FUNCTION(memmove)
  188. //
  189. // These are used to determine the number of bytes (including the NUL
  190. // terminator) in a string. This will generally be used when
  191. // calculating the size of a string for allocation purposes.
  192. //
  193. #define STRSIZE(p) ((STRLEN(p)+1) * sizeof(TCHAR))
  194. #define WCSSIZE(s) ((MAKE_STR_FUNCTION(wcslen)(s)+1) * sizeof(WCHAR))
  195. //
  196. // character literals (both types)
  197. //
  198. #define TCHAR_EOS ((_CHAR_TYPE)'\0')
  199. #define TCHAR_STAR ((_CHAR_TYPE)'*')
  200. #define TCHAR_BACKSLASH ((_CHAR_TYPE)'\\')
  201. #define TCHAR_FWDSLASH ((_CHAR_TYPE)'/')
  202. #define TCHAR_COLON ((_CHAR_TYPE)':')
  203. #define TCHAR_DOT ((_CHAR_TYPE)'.')
  204. #define TCHAR_SPACE ((_CHAR_TYPE)' ')
  205. #define TCHAR_TAB ((_CHAR_TYPE)'\t')
  206. //
  207. // General purpose macro for casting character types to whatever type in vogue
  208. // (as defined in this file)
  209. //
  210. #define MAKE_TCHAR(c) ((_CHAR_TYPE)(c))
  211. //
  212. // IS_PATH_SEPARATOR
  213. //
  214. // lifted from curdir.c and changed to use TCHAR_ character literals, checks
  215. // if a character is a path separator i.e. is a member of the set [\/]
  216. //
  217. #define IS_PATH_SEPARATOR(ch) ((ch == TCHAR_BACKSLASH) || (ch == TCHAR_FWDSLASH))
  218. //
  219. // The following 2 macros lifted from I_Net canonicalization files
  220. //
  221. #define IS_DRIVE(c) ISALPHA(c)
  222. #define IS_NON_ZERO_DIGIT(c) (((c) >= MAKE_TCHAR('1')) && ((c) <= MAKE_TCHAR('9')))
  223. //
  224. // STRING_SPACE_REQD returns a number (of bytes) corresponding to the space
  225. // required in which (n) characters can be accomodated
  226. //
  227. #define STRING_SPACE_REQD(n) ((n) * sizeof(_CHAR_TYPE))
  228. //
  229. // DOWN_LEVEL_STRLEN returns the number of single-byte characters necessary to
  230. // store a converted _CHAR_TYPE string. This will be WCHAR (or wchar_t) if
  231. // UNICODE is defined or CHAR (or char) otherwise
  232. //
  233. #define DOWN_LEVEL_STRSIZE(n) ((n) / sizeof(_CHAR_TYPE))
  234. #endif // _TSTR_H_INCLUDED