Register pre-defined command aliases in sorted order.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Tapan Shah <tapandshah@hp.com>
Reviewed-By: Jaben Carsey <jaben.carsey@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15999 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Tapan Shah 2014-08-29 20:43:08 +00:00 committed by jcarsey
parent 227a4b1c48
commit 4ba9b812da
1 changed files with 33 additions and 3 deletions

View File

@ -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.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
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);
}