]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/GuidChk/GuidList.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / GuidChk / GuidList.c
1 /*++
2
3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. 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 GuidList.c
15
16 Abstract:
17
18 Utility to create a GUID-to-name listing file that can
19 be used by other utilities. Basic operation is to take the
20 table of name+GUIDs that we have compiled into this utility,
21 and create a text file that can be parsed by other utilities
22 to do replacement of "name" with "GUID".
23
24 Notes:
25 To add a new GUID to this database:
26 1. Add a "#include EFI_GUID_DEFINITION(name)" statement below
27 2. Modify the mGuidList[] array below to add the new GUID name
28
29 The only issue that may come up is that, if the source GUID file
30 is not in the standard GUID directory, then this utility won't
31 compile because the #include fails. In this case you'd need
32 to define a new macro (if it's in a standard place) or modify
33 this utility's makefile to add the path to your new .h file.
34
35 --*/
36
37 #include <stdio.h>
38 #include <string.h>
39 #include <stdlib.h>
40 #include <ctype.h>
41
42 #include "Tiano.h"
43 #include "EfiUtilityMsgs.h"
44
45 #include EFI_GUID_DEFINITION (Apriori)
46 #include EFI_GUID_DEFINITION (AcpiTableStorage)
47 #include EFI_GUID_DEFINITION (Bmp)
48 #include EFI_GUID_DEFINITION (AcpiTableStorage)
49 #include EFI_GUID_DEFINITION (PeiApriori)
50
51
52 #define GUID_XREF(varname, guid) { \
53 #varname, #guid, guid \
54 }
55
56 #define NULL_GUID \
57 { \
58 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 \
59 }
60
61 typedef struct {
62 INT8 *VariableName;
63 INT8 *DefineName;
64 EFI_GUID Guid;
65 } GUID_LIST;
66
67 //
68 // This is our table of all GUIDs we want to print out to create
69 // a GUID-to-name cross reference.
70 // Use the #defined name from the GUID definition's source .h file.
71 //
72 static GUID_LIST mGuidList[] = {
73 GUID_XREF(gEfiPeiAprioriGuid, EFI_PEI_APRIORI_FILE_NAME_GUID),
74 GUID_XREF(gAprioriGuid, EFI_APRIORI_GUID),
75 GUID_XREF(gEfiDefaultBmpLogoGuid, EFI_DEFAULT_BMP_LOGO_GUID),
76 GUID_XREF(gEfiAcpiTableStorageGuid, EFI_ACPI_TABLE_STORAGE_GUID),
77 //
78 // Terminator
79 //
80 {
81 NULL,
82 NULL,
83 NULL_GUID
84 }
85 };
86
87 void
88 PrintGuidText (
89 FILE *OutFptr,
90 INT8 *VariableName,
91 INT8 *DefineName,
92 EFI_GUID *Guid
93 );
94
95 int
96 CreateGuidList (
97 INT8 *OutFileName
98 )
99 /*++
100
101 Routine Description:
102 Print our GUID/name list to the specified output file.
103
104 Arguments:
105 OutFileName - name of the output file to write our results to.
106
107 Returns:
108 0 if successful
109 nonzero otherwise
110
111 --*/
112 {
113 FILE *OutFptr;
114 int Index;
115
116 //
117 // Open output file for writing. If the name is NULL, then write to stdout
118 //
119 if (OutFileName != NULL) {
120 OutFptr = fopen (OutFileName, "w");
121 if (OutFptr == NULL) {
122 Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");
123 return STATUS_ERROR;
124 }
125 } else {
126 OutFptr = stdout;
127 }
128
129 for (Index = 0; mGuidList[Index].VariableName != NULL; Index++) {
130 PrintGuidText (OutFptr, mGuidList[Index].VariableName, mGuidList[Index].DefineName, &mGuidList[Index].Guid);
131 }
132 //
133 // Close the output file if they specified one.
134 //
135 if (OutFileName != NULL) {
136 fclose (OutFptr);
137 }
138
139 return STATUS_SUCCESS;
140 }
141
142 void
143 PrintGuidText (
144 FILE *OutFptr,
145 INT8 *VariableName,
146 INT8 *DefineName,
147 EFI_GUID *Guid
148 )
149 /*++
150
151 Routine Description:
152 Print a GUID/name combo in INF-style format
153
154 guid-guid-guid-guid DEFINE_NAME gName
155
156 Arguments:
157 OutFptr - file pointer to which to write the output
158 VariableName - the GUID variable's name
159 DefineName - the name used in the #define
160 Guid - pointer to the GUID value
161
162 Returns:
163 NA
164
165 --*/
166 {
167 if (OutFptr == NULL) {
168 OutFptr = stdout;
169 }
170
171 fprintf (
172 OutFptr,
173 "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X %s %s\n",
174 Guid->Data1,
175 Guid->Data2,
176 Guid->Data3,
177 Guid->Data4[0],
178 Guid->Data4[1],
179 Guid->Data4[2],
180 Guid->Data4[3],
181 Guid->Data4[4],
182 Guid->Data4[5],
183 Guid->Data4[6],
184 Guid->Data4[7],
185 DefineName,
186 VariableName
187 );
188 }