~ubuntu-branches/debian/sid/frama-c/sid

« back to all changes in this revision

Viewing changes to src/lib/pretty_utils.ml

  • Committer: Bazaar Package Importer
  • Author(s): Mehdi Dogguy
  • Date: 2009-06-03 08:19:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090603081925-kihvxvt0wy3zc4ar
Tags: upstream-20081201.dfsg
Import upstream version 20081201.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(**************************************************************************)
 
2
(*                                                                        *)
 
3
(*  This file is part of Frama-C.                                         *)
 
4
(*                                                                        *)
 
5
(*  Copyright (C) 2007-2008                                               *)
 
6
(*    CEA (Commissariat � l'�nergie Atomique)                             *)
 
7
(*                                                                        *)
 
8
(*  you can redistribute it and/or modify it under the terms of the GNU   *)
 
9
(*  Lesser General Public License as published by the Free Software       *)
 
10
(*  Foundation, version 2.1.                                              *)
 
11
(*                                                                        *)
 
12
(*  It is distributed in the hope that it will be useful,                 *)
 
13
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
 
14
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *)
 
15
(*  GNU Lesser General Public License for more details.                   *)
 
16
(*                                                                        *)
 
17
(*  See the GNU Lesser General Public License version 2.1                 *)
 
18
(*  for more details (enclosed in the file licenses/LGPLv2.1).            *)
 
19
(*                                                                        *)
 
20
(**************************************************************************)
 
21
 
 
22
(* $Id: pretty_utils.ml,v 1.5 2008/11/04 10:05:05 uid568 Exp $ *)
 
23
 
 
24
let sfprintf fmt =
 
25
  let b = Buffer.create 5 in
 
26
  let return fmt = Format.pp_print_flush fmt (); Buffer.contents b in
 
27
  Format.kfprintf return (Format.formatter_of_buffer b) fmt
 
28
 
 
29
let space_sep = format_of_string "@ "
 
30
let nl_sep = format_of_string "@\n"
 
31
 
 
32
let rec pp_print_string_fill out s =
 
33
  if String.contains s ' ' then begin
 
34
    let i = String.index s ' ' in
 
35
    let l = String.length s in
 
36
    let s1 = String.sub s 0 i in
 
37
    let s2 = String.sub s (i+1) (l - i - 1) in
 
38
      Format.fprintf out "%s@ %a" s1 pp_print_string_fill s2
 
39
  end else Format.pp_print_string out s
 
40
 
 
41
let open_box = format_of_string "@["
 
42
let close_box = format_of_string "@]"
 
43
 
 
44
let pp_list ?(pre=format_of_string "@[")
 
45
    ?(sep=format_of_string "") ?(suf=format_of_string "@]")
 
46
    pp_elt f l =
 
47
  let rec aux f l =
 
48
    match l with
 
49
        [] -> ()
 
50
      | e::l -> Format.fprintf f "%(%)%a%a" sep pp_elt e aux l
 
51
  in match l with
 
52
      [] -> ()
 
53
    | e::l -> Format.fprintf f "%(%)%a%a%(%)" pre pp_elt e aux l suf
 
54
 
 
55
let pp_opt
 
56
    ?(pre=format_of_string "")  ?(suf=format_of_string "") pp_elt f o =
 
57
  match o with
 
58
      None -> ()
 
59
    | Some v ->  Format.fprintf f "%(%)%a%(%)" pre pp_elt v suf
 
60
 
 
61
let pp_cond ?(pr_false=format_of_string "") cond f pr_true =
 
62
  Format.fprintf f "%(%)" (if cond then pr_true else pr_false)
 
63
 
 
64
let escape_underscores = Str.global_replace (Str.regexp_string "_") "__"
 
65
 
 
66
 
 
67
 
 
68
(*
 
69
Local Variables:
 
70
compile-command: "make -C ../.. -j"
 
71
End:
 
72
*)