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