Module Toolkit


module Toolkit: sig .. end
Some small functions and shortcuts which I find convenient.
Author(s): Gamall Wednesday Ida


Functions about lists, strings and files

val aggreg_args : string list -> string
Concatenate a list of arguments, putting spaces as separators
val trim : string -> string
Trim white spaces (not written by me)
val map_tr : ('a -> 'b) -> 'a list -> 'b list
Tail recursive version of map
val no_newline : string -> string
Get rid of trailing \n
val lines_of_file : ?f:(string -> string) -> string -> string list
Input a file into a list, tail-recursively (not by me)

Some shortcuts


Printing

val pl : string -> unit
Print line to stdout
val pe : string -> unit
Print line to stderr
val ps : string -> unit
Print string to stdout
val pf : ('a, Pervasives.out_channel, unit) Pervasives.format -> 'a
= Printf.printf: formated printing to stdout
val spf : ('a, unit, string) Pervasives.format -> 'a
= Printf.sprintf: formated printing to string
val epf : ('a, Pervasives.out_channel, unit) Pervasives.format -> 'a
= Printf.eprintf: formated printing to stderr
val fpf : Pervasives.out_channel ->
('a, Pervasives.out_channel, unit) Pervasives.format -> 'a
= Printf.fprintf: formated printing to output channel
val va : ('a, unit, string) Pervasives.format -> 'a
= spf: formated printing to stdout

Lists, strings and such

val tl : 'a list -> 'a list
Get the tail of list
val hd : 'a list -> 'a
Get the head of a list
val soi : int -> string
= string_of_int
val ios : string -> int
= int_of_string
val iosd : string -> string -> int
ios with debug instructions
val iosz : string -> int
ios with zero in case of failure
val strlen : string -> int
Get length of a string
val listlen : 'a list -> int
Get length of a list
val arrlen : 'a array -> int
Get length of an array
val break_string : string -> unit
DEBUG: display codes for each char in a string

standard channels

val stdinc : Pervasives.in_channel
stdin as input channel
val stdoutc : Pervasives.out_channel
stdout as output channel
val stdinf : Unix.file_descr
stdin as a file descriptor
val stdoutf : Unix.file_descr
stdout as a file descriptor

Unix tricks and sockets

val hue : ('a -> 'b) -> 'a -> 'b
= Unix.handle_unix_error
val open_out_append : string -> Pervasives.out_channel
Open for writing at end of file
val getport : string -> int
Get a valid port number (that is, between 0 and 65535) from a string, or fail
val pidd : string -> unit
DEBUG: quickly display what processus I'm in
val cpipe : ?nonblock:bool -> unit -> Pervasives.in_channel * Pervasives.out_channel
Setup a pipe with channels instead of file_descr. Optionally specify if reading is non-blocking. Blocking by default.
val pdfork : ?nb:bool ->
(Pervasives.in_channel -> Pervasives.out_channel -> unit) ->
Pervasives.in_channel * Pervasives.out_channel
Piped double fork, leaving no zombie process behind.
Returns couple of channels (channel reading from the son, channel writing to the son)
nb : is reading non-blocking ?
f : function the son will be executing. It takes two arguments: the channels to reading from the son and writing to the son, respectively.
val peek_line : Pervasives.in_channel -> string option
Do an input_line for non-blocking channels. None is returned if nothing is there.
val string_of_sockaddr : Unix.sockaddr -> string
Display a human-legible internet address in IP:port format
val repeat_pattern : string -> int -> string
Build a string by repeating the same pattern n times. Useful for drawing terminal lines etc
val separator_double_line : string
standard separator for terminal output: double
val separator_line : string
standard separator for terminal output: single
val separator_solid_line : string
standard separator for terminal output: underscore

Command-line

val av : string array
Array of command-line arguments
val ac : int
Number of command-line arguments
val al : string list
List of command-line arguments
val bad_args : unit -> unit
Incorrect command-line arguments routine: prints all arguments, insults user, and fails.