diff -r a179b74831c9 -r c1f20ce4abcf userlibandfileserver/fileserver/etshell/ts_com.cpp --- a/userlibandfileserver/fileserver/etshell/ts_com.cpp Thu Aug 19 11:14:22 2010 +0300 +++ b/userlibandfileserver/fileserver/etshell/ts_com.cpp Tue Aug 31 16:34:26 2010 +0300 @@ -42,6 +42,7 @@ // 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), @@ -49,6 +50,7 @@ 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), @@ -496,15 +498,13 @@ 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::Printf(_L("Volume Label:%S\n"),&vol.iName); + CShell::TheConsole->Printf(_L("Volume = %S\n"),&vol.iName); return(r); } - r=CShell::TheFs.SetVolumeLabel(aPath, drive); return(r); } @@ -582,39 +582,21 @@ } -/** - 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) + +void ShellFunction::OutputContentsToConsole(RPointerArray& aText,TUint aSwitches) +//outputs content of the buffer to console according to settings passed in aSwitches { if ((aText.Count()>0)&&((aSwitches&TShellCommand::EWSwitch)!=0)) AlignTextIntoColumns(aText); - TKeyCode key=EKeyNull; - TInt i; - - for(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%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()); + 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(" %- 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()); + 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) { - bBreak = OutputContentsToConsole(aText,aSwitches); + OutputContentsToConsole(aText,aSwitches); printCount=0; } - CleanupStack::Pop(); - if(bBreak) - break; } - - if(bBreak) - return; //-- the user has interrupted the listing - - OutputContentsToConsole(aText,aSwitches); - //--------------------------------- - //-- print out summary information - TBuf<100> buf; - buf.Format(_L(" %d File%c"), fileCount, (fileCount==1) ? ' ':'s'); - if(fileCount > 0) + //output summary information + CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %d File%c\n"),fileCount,(fileCount==1)?' ':'s'); + if (fileCount!=0) { - buf.AppendFormat(_L(", %LU bytes"), byteCount); + CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %lu byte%c\n"),byteCount,(fileCount==1)?' ':'s'); } - buf.Append(KNl); - - CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0), buf); - + TBuf<50> buf;// allocate string long enough for additional information(number of directories) buf.Format(_L(" %d Director"),dirCount); if (dirCount==1) buf.AppendFormat(_L("y\n")); @@ -737,8 +684,6 @@ buf.AppendFormat(_L("ies\n")); CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),buf); - - } TInt ShellFunction::Dir(TDes& aPath,TUint aSwitches) @@ -764,7 +709,7 @@ TInt r=dir.Open(TheShell->TheFs,aPath,KEntryAttMaskSupported); if (r!=KErrNone) { - CShell::Printf(_L("File or directory not found\n")); + CShell::TheConsole->Printf(_L("File or directory not found\n")); return(KErrNone); } @@ -779,7 +724,7 @@ //Sets the new length of path to the position of the last path delimiter +1 aPath.SetLength(aPath.LocateReverse(KPathDelimiter)+1); - CShell::Printf(_L("Directory of %S\n"),&aPath); + CShell::TheConsole->Printf(_L("Directory of %S\n"),&aPath); //allocate array to be used as an output buffer RPointerArray* text=new(ELeave) RPointerArray(); @@ -797,6 +742,13 @@ }; +TInt ShellFunction::Edit(TDes& /*aPath*/,TUint /*aSwitches*/) +// +// Dummy, used by edlin (now retired) +// + { + return(KErrNone); + } TInt ShellFunction::Attrib(TDes& aPath,TUint aSwitches) @@ -1055,14 +1007,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")); } @@ -1084,12 +1036,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")); @@ -1211,8 +1163,8 @@ CShell::Printf(_L("Mounted FS:%S\n"), &Buf); - //-- 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 + //-- 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 if(nRes == KErrNone) { Buf.Copy(_L("Supported FS: ")); @@ -1484,16 +1436,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; @@ -2054,60 +2006,52 @@ } //----------------------------------------------------------------------------------------------------------------------- -/** - 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); - const TInt KLineLength = 16; - TBuf<0x100> buf; - TBuf asciiBuf; - TBuf8 line; - + TInt offset=0; for (;;) { + const TInt KLineLength = 16; + + TBuf8 line; r=file.Read(line); if (r != KErrNone || line.Length() == 0) break; - buf.Zero(); - asciiBuf.Zero(); - + TBuf hexaRep; + TBuf asciiRep; for (TInt i=0; i\n"),&aName); - - if(key==EKeyEscape) - return EFalse; - + CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName); useCallBack=EFalse; - return ETrue; + return KErrNone; } -TBool TShowProcInfo::Prepare(const TFullName& aName,TCallBack& aCallBack) +TInt TShowProcInfo::Prepare(const TFullName& aName,TCallBack& aCallBack) { + iPrevName=_L(""); - TKeyCode key = CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName); - - if(key==EKeyEscape) - return EFalse; - - + CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName); useCallBack=ETrue; iCallBack=aCallBack; - - return ETrue; + return KErrNone; } TInt TShowProcInfo::Display(TFullName& aName) @@ -2784,11 +2698,7 @@ while (posA>=0) { TPtrC16 temp_desc=aName.Left(posA); - - TKeyCode key = CShell::OutputStringToConsole(ETrue,_L("%+ *S\n"),toTab+temp_desc.Left(posA).Length(),&temp_desc); - if (key==EKeyEscape) - break; - + CShell::OutputStringToConsole(ETrue,_L("%+ *S\n"),toTab+temp_desc.Left(posA).Length(),&temp_desc); toTab+=3; aName.Delete(0,posA+2); posA=aName.Match(_L("*::*")); @@ -2819,7 +2729,7 @@ TBool abort=EFalse; TBool processSelected=EFalse; TBuf<0x16> prompt=_L("ps>"); - showProcInfo.GetProcesses(processPrefix); + r=showProcInfo.GetProcesses(processPrefix); do { TBuf<0x10> command; @@ -2881,7 +2791,7 @@ if (findP.Next(findName)==KErrNone) { r=showProcInfo.DisplayMessage(_L("command prefixes more than one process")); - showProcInfo.GetProcesses(chosenP); + r=showProcInfo.GetProcesses(chosenP); } else { @@ -2895,42 +2805,42 @@ break; case 'A': { - showProcInfo.GetAll(processPrefix); + r=showProcInfo.GetAll(processPrefix); command.Zero(); } break; case 'P': - showProcInfo.GetProcesses(asterisk); + r=showProcInfo.GetProcesses(asterisk); break; case 'T': - showProcInfo.GetThreads(processPrefix); + r=showProcInfo.GetThreads(processPrefix); break; case 'C': - showProcInfo.GetChunks(processPrefix); + r=showProcInfo.GetChunks(processPrefix); break; case 'S': - showProcInfo.GetServers(processPrefix); + r=showProcInfo.GetServers(processPrefix); break; /* case 'I': r=showProcInfo.GetSessions(processPrefix); break; */ case 'L': - showProcInfo.GetLibraries(processPrefix); + r=showProcInfo.GetLibraries(processPrefix); break; // case 'G': // r=showProcInfo.GetLogicalChannels(processPrefix); // break; case 'V': - showProcInfo.GetLogicalDevices(processPrefix); + r=showProcInfo.GetLogicalDevices(processPrefix); break; case 'D': - showProcInfo.GetPhysicalDevices(processPrefix); + r=showProcInfo.GetPhysicalDevices(processPrefix); break; case 'E': - showProcInfo.GetSemaphores(processPrefix); + r=showProcInfo.GetSemaphores(processPrefix); break; case 'M': - showProcInfo.GetMutexes(processPrefix); + r=showProcInfo.GetMutexes(processPrefix); break; default: { @@ -3234,6 +3144,7 @@ c=*p, *p=p[1], p[1]=c; } +_LIT(KLitPercentS, "%S"); TInt ShellFunction::Type(TDes& aPath,TUint aSwitches) { ParsePath(aPath); @@ -3295,7 +3206,7 @@ { nchars=0; TPtrC bufLeft=buf.Left(r+1); - key = CShell::WriteBufToConsole((aSwitches&TShellCommand::EPSwitch)!=0, bufLeft); + key = CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,KLitPercentS(), &bufLeft); buf.Set(buf.Mid(r+1)); if(key == EKeyEscape) @@ -3305,8 +3216,7 @@ nchars=buf.Length(); if (nchars) { - key = CShell::WriteBufToConsole((aSwitches&TShellCommand::EPSwitch)!=0, buf); - + key = CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,KLitPercentS(), &buf); if(key == EKeyEscape) goto exit; @@ -3725,35 +3635,9 @@ //---------------------------------------------------------------------- -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<0x200> buf; + TBuf<256> buf; VA_LIST list; VA_START(list, aFmt); // coverity[uninit_use_in_call] @@ -3762,12 +3646,24 @@ if(!buf.Length()) return; - Print(buf); + TheConsole->Printf(buf); + + if(iDbgPrint) + { + const TInt bufLen = buf.Length(); + if(buf[bufLen-1] == '\n') + { + buf.Insert(bufLen-1, _L("\r")); + } + + RDebug::RawPrint(buf); + } + } void SIPrintf(TRefByValue aFmt, ...) { - TBuf<0x200> buf; + TBuf<256> buf; VA_LIST list; VA_START(list, aFmt); // coverity[uninit_use_in_call] @@ -3842,7 +3738,7 @@ aProg.Append(_L(".EXE")); #ifdef _DEBUG - CShell::Printf(_L("RUNEXEC: command %S, parameters %S, count %d, forever %d, issecs %d, exiterr %d"), + SIPrintf(_L("RUNEXEC: command %S, parameters %S, count %d, forever %d, issecs %d, exiterr %d"), &aProg, ¶meters, count, forever, countIsSecs, exitOnErr); #endif TInt i=0; @@ -3857,7 +3753,7 @@ r = newProcess.Create(aProg, parameters); if (r != KErrNone) { - CShell::Printf(KRunExecFailedProcessCreate, &aProg, r); + SIPrintf(KRunExecFailedProcessCreate, &aProg, r); return (r); // this is systematic - must return } newProcess.Logon(status); @@ -3871,7 +3767,7 @@ timeCurrent.HomeTime(); timeTaken = timeCurrent.MicroSecondsFrom(timeStart); TInt msecs = I64LOW(timeTaken.Int64() / 1000); - CShell::Printf(KRunExecReportStatusAndTime, msecs, i+1, exitType, retcode, &exitCat); + SIPrintf(KRunExecReportStatusAndTime, msecs, i+1, exitType, retcode, &exitCat); if (resetDebugRegs) {