sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32\etshell\ts_std.h sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "f32image.h" sl@0: sl@0: const TUint KShellMajorVersionNumber=0; sl@0: const TUint KShellMinorVersionNumber=1; sl@0: const TUint KShellBuildVersionNumber=KF32BuildVersionNumber; sl@0: const TInt KShellMaxCommandLine=0x100; sl@0: sl@0: const TInt KDefaultHistorySize=20; sl@0: sl@0: enum TShellPanic sl@0: { sl@0: EShellBadFileCopy, sl@0: EShellBadDrivePath, sl@0: EShellBadRelativePath, sl@0: EShellFilePathTooBig sl@0: }; sl@0: sl@0: enum TLineEditAction sl@0: { sl@0: ENoAction, sl@0: ECommandCompletion, sl@0: EShellCommand sl@0: }; sl@0: sl@0: class CLineEdit : public CBase sl@0: { sl@0: public: sl@0: enum TCursorType {ECursorNone=0,ECursorNormal=20,ECursorInsert=100}; sl@0: enum TEditMode {EEditOverWrite,EEditInsert}; sl@0: public: sl@0: static CLineEdit* NewL(CConsoleBase* aConsole,TInt aMaxHistory); sl@0: ~CLineEdit(); sl@0: TLineEditAction Edit(const TDesC& aPrompt, TDes* aBuf, TBool aNewLine); sl@0: TInt Pos() { return iPos; } sl@0: void SetPos(TInt aPos) { iPos = aPos; } sl@0: protected: sl@0: CLineEdit(); sl@0: TPoint Where(); sl@0: TInt Lines(); sl@0: TInt WordLeft(); sl@0: TInt WordRight(); sl@0: void ClearLine(); sl@0: void ClearLast(TInt aCnt); sl@0: void Recall(); sl@0: void Cursor(); sl@0: void Refresh(); sl@0: inline TDes& Buf() {return *iBuf;} sl@0: void NewLine(); sl@0: void StoreBufferHistory(); sl@0: sl@0: private: sl@0: CArrayFixFlat* iHistory; sl@0: CConsoleBase* iConsole; // Not owned sl@0: TInt iMaxHistory; sl@0: TInt iWidth; sl@0: TInt iHeight; sl@0: TInt iPos; sl@0: TInt iLine; sl@0: TInt iOrigin; sl@0: TInt iRecall; sl@0: TEditMode iMode; sl@0: TDes* iBuf; sl@0: TSize iFrameSizeChar; sl@0: TInt iTabCount; sl@0: }; sl@0: sl@0: class TShellCommand sl@0: { sl@0: public: sl@0: enum {EASwitch=0x1,EBSwitch=0x2,ECSwitch=0x4,EDSwitch=0x8,EESwitch=0x10, sl@0: EFSwitch=0x20,EGSwitch=0x40,EHSwitch=0x80,EISwitch=0x100,EJSwitch=0x200, sl@0: EKSwitch=0x400,ELSwitch=0x800,EMSwitch=0x1000,ENSwitch=0x2000,EOSwitch=0x4000, sl@0: EPSwitch=0x8000,EQSwitch=0x10000,ERSwitch=0x20000,ESSwitch=0x40000,ETSwitch=0x80000, sl@0: EUSwitch=0x100000,EVSwitch=0x200000,EWSwitch=0x400000,EXSwitch=0x800000,EYSwitch=0x1000000, sl@0: EZSwitch=0x2000000}; sl@0: const TPtrC iName; sl@0: const TPtrC iHelp; sl@0: const TPtrC iHelpDetail; sl@0: const TUint iSwitchesSupported; sl@0: TInt (* const iFunction)(TDes& aPath,TUint aSwitches); sl@0: public: sl@0: TShellCommand(const TDesC& aName,const TDesC& aHelp,const TDesC& aHelpDetail,TUint aSwitches,TInt (*aFunction)(TDes&,TUint)); sl@0: private: sl@0: TShellCommand& operator=(TShellCommand); sl@0: }; sl@0: sl@0: class TWord sl@0: { sl@0: // User types COMMAND aDes sl@0: // TWord is initialised with aDes sl@0: // NextWord takes aDes and locates any spaces sl@0: // If aDes is a single word, NextWord returns the start position of the word sl@0: // Otherwise, NextWord returns the start position of the next word sl@0: sl@0: public: sl@0: TWord (const TDesC& aDes); sl@0: void Init(const TDesC& aDes); sl@0: TInt FindNextWord(TDes& aWord); sl@0: private: sl@0: TInt iSpace; // Position of the first space sl@0: TInt iNextSpace; // Position of the following space sl@0: TPtrC iDes; // The given command line text sl@0: public: sl@0: TBuf iRightString; // The residual string after a space sl@0: TBuf iNextWord; // Text between a space and the end of the string or another space sl@0: }; sl@0: sl@0: sl@0: class CCliCompleter; sl@0: sl@0: class CShell : public CBase sl@0: { sl@0: public: sl@0: static CShell* NewL(); sl@0: ~CShell(); sl@0: void RunL(); sl@0: void SetCurrentPath(const TDesC& aDes); sl@0: TDes& CurrentPath(); sl@0: void SetDrivePath(const TDesC& aDes); sl@0: static void NewLine(); sl@0: static TKeyCode OutputStringToConsole(TBool aPageSwitch,TRefByValue aFmt,...); sl@0: static TKeyCode OutputStringToConsole(TBool aPageSwitch, const TDesC& aBuf); sl@0: static TKeyCode OutputStringToConsole(const TDesC& aNotification,TBool aPageSwitch,TRefByValue aFmt,...); sl@0: public: sl@0: static CConsoleBase* TheConsole; sl@0: static CFileMan* TheFileMan; sl@0: static CCliCompleter* TheCliCompleter; sl@0: sl@0: private: sl@0: sl@0: /** Total numbr of built-in shell commands */ sl@0: enum {ENoShellCommands=33}; sl@0: sl@0: private: sl@0: static void DoBanner(); sl@0: static void DoCommand(TDes& aCommand); sl@0: static void PrintError(TInt aError); sl@0: static void PrintHelp(); sl@0: static void PrintHelp(const TShellCommand* aCommand); sl@0: static void ChangeDrive(TChar aDrive); sl@0: static TInt RunBatch(TDes& aCommand); sl@0: static TInt RunExecutable(TDes& aCommand,TBool aWaitForCompletion); sl@0: static TKeyCode PageSwitchDisplay(const TDesC& aBuf); sl@0: private: sl@0: static TBuf currentPath; sl@0: static TBuf drivePaths[KMaxDrives]; sl@0: static const TShellCommand iCommand[ENoShellCommands]; sl@0: static RFs TheFs; sl@0: static CLineEdit* TheEditor; sl@0: friend class ShellFunction; sl@0: friend class CDllChecker; sl@0: }; sl@0: sl@0: sl@0: class CDllChecker : public CBase sl@0: // sl@0: // A class for checking dependencies of executables and Dlls sl@0: // sl@0: { sl@0: private: sl@0: enum TResultCheck {EAlreadyOpen,ECouldNotOpenFile,ENotFound,EUidNotSupported,ENoImportData,EUidDifference,EFileFoundAndUidSupported}; sl@0: struct SDllInfo sl@0: { sl@0: TBuf8 iDllName; sl@0: TUid iUid; sl@0: TResultCheck iResult; sl@0: }; sl@0: sl@0: CArrayFixFlat* iDllArray; // Array of Imports already checked sl@0: TInt iCalls; // Number of recursive calls of GetImportDataL() sl@0: sl@0: RFile iFile;//file object for reading data from phisical file sl@0: TUint32 iConversionOffset; sl@0: private: sl@0: void GetFileNameAndUid(SDllInfo &aDllInfo, const TDesC8 &aExportName); sl@0: TInt FindDll(TDes& aDllName,TFileName& aFileName, TPath& aPath); sl@0: void DllAppendL(const SDllInfo& aDllInfo); sl@0: TUint8* NextBlock(TUint8* aBlock); sl@0: sl@0: void LoadFileInflateL(E32ImageHeaderComp* aHeader,TUint8* aRestOfFileData,TUint32 aRestOfFileSize); sl@0: void LoadFileNoCompressL(E32ImageHeaderComp* aHeader,TUint8* aRestOfFileData,TUint32 aRestOfFileSize); sl@0: TInt CheckUid3(TInt32 aUid3,TUid aUid); sl@0: TInt LoadFile(TUint32 aCompression,E32ImageHeaderComp* aHeader,TUint8* aRestOfFileData,TUint32 iRestOfFileSize); sl@0: void GetDllTableL(TUint8* aImportData,TInt aDllRefTableCount,TUint aFlags); sl@0: public: sl@0: CDllChecker(); sl@0: ~CDllChecker(); sl@0: void ConstructL(); sl@0: void GetImportDataL(const TDesC& aFileName, TUid* aPointer); sl@0: void ListArray(); sl@0: }; sl@0: sl@0: class ShellFunction sl@0: { sl@0: public: sl@0: static CShell* TheShell; sl@0: public: sl@0: static TInt Attrib(TDes& aPath,TUint aSwitches); sl@0: static TInt Cd(TDes& aPath,TUint aSwitches); sl@0: static TInt ChkDeps(TDes& aPath,TUint aSwitches); sl@0: static TInt ChkDsk(TDes& aPath,TUint aSwitches); sl@0: static TInt Copy(TDes& aPath,TUint aSwitches); sl@0: #ifndef __DATA_CAGING__ sl@0: static TInt DefaultPath(TDes& aPath,TUint aSwitches); sl@0: #endif sl@0: static TInt VolumeLabel(TDes& aPath,TUint aSwitches); sl@0: static TInt Del(TDes& aPath,TUint aSwitches); sl@0: static TInt Dir(TDes& aPath,TUint aSwitches); sl@0: static TInt Edit(TDes& aPath,TUint aSwitches); sl@0: static TInt Format(TDes& aPath,TUint aSwitches); sl@0: static TInt Gobble(TDes& aPath,TUint aSwitches); sl@0: static TInt Hexdump(TDes& aPath,TUint aSwitches); sl@0: static TInt Md(TDes& aPath,TUint aSwitches); sl@0: static TInt Move(TDes& aPath,TUint aSwitches); sl@0: static TInt Ps(TDes& aPath,TUint aSwitches); sl@0: static TInt Rename(TDes& aPath,TUint aSwitches); sl@0: static TInt Rd(TDes& aPath,TUint aSwitches); sl@0: static TInt Start(TDes& aProgram,TUint aSwitches); sl@0: static TInt Time(TDes&,TUint aSwitches); sl@0: static TInt Trace(TDes& aState,TUint aSwitches); sl@0: static TInt Tree(TDes& aPath,TUint aSwitches); sl@0: static TInt Type(TDes& aPath,TUint aSwitches); sl@0: static TInt ValidName(TDes& aPath,TUint aSwitches); sl@0: static TInt XCopy(TDes& aPath,TUint aSwitches); sl@0: static TInt Lock(TDes& aPath, TUint aSwitches); sl@0: static TInt Unlock(TDes& aPath, TUint aSwitches); sl@0: static TInt Clear(TDes& aPath, TUint aSwitches); sl@0: static TInt SetSize(TDes& aPath,TUint aSwitches); sl@0: static TInt DebugPort(TDes& aArgs, TUint aSwitches); sl@0: static TInt Plugin(TDes& aArgs, TUint aSwitches); sl@0: static TInt DrvInfo(TDes& aArgs, TUint aSwitches); sl@0: static TInt SysInfo(TDes& aArgs, TUint aSwitches); sl@0: static TInt MountFileSystem(TDes& aArgs, TUint aSwitches); sl@0: static TInt ConsoleEcho(TDes& aArgs, TUint aSwitches); sl@0: static TInt RunExec(TDes& aProgram, TUint aSwitches); sl@0: static void ParsePath(TDes& aPath); sl@0: static TInt GetFullPath(TDes& aPath,TParse& aParse); sl@0: static void AlignTextIntoColumns(RPointerArray& aText); sl@0: static void StripQuotes(TDes& aVal); sl@0: sl@0: private: sl@0: static TInt ShowDirectoryTree(TDes& aPath,TUint aSwitches,TDes& aTreeGraph); sl@0: static TBool Certain(); sl@0: static void OutputContentsToConsole(RPointerArray& aText,TUint aSwitches); sl@0: static void OutputDirContentL(CDir* aDirList,RPointerArray& aText,TUint aSwitches); sl@0: }; sl@0: sl@0: GLREF_D TVersion TheShellVersion; sl@0: GLREF_C void Panic(TShellPanic anErrorCode); sl@0: GLREF_C TInt AddRelativePath(TParse& aParse,const TDesC& aRelativePath); sl@0: GLREF_C TInt GetFullPath(TParse& aParse,const TDesC& aPath,const TDesC& aCurrentPath); sl@0: GLREF_C void Get16BitDllName(TDes8& aDllName,TDes& aFileName); sl@0: sl@0: NONSHARABLE_CLASS(SimpleOverflowTruncate): public TDes16Overflow sl@0: { sl@0: public: sl@0: virtual void Overflow(TDes16&) sl@0: { sl@0: return; sl@0: } sl@0: };