HongboZhang avatar HongboZhang committed 95005fb

initial

Comments (0)

Files changed (29)

+_build/DSL_util.byte
+open Format
+open Unix  
+open Util
+let (|>) x f =  f x
+let prerr_endlinef fmt = ksprintf prerr_endline  fmt    
+  
+let roles = Hashtbl.create 50
+let col = Str.regexp ":"
+let ws = Str.regexp "[ \t]+"    
+(** make sure dchat is in your search path*)
+
+let dchat = begin
+  let chan = Unix.open_process_in "which dchat" in
+  let ans =input_line chan  in
+  if Sys.file_exists ans then begin 
+    prerr_endlinef "dchat:%s" ans;
+    ans
+  end 
+  else begin
+    prerr_endlinef "dchat not found: exit";
+    exit 1;
+  end 
+end 
+let machine_id = ref 1
+
+let config = begin
+  let conf = open_in "config.in" in
+  let pairs = ref [] in 
+  finally (fun _ -> close_in conf) (fun conf ->
+    try
+      while true do
+        let line = (input_line conf) in
+        let () = prerr_endline line in 
+        let [a;b] = Str.bounded_split col line 2 in
+        pairs := (a,b):: !pairs
+      done
+    with
+      End_of_file -> ()) conf;
+  !pairs
+end
+
+let client_port  =
+  try
+    List.assoc "client_port" config
+  with Not_found -> begin
+    prerr_endline "client_port not found";
+    raise Not_found
+  end
+
+let pennid =
+  try
+    List.assoc "pennid" config
+  with Not_found -> begin
+    prerr_endline "pennid not found";
+    raise Not_found
+  end 
+
+let gen_command i pennid =
+  sprintf "ssh spec%02d ps -U %s | grep dchat | sed 's/\\W*//' | cut -d ' ' \
+    -f 1 | while read ss; do echo \"spec%02d $ss\"; ssh spec%02d kill $ss; \
+    done" i pennid i i
+
+(** kill your dchat programs
+    to save your udp port 
+ *)      
+let reset ?(from=1) ?(until = !machine_id) ()= begin
+  for i = from to until do 
+    gen_command i pennid|> Sys.command |> ignore
+  done ;
+  Hashtbl.clear roles;
+  machine_id := 1;
+end 
+    
+let create_and_redir (name,args,fnormal,ferr) =
+  let (fd_in,fd_out) = pipe() in
+  match fork () with
+  | 0 -> begin 
+      dup2 fd_in stdin;
+      close fd_in;
+      close fd_out;
+      let out_chan = open_out fnormal in
+      let err_chan = open_out ferr in  begin
+        prerr_endlinef "create file %s and %s " fnormal ferr;
+        dup2 (descr_of_out_channel out_chan) stdout;
+        dup2 (descr_of_out_channel err_chan) stderr;
+        execvp name args
+      end 
+  end
+  | pid -> begin
+      close fd_in;
+      (fd_out,pid)
+  end 
+
+(** without buffering *)
+let write_out fd_out str =
+  write fd_out str 0 (String.length str)
+
+let role_exists role =  Hashtbl.mem roles role
+
+
+  
+let kill role =
+  if role_exists role then 
+    let _,pid,machine = Hashtbl.find roles role in begin
+      Unix.kill pid 9 
+    end
+  else
+    prerr_endlinef "role%s not exist" role
+      
+
+    
+let add_client role other  =
+  if role_exists role then
+    prerr_endlinef "role:%s already exists" role
+  else if not (role_exists other) then
+    prerr_endlinef "role:%s not exists" other
+  else
+    
+    let machine = sprintf "spec%02d" !machine_id in
+    let () = incr machine_id in    
+    let _,_,m = Hashtbl.find roles other in 
+    let args = [|"ssh"; machine; dchat; role; m^":"^ client_port|] in 
+    let (fid,pid) = create_and_redir ("ssh",args,role^".log",role^".err.log") in
+    let () = prerr_endlinef "%s" (Array.fold_left (fun x y -> x ^ " " ^ y) "" args) in
+    Hashtbl.add roles role (fid,pid,machine)
+
+let add_server role =
+  if role_exists role then
+    prerr_endlinef "role:%s already exists" role
+  else 
+    let machine = sprintf "spec%02d" !machine_id in
+    let args = [|"ssh"; machine; dchat; role|] in  (* only nick *)
+    let () = incr machine_id in
+    let (fid,pid) = create_and_redir ("ssh",args,role^".log",role^".err.log") in
+    let () = prerr_endlinef "%s" (Array.fold_left (fun x y -> x ^ " " ^ y) "" args) in
+    Hashtbl.add roles role (fid,pid,machine)
+
+
+let send_string role str=
+  if role_exists role then 
+    let fd_out,_,_ = Hashtbl.find roles role in begin
+      let _ = write_out fd_out (str^"\n") in
+      prerr_endlinef "%s:%s\n" role (str^"\n")
+    end
+  else prerr_endlinef "role%s does not exists" role
+
+
+open Camlp4.PreCast
+  
+let parser_of_entry entry  s =
+  try Gram.parse entry (Loc.mk "<string>") (Stream.of_string  s)
+  with
+    Loc.Exc_located(loc, e) -> begin 
+      prerr_endline (Loc.to_string loc);
+      let start_bol,stop_bol,
+        start_off, stop_off =
+        Loc.(start_bol loc,
+             stop_bol loc,
+             start_off loc,
+             stop_off loc
+            ) in
+      let abs_start_off = start_bol + start_off in
+      let abs_stop_off = stop_bol + stop_off in
+      let err_location = String.sub s abs_start_off
+          (abs_stop_off - abs_start_off + 1) in
+      prerr_endline (sprintf "err: ^%s^" err_location);
+      raise e ;
+    end
+        
+
+
+let instruction = Gram.Entry.mk "instruction"
+let instruction_eoi = Gram.Entry.mk "instruction_eoi"
+
+let _ = begin
+  EXTEND Gram GLOBAL: instruction instruction_eoi;
+  instruction_eoi:
+    [ [x = instruction ; `EOI -> x ] ];
+  instruction:
+    [
+     "top"
+       [ x=name ; "via"; y=name  -> begin
+         prerr_endlinef "add_client %s %s" x y;
+         add_client x y;
+       end
+       | x=name ; ":"; s=STRING -> begin
+           prerr_endlinef "%s:\"%s\"" x s ;
+           send_string x  s;
+       end 
+       | x=name ; "crash" -> begin
+           prerr_endlinef "kill %s" x ;
+           kill x;
+       end
+       | x=name ; "create" -> begin
+           prerr_endlinef "create server %s" x ;
+           add_server x;
+       end 
+       | "time" ; `INT(x,_) ->  begin
+           prerr_endlinef "sleep %d" x ;
+           Unix.sleep x;
+       end 
+       | "(" ; names = LIST1 name; ")" ; `INT(n,_);
+         "interval"; `FLOAT(f,_)-> begin
+           let () =
+             prerr_endlinef "(%s) in turn interval %f"
+               (List.fold_left  (fun x y -> x ^ " " ^ y) "" names) f in  
+           let start =  ref 0 in
+           for i = 1 to n do 
+             List.iter (fun role -> begin
+               send_string role (string_of_int !start);
+               Unix.select [] [] [] f |> ignore ;
+               incr start;
+             end
+              ) names
+           done 
+           end 
+       | -> begin
+           prerr_endlinef "empty";
+       end]];
+   name:
+    [ [x=LIDENT -> x
+      |x=UIDENT -> x]];
+  END;
+end
+    
+let parse_instruction = parser_of_entry instruction
+let parse_instruction_eoi = parser_of_entry instruction_eoi
+
+
+let file_lines_of str =
+  let chan = open_in str in
+  let lines = ref [] in
+  (try
+    while true do
+      lines := input_line chan :: !lines
+    done;
+  with
+    End_of_file -> begin 
+      close_in chan;
+    end);
+  List.rev !lines
+    
+(* let lines =  "leader_elect.ml" |> file_lines_of *)
+(* let ()  = reset ~until:3 () *)
+
+let _ =
+  try 
+    while true do 
+      (* List.iter parse_instruction_eoi lines *)
+      let line = read_line () in
+      let ()  =  prerr_endline line in
+      parse_instruction_eoi line
+    done
+  with
+    End_of_file ->
+      prerr_endlinef "finished"
+        
+open Format
+open Unix  
+open Util
+let (|>) x f =  f x
+let prerr_endlinef fmt = ksprintf prerr_endline  fmt    
+  
+let roles = Hashtbl.create 50
+let col = Str.regexp ":"
+let ws = Str.regexp "[ \t]+"    
+(** make sure dchat is in your search path*)
+let dchat = "dchat"
+let machine_id = ref 1
+
+let config = begin
+  let conf = open_in "config.in" in
+  let pairs = ref [] in 
+  finally (fun _ -> close_in conf) (fun conf ->
+    try
+      while true do
+        let line = (input_line conf) in
+        let () = prerr_endline line in 
+        let [a;b] = Str.bounded_split col line 2 in
+        pairs := (a,b):: !pairs
+      done
+    with
+      End_of_file -> ()) conf;
+  !pairs
+end
+
+let client_port  =
+  try
+    List.assoc "client_port" config
+  with Not_found -> begin
+    prerr_endline "client_port not found";
+    raise Not_found
+  end
+
+let pennid =
+  try
+    List.assoc "pennid" config
+  with Not_found -> begin
+    prerr_endline "pennid not found";
+    raise Not_found
+  end 
+
+let gen_command i pennid =
+  sprintf "ssh spec%02d ps -U %s | grep dchat | sed 's/\\W*//' | cut -d ' ' \
+    -f 1 | while read ss; do echo \"spec%02d $ss\"; ssh spec%02d kill $ss; \
+    done" i pennid i i
+
+(** kill your dchat programs
+    to save your udp port 
+ *)      
+let reset ?(from=1) ?(until = !machine_id) ()= begin
+  for i = from to until do 
+    gen_command i pennid|> Sys.command |> ignore
+  done ;
+  Hashtbl.clear roles;
+  machine_id := 1;
+end 
+    
+let create_and_redir (name,args,fnormal,ferr) =
+  let (fd_in,fd_out) = pipe() in
+  match fork () with
+  | 0 -> begin 
+      dup2 fd_in stdin;
+      close fd_in;
+      close fd_out;
+      let out_chan = open_out fnormal in
+      let err_chan = open_out ferr in  begin
+        prerr_endlinef "create file %s and %s " fnormal ferr;
+        dup2 (descr_of_out_channel out_chan) stdout;
+        dup2 (descr_of_out_channel err_chan) stderr;
+        execvp name args
+      end 
+  end
+  | pid -> begin
+      close fd_in;
+      (fd_out,pid)
+  end 
+
+(** without buffering *)
+let write_out fd_out str =
+  write fd_out str 0 (String.length str)
+
+let role_exists role =  Hashtbl.mem roles role
+
+
+  
+let kill role =
+  if role_exists role then 
+    let _,pid,machine = Hashtbl.find roles role in begin
+      Unix.kill pid 9 
+    end
+  else
+    prerr_endlinef "role%s not exist" role
+      
+
+    
+let add_client role other  =
+  if role_exists role then
+    prerr_endlinef "role:%s already exists" role
+  else if not (role_exists other) then
+    prerr_endlinef "role:%s not exists" other
+  else
+    
+    let machine = sprintf "spec%02d" !machine_id in
+    let () = incr machine_id in    
+    let _,_,m = Hashtbl.find roles other in 
+    let args = [|"ssh"; machine; dchat; role; m^":"^ client_port|] in 
+    let (fid,pid) = create_and_redir ("ssh",args,role^".log",role^".err.log") in
+    let () = prerr_endlinef "%s" (Array.fold_left (fun x y -> x ^ " " ^ y) "" args) in
+    Hashtbl.add roles role (fid,pid,machine)
+
+let add_server role =
+  if role_exists role then
+    prerr_endlinef "role:%s already exists" role
+  else 
+    let machine = sprintf "spec%02d" !machine_id in
+    let args = [|"ssh"; machine; dchat; role|] in  (* only nick *)
+    let () = incr machine_id in
+    let (fid,pid) = create_and_redir ("ssh",args,role^".log",role^".err.log") in
+    let () = prerr_endlinef "%s" (Array.fold_left (fun x y -> x ^ " " ^ y) "" args) in
+    Hashtbl.add roles role (fid,pid,machine)
+
+
+let send_string role str=
+  if role_exists role then 
+    let fd_out,_,_ = Hashtbl.find roles role in begin
+      let _ = write_out fd_out (str^"\n") in
+      prerr_endlinef "%s:%s\n" role (str^"\n")
+    end
+  else prerr_endlinef "role%s does not exists" role
+
+
+open Camlp4.PreCast
+  
+let parser_of_entry entry  s =
+  try Gram.parse entry (Loc.mk "<string>") (Stream.of_string  s)
+  with
+    Loc.Exc_located(loc, e) -> begin 
+      prerr_endline (Loc.to_string loc);
+      let start_bol,stop_bol,
+        start_off, stop_off =
+        Loc.(start_bol loc,
+             stop_bol loc,
+             start_off loc,
+             stop_off loc
+            ) in
+      let abs_start_off = start_bol + start_off in
+      let abs_stop_off = stop_bol + stop_off in
+      let err_location = String.sub s abs_start_off
+          (abs_stop_off - abs_start_off + 1) in
+      prerr_endline (sprintf "err: ^%s^" err_location);
+      raise e ;
+    end
+        
+
+
+let instruction = Gram.Entry.mk "instruction"
+let instruction_eoi = Gram.Entry.mk "instruction_eoi"
+
+let _ = begin
+  EXTEND Gram GLOBAL: instruction instruction_eoi;
+  instruction_eoi:
+    [ [x = instruction ; `EOI -> x ] ];
+  instruction:
+    [
+     "top"
+       [ x=name ; "via"; y=name  -> begin
+         prerr_endlinef "add_client %s %s" x y;
+         add_client x y;
+       end
+       | x=name ; ":"; s=STRING -> begin
+           prerr_endlinef "%s:\"%s\"" x s ;
+           send_string x  s;
+       end 
+       | x=name ; "crash" -> begin
+           prerr_endlinef "kill %s" x ;
+           kill x;
+       end
+       | x=name ; "create" -> begin
+           prerr_endlinef "create server %s" x ;
+           add_server x;
+       end 
+       | "time" ; `INT(x,_) ->  begin
+           prerr_endlinef "sleep %d" x ;
+           Unix.sleep x;
+       end 
+       | "(" ; names = LIST1 name; ")" ; `INT(n,_);
+         "interval"; `FLOAT(f,_)-> begin
+           let () =
+             prerr_endlinef "(%s) in turn interval %f"
+               (List.fold_left  (fun x y -> x ^ " " ^ y) "" names) f in  
+           let start =  ref 0 in
+           for i = 1 to n do 
+             List.iter (fun role -> begin
+               send_string role (string_of_int !start);
+               Unix.select [] [] [] f |> ignore ;
+               incr start;
+             end
+              ) names
+           done 
+           end 
+       | -> () ]];
+   name:
+    [ [x=LIDENT -> x
+      |x=UIDENT -> x]];
+  END;
+end
+    
+let parse_instruction = parser_of_entry instruction
+let parse_instruction_eoi = parser_of_entry instruction_eoi
+
+
+let file_lines_of str =
+  let chan = open_in str in
+  let lines = ref [] in
+  (try
+    while true do
+      lines := input_line chan :: !lines
+    done;
+  with
+    End_of_file -> begin 
+      close_in chan;
+    end);
+  List.rev !lines
+    
+(* let lines =  "leader_elect.ml" |> file_lines_of *)
+let ()  = reset ~until:3 ()
+let _ =
+  try 
+    (* List.iter parse_instruction_eoi lines *)
+    let line = read_line () in
+    parse_instruction_eoi line 
+  with
+    End_of_file ->
+      prerr_endlinef "finished"
+      
+      
+(** All supported commands:
+    >bob create  -->    ssh spec03 ~/system/driver.byte bob 
+    >justin via bob  -->  ssh spec07 ~/system/driver.byte spec03:22222
+    >bob crash
+    >justin crash
+    bob: hehe
+    justin: hehe 
+ *)
+(*      
+        let by_line line client_port =
+        if String.length line = 0 then
+        ()
+        else if line.[0] = '>' then 
+        match Str.bounded_split ws (String.sub line 1 (String.length line - 1) ) 3 with
+        | ["time"; tm] ->
+        let t = int_of_string tm in
+        sleep t
+        
+        | [role;"create"] ->  add_server role
+        
+        | [role;"via"; other] ->   add_client role other client_port
+        | [role; "crash"] ->    kill role 
+        |  _ -> prerr_endlinef "unsupported command %s\n" line
+        else if line.[0] = '#' then
+        ()
+        else 
+        match Str.bounded_split col line 2 with
+        | [role; words] ->
+        send_string role words
+        | _ -> prerr_endlinef "unhandled %s" line
+        
+        let by_lines client_port =
+        List.iter (by_line client_port)
+        
+        let interprete_scenario client_port =
+        try
+        while true do
+        let cmd = read_line () in
+        by_line cmd client_port
+        done 
+        with
+        End_of_file ->
+        Hashtbl.iter (fun _ (fid,pid,machine) -> begin 
+        Unix.close fid;
+        Unix.kill pid 9;
+        end ) roles
+ *)  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+clean :
+	ocamlbuild -clean
+	rm -rf *.log
+dsl:
+	ocamlbuild DSL_util.cmo
+	ocamlbuild -lflags dynlink.cma DSL_util.byte
+
+
+
+clean :
+	ocamlbuild -clean 
+dsl:
+	ocamlbuild DSL_util.cmo
+	ocamlbuild -lflags dynlink.cma DSL_util.byte

