EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

ShellPkg/Application/Shell/ShellParametersProtocol.c

Go to the documentation of this file.
00001 
00016 #include "ShellParametersProtocol.h"
00017 #include "ConsoleWrappers.h"
00018 
00034 VOID
00035 EFIAPI
00036 GetNextParameter(
00037   CHAR16 **Walker,
00038   CHAR16 **TempParameter
00039   )
00040 {
00041   CHAR16 *NextDelim;
00042   CHAR16 *TempLoc;
00043 
00044   ASSERT(Walker           != NULL);
00045   ASSERT(*Walker          != NULL);
00046   ASSERT(TempParameter    != NULL);
00047   ASSERT(*TempParameter   != NULL);
00048 
00049   //
00050   // make sure we dont have any leading spaces
00051   //
00052   while ((*Walker)[0] == L' ') {
00053       (*Walker)++;
00054   }
00055 
00056   //
00057   // make sure we still have some params now...
00058   //
00059   if (StrLen(*Walker) == 0) {
00060     ASSERT((*Walker)[0] == CHAR_NULL);
00061     *Walker = NULL;
00062     return;
00063   }
00064 
00065   //
00066   // we have a quoted parameter
00067   // could be the last parameter, but SHOULD have a trailing quote
00068   //
00069   if ((*Walker)[0] == L'\"') {
00070     NextDelim = NULL;
00071     for (TempLoc = *Walker + 1 ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {
00072       if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') {
00073         TempLoc++;
00074       } else if (*TempLoc == L'\"') {
00075         NextDelim = TempLoc;
00076         break;
00077       }
00078     }
00079 
00080     if (NextDelim - ((*Walker)+1) == 0) {
00081       //
00082       // found ""
00083       //
00084       StrCpy(*TempParameter, L"");
00085       *Walker = NextDelim + 1;
00086     } else if (NextDelim != NULL) {
00087       StrnCpy(*TempParameter, (*Walker)+1, NextDelim - ((*Walker)+1));
00088       *Walker = NextDelim + 1;
00089     } else {
00090       //
00091       // last one... someone forgot the training quote!
00092       //
00093       StrCpy(*TempParameter, *Walker);
00094       *Walker = NULL;
00095     }
00096     for (TempLoc = *TempParameter ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {
00097       if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') {
00098         CopyMem(TempLoc, TempLoc+1, StrSize(TempLoc) - sizeof(TempLoc[0]));
00099       }
00100     }
00101   } else {
00102     //
00103     // we have a regular parameter (no quote) OR
00104     // we have the final parameter (no trailing space)
00105     //
00106     NextDelim = StrStr((*Walker), L" ");
00107     if (NextDelim != NULL) {
00108       StrnCpy(*TempParameter, *Walker, NextDelim - (*Walker));
00109       (*TempParameter)[NextDelim - (*Walker)] = CHAR_NULL;
00110       *Walker = NextDelim+1;
00111     } else {
00112       //
00113       // last one.
00114       //
00115       StrCpy(*TempParameter, *Walker);
00116       *Walker = NULL;
00117     }
00118     for (NextDelim = *TempParameter ; NextDelim != NULL && *NextDelim != CHAR_NULL ; NextDelim++) {
00119       if (*NextDelim == L'^' && *(NextDelim+1) == L'^') {
00120         CopyMem(NextDelim, NextDelim+1, StrSize(NextDelim) - sizeof(NextDelim[0]));
00121       }
00122     }
00123     while ((*TempParameter)[StrLen(*TempParameter)-1] == L' ') {
00124       (*TempParameter)[StrLen(*TempParameter)-1] = CHAR_NULL;
00125     }
00126     while ((*TempParameter)[0] == L' ') {
00127       CopyMem(*TempParameter, (*TempParameter)+1, StrSize(*TempParameter) - sizeof((*TempParameter)[0]));
00128     }
00129   }
00130   return;
00131 }
00132 
00147 EFI_STATUS
00148 EFIAPI
00149 ParseCommandLineToArgs(
00150   IN CONST CHAR16 *CommandLine,
00151   IN OUT CHAR16 ***Argv,
00152   IN OUT UINTN *Argc
00153   )
00154 {
00155   UINTN       Count;
00156   CHAR16      *TempParameter;
00157   CHAR16      *Walker;
00158   CHAR16      *NewParam;
00159   UINTN       Size;
00160 
00161   ASSERT(Argc != NULL);
00162   ASSERT(Argv != NULL);
00163 
00164   if (CommandLine == NULL || StrLen(CommandLine)==0) {
00165     (*Argc) = 0;
00166     (*Argv) = NULL;
00167     return (EFI_SUCCESS);
00168   }
00169 
00170   Size = StrSize(CommandLine);
00171   TempParameter = AllocateZeroPool(Size);
00172   if (TempParameter == NULL) {
00173     return (EFI_OUT_OF_RESOURCES);
00174   }
00175 
00176   for ( Count = 0
00177       , Walker = (CHAR16*)CommandLine
00178       ; Walker != NULL && *Walker != CHAR_NULL
00179       ; GetNextParameter(&Walker, &TempParameter)
00180       , Count++
00181      );
00182 
00183 /*  Count = 0;
00184   Walker = (CHAR16*)CommandLine;
00185   while(Walker != NULL) {
00186     GetNextParameter(&Walker, &TempParameter);
00187     Count++;
00188   }
00189 */
00190   //
00191   // lets allocate the pointer array
00192   //
00193   (*Argv) = AllocateZeroPool((Count)*sizeof(CHAR16*));
00194   if (*Argv == NULL) {
00195     return (EFI_OUT_OF_RESOURCES);
00196   }
00197 
00198   *Argc = 0;
00199   Walker = (CHAR16*)CommandLine;
00200   while(Walker != NULL && *Walker != CHAR_NULL) {
00201     SetMem16(TempParameter, Size, CHAR_NULL);
00202     GetNextParameter(&Walker, &TempParameter);
00203     NewParam = AllocateZeroPool(StrSize(TempParameter));
00204     ASSERT(NewParam != NULL);
00205     StrCpy(NewParam, TempParameter);
00206     ((CHAR16**)(*Argv))[(*Argc)] = NewParam;
00207     (*Argc)++;
00208   }
00209   ASSERT(Count >= (*Argc));
00210   return (EFI_SUCCESS);
00211 }
00212 
00229 EFI_STATUS
00230 EFIAPI
00231 CreatePopulateInstallShellParametersProtocol (
00232   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  **NewShellParameters,
00233   IN OUT BOOLEAN                        *RootShellInstance
00234   )
00235 {
00236   EFI_STATUS Status;
00237   EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
00238   CHAR16                    *FullCommandLine;
00239   UINTN                     Size;
00240 
00241   Size = 0;
00242   FullCommandLine = NULL;
00243   LoadedImage = NULL;
00244 
00245   //
00246   // Assert for valid parameters
00247   //
00248   ASSERT(NewShellParameters != NULL);
00249   ASSERT(RootShellInstance  != NULL);
00250 
00251   //
00252   // See if we have a shell parameters placed on us
00253   //
00254   Status = gBS->OpenProtocol (
00255                 gImageHandle,
00256                 &gEfiShellParametersProtocolGuid,
00257                 (VOID **) &ShellInfoObject.OldShellParameters,
00258                 gImageHandle,
00259                 NULL,
00260                 EFI_OPEN_PROTOCOL_GET_PROTOCOL
00261                );
00262   //
00263   // if we don't then we must be the root shell (error is expected)
00264   //
00265   if (EFI_ERROR (Status)) {
00266     *RootShellInstance = TRUE;
00267   }
00268 
00269   //
00270   // Allocate the new structure
00271   //
00272   *NewShellParameters = AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL));
00273   if ((*NewShellParameters) == NULL) {
00274     return (EFI_OUT_OF_RESOURCES);
00275   }
00276 
00277   //
00278   // get loaded image protocol
00279   //
00280   Status = gBS->OpenProtocol (
00281                 gImageHandle,
00282                 &gEfiLoadedImageProtocolGuid,
00283                 (VOID **) &LoadedImage,
00284                 gImageHandle,
00285                 NULL,
00286                 EFI_OPEN_PROTOCOL_GET_PROTOCOL
00287                );
00288   ASSERT_EFI_ERROR(Status);
00289   //
00290   // Build the full command line
00291   //
00292   Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, &FullCommandLine);
00293   if (Status == EFI_BUFFER_TOO_SMALL) {
00294     FullCommandLine = AllocateZeroPool(Size + LoadedImage->LoadOptionsSize);
00295     Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, &FullCommandLine);
00296   }
00297   if (Status == EFI_NOT_FOUND) {
00298     //
00299     // no parameters via environment... ok
00300     //
00301   } else {
00302     if (EFI_ERROR(Status)) {
00303       return (Status);
00304     }
00305   }
00306   if (Size == 0 && LoadedImage->LoadOptionsSize != 0) {
00307     ASSERT(FullCommandLine == NULL);
00308     //
00309     // Now we need to include a NULL terminator in the size.
00310     //
00311     Size = LoadedImage->LoadOptionsSize + sizeof(FullCommandLine[0]);
00312     FullCommandLine = AllocateZeroPool(Size);
00313   }
00314   if (FullCommandLine != NULL) {
00315     if (LoadedImage->LoadOptionsSize != 0){
00316       StrCpy(FullCommandLine, LoadedImage->LoadOptions);
00317     }
00318     //
00319     // Populate Argc and Argv
00320     //
00321     Status = ParseCommandLineToArgs(FullCommandLine,
00322                                     &(*NewShellParameters)->Argv,
00323                                     &(*NewShellParameters)->Argc);
00324 
00325     FreePool(FullCommandLine);
00326 
00327     ASSERT_EFI_ERROR(Status);
00328   } else {
00329     (*NewShellParameters)->Argv = NULL;
00330     (*NewShellParameters)->Argc = 0;
00331   }
00332 
00333   //
00334   // Populate the 3 faked file systems...
00335   //
00336   if (*RootShellInstance) {
00337     (*NewShellParameters)->StdIn  = &FileInterfaceStdIn;
00338     (*NewShellParameters)->StdOut = &FileInterfaceStdOut;
00339     (*NewShellParameters)->StdErr = &FileInterfaceStdErr;
00340     Status = gBS->InstallProtocolInterface(&gImageHandle,
00341                                            &gEfiShellParametersProtocolGuid,
00342                                            EFI_NATIVE_INTERFACE,
00343                                            (VOID*)(*NewShellParameters));
00344   } else {
00345     //
00346     // copy from the existing ones
00347     //
00348     (*NewShellParameters)->StdIn  = ShellInfoObject.OldShellParameters->StdIn;
00349     (*NewShellParameters)->StdOut = ShellInfoObject.OldShellParameters->StdOut;
00350     (*NewShellParameters)->StdErr = ShellInfoObject.OldShellParameters->StdErr;
00351     Status = gBS->ReinstallProtocolInterface(gImageHandle,
00352                                              &gEfiShellParametersProtocolGuid,
00353                                              (VOID*)ShellInfoObject.OldShellParameters,
00354                                              (VOID*)(*NewShellParameters));
00355   }
00356 
00357   return (Status);
00358 }
00359 
00372 EFI_STATUS
00373 EFIAPI
00374 CleanUpShellParametersProtocol (
00375   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *NewShellParameters
00376   )
00377 {
00378   EFI_STATUS Status;
00379   UINTN LoopCounter;
00380 
00381   //
00382   // If the old exists we need to restore it
00383   //
00384   if (ShellInfoObject.OldShellParameters != NULL) {
00385     Status = gBS->ReinstallProtocolInterface(gImageHandle,
00386                                              &gEfiShellParametersProtocolGuid,
00387                                              (VOID*)NewShellParameters,
00388                                              (VOID*)ShellInfoObject.OldShellParameters);
00389     DEBUG_CODE(ShellInfoObject.OldShellParameters = NULL;);
00390   } else {
00391     //
00392     // No old one, just uninstall us...
00393     //
00394     Status = gBS->UninstallProtocolInterface(gImageHandle,
00395                                              &gEfiShellParametersProtocolGuid,
00396                                              (VOID*)NewShellParameters);
00397   }
00398   if (NewShellParameters->Argv != NULL) {
00399     for ( LoopCounter = 0
00400         ; LoopCounter < NewShellParameters->Argc
00401         ; LoopCounter++
00402        ){
00403       FreePool(NewShellParameters->Argv[LoopCounter]);
00404     }
00405     FreePool(NewShellParameters->Argv);
00406   }
00407   FreePool(NewShellParameters);
00408   return (Status);
00409 }
00410 
00419 EFI_STATUS
00420 EFIAPI
00421 IsUnicodeFile(
00422   IN CONST CHAR16 *FileName
00423   )
00424 {
00425   SHELL_FILE_HANDLE Handle;
00426   EFI_STATUS        Status;
00427   UINT64            OriginalFilePosition;
00428   UINTN             CharSize;
00429   CHAR16            CharBuffer;
00430 
00431   Status = gEfiShellProtocol->OpenFileByName(FileName, &Handle, EFI_FILE_MODE_READ);
00432   if (EFI_ERROR(Status)) {
00433     return (Status);
00434   }
00435   gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition);
00436   gEfiShellProtocol->SetFilePosition(Handle, 0);
00437   CharSize = sizeof(CHAR16);
00438   Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);
00439   if (EFI_ERROR(Status) || CharBuffer != gUnicodeFileTag) {
00440     Status = EFI_BUFFER_TOO_SMALL;
00441   }
00442   gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);
00443   gEfiShellProtocol->CloseFile(Handle);
00444   return (Status);  
00445 }
00446 
00454 VOID
00455 EFIAPI
00456 StripQuotes (
00457   IN OUT CHAR16 *TheString
00458   )
00459 {
00460   BOOLEAN RemoveNow;
00461 
00462   for (RemoveNow = FALSE ; TheString != NULL && *TheString != CHAR_NULL ; TheString++) {
00463     if (*TheString == L'^' && *(TheString + 1) == L'\"') {
00464       TheString++;
00465     } else if (*TheString == L'\"') {
00466       RemoveNow = (BOOLEAN)!RemoveNow;
00467     } else if (RemoveNow) {
00468       *TheString = L' ';
00469     }
00470   }
00471 }
00472 
00480 VOID
00481 CalculateEfiHdrCrc (
00482   IN  OUT EFI_TABLE_HEADER    *Hdr
00483   )
00484 {
00485   UINT32 Crc;
00486 
00487   Hdr->CRC32 = 0;
00488 
00489   //
00490   // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
00491   //  Crc will come back as zero if we set it to zero here
00492   //
00493   Crc = 0;
00494   gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
00495   Hdr->CRC32 = Crc;
00496 }
00497 
00506 CHAR16*
00507 EFIAPI
00508 FixFileName (
00509   IN CHAR16 *FileName
00510   )
00511 {
00512   CHAR16  *Copy;
00513   CHAR16  *TempLocation;
00514 
00515   if (FileName == NULL) {
00516     return (NULL);
00517   }
00518 
00519   if (FileName[0] == L'\"') {
00520     Copy = FileName+1;
00521     if ((TempLocation = StrStr(Copy , L"\"")) != NULL) {
00522       TempLocation[0] = CHAR_NULL;
00523     }    
00524   } else {
00525     Copy = FileName;
00526     if ((TempLocation = StrStr(Copy , L" ")) != NULL) {
00527       TempLocation[0] = CHAR_NULL;
00528     }    
00529   }
00530 
00531   if (Copy[0] == CHAR_NULL) {
00532     return (NULL);
00533   }
00534 
00535   return (Copy);
00536 }
00537 
00555 EFI_STATUS
00556 EFIAPI
00557 UpdateStdInStdOutStdErr(
00558   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,
00559   IN CHAR16                             *NewCommandLine,
00560   OUT SHELL_FILE_HANDLE                 *OldStdIn,
00561   OUT SHELL_FILE_HANDLE                 *OldStdOut,
00562   OUT SHELL_FILE_HANDLE                 *OldStdErr,
00563   OUT SYSTEM_TABLE_INFO                 *SystemTableInfo
00564   )
00565 {
00566   CHAR16            *CommandLineCopy;
00567   CHAR16            *CommandLineWalker;
00568   CHAR16            *StdErrFileName;
00569   CHAR16            *StdOutFileName;
00570   CHAR16            *StdInFileName;
00571   CHAR16            *StdInVarName;
00572   CHAR16            *StdOutVarName;
00573   CHAR16            *StdErrVarName;
00574   EFI_STATUS        Status;
00575   SHELL_FILE_HANDLE TempHandle;
00576   UINT64            FileSize;
00577   BOOLEAN           OutUnicode;
00578   BOOLEAN           InUnicode;
00579   BOOLEAN           ErrUnicode;
00580   BOOLEAN           OutAppend;
00581   BOOLEAN           ErrAppend;
00582   UINTN             Size;
00583   CHAR16            TagBuffer[2];
00584   SPLIT_LIST        *Split;
00585   CHAR16            *FirstLocation;
00586 
00587   OutUnicode      = TRUE;
00588   InUnicode       = TRUE;
00589   ErrUnicode      = TRUE;
00590   StdInVarName    = NULL;
00591   StdOutVarName   = NULL;
00592   StdErrVarName   = NULL;
00593   StdErrFileName  = NULL;
00594   StdInFileName   = NULL;
00595   StdOutFileName  = NULL;
00596   ErrAppend       = FALSE;
00597   OutAppend       = FALSE;
00598   CommandLineCopy = NULL;
00599   FirstLocation   = NULL;
00600 
00601   if (ShellParameters == NULL || SystemTableInfo == NULL || OldStdIn == NULL || OldStdOut == NULL || OldStdErr == NULL) {
00602     return (EFI_INVALID_PARAMETER);
00603   }
00604 
00605   SystemTableInfo->ConIn          = gST->ConIn;
00606   SystemTableInfo->ConInHandle    = gST->ConsoleInHandle;
00607   SystemTableInfo->ConOut         = gST->ConOut;
00608   SystemTableInfo->ConOutHandle   = gST->ConsoleOutHandle;
00609   SystemTableInfo->ConErr         = gST->StdErr;
00610   SystemTableInfo->ConErrHandle   = gST->StandardErrorHandle;
00611   *OldStdIn                       = ShellParameters->StdIn;
00612   *OldStdOut                      = ShellParameters->StdOut;
00613   *OldStdErr                      = ShellParameters->StdErr;
00614 
00615   if (NewCommandLine == NULL) {
00616     return (EFI_SUCCESS);
00617   }
00618 
00619   CommandLineCopy = StrnCatGrow(&CommandLineCopy, NULL, NewCommandLine, 0);
00620   if (CommandLineCopy == NULL) {
00621     return (EFI_OUT_OF_RESOURCES);
00622   }
00623   Status          = EFI_SUCCESS;
00624   Split           = NULL;
00625   FirstLocation   = CommandLineCopy + StrLen(CommandLineCopy);
00626 
00627   StripQuotes(CommandLineCopy);
00628 
00629   if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
00630     Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
00631     if (Split != NULL && Split->SplitStdIn != NULL) {
00632       ShellParameters->StdIn  = Split->SplitStdIn;
00633     }
00634     if (Split != NULL && Split->SplitStdOut != NULL) {
00635       ShellParameters->StdOut = Split->SplitStdOut;
00636     }
00637   }
00638 
00639   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>>v ")) != NULL) {
00640     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00641     SetMem16(CommandLineWalker, 12, L' ');
00642     StdErrVarName   = CommandLineWalker += 6;
00643     ErrAppend       = TRUE;
00644     if (StrStr(CommandLineWalker, L" 2>>v ") != NULL) {
00645       Status = EFI_NOT_FOUND;
00646     }
00647   }
00648   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>v ")) != NULL) {
00649     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00650     SetMem16(CommandLineWalker, 12, L' ');
00651     StdOutVarName   = CommandLineWalker += 6;
00652     OutAppend       = TRUE;
00653     if (StrStr(CommandLineWalker, L" 1>>v ") != NULL) {
00654       Status = EFI_NOT_FOUND;
00655     }
00656   } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>v ")) != NULL) {
00657     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00658     SetMem16(CommandLineWalker, 10, L' ');
00659     StdOutVarName   = CommandLineWalker += 5;
00660     OutAppend       = TRUE;
00661     if (StrStr(CommandLineWalker, L" >>v ") != NULL) {
00662       Status = EFI_NOT_FOUND;
00663     }
00664   } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >v ")) != NULL) {
00665     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00666     SetMem16(CommandLineWalker, 8, L' ');
00667     StdOutVarName   = CommandLineWalker += 4;
00668     OutAppend       = FALSE;
00669     if (StrStr(CommandLineWalker, L" >v ") != NULL) {
00670       Status = EFI_NOT_FOUND;
00671     }
00672   }
00673   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>a ")) != NULL) {
00674     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00675     SetMem16(CommandLineWalker, 12, L' ');
00676     StdOutFileName  = CommandLineWalker += 6;
00677     OutAppend       = TRUE;
00678     OutUnicode      = FALSE;
00679     if (StrStr(CommandLineWalker, L" 1>>a ") != NULL) {
00680       Status = EFI_NOT_FOUND;
00681     }
00682   }
00683   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>> ")) != NULL) {
00684     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00685     SetMem16(CommandLineWalker, 10, L' ');
00686     if (StdOutFileName != NULL) {
00687       Status = EFI_INVALID_PARAMETER;
00688     } else {
00689       StdOutFileName  = CommandLineWalker += 5;
00690       OutAppend       = TRUE;
00691     }
00692     if (StrStr(CommandLineWalker, L" 1>> ") != NULL) {
00693       Status = EFI_NOT_FOUND;
00694     }
00695   } 
00696   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >> ")) != NULL) {
00697     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00698     SetMem16(CommandLineWalker, 8, L' ');
00699     if (StdOutFileName != NULL) {
00700       Status = EFI_INVALID_PARAMETER;
00701     } else {
00702       StdOutFileName  = CommandLineWalker += 4;
00703       OutAppend       = TRUE;
00704     }
00705     if (StrStr(CommandLineWalker, L" >> ") != NULL) {
00706       Status = EFI_NOT_FOUND;
00707     }
00708   }
00709   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>a ")) != NULL) {
00710     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00711     SetMem16(CommandLineWalker, 10, L' ');
00712     if (StdOutFileName != NULL) {
00713       Status = EFI_INVALID_PARAMETER;
00714     } else {
00715       StdOutFileName  = CommandLineWalker += 5;
00716       OutAppend       = TRUE;
00717       OutUnicode      = FALSE;
00718     }
00719     if (StrStr(CommandLineWalker, L" >>a ") != NULL) {
00720       Status = EFI_NOT_FOUND;
00721     }
00722   } 
00723   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>a ")) != NULL) {
00724     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00725     SetMem16(CommandLineWalker, 10, L' ');
00726     if (StdOutFileName != NULL) {
00727       Status = EFI_INVALID_PARAMETER;
00728     } else {
00729       StdOutFileName  = CommandLineWalker += 5;
00730       OutAppend       = FALSE;
00731       OutUnicode      = FALSE;
00732     }
00733     if (StrStr(CommandLineWalker, L" 1>a ") != NULL) {
00734       Status = EFI_NOT_FOUND;
00735     }
00736   } 
00737   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >a ")) != NULL) {
00738     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00739     SetMem16(CommandLineWalker, 8, L' ');
00740     if (StdOutFileName != NULL) {
00741       Status = EFI_INVALID_PARAMETER;
00742     } else {
00743       StdOutFileName  = CommandLineWalker += 4;
00744       OutAppend       = FALSE;
00745       OutUnicode      = FALSE;
00746     }
00747     if (StrStr(CommandLineWalker, L" >a ") != NULL) {
00748       Status = EFI_NOT_FOUND;
00749     }
00750   }
00751   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>> ")) != NULL) {
00752     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00753     SetMem16(CommandLineWalker, 10, L' ');
00754     if (StdErrFileName != NULL) {
00755       Status = EFI_INVALID_PARAMETER;
00756     } else {
00757       StdErrFileName  = CommandLineWalker += 5;
00758       ErrAppend       = TRUE;
00759     }
00760     if (StrStr(CommandLineWalker, L" 2>> ") != NULL) {
00761       Status = EFI_NOT_FOUND;
00762     }
00763   }
00764 
00765   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>v ")) != NULL) {
00766     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00767     SetMem16(CommandLineWalker, 10, L' ');
00768     if (StdErrVarName != NULL) {
00769       Status = EFI_INVALID_PARAMETER;
00770     } else {
00771       StdErrVarName   = CommandLineWalker += 5;
00772       ErrAppend       = FALSE;
00773     }
00774     if (StrStr(CommandLineWalker, L" 2>v ") != NULL) {
00775       Status = EFI_NOT_FOUND;
00776     }
00777   }
00778   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>v ")) != NULL) {
00779     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00780     SetMem16(CommandLineWalker, 10, L' ');
00781     if (StdOutVarName != NULL) {
00782       Status = EFI_INVALID_PARAMETER;
00783     } else {
00784       StdOutVarName   = CommandLineWalker += 5;
00785       OutAppend       = FALSE;
00786     }
00787     if (StrStr(CommandLineWalker, L" 1>v ") != NULL) {
00788       Status = EFI_NOT_FOUND;
00789     }
00790   }
00791   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>a ")) != NULL) {
00792     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00793     SetMem16(CommandLineWalker, 10, L' ');
00794     if (StdErrFileName != NULL) {
00795       Status = EFI_INVALID_PARAMETER;
00796     } else {
00797       StdErrFileName  = CommandLineWalker += 5;
00798       ErrAppend       = FALSE;
00799       ErrUnicode      = FALSE;
00800     }
00801     if (StrStr(CommandLineWalker, L" 2>a ") != NULL) {
00802       Status = EFI_NOT_FOUND;
00803     }
00804   }
00805   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2> ")) != NULL) {
00806     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00807     SetMem16(CommandLineWalker, 8, L' ');
00808     if (StdErrFileName != NULL) {
00809       Status = EFI_INVALID_PARAMETER;
00810     } else {
00811       StdErrFileName  = CommandLineWalker += 4;
00812       ErrAppend       = FALSE;
00813     }
00814     if (StrStr(CommandLineWalker, L" 2> ") != NULL) {
00815       Status = EFI_NOT_FOUND;
00816     }
00817   }
00818 
00819   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1> ")) != NULL) {
00820     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00821     SetMem16(CommandLineWalker, 8, L' ');
00822     if (StdOutFileName != NULL) {
00823       Status = EFI_INVALID_PARAMETER;
00824     } else {
00825       StdOutFileName  = CommandLineWalker += 4;
00826       OutAppend       = FALSE;
00827     }
00828     if (StrStr(CommandLineWalker, L" 1> ") != NULL) {
00829       Status = EFI_NOT_FOUND;
00830     }
00831   }
00832 
00833   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" > ")) != NULL) {
00834     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00835     SetMem16(CommandLineWalker, 6, L' ');
00836     if (StdOutFileName != NULL) {
00837       Status = EFI_INVALID_PARAMETER;
00838     } else {
00839       StdOutFileName  = CommandLineWalker += 3;
00840       OutAppend       = FALSE;
00841     }
00842     if (StrStr(CommandLineWalker, L" > ") != NULL) {
00843       Status = EFI_NOT_FOUND;
00844     }
00845   }
00846 
00847   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" < ")) != NULL) {
00848     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00849     SetMem16(CommandLineWalker, 6, L' ');
00850     if (StdInFileName != NULL) {
00851       Status = EFI_INVALID_PARAMETER;
00852     } else {
00853       StdInFileName  = CommandLineWalker += 3;
00854     }
00855     if (StrStr(CommandLineWalker, L" < ") != NULL) {
00856       Status = EFI_NOT_FOUND;
00857     }
00858   }
00859   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <a ")) != NULL) {
00860     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00861     SetMem16(CommandLineWalker, 8, L' ');
00862     if (StdInFileName != NULL) {
00863       Status = EFI_INVALID_PARAMETER;
00864     } else {
00865       StdInFileName   = CommandLineWalker += 4;
00866       InUnicode       = FALSE;
00867     }
00868     if (StrStr(CommandLineWalker, L" <a ") != NULL) {
00869       Status = EFI_NOT_FOUND;
00870     }
00871   }
00872   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <v ")) != NULL) {
00873     FirstLocation = MIN(CommandLineWalker, FirstLocation);
00874     SetMem16(CommandLineWalker, 8, L' ');
00875     if (StdInVarName != NULL) {
00876       Status = EFI_INVALID_PARAMETER;
00877     } else {
00878       StdInVarName  = CommandLineWalker += 4;
00879     }
00880     if (StrStr(CommandLineWalker, L" <v ") != NULL) {
00881       Status = EFI_NOT_FOUND;
00882     }
00883   }
00884 
00885   //
00886   // re-populate the string to support any filenames that were in quotes.
00887   //
00888   StrCpy(CommandLineCopy, NewCommandLine);
00889 
00890   if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)
00891     && ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine))
00892     ){
00893     *(NewCommandLine + (UINTN)(FirstLocation - CommandLineCopy)) = CHAR_NULL;
00894   }
00895 
00896   if (!EFI_ERROR(Status)) {
00897 
00898     if (StdErrFileName != NULL) {
00899       if ((StdErrFileName    = FixFileName(StdErrFileName)) == NULL) {
00900         Status = EFI_INVALID_PARAMETER;
00901       }
00902     }
00903     if (StdOutFileName != NULL) {
00904       if ((StdOutFileName    = FixFileName(StdOutFileName)) == NULL) {
00905         Status = EFI_INVALID_PARAMETER;
00906       }
00907     }
00908     if (StdInFileName  != NULL) {
00909       if ((StdInFileName     = FixFileName(StdInFileName)) == NULL) {
00910         Status = EFI_INVALID_PARAMETER;
00911       }
00912     }
00913     if (StdErrVarName  != NULL) {
00914       if ((StdErrVarName     = FixFileName(StdErrVarName)) == NULL) {
00915         Status = EFI_INVALID_PARAMETER;
00916       }
00917     }
00918     if (StdOutVarName  != NULL) {
00919       if ((StdOutVarName     = FixFileName(StdOutVarName)) == NULL) {
00920         Status = EFI_INVALID_PARAMETER;
00921       }
00922     }
00923     if (StdInVarName   != NULL) {
00924       if ((StdInVarName      = FixFileName(StdInVarName)) == NULL) {
00925         Status = EFI_INVALID_PARAMETER;
00926       }
00927     }
00928 
00929     //
00930     // Verify not the same and not duplicating something from a split
00931     //
00932     if (
00933       //
00934       // Check that no 2 filenames are the same
00935       //
00936       (StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0)
00937       ||(StdErrFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdErrFileName, &StdInFileName ) == 0)
00938       ||(StdOutFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdOutFileName, &StdInFileName ) == 0)
00939       //
00940       // Check that no 2 variable names are the same
00941       //
00942       ||(StdErrVarName  != NULL && StdInVarName  != NULL && StringNoCaseCompare(&StdErrVarName , &StdInVarName  ) == 0)
00943       ||(StdOutVarName  != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdOutVarName , &StdInVarName  ) == 0)
00944       ||(StdErrVarName  != NULL && StdOutVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdOutVarName ) == 0)
00945       //
00946       // When a split (using | operator) is in place some are not allowed
00947       //
00948       ||(Split != NULL && Split->SplitStdIn  != NULL && (StdInVarName  != NULL || StdInFileName  != NULL))
00949       ||(Split != NULL && Split->SplitStdOut != NULL && (StdOutVarName != NULL || StdOutFileName != NULL))
00950       //
00951       // Check that nothing is trying to be output to 2 locations.
00952       //
00953       ||(StdErrFileName != NULL && StdErrVarName != NULL)
00954       ||(StdOutFileName != NULL && StdOutVarName != NULL)
00955       ||(StdInFileName  != NULL && StdInVarName  != NULL)
00956       //
00957       // Check for no volatile environment variables
00958       //
00959       ||(StdErrVarName  != NULL && !IsVolatileEnv(StdErrVarName))
00960       ||(StdOutVarName  != NULL && !IsVolatileEnv(StdOutVarName))
00961       //
00962       // Cant redirect during a reconnect operation.
00963       //
00964       ||(StrStr(NewCommandLine, L"connect -r") != NULL 
00965          && (StdOutVarName != NULL || StdOutFileName != NULL || StdErrFileName != NULL || StdErrVarName != NULL))
00966       //
00967       // Check that filetypes (Unicode/Ascii) do not change during an append
00968       //
00969       ||(StdOutFileName != NULL && OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && EFI_ERROR(IsUnicodeFile(StdOutFileName))))
00970       ||(StdErrFileName != NULL && ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && EFI_ERROR(IsUnicodeFile(StdErrFileName))))
00971       ||(StdOutFileName != NULL && !OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName))))
00972       ||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName))))
00973       ){
00974       Status = EFI_INVALID_PARAMETER;
00975       ShellParameters->StdIn  = *OldStdIn;
00976       ShellParameters->StdOut = *OldStdOut;
00977       ShellParameters->StdErr = *OldStdErr;
00978     } else if (!EFI_ERROR(Status)){
00979       //
00980       // Open the Std<Whatever> and we should not have conflicts here...
00981       //
00982 
00983       //
00984       // StdErr to a file
00985       //
00986       if (StdErrFileName != NULL) {
00987         if (!ErrAppend) {
00988           //
00989           // delete existing file.
00990           //
00991           ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdErrFileName);
00992         }
00993         Status = ShellOpenFileByName(StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
00994         if (!ErrAppend && ErrUnicode && !EFI_ERROR(Status)) {
00995           //
00996           // Write out the gUnicodeFileTag
00997           //
00998           Size = sizeof(CHAR16);
00999           TagBuffer[0] = gUnicodeFileTag;
01000           TagBuffer[1] = CHAR_NULL;
01001           ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
01002         }
01003         if (!ErrUnicode && !EFI_ERROR(Status)) {
01004           TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
01005           ASSERT(TempHandle != NULL);
01006         }
01007         if (!EFI_ERROR(Status)) {
01008           ShellParameters->StdErr = TempHandle;
01009           gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle);
01010         }
01011       }
01012 
01013       //
01014       // StdOut to a file
01015       //
01016       if (!EFI_ERROR(Status) && StdOutFileName != NULL) {
01017         if (!OutAppend) {
01018           //
01019           // delete existing file.
01020           //
01021           ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdOutFileName);
01022         }
01023         Status = ShellOpenFileByName(StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
01024         if (TempHandle == NULL) {
01025           Status = EFI_INVALID_PARAMETER;
01026         } else {
01027           if (StrStr(StdOutFileName, L"NUL")==StdOutFileName) {
01028             //no-op
01029           } else if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
01030             //
01031             // Write out the gUnicodeFileTag
01032             //
01033             Size = sizeof(CHAR16);
01034             TagBuffer[0] = gUnicodeFileTag;
01035             TagBuffer[1] = CHAR_NULL;
01036             ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
01037           } else if (OutAppend) {
01038             //
01039             // Move to end of file
01040             //
01041             Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize);
01042             if (!EFI_ERROR(Status)) {
01043               Status = ShellInfoObject.NewEfiShellProtocol->SetFilePosition(TempHandle, FileSize);
01044             }
01045           }
01046           if (!OutUnicode && !EFI_ERROR(Status)) {
01047             TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
01048             ASSERT(TempHandle != NULL);
01049           }
01050           if (!EFI_ERROR(Status)) {
01051             ShellParameters->StdOut = TempHandle;
01052             gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle);
01053           }
01054         }
01055       }
01056 
01057       //
01058       // StdOut to a var
01059       //
01060       if (!EFI_ERROR(Status) && StdOutVarName != NULL) {
01061         if (!OutAppend) {
01062           //
01063           // delete existing variable.
01064           //
01065           SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName, 0, L"");
01066         }
01067         TempHandle = CreateFileInterfaceEnv(StdOutVarName);
01068         ASSERT(TempHandle != NULL);
01069         ShellParameters->StdOut = TempHandle;
01070         gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle);
01071       }
01072 
01073       //
01074       // StdErr to a var
01075       //
01076       if (!EFI_ERROR(Status) && StdErrVarName != NULL) {
01077         if (!ErrAppend) {
01078           //
01079           // delete existing variable.
01080           //
01081           SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName, 0, L"");
01082         }
01083         TempHandle = CreateFileInterfaceEnv(StdErrVarName);
01084         ASSERT(TempHandle != NULL);
01085         ShellParameters->StdErr = TempHandle;
01086         gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle);
01087       }
01088 
01089       //
01090       // StdIn from a var
01091       //
01092       if (!EFI_ERROR(Status) && StdInVarName != NULL) {
01093         TempHandle = CreateFileInterfaceEnv(StdInVarName);
01094         if (TempHandle == NULL) {
01095           Status = EFI_OUT_OF_RESOURCES;
01096         } else {
01097           if (!InUnicode) {
01098             TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
01099           }
01100           Size = 0;
01101           if (TempHandle == NULL || ((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {
01102             Status = EFI_INVALID_PARAMETER;
01103           } else {
01104             ShellParameters->StdIn = TempHandle;
01105             gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);
01106           }
01107         }
01108       }
01109 
01110       //
01111       // StdIn from a file
01112       //
01113       if (!EFI_ERROR(Status) && StdInFileName != NULL) {
01114         Status = ShellOpenFileByName(
01115           StdInFileName,
01116           &TempHandle,
01117           EFI_FILE_MODE_READ,
01118           0);
01119         if (!InUnicode && !EFI_ERROR(Status)) {
01120           TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
01121         }
01122         if (!EFI_ERROR(Status)) {
01123           ShellParameters->StdIn = TempHandle;
01124           gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);
01125         }
01126       }
01127     }
01128   }
01129   FreePool(CommandLineCopy);
01130 
01131   CalculateEfiHdrCrc(&gST->Hdr);
01132 
01133   if (gST->ConIn == NULL ||gST->ConOut == NULL) {
01134     return (EFI_OUT_OF_RESOURCES);
01135   }
01136   return (Status);
01137 }
01138 
01149 EFI_STATUS
01150 EFIAPI
01151 RestoreStdInStdOutStdErr (
01152   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,
01153   IN  SHELL_FILE_HANDLE                 *OldStdIn,
01154   IN  SHELL_FILE_HANDLE                 *OldStdOut,
01155   IN  SHELL_FILE_HANDLE                 *OldStdErr,
01156   IN  SYSTEM_TABLE_INFO                 *SystemTableInfo
01157   )
01158 {
01159   SPLIT_LIST        *Split;
01160 
01161   if (ShellParameters == NULL 
01162     ||OldStdIn        == NULL
01163     ||OldStdOut       == NULL
01164     ||OldStdErr       == NULL
01165     ||SystemTableInfo == NULL) {
01166     return (EFI_INVALID_PARAMETER);
01167   }
01168   if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
01169     Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
01170   } else {
01171     Split = NULL;
01172   }
01173   if (ShellParameters->StdIn  != *OldStdIn) {
01174     if ((Split != NULL && Split->SplitStdIn != ShellParameters->StdIn) || Split == NULL) {
01175       gEfiShellProtocol->CloseFile(ShellParameters->StdIn);
01176     }
01177     ShellParameters->StdIn = *OldStdIn;
01178   }
01179   if (ShellParameters->StdOut != *OldStdOut) {
01180     if ((Split != NULL && Split->SplitStdOut != ShellParameters->StdOut) || Split == NULL) {
01181       gEfiShellProtocol->CloseFile(ShellParameters->StdOut);
01182     }
01183     ShellParameters->StdOut = *OldStdOut;
01184   }
01185   if (ShellParameters->StdErr != *OldStdErr) {
01186     gEfiShellProtocol->CloseFile(ShellParameters->StdErr);
01187     ShellParameters->StdErr = *OldStdErr;
01188   }
01189 
01190   if (gST->ConIn != SystemTableInfo->ConIn) {
01191     CloseSimpleTextInOnFile(gST->ConIn);
01192     gST->ConIn                = SystemTableInfo->ConIn;
01193     gST->ConsoleInHandle      = SystemTableInfo->ConInHandle;
01194   }
01195   if (gST->ConOut != SystemTableInfo->ConOut) {
01196     CloseSimpleTextOutOnFile(gST->ConOut);
01197     gST->ConOut               = SystemTableInfo->ConOut;
01198     gST->ConsoleOutHandle     = SystemTableInfo->ConOutHandle;
01199   }
01200   if (gST->StdErr != SystemTableInfo->ConErr) {
01201     CloseSimpleTextOutOnFile(gST->StdErr);
01202     gST->StdErr               = SystemTableInfo->ConErr;
01203     gST->StandardErrorHandle  = SystemTableInfo->ConErrHandle;
01204   }
01205 
01206   CalculateEfiHdrCrc(&gST->Hdr);
01207 
01208   return (EFI_SUCCESS);
01209 }
01225 EFI_STATUS
01226 EFIAPI
01227 UpdateArgcArgv(
01228   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,
01229   IN CONST CHAR16                       *NewCommandLine,
01230   OUT CHAR16                            ***OldArgv OPTIONAL,
01231   OUT UINTN                             *OldArgc OPTIONAL
01232   )
01233 {
01234   ASSERT(ShellParameters != NULL);
01235 
01236   if (OldArgc != NULL) {
01237     *OldArgc = ShellParameters->Argc;
01238   }
01239   if (OldArgc != NULL) {
01240     *OldArgv = ShellParameters->Argv;
01241   }
01242 
01243   return (ParseCommandLineToArgs(NewCommandLine, &(ShellParameters->Argv), &(ShellParameters->Argc)));
01244 }
01245 
01255 VOID
01256 EFIAPI
01257 RestoreArgcArgv(
01258   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,
01259   IN CHAR16                             ***OldArgv,
01260   IN UINTN                              *OldArgc
01261   )
01262 {
01263   UINTN LoopCounter;
01264   ASSERT(ShellParameters != NULL);
01265   ASSERT(OldArgv         != NULL);
01266   ASSERT(OldArgc         != NULL);
01267 
01268   if (ShellParameters->Argv != NULL) {
01269     for ( LoopCounter = 0
01270         ; LoopCounter < ShellParameters->Argc
01271         ; LoopCounter++
01272        ){
01273       FreePool(ShellParameters->Argv[LoopCounter]);
01274     }
01275     FreePool(ShellParameters->Argv);
01276   }
01277   ShellParameters->Argv = *OldArgv;
01278   *OldArgv = NULL;
01279   ShellParameters->Argc = *OldArgc;
01280   *OldArgc = 0;
01281 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines