EmbeddedPkg: Fix mispellings
[mirror_edk2.git] / EmbeddedPkg / Ebl / Script.c
1 /** @file
2 Script command allows the execution of commands from a text file
3
4 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 Module Name: EfiDevice.c
16
17 **/
18
19 #include "Ebl.h"
20
21
22 /**
23 Execute the passed in file like a series of commands. The ; can be used on
24 a single line to indicate multiple commands per line. The Ascii text file
25 can contain any number of lines. The following line termination forms are
26 supported:
27 LF : Unix, Mac OS X*, BeOS
28 CR+LF: MS-DOS*, Microsoft Windows*
29 CR : Commodore, Apple II, and really Mac OS
30 LF+CR: for simplicity and completeness
31
32 Argv[0] - "script"
33 Argv[1] - Device Name:path for the file to load
34
35 script fv1:\script.txt
36
37 @param Argc Number of command arguments in Argv
38 @param Argv Array of strings that represent the parsed command line.
39 Argv[0] is the command name
40
41 @return EFI_SUCCESS
42
43 **/
44 EFI_STATUS
45 EblScriptCmd (
46 IN UINTN Argc,
47 IN CHAR8 **Argv
48 )
49 {
50 EFI_STATUS Status;
51 EFI_OPEN_FILE *File;
52 VOID *Address;
53 UINTN Size;
54 CHAR8 *Ptr;
55 CHAR8 *ScanPtr;
56 UINTN CmdLineSize;
57
58
59
60 if (Argc < 2) {
61 // file name required
62 return EFI_SUCCESS;
63 }
64
65 File = EfiOpen (Argv[1], EFI_FILE_MODE_READ, 0);
66 if (File == NULL) {
67 AsciiPrint (" %a is not a valid path\n", Argv[1]);
68 return EFI_SUCCESS;
69 }
70
71 Status = EfiReadAllocatePool (File, &Address, &Size);
72 if (!EFI_ERROR (Status)) {
73 // Loop through each line in the text file
74 for (Ptr = (CHAR8 *)Address; (Ptr < (((CHAR8 *)Address) + Size)) && !EFI_ERROR (Status); Ptr += CmdLineSize) {
75 for (CmdLineSize = 0, ScanPtr = Ptr; ; CmdLineSize++, ScanPtr++) {
76 // look for the end of the line
77 if ((*ScanPtr == EBL_CR) || (*ScanPtr == EBL_LF)) {
78 // convert to NULL as this is what input routine would do
79 *ScanPtr = 0;
80 if ((*(ScanPtr + 1) == EBL_CR) || (*(ScanPtr + 1) == EBL_LF)) {
81 // if its a set get the 2nd EOL char
82 CmdLineSize++;
83 *(ScanPtr + 1) = 0;
84 }
85 CmdLineSize++;
86 break;
87 }
88
89 }
90
91 Status = ProcessCmdLine (Ptr, CmdLineSize);
92 }
93
94 FreePool (Address);
95 }
96
97 EfiClose (File);
98 return Status;
99 }
100
101
102
103 GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mScriptTemplate[] = {
104 {
105 "script",
106 " device:path; load an ascii file and execute it like commands",
107 NULL,
108 EblScriptCmd
109 }
110 };
111
112
113 /**
114 Initialize the commands in this in this file
115 **/
116
117 VOID
118 EblInitializeScriptCmd (
119 VOID
120 )
121 {
122 if (FeaturePcdGet (PcdEmbeddedScriptCmd)) {
123 EblAddCommands (mScriptTemplate, sizeof (mScriptTemplate)/sizeof (EBL_COMMAND_TABLE));
124 }
125 }
126