]>
Commit | Line | Data |
---|---|---|
1 | /*++\r | |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | UnicodeCollationEng.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Unicode Collation Protocol (English)\r | |
19 | \r | |
20 | Revision History\r | |
21 | \r | |
22 | --*/\r | |
23 | \r | |
24 | #include "UnicodeCollationEng.h"\r | |
25 | \r | |
26 | CHAR8 mEngUpperMap[0x100];\r | |
27 | CHAR8 mEngLowerMap[0x100];\r | |
28 | CHAR8 mEngInfoMap[0x100];\r | |
29 | \r | |
30 | CHAR8 mOtherChars[] = {\r | |
31 | '0',\r | |
32 | '1',\r | |
33 | '2',\r | |
34 | '3',\r | |
35 | '4',\r | |
36 | '5',\r | |
37 | '6',\r | |
38 | '7',\r | |
39 | '8',\r | |
40 | '9',\r | |
41 | '\\',\r | |
42 | '.',\r | |
43 | '_',\r | |
44 | '^',\r | |
45 | '$',\r | |
46 | '~',\r | |
47 | '!',\r | |
48 | '#',\r | |
49 | '%',\r | |
50 | '&',\r | |
51 | '-',\r | |
52 | '{',\r | |
53 | '}',\r | |
54 | '(',\r | |
55 | ')',\r | |
56 | '@',\r | |
57 | '`',\r | |
58 | '\'',\r | |
59 | '\0'\r | |
60 | };\r | |
61 | \r | |
62 | EFI_HANDLE mHandle = NULL;\r | |
63 | \r | |
64 | EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng = {\r | |
65 | EngStriColl,\r | |
66 | EngMetaiMatch,\r | |
67 | EngStrLwr,\r | |
68 | EngStrUpr,\r | |
69 | EngFatToStr,\r | |
70 | EngStrToFat,\r | |
71 | "eng"\r | |
72 | };\r | |
73 | \r | |
74 | //\r | |
75 | //\r | |
76 | //\r | |
77 | EFI_STATUS\r | |
78 | InitializeUnicodeCollationEng (\r | |
79 | IN EFI_HANDLE ImageHandle,\r | |
80 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
81 | )\r | |
82 | /*++\r | |
83 | \r | |
84 | Routine Description:\r | |
85 | \r | |
86 | Initializes the Unicode Collation Driver\r | |
87 | \r | |
88 | Arguments:\r | |
89 | \r | |
90 | ImageHandle -\r | |
91 | \r | |
92 | SystemTable -\r | |
93 | \r | |
94 | Returns:\r | |
95 | \r | |
96 | EFI_SUCCESS\r | |
97 | EFI_OUT_OF_RESOURCES\r | |
98 | \r | |
99 | --*/\r | |
100 | {\r | |
101 | UINTN Index;\r | |
102 | UINTN Index2;\r | |
103 | \r | |
104 | //\r | |
105 | // Initialize mapping tables for the supported languages\r | |
106 | //\r | |
107 | for (Index = 0; Index < 0x100; Index++) {\r | |
108 | mEngUpperMap[Index] = (CHAR8) Index;\r | |
109 | mEngLowerMap[Index] = (CHAR8) Index;\r | |
110 | mEngInfoMap[Index] = 0;\r | |
111 | \r | |
112 | if ((Index >= 'a' && Index <= 'z') || (Index >= 0xe0 && Index <= 0xf6) || (Index >= 0xf8 && Index <= 0xfe)) {\r | |
113 | \r | |
114 | Index2 = Index - 0x20;\r | |
115 | mEngUpperMap[Index] = (CHAR8) Index2;\r | |
116 | mEngLowerMap[Index2] = (CHAR8) Index;\r | |
117 | \r | |
118 | mEngInfoMap[Index] |= CHAR_FAT_VALID;\r | |
119 | mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r | |
120 | }\r | |
121 | }\r | |
122 | \r | |
123 | for (Index = 0; mOtherChars[Index]; Index++) {\r | |
124 | Index2 = mOtherChars[Index];\r | |
125 | mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r | |
126 | }\r | |
127 | //\r | |
128 | // Create a handle for the device\r | |
129 | //\r | |
130 | return gBS->InstallProtocolInterface (\r | |
131 | &mHandle,\r | |
132 | &gEfiUnicodeCollationProtocolGuid,\r | |
133 | EFI_NATIVE_INTERFACE,\r | |
134 | &UnicodeEng\r | |
135 | );\r | |
136 | }\r | |
137 | \r | |
138 | INTN\r | |
139 | EFIAPI\r | |
140 | EngStriColl (\r | |
141 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
142 | IN CHAR16 *s1,\r | |
143 | IN CHAR16 *s2\r | |
144 | )\r | |
145 | /*++\r | |
146 | \r | |
147 | Routine Description:\r | |
148 | \r | |
149 | Performs a case-insensitive comparison of two Null-terminated Unicode strings.\r | |
150 | \r | |
151 | Arguments:\r | |
152 | \r | |
153 | This\r | |
154 | s1\r | |
155 | s2\r | |
156 | \r | |
157 | Returns:\r | |
158 | \r | |
159 | --*/\r | |
160 | {\r | |
161 | while (*s1) {\r | |
162 | if (ToUpper (*s1) != ToUpper (*s2)) {\r | |
163 | break;\r | |
164 | }\r | |
165 | \r | |
166 | s1 += 1;\r | |
167 | s2 += 1;\r | |
168 | }\r | |
169 | \r | |
170 | return ToUpper (*s1) - ToUpper (*s2);\r | |
171 | }\r | |
172 | \r | |
173 | VOID\r | |
174 | EFIAPI\r | |
175 | EngStrLwr (\r | |
176 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
177 | IN OUT CHAR16 *Str\r | |
178 | )\r | |
179 | /*++\r | |
180 | \r | |
181 | Routine Description:\r | |
182 | \r | |
183 | Converts all the Unicode characters in a Null-terminated Unicode string\r | |
184 | to lower case Unicode characters.\r | |
185 | \r | |
186 | Arguments:\r | |
187 | \r | |
188 | This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.\r | |
189 | Str1 - A pointer to a Null-terminated Unicode string.\r | |
190 | Str2 - A pointer to a Null-terminated Unicode string.\r | |
191 | \r | |
192 | Returns:\r | |
193 | \r | |
194 | 0 - s1 is equivalent to s2.\r | |
195 | > 0 - s1 is lexically greater than s2.\r | |
196 | < 0 - s1 is lexically less than s2.\r | |
197 | \r | |
198 | --*/\r | |
199 | {\r | |
200 | while (*Str) {\r | |
201 | *Str = ToLower (*Str);\r | |
202 | Str += 1;\r | |
203 | }\r | |
204 | }\r | |
205 | \r | |
206 | VOID\r | |
207 | EFIAPI\r | |
208 | EngStrUpr (\r | |
209 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
210 | IN OUT CHAR16 *Str\r | |
211 | )\r | |
212 | /*++\r | |
213 | \r | |
214 | Routine Description:\r | |
215 | \r | |
216 | Converts all the Unicode characters in a Null-terminated \r | |
217 | Unicode string to upper case Unicode characters.\r | |
218 | \r | |
219 | Arguments:\r | |
220 | This\r | |
221 | Str\r | |
222 | \r | |
223 | Returns:\r | |
224 | None\r | |
225 | \r | |
226 | --*/\r | |
227 | {\r | |
228 | while (*Str) {\r | |
229 | *Str = ToUpper (*Str);\r | |
230 | Str += 1;\r | |
231 | }\r | |
232 | }\r | |
233 | \r | |
234 | BOOLEAN\r | |
235 | EFIAPI\r | |
236 | EngMetaiMatch (\r | |
237 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
238 | IN CHAR16 *String,\r | |
239 | IN CHAR16 *Pattern\r | |
240 | )\r | |
241 | /*++\r | |
242 | \r | |
243 | Routine Description:\r | |
244 | \r | |
245 | Performs a case-insensitive comparison between a Null-terminated\r | |
246 | Unicode pattern string and a Null-terminated Unicode string. \r | |
247 | \r | |
248 | The pattern string can use the '?' wildcard to match any character, \r | |
249 | and the '*' wildcard to match any sub-string.\r | |
250 | \r | |
251 | Arguments:\r | |
252 | \r | |
253 | This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.\r | |
254 | String - A pointer to a Null-terminated Unicode string.\r | |
255 | Pattern - A pointer to a Null-terminated Unicode pattern string.\r | |
256 | \r | |
257 | Returns:\r | |
258 | \r | |
259 | TRUE - Pattern was found in String.\r | |
260 | FALSE - Pattern was not found in String.\r | |
261 | \r | |
262 | --*/\r | |
263 | {\r | |
264 | CHAR16 CharC;\r | |
265 | CHAR16 CharP;\r | |
266 | CHAR16 Index3;\r | |
267 | \r | |
268 | for (;;) {\r | |
269 | CharP = *Pattern;\r | |
270 | Pattern += 1;\r | |
271 | \r | |
272 | switch (CharP) {\r | |
273 | case 0:\r | |
274 | //\r | |
275 | // End of pattern. If end of string, TRUE match\r | |
276 | //\r | |
277 | if (*String) {\r | |
278 | return FALSE;\r | |
279 | } else {\r | |
280 | return TRUE;\r | |
281 | }\r | |
282 | \r | |
283 | case '*':\r | |
284 | //\r | |
285 | // Match zero or more chars\r | |
286 | //\r | |
287 | while (*String) {\r | |
288 | if (EngMetaiMatch (This, String, Pattern)) {\r | |
289 | return TRUE;\r | |
290 | }\r | |
291 | \r | |
292 | String += 1;\r | |
293 | }\r | |
294 | \r | |
295 | return EngMetaiMatch (This, String, Pattern);\r | |
296 | \r | |
297 | case '?':\r | |
298 | //\r | |
299 | // Match any one char\r | |
300 | //\r | |
301 | if (!*String) {\r | |
302 | return FALSE;\r | |
303 | }\r | |
304 | \r | |
305 | String += 1;\r | |
306 | break;\r | |
307 | \r | |
308 | case '[':\r | |
309 | //\r | |
310 | // Match char set\r | |
311 | //\r | |
312 | CharC = *String;\r | |
313 | if (!CharC) {\r | |
314 | //\r | |
315 | // syntax problem\r | |
316 | //\r | |
317 | return FALSE;\r | |
318 | }\r | |
319 | \r | |
320 | Index3 = 0;\r | |
321 | CharP = *Pattern++;\r | |
322 | while (CharP) {\r | |
323 | if (CharP == ']') {\r | |
324 | return FALSE;\r | |
325 | }\r | |
326 | \r | |
327 | if (CharP == '-') {\r | |
328 | //\r | |
329 | // if range of chars, get high range\r | |
330 | //\r | |
331 | CharP = *Pattern;\r | |
332 | if (CharP == 0 || CharP == ']') {\r | |
333 | //\r | |
334 | // syntax problem\r | |
335 | //\r | |
336 | return FALSE;\r | |
337 | }\r | |
338 | \r | |
339 | if (ToUpper (CharC) >= ToUpper (Index3) && ToUpper (CharC) <= ToUpper (CharP)) {\r | |
340 | //\r | |
341 | // if in range, it's a match\r | |
342 | //\r | |
343 | break;\r | |
344 | }\r | |
345 | }\r | |
346 | \r | |
347 | Index3 = CharP;\r | |
348 | if (ToUpper (CharC) == ToUpper (CharP)) {\r | |
349 | //\r | |
350 | // if char matches\r | |
351 | //\r | |
352 | break;\r | |
353 | }\r | |
354 | \r | |
355 | CharP = *Pattern++;\r | |
356 | }\r | |
357 | //\r | |
358 | // skip to end of match char set\r | |
359 | //\r | |
360 | while (CharP && CharP != ']') {\r | |
361 | CharP = *Pattern;\r | |
362 | Pattern += 1;\r | |
363 | }\r | |
364 | \r | |
365 | String += 1;\r | |
366 | break;\r | |
367 | \r | |
368 | default:\r | |
369 | CharC = *String;\r | |
370 | if (ToUpper (CharC) != ToUpper (CharP)) {\r | |
371 | return FALSE;\r | |
372 | }\r | |
373 | \r | |
374 | String += 1;\r | |
375 | break;\r | |
376 | }\r | |
377 | }\r | |
378 | }\r | |
379 | \r | |
380 | VOID\r | |
381 | EFIAPI\r | |
382 | EngFatToStr (\r | |
383 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
384 | IN UINTN FatSize,\r | |
385 | IN CHAR8 *Fat,\r | |
386 | OUT CHAR16 *String\r | |
387 | )\r | |
388 | /*++\r | |
389 | \r | |
390 | Routine Description:\r | |
391 | \r | |
392 | Converts an 8.3 FAT file name using an OEM character set \r | |
393 | to a Null-terminated Unicode string.\r | |
394 | \r | |
395 | BUGBUG: Function has to expand DBCS FAT chars, currently not.\r | |
396 | \r | |
397 | Arguments:\r | |
398 | This\r | |
399 | FatSize\r | |
400 | Fat\r | |
401 | String\r | |
402 | \r | |
403 | Returns:\r | |
404 | \r | |
405 | --*/\r | |
406 | {\r | |
407 | //\r | |
408 | // No DBCS issues, just expand and add null terminate to end of string\r | |
409 | //\r | |
410 | while (*Fat && FatSize) {\r | |
411 | *String = *Fat;\r | |
412 | String += 1;\r | |
413 | Fat += 1;\r | |
414 | FatSize -= 1;\r | |
415 | }\r | |
416 | \r | |
417 | *String = 0;\r | |
418 | }\r | |
419 | \r | |
420 | BOOLEAN\r | |
421 | EFIAPI\r | |
422 | EngStrToFat (\r | |
423 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
424 | IN CHAR16 *String,\r | |
425 | IN UINTN FatSize,\r | |
426 | OUT CHAR8 *Fat\r | |
427 | )\r | |
428 | /*++\r | |
429 | \r | |
430 | Routine Description:\r | |
431 | \r | |
432 | Converts a Null-terminated Unicode string to legal characters \r | |
433 | in a FAT filename using an OEM character set.\r | |
434 | \r | |
435 | Functions has to crunch string to a fat string. Replacing\r | |
436 | any chars that can't be represented in the fat name.\r | |
437 | \r | |
438 | Arguments:\r | |
439 | This\r | |
440 | String\r | |
441 | FatSize\r | |
442 | Fat\r | |
443 | \r | |
444 | Returns:\r | |
445 | TRUE\r | |
446 | FALSE\r | |
447 | --*/\r | |
448 | {\r | |
449 | BOOLEAN SpecialCharExist;\r | |
450 | \r | |
451 | SpecialCharExist = FALSE;\r | |
452 | while (*String && FatSize) {\r | |
453 | //\r | |
454 | // Skip '.' or ' ' when making a fat name\r | |
455 | //\r | |
456 | if (*String != '.' && *String != ' ') {\r | |
457 | //\r | |
458 | // If this is a valid fat char, move it.\r | |
459 | // Otherwise, move a '_' and flag the fact that the name needs an Lfn\r | |
460 | //\r | |
461 | if (*String < 0x100 && (mEngInfoMap[*String] & CHAR_FAT_VALID)) {\r | |
462 | *Fat = mEngUpperMap[*String];\r | |
463 | } else {\r | |
464 | *Fat = '_';\r | |
465 | SpecialCharExist = TRUE;\r | |
466 | }\r | |
467 | \r | |
468 | Fat += 1;\r | |
469 | FatSize -= 1;\r | |
470 | }\r | |
471 | \r | |
472 | String += 1;\r | |
473 | }\r | |
474 | //\r | |
475 | // Do not terminate that fat string\r | |
476 | //\r | |
477 | return SpecialCharExist;\r | |
478 | }\r |