userlibandfileserver/fileserver/etshell/ts_edshl.cpp
branchRCL_3
changeset 42 a179b74831c9
parent 6 0173bcd7697c
child 43 c1f20ce4abcf
equal deleted inserted replaced
41:0ffb4e86fcc9 42:a179b74831c9
   530 			TRAP_IGNORE(iHistory->InsertL(0, pB));
   530 			TRAP_IGNORE(iHistory->InsertL(0, pB));
   531 			}
   531 			}
   532 		}
   532 		}
   533 	}
   533 	}
   534 
   534 
       
   535 
       
   536 //-------------------------------------------------------------------------
       
   537 //-- generic shell commands that don't require sophisticated processing
       
   538 
       
   539 _LIT(KCmd_Help, "HELP");    ///< displays help
       
   540 _LIT(KCmd_Cls,  "CLS");     ///< clears the screen
       
   541 _LIT(KCmd_Rem,  "REM");     ///< *.bat processing - commented out line
       
   542 _LIT(KCmd_Break,"BREAK");   ///< stops *.bat file execution
       
   543 _LIT(KCmd_Exit, "EXIT");    ///< exit the shell
       
   544 
       
   545 //-------------------------------------------------------------------------
   535 //////////////////////////////////////
   546 //////////////////////////////////////
   536 //CShell
   547 //CShell
   537 //////////////////////////////////////
   548 //////////////////////////////////////
   538 TShellCommand::TShellCommand(const TDesC& aName,const TDesC& aHelp,const TDesC& aHelpDetail,TUint aSwitches,TInt (*aFunction)(TDes&,TUint))
   549 TShellCommand::TShellCommand(const TDesC& aName,const TDesC& aHelp,const TDesC& aHelpDetail,TUint aSwitches,TInt (*aFunction)(TDes&,TUint))
   539 	:iName(aName),
   550 	:iName(aName),
   726 			{
   737 			{
   727 			case EShellCommand:
   738 			case EShellCommand:
   728 				tabCount = 0;
   739 				tabCount = 0;
   729 				
   740 				
   730 #if !defined(_EPOC)
   741 #if !defined(_EPOC)
   731 				if(commandText.CompareF(_L("EXIT")) == 0)
   742 				if(commandText.CompareF(KCmd_Exit) == 0)
   732 					{
   743 					{
   733 					exit = ETrue;
   744 					exit = ETrue;
   734 					break;
   745 					break;
   735 					}
   746 					}
   736 #endif
   747 #endif
   813 			}
   824 			}
   814 		}
   825 		}
   815 	
   826 	
   816 	CleanupStack::PopAndDestroy(fileManObserver);
   827 	CleanupStack::PopAndDestroy(fileManObserver);
   817 	}
   828 	}
       
   829 
       
   830 
       
   831 
       
   832 //-------------------------------------------------------------------------
   818 
   833 
   819 void CShell::DoCommand(TDes& aCommand)
   834 void CShell::DoCommand(TDes& aCommand)
   820 //
   835 //
   821 // Evaluate the commandline and run the command or file
   836 // Evaluate the commandline and run the command or file
   822 //
   837 //
   882 		}
   897 		}
   883 	else //Generic commands
   898 	else //Generic commands
   884 		{
   899 		{
   885 		TInt r;
   900 		TInt r;
   886 		
   901 		
   887 		if (aCommand.CompareF(_L("HELP"))==0)
   902 		if (aCommand.CompareF(KCmd_Help)==0)
   888 			PrintHelp();
   903 			PrintHelp();
   889 		else if (aCommand.CompareF(_L("CLS"))==0)
   904 		else if (aCommand.CompareF(KCmd_Cls)==0)
   890 			TheConsole->ClearScreen(); 
   905 			TheConsole->ClearScreen(); 
       
   906 		else if (aCommand.CompareF(KCmd_Break)==0)
       
   907 			{//-- "break" command, do nothing
       
   908             }
   891 		else if (aCommand.Length()==2 && TChar(aCommand[0]).IsAlpha() && aCommand[1]==':')
   909 		else if (aCommand.Length()==2 && TChar(aCommand[0]).IsAlpha() && aCommand[1]==':')
   892 			ChangeDrive(aCommand[0]);
   910 			ChangeDrive(aCommand[0]);
   893 		else if (aCommand.Length()!=0)
   911 		else if (aCommand.Length()!=0)
   894 			{
   912 			{
   895 			r=RunBatch(aCommand);
   913 			r=RunBatch(aCommand);
  1061 				currentPath=drivePaths[drive];
  1079 				currentPath=drivePaths[drive];
  1062 				}
  1080 				}
  1063 			else 
  1081 			else 
  1064 			PrintError(KErrNotFound);
  1082 			PrintError(KErrNotFound);
  1065 			}
  1083 			}
  1066 			
  1084 		else if (readBuf.Length()<3 || readBuf.Left(3).CompareF(KCmd_Rem)!=0)
  1067 		else if (readBuf.Length()<3 || readBuf.Left(3).CompareF(_L("REM"))!=0)
  1085             {
       
  1086 			//-- check if it is a "break" command. stop execution in this case
       
  1087             if(readBuf.CompareF(KCmd_Break) ==0)
       
  1088                 break; //-- terminate batch file execution        
       
  1089             else
  1068 			DoCommand(readBuf);
  1090 			DoCommand(readBuf);
  1069 		}
  1091 		}
       
  1092 		}
       
  1093 	
       
  1094     
  1070 	file.Close();
  1095 	file.Close();
  1071 	return KErrNone;
  1096 	return KErrNone;
  1072 	}
  1097 	}
  1073 
  1098 
  1074 
  1099 
  1216 	TInt drvNum;
  1241 	TInt drvNum;
  1217     __ASSERT_ALWAYS(charToDrive(drvLetter,drvNum)==KErrNone,User::Panic(_L("Invalid drive letter"),0));
  1242     __ASSERT_ALWAYS(charToDrive(drvLetter,drvNum)==KErrNone,User::Panic(_L("Invalid drive letter"),0));
  1218 	drivePaths[drvNum]=aDrivePath;
  1243 	drivePaths[drvNum]=aDrivePath;
  1219 	}
  1244 	}
  1220 
  1245 
  1221 
  1246 //----------------------------------------------------------------------
  1222 TKeyCode CShell::OutputStringToConsole(TBool aPageSwitch,TRefByValue<const TDesC> aFmt,... )
  1247 TKeyCode CShell::OutputStringToConsole(TBool aPageSwitch,TRefByValue<const TDesC> aFmt,... )
  1223 //function for output of a sring to console
  1248 //function for output of a sring to console
  1224 //aPageSwitch flag indicates that output should be page-by-page 
  1249 //aPageSwitch flag indicates that output should be page-by-page 
  1225 	{
  1250 	{
  1226 	//create an object to truncate argument list substitution 
  1251 	//create an object to truncate argument list substitution 
  1237 	_LIT(KPrompt , "Press any key to continue\n");		
  1262 	_LIT(KPrompt , "Press any key to continue\n");		
  1238 	
  1263 	
  1239 	return OutputStringToConsole(KPrompt,aPageSwitch,_L("%S"),&aBuf);
  1264 	return OutputStringToConsole(KPrompt,aPageSwitch,_L("%S"),&aBuf);
  1240 	}
  1265 	}
  1241 
  1266 
       
  1267 //----------------------------------------------------------------------
  1242 TKeyCode CShell::OutputStringToConsole(const TDesC& aNotification,TBool aPageSwitch,TRefByValue<const TDesC> aFmt,...)
  1268 TKeyCode CShell::OutputStringToConsole(const TDesC& aNotification,TBool aPageSwitch,TRefByValue<const TDesC> aFmt,...)
  1243 	//function for output of a string to console aPageSwitch flag indicates that output should be page-by-page 
  1269 	//function for output of a string to console aPageSwitch flag indicates that output should be page-by-page 
  1244 	//if aPageSwitch==ETrue user will be prompted with the message passed as aNotification
  1270 	//if aPageSwitch==ETrue user will be prompted with the message passed as aNotification
  1245 	//code of key pressed will be returned as a return value
  1271 	//code of key pressed will be returned as a return value
  1246 	{
  1272 	{
  1249 	//create an object to truncate argument list substitution 
  1275 	//create an object to truncate argument list substitution 
  1250 	SimpleOverflowTruncate overflow;
  1276 	SimpleOverflowTruncate overflow;
  1251 	
  1277 	
  1252 	VA_LIST list;
  1278 	VA_LIST list;
  1253 	VA_START(list,aFmt);
  1279 	VA_START(list,aFmt);
  1254 	
       
  1255 	TBuf<0x200> aBuf;
  1280 	TBuf<0x200> aBuf;
  1256 	//format output string using argumen list
  1281 	//format output string using argumen list
  1257 	
       
  1258 	//coverity[uninit_use_in_call]
  1282 	//coverity[uninit_use_in_call]
  1259 	TRAP_IGNORE(aBuf.AppendFormatList(aFmt,list,&overflow)); // ignore leave in TTimeOverflowLeave::Overflow()
  1283 	TRAP_IGNORE(aBuf.AppendFormatList(aFmt,list,&overflow)); // ignore leave in TTimeOverflowLeave::Overflow()
  1260 	//if we are requested to wait for the user input at the end of each page, we check whether output of next piece of text will fit into the screen
  1284 	//if we are requested to wait for the user input at the end of each page, we check whether output of next piece of text will fit into the screen
  1261 	if (aPageSwitch)
  1285 	if (aPageSwitch)
  1262 		{
  1286 		{
  1263 		key=PageSwitchDisplay(aNotification);				
  1287 		key=PageSwitchDisplay(aNotification);				
  1264 		}
  1288 		}
  1265 	//output current string
  1289 	//output current string
  1266 	TheConsole->Write(aBuf);
  1290 	
       
  1291 	Print(aBuf);
       
  1292     
  1267 	return key;			
  1293 	return key;			
  1268 	}
  1294 	}
  1269 
  1295 
  1270 TKeyCode CShell::OutputStringToConsole(TBool aPageSwitch, const TDesC& aBuf)
  1296 //----------------------------------------------------------------------
       
  1297 TKeyCode CShell::WriteBufToConsole(TBool aPageSwitch, const TDesC& aBuf)
  1271 	{
  1298 	{
  1272 	_LIT(KPrompt , "Press any key to continue\n");
  1299 	_LIT(KPrompt , "Press any key to continue\n");
  1273 	
  1300     return WriteBufToConsole(aPageSwitch, aBuf, KPrompt);
       
  1301 	}
       
  1302 	
       
  1303 //----------------------------------------------------------------------
       
  1304 TKeyCode CShell::WriteBufToConsole(TBool aPageSwitch, const TDesC& aBuf, const TDesC& aNotification)
       
  1305     {
  1274     TKeyCode key=EKeyNull;	
  1306     TKeyCode key=EKeyNull;	
  1275 
  1307 
  1276 	//if we are requested to wait for the user input at the end of each page, we check whether output of next piece of text will fit into the screen
  1308 	//if we are requested to wait for the user input at the end of each page, we check whether output of next piece of text will fit into the screen
  1277 	if (aPageSwitch)
  1309 	if (aPageSwitch)
  1278 		{
  1310 		{
  1279 		key = PageSwitchDisplay(KPrompt);				
  1311 		key = PageSwitchDisplay(aNotification);				
  1280 		}
  1312 		}
  1281 	//output current string
  1313 
  1282 	TheConsole->Write(aBuf);
  1314     Print(aBuf);
  1283 	
  1315 	
  1284     return key;
  1316     return key;
  1285 	}
  1317 	}
       
  1318 
  1286 
  1319 
  1287 TKeyCode CShell::PageSwitchDisplay(const TDesC& aNotification)
  1320 TKeyCode CShell::PageSwitchDisplay(const TDesC& aNotification)
  1288 	{
  1321 	{
  1289 	//create variable to store code of the key pressed by the user
  1322 	//create variable to store code of the key pressed by the user
  1290 	TKeyCode key=EKeyNull;	
  1323 	TKeyCode key=EKeyNull;	
  1311 		TheConsole->ClearScreen();
  1344 		TheConsole->ClearScreen();
  1312 		TheConsole->SetCursorPosAbs(TPoint (previous_cursor_pos_x,0)) ;			
  1345 		TheConsole->SetCursorPosAbs(TPoint (previous_cursor_pos_x,0)) ;			
  1313 		}						
  1346 		}						
  1314 	return key;			
  1347 	return key;			
  1315 	}
  1348 	}
       
  1349 
       
  1350 
       
  1351 
       
  1352 
       
  1353 
       
  1354