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), |
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++) |
|
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 { |
596 delete aText[i]; |
612 delete aText[i]; |
597 } |
613 } |
598 //empty string array |
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; |
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 |
|
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 |
644 if (entry.IsDir()) |
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++; |
|
700 |
661 //print the contents if a screen size of data is available. This will prevent huge buffer allocation. |
701 //print the contents if a screen size of data is available. This will prevent huge buffer allocation. |
662 if(printCount == CShell::TheConsole->ScreenSize().iHeight) |
702 if(printCount == CShell::TheConsole->ScreenSize().iHeight) |
663 { |
703 { |
664 OutputContentsToConsole(aText,aSwitches); |
704 bBreak = OutputContentsToConsole(aText,aSwitches); |
665 printCount=0; |
705 printCount=0; |
666 } |
706 } |
|
707 |
667 CleanupStack::Pop(); |
708 CleanupStack::Pop(); |
668 |
709 |
669 } |
710 if(bBreak) |
|
711 break; |
|
712 } |
|
713 |
|
714 if(bBreak) |
|
715 return; //-- the user has interrupted the listing |
|
716 |
|
717 |
670 OutputContentsToConsole(aText,aSwitches); |
718 OutputContentsToConsole(aText,aSwitches); |
671 |
719 |
672 //output summary information |
720 //--------------------------------- |
673 CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %d File%c\n"),fileCount,(fileCount==1)?' ':'s'); |
721 //-- print out summary information |
674 if (fileCount!=0) |
722 TBuf<100> buf; |
675 { |
723 buf.Format(_L(" %d File%c"), fileCount, (fileCount==1) ? ' ':'s'); |
676 CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %lu byte%c\n"),byteCount,(fileCount==1)?' ':'s'); |
724 if(fileCount > 0) |
677 } |
725 { |
678 |
726 buf.AppendFormat(_L(", %LU bytes"), byteCount); |
679 TBuf<50> buf;// allocate string long enough for additional information(number of directories) |
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); |
|
740 |
|
741 |
687 } |
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 |
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 |
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); |
|
2065 |
2015 RFile64 file; |
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) |
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 }; |
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 |
|
2517 if(!Prepare(_L("PROCESSES"))) |
|
2518 return; |
|
2519 |
2462 while (findHb.Next(name)==KErrNone) |
2520 while (findHb.Next(name)==KErrNone) |
2463 { |
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 |
|
2538 if(!Prepare(_L("THREADS"),threadCallBack)) |
|
2539 return; |
|
2540 |
2480 while (findHb.Next(name)==KErrNone) |
2541 while (findHb.Next(name)==KErrNone) |
2481 { |
2542 { |
2482 Display(name); |
2543 Display(name); |
2483 threads += 1; |
2544 threads += 1; |
2484 } |
2545 } |
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); |
|
2746 |
|
2747 if(key==EKeyEscape) |
|
2748 return EFalse; |
|
2749 |
|
2750 |
2666 useCallBack=ETrue; |
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 |
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(); |
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); |