<> <> <<>> DIRECTORY Process USING [CheckForAbort], FS USING [ErrorDesc, Error, StreamOpen, ExpandName], IO USING [STREAM, GetIndex, PutF], RopeFile USING [FromStream], Rope USING [ROPE, Concat, Equal, Length, Fetch], Commander USING [CommandProc, Register, Handle], CommandTool USING [ArgumentVector, Parse, Failed], FileNames USING [ResolveRelativePath, IsAPattern, IsADirectory, ConvertToSlashFormat, CurrentWorkingDirectory], ISMessage USING [OpenTempFile, OpenTiogaOutput, WriteTiogaOutputFile], ISNode USING [Implementation, ImplementationObject, GetImplementation, SetImplementation], ISTiogaIntern USING [DefaultPrintProc, DefaultInternalizeProc, InternalizeDocument, PrintPara, InternalizePara, PrintChars, InternalizeChars, InternalizeStyle, InternalizeProperties, InternalizeLooks], ISToken USING [NodeTVHandle], ISScan USING [CreateScan, CollectNode, ScanHandle, InitializeScanThroughCurly, AdvanceScan]; TiogaFromISImpl: CEDAR PROGRAM IMPORTS Commander, CommandTool, FileNames, FS, IO, RopeFile, ISScan, ISNode, ISTiogaIntern, ISMessage, Rope, Process ~ BEGIN TiogaFromISProc: Commander.CommandProc = { <<[cmd: Commander.Handle] RETURNS [result: REF ANY _ NIL, msg: ROPE _ NIL]>> destinationDirectory: Rope.ROPE _ NIL; leftArrowExists: BOOL; FSErrorMsg1: PROC [error: FS.ErrorDesc] RETURNS [Rope.ROPE] = { SELECT error.group FROM lock => RETURN[" -- locked!"]; ENDCASE => IF error.code = $unknownFile THEN RETURN [" -- not found!"] ELSE RETURN[Rope.Concat["\n -- FS.Error: ", error.explanation]]; }; HandleAFile: PROC [to, from: Rope.ROPE] = { Process.CheckForAbort[]; cmd.out.PutF[" %g _ %g\n", [rope[to]], [rope[from]]]; {ENABLE FS.Error => IF error.group # bug THEN {msg _ FSErrorMsg1[error];}; s: IO.STREAM _ FS.StreamOpen[to, $create]; script: Rope.ROPE; i: INT; pattern: Rope.ROPE; handle: ISToken.NodeTVHandle; scanner: ISScan.ScanHandle; implementation, documentImpl, paraImpl, charsImpl, styleImpl, propertiesImpl, looksImpl: ISNode.Implementation; ISMessage.OpenTempFile[]; ISMessage.OpenTiogaOutput[to]; pattern _ from; pattern _ FileNames.ResolveRelativePath[pattern]; pattern _ FS.ExpandName[pattern].fullFName; s _ FS.StreamOpen[pattern]; i _ IO.GetIndex[s]; script _ RopeFile.FromStream[s]; documentImpl _ NEW[ISNode.ImplementationObject]; documentImpl.internalize _ ISTiogaIntern.InternalizeDocument; [] _ ISNode.SetImplementation [$DOCUMENT, $Tioga, documentImpl]; paraImpl _ NEW[ISNode.ImplementationObject]; paraImpl.internalize _ ISTiogaIntern.InternalizePara; paraImpl.printTioga _ ISTiogaIntern.PrintPara; [] _ ISNode.SetImplementation [$PARA, $Tioga, paraImpl]; charsImpl _ NEW[ISNode.ImplementationObject]; charsImpl.internalize _ ISTiogaIntern.InternalizeChars; charsImpl.printTioga _ ISTiogaIntern.PrintChars; [] _ ISNode.SetImplementation [$CHARS, $Tioga, charsImpl]; styleImpl _ NEW[ISNode.ImplementationObject]; styleImpl.internalize _ ISTiogaIntern.InternalizeStyle; [] _ ISNode.SetImplementation [$STYLE, $Tioga, styleImpl]; looksImpl _ NEW[ISNode.ImplementationObject]; looksImpl.internalize _ ISTiogaIntern.InternalizeLooks; [] _ ISNode.SetImplementation [$LOOKS, $Tioga, looksImpl]; propertiesImpl _ NEW[ISNode.ImplementationObject]; propertiesImpl.internalize _ ISTiogaIntern.InternalizeProperties; [] _ ISNode.SetImplementation [$PROPERTIES, $Tioga, propertiesImpl]; implementation _ ISNode.GetImplementation[NIL, NIL]; implementation.internalize _ ISTiogaIntern.DefaultInternalizeProc; implementation.printTioga _ ISTiogaIntern.DefaultPrintProc; [] _ ISNode.SetImplementation[NIL, NIL, implementation]; scanner _ ISScan.CreateScan[base: script, index: i]; ISScan.InitializeScanThroughCurly[scanner]; ISScan.AdvanceScan[scanner]; handle _ ISScan.CollectNode[scanner]; ISMessage.WriteTiogaOutputFile[]; }; }; argv: CommandTool.ArgumentVector _ CommandTool.Parse[cmd ! CommandTool.Failed => {msg _ errorMsg; GO TO Die}]; nArgs: NAT _ argv.argc; { <> i: NAT _ 1; length: INT; Bump: PROC [scratch: NAT] = { FOR j: NAT IN (scratch..nArgs) DO argv[j - 1] _ argv[j]; ENDLOOP; nArgs _ nArgs - 1; }; <<>> WHILE i < nArgs DO length _ argv[i].Length[]; SELECT TRUE FROM length = 0 => Bump[i]; argv[i].Fetch[0] = '- => { FOR j: INT IN [1..length) DO SELECT argv[i].Fetch[j] FROM <> ENDCASE; ENDLOOP; Bump[i]; }; ENDCASE => i _ i + 1; ENDLOOP; }; -- end of switch processing <<>> <> leftArrowExists _ nArgs >= 3 AND Rope.Equal[argv[2], "_"]; FOR i: NAT IN [1..nArgs) DO argv[i] _ FileNames.ConvertToSlashFormat[FileNames.ResolveRelativePath[argv[i]]]; ENDLOOP; IF leftArrowExists THEN { IF FileNames.IsADirectory[argv[1]] THEN destinationDirectory _ argv[1] ELSE { IF nArgs # 4 OR FileNames.IsAPattern[argv[1]] OR FileNames.IsAPattern[argv[3]] THEN RETURN[$Failure, "Bad syntax for copying a file"]; HandleAFile[from: argv[3], to: argv[1]]; RETURN[IF msg # NIL THEN $Failure ELSE NIL, msg]; }; } ELSE destinationDirectory _ FileNames.ConvertToSlashFormat[FileNames.CurrentWorkingDirectory[]]; EXITS Die => result _ $Failure; }; Commander.Register["TiogaFromIS", TiogaFromISProc, "TiogaFromIS _ "]; END.