2 * Copyright (C) 2009-2011 Red Hat Inc.
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.
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.
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
19 (* Please read generator/README first. *)
21 (** Useful utility functions. *)
23 val errcode_of_ret : Generator_types.ret -> Generator_types.errcode
24 (** Map [ret] type to the error indication that the action returns,
25 eg. [errcode_of_ret RErr] => [`ErrorIsMinusOne] (meaning that
26 these actions return [-1]).
28 Note that [RConstOptString] cannot return an error indication, and
29 this returns [`CannotReturnError]. Callers must deal with it. *)
31 val string_of_errcode : [`ErrorIsMinusOne|`ErrorIsNULL] -> string
32 (** Return errcode as a string. Untyped for [`CannotReturnError]. *)
34 val uuidgen : unit -> string
35 (** Generate a random UUID (used in tests). *)
37 type rstructs_used_t = RStructOnly | RStructListOnly | RStructAndList
38 (** Return type of {!rstructs_used_by}. *)
40 val rstructs_used_by : Generator_types.action list -> (string * rstructs_used_t) list
41 (** Returns a list of RStruct/RStructList structs that are returned
44 val failwithf : ('a, unit, string, 'b) format4 -> 'a
45 (** Like [failwith] but supports printf-like arguments. *)
47 val unique : unit -> int
48 (** Returns a unique number each time called. *)
50 val replace_char : string -> char -> char -> string
51 (** Replace character in string. *)
53 val isspace : char -> bool
54 (** Return true if char is a whitespace character. *)
56 val triml : ?test:(char -> bool) -> string -> string
59 val trimr : ?test:(char -> bool) -> string -> string
62 val trim : ?test:(char -> bool) -> string -> string
63 (** Trim left and right. *)
65 val find : string -> string -> int
66 (** [find str sub] searches for [sub] in [str], returning the index
67 or -1 if not found. *)
69 val replace_str : string -> string -> string -> string
70 (** [replace_str str s1 s2] replaces [s1] with [s2] throughout [str]. *)
72 val string_split : string -> string -> string list
73 (** [string_split sep str] splits [str] at [sep]. *)
75 val files_equal : string -> string -> bool
76 (** [files_equal filename1 filename2] returns true if the files contain
79 val filter_map : ('a -> 'b option) -> 'a list -> 'b list
81 val find_map : ('a -> 'b option) -> 'a list -> 'b
83 val iteri : (int -> 'a -> unit) -> 'a list -> unit
85 val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
87 val count_chars : char -> string -> int
88 (** Count number of times the character occurs in string. *)
90 val explode : string -> char list
91 (** Explode a string into a list of characters. *)
93 val map_chars : (char -> 'a) -> string -> 'a list
94 (** Explode string, then map function over the characters. *)
96 val name_of_argt : Generator_types.argt -> string
97 (** Extract argument name. *)
99 val name_of_optargt : Generator_types.optargt -> string
100 (** Extract optional argument name. *)
102 val seq_of_test : Generator_types.test -> Generator_types.seq
103 (** Extract test sequence from a test. *)
105 val c_quote : string -> string
106 (** Perform quoting on a string so it is safe to include in a C source file. *)
108 val pod2text : ?width:int -> ?trim:bool -> ?discard:bool -> string -> string -> string list
109 (** [pod2text ?width ?trim ?discard name longdesc] converts the POD in
110 [longdesc] to plain ASCII lines of text.
112 [width] is the width in characters. If not specified, then
113 use the pod2text default.
115 [trim] means trim the left margin (useful when including the
116 output inside comments, as in Java generator).
118 [discard] means discard the first heading.
120 This is the slowest part of autogeneration, so the results are
121 memoized into a temporary file. *)
123 val action_compare : Generator_types.action -> Generator_types.action -> int
124 (** Compare the names of two actions, for sorting. *)
126 val chars : char -> int -> string
127 (** [chars c n] creates a string containing character c repeated n times. *)
129 val spaces : int -> string
130 (** [spaces n] creates a string of n spaces. *)
132 val args_of_optargs : Generator_types.optargs -> Generator_types.args
133 (** Convert a list of optargs into an equivalent list of args *)