From bbfd2ab18f52600aa41f061b2da9a2afe2a9d6ac Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre Date: Fri, 4 Aug 2017 12:10:50 -0400 Subject: Import Upstream version 0.9+1474479173.6c180c6 --- lib/shell.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/shell.c (limited to 'lib/shell.c') diff --git a/lib/shell.c b/lib/shell.c new file mode 100644 index 00000000..afd3952c --- /dev/null +++ b/lib/shell.c @@ -0,0 +1,57 @@ +/* + * Copyright 2012 + * + * see COPYING file + * + * misc shell helper functions + */ +#include +#include + +#include + +EFI_STATUS +argsplit(EFI_HANDLE image, int *argc, CHAR16*** ARGV) +{ + unsigned int i, count = 1; + EFI_STATUS status; + EFI_LOADED_IMAGE *info; + CHAR16 *start; + + *argc = 0; + + status = uefi_call_wrapper(BS->HandleProtocol, 3, image, &LoadedImageProtocol, (VOID **) &info); + if (EFI_ERROR(status)) { + Print(L"Failed to get arguments\n"); + return status; + } + + for (i = 0; i < info->LoadOptionsSize; i += 2) { + CHAR16 *c = (CHAR16 *)(info->LoadOptions + i); + if (*c == L' ' && *(c+1) != '\0') { + (*argc)++; + } + } + + (*argc)++; /* we counted spaces, so add one for initial */ + + *ARGV = AllocatePool(*argc * sizeof(**ARGV)); + if (!*ARGV) { + return EFI_OUT_OF_RESOURCES; + } + (*ARGV)[0] = (CHAR16 *)info->LoadOptions; + for (i = 0; i < info->LoadOptionsSize; i += 2) { + CHAR16 *c = (CHAR16 *)(info->LoadOptions + i); + if (*c == L' ') { + *c = L'\0'; + if (*(c + 1) == '\0') + /* strip trailing space */ + break; + start = c + 1; + (*ARGV)[count++] = start; + } + } + + return EFI_SUCCESS; +} + -- cgit v1.2.3