inspect: Add detection of Pardus.
[libguestfs.git] / generator / generator_utils.mli
1 (* libguestfs
2  * Copyright (C) 2009-2010 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *)
18
19 (* Please read generator/README first. *)
20
21 (** Useful utility functions. *)
22
23 val uuidgen : unit -> string
24 (** Generate a random UUID (used in tests). *)
25
26 type rstructs_used_t = RStructOnly | RStructListOnly | RStructAndList
27 (** Return type of {!rstructs_used_by}. *)
28
29 val rstructs_used_by : Generator_types.action list -> (string * rstructs_used_t) list
30 (** Returns a list of RStruct/RStructList structs that are returned
31     by any function. *)
32
33 val failwithf : ('a, unit, string, 'b) format4 -> 'a
34 (** Like [failwith] but supports printf-like arguments. *)
35
36 val unique : unit -> int
37 (** Returns a unique number each time called. *)
38
39 val replace_char : string -> char -> char -> string
40 (** Replace character in string. *)
41
42 val isspace : char -> bool
43 (** Return true if char is a whitespace character. *)
44
45 val triml : ?test:(char -> bool) -> string -> string
46 (** Trim left. *)
47
48 val trimr : ?test:(char -> bool) -> string -> string
49 (** Trim right. *)
50
51 val trim : ?test:(char -> bool) -> string -> string
52 (** Trim left and right. *)
53
54 val find : string -> string -> int
55 (** [find str sub] searches for [sub] in [str], returning the index
56     or -1 if not found. *)
57
58 val replace_str : string -> string -> string -> string
59 (** [replace_str str s1 s2] replaces [s1] with [s2] throughout [str]. *)
60
61 val string_split : string -> string -> string list
62 (** [string_split sep str] splits [str] at [sep]. *)
63
64 val files_equal : string -> string -> bool
65 (** [files_equal filename1 filename2] returns true if the files contain
66     the same content. *)
67
68 val filter_map : ('a -> 'b option) -> 'a list -> 'b list
69
70 val find_map : ('a -> 'b option) -> 'a list -> 'b
71
72 val iteri : (int -> 'a -> unit) -> 'a list -> unit
73
74 val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
75
76 val count_chars : char -> string -> int
77 (** Count number of times the character occurs in string. *)
78
79 val explode : string -> char list
80 (** Explode a string into a list of characters. *)
81
82 val map_chars : (char -> 'a) -> string -> 'a list
83 (** Explode string, then map function over the characters. *)
84
85 val name_of_argt : Generator_types.argt -> string
86 (** Extract argument name. *)
87
88 val seq_of_test : Generator_types.test -> Generator_types.seq
89 (** Extract test sequence from a test. *)
90
91 val c_quote : string -> string
92 (** Perform quoting on a string so it is safe to include in a C source file. *)
93
94 val pod2text : width:int -> string -> string -> string list
95 (** [pod2text ~width name longdesc] converts the POD in [longdesc] to
96     plain ASCII lines of text.  This is the slowest part of
97     autogeneration, so the results are memoized into a temporary
98     file. *)
99
100 val action_compare : Generator_types.action -> Generator_types.action -> int
101 (** Compare the names of two actions, for sorting. *)