[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[letaris@mac.com: [Caml-list] ANNOUNCE: cmigrep]



Cmigrep looks interesting to me. Should we integrate it in ocaml-tools ?

-Ralf.

----- Forwarded message from Eric Stokes <letaris@mac.com> -----

To: Caml List <caml-list@inria.fr>
From: Eric Stokes <letaris@mac.com>
Date: Sat, 27 Jan 2007 18:46:09 -0500
Subject: [Caml-list] ANNOUNCE: cmigrep

I am happy to announce the immediate availability of cmigrep, a small  
utility to mine cmi files for interesting bits of data. cmigrep is  
available in godi, or at http://homepage.mac.com/letaris

A short description of features,

cmigrep: <args> <module>

cmigrep has two modes, the first and most common is that of searching
for various types of objects inside a module. Objects that you can
search for include

switch         purpose
-t             (regexp) print types with matching names
-r             (regexp) print record field labels with matching names
-c             (regexp) print constructors with matching names
-e             (regexp) print exceptions with matching constructors
-v             (regexp) print values with matching names
-o             (regexp) print all classes with matching names
-a             (regexp) print all names which match the given expression

These are all very useful for finding specific things inside a given
module. Here are a few examples,

find some constructors in the unix module

itsg106:~ eric$ cmigrep -c SO_ Unix
SO_DEBUG (* socket_bool_option *)
SO_BROADCAST (* socket_bool_option *)
SO_REUSEADDR (* socket_bool_option *)
SO_KEEPALIVE (* socket_bool_option *)
SO_DONTROUTE (* socket_bool_option *)
SO_OOBINLINE (* socket_bool_option *)
SO_ACCEPTCONN (* socket_bool_option *)
SO_SNDBUF (* socket_int_option *)
SO_RCVBUF (* socket_int_option *)
SO_ERROR (* socket_int_option *)
SO_TYPE (* socket_int_option *)
SO_RCVLOWAT (* socket_int_option *)
SO_SNDLOWAT (* socket_int_option *)
SO_LINGER (* socket_optint_option *)
SO_RCVTIMEO (* socket_float_option *)
SO_SNDTIMEO (* socket_float_option *)

full types get printed in the case that the constructors have
arguments. Notice that adding to the include path is modeled after the
compiler. Findlib is also supported.

itsg106:~ eric$ cmigrep -c "^Tsig_.*" -I /opt/godi/lib/ocaml/compiler- 
lib Types
Tsig_value of Ident.t * value_description (* signature_item *)
Tsig_type of Ident.t * type_declaration * rec_status (*  
signature_item *)
Tsig_exception of Ident.t * exception_declaration (* signature_item *)
Tsig_module of Ident.t * module_type * rec_status (* signature_item *)
Tsig_modtype of Ident.t * modtype_declaration (* signature_item *)
Tsig_class of Ident.t * class_declaration * rec_status (*  
signature_item *)
Tsig_cltype of Ident.t * cltype_declaration * rec_status (*  
signature_item *)

record field labels

itsg106:~ eric$ cmigrep -r "^st_" Unix
st_dev: int (* stats *)
st_ino: int (* stats *)
st_kind: file_kind (* stats *)
st_perm: file_perm (* stats *)
st_nlink: int (* stats *)
st_uid: int (* stats *)
st_gid: int (* stats *)
st_rdev: int (* stats *)
st_size: int (* stats *)
st_atime: float (* stats *)
st_mtime: float (* stats *)
st_ctime: float (* stats *)

findlib support, matching value names

itsg106:~ eric$ cmigrep -package pcre -v for Pcre
val foreach_line : ?ic:in_channel -> (string -> unit) -> unit
val foreach_file : string list -> (string -> in_channel -> unit) -> unit

nested modules

itsg106:~ eric$ cmigrep -v ".*" Unix.LargeFile
val lseek : file_descr -> int64 -> seek_command -> int64
val truncate : string -> int64 -> unit
val ftruncate : file_descr -> int64 -> unit
val stat : string -> stats
val lstat : string -> stats
val fstat : file_descr -> stats

types

itsg106:~ eric$ cmigrep -t ".*" Unix.LargeFile
type stats = {
  st_dev : int;
  st_ino : int;
  st_kind : file_kind;
  st_perm : file_perm;
  st_nlink : int;
  st_uid : int;
  st_gid : int;
  st_rdev : int;
  st_size : int64;
  st_atime : float;
  st_mtime : float;
  st_ctime : float;
}

everything!

itsg106:~ eric$ cmigrep -a ".*" Unix.LargeFile
val lseek : file_descr -> int64 -> seek_command -> int64
val truncate : string -> int64 -> unit
val ftruncate : file_descr -> int64 -> unit
type stats = {
  st_dev : int;
  st_ino : int;
  st_kind : file_kind;
  st_perm : file_perm;
  st_nlink : int;
  st_uid : int;
  st_gid : int;
  st_rdev : int;
  st_size : int64;
  st_atime : float;
  st_mtime : float;
  st_ctime : float;
}
val stat : string -> stats
val lstat : string -> stats
val fstat : file_descr -> stats

exception declarations

itsg106:~/cmigrep eric$ ./cmigrep -e ".*" Unix
exception Unix_error of error * string * string

The second mode of cmigrep is for searching for modules in it's path,
this lets you do a regular expression match on the full module path,
including sub modules. For example,

itsg106:~/cmigrep eric$ cmigrep -m Net -package netstring
Netaccel
Netaccel_link
Netaddress
Netaux
Netaux.ArrayAux
Netaux.KMP
Netbuffer
Netchannels
Netconversion
Netdate
Netdb
Netencoding
Netencoding.Html
Netencoding.Url
Netencoding.Q
Netencoding.QuotedPrintable
Netencoding.Base64
Nethtml
Nethtml_scanner
Nethttp
Nethttp.Header
Netmappings
Netmappings_iso
Netmappings_jp
Netmappings_min
Netmappings_other
Netmime
Netsendmail
Netstream
Netstring_mt
Netstring_pcre
Netstring_str
Netstring_top
Netulex
Netulex.Ulexing
Netulex.ULB
Neturl

here are all modules starting with Net that contain a sub module
itsg106:~/cmigrep eric$ cmigrep -m "^Net.*\." -package netstring
Netaux.ArrayAux
Netaux.KMP
Netencoding.Html
Netencoding.Url
Netencoding.Q
Netencoding.QuotedPrintable
Netencoding.Base64
Nethttp.Header
Netulex.Ulexing
Netulex.ULB

modules exactly one level deep
itsg106:~/cmigrep eric$ cmigrep -m "^[^.]*\.[^.]*$"
Bigarray.Array3
Bigarray.Array2
Bigarray.Array1
Bigarray.Genarray
Hashtbl.Make
Map.Make
MoreLabels.Set
MoreLabels.Map
MoreLabels.Hashtbl
Pervasives.LargeFile
Random.State
Scanf.Scanning
Set.Make
StdLabels.String
StdLabels.List
StdLabels.Array
Unix.LargeFile
UnixLabels.LargeFile
Weak.Make

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


----- End forwarded message -----

-- 



Reply to: