+++ /dev/null
-/*++\r
-\r
- Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials \r
- are licensed and made available under the terms and conditions of the BSD License \r
- which accompanies this distribution. The full text of the license may be found at \r
- http://opensource.org/licenses/bsd-license.php \r
- \r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-\r
-Module Name:\r
-\r
- GenAprioriFile.c \r
-\r
-Abstract:\r
-\r
- Given an input file containing a list of GUIDs (or Guided file names),\r
- convert the file to an Apriori file consumable by the dispatcher.\r
-\r
---*/\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <ctype.h>\r
-\r
-#include "EfiCommon.h"\r
-#include "ParseInf.h"\r
-#include "CommonLib.h" // for compare guid\r
-#include "EfiUtilityMsgs.h"\r
-\r
-#define MAX_LINE_LEN 200\r
-#define MAX_PATH 200\r
-\r
-//\r
-// typedef unsigned int STATUS;\r
-// #define STATUS_SUCCESS 0\r
-// #define STATUS_WARNING 1\r
-// #define STATUS_ERROR 2\r
-//\r
-#define UTILITY_NAME "GenAprioriFile"\r
-#define UTILITY_VERSION "v1.0"\r
-//\r
-// Here's all our globals.\r
-//\r
-static struct {\r
- FILE *BinFptr; // output dependencies to this file\r
- INT8 *AprioriFileName;\r
- INT8 *OutputFileName;\r
- BOOLEAN Intelligent;\r
- BOOLEAN Verbose;\r
- BOOLEAN NullTerminate;\r
-} mGlobals;\r
-\r
-static\r
-STATUS\r
-ProcessArgs (\r
- int Argc,\r
- char *Argv[]\r
- );\r
-\r
-static\r
-BOOLEAN\r
-IsCommentLine (\r
- INT8 *Line\r
- );\r
-\r
-static\r
-void\r
-Usage (\r
- VOID\r
- );\r
-\r
-int\r
-main (\r
- int Argc,\r
- char *Argv[]\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Call the routine to parse the command-line options, then process the\r
- Apriori list file and generate the GUID file.\r
- \r
-Arguments:\r
-\r
- Standard C main() argc and argv.\r
-\r
-Returns:\r
-\r
- 0 if successful\r
- nonzero otherwise\r
- \r
---*/\r
-// GC_TODO: Argc - add argument and description to function comment\r
-// GC_TODO: ] - add argument and description to function comment\r
-{\r
- STATUS Status;\r
- FILE *AprioriFptr;\r
- FILE *BinFptr;\r
- INT8 Line[MAX_LINE_LEN];\r
- EFI_GUID Guid;\r
- EFI_GUID GuidIn;\r
- EFI_GUID ZeroGuid;\r
- UINT32 LineCounter;\r
- //\r
- // Initialize the error printing routines\r
- //\r
- SetUtilityName (UTILITY_NAME);\r
- //\r
- // Clear our globals\r
- //\r
- memset ((char *) &mGlobals, 0, sizeof (mGlobals));\r
- memset ((char *) &ZeroGuid, 0, sizeof (ZeroGuid));\r
- AprioriFptr = NULL;\r
- BinFptr = NULL;\r
-\r
- //\r
- // Process the command-line arguments\r
- //\r
- Status = ProcessArgs (Argc, Argv);\r
- if (Status != STATUS_SUCCESS) {\r
- return Status;\r
- }\r
- //\r
- // If arguments were ok, then open the Apriori file and process it.\r
- //\r
- if ((AprioriFptr = fopen (mGlobals.AprioriFileName, "r")) == NULL) {\r
- Error (NULL, 0, 0, mGlobals.AprioriFileName, "failed to open file for reading");\r
- goto FinishUp;\r
- }\r
- //\r
- // If -i intelligent option specified, then attempt to read and\r
- // existing output file and see if we'd be creating an identical file.\r
- //\r
- if (mGlobals.Intelligent) {\r
- if ((BinFptr = fopen (mGlobals.OutputFileName, "rb")) == NULL) {\r
- if (mGlobals.Verbose) {\r
- DebugMsg (NULL, 0, 0, "Creating new apriori file -- no existing file", NULL);\r
- }\r
-\r
- goto CreateFile;\r
- }\r
- //\r
- // Read lines from the input file until done. Convert each to a guid, then\r
- // read a guid from the input file and compare them.\r
- //\r
- while (fgets (Line, sizeof (Line), AprioriFptr) != NULL) {\r
-\r
- if (IsCommentLine (Line)) {\r
- continue;\r
- }\r
- //\r
- // Convert to a guid\r
- //\r
- if (StringToGuid (Line, &Guid) != EFI_SUCCESS) {\r
- if (mGlobals.Verbose) {\r
- DebugMsg (NULL, 0, 0, "failed to read GUID from input text file -- creating new file", NULL);\r
- }\r
-\r
- goto CreateFile;\r
- }\r
- //\r
- // Read guid from input file, then compare\r
- //\r
- if (fread (&GuidIn, sizeof (GuidIn), 1, BinFptr) != 1) {\r
- if (mGlobals.Verbose) {\r
- DebugMsg (NULL, 0, 0, "failed to read GUID from input binary file -- creating new file", NULL);\r
- }\r
-\r
- goto CreateFile;\r
- }\r
-\r
- if (CompareGuid (&Guid, &GuidIn) != 0) {\r
- if (mGlobals.Verbose) {\r
- DebugMsg (NULL, 0, 0, "GUID comparison failed -- creating new file", NULL);\r
- }\r
-\r
- goto CreateFile;\r
- }\r
- }\r
- //\r
- // May be one more NULL guid in the binary file\r
- //\r
- if (mGlobals.NullTerminate) {\r
- if (fread (&GuidIn, sizeof (GuidIn), 1, BinFptr) != 1) {\r
- if (mGlobals.Verbose) {\r
- DebugMsg (NULL, 0, 0, "failed to read NULL GUID from input binary file -- creating new file", NULL);\r
- }\r
-\r
- goto CreateFile;\r
- }\r
-\r
- if (CompareGuid (&GuidIn, &ZeroGuid) != 0) {\r
- if (mGlobals.Verbose) {\r
- DebugMsg (NULL, 0, 0, "NULL GUID comparison failed -- creating new file", NULL);\r
- }\r
-\r
- goto CreateFile;\r
- }\r
- }\r
- //\r
- // Make sure we're at the end of both files.\r
- //\r
- if ((fgets (Line, sizeof (Line), AprioriFptr) != NULL) || (fread (&GuidIn, 1, 1, BinFptr) != 0)) {\r
- if (mGlobals.Verbose) {\r
- DebugMsg (NULL, 0, 0, "file sizes different, -i test failed -- creating new file", NULL);\r
- }\r
-\r
- goto CreateFile;\r
- }\r
-\r
- if (mGlobals.Verbose) {\r
- DebugMsg (NULL, 0, 0, "existing file would be unchanged -- keeping existing apriori file", NULL);\r
- }\r
-\r
- goto FinishUp;\r
- }\r
-\r
-CreateFile:\r
- //\r
- // Rewind the Apriori file in case -i was specified. Also\r
- // try to close the output file for the case where we prescanned\r
- // it (again, because of -i).\r
- //\r
- rewind (AprioriFptr);\r
- if (BinFptr != NULL) {\r
- fclose (BinFptr);\r
- }\r
- //\r
- // Open the output file\r
- //\r
- if ((BinFptr = fopen (mGlobals.OutputFileName, "wb")) == NULL) {\r
- Error (NULL, 0, 0, mGlobals.OutputFileName, "could not open input file");\r
- goto FinishUp;\r
- }\r
- //\r
- // Read lines until we're done\r
- //\r
- LineCounter = 0;\r
- while (fgets (Line, sizeof (Line), AprioriFptr) != NULL) {\r
- LineCounter++;\r
- if (IsCommentLine (Line)) {\r
- continue;\r
- }\r
- //\r
- // Convert to a GUID\r
- //\r
- if (StringToGuid (Line, &Guid) != EFI_SUCCESS) {\r
- Error (mGlobals.AprioriFileName, LineCounter, 0, "failed to convert GUID", NULL);\r
- goto FinishUp;\r
- }\r
- //\r
- // Write the guid to the output file\r
- //\r
- if (fwrite (&Guid, sizeof (Guid), 1, BinFptr) != 1) {\r
- Error (NULL, 0, 0, mGlobals.OutputFileName, "failed to write GUID to output file");\r
- goto FinishUp;\r
- }\r
- }\r
- //\r
- // Write a null guid out to terminate the list\r
- //\r
- if (mGlobals.NullTerminate) {\r
- memset ((void *) &Guid, 0, sizeof (Guid));\r
- if (fwrite (&Guid, sizeof (Guid), 1, BinFptr) != 1) {\r
- Error (NULL, 0, 0, mGlobals.OutputFileName, "failed to write NULL termination GUID to output file");\r
- }\r
- }\r
-\r
-FinishUp:\r
-\r
- if (AprioriFptr != NULL) {\r
- fclose (AprioriFptr);\r
- }\r
-\r
- if (BinFptr != NULL) {\r
- fclose (BinFptr);\r
- }\r
-\r
- return GetUtilityStatus ();\r
-}\r
-\r
-static\r
-BOOLEAN\r
-IsCommentLine (\r
- INT8 *Line\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Line - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- for (; isspace (*Line) && *Line; Line++)\r
- ;\r
-\r
- //\r
- // Allow # or // comments\r
- //\r
- if ((*Line == '#') || ((*Line == '/') && (*(Line + 1) == '/')) || (*Line == '\n') || (*Line == 0)) {\r
- return TRUE;\r
- }\r
-\r
- return FALSE;\r
-}\r
-//\r
-// Process the command-line arguments\r
-//\r
-static\r
-STATUS\r
-ProcessArgs (\r
- int Argc,\r
- char *Argv[]\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Argc - GC_TODO: add argument description\r
- ] - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- //\r
- // Skip program name\r
- //\r
- Argc--;\r
- Argv++;\r
-\r
- //\r
- // Process until no more args\r
- //\r
- while (Argc) {\r
- //\r
- // -f AprioriFile\r
- //\r
- if (_stricmp (Argv[0], "-f") == 0) {\r
- //\r
- // check for one more arg\r
- //\r
- if (Argc > 1) {\r
- mGlobals.AprioriFileName = Argv[1];\r
- } else {\r
- Error (NULL, 0, 0, NULL, "missing filename with %s", Argv[0]);\r
- Usage ();\r
- return STATUS_ERROR;\r
- }\r
-\r
- Argc--;\r
- Argv++;\r
- } else if (_stricmp (Argv[0], "-i") == 0) {\r
- //\r
- // intelligent creation of output file. That is to say, if\r
- // there's already a file there, and it's the same as what\r
- // we'd create, then don't re-create. This is to support\r
- // incremental builds (that is to say, running nmake a second time\r
- // does nothing).\r
- //\r
- mGlobals.Intelligent = TRUE;\r
- } else if (_stricmp (Argv[0], "-v") == 0) {\r
- mGlobals.Verbose = TRUE;\r
- } else if (_stricmp (Argv[0], "-null") == 0) {\r
- mGlobals.NullTerminate = TRUE;\r
- } else if (_stricmp (Argv[0], "-o") == 0) {\r
- //\r
- // -o OutputFileName\r
- // check for one more arg\r
- //\r
- if (Argc > 1) {\r
- mGlobals.OutputFileName = Argv[1];\r
- } else {\r
- Error (NULL, 0, 0, NULL, "missing filename argument with %s", Argv[0]);\r
- Usage ();\r
- return STATUS_ERROR;\r
- }\r
-\r
- Argc--;\r
- Argv++;\r
- } else if ((_stricmp (Argv[0], "-h") == 0) || (strcmp (Argv[0], "-?") == 0)) {\r
- Usage ();\r
- return STATUS_ERROR;\r
- } else {\r
- Error (NULL, 0, 0, Argv[0], "unrecognized option");\r
- Usage ();\r
- return STATUS_ERROR;\r
- }\r
-\r
- Argc--;\r
- Argv++;\r
- }\r
- //\r
- // Had to specify the apriori input file and output file names\r
- //\r
- if (mGlobals.AprioriFileName == NULL) {\r
- Error (NULL, 0, 0, "must specify -f AprioriFile", NULL);\r
- Usage ();\r
- return STATUS_ERROR;\r
- }\r
-\r
- if (mGlobals.OutputFileName == NULL) {\r
- Error (NULL, 0, 0, "must specify -o OutputFile", NULL);\r
- Usage ();\r
- return STATUS_ERROR;\r
- }\r
-\r
- return STATUS_SUCCESS;\r
-}\r
-\r
-static\r
-void\r
-Usage (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Print usage information for this utility.\r
- \r
-Arguments:\r
-\r
- None.\r
-\r
-Returns:\r
-\r
- Nothing.\r
- \r
---*/\r
-{\r
- int Index;\r
- const char *Str[] = {\r
- UTILITY_NAME" "UTILITY_VERSION" - Intel Generate Apriori File Utility",\r
- " Copyright (C), 2006 - 2008 Intel Corporation",\r
- \r
-#if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )\r
- " Built from "UTILITY_BUILD", project of "UTILITY_VENDOR,\r
-#endif\r
- "",\r
- "Usage:",\r
- " "UTILITY_NAME" [OPTION]...",\r
- "Description:",\r
- " Generate an Apriori file consumable by the DXE or PEI dispatcher.",\r
- "Options:",\r
- " -h or -? for this help information",\r
- " -f AprioriFile parse the GUID'ed files in AprioriFile (required)",\r
- " -o OutputFile write output to OutputFile (required)",\r
- " -i for intelligent re-creation of OutputFile",\r
- " -null to terminate the output file with a NULL GUID",\r
- " -v verbose option",\r
- NULL\r
- };\r
- for (Index = 0; Str[Index] != NULL; Index++) {\r
- fprintf (stdout, "%s\n", Str[Index]);\r
- }\r
-}\r