]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/UefiStrGather/StringDB.h
9e4088bcf870b215f6e0a02b49c8fc668fe33135
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / UefiStrGather / StringDB.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 StringDB.h
15
16 Abstract:
17
18 Common defines and prototypes for string database management
19
20 --*/
21
22 #ifndef _STRING_DB_H_
23 #define _STRING_DB_H_
24
25 #define LANGUAGE_NAME_STRING_NAME L"$LANGUAGE_NAME"
26 #define PRINTABLE_LANGUAGE_NAME_STRING_NAME L"$PRINTABLE_LANGUAGE_NAME"
27
28 typedef CHAR16 WCHAR;
29
30 #define NARROW_CHAR 0xFFF0
31 #define WIDE_CHAR 0xFFF1
32 #define NON_BREAKING_CHAR 0xFFF2
33 #define GLYPH_WIDTH 8
34 #define GLYPH_HEIGHT 19
35
36 #define STRING_DB_KEY (('S' << 24) | ('D' << 16) | ('B' << 8) | 'K')
37 //
38 // Version supported by this tool
39 //
40 #define STRING_DB_VERSION 0x00010000
41
42 #define STRING_DB_MAJOR_VERSION_MASK 0xFFFF0000
43 #define STRING_DB_MINOR_VERSION_MASK 0x0000FFFF
44
45 #define DEFINE_STR L"// #define"
46
47 #define EFI_STRING_ID_BEGIN 0x01
48
49 //
50 // This is the header that gets written to the top of the
51 // output binary database file.
52 //
53 typedef struct {
54 UINT32 Key;
55 UINT32 HeaderSize;
56 UINT32 Version;
57 UINT32 NumStringIdenfiers;
58 UINT32 StringIdentifiersSize;
59 UINT32 NumLanguages;
60 } STRING_DB_HEADER;
61
62 //
63 // When we write out data to the database, we have a UINT16 identifier, which
64 // indicates what follows, followed by the data. Here's the structure.
65 //
66 typedef struct {
67 UINT16 DataType;
68 UINT16 Reserved;
69 } DB_DATA_ITEM_HEADER;
70
71 #define DB_DATA_TYPE_INVALID 0x0000
72 #define DB_DATA_TYPE_STRING_IDENTIFIER 0x0001
73 #define DB_DATA_TYPE_LANGUAGE_DEFINITION 0x0002
74 #define DB_DATA_TYPE_STRING_DEFINITION 0x0003
75 #define DB_DATA_TYPE_LAST DB_DATA_TYPE_STRING_DEFINITION
76
77 //
78 // We have to keep track of a list of languages, each of which has its own
79 // list of strings. Define a structure to keep track of all languages and
80 // their list of strings.
81 //
82 typedef struct _STRING_LIST {
83 struct _STRING_LIST *Next;
84 UINT32 Size; // number of bytes in string, including null terminator
85 WCHAR *LanguageName;
86 WCHAR *StringName; // for example STR_ID_TEXT1
87 WCHAR *Scope; //
88 WCHAR *Str; // the actual string
89 UINT16 Flags; // properties of this string (used, undefined)
90 } STRING_LIST;
91
92 typedef struct _LANGUAGE_LIST {
93 struct _LANGUAGE_LIST *Next;
94 WCHAR *LanguageName;
95 WCHAR *PrintableLanguageName;
96 WCHAR *SecondaryLanguageList;
97 STRING_LIST *String;
98 STRING_LIST *LastString;
99 } LANGUAGE_LIST;
100
101 //
102 // We also keep track of all the string identifier names, which we assign unique
103 // values to. Create a structure to keep track of them all.
104 //
105 typedef struct _STRING_IDENTIFIER {
106 struct _STRING_IDENTIFIER *Next;
107 UINT32 Index; // only need 16 bits, but makes it easier with UINT32
108 WCHAR *StringName;
109 UINT16 Flags; // if someone referenced it via STRING_TOKEN()
110 } STRING_IDENTIFIER;
111 //
112 // Keep our globals in this structure to be as modular as possible.
113 //
114 typedef struct {
115 FILE *StringDBFptr;
116 LANGUAGE_LIST *LanguageList;
117 LANGUAGE_LIST *LastLanguageList;
118 LANGUAGE_LIST *CurrentLanguage; // keep track of the last language they used
119 STRING_IDENTIFIER *StringIdentifier;
120 STRING_IDENTIFIER *LastStringIdentifier;
121 UINT8 *StringDBFileName;
122 UINT32 NumStringIdentifiers;
123 UINT32 NumStringIdentifiersReferenced;
124 STRING_IDENTIFIER *CurrentStringIdentifier; // keep track of the last string identifier they added
125 WCHAR *CurrentScope;
126 } STRING_DB_DATA;
127
128 typedef struct _SPkgBlkBuffer {
129 UINT32 mBlkSize;
130 VOID *mBlkBuffer;
131 struct _SPkgBlkBuffer *mNext;
132 } SPkgBlkBuffer;
133
134 void
135 StringDBConstructor (
136 void
137 );
138 void
139 StringDBDestructor (
140 void
141 );
142
143 STATUS
144 StringDBAddString (
145 WCHAR *LanguageName,
146 WCHAR *StringIdentifier,
147 WCHAR *Scope,
148 WCHAR *String,
149 BOOLEAN Format,
150 UINT16 Flags
151 );
152
153 STATUS
154 StringDBSetScope (
155 WCHAR *Scope
156 );
157
158 #define STRING_FLAGS_REFERENCED 0x0001 // if referenced somewhere
159 #define STRING_FLAGS_UNDEFINED 0x0002 // if we added it for padding purposes
160 #define STRING_FLAGS_INDEX_ASSIGNED 0x0004 // so don't change the index value
161 #define STRING_ID_INVALID 0xFFFF
162 #define STRING_ID_LANGUAGE_NAME 0x0000
163 #define STRING_ID_PRINTABLE_LANGUAGE_NAME 0x0001
164
165 STATUS
166 StringDBAddStringIdentifier (
167 WCHAR *StringIdentifier,
168 UINT16 *NewId,
169 UINT16 Flags
170 );
171
172 STATUS
173 StringDBReadDatabase (
174 INT8 *DBFileName,
175 BOOLEAN IgnoreIfNotExist,
176 BOOLEAN Verbose
177 );
178
179 STATUS
180 StringDBWriteDatabase (
181 INT8 *DBFileName,
182 BOOLEAN Verbose
183 );
184
185 STATUS
186 StringDBDumpDatabase (
187 INT8 *DBFileName,
188 INT8 *OutputFileName,
189 BOOLEAN Verbose
190 );
191
192 STATUS
193 StringDBAddLanguage (
194 WCHAR *LanguageName,
195 WCHAR *PrintableLanguageName,
196 WCHAR *SecondaryLanguageList
197 );
198
199 STATUS
200 StringDBAddSecondaryLanguage (
201 WCHAR *LanguageName,
202 WCHAR *SecondaryLanguageList
203 );
204
205 STATUS
206 StringDBDumpCStrings (
207 INT8 *BaseName,
208 INT8 *FileName
209 );
210
211 STATUS
212 StringDBDumpStringDefines (
213 INT8 *FileName,
214 INT8 *BaseName
215 );
216
217 STATUS
218 StringDBSetCurrentLanguage (
219 WCHAR *LanguageName
220 );
221
222 STATUS
223 StringDBSetStringReferenced (
224 INT8 *StringIdentifierName,
225 BOOLEAN IgnoreNotFound
226 );
227
228 void
229 StringDBFormatString (
230 WCHAR *String
231 );
232
233 LANGUAGE_LIST *
234 StringDBFindLanguageList (
235 WCHAR *LanguageName
236 );
237
238 #endif // #ifndef _STRING_DB_H_