]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/GenAprioriFile/GenAprioriFile.c
e346a1e4c879c7421df5519e47034f36d99a1692
3 Copyright (c) 2006, 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
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.
19 Given an input file containing a list of GUIDs (or Guided file names),
20 convert the file to an Apriori file consumable by the dispatcher.
28 #include "EfiCommon.h"
30 #include "CommonLib.h" // for compare guid
31 #include "EfiUtilityMsgs.h"
33 #define MAX_LINE_LEN 200
37 // typedef unsigned int STATUS;
38 // #define STATUS_SUCCESS 0
39 // #define STATUS_WARNING 1
40 // #define STATUS_ERROR 2
42 #define UTILITY_NAME "GenAprioriFile"
44 // Here's all our globals.
47 FILE *BinFptr
; // output dependencies to this file
48 INT8
*AprioriFileName
;
52 BOOLEAN NullTerminate
;
83 Call the routine to parse the command-line options, then process the
84 Apriori list file and generate the GUID file.
88 Standard C main() argc and argv.
96 // GC_TODO: Argc - add argument and description to function comment
97 // GC_TODO: ] - add argument and description to function comment
102 INT8 Line
[MAX_LINE_LEN
];
108 // Initialize the error printing routines
110 SetUtilityName (UTILITY_NAME
);
114 memset ((char *) &mGlobals
, 0, sizeof (mGlobals
));
115 memset ((char *) &ZeroGuid
, 0, sizeof (ZeroGuid
));
120 // Process the command-line arguments
122 Status
= ProcessArgs (Argc
, Argv
);
123 if (Status
!= STATUS_SUCCESS
) {
127 // If arguments were ok, then open the Apriori file and process it.
129 if ((AprioriFptr
= fopen (mGlobals
.AprioriFileName
, "r")) == NULL
) {
130 Error (NULL
, 0, 0, mGlobals
.AprioriFileName
, "failed to open file for reading");
134 // If -i intelligent option specified, then attempt to read and
135 // existing output file and see if we'd be creating an identical file.
137 if (mGlobals
.Intelligent
) {
138 if ((BinFptr
= fopen (mGlobals
.OutputFileName
, "rb")) == NULL
) {
139 if (mGlobals
.Verbose
) {
140 DebugMsg (NULL
, 0, 0, "Creating new apriori file -- no existing file", NULL
);
146 // Read lines from the input file until done. Convert each to a guid, then
147 // read a guid from the input file and compare them.
149 while (fgets (Line
, sizeof (Line
), AprioriFptr
) != NULL
) {
151 if (IsCommentLine (Line
)) {
157 if (StringToGuid (Line
, &Guid
) != EFI_SUCCESS
) {
158 if (mGlobals
.Verbose
) {
159 DebugMsg (NULL
, 0, 0, "failed to read GUID from input text file -- creating new file", NULL
);
165 // Read guid from input file, then compare
167 if (fread (&GuidIn
, sizeof (GuidIn
), 1, BinFptr
) != 1) {
168 if (mGlobals
.Verbose
) {
169 DebugMsg (NULL
, 0, 0, "failed to read GUID from input binary file -- creating new file", NULL
);
175 if (CompareGuid (&Guid
, &GuidIn
) != 0) {
176 if (mGlobals
.Verbose
) {
177 DebugMsg (NULL
, 0, 0, "GUID comparison failed -- creating new file", NULL
);
184 // May be one more NULL guid in the binary file
186 if (mGlobals
.NullTerminate
) {
187 if (fread (&GuidIn
, sizeof (GuidIn
), 1, BinFptr
) != 1) {
188 if (mGlobals
.Verbose
) {
189 DebugMsg (NULL
, 0, 0, "failed to read NULL GUID from input binary file -- creating new file", NULL
);
195 if (CompareGuid (&GuidIn
, &ZeroGuid
) != 0) {
196 if (mGlobals
.Verbose
) {
197 DebugMsg (NULL
, 0, 0, "NULL GUID comparison failed -- creating new file", NULL
);
204 // Make sure we're at the end of both files.
206 if ((fgets (Line
, sizeof (Line
), AprioriFptr
) != NULL
) || (fread (&GuidIn
, 1, 1, BinFptr
) != 0)) {
207 if (mGlobals
.Verbose
) {
208 DebugMsg (NULL
, 0, 0, "file sizes different, -i test failed -- creating new file", NULL
);
214 if (mGlobals
.Verbose
) {
215 DebugMsg (NULL
, 0, 0, "existing file would be unchanged -- keeping existing apriori file", NULL
);
223 // Rewind the Apriori file in case -i was specified. Also
224 // try to close the output file for the case where we prescanned
225 // it (again, because of -i).
227 rewind (AprioriFptr
);
228 if (BinFptr
!= NULL
) {
232 // Open the output file
234 if ((BinFptr
= fopen (mGlobals
.OutputFileName
, "wb")) == NULL
) {
235 Error (NULL
, 0, 0, mGlobals
.OutputFileName
, "could not open input file");
239 // Read lines until we're done
242 while (fgets (Line
, sizeof (Line
), AprioriFptr
) != NULL
) {
244 if (IsCommentLine (Line
)) {
250 if (StringToGuid (Line
, &Guid
) != EFI_SUCCESS
) {
251 Error (mGlobals
.AprioriFileName
, LineCounter
, 0, "failed to convert GUID", NULL
);
255 // Write the guid to the output file
257 if (fwrite (&Guid
, sizeof (Guid
), 1, BinFptr
) != 1) {
258 Error (NULL
, 0, 0, mGlobals
.OutputFileName
, "failed to write GUID to output file");
263 // Write a null guid out to terminate the list
265 if (mGlobals
.NullTerminate
) {
266 memset ((void *) &Guid
, 0, sizeof (Guid
));
267 if (fwrite (&Guid
, sizeof (Guid
), 1, BinFptr
) != 1) {
268 Error (NULL
, 0, 0, mGlobals
.OutputFileName
, "failed to write NULL termination GUID to output file");
274 if (AprioriFptr
!= NULL
) {
275 fclose (AprioriFptr
);
278 if (BinFptr
!= NULL
) {
282 return GetUtilityStatus ();
294 GC_TODO: Add function description
298 Line - GC_TODO: add argument description
302 GC_TODO: add return values
306 for (; isspace (*Line
) && *Line
; Line
++)
310 // Allow # or // comments
312 if ((*Line
== '#') || ((*Line
== '/') && (*(Line
+ 1) == '/')) || (*Line
== '\n') || (*Line
== 0)) {
319 // Process the command-line arguments
331 GC_TODO: Add function description
335 Argc - GC_TODO: add argument description
336 ] - GC_TODO: add argument description
340 GC_TODO: add return values
351 // Process until no more args
357 if (_stricmp (Argv
[0], "-f") == 0) {
359 // check for one more arg
362 mGlobals
.AprioriFileName
= Argv
[1];
364 Error (NULL
, 0, 0, NULL
, "missing filename with %s", Argv
[0]);
371 } else if (_stricmp (Argv
[0], "-i") == 0) {
373 // intelligent creation of output file. That is to say, if
374 // there's already a file there, and it's the same as what
375 // we'd create, then don't re-create. This is to support
376 // incremental builds (that is to say, running nmake a second time
379 mGlobals
.Intelligent
= TRUE
;
380 } else if (_stricmp (Argv
[0], "-v") == 0) {
381 mGlobals
.Verbose
= TRUE
;
382 } else if (_stricmp (Argv
[0], "-null") == 0) {
383 mGlobals
.NullTerminate
= TRUE
;
384 } else if (_stricmp (Argv
[0], "-o") == 0) {
387 // check for one more arg
390 mGlobals
.OutputFileName
= Argv
[1];
392 Error (NULL
, 0, 0, NULL
, "missing filename argument with %s", Argv
[0]);
399 } else if ((_stricmp (Argv
[0], "-h") == 0) || (strcmp (Argv
[0], "-?") == 0)) {
403 Error (NULL
, 0, 0, Argv
[0], "unrecognized option");
412 // Had to specify the apriori input file and output file names
414 if (mGlobals
.AprioriFileName
== NULL
) {
415 Error (NULL
, 0, 0, "must specify -f AprioriFile", NULL
);
420 if (mGlobals
.OutputFileName
== NULL
) {
421 Error (NULL
, 0, 0, "must specify -o OutputFile", NULL
);
426 return STATUS_SUCCESS
;
438 Print usage information for this utility.
451 static const char *Str
[] = {
452 UTILITY_NAME
" -- create an Apriori file consumable by the DXE dispatcher",
453 " Usage: "UTILITY_NAME
" [Options]",
455 " -h or -? for this help information",
456 " -f AprioriFile parse the GUID'ed files in AprioriFile (required)",
457 " -o OutputFile write output to OutputFile (required)",
458 " -i for intelligent re-creation of OutputFile",
459 " -null to terminate the output file with a NULL GUID",
460 " -v verbose option",
464 for (Index
= 0; Str
[Index
] != NULL
; Index
++) {
465 fprintf (stdout
, "%s\n", Str
[Index
]);