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.

382 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. hash.h
  5. Abstract:
  6. Replacement routines for the string table functions in setupapi.dll.
  7. This routines are much more easy to work with.
  8. Author:
  9. Jim Schmidt (jimschm) 22-Dec-1998
  10. Revision History:
  11. ovidiut 11-Oct-1999 Updated for new coding conventions and Win64 compliance
  12. --*/
  13. //
  14. // Includes
  15. //
  16. // None
  17. //
  18. // Strings
  19. //
  20. // None
  21. //
  22. // Constants
  23. //
  24. // None
  25. //
  26. // Macros
  27. //
  28. #define CASE_SENSITIVE TRUE
  29. #define CASE_INSENSITIVE FALSE
  30. #define UNKNOWN_LETTER_CASE FALSE
  31. #define ALREADY_LOWERCASE TRUE
  32. #define DEFAULT_BUCKET_SIZE 0
  33. //
  34. // Types
  35. //
  36. typedef const void *HASHTABLE;
  37. typedef const void *HASHITEM;
  38. typedef struct {
  39. PCSTR String;
  40. PCVOID ExtraData;
  41. HASHITEM Index;
  42. HASHTABLE Internal;
  43. } HASHTABLE_ENUMA, *PHASHTABLE_ENUMA;
  44. typedef struct {
  45. PCWSTR String;
  46. PCVOID ExtraData;
  47. HASHITEM Index;
  48. HASHTABLE Internal;
  49. } HASHTABLE_ENUMW, *PHASHTABLE_ENUMW;
  50. typedef
  51. BOOL
  52. (*PHASHTABLE_CALLBACK_ROUTINEA)(
  53. IN HASHTABLE HashTable,
  54. IN HASHITEM Index,
  55. IN PCSTR String,
  56. IN PVOID ExtraData,
  57. IN UINT ExtraDataSize,
  58. IN LPARAM lParam
  59. );
  60. typedef
  61. BOOL
  62. (*PHASHTABLE_CALLBACK_ROUTINEW)(
  63. IN HASHTABLE HashTable,
  64. IN HASHITEM Index,
  65. IN PCWSTR String,
  66. IN PVOID ExtraData,
  67. IN UINT ExtraDataSize,
  68. IN LPARAM lParam
  69. );
  70. typedef enum {
  71. WRITE_UNICODE_HEADER = 0x0001,
  72. REVERSE_ORDER = 0x0002
  73. } HASHTABLEOUTPUTFLAGS;
  74. //
  75. // Globals
  76. //
  77. // None
  78. //
  79. // Macro expansion list
  80. //
  81. // None
  82. //
  83. // Function prototypes and wrapper macros
  84. //
  85. HASHTABLE
  86. HtAllocExAW (
  87. IN BOOL CaseSensitive,
  88. IN BOOL Unicode,
  89. IN BOOL ExternalStrings,
  90. IN UINT ExtraDataSize,
  91. IN UINT BucketCount OPTIONAL
  92. );
  93. #define HtAllocA() HtAllocExAW(FALSE,FALSE,FALSE,0,0)
  94. #define HtAllocW() HtAllocExAW(FALSE,TRUE,FALSE,0,0)
  95. #define HtAllocWithDataA(size) HtAllocExAW(FALSE,FALSE,FALSE,size,0)
  96. #define HtAllocWithDataW(size) HtAllocExAW(FALSE,TRUE,FALSE,size,0)
  97. #define HtAllocExA(cs,datasize,bucketcount) HtAllocExAW(cs,FALSE,FALSE,datasize,bucketcount)
  98. #define HtAllocExW(cs,datasize,bucketcount) HtAllocExAW(cs,TRUE,FALSE,datasize,bucketcount)
  99. #define HtAllocExternStrA() HtAllocExAW(FALSE,FALSE,TRUE,0,0)
  100. #define HtAllocExternStrW() HtAllocExAW(FALSE,TRUE,TRUE,0,0)
  101. #define HtAllocExternStrWithDataA(size) HtAllocExAW(FALSE,FALSE,TRUE,0,0)
  102. #define HtAllocExternStrWithDataW(size) HtAllocExAW(FALSE,TRUE,TRUE,0,0)
  103. #define HtAllocExternStrExA(cs,size,bucketcount) HtAllocExAW(cs,FALSE,TRUE,size,bucketcount)
  104. #define HtAllocExternStrExW(cs,size,bucketcount) HtAllocExAW(cs,TRUE,TRUE,size,bucketcount)
  105. VOID
  106. HtFree (
  107. IN HASHTABLE HashTable
  108. );
  109. HASHITEM
  110. HtAddStringExA (
  111. IN HASHTABLE HashTable,
  112. IN PCSTR String,
  113. IN PCVOID ExtraData, OPTIONAL
  114. IN BOOL AlreadyLowercase
  115. );
  116. #define HtAddStringA(table,string) HtAddStringExA(table,string,NULL,UNKNOWN_LETTER_CASE)
  117. #define HtAddStringAndDataA(table,string,data) HtAddStringExA(table,string,data,UNKNOWN_LETTER_CASE)
  118. HASHITEM
  119. HtAddStringExW (
  120. IN HASHTABLE HashTable,
  121. IN PCWSTR String,
  122. IN PCVOID ExtraData, OPTIONAL
  123. IN BOOL AlreadyLowercase
  124. );
  125. #define HtAddStringW(table,string) HtAddStringExW(table,string,NULL,UNKNOWN_LETTER_CASE)
  126. #define HtAddStringAndDataW(table,string,data) HtAddStringExW(table,string,data,UNKNOWN_LETTER_CASE)
  127. BOOL
  128. HtRemoveItem (
  129. IN HASHTABLE HashTable,
  130. IN HASHITEM Item
  131. );
  132. BOOL
  133. HtRemoveStringA (
  134. IN HASHTABLE HashTable,
  135. IN PCSTR AnsiString
  136. );
  137. BOOL
  138. HtRemoveStringW (
  139. IN HASHTABLE HashTable,
  140. IN PCWSTR UnicodeString
  141. );
  142. HASHITEM
  143. HtFindStringExA (
  144. IN HASHTABLE HashTable,
  145. IN PCSTR String,
  146. OUT PVOID ExtraData, OPTIONAL
  147. IN BOOL AlreadyLowercase
  148. );
  149. #define HtFindStringA(table,string) HtFindStringExA(table,string,NULL,UNKNOWN_LETTER_CASE)
  150. #define HtFindStringAndDataA(table,string,data) HtFindStringExA(table,string,data,UNKNOWN_LETTER_CASE)
  151. HASHITEM
  152. HtFindStringExW (
  153. IN HASHTABLE HashTable,
  154. IN PCWSTR String,
  155. OUT PVOID ExtraData, OPTIONAL
  156. IN BOOL AlreadyLowercase
  157. );
  158. #define HtFindStringW(table,string) HtFindStringExW(table,string,NULL,UNKNOWN_LETTER_CASE)
  159. #define HtFindStringAndDataW(table,string,data) HtFindStringExW(table,string,data,UNKNOWN_LETTER_CASE)
  160. HASHITEM
  161. HtFindPrefixExA (
  162. IN HASHTABLE HashTable,
  163. IN PCSTR StringStart,
  164. IN PCSTR BufferEnd,
  165. OUT PVOID ExtraData, OPTIONAL
  166. IN BOOL AlreadyLowercase
  167. );
  168. #define HtFindPrefixA(table,str,end) HtFindPrefixExA(table,str,end,NULL,UNKNOWN_LETTER_CASE)
  169. HASHITEM
  170. HtFindPrefixExW (
  171. IN HASHTABLE HashTable,
  172. IN PCWSTR StringStart,
  173. IN PCWSTR BufferEnd,
  174. OUT PVOID ExtraData, OPTIONAL
  175. IN BOOL AlreadyLowercase
  176. );
  177. #define HtFindPrefixW(table,str,end) HtFindPrefixExW(table,str,end,NULL,UNKNOWN_LETTER_CASE)
  178. BOOL
  179. HtGetExtraData (
  180. IN HASHTABLE HashTable,
  181. IN HASHITEM Index,
  182. OUT PCVOID *ExtraData
  183. );
  184. BOOL
  185. HtCopyStringData (
  186. IN HASHTABLE HashTable,
  187. IN HASHITEM Index,
  188. OUT PVOID ExtraData
  189. );
  190. BOOL
  191. HtSetStringData (
  192. IN HASHTABLE HashTable,
  193. IN HASHITEM Index,
  194. IN PCVOID ExtraData
  195. );
  196. PCSTR
  197. HtGetStringFromItemA (
  198. IN HASHITEM Index
  199. );
  200. PCWSTR
  201. HtGetStringFromItemW (
  202. IN HASHITEM Index
  203. );
  204. BOOL
  205. EnumFirstHashTableStringA (
  206. OUT PHASHTABLE_ENUMA EnumPtr,
  207. IN HASHTABLE HashTable
  208. );
  209. BOOL
  210. EnumFirstHashTableStringW (
  211. OUT PHASHTABLE_ENUMW EnumPtr,
  212. IN HASHTABLE HashTable
  213. );
  214. BOOL
  215. EnumNextHashTableStringA (
  216. IN OUT PHASHTABLE_ENUMA EnumPtr
  217. );
  218. BOOL
  219. EnumNextHashTableStringW (
  220. IN OUT PHASHTABLE_ENUMW EnumPtr
  221. );
  222. BOOL
  223. EnumHashTableWithCallbackA (
  224. IN HASHTABLE Table,
  225. IN PHASHTABLE_CALLBACK_ROUTINEA Proc,
  226. IN LPARAM lParam
  227. );
  228. BOOL
  229. EnumHashTableWithCallbackW (
  230. IN HASHTABLE Table,
  231. IN PHASHTABLE_CALLBACK_ROUTINEW Proc,
  232. IN LPARAM lParam
  233. );
  234. BOOL
  235. HtIsEmpty (
  236. IN HASHTABLE HashTable
  237. );
  238. BOOL
  239. HtWriteToFile (
  240. IN HASHTABLE HashTable,
  241. IN HANDLE OutputFile,
  242. IN HASHTABLEOUTPUTFLAGS Flags
  243. );
  244. //
  245. // Macro expansion definition
  246. //
  247. // None
  248. //
  249. // A & W macros
  250. //
  251. #ifdef UNICODE
  252. #define HASHTABLE_ENUM HASHTABLE_ENUMW
  253. #define PHASHTABLE_ENUM PHASHTABLE_ENUMW
  254. #define PHASH_CALLBACK_ROUTINE PHASH_CALLBACK_ROUTINEW
  255. #define HtAlloc HtAllocW
  256. #define HtAllocWithData HtAllocWithDataW
  257. #define HtAllocEx HtAllocExW
  258. #define HtAllocExternStr HtAllocExternStrW
  259. #define HtAllocExternStrWithData HtAllocExternStrWithDataW
  260. #define HtAllocExternStrEx HtAllocExternStrExW
  261. #define HtAddString HtAddStringW
  262. #define HtAddStringAndData HtAddStringAndDataW
  263. #define HtAddStringEx HtAddStringExW
  264. #define HtRemoveString HtRemoveStringW
  265. #define HtFindString HtFindStringW
  266. #define HtFindStringAndData HtFindStringAndDataW
  267. #define HtFindStringEx HtFindStringExW
  268. #define HtFindPrefix HtFindPrefixW
  269. #define HtFindPrefixEx HtFindPrefixExW
  270. #define HtGetStringFromItem HtGetStringFromItemW
  271. #define EnumFirstHashTableString EnumFirstHashTableStringW
  272. #define EnumNextHashTableString EnumNextHashTableStringW
  273. #define EnumHashTableWithCallback EnumHashTableWithCallbackW
  274. #else
  275. #define HASHTABLE_ENUM HASHTABLE_ENUMA
  276. #define PHASHTABLE_ENUM PHASHTABLE_ENUMA
  277. #define PHASH_CALLBACK_ROUTINE PHASH_CALLBACK_ROUTINEA
  278. #define HtAlloc HtAllocA
  279. #define HtAllocWithData HtAllocWithDataA
  280. #define HtAllocEx HtAllocExA
  281. #define HtAllocExternStr HtAllocExternStrA
  282. #define HtAllocExternStrWithData HtAllocExternStrWithDataA
  283. #define HtAllocExternStrEx HtAllocExternStrExA
  284. #define HtAddString HtAddStringA
  285. #define HtAddStringAndData HtAddStringAndDataA
  286. #define HtAddStringEx HtAddStringExA
  287. #define HtRemoveString HtRemoveStringA
  288. #define HtFindString HtFindStringA
  289. #define HtFindStringAndData HtFindStringAndDataA
  290. #define HtFindStringEx HtFindStringExA
  291. #define HtFindPrefix HtFindPrefixA
  292. #define HtFindPrefixEx HtFindPrefixExA
  293. #define HtGetStringFromItem HtGetStringFromItemA
  294. #define EnumFirstHashTableString EnumFirstHashTableStringA
  295. #define EnumNextHashTableString EnumNextHashTableStringA
  296. #define EnumHashTableWithCallback EnumHashTableWithCallbackA
  297. #endif