]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Header file for helper functions useful for parsing INF files.\r | |
3 | \r | |
4 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
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 | |
17 | #ifdef __cplusplus\r | |
18 | extern "C" {\r | |
19 | #endif\r | |
20 | //\r | |
21 | // Functions declarations\r | |
22 | //\r | |
23 | CHAR8 *\r | |
24 | ReadLine (\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 | |
33 | Routine Description:\r | |
34 | \r | |
35 | This function reads a line, stripping any comments.\r | |
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 | |
41 | \r | |
42 | Arguments:\r | |
43 | \r | |
44 | InputFile Memory file image.\r | |
45 | InputBuffer Buffer to read into, must be MaxLength size.\r | |
46 | MaxLength The maximum size of the input buffer.\r | |
47 | \r | |
48 | Returns:\r | |
49 | \r | |
50 | NULL if error or EOF\r | |
51 | InputBuffer otherwise\r | |
52 | \r | |
53 | --*/\r | |
54 | BOOLEAN\r | |
55 | FindSection (\r | |
56 | IN MEMORY_FILE *InputFile,\r | |
57 | IN CHAR8 *Section\r | |
58 | )\r | |
59 | ;\r | |
60 | \r | |
61 | /*++\r | |
62 | \r | |
63 | Routine 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 | |
68 | Arguments:\r | |
69 | \r | |
70 | InputFile Memory file image.\r | |
71 | Section Section to search for\r | |
72 | \r | |
73 | Returns:\r | |
74 | \r | |
75 | FALSE if error or EOF\r | |
76 | TRUE if section found\r | |
77 | \r | |
78 | --*/\r | |
79 | EFI_STATUS\r | |
80 | FindToken (\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 | |
91 | Routine Description:\r | |
92 | \r | |
93 | Finds a token value given the section and token to search for.\r | |
94 | \r | |
95 | Arguments:\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 | |
101 | Value The string that holds the value following the =. Must be MAX_LONG_FILE_PATH in size.\r | |
102 | \r | |
103 | Returns:\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 | |
112 | EFI_STATUS\r | |
113 | StringToGuid (\r | |
114 | IN CHAR8 *AsciiGuidBuffer,\r | |
115 | OUT EFI_GUID *GuidBuffer\r | |
116 | )\r | |
117 | ;\r | |
118 | \r | |
119 | /*++\r | |
120 | \r | |
121 | Routine Description:\r | |
122 | \r | |
123 | Converts a string to an EFI_GUID. The string must be in the\r | |
124 | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.\r | |
125 | \r | |
126 | Arguments:\r | |
127 | \r | |
128 | GuidBuffer - pointer to destination Guid\r | |
129 | AsciiGuidBuffer - pointer to ascii string\r | |
130 | \r | |
131 | Returns:\r | |
132 | \r | |
133 | EFI_ABORTED Could not convert the string\r | |
134 | EFI_SUCCESS The string was successfully converted\r | |
135 | \r | |
136 | --*/\r | |
137 | EFI_STATUS\r | |
138 | AsciiStringToUint64 (\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 | |
147 | Routine Description:\r | |
148 | \r | |
149 | Converts a null terminated ascii string that represents a number into a\r | |
150 | UINT64 value. A hex number may be preceded by a 0x, but may not be\r | |
151 | succeeded by an h. A number without 0x or 0X is considered to be base 10\r | |
152 | unless the IsHex input is true.\r | |
153 | \r | |
154 | Arguments:\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 | |
160 | Returns:\r | |
161 | \r | |
162 | EFI_SUCCESS Number successfully converted.\r | |
163 | EFI_ABORTED Invalid character encountered.\r | |
164 | \r | |
165 | --*/\r | |
166 | CHAR8 *\r | |
167 | ReadLineInStream (\r | |
168 | IN FILE *InputFile,\r | |
169 | IN OUT CHAR8 *InputBuffer\r | |
170 | )\r | |
171 | ;\r | |
172 | \r | |
173 | /*++\r | |
174 | \r | |
175 | Routine Description:\r | |
176 | \r | |
177 | This function reads a line, stripping any comments.\r | |
178 | \r | |
179 | Arguments:\r | |
180 | \r | |
181 | InputFile Stream pointer.\r | |
182 | InputBuffer Buffer to read into, must be MAX_LONG_FILE_PATH size.\r | |
183 | \r | |
184 | Returns:\r | |
185 | \r | |
186 | NULL if error or EOF\r | |
187 | InputBuffer otherwise\r | |
188 | \r | |
189 | --*/\r | |
190 | BOOLEAN\r | |
191 | FindSectionInStream (\r | |
192 | IN FILE *InputFile,\r | |
193 | IN CHAR8 *Section\r | |
194 | )\r | |
195 | ;\r | |
196 | \r | |
197 | /*++\r | |
198 | \r | |
199 | Routine 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 | |
204 | Arguments:\r | |
205 | \r | |
206 | InputFile Stream pointer.\r | |
207 | Section Section to search for\r | |
208 | \r | |
209 | Returns:\r | |
210 | \r | |
211 | FALSE if error or EOF\r | |
212 | TRUE if section found\r | |
213 | \r | |
214 | --*/\r | |
215 | \r | |
216 | #ifdef __cplusplus\r | |
217 | }\r | |
218 | #endif\r | |
219 | \r | |
220 | #endif\r |