-
Notifications
You must be signed in to change notification settings - Fork 1
/
typonf.sh
26 lines (26 loc) · 1.21 KB
/
typonf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
script="/tmp/typonf.escript"
cat > $script <<EOF
%% -*- erlang -*-
main([File]) ->
{ok, [In]} = file:consult(File),
file:write_file(File, io_lib:format("~tp.~n", [replace(In)])).
replace({Key, {atom, <<>>, Default}}) -> {Key, Default};
replace({Key, {atom, Bin, _}}) -> replace({Key, {atom, Bin}});
replace({Key, {atom, Bin}}) -> {Key, binary_to_atom(Bin, utf8)};
replace({Key, {integer, <<>>, Default}}) -> {Key, Default};
replace({Key, {integer, Bin, _}}) -> replace({Key, {integer, Bin}});
replace({Key, {integer, Bin}}) -> {Key, list_to_integer(binary_to_list(Bin))};
replace({Key, {boolean, <<>>, Default}}) -> {Key, Default};
replace({Key, {boolean, Bin, _}}) -> replace({Key, {boolean, Bin}});
replace({Key, {boolean, <<"true">>}}) -> {Key, true};
replace({Key, {boolean, <<"True">>}}) -> {Key, true};
replace({Key, {boolean, <<"1">>}}) -> {Key, true};
replace({Key, {boolean, _}}) -> {Key, false};
replace({Key, Bin}) when is_binary(Bin) -> {Key, Bin};
replace({Key, Atom}) when is_atom(Atom) -> {Key, Atom};
replace({Key, List}) when is_list(List) -> {Key, replace(List)};
replace([]) -> [];
replace([H|T]) -> [replace(H)|replace(T)];
replace(Other) -> Other.
EOF
/app/erts-9.3.1/bin/escript $script $DEST_SYS_CONFIG_PATH