Convert:
PROC [tdir, schema:
ROPE]
RETURNS [] ~ {
s: STREAM;
fname, shortname, basename, logname: ROPE;
cp: FS.ComponentPositions;
root: TextNode.Ref;
File names
[fname, cp] ← FS.ExpandName[schema];
shortname ← Rope.Substr[base: fname, start: cp.base.start, len: cp.ver.start - cp.base.start];
basename ← Rope.Substr[base: fname, start: cp.base.start, len: cp.base.length];
logname ← Rope.Concat[Rope.Substr[base: fname, start: 0, len: cp.base.start+cp.base.length], ".lblog"];
Write log file
s ← FS.StreamOpen[fileName: logname, accessOptions: create];
root ← PutGet.FromFile[fileName: tdir];
FOR node: TextNode.Ref ← TextNode.StepForward[root], TextNode.StepForward[node]
WHILE node#
NIL
DO
For each non-comment node, write it to the log file.
commentProp: REF BOOL ← NARROW[NodeProps.GetProp[node, $Comment]];
IF commentProp#NIL AND commentProp^ THEN LOOP;
ParseAndOutput[s, TextNode.NodeRope[node]];
ENDLOOP;
IO.PutF[s, "\377"];
IO.Close[s];
Write schema file
s ← FS.StreamOpen[fileName: fname, accessOptions: create];
IO.PutF[s, "-- %g\n", IO.rope[shortname]];
IO.PutF[s, "-- A LoganBerry schema file for a Finch personal telephone directory\n"];
IO.PutF[s, "-- Created by TDirToLoganBerry from %g\n", IO.rope[tdir]];
IO.PutF[s, "\n"];
IO.PutF[s, "Directory [Indigo]<Voice>Loganberry>Top>\n"];
IO.PutF[s, " %g\n", IO.rope[shortname]];
IO.PutF[s, "\n"];
IO.PutF[s, "Directory [Indigo]<Voice>Loganberry>%g>\n", IO.rope[basename]];
IO.PutF[s, " --> log 0 readwrite\n"];
IO.PutF[s, " %g\n", IO.rope[Rope.Concat[basename, ".lblog"]]];
IO.PutF[s, "\n"];
IO.PutF[s, " --> index \"name\" primary\n"];
IO.PutF[s, " %gName.lbindex\n", IO.rope[basename]];
IO.PutF[s, " --> index \"rname\" secondary\n"];
IO.PutF[s, " %gRname.lbindex\n", IO.rope[basename]];
IO.PutF[s, " --> index \"officenumber\" secondary\n"];
IO.PutF[s, " %gOfficePhone.lbindex\n", IO.rope[basename]];
IO.PutF[s, " --> index \"homenumber\" secondary\n"];
IO.PutF[s, " %gHomePhone.lbindex\n", IO.rope[basename]];
IO.Close[s];
};
Doit: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
get file name from command line if present, otherwise use profile entry
tdir, schema: ROPE;
fname: ROPE;
cp: FS.ComponentPositions;
s: STREAM;
tdir ← CommandTool.NextArgument[cmd];
IF tdir =
NIL
THEN {
-- code taken from FinchDirectoryImpl
tdir ← UserProfile.Token[key: "Finch.TelephoneDirectory"];
IF tdir = NIL THEN RETURN[msg: "usage: TDirToLoganBerry file.tdir fileTDir.lbdf"];
s ← IO.RIS[tdir];
UNTIL
IO.EndOf[s]
DO
tdir ← IO.GetLineRope[s];
IF NOT Rope.Equal[tdir,""] THEN EXIT;
ENDLOOP;
};
schema ← CommandTool.NextArgument[cmd];
IF schema =
NIL
THEN {
[fname, cp] ← FS.ExpandName[tdir];
schema ← Rope.Concat[Rope.Substr[base: fname, start: 0, len: cp.base.start+cp.base.length], "TDir.lbdf"];
};
Convert[tdir, schema];
};
Commander.Register[key: "TDirToLoganBerry", proc: Doit, doc: "convert a Finch TDir file into a LoganBerry database
usage: TDirToLoganBerry file.tdir fileTDir.lbdf"];