Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Jul 17, 2023
1 parent 1cf7211 commit 217235c
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 141 deletions.
43 changes: 43 additions & 0 deletions .ocamlformat
@@ -0,0 +1,43 @@
version=0.25.1
assignment-operator=end-line
break-cases=fit
break-fun-decl=wrap
break-fun-sig=wrap
break-infix=wrap
break-infix-before-func=false
break-separators=before
break-sequences=true
cases-exp-indent=2
cases-matching-exp-indent=normal
doc-comments=before
doc-comments-padding=2
doc-comments-tag-only=default
dock-collection-brackets=false
exp-grouping=preserve
field-space=loose
if-then-else=compact
indicate-multiline-delimiters=space
indicate-nested-or-patterns=unsafe-no
infix-precedence=indent
leading-nested-match-parens=false
let-and=sparse
let-binding-spacing=compact
let-module=compact
margin=80
max-indent=2
module-item-spacing=sparse
ocaml-version=4.14.0
ocp-indent-compat=false
parens-ite=false
parens-tuple=always
parse-docstrings=true
sequence-blank-line=preserve-one
sequence-style=terminator
single-case=compact
space-around-arrays=true
space-around-lists=true
space-around-records=true
space-around-variants=true
type-decl=sparse
wrap-comments=false
wrap-fun-args=true
52 changes: 26 additions & 26 deletions example/print_dir.ml
Expand Up @@ -25,40 +25,40 @@ let () =
(* Printing base dirs *)
Format.printf "* Base dirs:@.";
print_dirs
[ B.home_dir, "home_dir: "
; B.cache_dir, "cache_dir: "
; B.config_dir, "config_dir: "
; B.data_dir, "data_dir: "
; B.data_local_dir, "data_local_dir:"
; B.preference_dir, "preference_dir:"
; B.runtime_dir, "runtime_dir: "
; B.state_dir, "state_dir: "
; B.executable_dir, "executable_dir:"
[ (B.home_dir, "home_dir: ")
; (B.cache_dir, "cache_dir: ")
; (B.config_dir, "config_dir: ")
; (B.data_dir, "data_dir: ")
; (B.data_local_dir, "data_local_dir:")
; (B.preference_dir, "preference_dir:")
; (B.runtime_dir, "runtime_dir: ")
; (B.state_dir, "state_dir: ")
; (B.executable_dir, "executable_dir:")
];

(* Printing user dirs *)
Format.printf "* User dirs:@.";
print_dirs
[ U.home_dir, "home_dir: "
; U.audio_dir, "audio_dir: "
; U.desktop_dir, "desktop_dir: "
; U.document_dir, "document_dir: "
; U.download_dir, "download_dir: "
; U.font_dir, "font_dir: "
; U.picture_dir, "picture_dir: "
; U.public_dir, "public_dir: "
; U.template_dir, "template_dir: "
; U.video_dir, "video_dir: "
[ (U.home_dir, "home_dir: ")
; (U.audio_dir, "audio_dir: ")
; (U.desktop_dir, "desktop_dir: ")
; (U.document_dir, "document_dir: ")
; (U.download_dir, "download_dir: ")
; (U.font_dir, "font_dir: ")
; (U.picture_dir, "picture_dir: ")
; (U.public_dir, "public_dir: ")
; (U.template_dir, "template_dir: ")
; (U.video_dir, "video_dir: ")
];

(* Printing project dirs*)
Format.printf "* Project dirs:@.";
print_dirs
[ P.cache_dir, "cache_dir: "
; P.config_dir, "config_dir: "
; P.data_dir, "data_dir: "
; P.data_local_dir, "data_local_dir:"
; P.preference_dir, "preference_dir:"
; P.state_dir, "state_dir: "
; P.runtime_dir, "runtime_dir: "
[ (P.cache_dir, "cache_dir: ")
; (P.config_dir, "config_dir: ")
; (P.data_dir, "data_dir: ")
; (P.data_local_dir, "data_local_dir:")
; (P.preference_dir, "preference_dir:")
; (P.state_dir, "state_dir: ")
; (P.runtime_dir, "runtime_dir: ")
]
2 changes: 2 additions & 0 deletions example/quick_start.ml
@@ -1,7 +1,9 @@
let () =
let module App_id = struct
let qualifier = "com"

let organization = "YourCompany"

let application = "yourapp"
end in
let module M = Directories.Project_dirs (App_id) in
Expand Down
25 changes: 25 additions & 0 deletions src/directories.mli
@@ -1,38 +1,63 @@
module Base_dirs () : sig
val home_dir : string option

val cache_dir : string option

val config_dir : string option

val data_dir : string option

val data_local_dir : string option

val preference_dir : string option

val runtime_dir : string option

val state_dir : string option

val executable_dir : string option
end

module User_dirs () : sig
val home_dir : string option

val audio_dir : string option

val desktop_dir : string option

val document_dir : string option

val download_dir : string option

val font_dir : string option

val picture_dir : string option

val public_dir : string option

val template_dir : string option

val video_dir : string option
end

module Project_dirs (App_id : sig
val qualifier : string

val organization : string

val application : string
end) : sig
val cache_dir : string option

val config_dir : string option

val data_dir : string option

val data_local_dir : string option

val preference_dir : string option

val runtime_dir : string option

val state_dir : string option
end
24 changes: 5 additions & 19 deletions src/directories_common.ml
Expand Up @@ -9,21 +9,12 @@ module type App_id = sig
end

(* TODO: remove once we drop 4.07 *)
let option_map f = function
| None -> None
| Some v -> Some (f v)
let option_map f = function None -> None | Some v -> Some (f v)

(* TODO: remove once we drop 4.07 *)
let option_bind o f =
match o with
| None -> None
| Some v -> f v
let option_bind o f = match o with None -> None | Some v -> f v

let relative_opt dir =
if Filename.is_relative dir then
None
else
Some dir
let relative_opt dir = if Filename.is_relative dir then None else Some dir

let getenv env =
match Sys.getenv env with
Expand All @@ -39,15 +30,10 @@ let lower_and_replace_ws s replace =
let should_replace = ref false in
for i = 0 to String.length s - 1 do
match s.[i] with
| ' '
| '\012'
| '\n'
| '\r'
| '\t' ->
| ' ' | '\012' | '\n' | '\r' | '\t' ->
if !should_replace then (
Buffer.add_string buff replace;
should_replace := false
)
should_replace := false )
| c ->
Buffer.add_char buff c;
should_replace := true
Expand Down
18 changes: 5 additions & 13 deletions src/linux/directories.ml
Expand Up @@ -66,18 +66,11 @@ module User_dirs () = struct
option_map (fun dir -> dir / "user-dirs.dirs") Base_dirs.config_dir

let user_dirs =
option_bind user_dirs (fun f ->
if Sys.file_exists f then
Some f
else
None)
option_bind user_dirs (fun f -> if Sys.file_exists f then Some f else None)

let user_dirs =
option_bind user_dirs (fun f ->
if Sys.is_directory f then
None
else
Some f)
if Sys.is_directory f then None else Some f )

let user_shell = getenv "SHELL"

Expand All @@ -91,9 +84,7 @@ module User_dirs () = struct
in
let xdg = input_line chan in
let result = Unix.close_process_in chan in
match result with
| WEXITED 0 -> Some xdg
| _ -> None
match result with WEXITED 0 -> Some xdg | _ -> None
with _ -> None )
| _ -> None

