From 824cd0873270912dce6bbb8c83562c21e0dd271c Mon Sep 17 00:00:00 2001 From: xonix Date: Mon, 22 Mar 2021 02:10:50 +0200 Subject: [PATCH] Propose a method to have parameterized goals #12 --- makesure.awk | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/makesure.awk b/makesure.awk index 3f352fd..06001f8 100755 --- a/makesure.awk +++ b/makesure.awk @@ -8,16 +8,18 @@ BEGIN { split("",Args) # parsed CLI args split("",ArgGoals) # invoked goals split("",Options) - split("",GoalNames) + split("",GoalNames) # list split("",GoalsByName) # name -> "" + split("",Code) # name -> body split("",DefineOverrides) # k -> v DefinesFile="" split("",Dependencies) # name,i -> dep goal split("",DependenciesCnt) # name -> dep cnd split("",Doc) # name,i -> doc str split("",DocCnt) # name -> doc lines cnt - split("",Code) # name -> body split("",ReachedIf) # name -> condition line + split("",ScriptNames) # list + split("",ScriptsByName) # name -> "" split("",Script) # script name -> body Mode = "prelude" # prelude/goal/script srand() @@ -150,9 +152,10 @@ function adjustOptions() { delete Options["timing"] } +function handlePreludeEnd() { if (isPrelude()) adjustOptions() } + function handleGoal( goal_name) { - if (isPrelude()) # 1st goal - adjustOptions() + handlePreludeEnd() Mode = "goal" @@ -167,6 +170,22 @@ function handleGoal( goal_name) { GoalsByName[goal_name] } +function handleScript( script_name) { + handlePreludeEnd() + + Mode = "script" + + script_name = trim($2) + if (length(script_name) == 0) { + die("Script must have a name") + } + if (script_name in ScriptsByName) { + die("Script " script_name " is already defined") + } + arrPush(ScriptNames, script_name) + ScriptsByName[script_name] +} + function handleDoc( goal_name) { checkGoalOnly() @@ -199,10 +218,6 @@ function handleReachedIf( goal_name) { ReachedIf[goal_name] = trim($0) } -function handleScript() { - Script[$1] -} - function handleCall() { }