Binary file added.

Binary file added.

Binary file added.

_build/DSL_util.ml

+open Format
+open Unix  
+open Util
+let (|>) x f =  f x
+let prerr_endlinef fmt = ksprintf prerr_endline  fmt    
+  
+let roles = Hashtbl.create 50
+let col = Str.regexp ":"
+let ws = Str.regexp "[ \t]+"    
+(** make sure dchat is in your search path*)
+
+let dchat = begin
+  let chan = Unix.open_process_in "which dchat" in
+  let ans =input_line chan  in
+  if Sys.file_exists ans then begin 
+    prerr_endlinef "dchat:%s" ans;
+    ans
+  end 
+  else begin
+    prerr_endlinef "dchat not found: exit";
+    exit 1;
+  end 
+end 
+let machine_id = ref 1
+
+let config = begin
+  let conf = open_in "config.in" in
+  let pairs = ref [] in 
+  finally (fun _ -> close_in conf) (fun conf ->
+    try
+      while true do
+        let line = (input_line conf) in
+        let () = prerr_endline line in 
+        let [a;b] = Str.bounded_split col line 2 in
+        pairs := (a,b):: !pairs
+      done
+    with
+      End_of_file -> ()) conf;
+  !pairs
+end
+
+let client_port  =
+  try
+    List.assoc "client_port" config
+  with Not_found -> begin
+    prerr_endline "client_port not found";
+    raise Not_found
+  end
+
+let pennid =
+  try
+    List.assoc "pennid" config
+  with Not_found -> begin
+    prerr_endline "pennid not found";
+    raise Not_found
+  end 
+
+let gen_command i pennid =
+  sprintf "ssh spec%02d ps -U %s | grep dchat | sed 's/\\W*//' | cut -d ' ' \
+    -f 1 | while read ss; do echo \"spec%02d $ss\"; ssh spec%02d kill $ss; \
+    done" i pennid i i
+
+(** kill your dchat programs
+    to save your udp port 
+ *)      
+let reset ?(from=1) ?(until = !machine_id) ()= begin
+  for i = from to until do 
+    gen_command i pennid|> Sys.command |> ignore
+  done ;
+  Hashtbl.clear roles;
+  machine_id := 1;
+end 
+    
+let create_and_redir (name,args,fnormal,ferr) =
+  let (fd_in,fd_out) = pipe() in
+  match fork () with
+  | 0 -> begin 
+      dup2 fd_in stdin;
+      close fd_in;
+      close fd_out;
+      let out_chan = open_out fnormal in
+      let err_chan = open_out ferr in  begin
+        prerr_endlinef "create file %s and %s " fnormal ferr;
+        dup2 (descr_of_out_channel out_chan) stdout;
+        dup2 (descr_of_out_channel err_chan) stderr;
+        execvp name args
+      end 
+  end
+  | pid -> begin
+      close fd_in;
+      (fd_out,pid)
+  end 
+
+(** without buffering *)
+let write_out fd_out str =
+  write fd_out str 0 (String.length str)
+
+let role_exists role =  Hashtbl.mem roles role
+
+
+  
+let kill role =
+  if role_exists role then 
+    let _,pid,machine = Hashtbl.find roles role in begin
+      Unix.kill pid 9 
+    end
+  else
+    prerr_endlinef "role%s not exist" role
+      
+
+    
+let add_client role other  =
+  if role_exists role then
+    prerr_endlinef "role:%s already exists" role
+  else if not (role_exists other) then
+    prerr_endlinef "role:%s not exists" other
+  else
+    
+    let machine = sprintf "spec%02d" !machine_id in
+    let () = incr machine_id in    
+    let _,_,m = Hashtbl.find roles other in 
+    let args = [|"ssh"; machine; dchat; role; m^":"^ client_port|] in 
+    let (fid,pid) = create_and_redir ("ssh",args,role^".log",role^".err.log") in
+    let () = prerr_endlinef "%s" (Array.fold_left (fun x y -> x ^ " " ^ y) "" args) in
+    Hashtbl.add roles role (fid,pid,machine)
+
+let add_server role =
+  if role_exists role then
+    prerr_endlinef "role:%s already exists" role
+  else 
+    let machine = sprintf "spec%02d" !machine_id in
+    let args = [|"ssh"; machine; dchat; role|] in  (* only nick *)
+    let () = incr machine_id in
+    let (fid,pid) = create_and_redir ("ssh",args,role^".log",role^".err.log") in
+    let () = prerr_endlinef "%s" (Array.fold_left (fun x y -> x ^ " " ^ y) "" args) in
+    Hashtbl.add roles role (fid,pid,machine)
+
+
+let send_string role str=
+  if role_exists role then 
+    let fd_out,_,_ = Hashtbl.find roles role in begin
+      let _ = write_out fd_out (str^"\n") in
+      prerr_endlinef "%s:%s\n" role (str^"\n")
+    end
+  else prerr_endlinef "role%s does not exists" role
+
+
+open Camlp4.PreCast
+  
+let parser_of_entry entry  s =
+  try Gram.parse entry (Loc.mk "<string>") (Stream.of_string  s)
+  with
+    Loc.Exc_located(loc, e) -> begin 
+      prerr_endline (Loc.to_string loc);
+      let start_bol,stop_bol,
+        start_off, stop_off =
+        Loc.(start_bol loc,
+             stop_bol loc,
+             start_off loc,
+             stop_off loc
+            ) in
+      let abs_start_off = start_bol + start_off in
+      let abs_stop_off = stop_bol + stop_off in
+      let err_location = String.sub s abs_start_off
+          (abs_stop_off - abs_start_off + 1) in
+      prerr_endline (sprintf "err: ^%s^" err_location);
+      raise e ;
+    end
+        
+
+
+let instruction = Gram.Entry.mk "instruction"
+let instruction_eoi = Gram.Entry.mk "instruction_eoi"
+
+let _ = begin
+  EXTEND Gram GLOBAL: instruction instruction_eoi;
+  instruction_eoi:
+    [ [x = instruction ; `EOI -> x ] ];
+  instruction:
+    [
+     "top"
+       [ x=name ; "via"; y=name  -> begin
+         prerr_endlinef "add_client %s %s" x y;
+         add_client x y;
+       end
+       | x=name ; ":"; s=STRING -> begin
+           prerr_endlinef "%s:\"%s\"" x s ;
+           send_string x  s;
+       end 
+       | x=name ; "crash" -> begin
+           prerr_endlinef "kill %s" x ;
+           kill x;
+       end
+       | x=name ; "create" -> begin
+           prerr_endlinef "create server %s" x ;
+           add_server x;
+       end 
+       | "time" ; `INT(x,_) ->  begin
+           prerr_endlinef "sleep %d" x ;
+           Unix.sleep x;
+       end 
+       | "(" ; names = LIST1 name; ")" ; `INT(n,_);
+         "interval"; `FLOAT(f,_)-> begin
+           let () =
+             prerr_endlinef "(%s) in turn interval %f"
+               (List.fold_left  (fun x y -> x ^ " " ^ y) "" names) f in  
+           let start =  ref 0 in
+           for i = 1 to n do 
+             List.iter (fun role -> begin
+               send_string role (string_of_int !start);
+               Unix.select [] [] [] f |> ignore ;
+               incr start;
+             end
+              ) names
+           done 
+           end 
+       | -> begin
+           prerr_endlinef "empty";
+       end]];
+   name:
+    [ [x=LIDENT -> x
+      |x=UIDENT -> x]];
+  END;
+end
+    
+let parse_instruction = parser_of_entry instruction
+let parse_instruction_eoi = parser_of_entry instruction_eoi
+
+
+let file_lines_of str =
+  let chan = open_in str in
+  let lines = ref [] in
+  (try
+    while true do
+      lines := input_line chan :: !lines
+    done;
+  with
+    End_of_file -> begin 
+      close_in chan;
+    end);
+  List.rev !lines
+    
+(* let lines =  "leader_elect.ml" |> file_lines_of *)
+(* let ()  = reset ~until:3 () *)
+
+let _ =
+  try 
+    while true do 
+      (* List.iter parse_instruction_eoi lines *)
+      let line = read_line () in
+      let ()  =  prerr_endline line in
+      parse_instruction_eoi line
+    done
+  with
+    End_of_file ->
+      prerr_endlinef "finished"
+        

