198 { |
197 { |
199 CASE_RETURN_LIT(EUnknown); |
198 CASE_RETURN_LIT(EUnknown); |
200 CASE_RETURN_LIT(EFailedToCreatePipeLine); |
199 CASE_RETURN_LIT(EFailedToCreatePipeLine); |
201 CASE_RETURN_LIT(EFailedToConstructCommand); |
200 CASE_RETURN_LIT(EFailedToConstructCommand); |
202 CASE_RETURN_LIT(EFailedToRunCommand); |
201 CASE_RETURN_LIT(EFailedToRunCommand); |
203 CASE_RETURN_LIT(EFailedToSetChildErrorVar); |
202 CASE_RETURN_LIT(EPipelineCompletionError); |
204 CASE_RETURN_LIT(EFailedToSetScriptLineVar); |
|
205 CASE_RETURN_LIT(ECommandError); |
203 CASE_RETURN_LIT(ECommandError); |
206 DEFAULT_RETURN_LIT("*** REASON UNKNOWN ***"); |
204 DEFAULT_RETURN_LIT("*** REASON UNKNOWN ***"); |
207 } |
205 } |
208 } |
206 } |
209 |
207 |
513 } |
511 } |
514 else if (iScriptName.Length() > 0) |
512 else if (iScriptName.Length() > 0) |
515 { |
513 { |
516 TIoHandleSet ioHandles(IoSession(), Stdin(), Stdout(), Stderr()); |
514 TIoHandleSet ioHandles(IoSession(), Stdin(), Stdout(), Stderr()); |
517 TBool helpPrinted; |
515 TBool helpPrinted; |
518 iScriptData = ReadScriptL(iScriptName, iScriptArgs, Env(), FsL(), ioHandles, helpPrinted); |
516 iScriptHandle = OpenScriptL(iScriptName, iScriptArgs, Env(), FsL(), ioHandles, helpPrinted); |
519 if (helpPrinted) |
517 if (helpPrinted) |
520 { |
518 { |
521 Complete(); |
519 Complete(); |
522 } |
520 } |
523 else |
521 else |
525 TUint mode = CParser::EExportLineNumbers; |
523 TUint mode = CParser::EExportLineNumbers; |
526 if (iKeepGoing) |
524 if (iKeepGoing) |
527 { |
525 { |
528 mode |= CParser::EKeepGoing; |
526 mode |= CParser::EKeepGoing; |
529 } |
527 } |
530 iParser = CParser::NewL(mode, *iScriptData, IoSession(), Stdin(), Stdout(), Stderr(), Env(), *iCommandFactory, this); |
528 iParser = CParser::NewL(mode, iScriptHandle, IoSession(), Stdin(), Stdout(), Stderr(), Env(), *iCommandFactory, this); |
531 RProcess::Rendezvous(KErrNone); |
529 RProcess::Rendezvous(KErrNone); |
532 iParser->Start(); |
530 iParser->Start(); |
533 } |
531 } |
534 } |
532 } |
535 else |
533 else |
639 } |
637 } |
640 } |
638 } |
641 return KErrNotFound; |
639 return KErrNotFound; |
642 } |
640 } |
643 |
641 |
644 HBufC* CShell::ReadScriptL(const TDesC& aScriptName, const TDesC* aArguments, IoUtils::CEnvironment& aEnv, RFs& aFs, TIoHandleSet& aIoHandles, TBool& aHelpPrinted, RPointerArray<HBufC>* aAdditionalPrefixArguments) |
642 RIoReadHandle CShell::OpenScriptL(const TDesC& aScriptName, const TDesC* aArguments, IoUtils::CEnvironment& aEnv, RFs& aFs, TIoHandleSet& aIoHandles, TBool& aHelpPrinted, RPointerArray<HBufC>* aAdditionalPrefixArguments) |
645 { |
643 { |
|
644 RIoReadHandle readHandle; |
|
645 readHandle.CreateL(aIoHandles.IoSession()); |
|
646 CleanupClosePushL(readHandle); |
|
647 |
646 TFileName2 scriptName(aScriptName); |
648 TFileName2 scriptName(aScriptName); |
647 |
649 |
648 // Check the scripts dirs in case it wasn't given as an absolute path (although iocli will have made it absolute relative to the pwd) |
650 // Check the scripts dirs in case it wasn't given as an absolute path (although iocli will have made it absolute relative to the pwd) |
649 _LIT(KScriptDir, "y:\\system\\console\\scripts\\"); |
651 _LIT(KScriptDir, "y:\\system\\console\\scripts\\"); |
650 _LIT(KScriptSuffix, ".script"); |
652 _LIT(KScriptSuffix, ".script"); |
668 // Put scriptname back the way it was |
670 // Put scriptname back the way it was |
669 scriptName.SetLength(scriptNameLen); |
671 scriptName.SetLength(scriptNameLen); |
670 } |
672 } |
671 } |
673 } |
672 |
674 |
673 RFile scriptFile; |
675 RIoFile scriptFile; |
674 TInt err; |
676 TInt err; |
675 TInt retries = 5; |
677 TInt retries = 5; |
676 do |
678 do |
677 { |
679 { |
678 err = scriptFile.Open(aFs, scriptName, EFileRead | EFileShareReadersOnly); |
680 err = scriptFile.Create(aIoHandles.IoSession(), scriptName, RIoFile::ERead); |
679 if ((err == KErrNone) || (err != KErrInUse)) |
681 if ((err == KErrNone) || (err != KErrInUse)) |
680 { |
682 { |
681 break; |
683 break; |
682 } |
684 } |
683 User::After(500000); |
685 User::After(500000); |
684 --retries; |
686 --retries; |
685 } |
687 } |
686 while (retries >= 0); |
688 while (retries >= 0); |
687 StaticLeaveIfErr(err, _L("Couldn't open script file %S"), &scriptName); |
689 StaticLeaveIfErr(err, _L("Couldn't open script file %S"), &scriptName); |
688 CleanupClosePushL(scriptFile); |
690 CleanupClosePushL(scriptFile); |
689 TInt scriptFileSize; |
691 scriptFile.AttachL(readHandle, RIoEndPoint::EForeground); |
690 User::LeaveIfError(scriptFile.Size(scriptFileSize)); |
692 CleanupStack::PopAndDestroy(&scriptFile); |
691 HBufC8* scriptData = HBufC8::NewLC(scriptFileSize); |
693 |
692 TPtr8 scriptDataPtr(scriptData->Des()); |
|
693 User::LeaveIfError(scriptFile.Read(scriptDataPtr)); |
|
694 HBufC* decodedScriptData = LtkUtils::DecodeUtf8L(*scriptData); |
|
695 CleanupStack::PopAndDestroy(2, &scriptFile); |
|
696 CleanupStack::PushL(decodedScriptData); |
|
697 aEnv.SetLocalL(KScriptName); |
694 aEnv.SetLocalL(KScriptName); |
698 aEnv.SetLocalL(KScriptPath); |
695 aEnv.SetLocalL(KScriptPath); |
699 aEnv.SetLocalL(KScriptLine); |
696 aEnv.SetLocalL(KScriptLine); |
700 aEnv.SetLocalL(_L("0")); |
697 aEnv.SetLocalL(_L("0")); |
701 aEnv.SetL(KScriptName, scriptName.NameAndExt()); |
698 aEnv.SetL(KScriptName, scriptName.NameAndExt()); |
702 aEnv.SetL(KScriptPath, scriptName.DriveAndPath()); |
699 aEnv.SetL(KScriptPath, scriptName.DriveAndPath()); |
703 aEnv.SetL(_L("0"), scriptName); |
700 aEnv.SetL(_L("0"), scriptName); |
|
701 |
704 CScriptCommand* scriptCommand = CScriptCommand::NewLC(scriptName, aIoHandles); |
702 CScriptCommand* scriptCommand = CScriptCommand::NewLC(scriptName, aIoHandles); |
705 TRAP(err, scriptCommand->ParseCommandLineArgsL(aArguments ? *aArguments : KNullDesC(), aEnv, aAdditionalPrefixArguments)); |
703 TRAP(err, scriptCommand->ParseCommandLineArgsL(aArguments ? *aArguments : KNullDesC(), aEnv, aAdditionalPrefixArguments)); |
706 if (err == KErrArgument || scriptCommand->ShouldDisplayHelp()) |
704 if (err == KErrArgument || scriptCommand->ShouldDisplayHelp()) |
707 { |
705 { |
708 // Need to display help |
706 // Need to display help |
721 { |
719 { |
722 aHelpPrinted = EFalse; |
720 aHelpPrinted = EFalse; |
723 } |
721 } |
724 User::LeaveIfError(err); // Propagate error |
722 User::LeaveIfError(err); // Propagate error |
725 CleanupStack::PopAndDestroy(scriptCommand); |
723 CleanupStack::PopAndDestroy(scriptCommand); |
726 CleanupStack::Pop(decodedScriptData); |
724 CleanupStack::Pop(&readHandle); |
727 return decodedScriptData; |
725 return readHandle; |
728 } |
726 } |
729 |
727 |
730 void CShell::SetToForeground() |
728 void CShell::SetToForeground() |
731 { |
729 { |
732 Stdin().SetToForeground(); |
730 Stdin().SetToForeground(); |