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.

270 lines
8.2 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. growlist.h
  5. Abstract:
  6. Implements a dynamic array-indexed list of binary objects. Typically,
  7. the binary objects are strings. The list uses a GROWBUF for the array,
  8. and a pool for the binary data of each list item.
  9. Author:
  10. Jim Schmidt (jimschm) 08-Aug-1997
  11. Revision History:
  12. <alias> <date> <comments>
  13. --*/
  14. #pragma once
  15. typedef struct {
  16. GROWBUFFER ListArray;
  17. PMHANDLE ListData;
  18. } GROWLIST, *PGROWLIST;
  19. #ifdef DEBUG
  20. #define INIT_GROWLIST {NULL,0,0,0,0,0, NULL}
  21. #else
  22. #define INIT_GROWLIST {NULL,0,0,0,0, NULL}
  23. #endif
  24. #define GlGetPtrArray(listptr) ((PVOID *) ((listptr)->ListArray.Buf))
  25. #define GlGetStringPtrArrayA(listptr) ((PCSTR *) ((listptr)->ListArray.Buf))
  26. #define GlGetStringPtrArrayW(listptr) ((PCWSTR *) ((listptr)->ListArray.Buf))
  27. PBYTE
  28. RealGlAppend (
  29. IN OUT PGROWLIST GrowList,
  30. IN PBYTE DataToAppend, OPTIONAL
  31. IN UINT SizeOfData
  32. );
  33. #define GlAppend(list,data,size) TRACK_BEGIN(PBYTE, GlAppend)\
  34. RealGlAppend (list,data,size) \
  35. TRACK_END()
  36. PBYTE
  37. RealGlAppendAddNul (
  38. IN OUT PGROWLIST GrowList,
  39. IN PBYTE DataToAppend, OPTIONAL
  40. IN UINT SizeOfData
  41. );
  42. #define GlAppendAddNul(list,data,size) TRACK_BEGIN(PBYTE, GlAppendAddNul) \
  43. RealGlAppendAddNul (list,data,size) \
  44. TRACK_END()
  45. VOID
  46. GlFree (
  47. IN PGROWLIST GrowList
  48. );
  49. VOID
  50. GlReset (
  51. IN OUT PGROWLIST GrowList
  52. );
  53. PBYTE
  54. GlGetItem (
  55. IN PGROWLIST GrowList,
  56. IN UINT Index
  57. );
  58. UINT
  59. GlGetSize (
  60. IN PGROWLIST GrowList
  61. );
  62. PBYTE
  63. RealGlInsert (
  64. IN OUT PGROWLIST GrowList,
  65. IN UINT Index,
  66. IN PBYTE DataToAppend, OPTIONAL
  67. IN UINT SizeOfData
  68. );
  69. #define GlInsert(list,index,data,size) TRACK_BEGIN(PBYTE,GlInsert) \
  70. RealGlInsert (list,index,data,size) \
  71. TRACK_END()
  72. PBYTE
  73. RealGlInsertAddNul (
  74. IN OUT PGROWLIST GrowList,
  75. IN UINT Index,
  76. IN PBYTE DataToAppend, OPTIONAL
  77. IN UINT SizeOfData
  78. );
  79. #define GlInsertAddNul(list,index,data,size) TRACK_BEGIN(PBYTE, GlInsertAddNul) \
  80. RealGlInsertAddNul (list,index,data,size) \
  81. TRACK_END()
  82. BOOL
  83. GlDeleteItem (
  84. IN OUT PGROWLIST GrowList,
  85. IN UINT Index
  86. );
  87. BOOL
  88. GlResetItem (
  89. IN OUT PGROWLIST GrowList,
  90. IN UINT Index
  91. );
  92. PBYTE
  93. RealGlSetItem (
  94. IN OUT PGROWLIST GrowList,
  95. IN UINT Index,
  96. IN PCBYTE DataToSet, OPTIONAL
  97. IN UINT SizeOfData
  98. );
  99. #define GlSetItem(list,index,data,size) TRACK_BEGIN(PBYTE, GlSetItem) \
  100. RealGlSetItem(list,index,data,size) \
  101. TRACK_END()
  102. __inline
  103. PCSTR
  104. RealGlAppendStringABA (
  105. IN OUT PGROWLIST GrowList,
  106. IN PCSTR String,
  107. IN PCSTR End
  108. )
  109. {
  110. DEBUGMSG_IF ((String > End, DBG_WHOOPS, "Start is greater than End in GrowListAppendStringABA"));
  111. return (PCSTR) GlAppendAddNul (
  112. GrowList,
  113. (PBYTE) String,
  114. //cast is OK, we don't expect pointers to be that far away
  115. String < End ? (UINT)((UBINT) End - (UBINT) String) : 0
  116. );
  117. }
  118. __inline
  119. PCWSTR
  120. RealGlAppendStringABW (
  121. IN OUT PGROWLIST GrowList,
  122. IN PCWSTR String,
  123. IN PCWSTR End
  124. )
  125. {
  126. DEBUGMSG_IF ((String > End, DBG_WHOOPS, "Start is greater than End in GrowListAppendStringABW"));
  127. return (PCWSTR) GlAppendAddNul (
  128. GrowList,
  129. (PBYTE) String,
  130. //cast is OK, we don't expect pointers to be that far away
  131. String < End ? (UINT)((UBINT) End - (UBINT) String) : 0
  132. );
  133. }
  134. __inline
  135. PCSTR
  136. RealGlInsertStringABA (
  137. IN OUT PGROWLIST GrowList,
  138. IN UINT Index,
  139. IN PCSTR String,
  140. IN PCSTR End
  141. )
  142. {
  143. DEBUGMSG_IF ((String > End, DBG_WHOOPS, "Start is greater than End in GrowListInsertStringABA"));
  144. return (PCSTR) GlInsertAddNul (
  145. GrowList,
  146. Index,
  147. (PBYTE) String,
  148. //cast is OK, we don't expect pointers to be that far away
  149. String < End ? (UINT)((UBINT) End - (UBINT) String) : 0
  150. );
  151. }
  152. __inline
  153. PCWSTR
  154. RealGlInsertStringABW (
  155. IN OUT PGROWLIST GrowList,
  156. IN UINT Index,
  157. IN PCWSTR String,
  158. IN PCWSTR End
  159. )
  160. {
  161. DEBUGMSG_IF ((String > End, DBG_WHOOPS, "Start is greater than End in GrowListInsertStringABW"));
  162. return (PCWSTR) GlInsertAddNul (
  163. GrowList,
  164. Index,
  165. (PBYTE) String,
  166. //cast is OK, we don't expect pointers to be that far away
  167. String < End ? (UINT)((UBINT) End - (UBINT) String) : 0
  168. );
  169. }
  170. #define GlAppendStringABA(list,a,b) TRACK_BEGIN(PCSTR, GrowListAppendStringABA) \
  171. RealGlAppendStringABA(list,a,b)\
  172. TRACK_END()
  173. #define GlAppendStringABW(list,a,b) TRACK_BEGIN(PCWSTR, GrowListAppendStringABW) \
  174. RealGlAppendStringABW(list,a,b)\
  175. TRACK_END()
  176. #define GlInsertStringABA(list,index,a,b) TRACK_BEGIN(PCSTR, GrowListInsertStringABA) \
  177. RealGlInsertStringABA(list,index,a,b)\
  178. TRACK_END()
  179. #define GlInsertStringABW(list,index,a,b) TRACK_BEGIN(PCWSTR, GrowListInsertStringABW) \
  180. RealGlInsertStringABW(list,index,a,b)\
  181. TRACK_END()
  182. #define GlAppendStringA(list,str) GlAppendStringABA(list,str,GetEndOfStringA(str))
  183. #define GlAppendStringW(list,str) GlAppendStringABW(list,str,GetEndOfStringW(str))
  184. #define GlInsertStringA(list,index,str) GlInsertStringABA(list,index,str,GetEndOfStringA(str))
  185. #define GlInsertStringW(list,index,str) GlInsertStringABW(list,index,str,GetEndOfStringW(str))
  186. #define GlAppendStringNA(list,str,len) GlAppendStringABA(list,str,CharCountToPointerA(str,len))
  187. #define GlAppendStringNW(list,str,len) GlAppendStringABW(list,str,CharCountToPointerW(str,len))
  188. #define GlInsertStringNA(list,index,str,len) GlInsertStringABA(list,index,str,CharCountToPointerA(str,len))
  189. #define GlInsertStringNW(list,index,str,len) GlInsertStringABW(list,index,str,CharCountToPointerW(str,len))
  190. #define GlGetStringA(list,index) (PCSTR)(GlGetItem(list,index))
  191. #define GlGetStringW(list,index) (PCWSTR)(GlGetItem(list,index))
  192. #define GlAppendEmptyItem(list) GlAppend (list,NULL,0)
  193. #define GlInsertEmptyItem(list,index) GlInsert (list,index,NULL,0)
  194. #ifdef UNICODE
  195. #define GlAppendString GlAppendStringW
  196. #define GlInsertString GlInsertStringW
  197. #define GlAppendStringAB GlAppendStringABW
  198. #define GlInsertStringAB GlInsertStringABW
  199. #define GlAppendStringN GlAppendStringNW
  200. #define GlInsertStringN GlInsertStringNW
  201. #define GlGetString GlGetStringW
  202. #define GlGetStringPtrArray GlGetStringPtrArrayW
  203. #else
  204. #define GlAppendString GlAppendStringA
  205. #define GlInsertString GlInsertStringA
  206. #define GlAppendStringAB GlAppendStringABA
  207. #define GlInsertStringAB GlInsertStringABA
  208. #define GlAppendStringN GlAppendStringNA
  209. #define GlInsertStringN GlInsertStringNA
  210. #define GlGetString GlGetStringA
  211. #define GlGetStringPtrArray GlGetStringPtrArrayA
  212. #endif