File: utils.mli

package info (click to toggle)
libnbd 1.22.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,636 kB
  • sloc: ansic: 53,855; ml: 12,311; sh: 8,499; python: 4,595; makefile: 2,902; perl: 165; cpp: 24
file content (81 lines) | stat: -rw-r--r-- 2,860 bytes parent folder | download | duplicates (2)
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
(* hey emacs, this is OCaml code: -*- tuareg -*- *)
(* nbd client library in userspace: utilities
 * Copyright Red Hat
 *
 * This library 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 2 of the License, or (at your option) any later version.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *)

(* Helper functions. *)

type comment_style =
  | CStyle
  | CPlusPlusStyle
  | HashStyle
  | OCamlStyle
  | HaskellStyle
  | PODCommentStyle

type chan = NoOutput | OutChannel of out_channel | Buffer of Buffer.t

type location = string * int  (** source location: file, line number *)

val failwithf : ('a, unit, string, 'b) format4 -> 'a

val filter_map : ('a -> 'b option) -> 'a list -> 'b list
val group_by : ('a * 'b) list -> ('a * 'b list) list
val uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
val is_prefix : string -> string -> bool
val find : string -> string -> int
val split : string -> string -> string * string
val nsplit : string -> string -> string list
val char_mem : char -> string -> bool
val span : string -> string -> int
val cspan : string -> string -> int
val string_starts_with : prefix:string -> string -> bool
val array_find_map : ('a -> 'b option) -> 'a array -> 'b option
val option_map : ('a -> 'b) -> 'a option -> 'b option
val quote : string -> string
val spaces : int -> string
val macro_name : string -> string
val files_equal : string -> string -> bool

val generate_header :
  ?extra_sources:string list -> ?copyright:string -> comment_style -> unit

(** Type of code formatter. *)
type formatter =
  | Gofmt
  | Rustfmt

(** Redirect stdout to a file. Possibly formatting the code. *)
val output_to : ?formatter:formatter option -> string -> (unit -> 'a) -> unit

val pr : ('a, unit, string, unit) format4 -> 'a
val pr_wrap : ?maxcol:int -> char -> (unit -> 'a) -> unit
val pr_wrap_cstr : ?maxcol:int -> (unit -> 'a) -> unit
val pr_wrap_c_comment : ?maxcol:int -> (unit -> 'a) -> unit
val output_lineno : unit -> int
val output_column : unit -> int

val noloc : location
val string_of_location : location -> string
val line_directive_of_location : location -> string

type cache_key = string
type cache_value = string list
val pod2text : cache_key -> cache_value

(* Convert C function name to upper-camel-case name. *)
val camel_case : string -> string