From 345cd2357af44872b2037f48ce63b05827cfa6c0 Mon Sep 17 00:00:00 2001 From: jcarsey Date: Fri, 25 Mar 2011 21:01:08 +0000 Subject: [PATCH] cls - add input verification. echo - add input verificaiton. help - prints out commands in sorted order. touch - add comments. type - add error when file not found. add comments. main lib files: add comments, clarify error messages. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11427 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/UefiShellLevel3CommandsLib/Cls.c | 8 ++--- .../Library/UefiShellLevel3CommandsLib/Echo.c | 28 +++++++++--------- .../Library/UefiShellLevel3CommandsLib/Help.c | 15 ++++++---- .../UefiShellLevel3CommandsLib/Touch.c | 21 ++++++++++++- .../Library/UefiShellLevel3CommandsLib/Type.c | 21 ++++++++++--- .../UefiShellLevel3CommandsLib.c | 10 ++++++- .../UefiShellLevel3CommandsLib.h | 7 ++++- .../UefiShellLevel3CommandsLib.uni | Bin 42206 -> 42494 bytes 8 files changed, 80 insertions(+), 30 deletions(-) diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c index 019aaf7231..dec24776ff 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c @@ -1,7 +1,7 @@ /** @file Main file for attrib shell level 2 function. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -83,11 +83,11 @@ ShellCommandRunCls ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (StrDecimalToUintn(Param1) > 7 || StrLen(Param1) > 1 || !ShellIsDecimalDigitCharacter(*Param1)) { + if (ShellStrToUintn(Param1) > 7 || StrLen(Param1) > 1 || !ShellIsDecimalDigitCharacter(*Param1)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, Param1); ShellStatus = SHELL_INVALID_PARAMETER; } else { - switch (StrDecimalToUintn(Param1)) { + switch (ShellStrToUintn(Param1)) { case 0: Background = EFI_BACKGROUND_BLACK; break; @@ -113,7 +113,7 @@ ShellCommandRunCls ( Background = EFI_BACKGROUND_LIGHTGRAY; break; } - ForeColor = (~StrDecimalToUintn(Param1)) & 0xF; + ForeColor = (~ShellStrToUintn(Param1)) & 0xF; Status = gST->ConOut->SetAttribute (gST->ConOut, ForeColor | Background); ASSERT_EFI_ERROR(Status); Status = gST->ConOut->ClearScreen (gST->ConOut); diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c index dc6bca0b8a..febfc000b3 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c @@ -1,7 +1,7 @@ /** @file Main file for Echo shell level 3 function. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -37,11 +37,11 @@ ShellCommandRunEcho ( { EFI_STATUS Status; LIST_ENTRY *Package; -// CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINTN ParamCount; + CHAR16 *ProblemParam; -// ProblemParam = NULL; + ProblemParam = NULL; ShellStatus = SHELL_SUCCESS; // @@ -53,16 +53,16 @@ ShellCommandRunEcho ( // // parse the command line // - Status = ShellCommandLineParseEx (ParamList, &Package, NULL, TRUE, TRUE); -// if (EFI_ERROR(Status)) { -// if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { -// ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam); -// FreePool(ProblemParam); -// ShellStatus = SHELL_INVALID_PARAMETER; -// } else { -// ASSERT(FALSE); -// } -// } else { + Status = ShellCommandLineParseEx (ParamList, &Package, &ProblemParam, TRUE, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { // // check for "-?" // @@ -109,7 +109,7 @@ ShellCommandRunEcho ( // free the command line package // ShellCommandLineFreeVarList (Package); -// } + } return (ShellStatus); } diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c index 04e3d31dba..1c643b0e57 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c @@ -1,7 +1,7 @@ /** @file Main file for Help shell level 3 function. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -18,7 +18,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { {L"-usage", TypeFlag}, - {L"-section", TypeValue}, + {L"-section", TypeMaxValue}, {L"-verbose", TypeFlag}, {L"-v", TypeFlag}, {NULL, TypeMax} @@ -133,19 +133,24 @@ ShellCommandRunHelp ( FreePool(HiiString); Found = TRUE; } else { - CommandList = ShellCommandGetCommandList(); + CommandList = ShellCommandGetCommandList(TRUE); ASSERT(CommandList != NULL); for ( Node = (COMMAND_LIST*)GetFirstNode(&CommandList->Link) ; CommandList != NULL && !IsListEmpty(&CommandList->Link) && !IsNull(&CommandList->Link, &Node->Link) ; Node = (COMMAND_LIST*)GetNextNode(&CommandList->Link, &Node->Link) ){ - if (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) { + if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) || + (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) { // // We have a command to look for help on. // Status = gEfiShellProtocol->GetHelpText(Node->CommandString, SectionToGetHelpOn, &OutText); if (EFI_ERROR(Status) || OutText == NULL) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString); + if (Status == EFI_DEVICE_ERROR) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, Node->CommandString); + } else { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString); + } ShellStatus = SHELL_NOT_FOUND; } else { while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') { diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c index 0252f7748d..7eb3c8c0e8 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c @@ -1,7 +1,7 @@ /** @file Main file for Touch shell level 3 function. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -16,6 +16,14 @@ #include +/** + Do the touch operation on a single handle. + + @param[in] Handle The handle to update the date/time on. + + @retval EFI_ACCESS_DENIED The file referenced by Handle is read only. + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS EFIAPI TouchFileByHandle ( @@ -40,6 +48,17 @@ TouchFileByHandle ( return (Status); } +/** + Touch a given file and potantially recurse down if it was a directory. + + @param[in] Name The name of this file. + @param[in] FS The name of the file system this file is on. + @param[in] Handle The handle of this file already opened. + @param[in] Rec TRUE to recurse if possible. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS EFIAPI DoTouchByHandle ( diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c index 05f13f0756..3e4ccb36e3 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c @@ -1,7 +1,7 @@ /** @file Main file for Type shell level 3 function. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -16,6 +16,18 @@ #include +/** + Display a single file to StdOut. + + If both Ascii and UCS2 are FALSE attempt to discover the file type. + + @param[in] Handle The handle to the file to display. + @param[in] Ascii TRUE to force ASCII, FALSE othewise. + @param[in] UCS2 TRUE to force UCS2, FALSE othewise. + + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS EFIAPI TypeFileByHandle ( @@ -31,7 +43,7 @@ TypeFileByHandle ( CHAR16 AsciiChar; ReadSize = PcdGet16(PcdShellFileOperationSize); - Buffer = AllocatePool(ReadSize); + Buffer = AllocateZeroPool(ReadSize); if (Buffer == NULL) { return (EFI_OUT_OF_RESOURCES); } @@ -47,7 +59,7 @@ TypeFileByHandle ( } if (!(Ascii|UCS2)){ - if (*(UINT16*)Buffer == UnicodeFileTag) { + if (*(UINT16*)Buffer == gUnicodeFileTag) { UCS2 = TRUE; Buffer = ((UINT16*)Buffer) + 1; } else { @@ -71,7 +83,7 @@ TypeFileByHandle ( Print(L"%s", Buffer); } } - Status = Print(L"\r\n", Buffer); + Print(L"\r\n", Buffer); return (Status); } @@ -161,6 +173,7 @@ ShellCommandRunType ( ){ Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ, &FileList); if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, (CHAR16*)Param); ShellStatus = SHELL_NOT_FOUND; break; } diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.c index 3ce39d7ea2..ef708cb17c 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.c +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.c @@ -1,7 +1,7 @@ /** @file Main file for NULL named library for level 3 shell command functions. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -20,6 +20,11 @@ STATIC CONST EFI_GUID gShellLevel3HiiGuid = \ 0x4344558d, 0x4ef9, 0x4725, { 0xb1, 0xe4, 0x33, 0x76, 0xe8, 0xd6, 0x97, 0x4f } \ }; +/** + return the filename to get help from is not using HII. + + @retval The filename. +**/ CONST CHAR16* EFIAPI ShellCommandGetManFileNameLevel3 ( @@ -79,6 +84,9 @@ ShellLevel3CommandsLibConstructor ( /** Destructor for the library. free any resources. + + @param ImageHandle The image handle of the process. + @param SystemTable The EFI System Table pointer. **/ EFI_STATUS EFIAPI diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.h b/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.h index b6ac99658d..6d19d9cc68 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.h +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.h @@ -1,7 +1,7 @@ /** @file header file for NULL named library for level 3 shell command functions. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -12,6 +12,9 @@ **/ +#if !defined (_UEFI_SHELL_LEVEL3_COMMANDS_LIB_H_) +#define _UEFI_SHELL_LEVEL3_COMMANDS_LIB_H_ + #include #include @@ -154,3 +157,5 @@ ShellCommandRunHelp ( IN EFI_SYSTEM_TABLE *SystemTable ); +#endif + diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.uni b/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.uni index ce5caf1249776fb7759487021e623176b123c9ea..723c25faf518dccebc2fa8559305372c32c23cd0 100644 GIT binary patch delta 270 zcmcb2lIh=RrU?Ozh8qJt*?E&0@)?SNFqI*hp=9z$U(v~0O#+i2@F+}v!9HoSm>=I{ zCN6``TR1G3c~clN8B!P&81jHxN;d!HHf0kAGl4>h3^_oU&rr^gI@wm};N&~G9Fs3Z zb4V65lmg972AW9$@N-Sx6(z*00JIw9&0LV&WJWH{ O$qK4mn{P<6bprsU21?KX delta 140 zcmex&n(5w2rU?Oz1{(uC**VJ?5*czBG8s}P3;K&r-ot)~9V#+8k>7Z-0Uz7uLmWoT zf@wfynLvf93@Ho>3?&Ttn;Cgb*|;+q@)%(1J%tW(BPpA#D3UyRf^Z(P*k(nMMpnkW O$%`cmH~)}g>jnVnttQq0