WhitePagesImpl.mesa
Interface to "Callup" databases
Last modified by Swinehart, January 12, 1984 7:05 pm
Last modified by Stewart, June 20, 1983 11:21 am
Last Edited by: Lia, July 26, 1983 6:17 pm
DIRECTORY
IO,
Rope USING [
Cat, Concat, Equal, Fetch, Length, MakeRope, ROPE, Substr],
ThNet
;
WhitePagesImpl: CEDAR PROGRAM
IMPORTS IO, Rope
EXPORTS ThNet = {
ROPE:TYPE=Rope.ROPE;
localPrefix: ROPE = "8923";
localDDDPrefix: ROPE = "9415";
intelnetPause: ROPE ← "\017";
lpLen: NAT = 4;
sp: REF IO.StreamProcs = IO.CreateStreamProcs[
variety: input,
class: $Undecorate,
getChar: UndecorateChar
];
HowToDial: PUBLIC PROC[phoneNumber: ROPE, ownExtension: ROPE]
RETURNS [whatToDial: ROPE, isLocalExtension: BOOLEAN] = {
phoneNumber ←
IO.GetLineRope[IO.CreateStream[sp,NIL,IO.RIS[phoneNumber]]!IO.EndOfStream=>{
phoneNumber←NIL; CONTINUE; }];
Phone number should now have no cosmetic characters in it . . . only digits.
SELECT phoneNumber.Length[] FROM
7, 10 => phoneNumber ← Rope.Concat["9", phoneNumber];
ENDCASE;
IF phoneNumber.Substr[len: lpLen].Equal[localPrefix]
THEN RETURN [phoneNumber.Substr[start: lpLen], TRUE]
ELSE IF phoneNumber.Substr[len: lpLen].Equal[localDDDPrefix]
THEN RETURN [Rope.Concat["9", phoneNumber.Substr[start: lpLen]], TRUE]
ELSE IF phoneNumber.Length[] >= 8 AND phoneNumber.Fetch[0] = '8 THEN
Intelnet number: wait 1.5 seconds after "8" and before auth. code (ownExtension)
(Any very small characters in a phone number are interpreted as 100 ms. pause intervals)
RETURN[
Rope.Cat["8", intelnetPause, phoneNumber.Substr[start: 1], intelnetPause, ownExtension],
FALSE]
ELSE RETURN [phoneNumber, phoneNumber.Length[]<6]; };
UndecorateChar: PROC[self: IO.STREAM] RETURNS[CHAR] = {
DO
c: CHAR=self.backingStream.GetChar[];
IF c IN ['0..'9] THEN RETURN[c];
ENDLOOP;
};
FeepName: PUBLIC PROC[rName: ROPE] RETURNS[feepName: ROPE] = {
RETURN[Rope.MakeRope[base: rName, size: rName.Length[], fetch: FeepFetch]]; };
FeepFetch: PROC[data: REF, index: INT] RETURNS [c: CHAR] = {
c←NARROW[data, ROPE].Fetch[index];
IF c IN ['A..'Z] THEN c𡤌+('a-'A);
IF c NOT IN ['a..'z] THEN c←'z+1;
RETURN[FeepMap[c]];
};
FeepMap: PACKED ARRAY CHAR['a..'z+1] OF CHAR = [
'2, '2, '2, '3, '3, '3, '4, '4, '4, '5, '5, '5, '6, '6, '6, '7, '7, '7, '7, '8, '8, '8, '9, '9, '9, '9, '1 ];
}.