Commits

Sébastien Ferré committed c7e1b2e

Functionals over options.
More applications.

  • Participants
  • Parent commits cc1f59c

Comments (0)

Files changed (1)

 (* List functionals *)
 (* ---------------- *)
 
+let iter_option : ('a -> unit) -> 'a option -> unit =
+  fun f -> function
+    | None -> ()
+    | Some x -> f x
+
+let fold_option : ('a -> 'b) -> 'b -> 'a option -> 'b =
+  fun f e -> function
+    | None -> e
+    | Some x -> f x
+
+let map_option : ('a -> 'b) -> 'a option -> 'b option =
+  fun f -> function
+    | None -> None
+    | Some x -> Some (f x)
+
 let rec filter : 'a option list -> 'a list =
   function
     | [] -> []
          xs
          (fold_pair f xs e)
 
+let compare_pair : ('a -> 'a -> int) * ('b -> 'b -> int) -> 'a * 'b -> 'a * 'b -> int =
+  fun (comp1,comp2) (a1,a2) (b1,b2) ->
+    match comp1 a1 b1 with
+    | 0 -> comp2 a2 b2
+    | c1 -> c1
+
 let rec scramble : 'a list -> 'a list =
   function
   | [] -> []
   ignore (Sys.command ("mozilla -remote \"openurl(" ^ url ^ ")\""))
     
 let gqview filename =
-  ignore (Sys.command ("gqview " ^ filename ^ " &"))
+  ignore (Sys.command ("gqview \"" ^ String.escaped filename ^ "\" &"))
+
+let xmms filename =
+  ignore (Sys.command ("xmms \"" ^ String.escaped filename ^ "\" &"))
 
 let cyg2win path = (* convert a Cygwin path to a Windows path *)
-  let shift = 12 in (* prefix "/cygdrive/c/" *)
-  "C:\\" ^ String.concat "\\" (Str.split (Str.regexp "/") (String.sub path shift (String.length path - shift)))
+  match Str.split (Str.regexp "/") path with
+  | "cygdrive"::drive::l -> String.uppercase drive ^ ":\\" ^ String.concat "\\" l
+  | l -> "C:\\cygwin\\" ^ String.concat "\\" l
 
 let acdsee_cygwin filename =
   ignore (Sys.command ("/cygdrive/c/Program\\ Files/ACD\\ Systems/ACDSee\\ Trial\\ Version/ACDSee.exe /v \"" ^ cyg2win filename ^ "\" &"))
 
+let irfanview_cygwin filename =
+  ignore (Sys.command ("/cygdrive/c/Program\\ Files/IrfanView/i_view32.exe \"" ^ cyg2win filename ^ "\" &"))
+
+let irfanslideshow_cygwin filename =
+  ignore (Sys.command ("/cygdrive/c/Program\\ Files/IrfanView/i_view32.exe /slideshow=\"" ^ cyg2win filename ^ "\" &"))
+
 let winamp_cygwin filename =
    ignore (Sys.command ("/cygdrive/c/Program\\ Files/Winamp/winamp.exe \"" ^ cyg2win filename ^ "\" &"))
-