DIRECTORY Basics, Commander, FS, IO, List, ProcMap, Rope; SearchForLog: CEDAR PROGRAM IMPORTS Commander, FS, IO, List, ProcMap, Rope = { STREAM: TYPE = IO.STREAM; ROPE: TYPE = Rope.ROPE; SortRecord: TYPE = RECORD [msg, mod, locProc: ROPE, src: INT, call: CHAR]; SortItem: TYPE = REF SortRecord; ShortName: PUBLIC PROC [rope: ROPE] RETURNS [ROPE] = { pos: INT _ Rope.Length[rope]; end: INT _ pos; WHILE pos > 0 DO under: INT = pos - 1; SELECT Rope.Fetch[rope, under] FROM '!, '. => end _ under; '>, '/, '<, '] => RETURN [Rope.Flatten[rope, pos, end-pos]]; ENDCASE; pos _ under; ENDLOOP; RETURN [Rope.Flatten[rope, 0, end]]; }; SetExt: PROC [fileName, ext: ROPE] RETURNS [ROPE] = { pos: INT _ Rope.Length[fileName]; dot: INT _ pos; WHILE pos > 0 DO under: INT = pos - 1; SELECT Rope.Fetch[fileName, under] FROM '. => {dot _ under; EXIT}; '>, '/ => EXIT; ENDCASE; pos _ under; ENDLOOP; RETURN [Rope.Cat[Rope.Substr[base: fileName, start: 0, len: dot], ".", ext]]; }; OpenFile: PROC [name: ROPE] RETURNS [st: STREAM] = { st _ FS.StreamOpen[name, $read ! FS.Error => IF error.group # bug THEN CONTINUE]}; MyTokenProc: IO.BreakProc = { RETURN[SELECT char FROM IN [IO.NUL .. IO.SP], ',, ':, ';, '[ => sepr, '], '(, '), '{, '}, '", '+, '-, '*, '/, '@, '_, '. => break, ENDCASE => other]}; SearchFile: PROC [fileName: ROPE, list: LIST OF REF ANY, log: STREAM] RETURNS[LIST OF REF ANY] = { st: STREAM; h: ProcMap.Handle; source, obj, short: ROPE; src: INT; ros: IO.STREAM; called, msg, locProc: ROPE; source _ SetExt[fileName, "mesa"]; obj _ SetExt[fileName, "bcd"]; short _ ShortName[fileName]; st _ OpenFile[source]; IF st = NIL THEN {log.PutRope[" can't be opened"]; RETURN[list]}; ros _ IO.ROS[]; h _ ProcMap.Create[obj]; DO ENABLE IO.EndOfStream => EXIT; IF Rope.Equal[st.GetTokenRope[MyTokenProc].token, "Log"] AND Rope.Equal[st.GetTokenRope[MyTokenProc].token, "."] THEN { src _ st.GetIndex[]; IF h = NIL THEN locProc _ NIL ELSE locProc _ h.FromSource[src]; called _ st.GetTokenRope[MyTokenProc].token; msg _ st.GetTokenRope[MyTokenProc].token; list _ CONS [NEW[SortRecord _ [ msg: msg, call: Rope.Fetch[called, 0], mod: short, locProc: locProc, src: src]], list]; }; ENDLOOP; RETURN[list]}; SearchListOfFiles: Commander.CommandProc = { CompareItems: List.CompareProc = TRUSTED { r1: SortItem = NARROW[ref1]; r2: SortItem = NARROW[ref2]; comp: Basics.Comparison _ Rope.Compare[r1.msg, r2.msg, FALSE]; IF comp # equal THEN RETURN[comp]; comp _ Rope.Compare[r1.mod, r2.mod, FALSE]; IF comp # equal THEN RETURN[comp]; SELECT r1.src FROM < r2.src => RETURN [less]; > r2.src => RETURN [greater]; ENDCASE => RETURN [equal]; }; ris: IO.STREAM _ IO.RIS[cmd.commandLine]; log: IO.STREAM _ cmd.err; out: IO.STREAM _ cmd.out; list: LIST OF REF ANY _ NIL; file: ROPE; DO ENABLE IO.EndOfStream => EXIT; file _ ris.GetTokenRope[IO.IDProc].token; log.PutF["\n%g", [rope[file]]]; list _ SearchFile[file, list, log]; ENDLOOP; log.PutRope["\nSorting..."]; list _ List.Sort[list, CompareItems]; WHILE list # NIL DO item: SortItem _ NARROW[list.first]; out.PutF["\n%-20g %g %5g %g \t%g", [rope[item.msg]], [character[item.call]], [integer[item.src]], [rope[item.mod]], [rope[item.locProc]]]; list _ list.rest; ENDLOOP; out.PutRope["\n"]; }; Commander.Register[ "SearchForLog", SearchListOfFiles, "Search list of files, finding all calls to Log"]; }. ΔSearchForLog.mesa Sweet November 25, 1985 11:44:32 am PST [cmd: Commander.Handle] RETURNS [result: REF ANY _ NIL, msg: ROPE _ NIL] [ref1: REF ANY, ref2: REF ANY] RETURNS [Basics.Comparison] Κ›˜codešœ™K™'—šΟk ˜ K˜K˜ Kšœ˜Kšœ˜K˜K˜K˜K˜—šœœ˜Kšœ œœ˜2Kšœœœœ˜Kšœœœ˜K˜Kš œ œœœœœ˜JKšœ œœ ˜ K˜š Οn œœœœœœ˜6Kšœœ˜Kšœœ˜šœ ˜Kšœœ ˜šœ˜#Kšœ˜Kšœœ%˜=Kšœ˜—K˜ Kšœ˜—Kšœ˜$K˜K˜—K˜š žœœœœœ˜5Kšœœ˜!Kšœœ˜šœ ˜Kšœœ ˜šœ˜'Kšœœ˜Kšœ œ˜Kšœ˜—K˜ Kšœ˜—KšœG˜MK˜K˜—š žœœœœœ˜4šœœ˜Kš œœ œœœ˜3—K˜—šœ œ˜šœœ˜Kš œœœœœ˜.Kšœ<˜Kšœœœ˜"Kšœ$œ˜+Kšœœœ˜"šœ˜Kšœ œ˜Kšœ œ ˜Kšœœ ˜—Kšœ˜—Kš œœœœœ˜)Kšœœœ ˜Kšœœœ ˜Kš œœœœœœ˜Kšœœ˜ š˜Kšœœœ˜Kšœœ˜)K˜K˜#Kšœ˜—K˜Kšœ%˜%šœœ˜Kšœœ ˜$˜"K˜K˜K˜K˜K˜—Kšœ˜Kšœ˜ —K˜K˜K˜—˜Kšœ"˜"Kšœ2˜2K˜—K˜——…— q