=== modified file 'shell.pl' --- shell.pl 2012-05-19 09:32:20 +0000 +++ shell.pl 2012-05-17 22:58:49 +0000 @@ -1,9 +1,5 @@ % vim: ft=prolog textwidth=80 tabstop=4 softtabstop=4 shiftwidth=4 expandtab -%%%%%%%%%%%%%%%%%%%%%%%%% -% Shell code generation % -%%%%%%%%%%%%%%%%%%%%%%%%% - :- module(shell, [ op(600,xfy,($:-)), % op(800,fx,(#)), @@ -19,23 +15,14 @@ :- use_module(generic). :- use_module(escape). -% check for (incomplete) list containing character codes -assert_string(""). -assert_string(Var) :- var(Var). -assert_string([Code|Rest]) :- - integer(Code), - assert_string(Rest). - -assert_dcg_string(L1, L2) :- - assertion(assert_string(L1)), - assertion(assert_string(L2)). +%%%%%%%%%%%%%%%%%%%%%%%%% +% Shell code generation % +%%%%%%%%%%%%%%%%%%%%%%%%% escape(In, Out) :- escape(sh, In, Out). escape_dcg(In) --> - assert_dcg_string, { escape(In, Out) }, - assert_dcg_string, prepend(Out). escape_dcglist(List) --> @@ -50,10 +37,8 @@ runnable(chroot(_,_)). cmd_escape_runnable([Arg]) --> - assert_dcg_string, escape_dcg(Arg). cmd_escape_runnable([Arg1,Arg2|Rest]) --> - assert_dcg_string, escape_dcg(Arg1), prepend(" "), cmd_escape_runnable([Arg2|Rest]). @@ -70,33 +55,28 @@ cmd_escape_runnable(Runnable), prepend(" )"). -check_returncode --> assert_dcg_string, prepend(" || exit $?\n"). +check_returncode --> prepend(" || exit $?\n"). cmd_tokens(verbatim(Verbatim)) --> - assert_dcg_string, str_dcg(Verbatim). cmd_tokens(Runnable) --> - assert_dcg_string, cmd_escape_runnable(Runnable), check_returncode. cmd_tokens(Runnable >> File) --> - assert_dcg_string, cmd_escape_runnable(Runnable), prepend(" >>"), escape_dcg(File), check_returncode. cmd_tokens(Runnable > File) --> - assert_dcg_string, cmd_escape_runnable(Runnable), prepend(" >"), escape_dcg(File), check_returncode. cmd_tokens(Variable = Value) --> - assert_dcg_string, str_dcg(Variable), prepend("="), ( { runnable(Value) } @@ -121,7 +101,6 @@ check_returncode. cmd_tokens(Variable = array(Runnable)) --> - assert_dcg_string, str_dcg(Variable), prepend("=( $("), cmd_escape_runnable(Runnable), @@ -129,7 +108,6 @@ check_returncode. cmd_tokens(comment(Text)) --> - assert_dcg_string, prepend("\n# "), { str(Text, String) }, make_comment(String),