as is
without express or implied warranty. Export of this
software outside of the United States of America may require an
export license.
MODULE; IMPORT Wr; FROM Stdio IMPORT stderr; IMPORT Env, Scan; IMPORT FloatMode, Lex; EXCEPTION ABORT; PROCEDURE Debug Out (t: TEXT; minLevel : CARDINAL) = BEGIN IF minLevel > level THEN RETURN END; TRY Wr.PutText(stderr, UnNil(t) & "\n"); Wr.Flush(stderr); EXCEPT ELSE END; END Out; PROCEDURES (t: TEXT; minLevel : CARDINAL) = BEGIN Out(t, minLevel); END S; PROCEDUREWarning (t: TEXT) = BEGIN TRY Wr.PutText(stderr,"WARNING: " & UnNil(t) & "\n"); Wr.Flush(stderr); EXCEPT ELSE END; END Warning; PROCEDUREError (t: TEXT) = <*FATAL ABORT*> BEGIN TRY Wr.PutText(stderr,"ERROR: " & UnNil(t) & "\n"); Wr.Flush(stderr); EXCEPT ELSE END; RAISE ABORT; END Error; PROCEDUREUnNil (text : TEXT) : TEXT = BEGIN IF text = NIL THEN RETURN "(NIL)" ELSE RETURN text END END UnNil; PROCEDURERaiseLevel (newLevel : CARDINAL) = BEGIN IF newLevel > level THEN level := newLevel END END RaiseLevel; PROCEDURELowerLevel (newLevel : CARDINAL) = BEGIN IF newLevel < level THEN level := newLevel END END LowerLevel; PROCEDURESetLevel (newLevel : CARDINAL) = BEGIN level := newLevel END SetLevel; PROCEDUREGetLevel () : CARDINAL = BEGIN RETURN level END GetLevel; VAR level := 0; BEGIN VAR debugStr := Env.Get("DEBUGLEVEL"); BEGIN TRY IF debugStr # NIL THEN level := Scan.Int(debugStr) END EXCEPT Lex.Error, FloatMode.Trap => Error("DEBUGLEVEL set to nonsense! \"" & debugStr & "\"") END END END Debug.