+(*
+ ||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 H = Hashtbl
+module S = Scanf
+module C = Cps
+
+type graph = string * (int -> int)
+
+let sorts = 2
+let sort = H.create sorts
+let index = ref 0
+
+(* Internal functions *******************************************************)
+
+let set_sort f (h:int) (s:string) =
+ H.add sort h s; f (succ h)
+
+(* Interface functions ******************************************************)
+
+let set_new_sorts f ss =
+ let f i = index := i; f i in
+ C.list_fold_left f set_sort !index ss
+
+let get_sort f h =
+ try f (Some (H.find sort h))
+ with Not_found -> f None
+
+let string_of_graph f (s, _) = f s
+
+let apply f (_, g) h = f (g h)
+
+let graph_of_string f s =
+ try
+ let x = S.sscanf s "Z%u" C.start in
+ if x > 0 then f (Some (s, fun h -> x + h)) else f None
+ with
+ S.Scan_failure _ | Failure _ | End_of_file -> f None
+
+let graph =
+ ref (graph_of_string (function Some g -> g | None -> assert false) "Z2")