package vlt

  1. Overview
  2. Docs
A variant of Bolt logging tool

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.2.5.tar.gz
sha256=756a6cba94204cda45ee767ca5f7e52ec321873dd53de48025c32dba1e03de24
md5=c0f22efcafa1119a9c82ffd9d7422da2

doc/src/vlt/utils.ml.html

Source file utils.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
(*
 * This file is part of Bolt.
 * Copyright (C) 2009-2012 Xavier Clerc.
 *
 * Bolt is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Bolt 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *)

let verbose s =
  let print s =
    prerr_string " *** Bolt: ";
    prerr_endline s in
  try
    match String.uppercase_ascii (Sys.getenv "BOLT_SILENT") with
    | "YES" | "ON" -> ()
    | _ -> print s
  with Not_found -> print s

type 'a container = (string, 'a) Hashtbl.t

let make_container_functions () =
  let id = ref 0 in
  let container =
    Hashtbl.create 17 in
  let register name elem =
    Hashtbl.replace container name elem in
  let register_unnamed elem =
    while Hashtbl.mem container (string_of_int !id) do
      incr id
    done;
    let name = string_of_int !id in
    register name elem;
    name in
  let get name =
    Hashtbl.find container name in
  container, register, register_unnamed, get

let thread_id = ref (fun () -> 0)

let hook_before = ref (fun () -> ())

let hook_after = ref (fun () -> ())

let get_thread_id () = !thread_id ()

let enter_critical_section () =
  !hook_before ()

let leave_critical_section () =
  !hook_after ()

let split seps s =
  let idx = ref 0 in
  let len = String.length s in
  let buff = Buffer.create len in
  let res = ref [] in
  let in_sep = ref false in
  while !idx < len do
    if !in_sep then begin
      if not (String.contains seps s.[!idx]) then begin
        Buffer.add_char buff s.[!idx];
        in_sep := false
      end
    end else begin
      if String.contains seps s.[!idx] then begin
        res := (Buffer.contents buff) :: !res;
        Buffer.clear buff;
        in_sep := true
      end else
        Buffer.add_char buff s.[!idx]
    end;
    incr idx
  done;
  let last = Buffer.contents buff in
  if last <> "" then res := last :: !res;
  List.rev !res

let is_whitespace = function
  | ' ' | '\t' | '\r' | '\n' -> true
  | _ -> false

let trim_gen left right s =
  let i = ref 0 in
  let len = String.length s in
  if left then
    while (!i < len) && (is_whitespace s.[!i]) do
      incr i
    done;
  let j = ref (pred len) in
  if right then
    while (!j >= !i) && (is_whitespace s.[!j]) do
      decr j
    done;
  if j >= i then
    String.sub s !i (!j - !i + 1)
  else
    ""

let trim_left = trim_gen true false

let trim_right = trim_gen false true

let trim = trim_gen true true


let register_thread_functions f g h =
  thread_id := f;
  hook_before := g;
  hook_after := h

let paje_t = ref ""

let daikon_t = ref ""