os/kernelhwsrv/userlibandfileserver/fileserver/etshell/ts_std.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // f32\etshell\ts_std.h
    15 // 
    16 //
    17 
    18 #include <e32debug.h>
    19 #include <e32svr.h>
    20 #include <f32file.h>
    21 #include <f32ver.h>
    22 #include <f32dbg.h>
    23 #include <e32cons.h>
    24 #include <e32twin.h>
    25 #include <e32des16.h> 
    26 #include "f32image.h"
    27 
    28 const TUint KShellMajorVersionNumber=0;
    29 const TUint KShellMinorVersionNumber=1;
    30 const TUint KShellBuildVersionNumber=KF32BuildVersionNumber;
    31 const TInt  KShellMaxCommandLine=0x100;
    32 
    33 const TInt KDefaultHistorySize=20;
    34 
    35 enum TShellPanic
    36 	{
    37 	EShellBadFileCopy,
    38 	EShellBadDrivePath,
    39 	EShellBadRelativePath,
    40 	EShellFilePathTooBig
    41 	};
    42 
    43 enum TLineEditAction
    44 	{
    45 	ENoAction,
    46 	ECommandCompletion,
    47 	EShellCommand
    48 	};
    49 
    50 class CLineEdit : public CBase
    51     {
    52 public:
    53 	enum TCursorType {ECursorNone=0,ECursorNormal=20,ECursorInsert=100};
    54 	enum TEditMode {EEditOverWrite,EEditInsert};
    55 public:
    56 	static CLineEdit* NewL(CConsoleBase* aConsole,TInt aMaxHistory);
    57 	~CLineEdit();
    58 	TLineEditAction Edit(const TDesC& aPrompt, TDes* aBuf, TBool aNewLine);
    59 	TInt Pos() { return iPos; }
    60 	void SetPos(TInt aPos) { iPos = aPos; }
    61 protected:
    62 	CLineEdit();
    63 	TPoint Where();
    64 	TInt Lines();
    65 	TInt WordLeft();
    66 	TInt WordRight();
    67 	void ClearLine();
    68 	void ClearLast(TInt aCnt);
    69 	void Recall();
    70 	void Cursor();
    71 	void Refresh();
    72 	inline TDes& Buf() {return *iBuf;}
    73 	void NewLine();
    74 	void StoreBufferHistory();
    75 	
    76 private:
    77 	CArrayFixFlat<HBufC*>* iHistory;
    78 	CConsoleBase* iConsole; // Not owned
    79 	TInt iMaxHistory;
    80 	TInt iWidth;
    81 	TInt iHeight;
    82 	TInt iPos;
    83 	TInt iLine;
    84 	TInt iOrigin;
    85  	TInt iRecall;
    86 	TEditMode iMode;
    87 	TDes* iBuf;
    88 	TSize iFrameSizeChar;
    89 	TInt iTabCount; 
    90 	};
    91 
    92 class TShellCommand
    93 	{
    94 public:
    95 	enum {EASwitch=0x1,EBSwitch=0x2,ECSwitch=0x4,EDSwitch=0x8,EESwitch=0x10,
    96 		EFSwitch=0x20,EGSwitch=0x40,EHSwitch=0x80,EISwitch=0x100,EJSwitch=0x200,
    97 		EKSwitch=0x400,ELSwitch=0x800,EMSwitch=0x1000,ENSwitch=0x2000,EOSwitch=0x4000,
    98 		EPSwitch=0x8000,EQSwitch=0x10000,ERSwitch=0x20000,ESSwitch=0x40000,ETSwitch=0x80000,
    99 		EUSwitch=0x100000,EVSwitch=0x200000,EWSwitch=0x400000,EXSwitch=0x800000,EYSwitch=0x1000000,
   100 		EZSwitch=0x2000000};
   101 	const TPtrC iName;
   102 	const TPtrC iHelp;
   103 	const TPtrC iHelpDetail;
   104 	const TUint iSwitchesSupported;
   105 	TInt (* const iFunction)(TDes& aPath,TUint aSwitches);
   106 public:
   107 	TShellCommand(const TDesC& aName,const TDesC& aHelp,const TDesC& aHelpDetail,TUint aSwitches,TInt (*aFunction)(TDes&,TUint));
   108 private:
   109 	TShellCommand& operator=(TShellCommand);
   110 	};
   111 
   112 class TWord
   113 {
   114 //	User types COMMAND aDes
   115 //	TWord is initialised with aDes
   116 //	NextWord takes aDes and locates any spaces
   117 //	If aDes is a single word, NextWord returns the start position of the word
   118 //	Otherwise, NextWord returns the start position of the next word
   119 
   120 public:
   121 	TWord (const TDesC& aDes);
   122 	void Init(const TDesC& aDes);
   123 	TInt FindNextWord(TDes& aWord);
   124 private:
   125 	TInt iSpace;			//	Position of the first space
   126 	TInt iNextSpace;		//	Position of the following space
   127 	TPtrC iDes;				//	The given command line text
   128 public:
   129 	TBuf<KShellMaxCommandLine> iRightString;	//	The residual string after a space 
   130 	TBuf<KShellMaxCommandLine> iNextWord;	//	Text between a space and the end of the string or another space
   131 };
   132 
   133 
   134 class CCliCompleter;
   135 
   136 class CShell : public CBase
   137 	{
   138 public:
   139 	static CShell* NewL();
   140 	~CShell();
   141 	void RunL();
   142 	void SetCurrentPath(const TDesC& aDes);
   143 	TDes& CurrentPath();
   144 	void SetDrivePath(const TDesC& aDes);
   145 	static void NewLine();
   146 	static TKeyCode OutputStringToConsole(TBool aPageSwitch,TRefByValue<const TDesC> aFmt,...);
   147 	static TKeyCode OutputStringToConsole(TBool aPageSwitch, const TDesC& aBuf);
   148 	static TKeyCode OutputStringToConsole(const TDesC& aNotification,TBool aPageSwitch,TRefByValue<const TDesC> aFmt,...);
   149 public:
   150 	static CConsoleBase* TheConsole;
   151 	static CFileMan* TheFileMan;
   152 	static CCliCompleter* TheCliCompleter;
   153 	
   154 private:
   155 	
   156     /** Total numbr of built-in shell commands */
   157     enum {ENoShellCommands=33};
   158 
   159 private:
   160 	static void DoBanner();
   161 	static void DoCommand(TDes& aCommand);
   162 	static void PrintError(TInt aError);
   163 	static void PrintHelp();
   164 	static void PrintHelp(const TShellCommand* aCommand);
   165 	static void ChangeDrive(TChar aDrive);
   166 	static TInt RunBatch(TDes& aCommand);
   167 	static TInt RunExecutable(TDes& aCommand,TBool aWaitForCompletion);
   168 	static TKeyCode PageSwitchDisplay(const TDesC& aBuf);
   169 private:
   170 	static TBuf<KMaxFileName> currentPath;
   171 	static TBuf<KMaxFileName> drivePaths[KMaxDrives];
   172 	static const TShellCommand iCommand[ENoShellCommands];
   173 	static RFs TheFs;
   174 	static CLineEdit* TheEditor;
   175 	friend class ShellFunction;
   176 	friend class CDllChecker;
   177 	};
   178 
   179 
   180 class CDllChecker : public CBase
   181 //
   182 //	A class for checking dependencies of executables and Dlls	
   183 //
   184 	{
   185 private:
   186 	enum TResultCheck {EAlreadyOpen,ECouldNotOpenFile,ENotFound,EUidNotSupported,ENoImportData,EUidDifference,EFileFoundAndUidSupported};
   187 	struct SDllInfo
   188 		{
   189 		TBuf8<KMaxFileName> iDllName;
   190 		TUid iUid;
   191 		TResultCheck iResult;
   192 		};
   193 	
   194 	CArrayFixFlat<SDllInfo>* iDllArray;	//	Array of Imports already checked
   195 	TInt iCalls;	//	Number of recursive calls of GetImportDataL()
   196 	
   197 	RFile iFile;//file object for reading data from phisical file
   198 	TUint32  iConversionOffset;
   199 private:
   200 	void GetFileNameAndUid(SDllInfo &aDllInfo, const TDesC8 &aExportName);
   201 	TInt FindDll(TDes& aDllName,TFileName& aFileName, TPath& aPath);
   202 	void DllAppendL(const SDllInfo& aDllInfo);
   203 	TUint8* NextBlock(TUint8* aBlock);
   204 	
   205 	void LoadFileInflateL(E32ImageHeaderComp* aHeader,TUint8* aRestOfFileData,TUint32 aRestOfFileSize);
   206 	void LoadFileNoCompressL(E32ImageHeaderComp* aHeader,TUint8* aRestOfFileData,TUint32 aRestOfFileSize);
   207 	TInt CheckUid3(TInt32 aUid3,TUid aUid);
   208 	TInt LoadFile(TUint32 aCompression,E32ImageHeaderComp* aHeader,TUint8* aRestOfFileData,TUint32 iRestOfFileSize);	
   209 	void GetDllTableL(TUint8* aImportData,TInt aDllRefTableCount,TUint aFlags);
   210 public:	
   211 	CDllChecker();
   212 	~CDllChecker();
   213 	void ConstructL();	
   214 	void GetImportDataL(const TDesC& aFileName, TUid* aPointer);	
   215 	void ListArray();	
   216 	};
   217 
   218 class ShellFunction
   219 	{
   220 public:
   221 	static CShell* TheShell;
   222 public:
   223 	static TInt Attrib(TDes& aPath,TUint aSwitches);
   224 	static TInt Cd(TDes& aPath,TUint aSwitches);
   225 	static TInt ChkDeps(TDes& aPath,TUint aSwitches);
   226 	static TInt ChkDsk(TDes& aPath,TUint aSwitches);
   227 	static TInt Copy(TDes& aPath,TUint aSwitches);
   228 #ifndef __DATA_CAGING__
   229 	static TInt DefaultPath(TDes& aPath,TUint aSwitches);
   230 #endif
   231 	static TInt VolumeLabel(TDes& aPath,TUint aSwitches);
   232 	static TInt Del(TDes& aPath,TUint aSwitches);
   233 	static TInt Dir(TDes& aPath,TUint aSwitches);
   234 	static TInt Edit(TDes& aPath,TUint aSwitches);
   235 	static TInt Format(TDes& aPath,TUint aSwitches);
   236 	static TInt Gobble(TDes& aPath,TUint aSwitches);
   237 	static TInt Hexdump(TDes& aPath,TUint aSwitches);
   238 	static TInt Md(TDes& aPath,TUint aSwitches);
   239 	static TInt Move(TDes& aPath,TUint aSwitches);
   240 	static TInt Ps(TDes& aPath,TUint aSwitches);
   241 	static TInt Rename(TDes& aPath,TUint aSwitches);
   242 	static TInt Rd(TDes& aPath,TUint aSwitches);
   243 	static TInt Start(TDes& aProgram,TUint aSwitches);
   244 	static TInt Time(TDes&,TUint aSwitches);
   245 	static TInt Trace(TDes& aState,TUint aSwitches);
   246 	static TInt Tree(TDes& aPath,TUint aSwitches);
   247 	static TInt Type(TDes& aPath,TUint aSwitches);
   248 	static TInt ValidName(TDes& aPath,TUint aSwitches);
   249 	static TInt XCopy(TDes& aPath,TUint aSwitches);
   250 	static TInt Lock(TDes& aPath, TUint aSwitches);
   251 	static TInt Unlock(TDes& aPath, TUint aSwitches);
   252 	static TInt Clear(TDes& aPath, TUint aSwitches);
   253 	static TInt SetSize(TDes& aPath,TUint aSwitches);
   254 	static TInt DebugPort(TDes& aArgs, TUint aSwitches);
   255 	static TInt Plugin(TDes& aArgs, TUint aSwitches);
   256     static TInt DrvInfo(TDes& aArgs, TUint aSwitches);
   257 	static TInt SysInfo(TDes& aArgs, TUint aSwitches);
   258     static TInt MountFileSystem(TDes& aArgs, TUint aSwitches);
   259     static TInt ConsoleEcho(TDes& aArgs, TUint aSwitches);
   260 	static TInt RunExec(TDes& aProgram, TUint aSwitches);
   261 	static void ParsePath(TDes& aPath);
   262 	static TInt GetFullPath(TDes& aPath,TParse& aParse);
   263 	static void AlignTextIntoColumns(RPointerArray<HBufC>& aText);
   264 	static void StripQuotes(TDes& aVal);
   265 	
   266 private:		
   267 	static TInt ShowDirectoryTree(TDes& aPath,TUint aSwitches,TDes& aTreeGraph);
   268 	static TBool Certain();	
   269 	static void OutputContentsToConsole(RPointerArray<HBufC>& aText,TUint aSwitches);
   270 	static void OutputDirContentL(CDir* aDirList,RPointerArray<HBufC>& aText,TUint aSwitches);	
   271 	};
   272 
   273 GLREF_D TVersion TheShellVersion;
   274 GLREF_C void Panic(TShellPanic anErrorCode);
   275 GLREF_C TInt AddRelativePath(TParse& aParse,const TDesC& aRelativePath);
   276 GLREF_C TInt GetFullPath(TParse& aParse,const TDesC& aPath,const TDesC& aCurrentPath);
   277 GLREF_C void Get16BitDllName(TDes8& aDllName,TDes& aFileName);
   278 
   279 NONSHARABLE_CLASS(SimpleOverflowTruncate): public TDes16Overflow
   280 	{
   281 	public:
   282 		virtual void Overflow(TDes16&)
   283 		{
   284 			return;
   285 		}
   286 	};