Expand Down Expand Up @@ -140,7 +131,8 @@ end
module Project_dirs (App_id : App_id) = struct
module Base_dirs = Base_dirs ()

let project_path = Directories_common.lower_and_replace_ws App_id.application ""
let project_path =
Directories_common.lower_and_replace_ws App_id.application ""

let concat_project_path = option_map (fun dir -> dir / project_path)

Expand Down
6 changes: 4 additions & 2 deletions src/macos/directories.ml
Expand Up @@ -81,9 +81,11 @@ module Project_dirs (App_id : App_id) = struct

let qualifier = Directories_common.lower_and_replace_ws App_id.qualifier "-"

let organization = Directories_common.lower_and_replace_ws App_id.organization "-"
let organization =
Directories_common.lower_and_replace_ws App_id.organization "-"

let application = Directories_common.lower_and_replace_ws App_id.application "-"
let application =
Directories_common.lower_and_replace_ws App_id.application "-"

let project_path =
Format.sprintf "%s.%s.%s" qualifier organization application
Expand Down
21 changes: 8 additions & 13 deletions src/windows/bindings/gen_functions.ml 100755 → 100644
@@ -1,29 +1,24 @@

let print_defines fmt =
List.iter (fun (d, v) -> Format.fprintf fmt "#define %s (%s)@\n" d v)

let print_headers fmt =
List.iter (Format.fprintf fmt "#include <%s>@\n")
let print_headers fmt = List.iter (Format.fprintf fmt "#include <%s>@\n")

let make_functions_stubs
(c_defines : (string * string) list)
(c_headers : string list)
(functions_functor : (module Cstubs.BINDINGS)) =
let make_functions_stubs (c_defines : (string * string) list)
(c_headers : string list) (functions_functor : (module Cstubs.BINDINGS)) =
let fmt = Format.std_formatter in
begin
match Sys.argv.(1) with
| "c" ->
print_defines fmt c_defines;
print_headers fmt c_headers;
Cstubs.write_c ~prefix:"win_stub" fmt functions_functor
| "ml" ->
Cstubs.write_ml ~prefix:"win_stub" fmt functions_functor
print_defines fmt c_defines;
print_headers fmt c_headers;
Cstubs.write_c ~prefix:"win_stub" fmt functions_functor
| "ml" -> Cstubs.write_ml ~prefix:"win_stub" fmt functions_functor
| s -> failwith ("unknown functions " ^ s)
end;
Format.pp_print_flush fmt ()

let () =
make_functions_stubs
[ "NTDDI_VERSION", "NTDDI_VISTA" ]
[ ("NTDDI_VERSION", "NTDDI_VISTA") ]
[ "windows.h"; "shlobj.h" ]
(module Win_functions_functor.Apply)
3 changes: 1 addition & 2 deletions src/windows/bindings/win_functions.ml 100755 → 100644
@@ -1,2 +1 @@

include Win_functions_functor.Apply(Win_functions_stubs)
include Win_functions_functor.Apply (Win_functions_stubs)

0 comments on commit 217235c

Please sign in to comment.