_build/DSL_util.ml.depends

+DSL_util.ml: Array Camlp4 Format Gram Hashtbl List Loc Str Stream String Sys Unix Util
+"Rule: ocaml dependencies ml (%=util )": "J\137�7�\153\141�\015!$\\ܩ�"
+"Resource: /mnt/castor/seas_home/h/hongboz/html/hongbo_zhang_files/dsl/DSL_util.ml": "N\016K\014\n\t�\152�_��\146l�<"
+"Resource: /mnt/castor/seas_home/h/hongboz/html/hongbo_zhang_files/dsl/util.ml": "A�P��\151\140�\005\004gG��2?"
+"Rule: ocaml: ml -> cmo & cmi (%=util )": "�\002�\132\142���x���\"�\154�"
+"Rule: ocaml: ml -> cmo & cmi (%=DSL_util )": "VD\134\024�f� d\140��m��\150"
+"Rule: ocaml: cmo* -> byte (%=DSL_util )": "��\031-H@L[8T���]n\019"
+"Rule: ocaml dependencies ml (%=DSL_util )": "^�5�(�z\148\006��I�5q�"
+### Starting build.
+# Target: DSL_util.ml.depends, tags: { extension:ml, file:DSL_util.ml, ocaml, ocamldep, pp(camlp4of), quiet, thread, traverse, use_str, use_unix }
+/home1/h/hongboz/SourceCode/godi-rocketboost-20110811/ocaml/bin/ocamldep.opt -pp camlp4of -modules DSL_util.ml > DSL_util.ml.depends # cached
+# Target: util.ml.depends, tags: { extension:ml, file:util.ml, ocaml, ocamldep, quiet, thread, traverse, use_str, use_unix }
+/home1/h/hongboz/SourceCode/godi-rocketboost-20110811/ocaml/bin/ocamldep.opt -modules util.ml > util.ml.depends # cached
+# Target: util.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:util.cmo, file:util.ml, implem, ocaml, quiet, thread, traverse, use_str, use_unix }
+/home1/h/hongboz/SourceCode/godi-rocketboost-20110811/ocaml/bin/ocamlc.opt -c -thread -o util.cmo util.ml # cached
+# Target: DSL_util.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:DSL_util.cmo, file:DSL_util.ml, implem, ocaml, pp(camlp4of), quiet, thread, traverse, use_camlp4, use_str, use_unix }
+/home1/h/hongboz/SourceCode/godi-rocketboost-20110811/ocaml/bin/ocamlc.opt -c -I +camlp4 -thread -pp camlp4of -o DSL_util.cmo DSL_util.ml # cached
+# Target: DSL_util.byte, tags: { byte, dont_link_with, extension:byte, file:DSL_util.byte, link, ocaml, pkg_dynlink, program, quiet, thread, traverse, use_camlp4, use_str, use_unix }
+/home1/h/hongboz/SourceCode/godi-rocketboost-20110811/ocaml/bin/ocamlc.opt dynlink.cma unix.cma str.cma -I +camlp4 camlp4lib.cma threads.cma -thread util.cmo DSL_util.cmo -o DSL_util.byte
+# Compilation successful.

