File: main.c

package info (click to toggle)
edk2 0~20131112.2590861a-3
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 125,836 kB
  • ctags: 175,818
  • sloc: ansic: 1,274,042; python: 75,968; asm: 68,082; perl: 22,386; cpp: 22,278; makefile: 14,914; sh: 4,113; pascal: 1,126; xml: 318; lisp: 24
file content (291 lines) | stat: -rw-r--r-- 6,616 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*++

Copyright (c) 2005 - 2007, Intel Corporation                                                  
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution. The full text of the license may be found at         
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:
  main.c

Abstract:
     

--*/

#include "EfiShellLib.h"
#include "editor.h"

extern UINT8  STRING_ARRAY_NAME[];

EFI_STATUS
InitializeEFIEditor (
  IN EFI_HANDLE           ImageHandle,
  IN EFI_SYSTEM_TABLE     *SystemTable
  );

EFI_BOOTSHELL_CODE(
  EFI_DRIVER_ENTRY_POINT (InitializeEFIEditor)
)
//
// Global Variables
//
EFI_HII_HANDLE    gEditHiiHandle;
#if (EFI_SPECIFICATION_VERSION < 0x0002000A)
EFI_HII_PROTOCOL  *Hii;
#endif
EFI_GUID          EfiEditGuid = EFI_EDIT_GUID;
SHELL_VAR_CHECK_ITEM    EditCheckList[] = {
  {
    L"-?",
    0x01,
    0,
    FlagTypeSingle
  },
  {
    L"-b",
    0x02,
    0,
    FlagTypeSingle
  },
  {
    NULL,
    0,
    0,
    (SHELL_VAR_CHECK_FLAG_TYPE) 0
  }
};



EFI_HANDLE        ImageHandleBackup;

//
// Name:
//    InitializeEFIEditor -- Entry point of editor
// In:
//    ImageHandle
//    SystemTable
// Out:
//    EFI_SUCCESS
//
EFI_STATUS
InitializeEFIEditor (
  IN EFI_HANDLE           ImageHandle,
  IN EFI_SYSTEM_TABLE     *SystemTable
  )
/*++

Routine Description:

  Command entry point

Arguments:

  ImageHandle - The image handle
  SystemTable - The system table

Returns:

  EFI_ABORTED - Aborted

--*/
{
  EFI_STATUS              Status;
  CHAR16                  *Buffer;
  UINT32                  Key;

  SHELL_VAR_CHECK_CODE    RetCode;
  CHAR16                  *Useful;
  SHELL_VAR_CHECK_PACKAGE ChkPck;

  Buffer                          = L"";
  ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE));

  //
  // backup this variable to transfer to FileBufferInit
  //
  ImageHandleBackup = ImageHandle;

  LibInitializeShellApplication (ImageHandle, SystemTable);

  //
  // Register our string package with HII and return the handle to it.
  // If previously registered we will simply receive the handle
  //
#if (EFI_SPECIFICATION_VERSION < 0x0002000A)
  //
  // There should only be one HII protocol
  //
  Status = LibLocateProtocol (&gEfiHiiProtocolGuid, (VOID**)&Hii);
  if (EFI_ERROR (Status) || NULL == Hii) {
    return EFI_ABORTED;
  }
