Windows NT 4.0 source code leak
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.

240 lines
7.9 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. tstring.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. Revision History:
  16. 22-May-1991 Danl
  17. Added STRSIZE macro
  18. 19-May-1991 JohnRo
  19. Changed some parm names to make things easier to read.
  20. 15-May-1991 rfirth
  21. Added TCHAR_SPACE and MAKE_TCHAR() macro
  22. 15-Jul-1991 RFirth
  23. Added STRING_SPACE_REQD() and DOWN_LEVEL_STRSIZE
  24. 05-Aug-1991 JohnRo
  25. Added MEMCPY macro.
  26. 19-Aug-1991 JohnRo
  27. Added character type stuff: ISDIGIT(), TOUPPER(), etc.
  28. 20-Aug-1991 JohnRo
  29. Changed strnicmp to _strnicmp to keep PC-LINT happy. Ditto stricmp.
  30. 13-Sep-1991 JohnRo
  31. Need UNICODE STRSIZE() too.
  32. 13-Sep-1991 JohnRo
  33. Added UNICODE STRCMP() and various others.
  34. 07-May-1992 beng
  35. Use official wchar.h header file
  36. --*/
  37. #ifndef _TSTRING_H_INCLUDED
  38. #define _TSTRING_H_INCLUDED
  39. #include <ctype.h> // isdigit(), iswdigit() eventually, etc.
  40. #ifdef LM20_COMPATIBLE
  41. #define MAKE_STR_FUNCTION(s) s##f
  42. #else
  43. #define MAKE_STR_FUNCTION(s) s
  44. #endif
  45. #if defined(UNICODE)
  46. #include <wchar.h> // wcslen(), etc.
  47. //
  48. // function macro prototypes
  49. //
  50. #define ISALNUM(tchar) iswalnum(tchar) // locale-dependent.
  51. #define ISALPHA(tchar) iswalpha(tchar) // locale-dependent.
  52. #define ISCNTRL(tchar) iswcntrl(tchar) // locale-dependent.
  53. #define ISDIGIT(tchar) iswdigit(tchar)
  54. #define ISGRAPH(tchar) iswgraph(tchar) // locale-dependent.
  55. #define ISLOWER(tchar) iswlower(tchar) // locale-dependent.
  56. #define ISPRINT(tchar) iswprint(tchar) // locale-dependent.
  57. #define ISPUNCT(tchar) iswpunct(tchar) // locale-dependent.
  58. #define ISSPACE(tchar) iswspace(tchar) // locale-dependent.
  59. #define ISUPPER(tchar) iswupper(tchar) // locale-dependent.
  60. #define ISXDIGIT(tchar) iswxdigit(tchar)
  61. #define STRCAT(dest, src) wcscat((dest), (src))
  62. #define STRCHR(s1, c) (LPTSTR)MAKE_STR_FUNCTION(wcschr)((s1), (c))
  63. #define STRCPY(dest, src) wcscpy((dest), (src))
  64. #define STRCSPN(s, c) (DWORD)MAKE_STR_FUNCTION(wcscspn)((s), (c))
  65. // STRLEN: Get character count of s.
  66. #define STRLEN(s) wcslen(s)
  67. #define STRNCAT(dest, src, n) \
  68. (LPTSTR)MAKE_STR_FUNCTION(wcsncat)((dest), (src), (n))
  69. #define STRNCPY(dest, src, n) \
  70. (LPTSTR)MAKE_STR_FUNCTION(wcsncpy)((dest), (src), (n))
  71. #define STRSPN(s1, s2) (DWORD)MAKE_STR_FUNCTION(wcsspn)((s1), (s2))
  72. #define STRRCHR (LPTSTR)MAKE_STR_FUNCTION(wcsrchr)
  73. #define STRTAIL(s1, s2) (LPTSTR)MAKE_STR_FUNCTION(wcstail)((s1), (s2))
  74. #define STRUPR(s) (LPTSTR)MAKE_STR_FUNCTION(wcsupr)(s)
  75. // these don't have formal parameters because we want to take the address of
  76. // the mapped function in certain cases. Modify as appropriate.
  77. // Note that for these functions, lengths are in characters.
  78. // compare functions: len is maximum number of characters being compared.
  79. #define STRCMP wcscmp
  80. #define STRICMP (LONG)MAKE_STR_FUNCTION(_wcsicmp)
  81. #define STRNCMP (LONG)MAKE_STR_FUNCTION(wcsncmp)
  82. #define STRNICMP (LONG)MAKE_STR_FUNCTION(_wcsnicmp)
  83. #define TOLOWER(tchar) towlower(tchar) // locale-dependent.
  84. #define TOUPPER(tchar) towupper(tchar) // locale-dependent.
  85. //
  86. // manifests
  87. //
  88. #define _CHAR_TYPE WCHAR
  89. #else // not UNICODE
  90. #include <string.h> // strlen(), etc.
  91. //
  92. // function macro prototypes
  93. //
  94. #define ISALNUM(tchar) isalnum(tchar) // locale-dependent.
  95. #define ISALPHA(tchar) isalpha(tchar) // locale-dependent.
  96. #define ISCNTRL(tchar) iscntrl(tchar) // locale-dependent.
  97. #define ISDIGIT(tchar) isdigit(tchar)
  98. #define ISGRAPH(tchar) isgraph(tchar) // locale-dependent.
  99. #define ISLOWER(tchar) islower(tchar) // locale-dependent.
  100. #define ISPRINT(tchar) isprint(tchar) // locale-dependent.
  101. #define ISPUNCT(tchar) ispunct(tchar) // locale-dependent.
  102. #define ISSPACE(tchar) isspace(tchar) // locale-dependent.
  103. #define ISUPPER(tchar) isupper(tchar) // locale-dependent.
  104. #define ISXDIGIT(tchar) isxdigit(tchar)
  105. #define STRCAT(dest, src) (LPTSTR)MAKE_STR_FUNCTION(strcat)((dest), (src))
  106. #define STRNCAT(dest, src, n) \
  107. (LPTSTR)MAKE_STR_FUNCTION(strncat)((dest), (src), (n))
  108. // STRLEN: Get character count of s.
  109. #define STRLEN(s) (DWORD)MAKE_STR_FUNCTION(strlen)(s)
  110. #define STRSPN(s1, s2) (DWORD)MAKE_STR_FUNCTION(strspn)((s1), (s2))
  111. #define STRCSPN(s, c) (DWORD)MAKE_STR_FUNCTION(strcspn)((s), (c))
  112. #define STRCPY(dest, src) (LPTSTR)MAKE_STR_FUNCTION(strcpy)((dest), (src))
  113. #define STRNCPY(dest, src, n) \
  114. (LPTSTR)MAKE_STR_FUNCTION(strncpy)((dest), (src), (n))
  115. #define STRCHR(s1, c) (LPTSTR)MAKE_STR_FUNCTION(strchr)((s1), (c))
  116. #define STRRCHR (LPTSTR)MAKE_STR_FUNCTION(strrchr)
  117. #define STRTAIL(s1, s2) (LPTSTR)MAKE_STR_FUNCTION(strtail)((s1), (s2))
  118. #define STRUPR(s) (LPTSTR)MAKE_STR_FUNCTION(strupr)(s)
  119. // these don't have formal parameters because we want to take the address of
  120. // the mapped function in certain cases. Modify as appropriate.
  121. // Note that for these functions, lengths are in characters.
  122. // compare functions: len is maximum number of characters being compared.
  123. #define STRCMP (LONG)MAKE_STR_FUNCTION(strcmp)
  124. #define STRICMP (LONG)MAKE_STR_FUNCTION(_stricmp)
  125. #define STRNCMP (LONG)MAKE_STR_FUNCTION(strncmp)
  126. #define STRNICMP (LONG)MAKE_STR_FUNCTION(_strnicmp)
  127. #define TOLOWER(tchar) tolower(tchar) // locale-dependent.
  128. #define TOUPPER(tchar) toupper(tchar) // locale-dependent.
  129. //
  130. // manifests
  131. //
  132. #define _CHAR_TYPE TCHAR
  133. #endif // not UNICODE
  134. //
  135. // For the memory routines, the counts are always BYTE counts.
  136. //
  137. #define MEMCPY memcpy
  138. #define MEMMOVE memmove
  139. //
  140. // This is used to determine the number of bytes (including the NUL
  141. // terminator) in a unicode string. This will generally be used when
  142. // calculating the size of a string for allocation purposes.
  143. //
  144. #define STRSIZE(p) ((STRLEN(p)+1) * sizeof(TCHAR))
  145. //
  146. // character literals (both types)
  147. //
  148. #define TCHAR_EOS ((_CHAR_TYPE)'\0')
  149. #define TCHAR_STAR ((_CHAR_TYPE)'*')
  150. #define TCHAR_BACKSLASH ((_CHAR_TYPE)'\\')
  151. #define TCHAR_FWDSLASH ((_CHAR_TYPE)'/')
  152. #define TCHAR_COLON ((_CHAR_TYPE)':')
  153. #define TCHAR_DOT ((_CHAR_TYPE)'.')
  154. #define TCHAR_SPACE ((_CHAR_TYPE)' ')
  155. //
  156. // General purpose macro for casting character types to whatever type in vogue
  157. // (as defined in this file)
  158. //
  159. #define MAKE_TCHAR(c) ((_CHAR_TYPE)(c))
  160. //
  161. // IS_PATH_SEPARATOR
  162. //
  163. // lifted from curdir.c and changed to use TCHAR_ character literals, checks
  164. // if a character is a path separator i.e. is a member of the set [\/]
  165. //
  166. #define IS_PATH_SEPARATOR(ch) ((ch == TCHAR_BACKSLASH) || (ch == TCHAR_FWDSLASH))
  167. //
  168. // The following 2 macros lifted from I_Net canonicalization files
  169. //
  170. #define IS_DRIVE(c) ISALPHA(c)
  171. #define IS_NON_ZERO_DIGIT(c) (((c) >= MAKE_TCHAR('1')) && ((c) <= MAKE_TCHAR('9')))
  172. //
  173. // STRING_SPACE_REQD returns a number (of bytes) corresponding to the space
  174. // required in which (n) characters can be accomodated
  175. //
  176. #define STRING_SPACE_REQD(n) ((n) * sizeof(_CHAR_TYPE))
  177. //
  178. // DOWN_LEVEL_STRLEN returns the number of single-byte characters necessary to
  179. // store a converted _CHAR_TYPE string. This will be WCHAR (or wchar_t) if
  180. // UNICODE is defined or TCHAR (or char) otherwise
  181. //
  182. #define DOWN_LEVEL_STRSIZE(n) ((n) / sizeof(_CHAR_TYPE))
  183. #endif // _TSTRING_H_INCLUDED