FastReader:
CEDAR PROGRAM
IMPORTS Commander, CommandTool, File, FileInternal, IO
= BEGIN
FastReaderProc: Commander.CommandProc = {
NowPage: FileInternal.EnumeratePagesProc =
TRUSTED {
PROC[status: Disk.Status, da: VolumeFormat.LogicalPage, label: POINTER TO Disk.Label] RETURNS[exit: BOOL ← FALSE];
count ← count+1;
IF count > 10000 THEN exit ← TRUE;
};
argv: CommandTool.ArgumentVector;
volume: File.Volume;
volumeFree: INT;
volumeSize: INT;
badStatus: INT ← 0;
count: INT ← 0;
argv ← CommandTool.Parse[cmd: cmd
! CommandTool.Failed => { msg ← errorMsg; CONTINUE; }];
IF argv = NIL THEN GOTO Failed;
IF argv.argc # 2 THEN GOTO Usage;
volume ← File.FindVolumeFromName[argv[1]];
IF volume = NIL THEN GOTO NoVolume;
[size: volumeSize, free: volumeFree] ← File.LogicalInfo[volume];
FileInternal.EnumeratePages[volume: volume, start: [0], skipBadPages: TRUE, work: NowPage];
cmd.out.PutF[" Volume %g is %s pages with %g pages free in the VAM\n",
IO.rope[argv[1]], IO.int[volumeSize], IO.int[volumeFree] ];
cmd.out.PutF[" Count %g \n",
IO.int[count]];
EXITS
Failed => RETURN[$Failure, msg];
Usage => RETURN[$Failure, " Usage: FastReader volumename\n"];
NoVolume => RETURN[$Failure, " No such volume\n"];
};
CHECKED
BEGIN
Commander.Register[key: "FastReader", proc: FastReaderProc, doc: "Read volume as fast as possible"];
END;