=== modified file 'escape.pl' --- escape.pl 2011-11-26 17:51:17 +0000 +++ escape.pl 2011-11-26 16:18:19 +0000 @@ -15,13 +15,13 @@ l_strip([ ], _ , [ ]). l_strip([Head|Tail], Strip, Out) :- ( member(Head, Strip) - -> l_strip(Tail, Strip, Out) + -> l_strip(Strip, Tail, Out) ; Out = [Head|Tail] ). r_strip([ ], _ , []). r_strip([Head|Tail], Strip, Out) :- - r_strip(Tail, Strip, Out0), + r_strip(Strip, Tail, Out0), ( Out0 = [], member(Head, Strip) -> Out = [ ] @@ -70,8 +70,7 @@ % can escape anything sh_double_quoted(Char, String) :- ( Char = variable(Name) - -> str(Name, NameStr), - concat(["${", NameStr, "}"], String) + -> concat(["${", Name, "}"], String) ; member(Char, "$\\\"`") -> ( [Bksl] = "\\", String = [Bksl, Char] ) ; String = [Char] === modified file 'stagebuilder.pl' --- stagebuilder.pl 2011-11-26 17:51:17 +0000 +++ stagebuilder.pl 2011-11-26 16:18:19 +0000 @@ -47,14 +47,12 @@ check_returncode(Escaped, Checked). cmd_tokens( run_outvar(List, Var) , Checked) :- maplist(escape, List, Escaped0), - str(Var, VarStr), - concat([VarStr, "=$("], Pre), + concat([Var, "=$("], Pre), concat([[Pre], Escaped0, [")"]], Escaped), check_returncode(Escaped, Checked). cmd_tokens(run_outarray(List, Var) , Checked) :- maplist(escape, List, Escaped0), - str(Var, VarStr), - concat([VarStr, "=( $("], Pre), + concat([Var, "=( $("], Pre), concat([[Pre], Escaped0, [") )"]], Escaped), check_returncode(Escaped, Checked). cmd_tokens( echo_append(String, File), Escaped) :- @@ -85,7 +83,8 @@ %print_cmds([ ]). print_cmds(Commands) :- - maplist(format_cmd, Commands, Lines), !, + flat_cmds(Commands, CmdList), + maplist(format_cmd, CmdList, Lines), !, str_join("\n", Lines, String), name(Name,String), nl, @@ -101,24 +100,28 @@ % maplist(print_solution, Solutions). cmd_repr(Command) :- - write('representation of: '), portray_clause(Command), write(' ::'), nl, - ( setof(Lines , maplist(format_cmd, [Command], Lines), Solutions) - -> maplist(print_solution, Solutions) - ; write('FAILED!'), nl, trace, format_cmd(Command, _) + write('representation of: '), write(Command), write(' ::'), nl, + setof(Lines , maplist(format_cmd, [Command], Lines), Solutions), + maplist(print_solution, Solutions). + + cmds_repr(Commands) :- + maplist(cmd_repr, Commands). + +flat_cmds(X, List) :- + ( is_list(X) + -> List = X + ; X = A + B + -> flat_cmds(A, AList), + flat_cmds(B, BList), + append(AList, BList, List) + ; functor(X, _Name, _), + arg(1, X, List), + ( is_list(List) + -> true + ; throw('functor does not have command list as first argument:' + X) + ) ). -cmds_repr(Commands) :- - maplist(cmd_repr, Commands). - -debug_target(Name) :- - target(C, Name, builddir), - !, - write('Commands: '), - nl, - write(C), - nl, - cmds_repr(C). - %%%%%%%%%%%%%%%%%%%%%% % Gentoo stuff below % %%%%%%%%%%%%%%%%%%%%%%