_build/ocamlc.where

+/home1/h/hongboz/SourceCode/godi-rocketboost-20110811/ocaml/lib/ocaml/std-lib

Binary file added.

Binary file added.

+(* -*- Mode:caml; -*-
+   *===----------------------------------------------------------------------===
+   * Version: $Id: util.ml,v 0.0 2012/03/31 13:41:36 bobzhang1988 Exp $
+   *===----------------------------------------------------------------------===*)
+open Format
+open Unix
+
+let (|>) x f =  f x
+let (^$) f x = f x
+
+(* exceptions *)
+exception Bad_parse
+exception Found
+
+let finally handler f x =
+  let r = (
+    try f x
+    with e -> handler () ; raise e
+   ) in
+  handler ();
+  r
+
+(** range of integers *)
+let rec range i j =
+  if i > j then
+    []
+  else i :: (range (i+1) j)
+
+let prerr_endlinef fmt = ksprintf prerr_endline  fmt
+
+(** all capital, then is command *)
+let is_cmd s =
+  let n = String.length s in 
+  if n = 0 then
+    false
+  else
+    let b = ref true in
+    let i = ref 0 in 
+    while !b && !i < n do begin 
+      if not (s.[!i] >= 'A' && s.[!i] <='Z') then
+	b:=false;
+      incr i;
+    end 
+    done;
+    !b
+let (|-) f g  x = g (f x)
+let print_string_list  = List.iter (print_string |- print_newline)
+let option_get = function
+  | Some x -> x
+  | None -> invalid_arg "option_get"
+
+let fatalf fmt =
+  ksprintf (fun str ->
+    eprintf "Fatal error: %s !\n%!" str;
+    exit 1
+    ) fmt
+
+
+let str_of_time ({tm_sec; tm_min; tm_hour; _ } ) =
+  sprintf "%02d:%02d:%02d" tm_hour tm_min tm_sec
+
+(** TODO we should put this somewhere better *)
+let log_printf ?(debug=true)  format =
+  ksprintf (fun str ->
+    if debug then begin
+      prerr_string (sprintf "%s)) " (str_of_time (localtime (gettimeofday()))));
+      prerr_endline str
+    end)  format
+
+(** turn a pretty printer function to a string_of_function
+ *)
+let make_of_string pretty content =
+  let buf = Buffer.create 100 in
+  let fmt = Format.formatter_of_buffer buf in begin
+    pretty fmt content;
+    Format.pp_print_flush fmt  ();
+    Buffer.contents buf
+  end
+
+(** first parse as digit, if failed
+    will try to gethostbyname
+    gethostbyname "www.google.com" works
+ *)
+let sockaddr_of_name_port  (s,port) =
+  try
+    ADDR_INET (inet_addr_of_string s, port)
+  with
+    e ->
+      try
+        ADDR_INET ((gethostbyname s).h_addr_list.(0),port)
+      with
+        e -> invalid_arg "sockaddr_of_string_int"
+
+let print_usage () = begin
+  log_printf "Usage: dchat < nickname > [ server_ip:server_port ]@.";
+  exit 1
+end
+
+(** parse_args
+    dchar nick ip:port
+    dchat nick
+ *)
+let parse_args () =
+  try match Array.length Sys.argv with
+  | 3 -> begin 
+      match Str.(split  (regexp ":") Sys.argv.(2)) with
+      | [ip;port] -> begin 
+          if int_of_string port > 65535 then
+            raise Bad_parse
+          else
+            (Sys.argv.(1), Some (sockaddr_of_name_port (ip, int_of_string port)))
+      end
+      | _ -> assert false
+  end 
+  | 2 -> (Sys.argv.(1), None)
+  | _ -> raise Bad_parse
+  with e -> begin print_usage () end
+

_build/util.ml.depends

+util.ml: Array Buffer Format List Str String Sys Unix
+true : use_unix
+true : thread
+true : use_str
+
+<DSL_util.ml> : pp(camlp4of)
+<DSL_util.cmo> : use_camlp4
+<DSL_util.byte> : pkg_dynlink, use_camlp4
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.