for review: maybe_int option
Andrew Bromage
bromage at cs.mu.oz.au
Fri Dec 19 13:33:24 AEDT 1997
Fergus, could you please review this (very small) change? Thanks.
Estimated hours taken: 1.0
library/getopt.m:
Added a new kind of option: maybe_int. Also added
getopt__lookup_maybe_int_option/3 to look up options of
type maybe_int.
NEWS:
Note the new option type.
Index: NEWS
===================================================================
RCS file: /home/staff/zs/imp/mercury/NEWS,v
retrieving revision 1.90
diff -u -r1.90 NEWS
--- NEWS 1997/12/09 04:09:27 1.90
+++ NEWS 1997/12/19 02:27:49
@@ -227,6 +227,11 @@
`MGNUCFLAGS=-DML_OMIT_ARRAY_BOUNDS_CHECKS' in your Mmake file).
[XXX we also need to fix problems with intermodule inlining heuristics.]
+* We've added a new type of option data: maybe_int(maybe(int)).
+ There is also a new corresponding lookup predicate,
+ getopt__lookup_maybe_string_option/3. See library/getopt.m for
+ details.
+
* The support for debugging using Prolog now includes support for
detailed control over how terms are printed out during debugging.
Index: library/getopt.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/getopt.m,v
retrieving revision 1.17
diff -u -r1.17 getopt.m
--- getopt.m 1997/11/29 14:47:33 1.17
+++ getopt.m 1997/12/04 05:09:23
@@ -114,6 +114,7 @@
---> bool(bool)
; int(int)
; string(string)
+ ; maybe_int(maybe(int))
; maybe_string(maybe(string))
; accumulating(list(string))
; special
@@ -147,6 +148,10 @@
:- pred getopt__lookup_string_option(option_table(Option), Option, string).
:- mode getopt__lookup_string_option(in, in, out) is det.
+:- pred getopt__lookup_maybe_int_option(option_table(Option), Option,
+ maybe(int)).
+:- mode getopt__lookup_maybe_int_option(in, in, out) is det.
+
:- pred getopt__lookup_maybe_string_option(option_table(Option), Option,
maybe(string)).
:- mode getopt__lookup_maybe_string_option(in, in, out) is det.
@@ -417,6 +422,19 @@
;
error("string argument expected in getopt__process_option")
).
+getopt__process_option(maybe_int(_), Option, Flag, MaybeArg, _OptionOps,
+ OptionTable0, Result) :-
+ ( MaybeArg = yes(Arg) ->
+ ( string__to_int(Arg, IntArg) ->
+ map__set(OptionTable0, Flag, maybe_int(yes(IntArg)),
+ OptionTable),
+ Result = ok(OptionTable)
+ ;
+ getopt__numeric_argument(Option, Arg, Result)
+ )
+ ;
+ error("integer argument expected in getopt__process_option")
+ ).
getopt__process_option(maybe_string(_), _Option, Flag, MaybeArg, _OptionOps,
OptionTable0, Result) :-
( MaybeArg = yes(Arg) ->
@@ -482,6 +500,10 @@
( OptionData = bool(_) ->
map__set(OptionTable0, Flag, bool(no), OptionTable),
Result = ok(OptionTable)
+ ; OptionData = maybe_int(_) ->
+ map__set(OptionTable0, Flag, maybe_int(no),
+ OptionTable),
+ Result = ok(OptionTable)
; OptionData = maybe_string(_) ->
map__set(OptionTable0, Flag, maybe_string(no),
OptionTable),
@@ -532,6 +554,7 @@
getopt__need_arg(bool(_), no).
getopt__need_arg(int(_), yes).
getopt__need_arg(string(_), yes).
+getopt__need_arg(maybe_int(_), yes).
getopt__need_arg(maybe_string(_), yes).
getopt__need_arg(accumulating(_), yes).
getopt__need_arg(special, no).
@@ -596,6 +619,13 @@
Val = Val0
;
error("Expected string option and didn't get one.")
+ ).
+
+getopt__lookup_maybe_int_option(OptionTable, Opt, Val) :-
+ ( map__lookup(OptionTable, Opt, maybe_int(Val0)) ->
+ Val = Val0
+ ;
+ error("Expected maybe_int option and didn't get one.")
).
getopt__lookup_maybe_string_option(OptionTable, Opt, Val) :-
More information about the developers
mailing list