Permalink
Browse files

Add more options to usage guide

  • Loading branch information...
1 parent 359fbf6 commit cb4197f9c125dc72de8e98d4b69d43ca46daf9a1 @psyeugenic committed Oct 19, 2010
Showing with 63 additions and 66 deletions.
  1. +50 −52 bin/eplot
  2. +13 −14 src/eplot_main.erl
View
102 bin/eplot
@@ -1,72 +1,67 @@
#!/usr/bin/env escript
%%! -smp enable -sname eplot
-
--mode(compile).
+%% vim: filetype=erlang
usage() ->
Text =
"eplot [options] files\r\n"
"Options:\r\n"
- "\t-o Outfile, directs the graph to the outfile\r\n"
+ "\t-o Outfile, :: filename(), directs the graph to the outfile\r\n"
"\t-render_engine Engine :: alpha | opaque, type of render engine\r\n"
- "\t-type Type :: png | raw_bitmap, output type\r\n"
- "\t-plot Plot :: plot2d | bar2d, plot type\r\n"
- "\t-width Width :: integer(), Width\r\n"
- "\t-height Height :: integer(), Height\r\n"
- "\t-x_label Label :: string(), X-axis label\r\n"
- "\t-y_label Label :: string(), Y-axis label\r\n",
+ "\t-type Type :: png | raw_bitmap, output type\r\n"
+ "\t-plot Plot :: plot2d | bar2d, plot type\r\n"
+ "\t-width Width :: integer(), Width\r\n"
+ "\t-height Height :: integer(), Height\r\n"
+ "\t-x_label Label :: string(), X-axis label\r\n"
+ "\t-y_label Label :: string(), Y-axis label\r\n"
+
+ "\t-x_range_min Min :: number()\r\n"
+ "\t-x_range_max Max :: number()\r\n"
+ "\t-y_range_min Min :: number()\r\n"
+ "\t-y_range_max Max :: number()\r\n"
+ "\t-margin Margin :: number()\r\n"
+ "\t-x_ticksize Size :: number()\r\n"
+ "\t-y_ticksize Size :: number()\r\n"
+ "\t-bg_rgba RGB[A] :: Background, ex. fefefe[fe]\r\n",
io:format("~s~n", [Text]),
+ halt(),
ok.
main([]) -> usage();
main(Args) ->
- code:add_patha(ebin()),
Options = parse_args(Args),
+ code:add_patha(ebin()),
Input = proplists:get_value(input, Options, []),
case proplists:get_value(o, Options) of
undefined -> eplot_main:eview(Input, Options);
Output -> eplot_main:png(Input, Output, Options)
end.
-parse_args(Args) -> parse_args(Args, [{bg_rgba, {255,255,255,255}},{plot, plot2d}]).
-parse_args([], Out) -> Out;
-parse_args([Value0,Value1|Args], Out) ->
- case Value0 of
+parse_args(Args) ->
+ parse_args(Args, [{bg_rgba, {255,255,255,255}},{plot, plot2d}], []).
+parse_args([], Opts, Inputs) -> [{input, Inputs}|Opts];
+parse_args([V0,V1|Args], Opts, Inputs) ->
+ case V0 of
+ "-h" ->
+ usage();
"-speedup" ->
- parse_args([Value1|Args], [{speedup,true}|Out]);
+ parse_args([V1|Args], [{speedup,true}|Opts], Inputs);
"-bg_rgba" ->
- parse_args(Args, [{bg_rgba, hexstring2rgb(Value1)}|proplists:delete(bg_rgba, Out)]);
- "-render_engine" ->
- parse_args(Args, [{render_engine, list_to_atom(Value1)}|proplists:delete(render_engine, Out)]);
- "-type" ->
- parse_args(Args, [{type, list_to_atom(Value1)}|proplists:delete(type, Out)]);
- "-plot" ->
- parse_args(Args, [{plot, list_to_atom(Value1)}|proplists:delete(plot, Out)]);
- [45|KeyString] ->
- Key = list_to_atom(KeyString),
- case proplists:get_value(Key, Out, []) of
- undefined ->
- parse_args(Args, [{Key, string2value(Value1)}|Out]);
- _ ->
- parse_args(Args, [{Key, string2value(Value1)}|proplists:delete(Key, Out)])
- end;
- Value0 ->
- case proplists:get_value(input, Out, []) of
- undefined ->
- parse_args([Value1|Args], [{input, [Value0]}|Out]);
- Values ->
- parse_args([Value1|Args], [{input, [Value0|Values]}|proplists:delete(input, Out)])
- end
+ parse_args(Args, [{bg_rgba, hexstring2rgb(V1)}|proplists:delete(bg_rgba, Opts)], Inputs);
+ "-" ++ SKey->
+ Key = list_to_atom(SKey),
+ parse_args(Args, [{Key, string_to_value(V1)}|proplists:delete(Key, Opts)], Inputs);
+ _ ->
+ parse_args([V1|Args], Opts, [V0|Inputs])
end;
-parse_args([Value|Args], Out) ->
- case proplists:get_value(input, Out, []) of
- undefined ->
- parse_args(Args, [{input, [Value]}|Out]);
- Values ->
- parse_args(Args, [{input, [Value|Values]}|proplists:delete(input, Out)])
+parse_args([Value|Args], Opts, Inputs) ->
+ case Value of
+ "-h" ->
+ usage();
+ _ ->
+ parse_args(Args, Opts, [Value|Inputs])
end.
-
hexstring2rgb(Hs = [_R0,_R1,_G0,_G1,_B0,_B1]) -> hexstring2rgb(Hs ++ "FF");
hexstring2rgb([R0,R1,G0,G1,B0,B1,A0,A1]) ->
R = hex2byte(R0)*15 + hex2byte(R1),
@@ -81,16 +76,19 @@ hex2byte(H) when H >= 65, H =< 70 -> H - 65 + 10;
hex2byte(H) when H >= 97, H =< 102 -> H - 97 + 10;
hex2byte(_) -> 0.
-string2value(Value) ->
- case catch list_to_integer(Value) of
- I when is_integer(I) -> I;
- _ ->
- case catch list_to_float(Value) of
- F when is_float(F) -> F;
- _ -> Value
+string_to_value(Value) ->
+ try
+ list_to_integer(Value)
+ catch
+ _:_ ->
+ try
+ list_to_float(Value)
+ catch
+ _:_ ->
+ list_to_atom(Value)
end
end.
-
+
ebin() ->
Sname = escript:script_name(),
Rname = real_name(Sname),
View
@@ -42,10 +42,7 @@ parse_data_files([Filename|Filenames], Out) ->
merge_options([], Out) -> Out;
merge_options([{Key, Value}|Opts], Out) ->
- case proplists:get_value(Key, Out) of
- undefined -> merge_options(Opts, [{Key, Value}|Out]);
- _ -> merge_options(Opts, [{Key, Value}|proplists:delete(Key, Out)])
- end.
+ merge_options(Opts, [{Key, Value}|proplists:delete(Key, Out)]).
data_speedup([]) -> [];
data_speedup([{Filename,[{X,Y}|T]}|Data]) ->
@@ -70,22 +67,24 @@ parse_data_file(Fd, String, Out) ->
tokens2item(Tokens) ->
Is = lists:map(fun
(String) ->
- list_to_term(String)
+ string_to_term(String)
end, Tokens),
[X,Y|_] = Is,
{X,Y}.
-list_to_term(String) ->
- case catch list_to_number(String) of
- {'EXIT', _} -> list_to_atom(String);
- I -> I
+string_to_term(Value) ->
+ try
+ list_to_integer(Value)
+ catch
+ _:_ ->
+ try
+ list_to_float(Value)
+ catch
+ _:_ ->
+ list_to_atom(Value)
+ end
end.
-list_to_number(String) ->
- case catch list_to_integer(String) of
- I when is_integer(I) -> I;
- _ -> list_to_float(String)
- end.
get_config() ->
Home = os:cmd("echo -n $HOME"),

0 comments on commit cb4197f

Please sign in to comment.