diff -r c1f20ce4abcf -r 3e88ff8f41d5 userlibandfileserver/fileserver/etshell/ts_com.cpp --- a/userlibandfileserver/fileserver/etshell/ts_com.cpp Tue Aug 31 16:34:26 2010 +0300 +++ b/userlibandfileserver/fileserver/etshell/ts_com.cpp Wed Sep 01 12:34:56 2010 +0100 @@ -42,7 +42,6 @@ // lint -e40,e30 const TShellCommand CShell::iCommand[ENoShellCommands]= { -// TShellCommand(_L("BLANK"),_L("Help"),_L("-?"),TShellCommand::EDSwitch,ShellFunction::BLANK), 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), TShellCommand(_L("CD"),_L("Change the current directory for a drive"),_L("[path] [/d]\n\n /d - Change drive"),TShellCommand::EDSwitch,ShellFunction::Cd), TShellCommand(_L("CHKDEPS"),_L("Check the dependencies of an executable or a Dll (ARM only)"),_L("[Filename.EXE] or [Filename.DLL]"),0,ShellFunction::ChkDeps), @@ -50,7 +49,6 @@ TShellCommand(_L("COPY"),_L("Copy one (or more) file(s), overwriting existing one(s)"),_L("source [destination]"),TShellCommand::ESSwitch,ShellFunction::Copy), TShellCommand(_L("DEL"),_L("Delete one file"),_L("[drive:][path][filename]"),TShellCommand::ESSwitch,ShellFunction::Del), 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), -// 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), TShellCommand(_L("FORMAT"),_L("Format a disk"),ptrFormatHelp,TShellCommand::EQSwitch|TShellCommand::ESSwitch|TShellCommand::EESwitch|TShellCommand::EFSwitch,ShellFunction::Format), 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), 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), @@ -498,13 +496,15 @@ TInt r=CShell::TheFs.CharToDrive(CShell::currentPath[0], drive); if (r!=KErrNone) return(r); + if (aPath.Length()==0) { r=CShell::TheFs.Volume(vol, drive); if (r==KErrNone) - CShell::TheConsole->Printf(_L("Volume = %S\n"),&vol.iName); + CShell::Printf(_L("Volume Label:%S\n"),&vol.iName); return(r); } + r=CShell::TheFs.SetVolumeLabel(aPath, drive); return(r); } @@ -582,21 +582,39 @@ } - -void ShellFunction::OutputContentsToConsole(RPointerArray& aText,TUint aSwitches) -//outputs content of the buffer to console according to settings passed in aSwitches +/** + outputs content of the buffer to console according to settings passed in aSwitches + @return ETrue if the user pressed Esc key +*/ +TBool ShellFunction::OutputContentsToConsole(RPointerArray& aText,TUint aSwitches) { if ((aText.Count()>0)&&((aSwitches&TShellCommand::EWSwitch)!=0)) AlignTextIntoColumns(aText); - for (TInt i=0;iCount(); TInt fileCount=0, dirCount=0, printCount=0; TInt64 byteCount=0; + TBool bBreak=EFalse; //compose an array of strings describing entries in the directory for (TInt j=0;jDes(); name=entry.iName; + const TPtrC desName(entry.iName); + const TBool bNameCut = desName.Length() > 26; + + _LIT(KDots, ">.."); //-- will be displayed if the name is longer than 26 characters + _LIT(KSpc, " "); + + if (entry.IsDir()) { dirCount++; - name.Format(_L(" %- 26S %+02d/%+02d/%- 4d %02d:%02d:%02d.%06d"), - &entry.iName,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond()); + + name.Format(_L(" %- 26S%S %+02d/%+02d/%- 4d %02d:%02d:%02d.%03d"), + &desName, + bNameCut ? &KDots : &KSpc, + modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond()); + + //name.Format(_L(" %- 26S %+02d/%+02d/%- 4d %02d:%02d:%02d.%06d"), + // &entry.iName,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond()); } else { TInt64 entrySize = entry.FileSize(); byteCount+=entrySize; fileCount++; - name.Format(_L(" %- 32S%+ 15Lu %+02d/%+02d/%- 4d %02d:%02d:%02d.%06d"), - &entry.iName,entrySize,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond()); + + name.Format(_L(" %- 26S%S%-11Lu %+02d/%+02d/%- 4d %02d:%02d:%02d.%03d"), + &desName, + bNameCut ? &KDots : &KSpc, + entrySize, + modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond()); + + //name.Format(_L(" %- 32S%+ 15Lu %+02d/%+02d/%- 4d %02d:%02d:%02d.%06d"), + // &entry.iName,entrySize,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond()); } } User::LeaveIfError(aText.Append(buf )); printCount++; + //print the contents if a screen size of data is available. This will prevent huge buffer allocation. if(printCount == CShell::TheConsole->ScreenSize().iHeight) { - OutputContentsToConsole(aText,aSwitches); + bBreak = OutputContentsToConsole(aText,aSwitches); printCount=0; } + CleanupStack::Pop(); + if(bBreak) + break; } + + if(bBreak) + return; //-- the user has interrupted the listing + + OutputContentsToConsole(aText,aSwitches); - //output summary information - CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %d File%c\n"),fileCount,(fileCount==1)?' ':'s'); - if (fileCount!=0) + //--------------------------------- + //-- print out summary information + TBuf<100> buf; + buf.Format(_L(" %d File%c"), fileCount, (fileCount==1) ? ' ':'s'); + if(fileCount > 0) { - CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %lu byte%c\n"),byteCount,(fileCount==1)?' ':'s'); + buf.AppendFormat(_L(", %LU bytes"), byteCount); } - TBuf<50> buf;// allocate string long enough for additional information(number of directories) + buf.Append(KNl); + + CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0), buf); + buf.Format(_L(" %d Director"),dirCount); if (dirCount==1) buf.AppendFormat(_L("y\n")); @@ -684,6 +737,8 @@ buf.AppendFormat(_L("ies\n")); CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),buf); + + } TInt ShellFunction::Dir(TDes& aPath,TUint aSwitches) @@ -709,7 +764,7 @@ TInt r=dir.Open(TheShell->TheFs,aPath,KEntryAttMaskSupported); if (r!=KErrNone) { - CShell::TheConsole->Printf(_L("File or directory not found\n")); + CShell::Printf(_L("File or directory not found\n")); return(KErrNone); } @@ -724,7 +779,7 @@ //Sets the new length of path to the position of the last path delimiter +1 aPath.SetLength(aPath.LocateReverse(KPathDelimiter)+1); - CShell::TheConsole->Printf(_L("Directory of %S\n"),&aPath); + CShell::Printf(_L("Directory of %S\n"),&aPath); //allocate array to be used as an output buffer RPointerArray* text=new(ELeave) RPointerArray(); @@ -742,13 +797,6 @@ }; -TInt ShellFunction::Edit(TDes& /*aPath*/,TUint /*aSwitches*/) -// -// Dummy, used by edlin (now retired) -// - { - return(KErrNone); - } TInt ShellFunction::Attrib(TDes& aPath,TUint aSwitches) @@ -1007,14 +1055,14 @@ if(aDrvInfo.iDriveAtt & KDriveAttRedirected) aPrintBuf.Append(_L("KDriveAttRedirected,")); if(aDrvInfo.iDriveAtt & KDriveAttSubsted) aPrintBuf.Append(_L("KDriveAttSubsted,")); if(aDrvInfo.iDriveAtt & KDriveAttInternal) aPrintBuf.Append(_L("KDriveAttInternal,")); - if(aDrvInfo.iDriveAtt & KDriveAttRemovable) aPrintBuf.Append(_L("KDriveAttRemovable")); - - if(aDrvInfo.iDriveAtt & KDriveAttRemote) aPrintBuf.Append(_L("KDriveAttRemote")); - if(aDrvInfo.iDriveAtt & KDriveAttTransaction) aPrintBuf.Append(_L("KDriveAttTransaction")); - - if(aDrvInfo.iDriveAtt & KDriveAttPageable) aPrintBuf.Append(_L("KDriveAttPageable")); - if(aDrvInfo.iDriveAtt & KDriveAttLogicallyRemovable) aPrintBuf.Append(_L("KDriveAttLogicallyRemovable")); - if(aDrvInfo.iDriveAtt & KDriveAttHidden) aPrintBuf.Append(_L("KDriveAttHidden")); + if(aDrvInfo.iDriveAtt & KDriveAttRemovable) aPrintBuf.Append(_L("KDriveAttRemovable,")); + + if(aDrvInfo.iDriveAtt & KDriveAttRemote) aPrintBuf.Append(_L("KDriveAttRemote,")); + if(aDrvInfo.iDriveAtt & KDriveAttTransaction) aPrintBuf.Append(_L("KDriveAttTransaction,")); + + if(aDrvInfo.iDriveAtt & KDriveAttPageable) aPrintBuf.Append(_L("KDriveAttPageable,")); + if(aDrvInfo.iDriveAtt & KDriveAttLogicallyRemovable) aPrintBuf.Append(_L("KDriveAttLogicallyRemovable,")); + if(aDrvInfo.iDriveAtt & KDriveAttHidden) aPrintBuf.Append(_L("KDriveAttHidden,")); aPrintBuf.Append(_L("\n")); } @@ -1036,12 +1084,12 @@ if(aDrvInfo.iMediaAtt & KMediaAttFormattable) aPrintBuf.Append(_L("KMediaAttFormattable,")); if(aDrvInfo.iMediaAtt & KMediaAttWriteProtected) aPrintBuf.Append(_L("KMediaAttWriteProtected,")); if(aDrvInfo.iMediaAtt & KMediaAttLockable) aPrintBuf.Append(_L("KMediaAttLockable,")); - if(aDrvInfo.iMediaAtt & KMediaAttLocked) aPrintBuf.Append(_L("KMediaAttLocked")); - - if(aDrvInfo.iMediaAtt & KMediaAttHasPassword) aPrintBuf.Append(_L("KMediaAttHasPassword")); - if(aDrvInfo.iMediaAtt & KMediaAttReadWhileWrite) aPrintBuf.Append(_L("KMediaAttReadWhileWrite")); - if(aDrvInfo.iMediaAtt & KMediaAttDeleteNotify) aPrintBuf.Append(_L("KMediaAttDeleteNotify")); - if(aDrvInfo.iMediaAtt & KMediaAttPageable) aPrintBuf.Append(_L("KMediaAttPageable")); + if(aDrvInfo.iMediaAtt & KMediaAttLocked) aPrintBuf.Append(_L("KMediaAttLocked,")); + + if(aDrvInfo.iMediaAtt & KMediaAttHasPassword) aPrintBuf.Append(_L("KMediaAttHasPassword,")); + if(aDrvInfo.iMediaAtt & KMediaAttReadWhileWrite) aPrintBuf.Append(_L("KMediaAttReadWhileWrite,")); + if(aDrvInfo.iMediaAtt & KMediaAttDeleteNotify) aPrintBuf.Append(_L("KMediaAttDeleteNotify,")); + if(aDrvInfo.iMediaAtt & KMediaAttPageable) aPrintBuf.Append(_L("KMediaAttPageable,")); aPrintBuf.Append(_L("\n")); @@ -1163,8 +1211,8 @@ CShell::Printf(_L("Mounted FS:%S\n"), &Buf); - //-- print out the list of supported file systems if there are more than 1 - nRes = aFs.SupportedFileSystemName(fsName, aDrvNum, 0+1); //-- try to get 2nd child name + //-- print out the list of supported file systems if there are more than 0 + nRes = aFs.SupportedFileSystemName(fsName, aDrvNum, 0); //-- try to get 1st child name if(nRes == KErrNone) { Buf.Copy(_L("Supported FS: ")); @@ -1436,16 +1484,16 @@ {//-- gaceful attempt to dismount the FS nRes = aFs.DismountFileSystem(fsName, aDrvNum); if(nRes != KErrNone) - { + { CShell::TheConsole->Printf(_L("Can't dismount FS!\n")); return nRes; - } + } else - { - CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum); - return KErrNone; - } + { + CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum); + return KErrNone; } +} else {//-- dismount by force TRequestStatus rqStat; @@ -2006,52 +2054,60 @@ } //----------------------------------------------------------------------------------------------------------------------- - +/** + Hex Dump of a file +*/ TInt ShellFunction::Hexdump(TDes& aPath,TUint aSwitches) { ShellFunction::StripQuotes(aPath); ParsePath(aPath); + RFile64 file; TInt r=file.Open(TheShell->TheFs,aPath,EFileStream); if (r!=KErrNone) return(r); - TInt offset=0; + const TInt KLineLength = 16; + TBuf<0x100> buf; + TBuf asciiBuf; + TBuf8 line; + for (;;) { - const TInt KLineLength = 16; - - TBuf8 line; r=file.Read(line); if (r != KErrNone || line.Length() == 0) break; - TBuf hexaRep; - TBuf asciiRep; + buf.Zero(); + asciiBuf.Zero(); + for (TInt i=0; i\n"),&aName); + TKeyCode key = CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName); + + if(key==EKeyEscape) + return EFalse; + useCallBack=EFalse; - return KErrNone; + return ETrue; } -TInt TShowProcInfo::Prepare(const TFullName& aName,TCallBack& aCallBack) +TBool TShowProcInfo::Prepare(const TFullName& aName,TCallBack& aCallBack) { - iPrevName=_L(""); - CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName); + TKeyCode key = CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName); + + if(key==EKeyEscape) + return EFalse; + + useCallBack=ETrue; iCallBack=aCallBack; - return KErrNone; + + return ETrue; } TInt TShowProcInfo::Display(TFullName& aName) @@ -2698,7 +2784,11 @@ while (posA>=0) { TPtrC16 temp_desc=aName.Left(posA); - CShell::OutputStringToConsole(ETrue,_L("%+ *S\n"),toTab+temp_desc.Left(posA).Length(),&temp_desc); + + TKeyCode key = CShell::OutputStringToConsole(ETrue,_L("%+ *S\n"),toTab+temp_desc.Left(posA).Length(),&temp_desc); + if (key==EKeyEscape) + break; + toTab+=3; aName.Delete(0,posA+2); posA=aName.Match(_L("*::*")); @@ -2729,7 +2819,7 @@ TBool abort=EFalse; TBool processSelected=EFalse; TBuf<0x16> prompt=_L("ps>"); - r=showProcInfo.GetProcesses(processPrefix); + showProcInfo.GetProcesses(processPrefix); do { TBuf<0x10> command; @@ -2791,7 +2881,7 @@ if (findP.Next(findName)==KErrNone) { r=showProcInfo.DisplayMessage(_L("command prefixes more than one process")); - r=showProcInfo.GetProcesses(chosenP); + showProcInfo.GetProcesses(chosenP); } else { @@ -2805,42 +2895,42 @@ break; case 'A': { - r=showProcInfo.GetAll(processPrefix); + showProcInfo.GetAll(processPrefix); command.Zero(); } break; case 'P': - r=showProcInfo.GetProcesses(asterisk); + showProcInfo.GetProcesses(asterisk); break; case 'T': - r=showProcInfo.GetThreads(processPrefix); + showProcInfo.GetThreads(processPrefix); break; case 'C': - r=showProcInfo.GetChunks(processPrefix); + showProcInfo.GetChunks(processPrefix); break; case 'S': - r=showProcInfo.GetServers(processPrefix); + showProcInfo.GetServers(processPrefix); break; /* case 'I': r=showProcInfo.GetSessions(processPrefix); break; */ case 'L': - r=showProcInfo.GetLibraries(processPrefix); + showProcInfo.GetLibraries(processPrefix); break; // case 'G': // r=showProcInfo.GetLogicalChannels(processPrefix); // break; case 'V': - r=showProcInfo.GetLogicalDevices(processPrefix); + showProcInfo.GetLogicalDevices(processPrefix); break; case 'D': - r=showProcInfo.GetPhysicalDevices(processPrefix); + showProcInfo.GetPhysicalDevices(processPrefix); break; case 'E': - r=showProcInfo.GetSemaphores(processPrefix); + showProcInfo.GetSemaphores(processPrefix); break; case 'M': - r=showProcInfo.GetMutexes(processPrefix); + showProcInfo.GetMutexes(processPrefix); break; default: { @@ -3144,7 +3234,6 @@ c=*p, *p=p[1], p[1]=c; } -_LIT(KLitPercentS, "%S"); TInt ShellFunction::Type(TDes& aPath,TUint aSwitches) { ParsePath(aPath); @@ -3206,7 +3295,7 @@ { nchars=0; TPtrC bufLeft=buf.Left(r+1); - key = CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,KLitPercentS(), &bufLeft); + key = CShell::WriteBufToConsole((aSwitches&TShellCommand::EPSwitch)!=0, bufLeft); buf.Set(buf.Mid(r+1)); if(key == EKeyEscape) @@ -3216,7 +3305,8 @@ nchars=buf.Length(); if (nchars) { - key = CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,KLitPercentS(), &buf); + key = CShell::WriteBufToConsole((aSwitches&TShellCommand::EPSwitch)!=0, buf); + if(key == EKeyEscape) goto exit; @@ -3635,9 +3725,35 @@ //---------------------------------------------------------------------- +void CShell::Print(const TDesC16& aBuf) +{ + + TheConsole->Write(aBuf); + + if(iDbgPrint) + { + const TInt bufLen = aBuf.Length(); + + if(bufLen >1 && aBuf[bufLen-1] == '\n' && aBuf[bufLen-2] != '\r') + { + RDebug::RawPrint(aBuf.Left(bufLen-1)); + RDebug::RawPrint(_L8("\r\n")); + } + else if(bufLen == 1 && aBuf[bufLen-1] == '\n') + { + RDebug::RawPrint(_L8("\r\n")); + } + else + { + RDebug::RawPrint(aBuf); + } + } + +} + void CShell::Printf(TRefByValue aFmt, ...) { - TBuf<256> buf; + TBuf<0x200> buf; VA_LIST list; VA_START(list, aFmt); // coverity[uninit_use_in_call] @@ -3646,24 +3762,12 @@ if(!buf.Length()) return; - TheConsole->Printf(buf); - - if(iDbgPrint) - { - const TInt bufLen = buf.Length(); - if(buf[bufLen-1] == '\n') - { - buf.Insert(bufLen-1, _L("\r")); - } - - RDebug::RawPrint(buf); - } - + Print(buf); } void SIPrintf(TRefByValue aFmt, ...) { - TBuf<256> buf; + TBuf<0x200> buf; VA_LIST list; VA_START(list, aFmt); // coverity[uninit_use_in_call] @@ -3738,7 +3842,7 @@ aProg.Append(_L(".EXE")); #ifdef _DEBUG - SIPrintf(_L("RUNEXEC: command %S, parameters %S, count %d, forever %d, issecs %d, exiterr %d"), + CShell::Printf(_L("RUNEXEC: command %S, parameters %S, count %d, forever %d, issecs %d, exiterr %d"), &aProg, ¶meters, count, forever, countIsSecs, exitOnErr); #endif TInt i=0; @@ -3753,7 +3857,7 @@ r = newProcess.Create(aProg, parameters); if (r != KErrNone) { - SIPrintf(KRunExecFailedProcessCreate, &aProg, r); + CShell::Printf(KRunExecFailedProcessCreate, &aProg, r); return (r); // this is systematic - must return } newProcess.Logon(status); @@ -3767,7 +3871,7 @@ timeCurrent.HomeTime(); timeTaken = timeCurrent.MicroSecondsFrom(timeStart); TInt msecs = I64LOW(timeTaken.Int64() / 1000); - SIPrintf(KRunExecReportStatusAndTime, msecs, i+1, exitType, retcode, &exitCat); + CShell::Printf(KRunExecReportStatusAndTime, msecs, i+1, exitType, retcode, &exitCat); if (resetDebugRegs) {