summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kahn_stdio.ml20
-rw-r--r--src/manager.ml2
-rw-r--r--src/poolclient.ml2
-rw-r--r--src/util.ml2
4 files changed, 18 insertions, 8 deletions
diff --git a/src/kahn_stdio.ml b/src/kahn_stdio.ml
index 234c1d4..1bed0a1 100644
--- a/src/kahn_stdio.ml
+++ b/src/kahn_stdio.ml
@@ -79,6 +79,7 @@ module ProtoKahn: S = struct
let origin = ref false
let dbg_out = ref false
+ let color = ref 0
let dbg x = if !dbg_out then Format.eprintf "(cli) %s@." x
let parse_args () =
@@ -86,12 +87,21 @@ module ProtoKahn: S = struct
let options = [
"-org", Arg.Set origin, "Launch root process";
"-dbg", Arg.Set dbg_out, "Show debug output";
+ "-col", Arg.Set_int color, "Color for output";
] in
Arg.parse options (fun _ -> assert false) usage
let run proc =
- Random.self_init();
parse_args();
+
+ Random.self_init();
+ let color =
+ if !color = 0
+ then Random.int 6 + 31
+ else 30 + !color in
+ let cseq = Format.sprintf "\x1B[%dm" color in
+ let ncseq = "\x1B[0m" in
+
(* Initialize protocol *)
send Hello;
if read () <> Hello then raise (ProtocolError "Server did not say Hello correctly.");
@@ -107,15 +117,15 @@ module ProtoKahn: S = struct
| GiveTask(td, _) ->
dbg "Got task!";
let t : task = Marshal.from_string td 0 in
- Format.eprintf "[@?";
+ Format.eprintf "%s[%s@?" cseq ncseq;
t();
- Format.eprintf "]@?";
+ Format.eprintf "%s]%s@?" cseq ncseq;
| GiveMsgTask(msg, td) ->
dbg "Got msg task!";
let t : msg_task = Marshal.from_string td 0 in
- Format.eprintf "{@?";
+ Format.eprintf "%s{%s@?" cseq ncseq;
t msg;
- Format.eprintf "}@?";
+ Format.eprintf "%s}%s@?" cseq ncseq;
| FinalResult(x) ->
dbg "Got result!";
result := Some (Marshal.from_string x 0)
diff --git a/src/manager.ml b/src/manager.ml
index 2e856fd..1e6a0df 100644
--- a/src/manager.ml
+++ b/src/manager.ml
@@ -265,7 +265,7 @@ let () =
dup2 m2p_p stdin;
dup2 p2m_p stdout;
let args = Array.of_list
- ([!program] @
+ ([!program; "-col"; string_of_int (i+1)] @
(if i = 0 then ["-org"] else []) @
(if !dbg_out then ["-dbg"] else [])) in
execv !program args
diff --git a/src/poolclient.ml b/src/poolclient.ml
index b6d5a89..5479c8c 100644
--- a/src/poolclient.ml
+++ b/src/poolclient.ml
@@ -15,7 +15,7 @@ let fullfill_request task (addr, port) n =
connect sock (make_addr addr port);
dup2 sock stdin;
dup2 sock stdout;
- execv task [|task|]
+ execv task [|task; "-col";string_of_int (i+1)|]
with
| _ -> exit 0
end
diff --git a/src/util.ml b/src/util.ml
index b37ae4f..ae1f049 100644
--- a/src/util.ml
+++ b/src/util.ml
@@ -3,7 +3,7 @@ open Unix
let (@@) a b = a b
type id = int * int
-let new_id () : id = (Random.int 100000, Random.int 100000)
+let new_id () : id = (Random.int 10000000, Random.int 10000000)
let id_str (a, b) = Format.sprintf "%d.%d" a b
(* make_addr : string -> int -> sockaddr *)