Files
paparazzi/sw/lib/ocaml/debug.ml
T
Rijesh Augustine 3432c04b14 Ocaml Compatibility, Strings Deprecated Warning (#1705)
* Use camlp4 to select Bytes vs. String modules with a Compat module
* Fixed http.ml warning
2016-06-13 09:38:06 +02:00

48 lines
1.5 KiB
OCaml

(*
* Debugging facilities
*
* Copyright (C) 2004 CENA/ENAC, Pascal Brisset, Antoine Drouin
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)
let level = ref (try Sys.getenv "PPRZ_DEBUG" with Not_found -> "")
let log = ref stderr
let call lev f =
assert( (* assert permet au compilo de tout virer avec l'option -noassert *)
if (Compat.bytes_contains !level '*' || Compat.bytes_contains !level lev)
then begin
f !log;
flush !log
end;
true)
let trace lev s = call lev (fun f -> Printf.fprintf f "%s\n" s)
let xprint = fun s ->
let n = Compat.bytes_length s in
let a = Compat.bytes_make (3*n) ' ' in
for i = 0 to n - 1 do
let x = Printf.sprintf "%02x" (Char.code s.[i]) in
Compat.bytes_set a (3*i) x.[0];
Compat.bytes_set a (3*i+1) x.[1]
done;
a