From 21641573083b324e4b28b052e79ac81e9dac7a50 Mon Sep 17 00:00:00 2001 From: malc Date: Sun, 9 Jan 2022 01:31:18 +0300 Subject: [PATCH] Behave sanely when $HOME/.config does not exist cf. https://github.com/moosotc/llpp/issues/180 --- config.ml | 9 +-------- main.ml | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/config.ml b/config.ml index e12e7b8..6c28f9a 100644 --- a/config.ml +++ b/config.ml @@ -301,15 +301,8 @@ let home = dolog "cannot determine home directory location: %s" @@ exntos exn; E.s -let defconfpath = - let dir = - let dir = Filename.concat home ".config" in - if Sys.is_directory dir then dir else home - in - Filename.concat dir "llpp.conf" - module S = struct - let confpath = ref defconfpath + let confpath = ref E.s let ss = ref Unix.stdin let wsfd = ref Unix.stdin let stderr = ref Unix.stdin diff --git a/main.ml b/main.ml index ef77bda..7eb3e49 100644 --- a/main.ml +++ b/main.ml @@ -1172,7 +1172,7 @@ let act cmds = | "tile" , args -> (* - C part is notifying us that it has finished redering a tile + C part is notifying us that it has finished rendering a tile valid = the tile fits current config (i.e. the settings with which the tile has been rendered match current ones) @@ -4536,6 +4536,7 @@ let () = let openlast = ref false in let doreap = ref false in let csspath = ref None in + let justversion = ref false in S.selfexec := Sys.executable_name; let spec = [("-p", Arg.Set_string S.password, " Set password"); @@ -4556,11 +4557,7 @@ let () = ("-remote", Arg.Set_string rcmdpath, " Set path to the remote fifo"); ("-gc", Arg.Set gc, " Collect garbage"); - ("-v", - Arg.Unit (fun () -> - Printf.printf "%s\nconfiguration file: %s\n" (Help.version ()) - Config.defconfpath; - exit 0), " Print version and exit"); + ("-v", Arg.Set justversion, " Print version and exit"); ("-css", Arg.String (fun s -> csspath := Some s), " Set path to the style sheet to use with EPUB/HTML"); ("-origin", Arg.Set_string S.origin, " "); @@ -4575,6 +4572,22 @@ let () = Arg.parse (Arg.align spec) (fun s -> S.path := s) ("Usage: " ^ Sys.argv.(0) ^ " [options] some.pdf\nOptions:"); + if !S.confpath == E.s + then ( + let dir = + let dir = Filename.concat home ".config" in + if try Sys.is_directory dir with _ -> false then dir else home + in + S.confpath := Filename.concat dir "llpp.conf" + ); + + if !justversion + then ( + Printf.printf "%s\nconfiguration file: %s\n" (Help.version ()) + !S.confpath; + exit 0 + ); + let histmode = emptystr !S.path && not !openlast in if !gc -- 2.11.4.GIT