Mitsuhiro Nakamura avatar Mitsuhiro Nakamura committed 792c569

Renamed modules: Ext -> Util and DoShuffle -> Perform.
Added time stamps.

Comments (0)

Files changed (7)

 PROGRAM        = shuffle
 NATIVE_ENABLED = true
 USE_OCAMLFIND  = true
-FILES[]        = argOpt doShuffle main shufflee ext
+FILES[]        = argOpt perform main shufflee util
 
 OCamlProgram($(PROGRAM), $(FILES))
 
-(* Last modified: 2011-12-31 18:41:21. *)
+(* Last modified: 2011-12-31 22:22:27. *)
 
-open Ext
+open Util
 
 type t =
   { mutable source   : [`Default | `File | `Quoted | `Natural of int]

src/doShuffle.ml

-open Ext
-
-let perform_file_lines_all args =
-  let cins = match args with
-             | [] -> [stdin]
-             | xs -> List.map open_in xs in
-  let ss = List.concat_map rev_input_lines cins in
-  let strm = Shufflee.of_list ss in
-  begin
-    List.iter close_in cins;
-    Shufflee.iter print_endline strm
-  end
-
-let perform_file_lines_limit k args =
-  let cins = match args with
-             | [] -> [stdin]
-             | xs -> List.map open_in xs in
-  let ss = List.concat_map rev_input_lines cins in
-  let strm = Shufflee.of_list ss in
-  begin
-    List.iter close_in cins;
-    let ss' = Shufflee.npeek k strm in
-    List.iter print_endline ss'
-  end
-
-(*
- * let perform_file_words_all args =
- *   let cins = match args with
- *              | [] -> [stdin]
- *              | xs -> List.map open_in xs in
- *   let ss = List.concat_map rev_input_words cins in
- *   let strm = Shufflee.of_list ss in
- *   begin
- *     List.iter close_in cins;
- *     Shufflee.iter print_endline strm
- *   end
- * 
- *)
-
-(*
- * let perform_file_words_limit k args =
- *   let cins = match args with
- *              | [] -> [stdin]
- *              | xs -> List.map open_in xs in
- *   let ss = List.concat_map rev_input_words cins in
- *   let strm = Shufflee.of_list ss in
- *   begin
- *     List.iter close_in cins;
- *     let ss' = Shufflee.npeek k strm in
- *     List.iter print_endline ss'
- *   end
- *)
-
-let perform_file_chars_all args =
-  let cins = match args with
-             | [] -> [stdin]
-             | xs -> List.map open_in xs in
-  let s = String.concat_map input_all cins in
-  let strm = Shufflee.of_string s in
-  begin
-    List.iter close_in cins;
-    Shufflee.iter print_char strm;
-    print_newline ()
-  end
-
-let perform_file_chars_limit k args =
-  let cins = match args with
-             | [] -> [stdin]
-             | xs -> List.map open_in xs in
-  let s = String.concat_map input_all cins in
-  let strm = Shufflee.of_string s in
-  begin
-    List.iter close_in cins;
-    let ss' = Shufflee.npeek k strm in
-    List.iter print_char ss';
-    print_newline ()
-  end
-
-let perform_quoted_words_all args =
-  let strm = Shufflee.of_list args in
-  begin
-    Shufflee.iter (fun s -> print_string s; print_string " ") strm;
-    print_newline ()
-  end
-
-let perform_quoted_words_limit k args =
-  let strm = Shufflee.of_list args in
-  let ss' = Shufflee.npeek k strm in
-  begin
-    List.iter (fun s -> print_string s; print_string " ") ss';
-    print_newline ()
-  end
-
-let perform_natural_all n =
-  if n < 0 then
-    failwith "option `-n' must be positive"
-  else
-    let strm = Shufflee.of_list (List.init n identity) in
-    begin
-      Shufflee.iter (fun i -> print_int i; print_string " ") strm;
-      print_newline ()
-    end
-
-let perform_natural_limit k n =
-  if n < 0 then
-    failwith "option `-n' must be positive"
-  else if k < 0 then
-    failwith "option `-k' must be positive"
-  else
-    let strm = Shufflee.of_list (List.init n identity) in
-    let ns = Shufflee.npeek k strm in
-    begin
-      List.iter (fun i -> print_int i; print_string " ") ns;
-      print_newline ()
-    end
-

src/ext.ml

-let identity x = x
-
-(* Bollowed from caml-core *)
-let input_all cin =
-  (* We use 4096 because that is the size of OCaml's IO buffers. *)
-  let buf_size = 4096 in
-  let buf = String.create buf_size in
-  let buffer = Buffer.create buf_size in
-  let rec loop () =
-    let len = input cin buf 0 (String.length buf) in
-    if len > 0 then
-      begin
-        Buffer.add_substring buffer buf 0 len;
-        loop ()
-      end in
-  loop ();
-  Buffer.contents buffer
-
-let rev_input_lines cin =
-  let may_eof f =
-    try Some (f ())
-    with End_of_file -> None in
-  let rec loop ls =
-    match may_eof (fun () -> input_line cin) with
-      None -> ls
-    | Some l -> loop (l :: ls) in
-  loop []
-
-module List =
-struct
-  include List
-
-  let combine3 xs ys zs =
-    let rec loop xs ys zs result =
-      match (xs, ys, zs) with
-      | ([], [], []) -> rev result
-      | (x :: xs, y :: ys, z :: zs) -> loop xs ys zs ((x, y, z) :: result)
-      | _ -> invalid_arg "List.combine3" in
-    loop xs ys zs []
-
-  let init n f =
-    let rec loop i xs =
-      if i > 0
-      then loop (i - 1) (f (i - 1) :: xs)
-      else xs in
-    loop n []
-
-  let concat_map f xs =
-    (* TODO: Optimize it *)
-    concat (map f xs)
-end
-
-module String =
-struct
-  include String
-
-  let concat_map ?(sep = "") f ss =
-    (* TODO: Optimize it *)
-    concat sep (List.map f ss)
-end
-
+(* Last modified: 2011-12-31 22:23:00. *)
+
 let _ =
   let opt = ArgOpt.create ()
   and args = ref [] in
     Arg.parse specs (fun a -> args := a :: !args) header;
     ArgOpt.set_default opt;
     let open ArgOpt in
-    let open DoShuffle in
+    let open Perform in
     begin
       match opt with
       | {source = `File; split_by = `Line; limit = `All} ->
+(* Last modified: 2011-12-31 22:23:07. *)
+
+open Util
+
+let perform_file_lines_all args =
+  let cins = match args with
+             | [] -> [stdin]
+             | xs -> List.map open_in xs in
+  let ss = List.concat_map rev_input_lines cins in
+  let strm = Shufflee.of_list ss in
+  begin
+    List.iter close_in cins;
+    Shufflee.iter print_endline strm
+  end
+
+let perform_file_lines_limit k args =
+  let cins = match args with
+             | [] -> [stdin]
+             | xs -> List.map open_in xs in
+  let ss = List.concat_map rev_input_lines cins in
+  let strm = Shufflee.of_list ss in
+  begin
+    List.iter close_in cins;
+    let ss' = Shufflee.npeek k strm in
+    List.iter print_endline ss'
+  end
+
+(*
+ * let perform_file_words_all args =
+ *   let cins = match args with
+ *              | [] -> [stdin]
+ *              | xs -> List.map open_in xs in
+ *   let ss = List.concat_map rev_input_words cins in
+ *   let strm = Shufflee.of_list ss in
+ *   begin
+ *     List.iter close_in cins;
+ *     Shufflee.iter print_endline strm
+ *   end
+ * 
+ *)
+
+(*
+ * let perform_file_words_limit k args =
+ *   let cins = match args with
+ *              | [] -> [stdin]
+ *              | xs -> List.map open_in xs in
+ *   let ss = List.concat_map rev_input_words cins in
+ *   let strm = Shufflee.of_list ss in
+ *   begin
+ *     List.iter close_in cins;
+ *     let ss' = Shufflee.npeek k strm in
+ *     List.iter print_endline ss'
+ *   end
+ *)
+
+let perform_file_chars_all args =
+  let cins = match args with
+             | [] -> [stdin]
+             | xs -> List.map open_in xs in
+  let s = String.concat_map input_all cins in
+  let strm = Shufflee.of_string s in
+  begin
+    List.iter close_in cins;
+    Shufflee.iter print_char strm;
+    print_newline ()
+  end
+
+let perform_file_chars_limit k args =
+  let cins = match args with
+             | [] -> [stdin]
+             | xs -> List.map open_in xs in
+  let s = String.concat_map input_all cins in
+  let strm = Shufflee.of_string s in
+  begin
+    List.iter close_in cins;
+    let ss' = Shufflee.npeek k strm in
+    List.iter print_char ss';
+    print_newline ()
+  end
+
+let perform_quoted_words_all args =
+  let strm = Shufflee.of_list args in
+  begin
+    Shufflee.iter (fun s -> print_string s; print_string " ") strm;
+    print_newline ()
+  end
+
+let perform_quoted_words_limit k args =
+  let strm = Shufflee.of_list args in
+  let ss' = Shufflee.npeek k strm in
+  begin
+    List.iter (fun s -> print_string s; print_string " ") ss';
+    print_newline ()
+  end
+
+let perform_natural_all n =
+  if n < 0 then
+    failwith "option `-n' must be positive"
+  else
+    let strm = Shufflee.of_list (List.init n identity) in
+    begin
+      Shufflee.iter (fun i -> print_int i; print_string " ") strm;
+      print_newline ()
+    end
+
+let perform_natural_limit k n =
+  if n < 0 then
+    failwith "option `-n' must be positive"
+  else if k < 0 then
+    failwith "option `-k' must be positive"
+  else
+    let strm = Shufflee.of_list (List.init n identity) in
+    let ns = Shufflee.npeek k strm in
+    begin
+      List.iter (fun i -> print_int i; print_string " ") ns;
+      print_newline ()
+    end
+
+(* Last modified: 2011-12-31 22:23:17. *)
+
+let identity x = x
+
+(* Bollowed from caml-core *)
+let input_all cin =
+  (* We use 4096 because that is the size of OCaml's IO buffers. *)
+  let buf_size = 4096 in
+  let buf = String.create buf_size in
+  let buffer = Buffer.create buf_size in
+  let rec loop () =
+    let len = input cin buf 0 (String.length buf) in
+    if len > 0 then
+      begin
+        Buffer.add_substring buffer buf 0 len;
+        loop ()
+      end in
+  loop ();
+  Buffer.contents buffer
+
+let rev_input_lines cin =
+  let may_eof f =
+    try Some (f ())
+    with End_of_file -> None in
+  let rec loop ls =
+    match may_eof (fun () -> input_line cin) with
+      None -> ls
+    | Some l -> loop (l :: ls) in
+  loop []
+
+module List =
+struct
+  include List
+
+  let combine3 xs ys zs =
+    let rec loop xs ys zs result =
+      match (xs, ys, zs) with
+      | ([], [], []) -> rev result
+      | (x :: xs, y :: ys, z :: zs) -> loop xs ys zs ((x, y, z) :: result)
+      | _ -> invalid_arg "List.combine3" in
+    loop xs ys zs []
+
+  let init n f =
+    let rec loop i xs =
+      if i > 0
+      then loop (i - 1) (f (i - 1) :: xs)
+      else xs in
+    loop n []
+
+  let concat_map f xs =
+    (* TODO: Optimize it *)
+    concat (map f xs)
+end
+
+module String =
+struct
+  include String
+
+  let concat_map ?(sep = "") f ss =
+    (* TODO: Optimize it *)
+    concat sep (List.map f ss)
+end
+
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.