userlibandfileserver/fileserver/etshell/ts_com.cpp
branchRCL_3
changeset 43 c1f20ce4abcf
parent 42 a179b74831c9
child 44 3e88ff8f41d5
equal deleted inserted replaced
42:a179b74831c9 43:c1f20ce4abcf
    40 TBool CShell::iDbgPrint = EFalse;
    40 TBool CShell::iDbgPrint = EFalse;
    41 
    41 
    42 //	lint -e40,e30
    42 //	lint -e40,e30
    43 const TShellCommand CShell::iCommand[ENoShellCommands]=
    43 const TShellCommand CShell::iCommand[ENoShellCommands]=
    44 	{
    44 	{
       
    45 //	TShellCommand(_L("BLANK"),_L("Help"),_L("-?"),TShellCommand::EDSwitch,ShellFunction::BLANK),
    45 	TShellCommand(_L("ATTRIB"),_L("Displays or changes file attributes"),_L("[drive:][path][filename] [+R | -R] [+H |-H] [+S | -S] [+A | -A] [/p]\n\n  /p - Pause after each screen of information"), TShellCommand::EPSwitch, ShellFunction::Attrib),
    46 	TShellCommand(_L("ATTRIB"),_L("Displays or changes file attributes"),_L("[drive:][path][filename] [+R | -R] [+H |-H] [+S | -S] [+A | -A] [/p]\n\n  /p - Pause after each screen of information"), TShellCommand::EPSwitch, ShellFunction::Attrib),
    46 	TShellCommand(_L("CD"),_L("Change the current directory for a drive"),_L("[path] [/d]\n\n  /d - Change drive"),TShellCommand::EDSwitch,ShellFunction::Cd),
    47 	TShellCommand(_L("CD"),_L("Change the current directory for a drive"),_L("[path] [/d]\n\n  /d - Change drive"),TShellCommand::EDSwitch,ShellFunction::Cd),
    47 	TShellCommand(_L("CHKDEPS"),_L("Check the dependencies of an executable or a Dll (ARM only)"),_L("[Filename.EXE] or [Filename.DLL]"),0,ShellFunction::ChkDeps),
    48 	TShellCommand(_L("CHKDEPS"),_L("Check the dependencies of an executable or a Dll (ARM only)"),_L("[Filename.EXE] or [Filename.DLL]"),0,ShellFunction::ChkDeps),
    48 	TShellCommand(_L("CHKDSK"),_L("Check disk for corruption"),_L("[drive:] [/s][/f|/u]\n\n/s - start ScanDrive instead of CheckDisk\n/f - finalise drive\n/u - unfinalise drive"),TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::EUSwitch,ShellFunction::ChkDsk),
    49 	TShellCommand(_L("CHKDSK"),_L("Check disk for corruption"),_L("[drive:] [/s][/f|/u]\n\n/s - start ScanDrive instead of CheckDisk\n/f - finalise drive\n/u - unfinalise drive"),TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::EUSwitch,ShellFunction::ChkDsk),
    49 	TShellCommand(_L("COPY"),_L("Copy one (or more) file(s), overwriting existing one(s)"),_L("source [destination]"),TShellCommand::ESSwitch,ShellFunction::Copy),
    50 	TShellCommand(_L("COPY"),_L("Copy one (or more) file(s), overwriting existing one(s)"),_L("source [destination]"),TShellCommand::ESSwitch,ShellFunction::Copy),
    50 	TShellCommand(_L("DEL"),_L("Delete one file"),_L("[drive:][path][filename]"),TShellCommand::ESSwitch,ShellFunction::Del),
    51 	TShellCommand(_L("DEL"),_L("Delete one file"),_L("[drive:][path][filename]"),TShellCommand::ESSwitch,ShellFunction::Del),
    51 	TShellCommand(_L("DIR"),_L("Show directory contents"),_L("[drive:][path][filename] [/p][/w]\n\n  /p - Pause after each screen of information\n  /w - Wide format"),TShellCommand::EPSwitch|TShellCommand::EWSwitch|TShellCommand::EASwitch,ShellFunction::Dir),
    52 	TShellCommand(_L("DIR"),_L("Show directory contents"),_L("[drive:][path][filename] [/p][/w]\n\n  /p - Pause after each screen of information\n  /w - Wide format"),TShellCommand::EPSwitch|TShellCommand::EWSwitch|TShellCommand::EASwitch,ShellFunction::Dir),
       
    53 //	TShellCommand(_L("EDLIN"),_L("Edit a text file"),_L("[drive:][path][filename] [/p]\n\n  /p - Pause after each screen of information"),TShellCommand::EPSwitch,ShellFunction::Edit),
    52     TShellCommand(_L("FORMAT"),_L("Format a disk"),ptrFormatHelp,TShellCommand::EQSwitch|TShellCommand::ESSwitch|TShellCommand::EESwitch|TShellCommand::EFSwitch,ShellFunction::Format),
    54     TShellCommand(_L("FORMAT"),_L("Format a disk"),ptrFormatHelp,TShellCommand::EQSwitch|TShellCommand::ESSwitch|TShellCommand::EESwitch|TShellCommand::EFSwitch,ShellFunction::Format),
    53     TShellCommand(_L("GOBBLE"),_L("Create a file"),_L("[filename] size [/e]\n\n /e - create an empty file, without writing any data"),TShellCommand::EESwitch,ShellFunction::Gobble),
    55     TShellCommand(_L("GOBBLE"),_L("Create a file"),_L("[filename] size [/e]\n\n /e - create an empty file, without writing any data"),TShellCommand::EESwitch,ShellFunction::Gobble),
    54 	TShellCommand(_L("HEXDUMP"),_L("Display the contents of a file in hexadecimal"),_L("[drive:][path][filename] [/p]\n\n  /p - Pause after each screen of information\n\n  Hit escape to exit from hexdump "),TShellCommand::EPSwitch,ShellFunction::Hexdump),
    56 	TShellCommand(_L("HEXDUMP"),_L("Display the contents of a file in hexadecimal"),_L("[drive:][path][filename] [/p]\n\n  /p - Pause after each screen of information\n\n  Hit escape to exit from hexdump "),TShellCommand::EPSwitch,ShellFunction::Hexdump),
    55 	TShellCommand(_L("LABEL"),_L("Set or return the volume label"),_L("[newlabel]"),0,ShellFunction::VolumeLabel),
    57 	TShellCommand(_L("LABEL"),_L("Set or return the volume label"),_L("[newlabel]"),0,ShellFunction::VolumeLabel),
    56 	TShellCommand(_L("MD"),_L("Make a new directory"),_L("name"),0,ShellFunction::Md),
    58 	TShellCommand(_L("MD"),_L("Make a new directory"),_L("name"),0,ShellFunction::Md),
   494 	TVolumeInfo vol;
   496 	TVolumeInfo vol;
   495 	TInt drive;
   497 	TInt drive;
   496 	TInt r=CShell::TheFs.CharToDrive(CShell::currentPath[0], drive);
   498 	TInt r=CShell::TheFs.CharToDrive(CShell::currentPath[0], drive);
   497 	if (r!=KErrNone)
   499 	if (r!=KErrNone)
   498 		return(r);
   500 		return(r);
   499 	
       
   500 	if (aPath.Length()==0)
   501 	if (aPath.Length()==0)
   501 		{
   502 		{
   502 		r=CShell::TheFs.Volume(vol, drive);
   503 		r=CShell::TheFs.Volume(vol, drive);
   503 		if (r==KErrNone)
   504 		if (r==KErrNone)
   504 			CShell::Printf(_L("Volume Label:%S\n"),&vol.iName);
   505 			CShell::TheConsole->Printf(_L("Volume = %S\n"),&vol.iName);
   505 		return(r);
   506 		return(r);
   506 		}
   507 		}
   507 	
       
   508 	r=CShell::TheFs.SetVolumeLabel(aPath, drive);
   508 	r=CShell::TheFs.SetVolumeLabel(aPath, drive);
   509 	return(r);
   509 	return(r);
   510 	}
   510 	}
   511 
   511 
   512 TInt ShellFunction::Del(TDes& aPath,TUint aSwitches)
   512 TInt ShellFunction::Del(TDes& aPath,TUint aSwitches)
   580 		aText.Remove(j);
   580 		aText.Remove(j);
   581 		}
   581 		}
   582 
   582 
   583 }
   583 }
   584 
   584 
   585 /**
   585 
   586     outputs content of the buffer to console according to settings passed in aSwitches
   586 void ShellFunction::OutputContentsToConsole(RPointerArray<HBufC>& aText,TUint aSwitches)
   587     @return ETrue if the user pressed Esc key 
   587 //outputs content of the buffer to console according to settings passed in aSwitches
   588 */
       
   589 TBool ShellFunction::OutputContentsToConsole(RPointerArray<HBufC>& aText,TUint aSwitches)
       
   590 	{
   588 	{
   591 	if ((aText.Count()>0)&&((aSwitches&TShellCommand::EWSwitch)!=0))
   589 	if ((aText.Count()>0)&&((aSwitches&TShellCommand::EWSwitch)!=0))
   592 		AlignTextIntoColumns(aText);
   590 		AlignTextIntoColumns(aText);
   593 
   591 
   594 	TKeyCode key=EKeyNull;
   592 	for (TInt i=0;i<aText.Count();i++)
   595     TInt i;
   593 		{
   596 
   594 		CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),*aText[i]);
   597     for(i=0;i<aText.Count();i++)
   595 		CShell::OutputStringToConsole(EFalse,_L("\n"));
   598 		{                                             
       
   599 		key = CShell::WriteBufToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),*aText[i]);
       
   600 		if(key == EKeyEscape)
       
   601             break;
       
   602         
       
   603         key = CShell::WriteBufToConsole(EFalse,_L("\n"));
       
   604 		if(key == EKeyEscape)
       
   605             break;
       
   606 
       
   607 		}
       
   608     
       
   609     //-- clean up string array
       
   610     for(i=0; i<aText.Count(); i++)
       
   611         {
       
   612 		delete aText[i];
   596 		delete aText[i];
   613 		}
   597 		}
   614 	
   598 	//empty string array
   615 	aText.Reset();
   599 	aText.Reset();
   616 
       
   617     return (key == EKeyEscape);
       
   618 	}
   600 	}
   619 
   601 
   620 
   602 
   621 void ShellFunction::OutputDirContentL(CDir* aDirList,RPointerArray<HBufC>& aText,TUint aSwitches)
   603 void ShellFunction::OutputDirContentL(CDir* aDirList,RPointerArray<HBufC>& aText,TUint aSwitches)
   622 //outputs content of a directory to console according to settings passed in aSwitches
   604 //outputs content of a directory to console according to settings passed in aSwitches
   623 	{
   605 	{
   624 	TInt count=aDirList->Count();
   606 	TInt count=aDirList->Count();
   625 	TInt fileCount=0, dirCount=0, printCount=0;
   607 	TInt fileCount=0, dirCount=0, printCount=0;
   626 	TInt64 byteCount=0;
   608 	TInt64 byteCount=0;
   627     TBool bBreak=EFalse;
       
   628 
   609 
   629 	//compose an array of strings describing entries in the directory
   610 	//compose an array of strings describing entries in the directory
   630 	for (TInt j=0;j<count;j++)
   611 	for (TInt j=0;j<count;j++)
   631 		{
   612 		{
   632 		HBufC* buf=NULL;
   613 		HBufC* buf=NULL;
   658 			buf = HBufC::NewL(KMaxFileName+100);//reserve additional space for the creation time information
   639 			buf = HBufC::NewL(KMaxFileName+100);//reserve additional space for the creation time information
   659 			CleanupStack::PushL(buf);
   640 			CleanupStack::PushL(buf);
   660 			TPtr name=buf->Des();
   641 			TPtr name=buf->Des();
   661 			name=entry.iName;
   642 			name=entry.iName;
   662 
   643 
   663             const TPtrC desName(entry.iName);
       
   664             const TBool bNameCut = desName.Length() > 26;
       
   665 
       
   666             _LIT(KDots, ">.."); //-- will be displayed if the name is longer than 26 characters
       
   667             _LIT(KSpc,  "   ");
       
   668 			
       
   669             
       
   670 			if (entry.IsDir())
   644 			if (entry.IsDir())
   671 				{
   645 				{
   672 				dirCount++;
   646 				dirCount++;
   673 				
   647 				name.Format(_L(" %- 26S   <DIR>         %+02d/%+02d/%- 4d  %02d:%02d:%02d.%06d"),
   674                 name.Format(_L(" %- 26S%S<DIR>         %+02d/%+02d/%- 4d  %02d:%02d:%02d.%03d"),
   648 											&entry.iName,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond());
   675 				    &desName,
       
   676                     bNameCut ? &KDots : &KSpc,
       
   677                     modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond());
       
   678 				
       
   679                 //name.Format(_L(" %- 26S   <DIR>         %+02d/%+02d/%- 4d  %02d:%02d:%02d.%06d"),
       
   680 				//							&entry.iName,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond());
       
   681 				}
   649 				}
   682 			else
   650 			else
   683 				{
   651 				{
   684 				TInt64 entrySize = entry.FileSize();
   652 				TInt64 entrySize = entry.FileSize();
   685 				byteCount+=entrySize;
   653 				byteCount+=entrySize;
   686 				fileCount++;
   654 				fileCount++;
   687 
   655  				name.Format(_L(" %- 32S%+ 15Lu   %+02d/%+02d/%- 4d  %02d:%02d:%02d.%06d"),
   688                 name.Format(_L(" %- 26S%S%-11Lu   %+02d/%+02d/%- 4d  %02d:%02d:%02d.%03d"),
   656  											&entry.iName,entrySize,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond());
   689  				    &desName,
       
   690                     bNameCut ? &KDots : &KSpc,
       
   691                     entrySize,
       
   692                     modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond());
       
   693  				
       
   694                 //name.Format(_L(" %- 32S%+ 15Lu   %+02d/%+02d/%- 4d  %02d:%02d:%02d.%06d"),
       
   695  				//							&entry.iName,entrySize,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond());
       
   696 				}
   657 				}
   697 			}
   658 			}
   698 		User::LeaveIfError(aText.Append(buf ));
   659 		User::LeaveIfError(aText.Append(buf ));
   699 		printCount++;
   660 		printCount++;
   700 		
       
   701 		//print the contents if a screen size of data is available. This will prevent huge buffer allocation.
   661 		//print the contents if a screen size of data is available. This will prevent huge buffer allocation.
   702 		if(printCount == CShell::TheConsole->ScreenSize().iHeight)
   662 		if(printCount == CShell::TheConsole->ScreenSize().iHeight)
   703 			{
   663 			{
   704 			bBreak = OutputContentsToConsole(aText,aSwitches);
   664 			OutputContentsToConsole(aText,aSwitches);
   705 			printCount=0;
   665 			printCount=0;
   706 			}
   666 			}
   707 		
       
   708 		CleanupStack::Pop();
   667 		CleanupStack::Pop();
   709 
   668 
   710         if(bBreak)
   669 		}
   711             break;    
       
   712 		}
       
   713 	
       
   714     if(bBreak)
       
   715         return; //-- the user has interrupted the listing
       
   716 
       
   717     
       
   718 	OutputContentsToConsole(aText,aSwitches);
   670 	OutputContentsToConsole(aText,aSwitches);
   719 
   671 
   720 	//---------------------------------
   672 	//output summary information
   721     //-- print out summary information
   673 	CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L("    %d File%c\n"),fileCount,(fileCount==1)?' ':'s');
   722 	TBuf<100> buf;
   674 	if (fileCount!=0)
   723     buf.Format(_L("    %d File%c"), fileCount, (fileCount==1) ? ' ':'s');
   675 		{
   724     if(fileCount > 0)
   676 		CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L("  %lu byte%c\n"),byteCount,(fileCount==1)?' ':'s');
   725 		{
   677 		}
   726         buf.AppendFormat(_L(", %LU bytes"), byteCount);
   678 
   727 		}
   679 	TBuf<50> buf;// allocate string long enough for additional information(number of directories)
   728 
       
   729     buf.Append(KNl);
       
   730     
       
   731     CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0), buf);
       
   732     
       
   733 	buf.Format(_L("    %d Director"),dirCount);
   680 	buf.Format(_L("    %d Director"),dirCount);
   734 	if (dirCount==1)
   681 	if (dirCount==1)
   735 		buf.AppendFormat(_L("y\n"));
   682 		buf.AppendFormat(_L("y\n"));
   736 	else
   683 	else
   737 		buf.AppendFormat(_L("ies\n"));
   684 		buf.AppendFormat(_L("ies\n"));
   738 
   685 
   739 	CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),buf);
   686 	CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),buf);
   740 
       
   741     
       
   742 	}
   687 	}
   743 
   688 
   744 TInt ShellFunction::Dir(TDes& aPath,TUint aSwitches)
   689 TInt ShellFunction::Dir(TDes& aPath,TUint aSwitches)
   745 //
   690 //
   746 //	Modified December 1997, to sort entries alphabetically
   691 //	Modified December 1997, to sort entries alphabetically
   762 	else file.Close();
   707 	else file.Close();
   763 
   708 
   764 	TInt r=dir.Open(TheShell->TheFs,aPath,KEntryAttMaskSupported);
   709 	TInt r=dir.Open(TheShell->TheFs,aPath,KEntryAttMaskSupported);
   765 	if (r!=KErrNone)
   710 	if (r!=KErrNone)
   766 		{
   711 		{
   767 		CShell::Printf(_L("File or directory not found\n"));
   712 		CShell::TheConsole->Printf(_L("File or directory not found\n"));
   768 		return(KErrNone);
   713 		return(KErrNone);
   769 		}
   714 		}
   770 
   715 
   771 	CDir* anEntryList;
   716 	CDir* anEntryList;
   772 	r=TheShell->TheFs.GetDir(aPath,KEntryAttMaskSupported,ESortByName,anEntryList);
   717 	r=TheShell->TheFs.GetDir(aPath,KEntryAttMaskSupported,ESortByName,anEntryList);
   777 		}
   722 		}
   778     CleanupStack::PushL(anEntryList);
   723     CleanupStack::PushL(anEntryList);
   779 
   724 
   780 	//Sets the new length of path to the position of the last path delimiter +1
   725 	//Sets the new length of path to the position of the last path delimiter +1
   781 	aPath.SetLength(aPath.LocateReverse(KPathDelimiter)+1);
   726 	aPath.SetLength(aPath.LocateReverse(KPathDelimiter)+1);
   782 	CShell::Printf(_L("Directory of %S\n"),&aPath);
   727 	CShell::TheConsole->Printf(_L("Directory of %S\n"),&aPath);
   783 
   728 
   784 	//allocate array to be used as an output buffer
   729 	//allocate array to be used as an output buffer
   785 	RPointerArray<HBufC>* text=new(ELeave) RPointerArray<HBufC>();
   730 	RPointerArray<HBufC>* text=new(ELeave) RPointerArray<HBufC>();
   786 	TRAPD(error,OutputDirContentL(anEntryList,*text,aSwitches));
   731 	TRAPD(error,OutputDirContentL(anEntryList,*text,aSwitches));
   787 	//we are not interesed in the error code because we need empty the buffer in any case
   732 	//we are not interesed in the error code because we need empty the buffer in any case
   795 	else
   740 	else
   796 		return(KErrNone);
   741 		return(KErrNone);
   797 	};
   742 	};
   798 
   743 
   799 
   744 
       
   745 TInt ShellFunction::Edit(TDes& /*aPath*/,TUint /*aSwitches*/)
       
   746 //
       
   747 //	Dummy, used by edlin (now retired)
       
   748 //
       
   749 	{
       
   750 	return(KErrNone);
       
   751 	}
   800 
   752 
   801 
   753 
   802 TInt ShellFunction::Attrib(TDes& aPath,TUint aSwitches)
   754 TInt ShellFunction::Attrib(TDes& aPath,TUint aSwitches)
   803 {
   755 {
   804 	ShellFunction::StripQuotes(aPath);
   756 	ShellFunction::StripQuotes(aPath);
  1053         if(aDrvInfo.iDriveAtt & KDriveAttLocal)         aPrintBuf.Append(_L("KDriveAttLocal,"));
  1005         if(aDrvInfo.iDriveAtt & KDriveAttLocal)         aPrintBuf.Append(_L("KDriveAttLocal,"));
  1054         if(aDrvInfo.iDriveAtt & KDriveAttRom)           aPrintBuf.Append(_L("KDriveAttRom,"));
  1006         if(aDrvInfo.iDriveAtt & KDriveAttRom)           aPrintBuf.Append(_L("KDriveAttRom,"));
  1055         if(aDrvInfo.iDriveAtt & KDriveAttRedirected)    aPrintBuf.Append(_L("KDriveAttRedirected,"));
  1007         if(aDrvInfo.iDriveAtt & KDriveAttRedirected)    aPrintBuf.Append(_L("KDriveAttRedirected,"));
  1056         if(aDrvInfo.iDriveAtt & KDriveAttSubsted)       aPrintBuf.Append(_L("KDriveAttSubsted,"));
  1008         if(aDrvInfo.iDriveAtt & KDriveAttSubsted)       aPrintBuf.Append(_L("KDriveAttSubsted,"));
  1057         if(aDrvInfo.iDriveAtt & KDriveAttInternal)      aPrintBuf.Append(_L("KDriveAttInternal,"));
  1009         if(aDrvInfo.iDriveAtt & KDriveAttInternal)      aPrintBuf.Append(_L("KDriveAttInternal,"));
  1058         if(aDrvInfo.iDriveAtt & KDriveAttRemovable)     aPrintBuf.Append(_L("KDriveAttRemovable,"));
  1010         if(aDrvInfo.iDriveAtt & KDriveAttRemovable)     aPrintBuf.Append(_L("KDriveAttRemovable"));
  1059 
  1011 
  1060         if(aDrvInfo.iDriveAtt & KDriveAttRemote)        aPrintBuf.Append(_L("KDriveAttRemote,"));
  1012         if(aDrvInfo.iDriveAtt & KDriveAttRemote)        aPrintBuf.Append(_L("KDriveAttRemote"));
  1061         if(aDrvInfo.iDriveAtt & KDriveAttTransaction)   aPrintBuf.Append(_L("KDriveAttTransaction,"));
  1013         if(aDrvInfo.iDriveAtt & KDriveAttTransaction)   aPrintBuf.Append(_L("KDriveAttTransaction"));
  1062 
  1014 
  1063         if(aDrvInfo.iDriveAtt & KDriveAttPageable)              aPrintBuf.Append(_L("KDriveAttPageable,"));
  1015         if(aDrvInfo.iDriveAtt & KDriveAttPageable)              aPrintBuf.Append(_L("KDriveAttPageable"));
  1064         if(aDrvInfo.iDriveAtt & KDriveAttLogicallyRemovable)    aPrintBuf.Append(_L("KDriveAttLogicallyRemovable,"));
  1016         if(aDrvInfo.iDriveAtt & KDriveAttLogicallyRemovable)    aPrintBuf.Append(_L("KDriveAttLogicallyRemovable"));
  1065         if(aDrvInfo.iDriveAtt & KDriveAttHidden)                aPrintBuf.Append(_L("KDriveAttHidden,"));
  1017         if(aDrvInfo.iDriveAtt & KDriveAttHidden)                aPrintBuf.Append(_L("KDriveAttHidden"));
  1066 
  1018 
  1067         aPrintBuf.Append(_L("\n"));
  1019         aPrintBuf.Append(_L("\n"));
  1068     }
  1020     }
  1069 
  1021 
  1070 //--------------------------------------------------------
  1022 //--------------------------------------------------------
  1082         if(aDrvInfo.iMediaAtt & KMediaAttVariableSize)      aPrintBuf.Append(_L("KMediaAttVariableSize,"));
  1034         if(aDrvInfo.iMediaAtt & KMediaAttVariableSize)      aPrintBuf.Append(_L("KMediaAttVariableSize,"));
  1083         if(aDrvInfo.iMediaAtt & KMediaAttDualDensity)       aPrintBuf.Append(_L("KMediaAttDualDensity,"));
  1035         if(aDrvInfo.iMediaAtt & KMediaAttDualDensity)       aPrintBuf.Append(_L("KMediaAttDualDensity,"));
  1084         if(aDrvInfo.iMediaAtt & KMediaAttFormattable)       aPrintBuf.Append(_L("KMediaAttFormattable,"));
  1036         if(aDrvInfo.iMediaAtt & KMediaAttFormattable)       aPrintBuf.Append(_L("KMediaAttFormattable,"));
  1085         if(aDrvInfo.iMediaAtt & KMediaAttWriteProtected)    aPrintBuf.Append(_L("KMediaAttWriteProtected,"));
  1037         if(aDrvInfo.iMediaAtt & KMediaAttWriteProtected)    aPrintBuf.Append(_L("KMediaAttWriteProtected,"));
  1086         if(aDrvInfo.iMediaAtt & KMediaAttLockable)          aPrintBuf.Append(_L("KMediaAttLockable,"));
  1038         if(aDrvInfo.iMediaAtt & KMediaAttLockable)          aPrintBuf.Append(_L("KMediaAttLockable,"));
  1087         if(aDrvInfo.iMediaAtt & KMediaAttLocked)            aPrintBuf.Append(_L("KMediaAttLocked,"));
  1039         if(aDrvInfo.iMediaAtt & KMediaAttLocked)            aPrintBuf.Append(_L("KMediaAttLocked"));
  1088 
  1040 
  1089         if(aDrvInfo.iMediaAtt & KMediaAttHasPassword)       aPrintBuf.Append(_L("KMediaAttHasPassword,"));
  1041         if(aDrvInfo.iMediaAtt & KMediaAttHasPassword)       aPrintBuf.Append(_L("KMediaAttHasPassword"));
  1090         if(aDrvInfo.iMediaAtt & KMediaAttReadWhileWrite)    aPrintBuf.Append(_L("KMediaAttReadWhileWrite,"));
  1042         if(aDrvInfo.iMediaAtt & KMediaAttReadWhileWrite)    aPrintBuf.Append(_L("KMediaAttReadWhileWrite"));
  1091         if(aDrvInfo.iMediaAtt & KMediaAttDeleteNotify)      aPrintBuf.Append(_L("KMediaAttDeleteNotify,"));
  1043         if(aDrvInfo.iMediaAtt & KMediaAttDeleteNotify)      aPrintBuf.Append(_L("KMediaAttDeleteNotify"));
  1092         if(aDrvInfo.iMediaAtt & KMediaAttPageable)          aPrintBuf.Append(_L("KMediaAttPageable,"));
  1044         if(aDrvInfo.iMediaAtt & KMediaAttPageable)          aPrintBuf.Append(_L("KMediaAttPageable"));
  1093         
  1045         
  1094 
  1046 
  1095         aPrintBuf.Append(_L("\n"));
  1047         aPrintBuf.Append(_L("\n"));
  1096     }
  1048     }
  1097 
  1049 
  1209                  Buf.AppendFormat(_L(" PExt:%S"), &fsName);
  1161                  Buf.AppendFormat(_L(" PExt:%S"), &fsName);
  1210             }
  1162             }
  1211 
  1163 
  1212             CShell::Printf(_L("Mounted FS:%S\n"), &Buf);
  1164             CShell::Printf(_L("Mounted FS:%S\n"), &Buf);
  1213 
  1165 
  1214             //-- print out the list of supported file systems if there are more than 0
  1166             //-- print out the list of supported file systems if there are more than 1
  1215             nRes = aFs.SupportedFileSystemName(fsName, aDrvNum, 0); //-- try to get 1st child name
  1167             nRes = aFs.SupportedFileSystemName(fsName, aDrvNum, 0+1); //-- try to get 2nd child name
  1216             if(nRes == KErrNone)
  1168             if(nRes == KErrNone)
  1217             {
  1169             {
  1218                 Buf.Copy(_L("Supported FS: "));
  1170                 Buf.Copy(_L("Supported FS: "));
  1219                 for(TInt i=0; ;++i)
  1171                 for(TInt i=0; ;++i)
  1220                 {
  1172                 {
  1482         
  1434         
  1483     if(!aForceDismount)    
  1435     if(!aForceDismount)    
  1484     {//-- gaceful attempt to dismount the FS
  1436     {//-- gaceful attempt to dismount the FS
  1485     nRes = aFs.DismountFileSystem(fsName, aDrvNum);
  1437     nRes = aFs.DismountFileSystem(fsName, aDrvNum);
  1486     if(nRes != KErrNone)
  1438     if(nRes != KErrNone)
  1487     {
  1439         {
  1488         CShell::TheConsole->Printf(_L("Can't dismount FS!\n"));
  1440         CShell::TheConsole->Printf(_L("Can't dismount FS!\n"));
  1489         return nRes;
  1441         return nRes;
  1490     }
  1442         }
  1491     else
  1443     else
  1492     {
  1444         {
  1493     CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum);
  1445         CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum);
  1494     return KErrNone;
  1446         return KErrNone;
  1495     }
  1447         }
  1496 }
  1448     }
  1497     else
  1449     else
  1498     {//-- dismount by force
  1450     {//-- dismount by force
  1499         TRequestStatus rqStat;
  1451         TRequestStatus rqStat;
  1500         aFs.NotifyDismount(aDrvNum, rqStat, EFsDismountForceDismount);  
  1452         aFs.NotifyDismount(aDrvNum, rqStat, EFsDismountForceDismount);  
  1501         User::WaitForRequest(rqStat);
  1453         User::WaitForRequest(rqStat);
  2052     
  2004     
  2053     return nRes;
  2005     return nRes;
  2054     }
  2006     }
  2055 
  2007 
  2056 //-----------------------------------------------------------------------------------------------------------------------
  2008 //-----------------------------------------------------------------------------------------------------------------------
  2057 /**
  2009 
  2058     Hex Dump of a file
       
  2059 */
       
  2060 TInt ShellFunction::Hexdump(TDes& aPath,TUint aSwitches)
  2010 TInt ShellFunction::Hexdump(TDes& aPath,TUint aSwitches)
  2061 	{
  2011 	{
  2062 	ShellFunction::StripQuotes(aPath);
  2012 	ShellFunction::StripQuotes(aPath);
  2063 
  2013 
  2064 	ParsePath(aPath);
  2014 	ParsePath(aPath);
  2065 	
       
  2066 	RFile64 file;
  2015 	RFile64 file;
  2067 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStream);
  2016 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStream);
  2068 	if (r!=KErrNone)
  2017 	if (r!=KErrNone)
  2069 		return(r);
  2018 		return(r);
  2070 
  2019 
       
  2020 	TInt offset=0;
       
  2021 	for (;;)
       
  2022 		{
  2071 		const TInt KLineLength = 16;
  2023 		const TInt KLineLength = 16;
  2072     TBuf<0x100> buf;
  2024 
  2073     TBuf<KLineLength> asciiBuf;
       
  2074 		TBuf8<KLineLength> line;
  2025 		TBuf8<KLineLength> line;
  2075 
       
  2076 	for (;;)
       
  2077 		{
       
  2078 		r=file.Read(line);
  2026 		r=file.Read(line);
  2079 		if (r != KErrNone || line.Length() == 0)
  2027 		if (r != KErrNone || line.Length() == 0)
  2080 			break;
  2028 			break;
  2081 
  2029 
  2082 		buf.Zero();
  2030 		TBuf<KLineLength*3+2> hexaRep;
  2083         asciiBuf.Zero();
  2031 		TBuf<KLineLength> asciiRep;
  2084 		
       
  2085 		for (TInt i=0; i<KLineLength; i++)
  2032 		for (TInt i=0; i<KLineLength; i++)
  2086 			{
  2033 			{
  2087 			if (i == KLineLength/2)
  2034 			if (i == KLineLength/2)
  2088 				{
  2035 				{
  2089 				buf.Append(' ');
  2036 				hexaRep.Append(' ');
  2090 				buf.Append(i<line.Length() ? '|' : ' ');
  2037 				hexaRep.Append(i<line.Length() ? '|' : ' ');
  2091 				}
  2038 				}
  2092 
  2039 
  2093             buf.Append(' ');
  2040 			hexaRep.Append(' ');
  2094 
  2041 
  2095 			if (i<line.Length())
  2042 			if (i<line.Length())
  2096 				{
  2043 				{
  2097 				buf.AppendNumFixedWidth(line[i], EHex, 2);
  2044 				hexaRep.AppendNumFixedWidth(line[i], EHex, 2);
  2098 				asciiBuf.Append(TChar(line[i]).IsPrint() ? line[i] : '.');
  2045 				asciiRep.Append(TChar(line[i]).IsPrint() ? line[i] : '.');
  2099 				}
  2046 				}
  2100 			else
  2047 			else
  2101 				buf.AppendFill(' ', 2);
  2048 				hexaRep.AppendFill(' ', 2);
  2102 			}
  2049 			}
  2103 
  2050 
  2104 		_LIT(KPrompt , " Hit escape to quit hexdump or any other key to continue\n");
  2051 		_LIT(KPrompt , " Hit escape to quit hexdump or any other key to continue\n");
  2105 		
  2052 		_LIT(KLineFmt, " %+07x0:%S %S\n");
  2106         buf.Append(_L(" "));
  2053 		TKeyCode key=CShell::OutputStringToConsole(KPrompt ,(aSwitches&TShellCommand::EPSwitch)!=0,KLineFmt, offset++,&hexaRep, &asciiRep);
  2107         buf.Append(asciiBuf);
  2054 
  2108         buf.Append(KNl);
       
  2109 
       
  2110         TKeyCode key= CShell::WriteBufToConsole((aSwitches&TShellCommand::EPSwitch)!=0, buf, KPrompt);
       
  2111 		if (key==EKeyEscape)
  2055 		if (key==EKeyEscape)
  2112 				break;
  2056 				break;
  2113 		}
  2057 		}
  2114 
  2058 
  2115 	if (r == KErrNone)
  2059 	if (r == KErrNone)
  2209     if(r != KErrNone)
  2153     if(r != KErrNone)
  2210         goto fail;
  2154         goto fail;
  2211 
  2155 
  2212 
  2156 
  2213     if(!(aSwitches&TShellCommand::EESwitch))
  2157     if(!(aSwitches&TShellCommand::EESwitch))
  2214     {//-- fill created file with random data
  2158     {//-- fill created file with randomn data
  2215 
  2159 
  2216 	    while(rem)
  2160 	    while(rem)
  2217 	    {
  2161 	    {
  2218 	        const TInt s=(TInt)Min((TInt64)KBufSize, rem);
  2162 	        const TInt s=(TInt)Min((TInt64)KBufSize, rem);
  2219 
  2163 
  2432 	{
  2376 	{
  2433 public:
  2377 public:
  2434 	TInt DisplayHelp();
  2378 	TInt DisplayHelp();
  2435 	TInt DisplayMessage(const TFullName& aName);
  2379 	TInt DisplayMessage(const TFullName& aName);
  2436 	TInt DisplayCmdUnknown();
  2380 	TInt DisplayCmdUnknown();
  2437 	void GetAll(const TDes& aName);
  2381 	TInt GetAll(const TDes& aName);
  2438 	void GetProcesses(const TDes& aName);
  2382 	TInt GetProcesses(const TDes& aName);
  2439 	void GetThreads(const TDes& aName);
  2383 	TInt GetThreads(const TDes& aName);
  2440 	void GetChunks(const TDes& aName);
  2384 	TInt GetChunks(const TDes& aName);
  2441 	void GetServers(const TDes& aName);
  2385 	TInt GetServers(const TDes& aName);
  2442 //	TInt GetSessions(const TDes& aName);
  2386 //	TInt GetSessions(const TDes& aName);
  2443 	void GetLibraries(const TDes& aName);
  2387 	TInt GetLibraries(const TDes& aName);
  2444 //	TInt GetLogicalChannels(const TDes& aName);
  2388 //	TInt GetLogicalChannels(const TDes& aName);
  2445 	void GetLogicalDevices(const TDes& aName);
  2389 	TInt GetLogicalDevices(const TDes& aName);
  2446 	void GetPhysicalDevices(const TDes& aName);
  2390 	TInt GetPhysicalDevices(const TDes& aName);
  2447 	void GetSemaphores(const TDes& aName);
  2391 	TInt GetSemaphores(const TDes& aName);
  2448 	void GetMutexes(const TDes& aName);
  2392 	TInt GetMutexes(const TDes& aName);
  2449 private:
  2393 private:
  2450 	void DisplayHelpLine(const TDesC& aCommand, const TDesC& aDescription);
  2394 	void DisplayHelpLine(const TDesC& aCommand, const TDesC& aDescription);
  2451 	TBool Prepare(const TFullName& aName);
  2395 	TInt Prepare(const TFullName& aName);
  2452 	TBool Prepare(const TFullName& aName,TCallBack& aCallBack);
  2396 	TInt Prepare(const TFullName& aName,TCallBack& aCallBack);
  2453 	TInt Display(TFullName& aName);
  2397 	TInt Display(TFullName& aName);
  2454 	TFullName iPrevName;
  2398 	TFullName iPrevName;
  2455 	TCallBack iCallBack;
  2399 	TCallBack iCallBack;
  2456 	TBool useCallBack;
  2400 	TBool useCallBack;
  2457 	};
  2401 	};
  2489 	{
  2433 	{
  2490 	CShell::OutputStringToConsole(ETrue,_L("Not supported\n"));
  2434 	CShell::OutputStringToConsole(ETrue,_L("Not supported\n"));
  2491 	return KErrNone;
  2435 	return KErrNone;
  2492 	}
  2436 	}
  2493 
  2437 
  2494 void TShowProcInfo::GetAll(const TDes& aName)
  2438 TInt TShowProcInfo::GetAll(const TDes& aName)
  2495 	{
  2439 	{
       
  2440 
  2496 	GetProcesses(aName);
  2441 	GetProcesses(aName);
  2497 	GetThreads(aName);
  2442 	GetThreads(aName);
  2498 	GetChunks(aName);
  2443 	GetChunks(aName);
  2499 	GetServers(aName);
  2444 	GetServers(aName);
  2500 //	GetSessions(aName);
  2445 //	GetSessions(aName);
  2502 //	GetLogicalChannels(aName);
  2447 //	GetLogicalChannels(aName);
  2503 	GetLogicalDevices(aName);
  2448 	GetLogicalDevices(aName);
  2504 	GetPhysicalDevices(aName);
  2449 	GetPhysicalDevices(aName);
  2505 	GetSemaphores(aName);
  2450 	GetSemaphores(aName);
  2506 	GetMutexes(aName);
  2451 	GetMutexes(aName);
  2507 
  2452 	return KErrNone;
  2508 	}
  2453 	}
  2509 
  2454 
  2510 void TShowProcInfo::GetProcesses(const TDes& aName)
  2455 TInt TShowProcInfo::GetProcesses(const TDes& aName)
  2511 	{
  2456 	{
  2512 
  2457 
  2513 	TFindProcess findHb;
  2458 	TFindProcess findHb;
  2514 	findHb.Find(aName);
  2459 	findHb.Find(aName);
  2515 	TFullName name;
  2460 	TFullName name;
  2516 	
  2461 	Prepare(_L("PROCESSES"));
  2517     if(!Prepare(_L("PROCESSES")))
       
  2518        return;
       
  2519 
       
  2520 	while (findHb.Next(name)==KErrNone)
  2462 	while (findHb.Next(name)==KErrNone)
  2521 		{
  2463 		{
  2522 		Display(name);
  2464 		Display(name);
  2523 		}
  2465 		}
  2524 
  2466 	return KErrNone;
  2525 	}
  2467 	}
  2526 
  2468 
  2527 void TShowProcInfo::GetThreads(const TDes& aName)
  2469 TInt TShowProcInfo::GetThreads(const TDes& aName)
  2528 	{
  2470 	{
  2529 	TInt threads=0;
  2471 	TInt threads=0;
  2530 	TFindThread findHb;
  2472 	TFindThread findHb;
  2531 	findHb.Find(aName);
  2473 	findHb.Find(aName);
  2532 	TFullName name;
  2474 	TFullName name;
  2533 	TAny* findPtr=(TAny*)&findHb;
  2475 	TAny* findPtr=(TAny*)&findHb;
  2534 
  2476 
  2535 //	Modified by WR, November 1997
  2477 //	Modified by WR, November 1997
  2536 	TCallBack threadCallBack(GetThreadInfo,findPtr);
  2478 	TCallBack threadCallBack(GetThreadInfo,findPtr);
  2537 	
  2479 	Prepare(_L("THREADS"),threadCallBack);
  2538     if(!Prepare(_L("THREADS"),threadCallBack))
       
  2539         return;
       
  2540 
       
  2541 	while (findHb.Next(name)==KErrNone)
  2480 	while (findHb.Next(name)==KErrNone)
  2542 		{
  2481 		{
  2543 		Display(name);
  2482 		Display(name);
  2544 		threads += 1;
  2483 		threads += 1;
  2545 		}
  2484 		}
  2547 		{
  2486 		{
  2548 		TFullName message;
  2487 		TFullName message;
  2549 		message.Format(_L("? No threads called %S"), &aName);
  2488 		message.Format(_L("? No threads called %S"), &aName);
  2550 		DisplayMessage(message);
  2489 		DisplayMessage(message);
  2551 		}
  2490 		}
  2552 	
  2491 	return KErrNone;
  2553     
  2492 //	End of modification
  2554 	}
  2493 	}
  2555 
  2494 
  2556 
  2495 
  2557 void TShowProcInfo::GetChunks(const TDes& aName)
  2496 TInt TShowProcInfo::GetChunks(const TDes& aName)
  2558 	{
  2497 	{
  2559 
  2498 
  2560 	TFindChunk findHb;
  2499 	TFindChunk findHb;
  2561 	findHb.Find(aName);
  2500 	findHb.Find(aName);
  2562 	TFullName name;
  2501 	TFullName name;
  2563 	TAny* namePtr=(TAny*)&name;
  2502 	TAny* namePtr=(TAny*)&name;
  2564 	TCallBack chunkCallBack(GetChunkInfo,namePtr);
  2503 	TCallBack chunkCallBack(GetChunkInfo,namePtr);
  2565 	
  2504 	Prepare(_L("CHUNKS & SIZES"),chunkCallBack);
  2566     if(!Prepare(_L("CHUNKS & SIZES"),chunkCallBack))
       
  2567         return;
       
  2568 
       
  2569 	TInt totalChunkSize=0;
  2505 	TInt totalChunkSize=0;
  2570 	TInt protectedChunks = 0;
  2506 	TInt protectedChunks = 0;
  2571 	while (findHb.Next(name)==KErrNone)
  2507 	while (findHb.Next(name)==KErrNone)
  2572 		{
  2508 		{
  2573 		Display(name);
  2509 		Display(name);
  2590 */
  2526 */
  2591 		}
  2527 		}
  2592 	CShell::OutputStringToConsole(ETrue,_L("  Total Chunk Size = %dk\n"),totalChunkSize);
  2528 	CShell::OutputStringToConsole(ETrue,_L("  Total Chunk Size = %dk\n"),totalChunkSize);
  2593 	if(protectedChunks)
  2529 	if(protectedChunks)
  2594 		CShell::OutputStringToConsole(ETrue,_L("  %d Protected chunks not counted\n"),protectedChunks);
  2530 		CShell::OutputStringToConsole(ETrue,_L("  %d Protected chunks not counted\n"),protectedChunks);
  2595 	
  2531 	return KErrNone;
  2596     
  2532 	}
  2597 	}
  2533 
  2598 
  2534 TInt TShowProcInfo::GetServers(const TDes& aName)
  2599 void TShowProcInfo::GetServers(const TDes& aName)
       
  2600 	{
  2535 	{
  2601 
  2536 
  2602 	TFindServer findHb;
  2537 	TFindServer findHb;
  2603 	findHb.Find(aName);
  2538 	findHb.Find(aName);
  2604 	TFullName name;
  2539 	TFullName name;
  2605 	if(!Prepare(_L("SERVERS")))
  2540 	Prepare(_L("SERVERS"));
  2606         return;
       
  2607 
       
  2608 	while (findHb.Next(name)==KErrNone)
  2541 	while (findHb.Next(name)==KErrNone)
  2609 		{
  2542 		{
  2610 		Display(name);
  2543 		Display(name);
  2611 		}
  2544 		}
       
  2545 	return KErrNone;
  2612 	}
  2546 	}
  2613 
  2547 
  2614 /*	TInt TShowProcInfo::GetSessions(const TDes& aName)
  2548 /*	TInt TShowProcInfo::GetSessions(const TDes& aName)
  2615 	{
  2549 	{
  2616 
  2550 
  2623 		Display(name);
  2557 		Display(name);
  2624 		}
  2558 		}
  2625 	return KErrNone;
  2559 	return KErrNone;
  2626 	}
  2560 	}
  2627 */
  2561 */
  2628 void TShowProcInfo::GetLibraries(const TDes& aName)
  2562 TInt TShowProcInfo::GetLibraries(const TDes& aName)
  2629 	{
  2563 	{
  2630 
  2564 
  2631 	TFindLibrary findHb;
  2565 	TFindLibrary findHb;
  2632 	findHb.Find(aName);
  2566 	findHb.Find(aName);
  2633 	TFullName name;
  2567 	TFullName name;
  2634 	if(!Prepare(_L("LIBRARIES")))
  2568 	Prepare(_L("LIBRARIES"));
  2635         return;
       
  2636 
       
  2637 	while (findHb.Next(name)==KErrNone)
  2569 	while (findHb.Next(name)==KErrNone)
  2638 		{
  2570 		{
  2639 		Display(name);
  2571 		Display(name);
  2640 		}
  2572 		}
  2641 	
  2573 	return KErrNone;
  2642 	}
  2574 	}
  2643 /*
  2575 /*
  2644 TInt TShowProcInfo::GetLogicalChannels(const TDes& aName)
  2576 TInt TShowProcInfo::GetLogicalChannels(const TDes& aName)
  2645 	{
  2577 	{
  2646 
  2578 
  2654 		}
  2586 		}
  2655 	return KErrNone;
  2587 	return KErrNone;
  2656 	}
  2588 	}
  2657 */
  2589 */
  2658 
  2590 
  2659 void TShowProcInfo::GetLogicalDevices(const TDes& aName)
  2591 TInt TShowProcInfo::GetLogicalDevices(const TDes& aName)
  2660 	{
  2592 	{
  2661 
  2593 
  2662 	TFindLogicalDevice findHb;
  2594 	TFindLogicalDevice findHb;
  2663 	findHb.Find(aName);
  2595 	findHb.Find(aName);
  2664 	TFullName name;
  2596 	TFullName name;
  2665 
  2597 	Prepare(_L("LOGICAL DEVICES"));
  2666 	if(!Prepare(_L("LOGICAL DEVICES")))
       
  2667         return;
       
  2668 
       
  2669 	while (findHb.Next(name)==KErrNone)
  2598 	while (findHb.Next(name)==KErrNone)
  2670 		{
  2599 		{
  2671 		Display(name);
  2600 		Display(name);
  2672 		}
  2601 		}
  2673 	
  2602 	return KErrNone;
  2674 	}
  2603 	}
  2675 
  2604 
  2676 void TShowProcInfo::GetPhysicalDevices(const TDes& aName)
  2605 TInt TShowProcInfo::GetPhysicalDevices(const TDes& aName)
  2677 	{
  2606 	{
  2678 
  2607 
  2679 	TFindPhysicalDevice findHb;
  2608 	TFindPhysicalDevice findHb;
  2680 	findHb.Find(aName);
  2609 	findHb.Find(aName);
  2681 	TFullName name;
  2610 	TFullName name;
  2682 	
  2611 	Prepare(_L("PHYSICAL DEVICES"));
  2683     if(!Prepare(_L("PHYSICAL DEVICES")))
       
  2684         return;
       
  2685 
       
  2686 	while (findHb.Next(name)==KErrNone)
  2612 	while (findHb.Next(name)==KErrNone)
  2687 		{
  2613 		{
  2688 		Display(name);
  2614 		Display(name);
  2689 		}
  2615 		}
  2690 	
  2616 	return KErrNone;
  2691 	}
  2617 	}
  2692 
  2618 
  2693 void TShowProcInfo::GetSemaphores(const TDes& aName)
  2619 TInt TShowProcInfo::GetSemaphores(const TDes& aName)
  2694 	{
  2620 	{
  2695 	TFindSemaphore findHb;
  2621 	TFindSemaphore findHb;
  2696 	findHb.Find(aName);
  2622 	findHb.Find(aName);
  2697 	TFullName name;
  2623 	TFullName name;
  2698 	if(!Prepare(_L("SEMAPHORES")))
  2624 	Prepare(_L("SEMAPHORES"));
  2699         return;
       
  2700 
       
  2701 	while (findHb.Next(name)==KErrNone)
  2625 	while (findHb.Next(name)==KErrNone)
  2702 		{
  2626 		{
  2703 		Display(name);
  2627 		Display(name);
  2704 		}
  2628 		}
  2705 	
  2629 	return KErrNone;
  2706 	}
  2630 	}
  2707 
  2631 
  2708 void TShowProcInfo::GetMutexes(const TDes& aName)
  2632 TInt TShowProcInfo::GetMutexes(const TDes& aName)
  2709 	{
  2633 	{
  2710 
  2634 
  2711 	TFindMutex findHb;
  2635 	TFindMutex findHb;
  2712 	findHb.Find(aName);
  2636 	findHb.Find(aName);
  2713 	TFullName name;
  2637 	TFullName name;
  2714 	if(!Prepare(_L("MUTEXES")))
  2638 	Prepare(_L("MUTEXES"));
  2715         return;
       
  2716 	while (findHb.Next(name)==KErrNone)
  2639 	while (findHb.Next(name)==KErrNone)
  2717 		{
  2640 		{
  2718 		Display(name);
  2641 		Display(name);
  2719 		}
  2642 		}
  2720 	
  2643 	return KErrNone;
  2721 	}
  2644 	}
  2722 
  2645 
  2723 void TShowProcInfo::DisplayHelpLine(const TDesC& aCommand, const TDesC& aDescription)
  2646 void TShowProcInfo::DisplayHelpLine(const TDesC& aCommand, const TDesC& aDescription)
  2724 	{
  2647 	{
  2725 	CShell::OutputStringToConsole(ETrue,_L("%- *S%S\n"),8,&aCommand,&aDescription);
  2648 	CShell::OutputStringToConsole(ETrue,_L("%- *S%S\n"),8,&aCommand,&aDescription);
  2726 	}
  2649 	}
  2727 
  2650 
  2728 
  2651 
  2729 TBool TShowProcInfo::Prepare(const TFullName& aName)
  2652 TInt TShowProcInfo::Prepare(const TFullName& aName)
  2730 	{
  2653 	{
  2731 
  2654 
  2732 	iPrevName=_L("");
  2655 	iPrevName=_L("");
  2733 	TKeyCode key = CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName);
  2656 	CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName);
  2734     
       
  2735     if(key==EKeyEscape)
       
  2736         return EFalse;
       
  2737 
       
  2738 	useCallBack=EFalse;
  2657 	useCallBack=EFalse;
  2739     return ETrue;
  2658 	return KErrNone;
  2740 	}
  2659 	}
  2741 
  2660 
  2742 TBool  TShowProcInfo::Prepare(const TFullName& aName,TCallBack& aCallBack)
  2661 TInt TShowProcInfo::Prepare(const TFullName& aName,TCallBack& aCallBack)
  2743 	{
  2662 	{
       
  2663 
  2744 	iPrevName=_L("");
  2664 	iPrevName=_L("");
  2745 	TKeyCode key = CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName);
  2665 	CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName);
  2746 
       
  2747     if(key==EKeyEscape)
       
  2748         return EFalse;
       
  2749 	
       
  2750     
       
  2751 	useCallBack=ETrue;
  2666 	useCallBack=ETrue;
  2752 	iCallBack=aCallBack;
  2667 	iCallBack=aCallBack;
  2753 	
  2668 	return KErrNone;
  2754     return ETrue;
       
  2755 	}
  2669 	}
  2756 
  2670 
  2757 TInt TShowProcInfo::Display(TFullName& aName)
  2671 TInt TShowProcInfo::Display(TFullName& aName)
  2758 
  2672 
  2759 //	Modifications by WR, November 1997
  2673 //	Modifications by WR, November 1997
  2782 				break;
  2696 				break;
  2783 			}
  2697 			}
  2784 		while (posA>=0)
  2698 		while (posA>=0)
  2785 			{
  2699 			{
  2786 			TPtrC16 temp_desc=aName.Left(posA);
  2700 			TPtrC16 temp_desc=aName.Left(posA);
  2787 			
  2701 			CShell::OutputStringToConsole(ETrue,_L("%+ *S\n"),toTab+temp_desc.Left(posA).Length(),&temp_desc);
  2788             TKeyCode key = CShell::OutputStringToConsole(ETrue,_L("%+ *S\n"),toTab+temp_desc.Left(posA).Length(),&temp_desc);
       
  2789 			if (key==EKeyEscape)
       
  2790 			    break;
       
  2791 
       
  2792 			toTab+=3;
  2702 			toTab+=3;
  2793 			aName.Delete(0,posA+2);
  2703 			aName.Delete(0,posA+2);
  2794 			posA=aName.Match(_L("*::*"));
  2704 			posA=aName.Match(_L("*::*"));
  2795 			}
  2705 			}
  2796 		}
  2706 		}
  2817     TBuf<0x1> asterisk=_L("*");
  2727     TBuf<0x1> asterisk=_L("*");
  2818 	TName processPrefix=asterisk;
  2728 	TName processPrefix=asterisk;
  2819 	TBool abort=EFalse;
  2729 	TBool abort=EFalse;
  2820 	TBool processSelected=EFalse;
  2730 	TBool processSelected=EFalse;
  2821 	TBuf<0x16> prompt=_L("ps>");
  2731 	TBuf<0x16> prompt=_L("ps>");
  2822 	showProcInfo.GetProcesses(processPrefix);
  2732 	r=showProcInfo.GetProcesses(processPrefix);
  2823 	do
  2733 	do
  2824 		{
  2734 		{
  2825 		TBuf<0x10> command;
  2735 		TBuf<0x10> command;
  2826 		CShell::TheEditor->Edit(prompt, &command, ETrue);
  2736 		CShell::TheEditor->Edit(prompt, &command, ETrue);
  2827 		while (command.Length() && !abort && r==KErrNone)
  2737 		while (command.Length() && !abort && r==KErrNone)
  2879 					else
  2789 					else
  2880 						{
  2790 						{
  2881 						if (findP.Next(findName)==KErrNone)
  2791 						if (findP.Next(findName)==KErrNone)
  2882 							{
  2792 							{
  2883 							r=showProcInfo.DisplayMessage(_L("command prefixes more than one process"));
  2793 							r=showProcInfo.DisplayMessage(_L("command prefixes more than one process"));
  2884 							showProcInfo.GetProcesses(chosenP);
  2794 							r=showProcInfo.GetProcesses(chosenP);
  2885 							}
  2795 							}
  2886 						else
  2796 						else
  2887 							{
  2797 							{
  2888 							processSelected=ETrue;
  2798 							processSelected=ETrue;
  2889 							processPrefix=chosenP;
  2799 							processPrefix=chosenP;
  2893 						}
  2803 						}
  2894 					}
  2804 					}
  2895 					break;
  2805 					break;
  2896 				case 'A':
  2806 				case 'A':
  2897 					{
  2807 					{
  2898 					showProcInfo.GetAll(processPrefix);
  2808 					r=showProcInfo.GetAll(processPrefix);
  2899 					command.Zero();
  2809 					command.Zero();
  2900 					}
  2810 					}
  2901 					break;
  2811 					break;
  2902 				case 'P':
  2812 				case 'P':
  2903 					showProcInfo.GetProcesses(asterisk);
  2813 					r=showProcInfo.GetProcesses(asterisk);
  2904 					break;
  2814 					break;
  2905 				case 'T':
  2815 				case 'T':
  2906 					showProcInfo.GetThreads(processPrefix);
  2816 					r=showProcInfo.GetThreads(processPrefix);
  2907 					break;
  2817 					break;
  2908 				case 'C':
  2818 				case 'C':
  2909 					showProcInfo.GetChunks(processPrefix);
  2819 					r=showProcInfo.GetChunks(processPrefix);
  2910 					break;
  2820 					break;
  2911 				case 'S':
  2821 				case 'S':
  2912 					showProcInfo.GetServers(processPrefix);
  2822 					r=showProcInfo.GetServers(processPrefix);
  2913 					break;
  2823 					break;
  2914 /*				case 'I':
  2824 /*				case 'I':
  2915 					r=showProcInfo.GetSessions(processPrefix);
  2825 					r=showProcInfo.GetSessions(processPrefix);
  2916 					break;
  2826 					break;
  2917 */				case 'L':
  2827 */				case 'L':
  2918 					showProcInfo.GetLibraries(processPrefix);
  2828 					r=showProcInfo.GetLibraries(processPrefix);
  2919 					break;
  2829 					break;
  2920 //				case 'G':
  2830 //				case 'G':
  2921 //					r=showProcInfo.GetLogicalChannels(processPrefix);
  2831 //					r=showProcInfo.GetLogicalChannels(processPrefix);
  2922 //					break;
  2832 //					break;
  2923 				case 'V':
  2833 				case 'V':
  2924 					showProcInfo.GetLogicalDevices(processPrefix);
  2834 					r=showProcInfo.GetLogicalDevices(processPrefix);
  2925 					break;
  2835 					break;
  2926 				case 'D':
  2836 				case 'D':
  2927 					showProcInfo.GetPhysicalDevices(processPrefix);
  2837 					r=showProcInfo.GetPhysicalDevices(processPrefix);
  2928 					break;
  2838 					break;
  2929 				case 'E':
  2839 				case 'E':
  2930 					showProcInfo.GetSemaphores(processPrefix);
  2840 					r=showProcInfo.GetSemaphores(processPrefix);
  2931 					break;
  2841 					break;
  2932 				case 'M':
  2842 				case 'M':
  2933 					showProcInfo.GetMutexes(processPrefix);
  2843 					r=showProcInfo.GetMutexes(processPrefix);
  2934 					break;
  2844 					break;
  2935 				default:
  2845 				default:
  2936 					{
  2846 					{
  2937 					showProcInfo.DisplayCmdUnknown();
  2847 					showProcInfo.DisplayCmdUnknown();
  2938 					command.Zero();
  2848 					command.Zero();
  3232 	TUint8 c;
  3142 	TUint8 c;
  3233 	for (; p<pE; p+=2)
  3143 	for (; p<pE; p+=2)
  3234 		c=*p, *p=p[1], p[1]=c;
  3144 		c=*p, *p=p[1], p[1]=c;
  3235 	}
  3145 	}
  3236 
  3146 
       
  3147 _LIT(KLitPercentS, "%S");
  3237 TInt ShellFunction::Type(TDes& aPath,TUint aSwitches)
  3148 TInt ShellFunction::Type(TDes& aPath,TUint aSwitches)
  3238 	{
  3149 	{
  3239 	ParsePath(aPath);
  3150 	ParsePath(aPath);
  3240 	RFile64 file;
  3151 	RFile64 file;
  3241 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStreamText|EFileShareReadersOnly);
  3152 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStreamText|EFileShareReadersOnly);
  3293 			}
  3204 			}
  3294 		while ((r=buf.Locate('\n'))!=KErrNotFound)
  3205 		while ((r=buf.Locate('\n'))!=KErrNotFound)
  3295 			{
  3206 			{
  3296 			nchars=0;
  3207 			nchars=0;
  3297 			TPtrC bufLeft=buf.Left(r+1);
  3208 			TPtrC bufLeft=buf.Left(r+1);
  3298             key = CShell::WriteBufToConsole((aSwitches&TShellCommand::EPSwitch)!=0, bufLeft);
  3209 			key = CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,KLitPercentS(), &bufLeft);
  3299 			buf.Set(buf.Mid(r+1));
  3210 			buf.Set(buf.Mid(r+1));
  3300 	
  3211 	
  3301     		if(key == EKeyEscape) 
  3212     		if(key == EKeyEscape) 
  3302                 goto exit;
  3213                 goto exit;
  3303 			}
  3214 			}
  3304 
  3215 
  3305 		nchars=buf.Length();
  3216 		nchars=buf.Length();
  3306 		if (nchars)
  3217 		if (nchars)
  3307 			{
  3218 			{
  3308     		key = CShell::WriteBufToConsole((aSwitches&TShellCommand::EPSwitch)!=0, buf);
  3219             key = CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,KLitPercentS(), &buf);
  3309 
       
  3310     		if(key == EKeyEscape) 
  3220     		if(key == EKeyEscape) 
  3311                 goto exit;
  3221                 goto exit;
  3312 
  3222 
  3313             }
  3223             }
  3314 
  3224 
  3723 	}
  3633 	}
  3724 
  3634 
  3725 
  3635 
  3726 
  3636 
  3727 //----------------------------------------------------------------------
  3637 //----------------------------------------------------------------------
  3728 void CShell::Print(const TDesC16& aBuf)
       
  3729 {
       
  3730 
       
  3731     TheConsole->Write(aBuf);
       
  3732 
       
  3733     if(iDbgPrint)
       
  3734     {
       
  3735         const TInt bufLen = aBuf.Length();
       
  3736         
       
  3737         if(bufLen >1 && aBuf[bufLen-1] == '\n' && aBuf[bufLen-2] != '\r')
       
  3738             {
       
  3739             RDebug::RawPrint(aBuf.Left(bufLen-1));            
       
  3740             RDebug::RawPrint(_L8("\r\n"));
       
  3741             }
       
  3742         else if(bufLen == 1 && aBuf[bufLen-1] == '\n')
       
  3743             {
       
  3744             RDebug::RawPrint(_L8("\r\n"));
       
  3745             }
       
  3746         else
       
  3747             {
       
  3748             RDebug::RawPrint(aBuf);
       
  3749             }
       
  3750     }
       
  3751 
       
  3752 }
       
  3753 
       
  3754 void CShell::Printf(TRefByValue<const TDesC16> aFmt, ...)
  3638 void CShell::Printf(TRefByValue<const TDesC16> aFmt, ...)
  3755 {
  3639 {
  3756 	TBuf<0x200> buf;
  3640 	TBuf<256> buf;
  3757 	VA_LIST list;					
  3641 	VA_LIST list;					
  3758 	VA_START(list, aFmt);
  3642 	VA_START(list, aFmt);
  3759 	// coverity[uninit_use_in_call]
  3643 	// coverity[uninit_use_in_call]
  3760 	buf.FormatList(aFmt, list);			
  3644 	buf.FormatList(aFmt, list);			
  3761 
  3645 
  3762     if(!buf.Length())
  3646     if(!buf.Length())
  3763         return;
  3647         return;
  3764 
  3648 
  3765     Print(buf);
  3649     TheConsole->Printf(buf);
       
  3650 
       
  3651     if(iDbgPrint)
       
  3652     {
       
  3653         const TInt bufLen = buf.Length();
       
  3654         if(buf[bufLen-1] == '\n')
       
  3655         {
       
  3656             buf.Insert(bufLen-1, _L("\r"));
       
  3657         }
       
  3658     
       
  3659         RDebug::RawPrint(buf);
       
  3660     }
       
  3661 
  3766 }
  3662 }
  3767 
  3663 
  3768 void SIPrintf(TRefByValue<const TDesC16> aFmt, ...)
  3664 void SIPrintf(TRefByValue<const TDesC16> aFmt, ...)
  3769 	{
  3665 	{
  3770 	TBuf<0x200> buf;
  3666 	TBuf<256> buf;
  3771 	VA_LIST list;					
  3667 	VA_LIST list;					
  3772 	VA_START(list, aFmt);
  3668 	VA_START(list, aFmt);
  3773 	// coverity[uninit_use_in_call]
  3669 	// coverity[uninit_use_in_call]
  3774 	buf.FormatList(aFmt, list);			
  3670 	buf.FormatList(aFmt, list);			
  3775 	buf.Append(KCrNl);					
  3671 	buf.Append(KCrNl);					
  3840 	aProg.UpperCase();
  3736 	aProg.UpperCase();
  3841 	if (aProg.FindF(_L(".EXE")) == KErrNotFound && (aProg.Length()+4) <= KShellMaxCommandLine)
  3737 	if (aProg.FindF(_L(".EXE")) == KErrNotFound && (aProg.Length()+4) <= KShellMaxCommandLine)
  3842 		aProg.Append(_L(".EXE"));
  3738 		aProg.Append(_L(".EXE"));
  3843 
  3739 
  3844 #ifdef _DEBUG
  3740 #ifdef _DEBUG
  3845 	CShell::Printf(_L("RUNEXEC: command %S, parameters %S, count %d, forever %d, issecs %d, exiterr %d"),
  3741 	SIPrintf(_L("RUNEXEC: command %S, parameters %S, count %d, forever %d, issecs %d, exiterr %d"),
  3846 		&aProg, &parameters, count, forever, countIsSecs, exitOnErr); 
  3742 		&aProg, &parameters, count, forever, countIsSecs, exitOnErr); 
  3847 #endif
  3743 #endif
  3848 	TInt i=0;
  3744 	TInt i=0;
  3849 	FOREVER
  3745 	FOREVER
  3850 		{
  3746 		{
  3855 		TBuf<KMaxExitCategoryName> exitCat(0);
  3751 		TBuf<KMaxExitCategoryName> exitCat(0);
  3856 
  3752 
  3857 		r = newProcess.Create(aProg, parameters);
  3753 		r = newProcess.Create(aProg, parameters);
  3858 		if (r != KErrNone)
  3754 		if (r != KErrNone)
  3859 			{
  3755 			{
  3860 			CShell::Printf(KRunExecFailedProcessCreate, &aProg, r);
  3756 			SIPrintf(KRunExecFailedProcessCreate, &aProg, r);
  3861 			return (r);						// this is systematic - must return
  3757 			return (r);						// this is systematic - must return
  3862 			}
  3758 			}
  3863 		newProcess.Logon(status);
  3759 		newProcess.Logon(status);
  3864 		newProcess.Resume();
  3760 		newProcess.Resume();
  3865 		User::WaitForRequest(status);
  3761 		User::WaitForRequest(status);
  3869 		newProcess.Close();
  3765 		newProcess.Close();
  3870 
  3766 
  3871 		timeCurrent.HomeTime();
  3767 		timeCurrent.HomeTime();
  3872 		timeTaken = timeCurrent.MicroSecondsFrom(timeStart);
  3768 		timeTaken = timeCurrent.MicroSecondsFrom(timeStart);
  3873 		TInt msecs = I64LOW(timeTaken.Int64() / 1000);
  3769 		TInt msecs = I64LOW(timeTaken.Int64() / 1000);
  3874 		CShell::Printf(KRunExecReportStatusAndTime, msecs, i+1, exitType, retcode, &exitCat);
  3770 		SIPrintf(KRunExecReportStatusAndTime, msecs, i+1, exitType, retcode, &exitCat);
  3875 
  3771 
  3876 		if (resetDebugRegs)
  3772 		if (resetDebugRegs)
  3877 			{
  3773 			{
  3878 			TheShell->TheFs.SetDebugRegister(0);
  3774 			TheShell->TheFs.SetDebugRegister(0);
  3879 			User::SetDebugMask(0);
  3775 			User::SetDebugMask(0);