<> <> <> <<>> DIRECTORY Commander USING [CommandProc, Handle, Register], CommandTool USING [ArgumentVector, Failed, Parse], Convert USING [Error, IntFromRope], FSBackdoor USING [EnumerateCacheForInfo, InfoProc], IO USING [PutF, STREAM], ProcessExtras USING [CheckForAbort], Rope; PigsInSpace: CEDAR PROGRAM IMPORTS Commander, CommandTool, Convert, FSBackdoor, IO, ProcessExtras = BEGIN ROPE: TYPE = Rope.ROPE; STREAM: TYPE = IO.STREAM; PigsInSpaceProc: Commander.CommandProc = { <<[cmd: REF CommandObject] RETURNS [result: REF _ NIL, msg: ROPE _ NIL]>> <> <> <> <> <<>> out: STREAM _ cmd.out; count: INT _ 10; pigItem: TYPE = RECORD [ fullGName: ROPE _ NIL, bytes: INT _ 0 ]; pigArray: TYPE = RECORD [ items: SEQUENCE length: NAT OF pigItem ]; pigs: REF pigArray; minBytes: INT _ 0; infoProc: FSBackdoor.InfoProc = { <> victim: NAT _ count+1; minBytesSoFar: INT _ LAST[INT]; ProcessExtras.CheckForAbort[]; IF bytes < minBytes THEN RETURN[TRUE]; FOR index: INT IN [0..count) DO IF pigs[index].bytes <= minBytes THEN {victim _ index; EXIT}; IF pigs[index].bytes < minBytesSoFar THEN { victim _ index; minBytesSoFar _ pigs[index].bytes; }; ENDLOOP; IF victim = count+1 THEN RETURN[TRUE]; pigs[victim].fullGName _ fullGName; minBytes _ pigs[victim].bytes; pigs[victim].bytes _ bytes; RETURN[TRUE]; }; argv: CommandTool.ArgumentVector _ CommandTool.Parse[cmd ! CommandTool.Failed => {msg _ errorMsg; GO TO Usage}]; IF argv.argc > 2 THEN GOTO Usage; IF argv.argc = 2 THEN count _ Convert.IntFromRope[argv[1] ! Convert.Error => GOTO Usage]; IF count <= 0 THEN GOTO Usage; pigs _ NEW[pigArray[count]]; FSBackdoor.EnumerateCacheForInfo[ proc: infoProc]; FOR outputLine: INT IN [0..count) DO biggestIndex: NAT _ LAST[NAT]; biggestBytes: INT _ 0; FOR index: INT IN [0..count) DO IF pigs[index].bytes > biggestBytes THEN { biggestIndex _ index; biggestBytes _ pigs[index].bytes; }; ENDLOOP; IF biggestIndex = LAST[NAT] THEN EXIT; IO.PutF[out, " %-30g %g\n", [rope[pigs[biggestIndex].fullGName]], [integer[pigs[biggestIndex].bytes]]]; pigs[biggestIndex].bytes _ -1; ENDLOOP; pigs _ NIL; EXITS Usage => RETURN[$Failure, "Usage: PigsInSpace {count _ 10} "]; }; <<>> Init: PROCEDURE = { Commander.Register[ "///Commands/PigsInSpace", PigsInSpaceProc, "PigsInSpace {count _ 10} -- list `count' largest files cached"]; }; <<>> <> Init[]; END. <<>> <<>> <> <> <<>>