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