diff --git a/makesure_candidate b/makesure_candidate index 1ec703d..a89d057 100755 --- a/makesure_candidate +++ b/makesure_candidate @@ -96,7 +96,7 @@ function handleOptions(i){ addError("Provide at least one option") for(i=2;i<=NF;i++){ if(!($i in SupportedOptions)) - addError("Option '\''" $i "'\'' is not supported") + addError("Option '\''" $i"'\'' is not supported") Options[$i]}} function handleDefine(){ started("define") @@ -104,22 +104,22 @@ function handleDefine(){ addError("Invalid @define syntax, should be @define VAR_NAME '\''value'\''") return} if($2 !~ /^[A-Za-z_][A-Za-z0-9_]*$/){ - addError("Wrong variable name: '\''" $2 "'\''") + addError("Wrong variable name: '\''" $2"'\''") return} if(!($2 in DefineOverrides)) Vars[$2]=$3} function handleShell(){ checkPreludeOnly() if(!((Shell=$2)in SupportedShells)) - addError("Shell '\''" Shell "'\'' is not supported")} + addError("Shell '\''" Shell"'\'' is not supported")} function timingOn(){ - return "timing"in Options&&!("silent"in Options)} + return"timing"in Options&&!("silent"in Options)} function started(mode){ Mode=mode} function handleLib(libName){ started("lib") if((libName=$2)in Lib){ - addError("Lib '\''" libName "'\'' is already defined")} + addError("Lib '\''" libName"'\'' is already defined")} arrPush(LibNames,libName) Lib[libName]} function handleUseLib(i){ @@ -143,7 +143,7 @@ function handleGoal(i,goalName){ GoalParams[goalName,GoalParamsCnt[goalName]++]=validateParamName($i) }else if(NF>2)addError("nothing allowed after goal name")} function validateParamName(p){ - if(p !~ /^[A-Z_][A-Z0-9_]*$/)addError("@param name should match /^[A-Z_][A-Z0-9_]*$/: '\''" p "'\''") + if(p !~ /^[A-Z_][A-Z0-9_]*$/)addError("@param name should match /^[A-Z_][A-Z0-9_]*$/: '\''" p"'\''") return p} function registerGoal(priv,goalName){ if(""==goalName||"@params"==goalName) @@ -154,14 +154,14 @@ function registerGoal(priv,goalName){ arrPush(GoalNames,goalName) GoalsByName[goalName]=priv return 1}} -function globGoal(i){return (GlobGoalName?GlobGoalName "@":"")GlobFiles[i]} +function globGoal(i){return (GlobGoalName?GlobGoalName"@":"")GlobFiles[i]} function calcGlob(goalName,pattern,script,file){ GlobCnt=0 GlobGoalName=goalName delete GlobFiles - script=MyDirScript ";for f in " pattern ";do test -e \"$f\"&&echo \"$f\"||:;done" + script=MyDirScript";for f in " pattern";do test -e \"$f\"&&echo \"$f\"||:;done" if("sh"!=Shell) - script=Shell " -c " quoteArg(script) + script=Shell" -c " quoteArg(script) while((script|getline file)>0){ GlobCnt++ arrPush(GlobFiles,file)} @@ -204,7 +204,7 @@ function handleDoc(i){ registerDoc(globGoal(i))}} function registerDoc(goalName){ if(goalName in Doc) - addError("Multiple " $1 " not allowed for a goal") + addError("Multiple " $1" not allowed for a goal") $1="" Doc[goalName]=trim($0)} function handleDependsOn(i){ @@ -241,10 +241,10 @@ function handleReachedIf(i){ for(i=0;i " loop[2])} -function isCodeAllowed(){return "goal"==Mode||"goal_glob"==Mode||"lib"==Mode} -function isPrelude(){return "prelude"==Mode} -function checkPreludeOnly(){if(!isPrelude())addError("Only use " $1 " in prelude")} -function checkGoalOnly(){if("goal"!=Mode&&"goal_glob"!=Mode)addError("Only use " $1 " in @goal")} +function isCodeAllowed(){return"goal"==Mode||"goal_glob"==Mode||"lib"==Mode} +function isPrelude(){return"prelude"==Mode} +function checkPreludeOnly(){if(!isPrelude())addError("Only use " $1" in prelude")} +function checkGoalOnly(){if("goal"!=Mode&&"goal_glob"!=Mode)addError("Only use " $1" in @goal")} function currentGoalName(){return arrLast(GoalNames)} function currentLibName(){return arrLast(LibNames)} function realExit(code){ exit code} -function addError(err,n){if(!n)n=NR;Error=addL(Error,err ":\n" ARGV[1]":" n ": " Lines[n])} +function addError(err,n){if(!n)n=NR;Error=addL(Error,err":\n" ARGV[1]":" n": " Lines[n])} function addErrorDedup(err,n){if((err,n)in AddedErrors)return;AddedErrors[err,n];addError(err,n)} function die(msg,out){ out="cat 1>&2" @@ -364,15 +364,15 @@ function die(msg,out){ function checkConditionReached(goalName,conditionStr,script){ script=getPreludeCode() if(goalName in GoalToLib) - script=script "\n" Lib[GoalToLib[goalName]] - script=script "\n" conditionStr - return shellExec(script,goalName "@reached_if")==0} + script=script"\n" Lib[GoalToLib[goalName]] + script=script"\n" conditionStr + return shellExec(script,goalName"@reached_if")==0} function shellExec(script,comment,res){ if("tracing"in Options){ script=": " quoteArg(comment)"\n" script - script=Shell " -x -e -c " quoteArg(script) + script=Shell" -x -e -c " quoteArg(script) }else - script=Shell " -e -c " quoteArg(script) + script=Shell" -e -c " quoteArg(script) script="trap '\''exit 7'\'' INT;" script res=system(script) return res} @@ -443,15 +443,15 @@ function instantiate(goal,args,newArgs,i,j,depArg,depArgType,dep,goalNameInstant copyKey(goal,goalNameInstantiated,ReachedIf) copyKey(goal,goalNameInstantiated,GoalToLib) for(i in args) - argsCode=addL(argsCode,i "=" quoteArg(args[i])) + argsCode=addL(argsCode,i"=" quoteArg(args[i])) CodePre[goalNameInstantiated]=addL(CodePre[goalNameInstantiated],argsCode) if(goalNameInstantiated in ReachedIf) - ReachedIf[goalNameInstantiated]=argsCode "\n" ReachedIf[goalNameInstantiated]} + ReachedIf[goalNameInstantiated]=argsCode"\n" ReachedIf[goalNameInstantiated]} for(i=0;i " newVer - }else print"you have latest version " Version " installed"} + else print"updated " Version" -> " newVer + }else print"you have latest version " Version" installed"} rm(tmp) if(err)die(err)} function renderDuration(deltaMillis,\ @@ -508,17 +508,17 @@ function renderDuration(deltaMillis,\ if(deltaHr>=24){ deltaDay=int(deltaHr/24) deltaHr=deltaHr-deltaDay*24} - dayS=deltaDay>0?deltaDay " d":"" - hrS=deltaHr>0?deltaHr " h":"" - minS=deltaMin>0?deltaMin " m":"" - secS=deltaSec>0?deltaSec " s":"" + dayS=deltaDay>0?deltaDay" d":"" + hrS=deltaHr>0?deltaHr" h":"" + minS=deltaMin>0?deltaMin" m":"" + secS=deltaSec>0?deltaSec" s":"" secSI=deltaSec>0?int(deltaSec)" s":"" if(dayS!="") - res=dayS " " (hrS==""?"0 h":hrS) + res=dayS" " (hrS==""?"0 h":hrS) else if(deltaHr>0) - res=hrS " " (minS==""?"0 m":minS) + res=hrS" " (minS==""?"0 m":minS) else if(deltaMin>0) - res=minS " " (secSI==""?"0 s":secSI) + res=minS" " (secSI==""?"0 s":secSI) else res=deltaSec>0?secS:"0 s" return res} @@ -531,11 +531,11 @@ function dl(url,dest,verbose){ verbose="VERBOSE"in ENVIRON if(commandExists("wget")){ if(!ok("wget " (verbose?"":"-q")" " quoteArg(url)" -O" quoteArg(dest))) - return "error with wget" + return"error with wget" }else if(commandExists("curl")){ if(!ok("curl " (verbose?"":"-s")" " quoteArg(url)" -o " quoteArg(dest))) - return "error with curl" - }else return "wget/curl not found"} + return"error with curl" + }else return"wget/curl not found"} function natOrder(s1,s2,i1,i2,c1,c2,n1,n2){ if(_digit(c1=substr(s1,i1,1))&&_digit(c2=substr(s2,i2,1))){ n1=+c1;while(_digit(c1=substr(s1,++i1,1))){n1=n1*10+c1} @@ -574,7 +574,7 @@ function parseCli_2(line,vars,res,pos,c,c1,isDoll,q,var,inDef,defVal,val,w,i){ w="" while((c=substr(line,++pos,1))!=q){ if(c=="") - return "unterminated argument" + return"unterminated argument" else if(c=="\\"&&((c1=substr(line,pos+1,1))=="'\''"&&isDoll||c1==c||q=="\""&&(c1==q||c1=="$"))){ c=c1;pos++ }else if(c=="$"&&q=="\""){ @@ -584,7 +584,7 @@ function parseCli_2(line,vars,res,pos,c,c1,isDoll,q,var,inDef,defVal,val,w,i){ if((c1=substr(line,pos+1,1))=="{"){ for(pos++;(c=substr(line,++pos,1))!="}";){ if(c=="") - return "unterminated argument" + return"unterminated argument" if(!inDef&&":"==c&&"-"==substr(line,pos+1,1)){ inDef=1 c=substr(line,pos += 2,1)} @@ -600,20 +600,20 @@ function parseCli_2(line,vars,res,pos,c,c1,isDoll,q,var,inDef,defVal,val,w,i){ for(;(c=substr(line,pos+1,1))~/[_A-Za-z0-9]/;pos++) var=var c if(var !~ /^[_A-Za-z][_A-Za-z0-9]*$/) - return "wrong var: '\''" var "'\''" + return"wrong var: '\''" var"'\''" w=(w)((val=var in vars?vars[var]:ENVIRON[var])!=""?val:defVal) continue} w=w c} res[i=+res[-7]++,"quote"]=isDoll?"$":q res[i]=w if((c=substr(line,++pos,1))!=""&&c!=" "&&c!="\t") - return "joined arguments" + return"joined arguments" }else { w=c while((c=substr(line,++pos,1))!=""&&c!=" "&&c!="\t"){ w=w c} if(w !~ /^[_A-Za-z0-9@.]+$/) - return "wrong unquoted: '\''" w "'\''" + return"wrong unquoted: '\''" w"'\''" res[i=+res[-7]++,"quote"]="u" res[i]=w}}}} function reparseCli(res,i,err){ @@ -634,11 +634,11 @@ function quote2(s,force){ if(index(s,"'\''")){ gsub(/\\/,"\\\\",s) gsub(/'\''/,"\\'\''",s) - return "$'\''" s "'\''" + return"$'\''" s"'\''" }else - return force||s~/[^a-zA-Z0-9.,@_\/=+-]/?"'\''" s "'\''":s} + return force||s~/[^a-zA-Z0-9.,@_\/=+-]/?"'\''" s"'\''":s} function addLine(target,line){target[0]=addL(target[0],line)} -function addL(s,l){return s?s "\n" l:l} +function addL(s,l){return s?s"\n" l:l} function arrPush(arr,elt){arr[arr[-7]++]=elt} function arrLen(arr){return +arr[-7]} function arrDel(arr,v,l,i,e,resArr){ @@ -650,10 +650,10 @@ function arrDel(arr,v,l,i,e,resArr){ for(i in resArr) arr[i]=resArr[i]} function arrLast(arr,l){return (l=arrLen(arr))>0?arr[l-1]:""} -function commandExists(cmd){return ok("command -v " cmd " >/dev/null")} +function commandExists(cmd){return ok("command -v " cmd" >/dev/null")} function ok(cmd){return system(cmd)==0} function isFile(path){return ok("test -f " quoteArg(path))} function rm(f){system("rm " quoteArg(f))} -function quoteArg(a){gsub("'\''","'\''\\'\'''\''",a);return "'\''" a "'\''"} +function quoteArg(a){gsub("'\''","'\''\\'\'''\''",a);return"'\''" a"'\''"} function trim(s){sub(/^[ \t\r\n]+/,"",s);sub(/[ \t\r\n]+$/,"",s);return s} function copyKey(keySrc,keyDst,arr){if(keySrc in arr)arr[keyDst]=arr[keySrc]}' Makesurefile "$@" diff --git a/minify.awk b/minify.awk index be400d3..000daab 100644 --- a/minify.awk +++ b/minify.awk @@ -36,6 +36,7 @@ in_begin && $1 ~ /^delete/{ next } gsub(/printf +"/, "printf\"") if (!/^ +}/) gsub(/ +}/, "}") gsubKeepStrings("^ +in ", "in ") + gsubKeepStrings(" +$", "") gsub(Q, Q "\\" Q Q) if (l = trim($0)) { decreaseIndent(); printf "%s", (l == "}" ? l : (NR == 1 ? "" : "\n") $0) } } @@ -49,8 +50,7 @@ function gsubKeepStrings(regex, replacement, nonString,s,isString,i,c) { isString = 0 for (i=1;(c=substr($0,i,1))!="";i++) { # print "> " i " " c - if ("\"" == c) { - # TODO escaped " + if ("\"" == c && (substr($0,i-1,1) != "\\" || substr($0,i-2,1) == "\\")) { if (!isString) { gsub(regex, replacement, nonString) s = s nonString @@ -69,4 +69,5 @@ function gsubKeepStrings(regex, replacement, nonString,s,isString,i,c) { $0 = s } #BEGIN { $0 = "aaa\"aaa\"bbbaaa"; gsubKeepStrings("aaa","AAA"); print } -#BEGIN { $0 = "if (\"-h\" in Args || \"--help\" in Args) {"; gsubKeepStrings("^ +in", "in"); print } \ No newline at end of file +#BEGIN { $0 = "aaa\"aaa\\\"aaa\"bbbaaa"; gsubKeepStrings("aaa","AAA"); print } +#BEGIN { $0 = "if (\"-h\" in Args || \"--help\" in Args) {"; gsubKeepStrings("^ +in", "in"); print }