diff --git a/makesure.awk b/makesure.awk index cb6540c..0ebf497 100755 --- a/makesure.awk +++ b/makesure.awk @@ -15,6 +15,7 @@ BEGIN { delete GoalParams # name,paramI -> param name delete CodePre # name -> pre-body (should also go before lib) delete Code # name -> body + delete Vars # k -> "val" delete DefineOverrides # k -> "" DefinesCode = "" delete Dependencies # name,i -> dep goal @@ -32,7 +33,7 @@ BEGIN { delete Lib # name -> code delete UseLibLineNo# name -> line no. delete GoalToLib # goal name -> lib name - delete Quotes # NF -> quote of field ("'"|"$"|"") + delete Quotes # NF -> quote of field ("'"|"$"|"u"|"\"") Mode = "prelude" # prelude|define|goal|goal_glob|lib srand() prepareArgs() @@ -123,7 +124,8 @@ function splitKV(arg, kv, n) { } function handleOptionDefineOverride(arg, kv) { splitKV(arg, kv) - handleDefineLine(kv[0] "=" quoteArg(kv[1])) + # handleDefineLine(kv[0] "=" quoteArg(kv[1])) + Vars[kv[0]] = kv[1] DefineOverrides[kv[0]] } @@ -142,8 +144,14 @@ function handleOptions( i) { function handleDefine() { started("define") - $1 = "" - handleDefineLine($0) + # $1 = "" + # handleDefineLine($0) + if (NF != 3) { + addError("@define NF != 3") # TODO better error msg + return + } + if (!($2 in DefineOverrides)) + Vars[$2] = $3 } function handleDefineLine(line, kv) { if (!checkValidDefineSyntax(line)) @@ -366,9 +374,12 @@ function checkBeforeRun( i,j,dep,depCnt,goalName) { } } -function getPreludeCode( a) { +function getPreludeCode( a,k) { addLine(a, MyDirScript) - addLine(a, DefinesCode) + # addLine(a, DefinesCode) + for (k in Vars) { + addLine(a, k "=" quoteArg(Vars[k]) ";export " k) + } return a[0] } @@ -850,7 +861,7 @@ function parseCli_2(line, vars, res, pos,c,c1,isDoll,q,var,inDef,defVal,val,w, if (inDef) { if ("}" == c) break - if ("\\" == c && ((c1 = substr(line,pos+1,1)) == "$" || c1 == "\\" || c1 == "}" || c1 == "\"")) { + if ("\\" == c && ((c1 = substr(line,pos + 1,1)) == "$" || c1 == "\\" || c1 == "}" || c1 == "\"")) { c = c1; pos++ } defVal = defVal c @@ -868,7 +879,7 @@ function parseCli_2(line, vars, res, pos,c,c1,isDoll,q,var,inDef,defVal,val,w, } w = w c } - res[i=+res[-7]++,"quote"] = isDoll ? "$" : q + res[i = +res[-7]++,"quote"] = isDoll ? "$" : q res[i] = w if ((c = substr(line,++pos,1)) != "" && c != " " && c != "\t") return "joined arguments" @@ -880,14 +891,14 @@ function parseCli_2(line, vars, res, pos,c,c1,isDoll,q,var,inDef,defVal,val,w, } if (w !~ /^[_A-Za-z0-9@.]+$/) return "wrong unquoted: '" w "'" - res[i=+res[-7]++,"quote"] = "u" + res[i = +res[-7]++,"quote"] = "u" res[i] = w } } } } -function reparseCli( todo,res,i,err) { - err = parseCli_2($0, todo, res) +function reparseCli( res,i,err) { + err = parseCli_2($0, Vars, res) if (err) { addError("Syntax error: " err) die(Error) diff --git a/tests/10_define.sh b/tests/10_define.sh index ec13277..66c205b 100644 --- a/tests/10_define.sh +++ b/tests/10_define.sh @@ -1,8 +1,8 @@ -@define A=aaa -@define B="${A}bbb" -@define Commented=value # just a comment +@define A aaa +@define B "${A}bbb" +@define Commented value # just a comment @goal testA echo A=$A diff --git a/tests/10_define_in_goal.sh b/tests/10_define_in_goal.sh index be04cf1..5a0275b 100644 --- a/tests/10_define_in_goal.sh +++ b/tests/10_define_in_goal.sh @@ -1,4 +1,4 @@ @goal default -@define A=1 +@define A 1 echo "$0" diff --git a/tests/4_trace.sh b/tests/4_trace.sh index 5c0f356..fdd6694 100644 --- a/tests/4_trace.sh +++ b/tests/4_trace.sh @@ -1,4 +1,4 @@ -@define A=aaa +@define A aaa @goal default @reached_if [[ 1 -eq 2 ]] diff --git a/tests/4_trace_shell_sh.sh b/tests/4_trace_shell_sh.sh index 7e8835f..840f0db 100644 --- a/tests/4_trace_shell_sh.sh +++ b/tests/4_trace_shell_sh.sh @@ -1,6 +1,6 @@ @shell sh -@define A=aaa +@define A aaa @goal default @reached_if [ 1 -eq 2 ] diff --git a/tests/9_prelude.sh b/tests/9_prelude.sh index 60cd1ce..77aabc4 100644 --- a/tests/9_prelude.sh +++ b/tests/9_prelude.sh @@ -5,7 +5,7 @@ # comment with whitespaces before it @shell bash -@define A=B +@define A B @goal a @depends_on b diff --git a/tests/9_prelude_define_wrong2.sh b/tests/9_prelude_define_wrong2.sh index bc5b97b..76369dc 100644 --- a/tests/9_prelude_define_wrong2.sh +++ b/tests/9_prelude_define_wrong2.sh @@ -1,5 +1,5 @@ -@define A=aaa echo 'Hello' +@define A aaa echo 'Hello' @goal default echo "$0"