File: BuildFileImpl.mesa   
Copyright © 1984 by Xerox Corporation. All rights reserved.
Created by: August 16, 1984 6:43:29 pm PDT
Last Edited by: Mayo, August 17, 1984 6:00:17 pm PDT
DIRECTORY
BuildFile,
TiogaOps, TiogaExtraOps, FS,
Rope USING [ROPE, Cat];
BuildFileImpl: CEDAR PROGRAM    
IMPORTS TiogaOps, TiogaExtraOps, FS, Rope EXPORTS BuildFile = BEGIN
OPEN BuildFile;
-- Prepare a template from a Tioga file with key fields.
OpenTemplate: PUBLIC PROC[fileName: Rope.ROPE] RETURNS[Handle] = BEGIN
-- valid = TRUE if successful
handle: Handle;
haveError: BOOLFALSE;
handle.rootRef ← TiogaExtraOps.GetFile[fileName ! FS.Error => {haveError ← TRUE; CONTINUE}];
handle.valid ← ~haveError;
RETURN[handle];
END;
-- Substitute all occurences of key with value
Substitute: PUBLIC PROC[hand: Handle, key: Rope.ROPE, value: Rope.ROPE] = BEGIN
found: BOOL;
pat: TiogaOps.Pattern ← TiogaOps.CreateSimplePattern[target: Rope.Cat["", key, ""], case: TRUE, literal: TRUE];
DO
[found, start, end] ← TiogaOps.NodeSearch[pattern: pat, whichDir: $anywhere, startLoc: , endLoc: TiogaOps.LastLocWithin[hand.rootRef]];
IF ~found THEN EXIT;
ENDLOOP;
END;
-- Write the resulting file, invalidating the handle.
WriteAndClose: PUBLIC PROC[hand: Handle, fileName: Rope.ROPE] = BEGIN
TiogaExtraOps.PutFile[fileName, hand.rootRef];
TiogaExtraOps.FreeTree[hand.rootRef];
hand.rootRef ← NIL;
hand.valid ← FALSE;
END;
END.