aboutsummaryrefslogtreecommitdiff
path: root/dist/isum.awk
blob: 7f7745614254530d9472e535a9a7b12039b6bde6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Summarize the installation log, printing errors along with
# enough context to make sense of them.

BEGIN {
#	print verbose 
	cd = ""
	out = "/dev/stdout"
	statuslen = 0
	debug = 0
	updates = "/dev/stderr"
}

function myflush(f)
{
	# fflush is not available on sun, but system("") appears to work everywhere
	system("")
}

function clearstatus(noflush, i)
{
	if(!updates)
		return
	for(i=0; i<statuslen; i++)
		printf("\b \b") >updates
	statuslen = 0
	if(!noflush)
		myflush(updates)
}

function status(s)
{
	if(!updates)
		return
	clearstatus(1)
	printf("    %s ", s) >updates
	statuslen = length(s)+5
	myflush(updates)
}

debug!=0 { print "# " $0 }

/^$/ { next }

/^echo cd / { next }
/^\+\+ pwd/ { next }

/^\* /{
	clearstatus()
	if(debug) print "% mark"
	print >out
	myflush(out)
	if(copy){
		print >copy
		myflush(copy)
	}
	cmd = ""
	printtabs = 1	# print indented lines immediately following
	errors = 0
	next
}

/^	/ && printtabs!=0 {
	clearstatus()
	print >out
	myflush(out)
	if(copy){
		print >copy
		myflush(copy)
	}
	next
}

{ printtabs = 0 }

/^(9a|9c|9l|9ar|9?install|cat pdf|cp|rm|mv|mk|9 yacc|9 lex|9 rc|do|for i|if|mk|gcc|cpp|cp|sh|cmp|rc|\.\/o)($|[^:])/ {
	if(debug) print "% start"
	errors = 0
	cmd = ""
	if(!verbose)
		cmd = cmd cd
	cmd = cmd $0 "\n"
	next
}

/^cd .+; mk .+/ && !verbose {
	dir = $2
	sub(/;$/, "", dir)
	status(dir " mk " $4)
}

/^cd / {
	if(debug) print "% cd"
	errors = 0
	if(verbose){
		print >out
		myflush(out)
		if(copy){
			print >copy
			myflush(copy)
		}
	}
	cd = $0 "\n"
	cmd = ""
	next
}

{
	cmd = cmd $0 "\n"
}

errors != 0 {
	clearstatus()
	if(debug) print "% errors"
	printf "%s", cmd >out
	myflush(out)
	if(copy){
		printf "%s", cmd >copy
		myflush(copy)
	}
	cmd = ""
	next
}

/^(	|then|else|fi|done|[ar] - [^ ]*\.o$)/ {
	next
}

/^(conflicts:)/ {
	if(debug) print "% skip1"
	next
}

/(up to date|nothing to see|assuming it will be|loop not entered)/ {
	next
}

/(nodes\(%e\)|packed transitions)/ {
	if(debug) print "% skip2"
	next
}

{ 
	# unexpected line 
	clearstatus()
	if(debug) print "% errors1"
	errors = 1
	printf ">>> %s", cmd >out
	myflush(out)
	if(copy){
		printf ">>> %s", cmd >copy
		myflush(copy)
	}
	cmd = ""
}