ConvertTunes.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Doug Terry, January 21, 1987 11:14:42 am PST
Program to convert the old TunesRefs LoganBerry log to a log of voice rope interests.
DIRECTORY
BasicTime USING [earliestGMT, Now, Period],
Commander USING [CommandProc, Register],
Convert USING [TimeFromRope],
IO USING [GetChar, PutFR, rope, int, STREAM],
LoganBerry USING [AttributeType, AttributeValue, Entry, Open, OpenDB, ReadEntry],
LoganBerryBackdoor USING [ReadLogEntry, WriteLogEntry, MarkUpdateComplete],
Rope USING [Equal, Find, Substr, ROPE];
ConvertTunes: CEDAR PROGRAM
IMPORTS BasicTime, Commander, Convert, IO, LoganBerry, LoganBerryBackdoor, Rope
~ BEGIN
RefsToInterests: PROC [rs, is: IO.STREAM] RETURNS [] ~ {
rs = log of old-style tunerefs,
is = log of newly-created voice rope interests
ref, interest: LoganBerry.Entry;
gvID, creator, time, rtp, interestID: Rope.ROPE;
timestamp: INT;
ref ← LoganBerryBackdoor.ReadLogEntry[logStream: rs, byte: 0];
UNTIL ref = NIL DO
extract info from ref
FOR e: LoganBerry.Entry ← ref, e.rest WHILE e # NIL DO
SELECT e.first.type FROM
$rtp => {
rtp ← e.first.value;
rtp ← IF Rope.Equal[rtp, "GVID"] THEN "WalnutMsg" ELSE rtp;
};
$cre => creator ← e.first.value;
$rid => {
gvID ← e.first.value;
gvID ← Rope.Substr[base: gvID, start: Rope.Find[s1: gvID, s2: "/"]+1];
};
$tim => {
time ← e.first.value;
timestamp ← BasicTime.Period[from: BasicTime.earliestGMT, to: Convert.TimeFromRope[time]];
};
ENDCASE => NULL;
ENDLOOP;
create a separate interest for each voice rope in ref
FOR e: LoganBerry.Entry ← ref, e.rest WHILE e # NIL DO
IF e.first.type = $vid THEN {
interest ← LIST[[$Class, rtp], [$RefID, gvID]];
interest ← CONS[[$VRID, e.first.value], interest];
interestID ← IO.PutFR["%g#%g", IO.rope[creator], IO.int[timestamp]];
timestamp ← timestamp + 1; -- so next IID is different
interest ← CONS[[$IID, interestID], interest];
IF Rope.Equal[rtp, "WalnutMsg"] THEN
[] ← LoganBerryBackdoor.WriteLogEntry[logStream: is, entry: interest, continuation: TRUE];
};
ENDLOOP;
get next ref entry
[] ← IO.GetChar[rs]; -- eat up EndOfEntry
ref ← LoganBerryBackdoor.ReadLogEntry[logStream: rs, byte: -1];
ENDLOOP;
LoganBerryBackdoor.MarkUpdateComplete[logStream: is];
};
TunesToTempInterests: PROC [vrs, is: IO.STREAM, idb: LoganBerry.OpenDB] RETURNS [] ~ {
vrs = log of voice ropes converted from tunes,
idb = LoganBerry database of existing interests,
is = log of newly created temporary interests for tune ropes without existing interests
vr, interest: LoganBerry.Entry;
vrID, interestID, creator: Rope.ROPE;
timestamp: INT ← BasicTime.Period[from: BasicTime.earliestGMT, to: BasicTime.Now[]];
vr ← LoganBerryBackdoor.ReadLogEntry[logStream: vrs, byte: 0];
UNTIL vr = NIL DO
vrID ← GetAttributeValue[vr, $VRID];
if vr has no existing interest, then create one
IF LoganBerry.ReadEntry[db: idb, key: $VRID, value: vrID].entry = NIL THEN {
creator ← GetAttributeValue[vr, $Creator];
interestID ← IO.PutFR["%g#%g", IO.rope[creator], IO.int[timestamp]];
timestamp ← timestamp + 1; -- so next IID is different
interest ← LIST[[$IID, interestID], [$VRID, vrID], [$Class, "OldTune"], [$RefID, "temporary"]];
[] ← LoganBerryBackdoor.WriteLogEntry[logStream: is, entry: interest, continuation: TRUE];
};
get next vr entry
[] ← IO.GetChar[vrs]; -- eat up EndOfEntry
vr ← LoganBerryBackdoor.ReadLogEntry[logStream: vrs, byte: -1];
ENDLOOP;
LoganBerryBackdoor.MarkUpdateComplete[logStream: is];
};
GetAttributeValue: PROC [entry: LoganBerry.Entry, type: LoganBerry.AttributeType] RETURNS [LoganBerry.AttributeValue] ~ {
FOR e: LoganBerry.Entry ← entry, e.rest WHILE e # NIL DO
IF e.first.type = type THEN
RETURN[e.first.value];
ENDLOOP;
RETURN[NIL];
};
TempInterestsProc: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL]
Assumes that the TuneRopes log is given as standard input and the voice rope interests log is written as standard output.
TunesToTempInterests[vrs: cmd.in, is: cmd.out, idb: LoganBerry.Open[dbName: "TempVRRefs.db"]];
};
ConvertProc: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL]
Assumes that the TuneRefs log is given as standard input and the voice rope interests log is written as standard output.
RefsToInterests[rs: cmd.in, is: cmd.out];
};
Commander.Register[key: "ConvertTunes", proc: ConvertProc, doc: "Converts tune references to voice rope interests\n Usage: ConvertTunes < TunesRefs.dblog > TuneRopesRefs.dblog"];
Commander.Register[key: "TempInterests", proc: TempInterestsProc, doc: "Creates temporary interests for tune ropes\n Usage: TempInterests < TuneRopes.dblog > TempRopeRefs.dblog"];
END.
Doug Terry, January 8, 1987 5:46:46 pm PST
changes to: ConvertTunes, ~, GetAttributeValue
Doug Terry, January 20, 1987 4:29:33 pm PST
changes to: RefsToInterests, GetAttributeValue, ConvertProc, ~, DIRECTORY, IMPORTS
Doug Terry, January 21, 1987 11:14:42 am PST
changes to: RefsToInterests, DIRECTORY, TunesToTempInterests, GetAttributeValue, TempInterestsProc, ConvertProc, ~, IMPORTS