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