Skip to content

Commit a5793b2

Browse files
committed
Spacing & bracing updates per second edition of TAPL
1 parent 7bb6a6d commit a5793b2

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

awkmake.awk

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,52 @@
11
BEGIN {
2-
while (getline <"makefile" > 0)
2+
while (getline <"makefile" > 0) {
33
if ($0 ~ /^[A-Za-z]/) { # $1: $2 $3 ...
44
sub(/:/, "")
55
if (++names[nm = $1] > 1)
66
error(nm " is multiply defined")
77
for (i = 2; i <= NF; i++) # remember targets
88
slist[nm, ++scnt[nm]] = $i
9-
} else if ($0 ~ /^\t/) # remember cmd for
9+
} else if ($0 ~ /^\t/) { # remember cmd for
1010
cmd[nm] = cmd[nm] $0 "\n" # current name
11-
else if (NF > 0)
11+
} else if (NF > 0) {
1212
error("illegal line in makefile: " $0)
13+
}
14+
}
15+
1316
ages() # compute initial ages
17+
1418
if (ARGV[1] in names) {
1519
if (update(ARGV[1]) == 0)
1620
print ARGV[1] " is up to date"
17-
} else
21+
} else {
1822
error(ARGV[1] " is not in makefile")
23+
}
1924
}
2025

2126
function ages( f,n,t) {
2227
for (t = 1; ("ls -t" | getline f) > 0; t++)
23-
age[f] = t # all existing files get an age
28+
age[f] = t # all existing files get an age
2429
close("ls -t")
30+
2531
for (n in names)
2632
if (!(n in age)) # if n has not been created
2733
age[n] = 9999 # make n really old
2834
}
35+
2936
function update(n, changed,i,s) {
30-
if (!(n in age)) error(n " does not exist")
31-
if (!(n in names)) return 0
37+
if (!(n in age))
38+
error(n " does not exist")
39+
if (!(n in names))
40+
return 0
3241
changed = 0
3342
visited[n] = 1
3443
for (i = 1; i <= scnt[n]; i++) {
35-
if (visited[s = slist[n, i]] == 0) update(s)
44+
if (visited[s = slist[n, i]] == 0)
45+
update(s)
3646
else if (visited[s] == 1)
3747
error(s " and " n " are circularly defined")
38-
if (age[s] <= age[n]) changed++
48+
if (age[s] <= age[n])
49+
changed++
3950
}
4051
visited[n] = 2
4152
if (changed || scnt[n] == 0) {
@@ -47,4 +58,5 @@ function update(n, changed,i,s) {
4758
}
4859
return 0
4960
}
61+
5062
function error(s) { print "error: " s; exit }

0 commit comments

Comments
 (0)