]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/GenAprioriFile/GenAprioriFile.c
81ffcb78dfa03df8aa97ea26374c37d1bd9d8783
3 Copyright (c) 2006 - 2010, 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"
43 #define UTILITY_VERSION "v1.0"
45 // Here's all our globals.
48 FILE *BinFptr
; // output dependencies to this file
49 INT8
*AprioriFileName
;
53 BOOLEAN NullTerminate
;
84 Call the routine to parse the command-line options, then process the
85 Apriori list file and generate the GUID file.
89 Standard C main() argc and argv.
97 // GC_TODO: Argc - add argument and description to function comment
98 // GC_TODO: ] - add argument and description to function comment
103 INT8 Line
[MAX_LINE_LEN
];
109 // Initialize the error printing routines
111 SetUtilityName (UTILITY_NAME
);
115 memset ((char *) &mGlobals
, 0, sizeof (mGlobals
));
116 memset ((char *) &ZeroGuid
, 0, sizeof (ZeroGuid
));
121 // Process the command-line arguments
123 Status
= ProcessArgs (Argc
, Argv
);
124 if (Status
!= STATUS_SUCCESS
) {
128 // If arguments were ok, then open the Apriori file and process it.
130 if ((AprioriFptr
= fopen (mGlobals
.AprioriFileName
, "r")) == NULL
) {
131 Error (NULL
, 0, 0, mGlobals
.AprioriFileName
, "failed to open file for reading");
135 // If -i intelligent option specified, then attempt to read and
136 // existing output file and see if we'd be creating an identical file.
138 if (mGlobals
.Intelligent
) {
139 if ((BinFptr
= fopen (mGlobals
.OutputFileName
, "rb")) == NULL
) {
140 if (mGlobals
.Verbose
) {
141 DebugMsg (NULL
, 0, 0, "Creating new apriori file -- no existing file", NULL
);
147 // Read lines from the input file until done. Convert each to a guid, then
148 // read a guid from the input file and compare them.
150 while (fgets (Line
, sizeof (Line
), AprioriFptr
) != NULL
) {
152 if (IsCommentLine (Line
)) {
158 if (StringToGuid (Line
, &Guid
) != EFI_SUCCESS
) {
159 if (mGlobals
.Verbose
) {
160 DebugMsg (NULL
, 0, 0, "failed to read GUID from input text file -- creating new file", NULL
);
166 // Read guid from input file, then compare
168 if (fread (&GuidIn
, sizeof (GuidIn
), 1, BinFptr
) != 1) {
169 if (mGlobals
.Verbose
) {
170 DebugMsg (NULL
, 0, 0, "failed to read GUID from input binary file -- creating new file", NULL
);
176 if (CompareGuid (&Guid
, &GuidIn
) != 0) {
177 if (mGlobals
.Verbose
) {
178 DebugMsg (NULL
, 0, 0, "GUID comparison failed -- creating new file", NULL
);
185 // May be one more NULL guid in the binary file
187 if (mGlobals
.NullTerminate
) {
188 if (fread (&GuidIn
, sizeof (GuidIn
), 1, BinFptr
) != 1) {
189 if (mGlobals
.Verbose
) {
190 DebugMsg (NULL
, 0, 0, "failed to read NULL GUID from input binary file -- creating new file", NULL
);
196 if (CompareGuid (&GuidIn
, &ZeroGuid
) != 0) {
197 if (mGlobals
.Verbose
) {
198 DebugMsg (NULL
, 0, 0, "NULL GUID comparison failed -- creating new file", NULL
);
205 // Make sure we're at the end of both files.
207 if ((fgets (Line
, sizeof (Line
), AprioriFptr
) != NULL
) || (fread (&GuidIn
, 1, 1, BinFptr
) != 0)) {
208 if (mGlobals
.Verbose
) {
209 DebugMsg (NULL
, 0, 0, "file sizes different, -i test failed -- creating new file", NULL
);
215 if (mGlobals
.Verbose
) {
216 DebugMsg (NULL
, 0, 0, "existing file would be unchanged -- keeping existing apriori file", NULL
);
224 // Rewind the Apriori file in case -i was specified. Also
225 // try to close the output file for the case where we prescanned
226 // it (again, because of -i).
228 rewind (AprioriFptr
);
229 if (BinFptr
!= NULL
) {
233 // Open the output file
235 if ((BinFptr
= fopen (mGlobals
.OutputFileName
, "wb")) == NULL
) {
236 Error (NULL
, 0, 0, mGlobals
.OutputFileName
, "could not open input file");
240 // Read lines until we're done
243 while (fgets (Line
, sizeof (Line
), AprioriFptr
) != NULL
) {
245 if (IsCommentLine (Line
)) {
251 if (StringToGuid (Line
, &Guid
) != EFI_SUCCESS
) {
252 Error (mGlobals
.AprioriFileName
, LineCounter
, 0, "failed to convert GUID", NULL
);
256 // Write the guid to the output file
258 if (fwrite (&Guid
, sizeof (Guid
), 1, BinFptr
) != 1) {
259 Error (NULL
, 0, 0, mGlobals
.OutputFileName
, "failed to write GUID to output file");
264 // Write a null guid out to terminate the list
266 if (mGlobals
.NullTerminate
) {
267 memset ((void *) &Guid
, 0, sizeof (Guid
));
268 if (fwrite (&Guid
, sizeof (Guid
), 1, BinFptr
) != 1) {
269 Error (NULL
, 0, 0, mGlobals
.OutputFileName
, "failed to write NULL termination GUID to output file");
275 if (AprioriFptr
!= NULL
) {
276 fclose (AprioriFptr
);
279 if (BinFptr
!= NULL
) {
283 return GetUtilityStatus ();
295 GC_TODO: Add function description
299 Line - GC_TODO: add argument description
303 GC_TODO: add return values
307 for (; isspace (*Line
) && *Line
; Line
++)
311 // Allow # or // comments
313 if ((*Line
== '#') || ((*Line
== '/') && (*(Line
+ 1) == '/')) || (*Line
== '\n') || (*Line
== 0)) {
320 // Process the command-line arguments
332 GC_TODO: Add function description
336 Argc - GC_TODO: add argument description
337 ] - GC_TODO: add argument description
341 GC_TODO: add return values
352 // Process until no more args
358 if (_stricmp (Argv
[0], "-f") == 0) {
360 // check for one more arg
363 mGlobals
.AprioriFileName
= Argv
[1];
365 Error (NULL
, 0, 0, NULL
, "missing filename with %s", Argv
[0]);
372 } else if (_stricmp (Argv
[0], "-i") == 0) {
374 // intelligent creation of output file. That is to say, if
375 // there's already a file there, and it's the same as what
376 // we'd create, then don't re-create. This is to support
377 // incremental builds (that is to say, running nmake a second time
380 mGlobals
.Intelligent
= TRUE
;
381 } else if (_stricmp (Argv
[0], "-v") == 0) {
382 mGlobals
.Verbose
= TRUE
;
383 } else if (_stricmp (Argv
[0], "-null") == 0) {
384 mGlobals
.NullTerminate
= TRUE
;
385 } else if (_stricmp (Argv
[0], "-o") == 0) {
388 // check for one more arg
391 mGlobals
.OutputFileName
= Argv
[1];
393 Error (NULL
, 0, 0, NULL
, "missing filename argument with %s", Argv
[0]);
400 } else if ((_stricmp (Argv
[0], "-h") == 0) || (strcmp (Argv
[0], "-?") == 0)) {
404 Error (NULL
, 0, 0, Argv
[0], "unrecognized option");
413 // Had to specify the apriori input file and output file names
415 if (mGlobals
.AprioriFileName
== NULL
) {
416 Error (NULL
, 0, 0, "must specify -f AprioriFile", NULL
);
421 if (mGlobals
.OutputFileName
== NULL
) {
422 Error (NULL
, 0, 0, "must specify -o OutputFile", NULL
);
427 return STATUS_SUCCESS
;
439 Print usage information for this utility.
452 const char *Str
[] = {
453 UTILITY_NAME
" "UTILITY_VERSION
" - Intel Generate Apriori File Utility",
454 " Copyright (C), 2006 - 2008 Intel Corporation",
456 #if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )
457 " Built from "UTILITY_BUILD
", project of "UTILITY_VENDOR
,
461 " "UTILITY_NAME
" [OPTION]...",
463 " Generate an Apriori file consumable by the DXE or PEI dispatcher.",
465 " -h or -? for this help information",
466 " -f AprioriFile parse the GUID'ed files in AprioriFile (required)",
467 " -o OutputFile write output to OutputFile (required)",
468 " -i for intelligent re-creation of OutputFile",
469 " -null to terminate the output file with a NULL GUID",
470 " -v verbose option",
473 for (Index
= 0; Str
[Index
] != NULL
; Index
++) {
474 fprintf (stdout
, "%s\n", Str
[Index
]);