|
@@ -1,7 +1,9 @@
|
|
|
-module(mad_repl).
|
|
|
--copyright('Maxim Sokhatsky').
|
|
|
+%%-copyright('Maxim Sokhatsky').
|
|
|
+
|
|
|
-compile([export_all, nowarn_export_all]).
|
|
|
|
|
|
+
|
|
|
disabled() -> [].
|
|
|
system() -> [compiler,syntax_tools,sasl,tools,mnesia,reltool,xmerl,crypto,kernel,stdlib,ssh,eldap,
|
|
|
wx,webtool,ssl,runtime_tools,public_key,observer,inets,asn1,et,eunit,hipe,os_mon].
|
|
@@ -27,15 +29,31 @@ parse_applist(AppList) ->
|
|
|
[ list_to_atom(R) || R <-Res ] -- disabled().
|
|
|
|
|
|
load_config() ->
|
|
|
- Config = wildcards(["sys.config"]),
|
|
|
+ Config = wildcards(["sys.config", lists:concat( ["etc/", mad:host(), "/sys.config"] )]),
|
|
|
Apps = case Config of
|
|
|
[] -> case mad_repl:load_file("sys.config") of
|
|
|
{error,_} -> [];
|
|
|
- {ok,Bin} -> parse(binary_to_list(Bin)) end;
|
|
|
- File -> case file:consult(File) of
|
|
|
+ {ok,Bin} -> parse(unicode:characters_to_list(Bin)) end;
|
|
|
+ File -> case file:consult(hd(File)) of
|
|
|
{error,_} -> [];
|
|
|
{ok,[A]} -> A end end,
|
|
|
- [ begin [ application:set_env(App,K,V) || {K,V} <- Cfg ], {App,Cfg} end || {App,Cfg} <- Apps ].
|
|
|
+ load_config(Apps, []).
|
|
|
+
|
|
|
+
|
|
|
+load_config([H|T], Apps2) ->
|
|
|
+ App2 = case H of
|
|
|
+ {App,Cfg} -> [application:set_env(App,K,V) || {K,V} <- Cfg], [H];
|
|
|
+ File when erlang:is_list(File) ->
|
|
|
+ Apps = case file:consult(File) of
|
|
|
+ {error,_} -> [];
|
|
|
+ {ok,[A]} -> A end,
|
|
|
+ load_config(Apps, []);
|
|
|
+ _ -> []
|
|
|
+ end,
|
|
|
+ load_config(T, Apps2 ++ App2);
|
|
|
+load_config([], Apps2) ->
|
|
|
+ Apps2.
|
|
|
+
|
|
|
|
|
|
acc_start(A,Acc) ->
|
|
|
case application:start(A) of
|
|
@@ -69,11 +87,14 @@ sh(Params) ->
|
|
|
load(),
|
|
|
Config = load_config(),
|
|
|
Driver = mad_utils:get_value(shell_driver,_Config,user_drv),
|
|
|
- pre(Driver),
|
|
|
+ repl_intro(),
|
|
|
case os:type() of
|
|
|
- {win32,nt} -> shell:start();
|
|
|
- _ -> Driver:start() end,
|
|
|
- post(Driver),
|
|
|
+ {win32,nt} ->
|
|
|
+ os:cmd("chcp 65001"),
|
|
|
+ shell:start();
|
|
|
+ _ ->
|
|
|
+ Driver:start()
|
|
|
+ end,
|
|
|
load_apps(Params,Config,[]),
|
|
|
case Params of
|
|
|
["applist"] -> skip;
|
|
@@ -121,18 +142,8 @@ parse(String) ->
|
|
|
{value,Value,_Bs} = erl_eval:exprs(AbsForm, erl_eval:new_bindings()),
|
|
|
Value.
|
|
|
|
|
|
-% we need to call printing before starting driver for user_drv
|
|
|
-% but for start_kjell we should call after, that's why we have pre and post here.
|
|
|
-
|
|
|
-pre(start_kjell) -> [];
|
|
|
-pre(user_drv) -> unregister(user), appconfig(user_drv);
|
|
|
-pre(Driver) -> appconfig(Driver).
|
|
|
-post(start_kjell) -> appconfig(start_kjell);
|
|
|
-post(_) -> [].
|
|
|
-print(Label,Value,start_kjell) -> io:requests([{put_chars,Label ++ normalize(length(Label)+1,Value) ++ "\n\r"}]);
|
|
|
-print(Label,Value,_) -> mad:info("~s~p~n",[Label,Value]).
|
|
|
-normalize(Padding,V) -> [ case X of 10 -> [13,10]; E -> E end || X <- lists:flatten(pp(Padding,V) )].
|
|
|
-pp(Padding,V) -> k_io_lib_pretty:print(V, Padding, 80, 30, 60, fun(_,_)-> no end).
|
|
|
-appconfig(Driver) ->
|
|
|
- print("Configuration: ", load_config(), Driver),
|
|
|
- print("Applications: ", applist(), Driver).
|
|
|
+
|
|
|
+repl_intro() ->
|
|
|
+ io:format("Configuration: ~p~n", [load_config()]),
|
|
|
+ io:format("Applications: ~p~n", [applist()]).
|
|
|
+
|