--ILTEraseImpl.mesa
--Created by
--   JFung.PASA	  	19-Sep-83 17:06:11

--last edited by
--   JFung.PASA	   	19-Dec-83 16:54:33



DIRECTORY
     Cursor USING [Set],
     LispToolOps USING [Data, DataHandle, toolData, GetVolumeID],
     PhysicalVolume USING [EraseLogicalVolume],
     Process USING [Pause, SecondsToTicks],
     Put USING [CR, Line, LongString, Text],
     SpecialVolume USING [OpenVolume],
     String USING [EquivalentString],
     Volume USING [
          GetLabelString, GetNext, GetType, ID, maxNameLength, NeedsScavenging,
          nullID, systemID, Type, TypeSet];



ILTEraseImpl: PROGRAM
     IMPORTS
          Cursor, LispToolOps, PhysicalVolume, Process, Put, 
	  SpecialVolume, String, Volume
     EXPORTS LispToolOps =

     BEGIN OPEN ILT: LispToolOps;
     
     debug: BOOLEAN ← FALSE;


     EraseProc: PUBLIC PROCEDURE [vName: LONG STRING] =
          BEGIN
          volumeID: Volume.ID ← Volume.nullID;

          IF debug THEN {
               Put.Line[ILT.toolData.fileSW, "Enter EraseProc..."L];
               --Process.Pause[Process.SecondsToTicks[5]];
               Put.LongString[ILT.toolData.fileSW, vName];
               Put.CR[ILT.toolData.fileSW];
               };

          [volumeID, ] ← ILT.GetVolumeID[vName];
          IF debug THEN Put.Text[ILT.toolData.fileSW, "Volume = "L];
          IF volumeID = Volume.nullID THEN
               BEGIN
               IF debug THEN Put.Line[ILT.toolData.fileSW, "Null ID"L];
               RETURN;
               END;
          Put.Text[ILT.toolData.fileSW, " Erasing... "L];
	  Cursor.Set[hourGlass];

          PhysicalVolume.EraseLogicalVolume[volumeID];
	  Cursor.Set[textPointer];
          Put.Line[ILT.toolData.fileSW, " Done"L];
          END;




     GetVolumeID: PUBLIC PROCEDURE [volumeName: LONG STRING]
          RETURNS [volumeID: Volume.ID ← Volume.nullID, volumeOpen: BOOLEAN] =

          BEGIN OPEN Volume;

          myType: Volume.Type = Volume.GetType[Volume.systemID];
          all: Volume.TypeSet ← [
               normal: TRUE,
               debugger: myType = debugger OR myType = debuggerDebugger,
               debuggerDebugger: myType = debuggerDebugger];
          name: STRING = [maxNameLength];

          IF debug THEN {
               Put.Line[ILT.toolData.fileSW, "Enter GetVolume..."L];
               --Process.Pause[Process.SecondsToTicks[10]];
               Put.LongString[ILT.toolData.fileSW, volumeName];
               Put.CR[ILT.toolData.fileSW];
               };
          volumeOpen ← FALSE;

          FOR volumeID ← GetNext[nullID, all], GetNext[volumeID, all] UNTIL
               volumeID = nullID DO
               name.length ← 0;
               Volume.GetLabelString[volumeID, name];
               IF String.EquivalentString[name, volumeName] THEN EXIT;
               ENDLOOP;


          SELECT volumeID FROM
               nullID =>
                    BEGIN
                    Put.LongString[ILT.toolData.msgSW, volumeName];
                    --Process.Pause[Process.SecondsToTicks[5]];
                    Put.Line[ILT.toolData.msgSW, "Volume not found!"L];
                    --Process.Pause[Process.SecondsToTicks[5]];
                    RETURN;
                    END;
               Volume.systemID =>
                    BEGIN
                    Put.LongString[ILT.toolData.fileSW, volumeName];
                    Put.Line[ILT.toolData.fileSW, " is your system volume!"L];
                    --Process.Pause[Process.SecondsToTicks[5]];
                    --RETURN;
                    END;

               ENDCASE;



          SpecialVolume.OpenVolume[
               volume: volumeID, access: readWrite !
               Volume.NeedsScavenging => GOTO BadVolume];
          volumeOpen ← TRUE;
          IF debug THEN {
               Put.Line[ILT.toolData.fileSW, "volume opened!"L];
               --Process.Pause[Process.SecondsToTicks[5]];
               };

          RETURN[volumeID, volumeOpen];

          EXITS
               BadVolume =>
                    BEGIN
                    Put.Line[ILT.toolData.msgSW, "Can not open volume "L];
                    Put.LongString[ILT.toolData.fileSW, volumeName];
                    Put.Line[ILT.toolData.fileSW, " needs scavenging."L];
                    Process.Pause[Process.SecondsToTicks[10]];
                    END;

          END;

     END...