]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/Common/ParseInf.h
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / C / Common / ParseInf.h
CommitLineData
30fdf114 1/** @file\r
97fa0ee9 2Header file for helper functions useful for parsing INF files.\r
30fdf114 3\r
f7496d71 4Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
2e351cbe 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
30fdf114 6\r
30fdf114
LG
7**/\r
8\r
9#ifndef _EFI_PARSE_INF_H\r
10#define _EFI_PARSE_INF_H\r
11\r
12#include <stdio.h>\r
13#include <stdlib.h>\r
14#include <Common/UefiBaseTypes.h>\r
15#include <MemoryFile.h>\r
16\r
4234283c
LG
17#ifdef __cplusplus\r
18extern "C" {\r
19#endif\r
30fdf114
LG
20//\r
21// Functions declarations\r
22//\r
23CHAR8 *\r
24ReadLine (\r
25 IN MEMORY_FILE *InputFile,\r
26 IN OUT CHAR8 *InputBuffer,\r
27 IN UINTN MaxLength\r
28 )\r
29;\r
30\r
31/*++\r
32\r
33Routine Description:\r
34\r
35 This function reads a line, stripping any comments.\r
f7496d71
LG
36 The function reads a string from the input stream argument and stores it in\r
37 the input string. ReadLine reads characters from the current file position\r
38 to and including the first newline character, to the end of the stream, or\r
39 until the number of characters read is equal to MaxLength - 1, whichever\r
40 comes first. The newline character, if read, is replaced with a \0.\r
30fdf114
LG
41\r
42Arguments:\r
43\r
44 InputFile Memory file image.\r
1be2ed90 45 InputBuffer Buffer to read into, must be MaxLength size.\r
30fdf114
LG
46 MaxLength The maximum size of the input buffer.\r
47\r
48Returns:\r
49\r
50 NULL if error or EOF\r
51 InputBuffer otherwise\r
52\r
53--*/\r
54BOOLEAN\r
55FindSection (\r
56 IN MEMORY_FILE *InputFile,\r
57 IN CHAR8 *Section\r
58 )\r
59;\r
60\r
61/*++\r
62\r
63Routine Description:\r
64\r
65 This function parses a file from the beginning to find a section.\r
66 The section string may be anywhere within a line.\r
67\r
68Arguments:\r
69\r
70 InputFile Memory file image.\r
71 Section Section to search for\r
72\r
73Returns:\r
74\r
75 FALSE if error or EOF\r
76 TRUE if section found\r
77\r
78--*/\r
79EFI_STATUS\r
80FindToken (\r
81 IN MEMORY_FILE *InputFile,\r
82 IN CHAR8 *Section,\r
83 IN CHAR8 *Token,\r
84 IN UINTN Instance,\r
85 OUT CHAR8 *Value\r
86 )\r
87;\r
88\r
89/*++\r
90\r
91Routine Description:\r
92\r
93 Finds a token value given the section and token to search for.\r
94\r
95Arguments:\r
96\r
97 InputFile Memory file image.\r
98 Section The section to search for, a string within [].\r
99 Token The token to search for, e.g. EFI_PEIM_RECOVERY, followed by an = in the INF file.\r
100 Instance The instance of the token to search for. Zero is the first instance.\r
1be2ed90 101 Value The string that holds the value following the =. Must be MAX_LONG_FILE_PATH in size.\r
30fdf114
LG
102\r
103Returns:\r
104\r
105 EFI_SUCCESS Value found.\r
106 EFI_ABORTED Format error detected in INF file.\r
107 EFI_INVALID_PARAMETER Input argument was null.\r
108 EFI_LOAD_ERROR Error reading from the file.\r
109 EFI_NOT_FOUND Section/Token/Value not found.\r
110\r
111--*/\r
112EFI_STATUS\r
113StringToGuid (\r
114 IN CHAR8 *AsciiGuidBuffer,\r
115 OUT EFI_GUID *GuidBuffer\r
116 )\r
117;\r
118\r
119/*++\r
120\r
f7496d71 121Routine Description:\r
30fdf114 122\r
f7496d71 123 Converts a string to an EFI_GUID. The string must be in the\r
30fdf114
LG
124 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.\r
125\r
f7496d71 126Arguments:\r
30fdf114
LG
127\r
128 GuidBuffer - pointer to destination Guid\r
129 AsciiGuidBuffer - pointer to ascii string\r
130\r
f7496d71 131Returns:\r
30fdf114
LG
132\r
133 EFI_ABORTED Could not convert the string\r
134 EFI_SUCCESS The string was successfully converted\r
135\r
136--*/\r
137EFI_STATUS\r
138AsciiStringToUint64 (\r
139 IN CONST CHAR8 *AsciiString,\r
140 IN BOOLEAN IsHex,\r
141 OUT UINT64 *ReturnValue\r
142 )\r
143;\r
144\r
145/*++\r
146\r
147Routine Description:\r
148\r
f7496d71 149 Converts a null terminated ascii string that represents a number into a\r
fb0b35e0 150 UINT64 value. A hex number may be preceded by a 0x, but may not be\r
f7496d71 151 succeeded by an h. A number without 0x or 0X is considered to be base 10\r
30fdf114
LG
152 unless the IsHex input is true.\r
153\r
154Arguments:\r
155\r
156 AsciiString The string to convert.\r
157 IsHex Force the string to be treated as a hex number.\r
158 ReturnValue The return value.\r
159\r
160Returns:\r
161\r
162 EFI_SUCCESS Number successfully converted.\r
163 EFI_ABORTED Invalid character encountered.\r
164\r
165--*/\r
166CHAR8 *\r
167ReadLineInStream (\r
168 IN FILE *InputFile,\r
169 IN OUT CHAR8 *InputBuffer\r
170 )\r
171;\r
172\r
173/*++\r
174\r
175Routine Description:\r
176\r
177 This function reads a line, stripping any comments.\r
178\r
179Arguments:\r
180\r
181 InputFile Stream pointer.\r
1be2ed90 182 InputBuffer Buffer to read into, must be MAX_LONG_FILE_PATH size.\r
30fdf114
LG
183\r
184Returns:\r
185\r
186 NULL if error or EOF\r
187 InputBuffer otherwise\r
188\r
189--*/\r
190BOOLEAN\r
191FindSectionInStream (\r
192 IN FILE *InputFile,\r
193 IN CHAR8 *Section\r
194 )\r
195;\r
196\r
197/*++\r
198\r
199Routine Description:\r
200\r
201 This function parses a stream file from the beginning to find a section.\r
202 The section string may be anywhere within a line.\r
203\r
204Arguments:\r
205\r
206 InputFile Stream pointer.\r
207 Section Section to search for\r
208\r
209Returns:\r
210\r
211 FALSE if error or EOF\r
212 TRUE if section found\r
213\r
214--*/\r
4234283c
LG
215\r
216#ifdef __cplusplus\r
217}\r
218#endif\r
219\r
30fdf114 220#endif\r