Version which support DEC SRC Modula-3 extensions
MODULE; IMPORT Pathname, TextRefTbl; VAR exts_g := NEW(TextRefTbl.Default).init(); PROCEDURE M3Extension ToText (t: T): TEXT = BEGIN CASE t OF T.Int => RETURN "i3"; | T.IntG => RETURN "ig"; | T.PInt => RETURN "pi"; | T.PIntR => RETURN "pir"; | T.Mod => RETURN "m3"; | T.ModG => RETURN "mg"; | T.PMod => RETURN "pm"; | T.PModR => RETURN "pmr"; | T.IObj => RETURN "io"; | T.MObj => RETURN "mo"; | T.Exe => RETURN "out"; | T.MC => RETURN "mc"; | T.IC => RETURN "ic"; | T.MX => RETURN "mx"; | T.IX => RETURN "ix"; | T.MAsm => RETURN "ms"; | T.IAsm => RETURN "is"; | T.Tmp => RETURN "tmp"; | T.ObjLib => RETURN "a"; | T.ObjLibX => RETURN "ax"; | T.Null => RETURN ""; END; END ToText; PROCEDUREFromText (text: TEXT; VAR t: T): BOOLEAN= VAR ref: REFANY; BEGIN IF exts_g.get(text, ref) THEN t := NARROW(ref, REF T)^; RETURN TRUE; ELSE RETURN FALSE; END; END FromText; PROCEDUREExtend (name: TEXT; t: T): TEXT= VAR b := Pathname.Base(name); BEGIN IF t = T.Null THEN RETURN b; ELSE RETURN Pathname.Join(NIL, b, ToText(t)); END; END Extend; PROCEDUREHas (name: TEXT; VAR t: T): BOOLEAN= BEGIN RETURN FromText(Pathname.LastExt(name), t); END Has; EXCEPTION Fatal; PROCEDUREInit () = BEGIN FOR i := FIRST(T) TO LAST(T) DO IF exts_g.put(ToText(i), NewRefT(i)) THEN <*FATAL Fatal*> BEGIN RAISE Fatal; END; END; END; (* for *) END Init; PROCEDURENewRefT (t: T): REF T= VAR r: REF T; BEGIN r := NEW(REF T); r^ := t; RETURN r; END NewRefT; BEGIN Init(); END M3Extension.