Source code of Windows XP (NT5)
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.

272 lines
7.1 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1996 Microsoft Corporation
  4. //
  5. // File: olestr.h
  6. //
  7. // Synopsis: ct versions of the printf family and olestr functions
  8. //
  9. // History: 30-May-96 MikeW Created.
  10. // 12-Nov-97 a-sverrt Added a couple more olestrxxx macros.
  11. //
  12. // Notes: The ct version of the printf family adds two new format
  13. // specifiers: %os and %oc. These specifiers mean ole-string
  14. // and ole-character respectively.
  15. //
  16. // In the ANSI-version of this family these specifiers mean
  17. // "an octal digit followed by the letter s (or c)". Code that
  18. // uses octal should be careful when using these functions.
  19. //
  20. //-----------------------------------------------------------------------------
  21. #ifndef _OLESTR_H_
  22. #define _OLESTR_H_
  23. //
  24. // Determine if Ole is Unicode based or not
  25. //
  26. #if !defined(WIN16) && !defined(_MAC)
  27. #define OLE_IS_UNICODE
  28. #endif
  29. //
  30. // Use : as path separator on Mac
  31. //
  32. #ifdef _MAC
  33. #define CH_SEP ':'
  34. #define SZ_SEP TEXT(":")
  35. #else
  36. #define CH_SEP '\\'
  37. #define SZ_SEP TEXT("\\")
  38. #endif // _MAC
  39. //
  40. // Format specifiers for Unicode and Ansi strings and characters
  41. //
  42. #define UNICODE_STRING_SPECIFIER "ls"
  43. #define UNICODE_CHAR_SPECIFIER "lc"
  44. #define ANSI_STRING_SPECIFIER "hs"
  45. #define ANSI_CHAR_SPECIFIER "hc"
  46. //
  47. // Format specifiers for Ole strings and characters
  48. //
  49. #ifdef OLE_IS_UNICODE
  50. #define OLE_STRING_SPECIFIER UNICODE_STRING_SPECIFIER
  51. #define OLE_CHAR_SPECIFIER UNICODE_CHAR_SPECIFIER
  52. #else // !OLE_IS_UNICODE
  53. #define OLE_STRING_SPECIFIER ANSI_STRING_SPECIFIER
  54. #define OLE_CHAR_SPECIFIER ANSI_CHAR_SPECIFIER
  55. #endif // !OLE_IS_UNICODE
  56. //
  57. // Unicode/Ansi indepedent ctprintf-family
  58. //
  59. #ifndef UNICODE_ONLY
  60. int ctprintfA(const char *format, ...);
  61. int ctsprintfA(char *buffer, const char *format, ...);
  62. int ctsnprintfA(char *buffer, size_t count, const char *format, ...);
  63. int ctfprintfA(FILE *stream, const char *format, ...);
  64. int ctvprintfA(const char *format, va_list varargs);
  65. int ctvsprintfA(char *buffer, const char *format, va_list varargs);
  66. int ctvsnprintfA(
  67. char *buffer,
  68. size_t count,
  69. const char *format,
  70. va_list varargs);
  71. int ctvfprintfA(FILE *stream, const char *format, va_list varargs);
  72. #endif // !UNICODE_ONLY
  73. #ifndef ANSI_ONLY
  74. int ctprintfW(const wchar_t *format, ...);
  75. int ctsprintfW(wchar_t *buffer, const wchar_t *format, ...);
  76. int ctsnprintfW(wchar_t *buffer, size_t count, const wchar_t *format, ...);
  77. int ctfprintfW(FILE *stream, const wchar_t *format, ...);
  78. int ctvprintfW(const wchar_t *format, va_list varargs);
  79. int ctvsprintfW(wchar_t *buffer, const wchar_t *format, va_list varargs);
  80. int ctvsnprintfW(
  81. wchar_t *buffer,
  82. size_t count,
  83. const wchar_t *format,
  84. va_list varargs);
  85. int ctvfprintfW(FILE *stream, const wchar_t *format, va_list varargs);
  86. #endif //!ANSI_ONLY
  87. #ifdef UNICODE
  88. #define ctprintf ctprintfW
  89. #define ctsprintf ctsprintfW
  90. #define ctsnprintf ctsnprintfW
  91. #define ctfprintf ctfprintfW
  92. #define ctvprintf ctvprintfW
  93. #define ctvsprintf ctvsprintfW
  94. #define ctvsnprintf ctvsnprintfW
  95. #define ctvfprintf ctvfprintfW
  96. #else // !UNICODE
  97. #define ctprintf ctprintfA
  98. #define ctsprintf ctsprintfA
  99. #define ctsnprintf ctsnprintfA
  100. #define ctfprintf ctfprintfA
  101. #define ctvprintf ctvprintfA
  102. #define ctvsprintf ctvsprintfA
  103. #define ctvsnprintf ctvsnprintfA
  104. #define ctvfprintf ctvfprintfA
  105. #endif // !UNICODE
  106. //
  107. // Unicode/Ansi independent ole string functions
  108. //
  109. #ifdef OLE_IS_UNICODE
  110. #define olembstowcs(x,y,z) mbstowcs(x,y,z)
  111. #define olestrcat wcscat
  112. #define olestrchr wcschr
  113. #define olestrcmp wcscmp
  114. #define olestrcpy wcscpy
  115. #define _olestricmp _wcsicmp
  116. #define olestrlen wcslen
  117. #define olestrncmp wcsncmp
  118. #define olestrncpy wcsncpy
  119. #define _olestrnicmp _wcsnicmp
  120. #define olestrrchr wcsrchr
  121. #define olestrstr wcsstr
  122. #define olestrtok wcstok
  123. #define olestrtol wcstol
  124. #define olestrtoul wcstoul
  125. #define olestrtombs(x,y,z) wcstombs(x,y,z)
  126. #define olewcstombs(x,y,z) wcstombs(x,y,z)
  127. #define tooleupper towupper
  128. #define _ltoole _ltow
  129. #define olectsnprintf ctsnprintfW
  130. #define olectsprintf ctsprintfW
  131. #define olesscanf swscanf
  132. #define olesprintf swprintf
  133. #else // !OLE_IS_UNICODE
  134. #define olembstowcs(x,y,z) strcpy(x,y)
  135. #define olestrcat strcat
  136. #define olestrchr strchr
  137. #define olestrcmp strcmp
  138. #define olestrcpy strcpy
  139. #define _olestricmp _stricmp
  140. #define olestrlen strlen
  141. #define olestrncmp strncmp
  142. #define olestrncpy strncpy
  143. #define _olestrnicmp _strnicmp
  144. #define olestrrchr strrchr
  145. #define olestrstr strstr
  146. #define olestrtok strtok
  147. #define olestrtol strtol
  148. #define olestrtoul strtoul
  149. #define olestrtombs(x,y,z) strncpy(x,y,z)
  150. #define olewcstombs(x,y,z) strcpy(x,y) // srt: equivalent to converting in this case
  151. #define tooleupper toupper
  152. #define _ltoole _ltoa
  153. #define olectsnprintf ctsnprintfA
  154. #define olectsprintf ctsprintfA
  155. #define olesscanf sscanf
  156. #define olesprintf sprintf
  157. #endif // !OLE_IS_UNICODE
  158. //
  159. // String copy & conversion functions
  160. //
  161. #ifdef __cplusplus
  162. HRESULT CopyString(LPCWSTR, LPSTR *);
  163. HRESULT CopyString(LPCSTR, LPWSTR *);
  164. HRESULT CopyString(LPCSTR, LPSTR *);
  165. HRESULT CopyString(LPCWSTR, LPWSTR *);
  166. HRESULT CopyString(LPCWSTR, LPSTR, int, int);
  167. HRESULT CopyString(LPCSTR, LPWSTR, int, int);
  168. //+--------------------------------------------------------------------------
  169. //
  170. // unsigned char thunks
  171. //
  172. // DBCS chars are unsigned so the signed functions above won't match.
  173. // However, the signed functions are written to be DBCS aware so it's ok
  174. // to just cast & thunk.
  175. //
  176. //---------------------------------------------------------------------------
  177. inline HRESULT CopyString(LPCWSTR pszSource, unsigned char **ppszDest)
  178. {
  179. return CopyString(pszSource, (char **) ppszDest);
  180. }
  181. inline HRESULT CopyString(unsigned char *pszSource, LPWSTR *ppszDest)
  182. {
  183. return CopyString((char *) pszSource, ppszDest);
  184. }
  185. inline HRESULT CopyString(unsigned char *pszSource, unsigned char ** ppszDest)
  186. {
  187. return CopyString((char *) pszSource, (char **) ppszDest);
  188. }
  189. #endif // __cplusplus
  190. HRESULT TStringToOleString(LPCTSTR pszSource, LPOLESTR *ppszDest);
  191. HRESULT WStringToOleString(LPCWSTR pszSource, LPOLESTR *ppszDest);
  192. HRESULT AStringToOleString(LPCSTR pszSource, LPOLESTR *ppszDest);
  193. HRESULT OleStringToTString(LPCOLESTR pszSource, LPTSTR *ppszDest);
  194. HRESULT OleStringToWString(LPCOLESTR pszSource, LPWSTR *ppszDest);
  195. HRESULT OleStringToAString(LPCOLESTR pszSource, LPSTR *ppszDest);
  196. HRESULT TStringToAString (LPCTSTR pszSource, LPSTR *ppszDest);
  197. HRESULT AStringToTString (LPCSTR pszSource, LPTSTR *ppszDest);
  198. #endif // _OLESTR_H_