* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
+open Printf
+
open Utils
let rec evaluate_targets env exprs =
| [] -> env
| d :: _ -> Ast.Env.add "^" d env in
let code = Ast.to_shell_script env loc code in
- Printf.printf "running : %s\n" code
+ printf "%s\n%!" (trim code);
+ let r = Sys.command code in
+ if r <> 0 then (
+ eprintf "*** goal ā%sā failed with exit code %d\n" name r;
+ exit 1
+ )
);
(* Check all targets were updated (else it's an error). *)
-1 (* not found *)
in
loop 0
+
+let isspace c =
+ c = ' '
+ (* || c = '\f' *) || c = '\n' || c = '\r' || c = '\t' (* || c = '\v' *)
+
+let triml ?(test = isspace) str =
+ let i = ref 0 in
+ let n = ref (String.length str) in
+ while !n > 0 && test str.[!i]; do
+ decr n;
+ incr i
+ done;
+ if !i = 0 then str
+ else String.sub str !i !n
+
+let trimr ?(test = isspace) str =
+ let n = ref (String.length str) in
+ while !n > 0 && test str.[!n-1]; do
+ decr n
+ done;
+ if !n = String.length str then str
+ else String.sub str 0 !n
+
+let trim ?(test = isspace) str =
+ trimr ~test (triml ~test str)
val string_find : string -> string -> int
(** [string_find str sub] finds the index of [sub] in [str]. If
not found, returns -1. *)
+
+val isspace : char -> bool
+val triml : ?test:(char -> bool) -> string -> string
+val trimr : ?test:(char -> bool) -> string -> string
+val trim : ?test:(char -> bool) -> string -> string
+(** Trim strings at left, right or both. *)