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