1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-08-09 06:15:01 -07:00
|
|
|
(* Module [Printf]: formatting printing functions *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
val fprintf: out_channel -> ('a, out_channel, unit) format -> 'a
|
|
|
|
(* [fprintf outchan format arg1 ... argN] formats the arguments
|
|
|
|
[arg1] to [argN] according to the format string [format],
|
|
|
|
and outputs the resulting string on the channel [outchan].
|
1995-08-08 06:37:34 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
The format is a character string which contains two types of
|
|
|
|
objects: plain characters, which are simply copied to the
|
|
|
|
output channel, and conversion specifications, each of which
|
|
|
|
causes conversion and printing of one argument.
|
1995-08-08 06:37:34 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
Conversion specifications consist in the [%] character, followed
|
|
|
|
by optional flags and field widths, followed by one conversion
|
|
|
|
character. The conversion characters and their meanings are:
|
|
|
|
- [d] or [i]: convert an integer argument to signed decimal
|
|
|
|
- [u]: convert an integer argument to unsigned decimal
|
|
|
|
- [x]: convert an integer argument to unsigned hexadecimal,
|
|
|
|
using lowercase letters.
|
|
|
|
- [X]: convert an integer argument to unsigned hexadecimal,
|
|
|
|
using uppercase letters.
|
|
|
|
- [s]: insert a string argument
|
|
|
|
- [c]: insert a character argument
|
|
|
|
- [f]: convert a floating-point argument to decimal notation,
|
|
|
|
in the style [dddd.ddd]
|
|
|
|
- [e] or [E]: convert a floating-point argument to decimal notation,
|
|
|
|
in the style [d.ddd e+-dd] (mantissa and exponent)
|
|
|
|
- [g] or [G]: convert a floating-point argument to decimal notation,
|
|
|
|
in style [f] or [e], [E] (whichever is more compact)
|
|
|
|
- [b]: convert a boolean argument to the string [true] or [false]
|
|
|
|
- [a]: user-defined printer. Takes two arguments and apply the first
|
|
|
|
one to [outchan] (the current output channel) and to the second
|
|
|
|
argument. The first argument must therefore have type
|
|
|
|
[out_channel -> 'b -> unit] and the second ['b].
|
|
|
|
The output produced by the function is therefore inserted
|
|
|
|
in the output of [fprintf] at the current point.
|
|
|
|
- [t]: same as [%a], but takes only one argument (with type
|
|
|
|
[out_channel -> unit]) and apply it to [outchan].
|
1998-04-27 02:55:50 -07:00
|
|
|
- [%]: take no argument and output one [%] character.
|
1995-05-04 03:15:53 -07:00
|
|
|
- Refer to the C library [printf] function for the meaning of
|
1995-08-08 06:37:34 -07:00
|
|
|
flags and field width specifiers.
|
|
|
|
|
|
|
|
If too few arguments are provided, printing stops just
|
|
|
|
before converting the first missing argument. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
val printf: ('a, out_channel, unit) format -> 'a
|
1996-09-10 06:58:05 -07:00
|
|
|
(* Same as [fprintf], but output on [stdout]. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
val eprintf: ('a, out_channel, unit) format -> 'a
|
1996-09-10 06:58:05 -07:00
|
|
|
(* Same as [fprintf], but output on [stderr]. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1995-05-05 03:05:18 -07:00
|
|
|
val sprintf: ('a, unit, string) format -> 'a
|
1998-04-27 02:55:50 -07:00
|
|
|
(* Same as [printf], but instead of printing on an output channel,
|
|
|
|
return a string containing the result of formatting
|
|
|
|
the arguments. *)
|