DIRECTORY Commander USING [CommandProc, Register], CommandTool USING [ArgumentVector, Parse, Failed], Rope USING [ROPE, Equal, Concat, Length, Fetch, Substr], FileNames USING [ResolveRelativePath, IsAPattern, IsADirectory, ConvertToSlashFormat, CurrentWorkingDirectory], TiogaAccess USING [Reader, FromFile, DoneWith, Get, Peek, GetExternalProp, GetNodeProps, EndOf, Look, Looks, TiogaChar, SkipToNextNode], Process USING [CheckForAbort], FS USING [ErrorDesc, Error, StreamOpen], IO USING [STREAM, PutRope, PutChar, PutF, --int,-- char, rope, atom, Close--, Flush--], Atom USING [PropList, DottedPair, GetPName, MakeAtom, GetPropFromList]; ISFromTioga: CEDAR PROGRAM IMPORTS Commander, CommandTool, Rope, FileNames, TiogaAccess, Process, FS, IO, Atom ~ BEGIN TiogaToISProc: Commander.CommandProc = { 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", [rope[to]], [rope[from]]]; {ENABLE FS.Error => IF error.group # bug THEN {msg _ FSErrorMsg1[error]; GO TO skipIt}; s: IO.STREAM _ FS.StreamOpen[to, $create]; r: TiogaAccess.Reader _ TiogaAccess.FromFile[from]; d: INT --_ 0--; EmitNodes: PROC ~ { DO noLooks: TiogaAccess.Looks = ALL[FALSE]; looks: TiogaAccess.Looks _ noLooks; started: BOOL _ FALSE; format: ATOM _ TiogaAccess.Peek[r].format; comment: BOOL _ TiogaAccess.Peek[r].comment; secondaryTags: LIST OF ATOM _ NIL; tag: Rope.ROPE _ TiogaAccess.GetExternalProp[$ISTag, Atom.GetPropFromList[TiogaAccess.GetNodeProps[r], $ISTag]]; EmitBindings: PROC [t: ATOM, propList: Atom.PropList] ~ { FOR l: Atom.PropList _ propList, l.rest UNTIL l=NIL DO binding: Atom.DottedPair _ l.first; IF BindingTag[NARROW[binding.key]]=t THEN IO.PutF[s, "%g%g=%g ", IO.rope[IF t=$PROPERTIES THEN "PROPERTIES." ELSE ""], IO.atom[NARROW[binding.key]], IO.rope[TiogaAccess.GetExternalProp[NARROW[binding.key], binding.val]]]; ENDLOOP; IF t=$PROPERTIES AND comment THEN IO.PutF[s, "PROPERTIES.Comment= "]; }; BindingTag: PROC [b: ATOM] RETURNS [ATOM] ~ { n: Rope.ROPE = Atom.GetPName[b]; i: INT _ 0; l: INT = Rope.Length[n]; WHILE i}\n"] ELSE started _ TRUE; IO.PutRope[s, "{CHARS$ LOOKS$ "]; FOR l: TiogaAccess.Look IN [FIRST[TiogaAccess.Look]..LAST[TiogaAccess.Look]] DO IF looks[l] THEN IO.PutF[s, "LOOKS.%g=TRUE ", IO.char[l]]; ENDLOOP; IO.PutChar[s, '<] } ELSE { IF started THEN IO.PutRope[s, ">}\n"] ELSE started _ TRUE; IO.PutRope[s, "{CHARS$ <"] } } ELSE IF NOT started THEN { IO.PutRope[s, "{CHARS$ <"]; started _ TRUE }; IO.PutChar[s, c.char]; IF c.char='> THEN IO.PutChar[s, c.char]; IF c.endOfNode THEN { d _ c.deltaLevel; EXIT }; ENDLOOP; IO.PutRope[s, ">}"]; END ELSE IF Rope.Equal[tag, "CHARS"] THEN BEGIN IO.PutRope[s, "<"]; BEGIN c: TiogaAccess.TiogaChar; c.endOfNode _ FALSE; UNTIL c.endOfNode DO c _ TiogaAccess.Get[r]; IO.PutChar[s, c.char]; ENDLOOP; d _ c.deltaLevel; END; IO.PutRope[s, ">"]; END ELSE d _ TiogaAccess.SkipToNextNode[r]; --No text in unknown nodes-- WHILE d<1 DO { d _ d+1; IO.PutChar[s, '}]; } ENDLOOP; IO.PutChar[s, '\n]; IF TiogaAccess.EndOf[r] THEN EXIT; }; ENDLOOP; }; IO.PutRope[s," {DOCUMENT$\n"]; EmitNodes[]; IO.PutRope[s, "}\n"]; IO.Close[s]; TiogaAccess.DoneWith[r]; EXITS skipIt => {}; }; cmd.out.PutRope["\n"]; }; 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[ "ISFromTioga", TiogaToISProc, "ISFromTioga newFile _ oldFile", $ISFromTioga]; END. ˆISFromTioga.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. MKaplan, September 13, 1985 0:46:13 am PDT EXPORTS ExportsList [cmd: REF CommandObject] RETURNS [result: REF _ NIL, msg: ROPE _ NIL] CommandObject = [ in, out, err: STREAM, commandLine, command: ROPE, propertyList: List.AList, procData: CommandProcHandle] contents: REF; IF (contents _ Atom.GetPropFromList[TiogaAccess.GetNodeProps[r], $ISContents])#NIL THEN IO.PutF[s, "%g ", IO.rope[TiogaAccess.GetExternalProp[$ISContents, contents]]]; Process switches no switches... First find out whether there is a _ anywhere. If there is, it must be the second arg. Κ K˜™Icodešœ Οmœ1™