From 4ba9b812daf1695bc5f6ac99504e53569297c2bf Mon Sep 17 00:00:00 2001 From: Tapan Shah Date: Fri, 29 Aug 2014 20:43:08 +0000 Subject: [PATCH] Register pre-defined command aliases in sorted order. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Tapan Shah Reviewed-By: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15999 6f19259b-4bc3-4df7-8a09-765794883524 --- .../UefiShellCommandLib/UefiShellCommandLib.c | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index 2984da9699..b3939ea4d6 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1,7 +1,7 @@ /** @file Provides interface to shell internal functions for shell commands. - (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P. + Copyright (c) 2013-2014, Hewlett-Packard Development Company, L.P.
Copyright (c) 2009 - 2014, 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 @@ -777,6 +777,9 @@ ShellCommandRegisterAlias ( ) { ALIAS_LIST *Node; + ALIAS_LIST *CommandAlias; + ALIAS_LIST *PrevCommandAlias; + INTN LexicalMatchValue; // // Asserts for NULL @@ -800,10 +803,37 @@ ShellCommandRegisterAlias ( StrCpy(Node->CommandString, Command); StrCpy(Node->Alias , Alias ); + InsertHeadList (&mAliasList.Link, &Node->Link); + // - // add the new struct to the list + // Move a new pre-defined registered alias to its sorted ordered location in the list // - InsertTailList (&mAliasList.Link, &Node->Link); + for ( CommandAlias = (ALIAS_LIST *)GetFirstNode (&mAliasList.Link), + PrevCommandAlias = (ALIAS_LIST *)GetFirstNode (&mAliasList.Link) + ; !IsNull (&mAliasList.Link, &CommandAlias->Link) + ; CommandAlias = (ALIAS_LIST *) GetNextNode (&mAliasList.Link, &CommandAlias->Link) ) { + // + // Get Lexical comparison value between PrevCommandAlias and CommandAlias List Entry + // + LexicalMatchValue = gUnicodeCollation->StriColl ( + gUnicodeCollation, + PrevCommandAlias->Alias, + CommandAlias->Alias + ); + + // + // Swap PrevCommandAlias and CommandAlias list entry if PrevCommandAlias list entry + // is alphabetically greater than CommandAlias list entry + // + if (LexicalMatchValue > 0) { + CommandAlias = (ALIAS_LIST *) SwapListEntries (&PrevCommandAlias->Link, &CommandAlias->Link); + } else if (LexicalMatchValue < 0) { + // + // PrevCommandAlias entry is lexically lower than CommandAlias entry + // + break; + } + } return (RETURN_SUCCESS); }