(* ||M|| This file is part of HELM, an Hypertextual, Electronic ||A|| Library of Mathematics, developed at the Computer Science ||T|| Department, University of Bologna, Italy. ||I|| ||T|| HELM is free software; you can redistribute it and/or ||A|| modify it under the terms of the GNU General Public License \ / version 2 or (at your option) any later version. \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) module KT = String module KP = Printf module U = NUri type ('b, 'c) item = Term of 'b * 'c | LEnv of 'b | Warn of string | Uri of U.uri type ('b, 'c) message = ('b, 'c) item list type ('a, 'b, 'c) specs = { pp_term: 'a -> 'b -> out_channel -> 'c -> unit; pp_lenv: 'a -> out_channel -> 'b -> unit } (* Internal functions *******************************************************) let std = stdout let err = stderr let pp_items och a st l items = let indent = KT.make (l+l) ' ' in let pp_item och = function | Term (c, t) -> KP.fprintf och "%s%a\n" indent (st.pp_term a c) t | LEnv c -> KP.fprintf och "%s%a\n" indent (st.pp_lenv a) c | Warn s -> KP.fprintf och "%s%s\n" indent s | Uri u -> KP.fprintf och "%s<%s>\n" indent (U.string_of_uri u) in let iter map och l = List.iter (map och) l in KP.fprintf och "%a%!" (iter pp_item) items (* Interface functions ******************************************************) let log a st l items = pp_items std a st l items let error a st items = pp_items err a st 0 items let items1 s = [Warn s] let t_items1 st c t = [Warn st; Term (c, t)] let et_items1 sc c st t = [Warn sc; LEnv c; Warn st; Term (c, t)] let et_items2 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 = let tl = match sc2, c2 with | Some sc2, Some c2 -> et_items1 sc2 c2 st2 t2 | None, None -> t_items1 st2 c1 t2 | _ -> assert false in et_items1 sc1 c1 st1 t1 @ tl let et_items3 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 ?sc3 ?c3 st3 t3 = let tl = match sc3, c3 with | Some sc3, Some c3 -> et_items1 sc3 c3 st3 t3 | None, None -> t_items1 st3 c1 t3 | _ -> assert false in et_items2 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 @ tl let specs = { pp_term = (fun _ _ _ _ -> ()); pp_lenv = (fun _ _ _ -> ()); } let warn level str = log () specs level (items1 str)