#endif

  Status = LibInitializeStrings (&gEditHiiHandle, STRING_ARRAY_NAME, &EfiEditGuid);

  if (EFI_ERROR (Status)) {
    return Status;
  }

  RetCode = LibCheckVariables (SI, EditCheckList, &ChkPck, &Useful);
  if (VarCheckOk != RetCode) {
    switch (RetCode) {
    case VarCheckUnknown:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), gEditHiiHandle, L"edit", Useful);
      break;

    default:
      break;
    }

    Status = EFI_INVALID_PARAMETER;
    goto done;
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) {
    if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) {
      EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);
    }
  }
  //
  // Out put help.
  //
  if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) {
    if (ChkPck.ValueCount > 0 ||
        ChkPck.FlagCount > 2 ||
        (ChkPck.FlagCount == 2 && LibCheckVarGetFlag (&ChkPck, L"-b") == NULL)
        ) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), gEditHiiHandle, L"edit");
      Status = EFI_INVALID_PARAMETER;
    } else {
      PrintToken (STRING_TOKEN (STR_EDIT_VERBOSE_HELP), gEditHiiHandle);
      Status = EFI_SUCCESS;
    }

    goto done;
  }

  if (ChkPck.ValueCount > 1) {
    PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), gEditHiiHandle, L"edit");
    Status = EFI_INVALID_PARAMETER;
    goto done;
  }

  if (ChkPck.ValueCount == 1) {
    if (!IsValidFileName (ChkPck.VarList->VarStr)) {
      PrintToken (STRING_TOKEN (STR_EDIT_MAIN_INVALID_FILE_NAME), gEditHiiHandle);
      Status = EFI_INVALID_PARAMETER;
      goto done;
    }
  }

  if (SI->RedirArgc != 0) {
    PrintToken (STRING_TOKEN (STR_EDIT_NOREDIRECT), gEditHiiHandle);
    Status = EFI_INVALID_PARAMETER;
    goto done;
  }

  Status = MainEditorInit ();
  if (EFI_ERROR (Status)) {
    Out->ClearScreen (Out);
    Out->EnableCursor (Out, TRUE);
    PrintToken (STRING_TOKEN (STR_EDIT_MAIN_INIT_FAILED), gEditHiiHandle);
    goto done;
  }

  MainEditorBackup ();

  //
  // if editor launched with file named
  //
  if (ChkPck.ValueCount == 1) {

    FileBufferSetFileName (ChkPck.VarList->VarStr);
  }

  Status = FileBufferRead (&MainEditor.FileBuffer->FileName, FALSE);
  if (!EFI_ERROR (Status)) {
    MainEditorRefresh ();
    //
    // Set Key Filter, to be sure that the output will no pause
    //
    Key = SE2->GetKeyFilter ();
    SE2->SetKeyFilter (EFI_OUTPUT_SCROLL);

    Status = MainEditorKeyInput ();
    //
    // Set Key Filter to original value
    //
    SE2->SetKeyFilter (Key);

  }

  if (Status != EFI_OUT_OF_RESOURCES) {
    //
    // back up the status string
    //
    Buffer = PoolPrint (L"%s", MainEditor.StatusBar->StatusString);
  }

  MainEditorCleanup ();

  //
  // print editor exit code on screen
  //
  if (Status == EFI_SUCCESS) {
  } else if (Status == EFI_OUT_OF_RESOURCES) {
    PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_OUT_RESOURCE), gEditHiiHandle, L"edit");
  } else {
    if (Buffer != NULL) {
      if (StrCmp (Buffer, L"") != 0) {
        //
        // print out the status string
        //
        PrintToken (STRING_TOKEN (STR_EDIT_MAIN_BUFFER), gEditHiiHandle, Buffer);
      } else {
        PrintToken (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gEditHiiHandle);
      }
    } else {
      PrintToken (STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gEditHiiHandle);
    }
  }

  if (Status != EFI_OUT_OF_RESOURCES) {
    EditorFreePool (Buffer);
  }

done:
  LibCheckVarFreeVarList (&ChkPck);
  LibUnInitializeStrings ();
  return Status;

}

EFI_STATUS
InitializeEFIEditorGetLineHelp (
  OUT CHAR16              **Str
  )
/*++

Routine Description:

  Get this command's line help

Arguments:

  Str - The line help

Returns:

  EFI_SUCCESS   - Success

--*/
{
  return LibCmdGetStringByToken (STRING_ARRAY_NAME, &EfiEditGuid, STRING_TOKEN (STR_EDIT_LINE_HELP), Str);
}