-and set_variable name value typ =
- let value = match typ with
- | `Bool ->
- (match value with
- | "true"|"t"|"yes"|"y"|"on"|"1" -> `bool_t true
- | "false"|"f"|"no"|"n"|"off"|"0" -> `bool_t false
- | _ ->
- eprintf "whenjobs: variable does not have a boolean value\n";
- exit 1
- )
- | `String -> `string_t value
- | `Int ->
- (try ignore (big_int_of_string value)
- with Failure _ ->
- eprintf "whenjobs: variable is not an integer\n";
- exit 1
- );
- `int_t value (* the string is what we pass over the wire *)
- | `Float ->
- (try `float_t (float_of_string value)
- with Failure _ ->
- eprintf "whenjobs: variable is not a floating point number\n";
- exit 1
- )
- | `Unit ->
- if value <> "" then (
- eprintf "whenjobs: unit variables must be empty strings\n";
- exit 1
- );
- `unit_t in
+and set_variables argtypes =
+ let vars = List.map (
+ fun (def, typ) ->
+ (* 'def' should have the form "name=value". The value part may
+ * be missing, but the equals sign is required.
+ *)
+ let i =
+ try String.index def '='
+ with Not_found ->
+ eprintf "whenjobs: set: missing = sign in variable definition\n";
+ suggest_help ();
+ exit 1 in
+ let name = String.sub def 0 i in
+ let value = String.sub def (i+1) (String.length def - (i+1)) in
+ let value = value_of_string value typ in
+ { Whenproto_aux.sv_name = name; sv_value = value }
+ ) argtypes in
+ let vars = Array.of_list vars in