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.

509 lines
11 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. inf.h
  5. Abstract:
  6. Declares interface for INF wrapper routines. These routines simplify
  7. access of INFs by wrapping the setup APIs with routines that use
  8. pools or grow buffers.
  9. The INF wrapper routines also implement append and replace capabilities,
  10. so any INF used by the Win9x upgrade can be appended in the future, or
  11. completely replaced.
  12. Author:
  13. Marc R. Whitten (marcw) 20-Oct-1997
  14. Revision History:
  15. jimschm 05-Jan-1999 INF parser moved to migutil
  16. marcw 28-Oct-1998 Append/Replace capability
  17. marcw 08-Aug-1997 Pool/Growbuf routines
  18. --*/
  19. typedef enum {
  20. INF_USE_POOLHANDLE,
  21. INF_USE_GROWBUFFER,
  22. INF_USE_PRIVATE_GROWBUFFER,
  23. INF_USE_PRIVATE_POOLHANDLE
  24. } ALLOCATORTYPES;
  25. typedef struct {
  26. INFCONTEXT Context;
  27. GROWBUFFER GrowBuffer;
  28. POOLHANDLE PoolHandle;
  29. ALLOCATORTYPES Allocator;
  30. PCSTR KeyName;
  31. } INFSTRUCTA, *PINFSTRUCTA;
  32. typedef struct {
  33. INFCONTEXT Context;
  34. GROWBUFFER GrowBuffer;
  35. POOLHANDLE PoolHandle;
  36. ALLOCATORTYPES Allocator;
  37. PCWSTR KeyName;
  38. } INFSTRUCTW, *PINFSTRUCTW;
  39. #define INFCONTEXT_INIT {NULL,NULL,0,0}
  40. #define INITINFSTRUCT_GROWBUFFER {INFCONTEXT_INIT,GROWBUF_INIT,NULL,INF_USE_PRIVATE_GROWBUFFER,NULL}
  41. #define INITINFSTRUCT_POOLHANDLE {INFCONTEXT_INIT,GROWBUF_INIT,NULL,INF_USE_PRIVATE_POOLHANDLE,NULL}
  42. #define InfOpenAppendInfFile SetupOpenAppendInfFile
  43. extern PBOOL g_UpginfsUpdated;
  44. VOID
  45. InfCleanUpInfStructA (
  46. PINFSTRUCTA Context
  47. );
  48. VOID
  49. InfCleanUpInfStructW (
  50. PINFSTRUCTW Context
  51. );
  52. VOID
  53. InitInfStructA (
  54. OUT PINFSTRUCTA Context,
  55. IN PGROWBUFFER GrowBuffer, OPTIONAL
  56. IN POOLHANDLE PoolHandle OPTIONAL
  57. );
  58. VOID
  59. InitInfStructW (
  60. OUT PINFSTRUCTW Context,
  61. IN PGROWBUFFER GrowBuffer, OPTIONAL
  62. IN POOLHANDLE PoolHandle OPTIONAL
  63. );
  64. #define InfOpenInfFileA(f) SETTRACKCOMMENT(HINF,"InfOpenInfFile",__FILE__,__LINE__)\
  65. RealInfOpenInfFileA((f)/*,*/ ALLOCATION_TRACKING_CALL)\
  66. CLRTRACKCOMMENT
  67. #define InfOpenInfFileW(f) SETTRACKCOMMENT(HINF,"InfOpenInfFile",__FILE__,__LINE__)\
  68. RealInfOpenInfFileW((f)/*,*/ ALLOCATION_TRACKING_CALL)\
  69. CLRTRACKCOMMENT
  70. HINF
  71. RealInfOpenInfFileA (
  72. IN PCSTR FileName /*,*/
  73. ALLOCATION_TRACKING_DEF
  74. );
  75. HINF
  76. RealInfOpenInfFileW (
  77. IN PCWSTR FileName /*,*/
  78. ALLOCATION_TRACKING_DEF
  79. );
  80. VOID
  81. InfCloseInfFile (HINF Inf);
  82. //
  83. // See the macros below before calling InfOpenInfInAllSourcesA or W.
  84. //
  85. HINF
  86. InfOpenInfInAllSourcesA (
  87. IN PCSTR InfSpecifier,
  88. IN DWORD SourceCount,
  89. IN PCSTR * SourceDirectories
  90. );
  91. HINF
  92. InfOpenInfInAllSourcesW (
  93. IN PCWSTR InfSpecifier,
  94. IN DWORD SourceCount,
  95. IN PCWSTR *SourceDirectories
  96. );
  97. PSTR
  98. InfGetLineTextA (
  99. IN OUT PINFSTRUCTA
  100. );
  101. PWSTR
  102. InfGetLineTextW (
  103. IN OUT PINFSTRUCTW
  104. );
  105. PSTR
  106. InfGetStringFieldA (
  107. IN OUT PINFSTRUCTA Context,
  108. IN UINT FieldIndex
  109. );
  110. PWSTR
  111. InfGetStringFieldW (
  112. IN OUT PINFSTRUCTW Context,
  113. IN UINT FieldIndex
  114. );
  115. PSTR
  116. InfGetMultiSzFieldA (
  117. IN OUT PINFSTRUCTA Context,
  118. IN UINT FieldIndex
  119. ) ;
  120. PWSTR
  121. InfGetMultiSzFieldW (
  122. IN OUT PINFSTRUCTW Context,
  123. IN UINT FieldIndex
  124. ) ;
  125. BOOL
  126. InfGetIntFieldA (
  127. IN PINFSTRUCTA Context,
  128. IN UINT FieldIndex,
  129. IN PINT Value
  130. );
  131. BOOL
  132. InfGetIntFieldW (
  133. IN PINFSTRUCTW Context,
  134. IN UINT FieldIndex,
  135. IN PINT Value
  136. );
  137. PBYTE
  138. InfGetBinaryFieldA (
  139. IN PINFSTRUCTA Context,
  140. IN UINT FieldIndex
  141. );
  142. PBYTE
  143. InfGetBinaryFieldW (
  144. IN PINFSTRUCTW Context,
  145. IN UINT FieldIndex
  146. );
  147. BOOL
  148. InfGetLineByIndexA (
  149. IN HINF InfHandle,
  150. IN PCSTR Section,
  151. IN DWORD Index,
  152. OUT PINFSTRUCTA Context
  153. );
  154. BOOL
  155. InfGetLineByIndexW (
  156. IN HINF InfHandle,
  157. IN PCWSTR Section,
  158. IN DWORD Index,
  159. OUT PINFSTRUCTW Context
  160. );
  161. BOOL
  162. InfFindFirstLineA (
  163. IN HINF InfHandle,
  164. IN PCSTR Section,
  165. IN PCSTR Key,
  166. OUT PINFSTRUCTA Context
  167. );
  168. BOOL
  169. InfFindFirstLineW (
  170. IN HINF InfHandle,
  171. IN PCWSTR Section,
  172. IN PCWSTR Key,
  173. OUT PINFSTRUCTW Context
  174. );
  175. BOOL
  176. InfFindNextLineA (
  177. IN OUT PINFSTRUCTA Context
  178. );
  179. BOOL
  180. InfFindNextLineW (
  181. IN OUT PINFSTRUCTW Context
  182. );
  183. UINT
  184. InfGetFieldCountA (
  185. IN PINFSTRUCTA Context
  186. );
  187. UINT
  188. InfGetFieldCountW (
  189. IN PINFSTRUCTW Context
  190. );
  191. PCSTR
  192. InfGetOemStringFieldA (
  193. IN PINFSTRUCTA Context,
  194. IN UINT Field
  195. );
  196. BOOL
  197. SetupGetOemStringFieldA (
  198. IN PINFCONTEXT Context,
  199. IN DWORD Index,
  200. IN PTSTR ReturnBuffer,
  201. IN DWORD ReturnBufferSize,
  202. OUT PDWORD RequiredSize
  203. );
  204. VOID
  205. InfResetInfStructA (
  206. IN OUT PINFSTRUCTA Context
  207. );
  208. VOID
  209. InfResetInfStructW (
  210. IN OUT PINFSTRUCTW Context
  211. );
  212. //
  213. // INF parser
  214. //
  215. typedef struct _tagINFLINE {
  216. PCWSTR Key; OPTIONAL
  217. PCWSTR Data;
  218. DWORD LineFlags;
  219. struct _tagINFLINE *Next, *Prev;
  220. struct _tagINFSECTION *Section;
  221. } INFLINE, *PINFLINE;
  222. #define LINEFLAG_KEY_QUOTED 0x0001
  223. #define LINEFLAG_ALL_COMMENTS 0x0002
  224. #define LINEFLAG_TRAILING_COMMENTS 0x0004
  225. typedef struct _tagINFSECTION {
  226. PCWSTR Name;
  227. PINFLINE FirstLine;
  228. PINFLINE LastLine;
  229. UINT LineCount;
  230. struct _tagINFSECTION *Next, *Prev;
  231. } INFSECTION, *PINFSECTION;
  232. PINFSECTION
  233. AddInfSectionToTableA (
  234. IN HINF Inf,
  235. IN PCSTR SectionName
  236. );
  237. PINFSECTION
  238. AddInfSectionToTableW (
  239. IN HINF Inf,
  240. IN PCWSTR SectionName
  241. );
  242. PINFSECTION
  243. FindInfSectionInTableA (
  244. IN HINF Inf,
  245. IN PCSTR SectionName
  246. );
  247. PINFSECTION
  248. GetFirstInfSectionInTable (
  249. IN HINF Inf
  250. );
  251. PINFSECTION
  252. GetNextInfSectionInTable (
  253. IN PINFSECTION Section
  254. );
  255. PINFSECTION
  256. FindInfSectionInTableW (
  257. IN HINF Inf,
  258. IN PCWSTR SectionName
  259. );
  260. PINFLINE
  261. AddInfLineToTableA (
  262. IN HINF Inf,
  263. IN PINFSECTION SectionPtr,
  264. IN PCSTR Key, OPTIONAL
  265. IN PCSTR Data,
  266. IN DWORD LineFlags
  267. );
  268. PINFLINE
  269. AddInfLineToTableW (
  270. IN HINF Inf,
  271. IN PINFSECTION SectionPtr,
  272. IN PCWSTR Key, OPTIONAL
  273. IN PCWSTR Data,
  274. IN DWORD LineFlags
  275. );
  276. PINFLINE
  277. FindLineInInfSectionA (
  278. IN HINF Inf,
  279. IN PINFSECTION Section,
  280. IN PCSTR Key
  281. );
  282. PINFLINE
  283. FindLineInInfSectionW (
  284. IN HINF Inf,
  285. IN PINFSECTION Section,
  286. IN PCWSTR Key
  287. );
  288. PINFLINE
  289. GetFirstLineInSectionStrA (
  290. IN HINF Inf,
  291. IN PCSTR Section
  292. );
  293. PINFLINE
  294. GetFirstLineInSectionStrW (
  295. IN HINF Inf,
  296. IN PCWSTR Section
  297. );
  298. PINFLINE
  299. GetFirstLineInSectionStruct (
  300. IN PINFSECTION Section
  301. );
  302. PINFLINE
  303. GetNextLineInSection (
  304. IN PINFLINE PrevLine
  305. );
  306. UINT
  307. GetInfSectionLineCount (
  308. IN PINFSECTION Section
  309. );
  310. BOOL
  311. DeleteSectionInInfFile (
  312. IN HINF Inf,
  313. IN PINFSECTION Section
  314. );
  315. BOOL
  316. DeleteLineInInfSection (
  317. IN HINF Inf,
  318. IN PINFLINE InfLine
  319. );
  320. HINF
  321. OpenInfFileExA (
  322. IN PCSTR InfFilePath,
  323. IN PSTR SectionList,
  324. IN BOOL KeepComments
  325. );
  326. #define OpenInfFileA(Path) OpenInfFileExA (Path, NULL, TRUE)
  327. HINF
  328. OpenInfFileExW (
  329. IN PCWSTR InfFilePath,
  330. IN PWSTR SectionList,
  331. IN BOOL KeepComments
  332. );
  333. #define OpenInfFileW(Path) OpenInfFileExW (Path, NULL, TRUE)
  334. VOID
  335. CloseInfFile (
  336. HINF InfFile
  337. );
  338. BOOL
  339. SaveInfFileA (
  340. IN HINF Inf,
  341. IN PCSTR SaveToFileSpec
  342. );
  343. BOOL
  344. SaveInfFileW (
  345. IN HINF Inf,
  346. IN PCWSTR SaveToFileSpec
  347. );
  348. VOID
  349. InitInfReplaceTable (
  350. VOID
  351. );
  352. //
  353. // ANSI/UNICODE mappings.
  354. //
  355. #ifdef UNICODE
  356. # define INFSTRUCT INFSTRUCTW
  357. # define PINFSTRUCT PINFSTRUCTW
  358. # define InfCleanUpInfStruct InfCleanUpInfStructW
  359. # define InitInfStruct InitInfStructW
  360. # define InfResetInfStruct InfResetInfStructW
  361. # define InfFindFirstLine InfFindFirstLineW
  362. # define InfFindNextLine InfFindNextLineW
  363. # define InfGetLineByIndex InfGetLineByIndexW
  364. # define InfGetStringField InfGetStringFieldW
  365. # define InfGetMultiSzField InfGetMultiSzFieldW
  366. # define InfGetLineText InfGetLineTextW
  367. # define InfOpenInfFile InfOpenInfFileW
  368. # define InfGetOemStringField InfGetStringFieldW
  369. # define InfGetIntField InfGetIntFieldW
  370. # define InfGetBinaryField InfGetBinaryFieldW
  371. # define InfGetFieldCount InfGetFieldCountW
  372. # define SetupGetOemStringField SetupGetStringFieldW
  373. # define InfOpenInfInAllSources(x) InfOpenInfInAllSourcesW((x),1,&g_SourceDirectory);
  374. # define AddInfSectionToTable AddInfSectionToTableW
  375. # define FindInfSectionInTable FindInfSectionInTableW
  376. # define AddInfLineToTable AddInfLineToTableW
  377. # define FindLineInInfSection FindLineInInfSectionW
  378. # define GetFirstLineInSectionStr GetFirstLineInSectionStrW
  379. # define OpenInfFileEx OpenInfFileExW
  380. # define OpenInfFile OpenInfFileW
  381. # define SaveInfFile SaveInfFileW
  382. #else
  383. # define INFSTRUCT INFSTRUCTA
  384. # define PINFSTRUCT PINFSTRUCTA
  385. # define InfCleanUpInfStruct InfCleanUpInfStructA
  386. # define InitInfStruct InitInfStructA
  387. # define InfResetInfStruct InfResetInfStructA
  388. # define InfFindFirstLine InfFindFirstLineA
  389. # define InfFindNextLine InfFindNextLineA
  390. # define InfGetLineByIndex InfGetLineByIndexA
  391. # define InfGetStringField InfGetStringFieldA
  392. # define InfGetMultiSzField InfGetMultiSzFieldA
  393. # define InfGetLineText InfGetLineTextA
  394. # define InfOpenInfFile InfOpenInfFileA
  395. # define InfGetOemStringField InfGetOemStringFieldA
  396. # define InfGetIntField InfGetIntFieldA
  397. # define InfGetBinaryField InfGetBinaryFieldA
  398. # define InfGetFieldCount InfGetFieldCountA
  399. # define SetupGetOemStringField SetupGetOemStringFieldA
  400. # define InfOpenInfInAllSources(x) InfOpenInfInAllSourcesA((x),g_SourceDirectoryCount,g_SourceDirectories);
  401. # define AddInfSectionToTable AddInfSectionToTableA
  402. # define FindInfSectionInTable FindInfSectionInTableA
  403. # define AddInfLineToTable AddInfLineToTableA
  404. # define FindLineInInfSection FindLineInInfSectionA
  405. # define GetFirstLineInSectionStr GetFirstLineInSectionStrA
  406. # define OpenInfFileEx OpenInfFileExA
  407. # define OpenInfFile OpenInfFileA
  408. # define SaveInfFile SaveInfFileA
  409. #endif