-- TempFileManager.mesa -- created by Schroeder, November 18, 1980 9:19 PM -- edited by Brotz, March 11, 1983 10:21 AM DIRECTORY Core USING [Close, Open], exD: FROM "ExceptionDefs" USING [SysBug], Storage USING [Node], String USING [AppendDecimal, AppendString], tfD: FROM "TempFileDefs", VMDefs USING [CantOpen, FileHandle, GetFileLength, SetFileLength]; TempFileManager: MONITOR IMPORTS Core, exD, Storage, String, VMDefs EXPORTS tfD = BEGIN TempFile: TYPE = RECORD [c: CARDINAL, h: VMDefs.FileHandle, n: POINTER TO TempFile]; alloc: POINTER TO TempFile _ NIL; --checked out temp files free: POINTER TO TempFile _ NIL; --freed temp files tmpFileCntr: CARDINAL _ 100; AllocateTempFile: PUBLIC ENTRY PROCEDURE RETURNS [VMDefs.FileHandle] = BEGIN t: POINTER TO TempFile; fnm: STRING _ [10]; IF free = NIL THEN BEGIN -- generate a new temp file node t _ Storage.Node[SIZE[TempFile]]; IF (tmpFileCntr _ tmpFileCntr - 1) = 0 THEN exD.SysBug[]; t.c _ tmpFileCntr; END ELSE -- take one from free list -- {t _ free; free _ t.n}; t.n _ alloc; alloc _ t; DO String.AppendString[fnm, "DMS-"L]; String.AppendDecimal[fnm, t.c]; String.AppendString[fnm, ".TMP"L]; t.h _ Core.Open[fnm, update ! VMDefs.CantOpen => BEGIN fnm.length _ 0; IF (tmpFileCntr _ tmpFileCntr - 1) = 0 THEN GO TO OutOfFiles; t.c _ tmpFileCntr; LOOP; END]; EXIT; REPEAT OutOfFiles => exD.SysBug[]; ENDLOOP; RETURN[t.h]; END; -- of AllocateTempFile -- FreeTempFile: PUBLIC ENTRY PROCEDURE [h: VMDefs.FileHandle] = BEGIN current: POINTER TO TempFile; previous: POINTER TO TempFile _ NIL; FOR current _ alloc, current.n UNTIL current = NIL DO IF current.h = h THEN EXIT; previous _ current; REPEAT FINISHED => exD.SysBug[]; ENDLOOP; IF previous = NIL THEN alloc _ current.n ELSE previous.n _ current.n; current.n _ free; free _ current; IF VMDefs.GetFileLength[current.h].page > 3 THEN VMDefs.SetFileLength[current.h, [4, 0]]; Core.Close[current.h]; current.h _ NIL; END; -- of FreeTempFile -- END. -- of TempFileManager -- (635)\f1 326f0 2f1