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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\etshell\ts_std.h
28 const TUint KShellMajorVersionNumber=0;
29 const TUint KShellMinorVersionNumber=1;
30 const TUint KShellBuildVersionNumber=KF32BuildVersionNumber;
31 const TInt KShellMaxCommandLine=0x100;
33 const TInt KDefaultHistorySize=20;
39 EShellBadRelativePath,
50 class CLineEdit : public CBase
53 enum TCursorType {ECursorNone=0,ECursorNormal=20,ECursorInsert=100};
54 enum TEditMode {EEditOverWrite,EEditInsert};
56 static CLineEdit* NewL(CConsoleBase* aConsole,TInt aMaxHistory);
58 TLineEditAction Edit(const TDesC& aPrompt, TDes* aBuf, TBool aNewLine);
59 TInt Pos() { return iPos; }
60 void SetPos(TInt aPos) { iPos = aPos; }
68 void ClearLast(TInt aCnt);
72 inline TDes& Buf() {return *iBuf;}
74 void StoreBufferHistory();
77 CArrayFixFlat<HBufC*>* iHistory;
78 CConsoleBase* iConsole; // Not owned
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,
103 const TPtrC iHelpDetail;
104 const TUint iSwitchesSupported;
105 TInt (* const iFunction)(TDes& aPath,TUint aSwitches);
107 TShellCommand(const TDesC& aName,const TDesC& aHelp,const TDesC& aHelpDetail,TUint aSwitches,TInt (*aFunction)(TDes&,TUint));
109 TShellCommand& operator=(TShellCommand);
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
121 TWord (const TDesC& aDes);
122 void Init(const TDesC& aDes);
123 TInt FindNextWord(TDes& aWord);
125 TInt iSpace; // Position of the first space
126 TInt iNextSpace; // Position of the following space
127 TPtrC iDes; // The given command line text
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
136 class CShell : public CBase
139 static CShell* NewL();
142 void SetCurrentPath(const TDesC& aDes);
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,...);
150 static CConsoleBase* TheConsole;
151 static CFileMan* TheFileMan;
152 static CCliCompleter* TheCliCompleter;
156 /** Total numbr of built-in shell commands */
157 enum {ENoShellCommands=33};
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);
170 static TBuf<KMaxFileName> currentPath;
171 static TBuf<KMaxFileName> drivePaths[KMaxDrives];
172 static const TShellCommand iCommand[ENoShellCommands];
174 static CLineEdit* TheEditor;
175 friend class ShellFunction;
176 friend class CDllChecker;
180 class CDllChecker : public CBase
182 // A class for checking dependencies of executables and Dlls
186 enum TResultCheck {EAlreadyOpen,ECouldNotOpenFile,ENotFound,EUidNotSupported,ENoImportData,EUidDifference,EFileFoundAndUidSupported};
189 TBuf8<KMaxFileName> iDllName;
191 TResultCheck iResult;
194 CArrayFixFlat<SDllInfo>* iDllArray; // Array of Imports already checked
195 TInt iCalls; // Number of recursive calls of GetImportDataL()
197 RFile iFile;//file object for reading data from phisical file
198 TUint32 iConversionOffset;
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);
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);
214 void GetImportDataL(const TDesC& aFileName, TUid* aPointer);
221 static CShell* TheShell;
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);
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);
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);
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);
279 NONSHARABLE_CLASS(SimpleOverflowTruncate): public TDes16Overflow
282 virtual void Overflow(TDes16&)