Commits

juster  committed 1c73dd4

Change style of expvars to K&R.

  • Participants
  • Parent commits 0d9a346

Comments (0)

Files changed (1)

File vars/expvars

 #!/usr/bin/awk -f
 
 BEGIN {
-	OFS=FS="\n"
-	RS=""
-	ORS="\n\n"
-	PROG = "expvars"
+	OFS = FS = "\n"; RS = ""; ORS = "\n\n"; PROG = "expvars"
 }
 
 {
-	for (i=2; i<=NF; i++) $i = expand($i)
+	for(i=2; i<=NF; i++) $i = expand($i)
 	PBVARS[$1] = $2 # TODO: expanding ${arrays[@]}?
 	print
 }
 function die (msg)
 {
 	printf "%s:%s:%d:%s %s\n", PROG, ENVIRON["PBPATH"], FNR, $1, \
-	  msg | "cat 1>&2"
+		msg | "cat 1>&2"
 	exit 1
 }
 
 	while(j <= length(line)){
 		ch = substr(line, j, 1)
 
-		if (ch ~ /[ \t]/ && top == 0) die("Spaces must be quoted.")
+		if(ch ~ /[ \t]/ && top == 0) die("Spaces must be quoted.")
 
-		if (ch == "\\" || esc) {
+		if(ch == "\\" || esc){
 			if(!esc && toks[top] !~ /[`\)]/){
 				# Don't remove backslashes inside command expansions
 				line = splice(line, "", j, j)
 				j++
 			}
 			esc = !esc
-		}
-		# Single quotes are simple characters when inside double-quotes.
-		# Closing single quotes cannot be escaped so just find the next one.
-		else if (ch == "'" && toks[top] !~ /["`\)]/) {
+		}else if(ch == "'" && toks[top] !~ /["`\)]/){
+			# Single quotes are simple characters when inside double-quotes.
+			# Closing single quotes cannot be escaped so just find the next one.
 			start = j
 			stop = 0
 			for (j++; j <= length(line); j++) {
 
 			x = substr(line, start+1, stop-start-1)
 			line = splice(line, x, start, stop)
-		}
-		else if (ch == toks[top]) {
+		}else if(ch == toks[top]){
 			# The end of a quote was found, now expand it.
 			start = idxs[top]
 			x = expq(substr(line, start, j-start+1), ch)
 			line = splice(line, x, start, j)
 			top--
-		}
-		else if (ch ~ /[`"]/) {
+		}else if(ch ~ /[`"]/){
 			toks[++top] = ch
 			idxs[top] = j++
-		}
-		else if (ch == "$") {
+		}else if(ch == "$"){
 			nc = substr(line, j+1, 1)
-			if (nc ~ /[{(]/) {
+			if(nc ~ /[{(]/){
 				toks[++top] = (nc == "{" ? "}" : ")")
 				idxs[top] = j++
-			}
-			else {
+			}else{
 				# Expand a simple parameter.
 				val = expparam(substr(line, j + 1))
 				line = splice(line, val, j, j + RLENGTH)
 			}
-		}
-		else j++
+		}else j++
 	}
 
 	if(top){
 # Splice one string into another, replacing a chunk of it.
 # Params: Spliced string, Splicing str, Start of replaced, End of replaced.
 # Returns the result and adjusts j which is a var in expand.
-function splice(str, xstr, beg, end)
+function splice (str, xstr, beg, end)
 {
 	str = substr(str, 1, beg-1) xstr substr(str, end+1)
 	j = beg + length(xstr)
 	if(qch == "`" || qch == ")"){
 		x = (qch == ")" ? 3 : 2)
 		cmd = substr(qstr, x, length(qstr)-x)
-		if (cmd ~ /\|/ || cmd != "uname -m") {
+		if(cmd ~ /\|/ || cmd != "uname -m"){
 			die("Cowardly refusing to execute $(" cmd ")")
 		}
 		"uname -m" | getline arch