Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /smlnj-lib/trunk/Util/getopt-sig.sml
ViewVC logotype

Annotation of /smlnj-lib/trunk/Util/getopt-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2144 - (view) (download)

1 : monnier 409 (* getopt-sig.sml
2 :     *
3 :     * COPYRIGHT (c) 1998 Bell Labs, Lucent Technologies.
4 :     *
5 :     * A SML port of GNU's getopt library.
6 :     *
7 :     * This port is derived from Sven Panne's
8 :     * <Sven.Panne@informatik.uni-muenchen.de>
9 :     * implementation of the getopt library in Haskell <http://www.haskell.org>
10 :     *
11 :     * The following comments are lifted from Sven's code:
12 :     *
13 :     * Two rather obscure features are missing: The Bash 2.0 non-option hack (if
14 :     * you don't already know it, you probably don't want to hear about it...)
15 :     * and the recognition of long options with a single dash (e.g. '-help' is
16 :     * recognised as '--help', as long as there is no short option 'h').
17 :     *
18 :     * Other differences between GNU's getopt and this implementation:
19 :     * * To enforce a coherent description of options and arguments, there are
20 :     * explanation fields in the option/argument descriptor.
21 :     * * Error messages are now more informative, but no longer POSIX
22 :     * compliant... :-(
23 :     *
24 :     *
25 :     *
26 : jhr 688 * A difference with Sven's port: errors now invoke an error callback, rather
27 : monnier 409 * than returning error strings while continuing processing options.
28 :     * The full generality of the latter does not seem justified.
29 :     *)
30 :    
31 :    
32 :     signature GET_OPT =
33 :     sig
34 :    
35 :     datatype 'a arg_order
36 :     = RequireOrder
37 :     | Permute
38 :     | ReturnInOrder of string -> 'a
39 :     (* What to do with options following non-options:
40 :     * RequireOrder: no option processing after first non-option
41 :     * Permute: freely intersperse options and non-options
42 :     * ReturnInOrder: wrap non-options into options
43 :     *)
44 :    
45 :     datatype 'a arg_descr
46 : monnier 469 = NoArg of unit -> 'a
47 : monnier 409 | ReqArg of (string -> 'a) * string
48 :     | OptArg of (string option -> 'a) * string
49 :     (* Description of an argument option:
50 :     * NoArg: no argument required
51 : jhr 1772 * ReqArg: option requires an argument; the string is the argument name
52 :     * OptArg: optional argument; the string is the argument name
53 : monnier 409 *)
54 :    
55 :     type 'a opt_descr = {
56 :     short : string,
57 :     long : string list,
58 :     desc : 'a arg_descr,
59 :     help : string
60 :     }
61 :     (* Description of a single option *)
62 : monnier 469
63 :     val usageInfo : {
64 :     header : string,
65 :     options : 'a opt_descr list
66 :     } -> string
67 : monnier 409 (* takes a header string and a list of option descriptions and
68 : jhr 1772 * returns a string explaining the usage information. A newline will
69 :     * be added following the header, so it should not be newline terminated.
70 : monnier 409 *)
71 : monnier 469
72 :     val getOpt : {
73 :     argOrder : 'a arg_order,
74 :     options : 'a opt_descr list,
75 :     errFn : string -> unit
76 :     } -> string list -> ('a list * string list)
77 : monnier 409 (* takes as argument an arg_order to specify the non-options
78 : jhr 688 * handling, a list of option descriptions, an error callback,
79 :     * and a command line containing the options and arguments,
80 :     * and returns a list of (options, non-options)
81 : monnier 409 *)
82 : monnier 469
83 : monnier 409 end
84 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0