Port DriverSample.inf, HiiDatabase.inf and SetupBrowser.inf
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / SetupBrowserDxe / ProcessOptions.c
1 /**@file
2 Implementation for handling the User Interface option processing.
3
4 Copyright (c) 2006 - 2007 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 //
16 // Include common header file for this module.
17 //
18 #include "CommonHeader.h"
19
20 #include "Setup.h"
21 #include "Ui.h"
22
23 EFI_STATUS
24 ExtractRequestedNvMap (
25 IN EFI_FILE_FORM_TAGS *FileFormTags,
26 IN UINT16 VariableId,
27 OUT EFI_VARIABLE_DEFINITION **VariableDefinition
28 )
29 {
30 *VariableDefinition = FileFormTags->VariableDefinitions;
31
32 //
33 // Extract the data from the NV variable - consumer will free the buffer.
34 //
35 for (; *VariableDefinition != NULL; *VariableDefinition = (*VariableDefinition)->Next) {
36 //
37 // If there is a variable with this ID return with EFI_SUCCESS
38 //
39 if (!CompareMem (&(*VariableDefinition)->VariableId, &VariableId, sizeof (UINT16))) {
40 return EFI_SUCCESS;
41 }
42 }
43
44 return EFI_NOT_FOUND;
45 }
46
47 EFI_STATUS
48 ExtractNvValue (
49 IN EFI_FILE_FORM_TAGS *FileFormTags,
50 IN UINT16 VariableId,
51 IN UINT16 VariableSize,
52 IN UINT16 OffsetValue,
53 OUT VOID **Buffer
54 )
55 {
56 EFI_STATUS Status;
57 EFI_VARIABLE_DEFINITION *VariableDefinition;
58
59 Status = ExtractRequestedNvMap (FileFormTags, VariableId, &VariableDefinition);
60
61 if (!EFI_ERROR (Status)) {
62 //
63 // Allocate sufficient space for the data and copy it into the outgoing buffer
64 //
65 if (VariableSize != 0) {
66 *Buffer = AllocateZeroPool (VariableSize);
67 ASSERT (*Buffer != NULL);
68 CopyMem (*Buffer, &VariableDefinition->NvRamMap[OffsetValue], VariableSize);
69 }
70 return EFI_SUCCESS;
71 }
72
73 return Status;
74 }
75
76 STATIC
77 VOID
78 AdjustNvMap (
79 IN EFI_FILE_FORM_TAGS *FileFormTags,
80 IN UI_MENU_OPTION *MenuOption
81 )
82 {
83 CHAR8 *NvRamMap;
84 UINTN SizeRequired;
85 UINTN Index;
86 UINTN CachedStart;
87 EFI_VARIABLE_DEFINITION *VariableDefinition;
88
89 CachedStart = 0;
90
91 SizeRequired = MenuOption->ThisTag->StorageStart + MenuOption->ThisTag->StorageWidth;
92
93 ExtractRequestedNvMap (FileFormTags, MenuOption->Tags->VariableNumber, &VariableDefinition);
94
95 //
96 // We arrived here because the current NvRamMap is too small for the new op-code to store things and
97 // we need to adjust the buffer to support this.
98 //
99 NvRamMap = AllocateZeroPool (SizeRequired + 1);
100 ASSERT (NvRamMap != NULL);
101
102 //
103 // Copy current NvRamMap to the new NvRamMap
104 //
105 CopyMem (NvRamMap, VariableDefinition->NvRamMap, VariableDefinition->VariableFakeSize);
106
107 //
108 // Remember, the only time we come here is because we are in the NVPlus section of the NvRamMap
109 //
110 for (Index = MenuOption->TagIndex;
111 (MenuOption->Tags[Index].Operand != EFI_IFR_END_FORM_OP) && (MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP);
112 Index++
113 ) {
114
115 switch (MenuOption->Tags[Index].Operand) {
116 case EFI_IFR_ORDERED_LIST_OP:
117 case EFI_IFR_ONE_OF_OP:
118 CachedStart = MenuOption->Tags[Index].StorageStart;
119 break;
120
121 case EFI_IFR_ONE_OF_OPTION_OP:
122 if (MenuOption->Tags[Index].Flags & EFI_IFR_FLAG_DEFAULT) {
123 CopyMem (&NvRamMap[CachedStart], &MenuOption->Tags[Index].Value, 2);
124 }
125 break;
126
127 case EFI_IFR_CHECKBOX_OP:
128 CopyMem (&NvRamMap[MenuOption->Tags[Index].StorageStart], &MenuOption->Tags[Index].Flags, 1);
129 break;
130
131 case EFI_IFR_NUMERIC_OP:
132 case EFI_IFR_DATE_OP:
133 case EFI_IFR_TIME_OP:
134 case EFI_IFR_STRING_OP:
135 case EFI_IFR_PASSWORD_OP:
136 CopyMem (
137 &NvRamMap[MenuOption->Tags[Index].StorageStart],
138 &MenuOption->Tags[Index].Value,
139 MenuOption->Tags[Index].StorageWidth
140 );
141 break;
142
143 }
144 }
145
146 FreePool (VariableDefinition->NvRamMap);
147 VariableDefinition->NvRamMap = NvRamMap;
148 VariableDefinition->VariableFakeSize = (UINT16) SizeRequired;
149 }
150
151 EFI_STATUS
152 ProcessOptions (
153 IN UI_MENU_OPTION *MenuOption,
154 IN BOOLEAN Selected,
155 IN EFI_FILE_FORM_TAGS *FileFormTagsHead,
156 IN EFI_IFR_DATA_ARRAY *PageData,
157 OUT CHAR16 **OptionString
158 )
159 {
160 EFI_STATUS Status;
161 CHAR16 *StringPtr;
162 UINTN Index;
163 UINTN CachedIndex;
164 EFI_FILE_FORM_TAGS *FileFormTags;
165 EFI_TAG *Tag;
166 CHAR16 FormattedNumber[6];
167 UINT16 Number;
168 UINT16 Value;
169 UINT16 *ValueArray;
170 UINT16 *NvRamMap;
171 CHAR8 *TmpNvRamMap;
172 UINTN Default;
173 UINTN StringCount;
174 CHAR16 Character[2];
175 UINTN Count;
176 EFI_TIME Time;
177 EFI_FORM_CALLBACK_PROTOCOL *FormCallback;
178 STRING_REF PopUp;
179 CHAR16 NullCharacter;
180 EFI_INPUT_KEY Key;
181 EFI_VARIABLE_DEFINITION *VariableDefinition;
182 BOOLEAN OrderedList;
183 BOOLEAN Initialized;
184 UINT16 KeyValue;
185 BOOLEAN Skip;
186
187 FileFormTags = FileFormTagsHead;
188
189 for (Index = 0; Index < MenuOption->IfrNumber; Index++) {
190 FileFormTags = FileFormTags->NextFile;
191 }
192
193 OrderedList = FALSE;
194 Initialized = FALSE;
195 ValueArray = NULL;
196 VariableDefinition = NULL;
197 Skip = FALSE;
198
199 ZeroMem (&Time, sizeof (EFI_TIME));
200
201 StringPtr = (CHAR16 *) L"\0";
202 Tag = MenuOption->ThisTag;
203 ExtractRequestedNvMap (FileFormTags, Tag->VariableNumber, &VariableDefinition);
204
205 if (Tag->StorageStart > VariableDefinition->VariableSize) {
206 NvRamMap = (UINT16 *) &VariableDefinition->FakeNvRamMap[Tag->StorageStart];
207 } else {
208 NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
209 }
210
211 StringCount = 0;
212 Character[1] = 0;
213 Count = 0;
214 Default = 0;
215 NullCharacter = CHAR_NULL;
216 FormCallback = NULL;
217
218 if (MenuOption->ThisTag->Operand == EFI_IFR_ORDERED_LIST_OP) {
219 OrderedList = TRUE;
220 if (((UINT8 *) NvRamMap)[0] != 0x00) {
221 Initialized = TRUE;
222 }
223 }
224
225 ZeroMem (FormattedNumber, 12);
226
227 Status = gBS->HandleProtocol (
228 (VOID *) (UINTN) FileFormTags->FormTags.Tags[0].CallbackHandle,
229 &gEfiFormCallbackProtocolGuid,
230 (VOID **) &FormCallback
231 );
232
233 if (*OptionString != NULL) {
234 FreePool (*OptionString);
235 *OptionString = NULL;
236 }
237
238 switch (Tag->Operand) {
239
240 case EFI_IFR_ORDERED_LIST_OP:
241 case EFI_IFR_ONE_OF_OP:
242 //
243 // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
244 // created entry which has an expanded NvMap requirement. We won't save this information - but we need to adjust
245 // the NvMap so that we can properly display the information
246 //
247 if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
248 AdjustNvMap (FileFormTags, MenuOption);
249 NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
250 }
251
252 CachedIndex = MenuOption->TagIndex;
253
254 //
255 // search for EFI_IFR_ONE_OF_OPTION_OP until you hit the EFI_IFR_END_ONE_OF_OP,
256 // each of the .Text in the options are going to be what gets displayed. Break each into 26 char chunks
257 // when hit right/left arrow allows for selection - then repopulate Tag[TagIndex] with the choice
258 //
259 for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP; Index++) {
260 //
261 // We found an option - which assumedly has a string. We will eventually have to support
262 // wrapping of strings. For now, let's pretend they don't wrap and code that up.
263 //
264 // Count how many strings there are
265 //
266 if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {
267 //
268 // If one of the options for the one-of has an interactive flag, back-define the oneof to have one too
269 //
270 if (MenuOption->Tags[Index].Flags & EFI_IFR_FLAG_INTERACTIVE) {
271 MenuOption->Tags[CachedIndex].Flags = (UINT8) (MenuOption->Tags[CachedIndex].Flags | EFI_IFR_FLAG_INTERACTIVE);
272 }
273
274 StringCount++;
275 }
276 }
277 //
278 // We now know how many strings we will have, so we can allocate the
279 // space required for the array or strings.
280 //
281 *OptionString = AllocateZeroPool (StringCount * (gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);
282 ASSERT (*OptionString);
283
284 //
285 // Add left delimeter to string
286 //
287 *OptionString[0] = LEFT_ONEOF_DELIMITER;
288
289 //
290 // Retrieve the current OneOf value
291 //
292 if (Selected) {
293 //
294 // Auto selection from list
295 //
296 Value = 0;
297 //
298 // Copy current setting to the seed Value
299 //
300 if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {
301 ValueArray = AllocateZeroPool (MenuOption->ThisTag->StorageWidth);
302 ASSERT (ValueArray != NULL);
303 CopyMem (ValueArray, NvRamMap, MenuOption->ThisTag->StorageWidth);
304 } else {
305 CopyMem (&Value, NvRamMap, MenuOption->ThisTag->StorageWidth);
306 CopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);
307 }
308
309 Number = Value;
310 if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {
311 Status = GetSelectionInputPopUp (MenuOption, Tag, MenuOption->ThisTag->StorageWidth, ValueArray, &KeyValue);
312 } else {
313 Status = GetSelectionInputPopUp (MenuOption, Tag, 1, &Value, &KeyValue);
314 }
315
316 if (!EFI_ERROR (Status)) {
317 if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {
318 CopyMem (NvRamMap, ValueArray, MenuOption->ThisTag->StorageWidth);
319 FreePool (ValueArray);
320 } else {
321 //
322 // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
323 //
324 CopyMem (NvRamMap, &Value, Tag->StorageWidth);
325 MenuOption->ThisTag->Key = KeyValue;
326 }
327 //
328 // If a late check is required save off the information. This is used when consistency checks
329 // are required, but certain values might be bound by an impossible consistency check such as
330 // if two questions are bound by consistency checks and each only has two possible choices, there
331 // would be no way for a user to switch the values. Thus we require late checking.
332 //
333 if (Tag->Flags & EFI_IFR_FLAG_LATE_CHECK) {
334 CopyMem (&Tag->OldValue, &Value, Tag->StorageWidth);
335 } else {
336 //
337 // In theory, passing the value and the Id are sufficient to determine what needs
338 // to be done. The Id is the key to look for the entry needed in the Inconsistency
339 // database. That will yields operand and ID data - and since the ID's correspond
340 // to the NV storage, we can determine the values for other IDs there.
341 //
342 if (ValueIsNotValid (TRUE, 0, Tag, FileFormTags, &PopUp)) {
343 if (PopUp == 0x0000) {
344 //
345 // Restore Old Value
346 //
347 if (!Tag->Suppress && !Tag->GrayOut) {
348 CopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);
349 }
350 break;
351 }
352
353 StringPtr = GetToken (PopUp, MenuOption->Handle);
354
355 CreatePopUp (GetStringWidth (StringPtr) / 2, 3, &NullCharacter, StringPtr, &NullCharacter);
356
357 do {
358 Status = WaitForKeyStroke (&Key);
359
360 switch (Key.UnicodeChar) {
361
362 case CHAR_CARRIAGE_RETURN:
363 //
364 // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
365 //
366 CopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);
367 FreePool (StringPtr);
368 break;
369
370 default:
371 break;
372 }
373 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
374 }
375 }
376
377 UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);
378 } else {
379 if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {
380 FreePool (ValueArray);
381 }
382
383 return EFI_SUCCESS;
384 }
385 } else {
386 for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP; Index++) {
387 //
388 // We found an option - which assumedly has a string. We will eventually have to support
389 // wrapping of strings. For now, let's pretend they don't wrap and code that up.
390 //
391 if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {
392 if (OrderedList) {
393 if (!Initialized) {
394 //
395 // If the first entry is invalid, then the "default" settings are based on what is reflected
396 // in the order of the op-codes
397 //
398 ((UINT8 *) NvRamMap)[Index - MenuOption->TagIndex - 1] = (UINT8) MenuOption->Tags[Index].Value;
399 }
400 //
401 // Only display 3 lines of stuff at most
402 //
403 if ((Index - MenuOption->TagIndex) > ORDERED_LIST_SIZE) {
404 break;
405 }
406
407 if (((Index - MenuOption->TagIndex) != 1) && !Skip) {
408 Character[0] = LEFT_ONEOF_DELIMITER;
409 NewStrCat (OptionString[0], Character);
410 }
411
412 MenuOption->ThisTag->NumberOfLines = (UINT16) (Index - MenuOption->TagIndex);
413 if (!Initialized) {
414 StringPtr = GetToken (MenuOption->Tags[Index].Text, MenuOption->Handle);
415 } else {
416 for (Value = (UINT16) (MenuOption->TagIndex + 1);
417 MenuOption->Tags[Value].Operand != EFI_IFR_END_ONE_OF_OP;
418 Value++
419 ) {
420 if (MenuOption->Tags[Value].Value == ((UINT8 *) NvRamMap)[Index - MenuOption->TagIndex - 1]) {
421 StringPtr = GetToken (MenuOption->Tags[Value].Text, MenuOption->Handle);
422 break;
423 }
424 }
425
426 if (MenuOption->Tags[Value].Operand == EFI_IFR_END_ONE_OF_OP) {
427 Skip = TRUE;
428 continue;
429 }
430 }
431
432 Skip = FALSE;
433 NewStrCat (OptionString[0], StringPtr);
434 Character[0] = RIGHT_ONEOF_DELIMITER;
435 NewStrCat (OptionString[0], Character);
436 Character[0] = CHAR_CARRIAGE_RETURN;
437 NewStrCat (OptionString[0], Character);
438
439 //
440 // Remove Buffer allocated for StringPtr after it has been used.
441 //
442 FreePool (StringPtr);
443 } else {
444 //
445 // The option value is the same as what is stored in NV store. Print this.
446 //
447 if (!CompareMem (&(MenuOption->Tags[Index].Value), NvRamMap, MenuOption->ThisTag->StorageWidth)) {
448 StringPtr = GetToken (MenuOption->Tags[Index].Text, MenuOption->Handle);
449 NewStrCat (OptionString[0], StringPtr);
450 Character[0] = RIGHT_ONEOF_DELIMITER;
451 NewStrCat (OptionString[0], Character);
452 //
453 // Remove Buffer allocated for StringPtr after it has been used.
454 //
455 FreePool (StringPtr);
456 Default = 0;
457 break;
458 }
459
460 if ((MenuOption->Tags[Index].Flags & EFI_IFR_FLAG_DEFAULT) == 1) {
461 Default = MenuOption->Tags[Index].Text;
462 Value = MenuOption->Tags[Index].Value;
463 };
464 }
465 }
466 }
467 //
468 // We didn't find a value that matched a setting in the NVRAM Map - display default - set default
469 //
470 if (Default != 0) {
471 //
472 // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
473 //
474 CopyMem (NvRamMap, &Value, MenuOption->ThisTag->StorageWidth);
475
476 StringPtr = GetToken ((UINT16) Default, MenuOption->Handle);
477 NewStrCat (OptionString[0], StringPtr);
478 Character[0] = RIGHT_ONEOF_DELIMITER;
479 NewStrCat (OptionString[0], Character);
480 //
481 // Remove Buffer allocated for StringPtr after it has been used.
482 //
483 FreePool (StringPtr);
484 }
485 }
486 break;
487
488 case EFI_IFR_CHECKBOX_OP:
489 //
490 // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
491 // created entry which has an expanded NvMap requirement. We won't save this information - but we need to adjust
492 // the NvMap so that we can properly display the information
493 //
494 if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
495 AdjustNvMap (FileFormTags, MenuOption);
496 NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
497 }
498
499 Default = Tag->Flags & 1;
500 //
501 // If hit spacebar, set or unset Tag[TagIndex].Flags based on it's previous value - BOOLEAN
502 //
503 *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);
504 ASSERT (*OptionString);
505
506 //
507 // Since Checkboxes are BOOLEAN values, bit 0 of the Flags bit defines the default option, therefore, if
508 // the default option (only one option for checkboxes) is on, then the default value is on. Tag.Default is not
509 // an active field for Checkboxes.
510 //
511 StrnCpy (OptionString[0], (CHAR16 *) LEFT_CHECKBOX_DELIMITER, 1);
512
513 //
514 // Since this is a BOOLEAN operation, flip bit 0 upon selection
515 //
516 if (Selected) {
517 Tag->Value = (UINT16) (Tag->Value ^ 1);
518 *(UINT8 *) NvRamMap = (UINT8) (Tag->Value & 1);
519 UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);
520 }
521
522 if ((*(UINT8 *) NvRamMap & 1) == 0x01) {
523 NewStrCat (OptionString[0], (CHAR16 *) CHECK_ON);
524 //
525 // If someone reset default variables - we may need to reload from our NvMapping....
526 //
527 Tag->Value = *(UINT8 *) NvRamMap;
528 } else {
529 //
530 // If someone reset default variables - we may need to reload from our NvMapping....
531 //
532 NewStrCat (OptionString[0], (CHAR16 *) CHECK_OFF);
533 Tag->Value = *(UINT8 *) NvRamMap;
534 }
535
536 NewStrCat (OptionString[0], (CHAR16 *) RIGHT_CHECKBOX_DELIMITER);
537 NewStrCat (OptionString[0], StringPtr);
538 break;
539
540 case EFI_IFR_NUMERIC_OP:
541 //
542 // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
543 // created entry which has an expanded NvMap requirement. We won't save this information - but we need to adjust
544 // the NvMap so that we can properly display the information
545 //
546 if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
547 AdjustNvMap (FileFormTags, MenuOption);
548 NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
549 }
550
551 *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);
552 ASSERT (*OptionString);
553
554 //
555 // Add left delimeter to string
556 //
557 *OptionString[0] = LEFT_NUMERIC_DELIMITER;
558
559 //
560 // Retrieve the current numeric value
561 //
562 if (Selected) {
563 //
564 // Go ask for input
565 //
566 if (Tag->Step == 0) {
567 //
568 // Manual Input
569 //
570 Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, REGULAR_NUMERIC, &Number);
571 if (!EFI_ERROR (Status)) {
572 CopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);
573 UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);
574
575 //
576 // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
577 //
578 CopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);
579 } else {
580 return EFI_SUCCESS;
581 }
582 } else {
583 //
584 // Auto selection from list
585 //
586 if ((((Tag->StorageWidth == 1) && (UINT8) (*NvRamMap) > Tag->Maximum) || ((UINT8) (*NvRamMap) < Tag->Minimum)) ||
587 (((Tag->StorageWidth == 2) && *NvRamMap > Tag->Maximum) || (*NvRamMap < Tag->Minimum))
588 ) {
589 //
590 // Seed Number with valid value if currently invalid
591 //
592 Number = Tag->Default;
593 } else {
594 if (Tag->StorageWidth == 1) {
595 Number = (UINT8) (*NvRamMap);
596 } else {
597 Number = *NvRamMap;
598 }
599 }
600
601 Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, REGULAR_NUMERIC, &Number);
602 if (!EFI_ERROR (Status)) {
603 CopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);
604 UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);
605
606 //
607 // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
608 //
609 CopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);
610 } else {
611 return EFI_SUCCESS;
612 }
613 }
614 } else {
615 if (((Tag->StorageWidth == 1) && (UINT8) (*NvRamMap) <= Tag->Maximum && (UINT8) (*NvRamMap) >= Tag->Minimum) ||
616 ((Tag->StorageWidth == 2) && *NvRamMap <= Tag->Maximum && *NvRamMap >= Tag->Minimum)
617 ) {
618 if (Tag->StorageWidth == 1) {
619 Number = (UINT8) (*NvRamMap);
620 } else {
621 Number = *NvRamMap;
622 }
623 UnicodeValueToString (
624 FormattedNumber,
625 FALSE,
626 (UINTN) Number,
627 (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))
628 );
629 Number = (UINT16) GetStringWidth (FormattedNumber);
630 StrnCpy (OptionString[0] + 1, FormattedNumber, Number);
631 } else {
632 //
633 // If *NvRamMap isn't within parameters, set it to within parameters
634 //
635 //
636 // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
637 //
638 CopyMem (NvRamMap, &Tag->Default, MenuOption->ThisTag->StorageWidth);
639 Number = Tag->Default;
640
641 UnicodeValueToString (
642 FormattedNumber,
643 FALSE,
644 (UINTN) Number,
645 (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))
646 );
647 Number = (UINT16) GetStringWidth (FormattedNumber);
648 StrnCpy (OptionString[0] + 1, FormattedNumber, Number);
649 }
650
651 *(OptionString[0] + Number / 2) = RIGHT_NUMERIC_DELIMITER;
652 NewStrCat (OptionString[0] + (Number / 2) + 1, StringPtr);
653 }
654 break;
655
656 case EFI_IFR_DATE_OP:
657 //
658 // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
659 // created entry which has an expanded NvMap requirement. We won't save this information - but we need to adjust
660 // the NvMap so that we can properly display the information
661 //
662 if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
663 AdjustNvMap (FileFormTags, MenuOption);
664 NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
665 }
666
667 Status = gRT->GetTime (&Time, NULL);
668 if (EFI_ERROR (Status)) {
669 return EFI_SUCCESS;
670 }
671 //
672 // This for loop advances Index till it points immediately after a date entry. We can then
673 // subtract MenuOption->TagIndex from Index and find out relative to the start of the Date
674 // structure which field we were in. For instance, if TagIndex was 52, and we advanced Index
675 // to 53 and found it to no longer point to a date operand, we were pointing to the last of 3
676 // date operands.
677 //
678 //
679 // This has BUGBUG potential....fix this - if someone wants to ask two DATE questions in a row.....code
680 // against such silliness.
681 //
682 // Also, we want to internationalize the order of the date information. We need to code for it as well.
683 //
684 for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand == EFI_IFR_DATE_OP; Index++)
685 ;
686
687 //
688 // Count 0 = We entered on the first Date operand
689 // Count 1 = We entered on the second Date operand
690 // Count 2 = We entered on the third Date operand
691 //
692 Count = 3 - (Index - MenuOption->TagIndex);
693 if (Count > 2) {
694 return EFI_SUCCESS;
695 }
696 //
697 // This is similar to numerics, except for the following:
698 // We will under normal circumstances get 3 consecutive calls
699 // to process this opcodes data.
700 //
701 *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);
702 ASSERT (*OptionString);
703
704 switch (Count) {
705 case 0:
706 if (Selected) {
707 Number = (UINT16) Time.Month;
708
709 if (Tag->Step == 0) {
710 MenuOption->OptCol++;
711 Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, DATE_NUMERIC, &Number);
712 } else {
713 //
714 // Seed value with current setting
715 //
716 Tag->Value = (UINT16) Time.Month;
717 Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, DATE_NUMERIC, &Number);
718 }
719
720 if (!EFI_ERROR (Status)) {
721 Time.Month = (UINT8) Number;
722 gRT->SetTime (&Time);
723 }
724 }
725
726 VariableDefinition->FakeNvRamMap[Tag->Id] = Time.Month;
727 *OptionString[0] = LEFT_NUMERIC_DELIMITER;
728
729 UnicodeValueToString (
730 FormattedNumber,
731 FALSE,
732 (UINTN) Time.Month,
733 (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))
734 );
735 Number = (UINT16) GetStringWidth (FormattedNumber);
736
737 if (Number == 4) {
738 FormattedNumber[2] = FormattedNumber[1];
739 FormattedNumber[1] = FormattedNumber[0];
740 FormattedNumber[0] = L'0';
741 Number = 6;
742 }
743
744 StrnCpy (OptionString[0] + 1, FormattedNumber, Number);
745 *(OptionString[0] + Number / 2) = DATE_SEPARATOR;
746 StrCat (OptionString[0] + (Number / 2) + 1, StringPtr);
747 break;
748
749 case 1:
750 if (Selected) {
751 Number = (UINT16) Time.Day;
752
753 if (Tag->Step == 0) {
754 Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, DATE_NUMERIC, &Number);
755 } else {
756 //
757 // Seed value with current setting
758 //
759 Tag->Value = (UINT16) Time.Day;
760 Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, DATE_NUMERIC, &Number);
761 }
762
763 if (!EFI_ERROR (Status)) {
764 Time.Day = (UINT8) Number;
765 gRT->SetTime (&Time);
766 }
767 }
768
769 VariableDefinition->FakeNvRamMap[Tag->Id] = Time.Day;
770 SetUnicodeMem (OptionString[0], 4, L' ');
771
772 UnicodeValueToString (
773 FormattedNumber,
774 FALSE,
775 (UINTN) Time.Day,
776 (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))
777 );
778 Number = (UINT16) GetStringWidth (FormattedNumber);
779 if (Number == 4) {
780 FormattedNumber[2] = FormattedNumber[1];
781 FormattedNumber[1] = FormattedNumber[0];
782 FormattedNumber[0] = L'0';
783 Number = 6;
784 }
785
786 StrnCpy (OptionString[0] + 4, FormattedNumber, Number);
787 *(OptionString[0] + Number / 2 + 3) = DATE_SEPARATOR;
788 StrCat (OptionString[0] + (Number / 2) + 4, StringPtr);
789 break;
790
791 case 2:
792 if (Selected) {
793 Number = (UINT16) Time.Year;
794
795 if (Tag->Step == 0) {
796 Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, DATE_NUMERIC, &Number);
797 } else {
798 //
799 // Seed value with current setting
800 //
801 Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, DATE_NUMERIC, &Number);
802 }
803
804 if (!EFI_ERROR (Status)) {
805 Time.Year = (UINT16) Number;
806 gRT->SetTime (&Time);
807 }
808 }
809
810 Tag->Value = (UINT16) Time.Year;
811 VariableDefinition->FakeNvRamMap[Tag->Id] = (UINT8) Tag->Value;
812 VariableDefinition->FakeNvRamMap[Tag->Id + 1] = (UINT8) (Tag->Value >> 8);
813 SetUnicodeMem (OptionString[0], 7, L' ');
814 UnicodeValueToString (
815 FormattedNumber,
816 FALSE,
817 (UINTN) Time.Year,
818 (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))
819 );
820 Number = (UINT16) GetStringWidth (FormattedNumber);
821 StrnCpy (OptionString[0] + 7, FormattedNumber, Number);
822 *(OptionString[0] + Number / 2 + 6) = RIGHT_NUMERIC_DELIMITER;
823 StrCat (OptionString[0] + (Number / 2) + 7, StringPtr);
824 break;
825 }
826
827 break;
828
829 //
830 // BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG
831 // We need to add code to support the NVRam storage version of Date - this is the 1% case where someone
832 // might want to set an alarm and actually preserve the data in NVRam so a driver can pick up the instruction
833 // BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG
834 //
835 case EFI_IFR_TIME_OP:
836 //
837 // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
838 // created entry which has an expanded NvMap requirement. We won't save this information - but we need to adjust
839 // the NvMap so that we can properly display the information
840 //
841 if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
842 AdjustNvMap (FileFormTags, MenuOption);
843 NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
844 }
845
846 Status = gRT->GetTime (&Time, NULL);
847 if (EFI_ERROR (Status)) {
848 return EFI_SUCCESS;
849 }
850 //
851 // This is similar to numerics, except for the following:
852 // We will under normal circumstances get 3 consecutive calls
853 // to process this opcodes data.
854 //
855 *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);
856 ASSERT (*OptionString);
857
858 //
859 // This for loop advances Index till it points immediately after a date entry. We can then
860 // subtract MenuOption->TagIndex from Index and find out relative to the start of the Date
861 // structure which field we were in. For instance, if TagIndex was 52, and we advanced Index
862 // to 53 and found it to no longer point to a date operand, we were pointing to the last of 3
863 // date operands.
864 //
865 for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand == EFI_IFR_TIME_OP; Index++)
866 ;
867 //
868 // Count 0 = We entered on the first Date operand
869 // Count 1 = We entered on the second Date operand
870 // Count 2 = We entered on the third Date operand
871 //
872 Count = 3 - (Index - MenuOption->TagIndex);
873 if (Count > 2) {
874 return EFI_SUCCESS;
875 }
876
877 switch (Count) {
878 case 0:
879 Number = Time.Hour;
880 break;
881
882 case 1:
883 Number = Time.Minute;
884 break;
885
886 case 2:
887 Number = Time.Second;
888 }
889 //
890 // Retrieve the current numeric value
891 //
892 if (Selected) {
893 //
894 // Go ask for input
895 //
896 if (Tag->Step == 0) {
897 //
898 // Manual Input
899 //
900 Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, TIME_NUMERIC, &Number);
901 if (!EFI_ERROR (Status)) {
902 *NvRamMap = Number;
903 Time.Nanosecond = 0;
904 gRT->SetTime (&Time);
905 } else {
906 return EFI_SUCCESS;
907 }
908 } else {
909 //
910 // Auto selection from list
911 //
912 Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, TIME_NUMERIC, &Number);
913 if (!EFI_ERROR (Status)) {
914 *NvRamMap = Number;
915 } else {
916 return EFI_SUCCESS;
917 }
918 }
919
920 switch (Count) {
921 case 0:
922 Time.Hour = (UINT8) Number;
923 break;
924
925 case 1:
926 Time.Minute = (UINT8) Number;
927 break;
928
929 case 2:
930 Time.Second = (UINT8) Number;
931 }
932
933 Time.Nanosecond = 0;
934 gRT->SetTime (&Time);
935 } else {
936 switch (Count) {
937 case 0:
938 *OptionString[0] = LEFT_NUMERIC_DELIMITER;
939 UnicodeValueToString (
940 FormattedNumber,
941 FALSE,
942 (UINTN) Time.Hour,
943 (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))
944 );
945 Number = (UINT16) GetStringWidth (FormattedNumber);
946 if (Number == 4) {
947 FormattedNumber[2] = FormattedNumber[1];
948 FormattedNumber[1] = FormattedNumber[0];
949 FormattedNumber[0] = L'0';
950 Number = 6;
951 }
952
953 StrnCpy (OptionString[0] + 1, FormattedNumber, Number);
954 *(OptionString[0] + Number / 2) = TIME_SEPARATOR;
955 StrCat (OptionString[0] + (Number / 2) + 1, StringPtr);
956 break;
957
958 case 1:
959 SetUnicodeMem (OptionString[0], 4, L' ');
960 UnicodeValueToString (
961 FormattedNumber,
962 FALSE,
963 (UINTN) Time.Minute,
964 (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))
965 );
966 Number = (UINT16) GetStringWidth (FormattedNumber);
967 if (Number == 4) {
968 FormattedNumber[2] = FormattedNumber[1];
969 FormattedNumber[1] = FormattedNumber[0];
970 FormattedNumber[0] = L'0';
971 Number = 6;
972 }
973
974 StrnCpy (OptionString[0] + 4, FormattedNumber, Number);
975 *(OptionString[0] + Number / 2 + 3) = TIME_SEPARATOR;
976 StrCat (OptionString[0] + (Number / 2) + 4, StringPtr);
977 break;
978
979 case 2:
980 SetUnicodeMem (OptionString[0], 7, L' ');
981 UnicodeValueToString (
982 FormattedNumber,
983 FALSE,
984 (UINTN) Time.Second,
985 (sizeof (FormattedNumber) / sizeof (FormattedNumber[0]))
986 );
987 Number = (UINT16) GetStringWidth (FormattedNumber);
988 if (Number == 4) {
989 FormattedNumber[2] = FormattedNumber[1];
990 FormattedNumber[1] = FormattedNumber[0];
991 FormattedNumber[0] = L'0';
992 Number = 6;
993 }
994
995 StrnCpy (OptionString[0] + 7, FormattedNumber, Number);
996 *(OptionString[0] + Number / 2 + 6) = RIGHT_NUMERIC_DELIMITER;
997 StrCat (OptionString[0] + (Number / 2) + 7, StringPtr);
998 break;
999 }
1000 //
1001 // BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG
1002 // We need to add code to support the NVRam storage version of Date - this is the 1% case where someone
1003 // might want to set an alarm and actually preserve the data in NVRam so a driver can pick up the instruction
1004 // BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG BUGBUG
1005 //
1006 }
1007 break;
1008
1009 case EFI_IFR_STRING_OP:
1010 //
1011 // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
1012 // created entry which has an expanded NvMap requirement. We won't save this information - but we need to adjust
1013 // the NvMap so that we can properly display the information
1014 //
1015 if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
1016 AdjustNvMap (FileFormTags, MenuOption);
1017 NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
1018 }
1019
1020 *OptionString = AllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);
1021 ASSERT (*OptionString);
1022
1023 if (Selected) {
1024 StringPtr = AllocateZeroPool (Tag->Maximum);
1025 ASSERT (StringPtr);
1026
1027 Status = ReadString (MenuOption, StringPtr);
1028
1029 if (!EFI_ERROR (Status)) {
1030 CopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);
1031 CopyMem (&VariableDefinition->NvRamMap[Tag->StorageStart], StringPtr, Tag->StorageWidth);
1032
1033 UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);
1034 }
1035
1036 FreePool (StringPtr);
1037 return Status;
1038 } else {
1039 for (Index = 0; Index < gOptionBlockWidth; Index++) {
1040 if (VariableDefinition->NvRamMap[Tag->StorageStart + (Index * 2)] != 0x0000) {
1041 CopyMem (OptionString[0] + Index, &VariableDefinition->NvRamMap[Tag->StorageStart + (Index * 2)], 2);
1042 } else {
1043 if (Index == 0) {
1044 *(OptionString[0] + Index) = '_';
1045 *(OptionString[0] + 1 + Index) = 0;
1046 }
1047 break;
1048 }
1049 }
1050
1051 return Status;
1052 }
1053
1054 case EFI_IFR_PASSWORD_OP:
1055 //
1056 // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
1057 // created entry which has an expanded NvMap requirement. We won't save this information - but we need to adjust
1058 // the NvMap so that we can properly display the information
1059 //
1060 if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
1061 AdjustNvMap (FileFormTags, MenuOption);
1062 NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
1063 }
1064
1065 if (Selected) {
1066 StringPtr = AllocateZeroPool (Tag->Maximum);
1067 ASSERT (StringPtr);
1068
1069 //
1070 // If interactive, read the password and do the appropriate callbacks in that routine.
1071 // Since interactive passwords assume to handle the password data in a separate variable
1072 // storage, we don't need to do more than what is below for password callbacks
1073 //
1074 if (Tag->Flags & EFI_IFR_FLAG_INTERACTIVE) {
1075 MenuOption->Tags[0].CallbackHandle = FileFormTags->FormTags.Tags[0].CallbackHandle;
1076 Status = ReadPassword (MenuOption, TRUE, Tag, PageData, FALSE, FileFormTags, StringPtr);
1077 ZeroMem (StringPtr, Tag->Maximum);
1078
1079 if (EFI_ERROR (Status)) {
1080 if (Status == EFI_NOT_READY) {
1081 FreePool (StringPtr);
1082 return EFI_SUCCESS;
1083 }
1084 }
1085
1086 Status = ReadPassword (MenuOption, TRUE, Tag, PageData, TRUE, FileFormTags, StringPtr);
1087 FreePool (StringPtr);
1088 return EFI_SUCCESS;
1089 }
1090
1091 for (Index = 0; Index < Tag->Maximum; Index++) {
1092 if (VariableDefinition->NvRamMap[Tag->StorageStart + Index] != 0x00) {
1093 //
1094 // There is something there! Prompt for password
1095 //
1096 Status = ReadPassword (MenuOption, TRUE, Tag, PageData, FALSE, FileFormTags, StringPtr);
1097 if (EFI_ERROR (Status)) {
1098 FreePool (StringPtr);
1099 return EFI_SUCCESS;
1100 }
1101
1102 if (Tag->Encoding == 1) {
1103 EncodePassword (StringPtr, (UINT8) Tag->Maximum);
1104 Status = CompareMem (StringPtr, &VariableDefinition->NvRamMap[Tag->StorageStart], Tag->Maximum);
1105 } else {
1106 Status = CompareMem (StringPtr, &VariableDefinition->NvRamMap[Tag->StorageStart], Tag->Maximum);
1107 }
1108
1109 if (Status != 0) {
1110 FreePool (StringPtr);
1111 return EFI_SUCCESS;
1112 } else {
1113 break;
1114 }
1115 }
1116 }
1117 //
1118 // Clean the string
1119 //
1120 ZeroMem (StringPtr, Tag->Maximum);
1121
1122 //
1123 // No password set! Go ahead and prompt the user for a password.
1124 //
1125 Status = ReadPassword (MenuOption, FALSE, Tag, PageData, FALSE, FileFormTags, StringPtr);
1126
1127 if (EFI_ERROR (Status)) {
1128 //
1129 // User couldn't figure out how to type two identical passwords
1130 //
1131 FreePool (StringPtr);
1132 return EFI_SUCCESS;
1133 }
1134 //
1135 // Very simple example of how one MIGHT do password encoding
1136 //
1137 if (Tag->Encoding == 1) {
1138 EncodePassword (StringPtr, (UINT8) Tag->Maximum);
1139 }
1140
1141 TmpNvRamMap = AllocatePool (VariableDefinition->VariableSize);
1142 ASSERT (TmpNvRamMap != NULL);
1143
1144 Count = VariableDefinition->VariableSize;
1145
1146 if ((FormCallback != NULL) && (FormCallback->NvRead != NULL)) {
1147 Status = FormCallback->NvRead (
1148 FormCallback,
1149 VariableDefinition->VariableName,
1150 &VariableDefinition->Guid,
1151 NULL,
1152 &Count,
1153 (VOID *) TmpNvRamMap
1154 );
1155 } else {
1156 Status = gRT->GetVariable (
1157 VariableDefinition->VariableName,
1158 &VariableDefinition->Guid,
1159 NULL,
1160 &Count,
1161 (VOID *) TmpNvRamMap
1162 );
1163 }
1164
1165 CopyMem (&VariableDefinition->NvRamMap[Tag->StorageStart], StringPtr, Tag->StorageWidth);
1166 CopyMem (&TmpNvRamMap[Tag->StorageStart], StringPtr, Tag->StorageWidth);
1167
1168 if ((FormCallback != NULL) && (FormCallback->NvWrite != NULL)) {
1169 Status = FormCallback->NvWrite (
1170 FormCallback,
1171 VariableDefinition->VariableName,
1172 &VariableDefinition->Guid,
1173 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1174 VariableDefinition->VariableSize,
1175 (VOID *) TmpNvRamMap,
1176 &gResetRequired
1177 );
1178 } else {
1179 Status = gRT->SetVariable (
1180 VariableDefinition->VariableName,
1181 &VariableDefinition->Guid,
1182 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1183 VariableDefinition->VariableSize,
1184 (VOID *) TmpNvRamMap
1185 );
1186 }
1187
1188 FreePool (TmpNvRamMap);
1189 FreePool (StringPtr);
1190 break;
1191 }
1192
1193 default:
1194 break;
1195 }
1196
1197 return EFI_SUCCESS;
1198 }
1199
1200 /**
1201 Split StringPtr to several lines of strings stored in FormattedString and the glyph width of
1202 each line cannot exceed gHelpBlockWidth.
1203
1204 @param StringPtr The pointer of string
1205 @param FormattedString The pointer of format string
1206 @param RowCount The count of row
1207
1208 **/
1209 VOID
1210 ProcessHelpString (
1211 IN CHAR16 *StringPtr,
1212 OUT CHAR16 **FormattedString,
1213 IN UINTN RowCount
1214 )
1215 {
1216 CONST UINTN BlockWidth = (UINTN) gHelpBlockWidth - 1;
1217 UINTN AllocateSize;
1218 //
1219 // [PrevCurrIndex, CurrIndex) forms a range of a screen-line
1220 //
1221 UINTN CurrIndex;
1222 UINTN PrevCurrIndex;
1223 UINTN LineCount;
1224 UINTN VirtualLineCount;
1225 //
1226 // GlyphOffset stores glyph width of current screen-line
1227 //
1228 UINTN GlyphOffset;
1229 //
1230 // GlyphWidth equals to 2 if we meet width directive
1231 //
1232 UINTN GlyphWidth;
1233 //
1234 // during scanning, we remember the position of last space character
1235 // in case that if next word cannot put in current line, we could restore back to the position
1236 // of last space character
1237 // while we should also remmeber the glyph width of the last space character for restoring
1238 //
1239 UINTN LastSpaceIndex;
1240 UINTN LastSpaceGlyphWidth;
1241 //
1242 // every time we begin to form a new screen-line, we should remember glyph width of single character
1243 // of last line
1244 //
1245 UINTN LineStartGlyphWidth;
1246 UINTN *IndexArray;
1247 UINTN *OldIndexArray;
1248
1249 //
1250 // every three elements of IndexArray form a screen-line of string:[ IndexArray[i*3], IndexArray[i*3+1] )
1251 // IndexArray[i*3+2] stores the initial glyph width of single character. to save this is because we want
1252 // to bring the width directive of the last line to current screen-line.
1253 // e.g.: "\wideabcde ... fghi", if "fghi" also has width directive but is splitted to the next screen-line
1254 // different from that of "\wideabcde", we should remember the width directive.
1255 //
1256 AllocateSize = 0x20;
1257 IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);
1258
1259 if (*FormattedString != NULL) {
1260 FreePool (*FormattedString);
1261 *FormattedString = NULL;
1262 }
1263
1264 for (PrevCurrIndex = 0, CurrIndex = 0, LineCount = 0, LastSpaceIndex = 0,
1265 IndexArray[0] = 0, GlyphWidth = 1, GlyphOffset = 0, LastSpaceGlyphWidth = 1, LineStartGlyphWidth = 1;
1266 (StringPtr[CurrIndex] != CHAR_NULL);
1267 CurrIndex ++) {
1268
1269 if (LineCount == AllocateSize) {
1270 AllocateSize += 0x10;
1271 OldIndexArray = IndexArray;
1272 IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);
1273 CopyMem (IndexArray, OldIndexArray, LineCount * sizeof (UINTN) * 3);
1274 if (OldIndexArray != NULL) {
1275 FreePool (OldIndexArray);
1276 }
1277 }
1278
1279 switch (StringPtr[CurrIndex]) {
1280
1281 case NARROW_CHAR:
1282 case WIDE_CHAR:
1283 GlyphWidth = ((StringPtr[CurrIndex] == WIDE_CHAR) ? 2 : 1);
1284 if (CurrIndex == 0) {
1285 LineStartGlyphWidth = GlyphWidth;
1286 }
1287 break;
1288
1289 //
1290 // char is '\n'
1291 // "\r\n" isn't handled here, handled by case CHAR_CARRIAGE_RETURN
1292 //
1293 case CHAR_LINEFEED:
1294 //
1295 // Store a range of string as a line
1296 //
1297 IndexArray[LineCount*3] = PrevCurrIndex;
1298 IndexArray[LineCount*3+1] = CurrIndex;
1299 IndexArray[LineCount*3+2] = LineStartGlyphWidth;
1300 LineCount ++;
1301 //
1302 // Reset offset and save begin position of line
1303 //
1304 GlyphOffset = 0;
1305 LineStartGlyphWidth = GlyphWidth;
1306 PrevCurrIndex = CurrIndex + 1;
1307 break;
1308
1309 //
1310 // char is '\r'
1311 // "\r\n" and "\r" both are handled here
1312 //
1313 case CHAR_CARRIAGE_RETURN:
1314 if (StringPtr[CurrIndex + 1] == CHAR_LINEFEED) {
1315 //
1316 // next char is '\n'
1317 //
1318 IndexArray[LineCount*3] = PrevCurrIndex;
1319 IndexArray[LineCount*3+1] = CurrIndex;
1320 IndexArray[LineCount*3+2] = LineStartGlyphWidth;
1321 LineCount ++;
1322 CurrIndex ++;
1323 }
1324 GlyphOffset = 0;
1325 LineStartGlyphWidth = GlyphWidth;
1326 PrevCurrIndex = CurrIndex + 1;
1327 break;
1328
1329 //
1330 // char is space or other char
1331 //
1332 default:
1333 GlyphOffset += GlyphWidth;
1334 if (GlyphOffset >= BlockWidth) {
1335 if (LastSpaceIndex > PrevCurrIndex) {
1336 //
1337 // LastSpaceIndex points to space inside current screen-line,
1338 // restore to LastSpaceIndex
1339 // (Otherwise the word is too long to fit one screen-line, just cut it)
1340 //
1341 CurrIndex = LastSpaceIndex;
1342 GlyphWidth = LastSpaceGlyphWidth;
1343 } else if (GlyphOffset > BlockWidth) {
1344 //
1345 // the word is too long to fit one screen-line and we don't get the chance
1346 // of GlyphOffset == BlockWidth because GlyphWidth = 2
1347 //
1348 CurrIndex --;
1349 }
1350
1351 IndexArray[LineCount*3] = PrevCurrIndex;
1352 IndexArray[LineCount*3+1] = CurrIndex + 1;
1353 IndexArray[LineCount*3+2] = LineStartGlyphWidth;
1354 LineStartGlyphWidth = GlyphWidth;
1355 LineCount ++;
1356 //
1357 // Reset offset and save begin position of line
1358 //
1359 GlyphOffset = 0;
1360 PrevCurrIndex = CurrIndex + 1;
1361 }
1362
1363 //
1364 // LastSpaceIndex: remember position of last space
1365 //
1366 if (StringPtr[CurrIndex] == CHAR_SPACE) {
1367 LastSpaceIndex = CurrIndex;
1368 LastSpaceGlyphWidth = GlyphWidth;
1369 }
1370 break;
1371 }
1372 }
1373
1374 if (GlyphOffset > 0) {
1375 IndexArray[LineCount*3] = PrevCurrIndex;
1376 IndexArray[LineCount*3+1] = CurrIndex;
1377 IndexArray[LineCount*3+2] = GlyphWidth;
1378 LineCount ++;
1379 }
1380
1381 if (LineCount == 0) {
1382 //
1383 // in case we meet null string
1384 //
1385 IndexArray[0] = 0;
1386 IndexArray[1] = 1;
1387 //
1388 // we assume null string's glyph width is 1
1389 //
1390 IndexArray[1] = 1;
1391 LineCount ++;
1392 }
1393
1394 VirtualLineCount = RowCount * (LineCount / RowCount + (LineCount % RowCount > 0));
1395 *FormattedString = AllocateZeroPool (VirtualLineCount * (BlockWidth + 1) * sizeof (CHAR16) * 2);
1396
1397 for (CurrIndex = 0; CurrIndex < LineCount; CurrIndex ++) {
1398 *(*FormattedString + CurrIndex * 2 * (BlockWidth + 1)) = (CHAR16)((IndexArray[CurrIndex*3+2] == 2) ? WIDE_CHAR : NARROW_CHAR);
1399 StrnCpy (
1400 *FormattedString + CurrIndex * 2 * (BlockWidth + 1) + 1,
1401 StringPtr + IndexArray[CurrIndex*3],
1402 IndexArray[CurrIndex*3+1]-IndexArray[CurrIndex*3]
1403 );
1404 }
1405
1406 if (IndexArray != NULL) {
1407 FreePool (IndexArray);
1408 }
1409 }
1410
1411 VOID
1412 IfrToFormTag (
1413 IN UINT8 OpCode,
1414 IN EFI_TAG *TargetTag,
1415 IN VOID *FormData,
1416 EFI_VARIABLE_DEFINITION *VariableDefinitionsHead
1417 )
1418 {
1419 UINT16 TempValue;
1420 CHAR16 *VariableName;
1421 CHAR8 *AsciiString;
1422 EFI_VARIABLE_DEFINITION *VariableDefinitions;
1423 EFI_VARIABLE_DEFINITION *PreviousVariableDefinitions;
1424 STATIC UINT16 VariableSize;
1425 EFI_GUID Guid;
1426 STATIC UINT16 CurrentVariable;
1427 STATIC UINT16 CurrentVariable2;
1428 UINTN Index;
1429
1430 switch (OpCode) {
1431 case EFI_IFR_FORM_OP:
1432 CopyMem (&TargetTag->Id, &((EFI_IFR_FORM *) FormData)->FormId, sizeof (UINT16));
1433 CopyMem (&TargetTag->Text, &((EFI_IFR_FORM *) FormData)->FormTitle, sizeof (UINT16));
1434 TargetTag->VariableNumber = CurrentVariable;
1435 if (VariableDefinitionsHead != NULL) {
1436 VariableName = AllocateZeroPool (12);
1437 ASSERT (VariableName != NULL);
1438 CopyMem (VariableName, L"Setup", 12);
1439 VariableDefinitionsHead->VariableName = VariableName;
1440 VariableDefinitionsHead->VariableSize = VariableSize;
1441 CopyMem (&VariableDefinitionsHead->Guid, &Guid, sizeof (EFI_GUID));
1442 }
1443 break;
1444
1445 case EFI_IFR_SUBTITLE_OP:
1446 TargetTag->NumberOfLines = 1;
1447 CopyMem (&TargetTag->Text, &((EFI_IFR_SUBTITLE *) FormData)->SubTitle, sizeof (UINT16));
1448 TargetTag->VariableNumber = CurrentVariable;
1449 break;
1450
1451 case EFI_IFR_TEXT_OP:
1452 TargetTag->NumberOfLines = 1;
1453 CopyMem (&TargetTag->Text, &((EFI_IFR_TEXT *) FormData)->Text, sizeof (UINT16));
1454 CopyMem (&TargetTag->Help, &((EFI_IFR_TEXT *) FormData)->Help, sizeof (UINT16));
1455 TargetTag->VariableNumber = CurrentVariable;
1456
1457 //
1458 // To optimize the encoding size, certain opcodes have optional fields such as those
1459 // inside the if() statement. If the encoded length is the complete size, then we
1460 // know we have valid data encoded that we want to integrate
1461 //
1462 if (((EFI_IFR_TEXT *) FormData)->Header.Length == sizeof (EFI_IFR_TEXT)) {
1463 //
1464 // Text has no help associated with it, but in case there is a second entry due to
1465 // dynamic/interactive flags being active, bring this data over.
1466 //
1467 CopyMem (&TargetTag->TextTwo, &((EFI_IFR_TEXT *) FormData)->TextTwo, sizeof (UINT16));
1468 TargetTag->Flags = ((EFI_IFR_TEXT *) FormData)->Flags;
1469 CopyMem (&TargetTag->Key, &((EFI_IFR_TEXT *) FormData)->Key, sizeof (UINT16));
1470 }
1471 break;
1472
1473 case EFI_IFR_ONE_OF_OPTION_OP:
1474 CopyMem (&TargetTag->Text, &((EFI_IFR_ONE_OF_OPTION *) FormData)->Option, sizeof (UINT16));
1475 CopyMem (&TargetTag->Value, &((EFI_IFR_ONE_OF_OPTION *) FormData)->Value, sizeof (UINT16));
1476 TargetTag->Flags = ((EFI_IFR_ONE_OF_OPTION *) FormData)->Flags;
1477 CopyMem (&TargetTag->Key, &((EFI_IFR_ONE_OF_OPTION *) FormData)->Key, sizeof (UINT16));
1478 TargetTag->VariableNumber = CurrentVariable;
1479 break;
1480
1481 case EFI_IFR_CHECKBOX_OP:
1482 TargetTag->Flags = ((EFI_IFR_CHECKBOX *) FormData)->Flags;
1483 TargetTag->ResetRequired = (BOOLEAN) (TargetTag->Flags & EFI_IFR_FLAG_RESET_REQUIRED);
1484 CopyMem (&TargetTag->Key, &((EFI_IFR_CHECKBOX *) FormData)->Key, sizeof (UINT16));
1485 TargetTag->VariableNumber = CurrentVariable;
1486 break;
1487
1488 case EFI_IFR_NUMERIC_OP:
1489 TargetTag->Flags = ((EFI_IFR_NUMERIC *) FormData)->Flags;
1490 CopyMem (&TargetTag->Key, &((EFI_IFR_NUMERIC *) FormData)->Key, sizeof (UINT16));
1491 TargetTag->VariableNumber = CurrentVariable;
1492 break;
1493
1494 case EFI_IFR_STRING_OP:
1495 //
1496 // Convert EFI_IFR_STRING.MinSize and EFI_IFR_STRING.MaxSize to actual minimum and maximum bytes
1497 // and store to EFI_TAG.Minimum and EFI_TAG.Maximum
1498 //
1499 TempValue = 0;
1500 CopyMem (&TempValue, &((EFI_IFR_STRING *) FormData)->MinSize, sizeof (UINT8));
1501 TempValue = (UINT16) (TempValue * 2);
1502 CopyMem (&TargetTag->Minimum, &TempValue, sizeof (UINT16));
1503
1504 TempValue = 0;
1505 CopyMem (&TempValue, &((EFI_IFR_STRING *) FormData)->MaxSize, sizeof (UINT8));
1506 TempValue = (UINT16) (TempValue * 2);
1507 CopyMem (&TargetTag->Maximum, &TempValue, sizeof (UINT16));
1508 CopyMem (&TargetTag->StorageWidth, &TempValue, sizeof (UINT16));
1509 TargetTag->Flags = (UINT8) (((EFI_IFR_STRING *) FormData)->Flags);
1510 TargetTag->ResetRequired = (BOOLEAN) (TargetTag->Flags & EFI_IFR_FLAG_RESET_REQUIRED);
1511 CopyMem (&TargetTag->Key, &((EFI_IFR_STRING *) FormData)->Key, sizeof (UINT16));
1512 TargetTag->VariableNumber = CurrentVariable;
1513 break;
1514
1515 case EFI_IFR_PASSWORD_OP:
1516 TempValue = 0;
1517 CopyMem (&TempValue, &((EFI_IFR_PASSWORD *) FormData)->MinSize, sizeof (UINT8));
1518 TempValue = (UINT16) (TempValue * 2);
1519 CopyMem (&TargetTag->Minimum, &TempValue, sizeof (UINT16));
1520
1521 TempValue = 0;
1522 CopyMem (&TempValue, &((EFI_IFR_PASSWORD *) FormData)->MaxSize, sizeof (UINT8));
1523 TempValue = (UINT16) (TempValue * 2);
1524 CopyMem (&TargetTag->Maximum, &TempValue, sizeof (UINT16));
1525 CopyMem (&TargetTag->StorageWidth, &TempValue, sizeof (UINT16));
1526 TargetTag->Flags = ((EFI_IFR_PASSWORD *) FormData)->Flags;
1527 TargetTag->ResetRequired = (BOOLEAN) (TargetTag->Flags & EFI_IFR_FLAG_RESET_REQUIRED);
1528 CopyMem (&TargetTag->Key, &((EFI_IFR_PASSWORD *) FormData)->Key, sizeof (UINT16));
1529 CopyMem (&TargetTag->Encoding, &((EFI_IFR_PASSWORD *) FormData)->Encoding, sizeof (UINT16));
1530 TargetTag->VariableNumber = CurrentVariable;
1531 break;
1532
1533 case EFI_IFR_VARSTORE_OP:
1534 //
1535 // It should NEVER be NULL
1536 //
1537 if (VariableDefinitionsHead == NULL) {
1538 break;
1539 }
1540
1541 VariableDefinitions = VariableDefinitionsHead;
1542
1543 //
1544 // Advance VariableDefinitions to the last entry
1545 //
1546 for (; VariableDefinitions != NULL; VariableDefinitions = VariableDefinitions->Next) {
1547 PreviousVariableDefinitions = VariableDefinitions;
1548 //
1549 // If there is a variable with this GUID and ID already, we need to bail out
1550 //
1551 if (!CompareMem (&VariableDefinitions->Guid, &((EFI_IFR_VARSTORE *) FormData)->Guid, sizeof (EFI_GUID)) &&
1552 !CompareMem (&VariableDefinitions->VariableId, &((EFI_IFR_VARSTORE *) FormData)->VarId, sizeof (UINT16))
1553 ) {
1554 return ;
1555 }
1556
1557 if (VariableDefinitions->Next == NULL) {
1558 break;
1559 }
1560 }
1561 //
1562 // If the last entry has a variable in it already, allocate a new entry and use it
1563 //
1564 if (VariableDefinitions->VariableName != NULL) {
1565 VariableDefinitions->Next = AllocateZeroPool (sizeof (EFI_VARIABLE_DEFINITION));
1566 ASSERT (VariableDefinitions->Next != NULL);
1567 PreviousVariableDefinitions = VariableDefinitions;
1568 VariableDefinitions = VariableDefinitions->Next;
1569 VariableDefinitions->Previous = PreviousVariableDefinitions;
1570 }
1571 //
1572 // Copy the Variable data to our linked list
1573 //
1574 CopyMem (&VariableDefinitions->VariableId, &((EFI_IFR_VARSTORE *) FormData)->VarId, sizeof (UINT16));
1575 CopyMem (&VariableDefinitions->VariableSize, &((EFI_IFR_VARSTORE *) FormData)->Size, sizeof (UINT16));
1576 CopyMem (&VariableDefinitions->Guid, &((EFI_IFR_VARSTORE *) FormData)->Guid, sizeof (EFI_GUID));
1577
1578 //
1579 // The ASCII String which is immediately past the EFI_IFR_VARSTORE is inferred by the structure definition
1580 // due to it being variable sized. There are rules preventing it from being > 40 characters long and should
1581 // be enforced by the compiler.
1582 //
1583 AsciiString = (CHAR8 *) (&((EFI_IFR_VARSTORE *) FormData)->Size);
1584 AsciiString = AsciiString + 2;
1585 VariableDefinitions->VariableName = AllocateZeroPool ((AsciiStrLen (AsciiString) + 1) * 2);
1586 ASSERT (VariableDefinitions->VariableName != NULL);
1587 for (Index = 0; AsciiString[Index] != 0; Index++) {
1588 VariableDefinitions->VariableName[Index] = (CHAR16) AsciiString[Index];
1589 }
1590
1591 VariableDefinitions->VariableName[Index] = 0;
1592
1593 //
1594 // Propogate the tag information for this op-code
1595 //
1596 CopyMem (&TargetTag->VariableNumber, &((EFI_IFR_VARSTORE *) FormData)->VarId, sizeof (UINT16));
1597 CopyMem (&TargetTag->GuidValue, &((EFI_IFR_VARSTORE *) FormData)->Guid, sizeof (EFI_GUID));
1598 CopyMem (&TargetTag->StorageWidth, &((EFI_IFR_VARSTORE *) FormData)->Size, sizeof (UINT16));
1599 CopyMem (&TargetTag->Maximum, &((EFI_IFR_VARSTORE *) FormData)->Size, sizeof (UINT16));
1600 break;
1601
1602 case EFI_IFR_VARSTORE_SELECT_OP:
1603 CopyMem (&TargetTag->VariableNumber, &((EFI_IFR_VARSTORE_SELECT *) FormData)->VarId, sizeof (UINT16));
1604 CopyMem (&CurrentVariable, &((EFI_IFR_VARSTORE_SELECT *) FormData)->VarId, sizeof (UINT16));
1605 CurrentVariable2 = CurrentVariable;
1606 break;
1607
1608 case EFI_IFR_VARSTORE_SELECT_PAIR_OP:
1609 CopyMem (&TargetTag->VariableNumber, &((EFI_IFR_VARSTORE_SELECT_PAIR *) FormData)->VarId, sizeof (UINT16));
1610 CopyMem (
1611 &TargetTag->VariableNumber2,
1612 &((EFI_IFR_VARSTORE_SELECT_PAIR *) FormData)->SecondaryVarId,
1613 sizeof (UINT16)
1614 );
1615 CopyMem (&CurrentVariable, &((EFI_IFR_VARSTORE_SELECT_PAIR *) FormData)->VarId, sizeof (UINT16));
1616 CopyMem (&CurrentVariable2, &((EFI_IFR_VARSTORE_SELECT_PAIR *) FormData)->SecondaryVarId, sizeof (UINT16));
1617 break;
1618
1619 case EFI_IFR_REF_OP:
1620 TargetTag->NumberOfLines = 1;
1621 CopyMem (&TargetTag->Id, &((EFI_IFR_REF *) FormData)->FormId, sizeof (UINT16));
1622 CopyMem (&TargetTag->Key, &((EFI_IFR_REF *) FormData)->Key, sizeof (UINT16));
1623 CopyMem (&TargetTag->Text, &((EFI_IFR_REF *) FormData)->Prompt, sizeof (UINT16));
1624 CopyMem (&TargetTag->Help, &((EFI_IFR_REF *) FormData)->Help, sizeof (UINT16));
1625 TargetTag->Flags = ((EFI_IFR_REF *) FormData)->Flags;
1626 TargetTag->VariableNumber = CurrentVariable;
1627 break;
1628
1629 case EFI_IFR_EQ_ID_VAL_OP:
1630 CopyMem (&TargetTag->Value, &((EFI_IFR_EQ_ID_VAL *) FormData)->Value, sizeof (UINT16));
1631 CopyMem (&TargetTag->Id, &((EFI_IFR_EQ_ID_VAL *) FormData)->QuestionId, sizeof (UINT16));
1632 TargetTag->StorageWidth = ((EFI_IFR_EQ_ID_VAL *) FormData)->Width;
1633 TargetTag->VariableNumber = CurrentVariable;
1634 break;
1635
1636 case EFI_IFR_EQ_VAR_VAL_OP:
1637 CopyMem (&TargetTag->Value, &((EFI_IFR_EQ_VAR_VAL *) FormData)->Value, sizeof (UINT16));
1638 CopyMem (&TargetTag->Id, &((EFI_IFR_EQ_VAR_VAL *) FormData)->VariableId, sizeof (UINT16));
1639 TargetTag->VariableNumber = CurrentVariable;
1640 break;
1641
1642 case EFI_IFR_EQ_ID_ID_OP:
1643 CopyMem (&TargetTag->Id, &((EFI_IFR_EQ_ID_ID *) FormData)->QuestionId1, sizeof (UINT16));
1644 CopyMem (&TargetTag->Id2, &((EFI_IFR_EQ_ID_ID *) FormData)->QuestionId2, sizeof (UINT16));
1645 TargetTag->StorageWidth = ((EFI_IFR_EQ_ID_ID *) FormData)->Width;
1646 TargetTag->VariableNumber = CurrentVariable;
1647 TargetTag->VariableNumber = CurrentVariable2;
1648 break;
1649
1650 case EFI_IFR_EQ_ID_LIST_OP:
1651 CopyMem (&TargetTag->Id, &((EFI_IFR_EQ_ID_LIST *) FormData)->QuestionId, sizeof (UINT16));
1652 CopyMem (&TargetTag->Id2, &((EFI_IFR_EQ_ID_LIST *) FormData)->ListLength, sizeof (UINT16));
1653 TargetTag->StorageWidth = ((EFI_IFR_EQ_ID_LIST *) FormData)->Width;
1654
1655 TargetTag->IntList = AllocateZeroPool (TargetTag->Id2 * sizeof (UINT16));
1656 ASSERT (TargetTag->IntList);
1657
1658 for (TempValue = 0; TempValue < TargetTag->Id2; TempValue++) {
1659 CopyMem (
1660 &TargetTag->IntList[TempValue],
1661 &((EFI_IFR_EQ_ID_LIST *) FormData)->ValueList[TempValue],
1662 sizeof (UINT16)
1663 );
1664 }
1665
1666 TargetTag->VariableNumber = CurrentVariable;
1667 break;
1668
1669 case EFI_IFR_FORM_SET_OP:
1670 CopyMem (&VariableSize, &((EFI_IFR_FORM_SET *) FormData)->NvDataSize, sizeof (UINT16));
1671 CopyMem (&Guid, &((EFI_IFR_FORM_SET *) FormData)->Guid, sizeof (EFI_GUID));
1672 //
1673 // If there is a size specified in the formste, we will establish a "default" variable
1674 //
1675 if (VariableDefinitionsHead != NULL) {
1676 VariableName = AllocateZeroPool (12);
1677 ASSERT (VariableName != NULL);
1678 CopyMem (VariableName, L"Setup", 12);
1679 VariableDefinitionsHead->VariableName = VariableName;
1680 VariableDefinitionsHead->VariableSize = VariableSize;
1681 CopyMem (&VariableDefinitionsHead->Guid, &Guid, sizeof (EFI_GUID));
1682 }
1683 break;
1684
1685 case EFI_IFR_END_FORM_SET_OP:
1686 CurrentVariable = 0;
1687 CurrentVariable2 = 0;
1688 break;
1689 }
1690
1691 return ;
1692 }