5 case os:getenv("HOME") of
9 get_dir(dir_home_config
) ->
10 case get_dir(dir_home
) of
11 undefined
-> undefined
;
12 Dir
-> filename:absname_join(Dir
, ".config")
14 get_dir(dir_config
) -> "/etc";
15 get_dir(dir_current
) ->
16 case file:get_cwd() of
20 get_dir(_
) -> undefined
.
22 load_conf_spec(DirId
, FileName
, Prefix
, D
) ->
23 case get_dir(DirId
) of
25 Dir
-> load_conf_spec(filename:absname_join(Dir
, [Prefix
|FileName
]), D
)
27 load_conf_spec(FileName
, D
) ->
28 case file:open(FileName
, [read
]) of
29 {ok
, Fd
} -> load_conf_file(Fd
, D
);
33 trim(S
) -> re:replace(S
, "\\s+", "", [global
,{return
,list}]).
35 load_conf_file(Fd
, D
) ->
36 case file:read_line(Fd
) of
37 {ok
, Line
} -> load_conf_file(Fd
, Line
, D
);
38 _
-> file:close(Fd
), D
40 load_conf_file(Fd
, Line
, D
) ->
41 case list_to_tuple(re:split(Line
, "=", [{return
, list}])) of
43 load_conf_file(Fd
, dict:store(trim(Key
), trim(Value
), D
));
44 _
-> load_conf_file(Fd
, D
)
48 load([{dir_config
,[]}, {dir_home_config
,[]}, {dir_home
,"."}, {dir_current
,"."}], FileName
, dict:new()).
50 load([{DirId
,Prefix
}|T
], FileName
, D
) ->
51 load(T
, FileName
, load_conf_spec(DirId
, FileName
, Prefix
, D
));