-
Notifications
You must be signed in to change notification settings - Fork 4
/
view-xdcc.awk
executable file
·133 lines (131 loc) · 2.58 KB
/
view-xdcc.awk
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
#!/usr/bin/awk -f
BEGIN {
TMP="/tmp/view.sizes"
SAVED_FS = FS
FS = ":"
CONTROL="size.data"
while ( ( res = getline < CONTROL ) > 0 ) {
SIZE_CACHE[ $1 ] = $2
}
close( CONTROL )
FS = SAVED_FS
}
function makesize( VAL ) {
NBYTES = 0 + VAL
if ( NBYTES < 1000 ) {
return sprintf( "%3db", NBYTES )
}
NBYTES = ( NBYTES + 512 ) / 1024
if ( NBYTES < 1000 ) {
return sprintf( "%3dk", NBYTES )
}
NBYTES = ( NBYTES + 512 ) / 1024
if ( DEBUG != "" ) {
return sprintf( "% dM", NBYTES )
}
if ( NBYTES < 1000 ) {
return sprintf( "%3dM", NBYTES )
}
if ( NBYTES < 10000 ) {
return sprintf( "%3.1fG", NBYTES / 1024 )
}
NBYTES = ( NBYTES + 512 ) / 1024
if ( NBYTES < 1000 ) {
return sprintf( "%3dG", NBYTES )
}
NBYTES = ( NBYTES + 512 ) / 1024
if ( NBYTES < 1000 ) {
return sprintf( "%3dT", NBYTES )
}
return sprintf( "%3dE", NBYTES )
}
function ausgabe() {
PACK ++
ALL_PACK ++
printf( "%3s %3dx [%4s] %s\n", \
"#" PACK, XG, SIZE, XD )
}
function ausgabetotal() {
SUM_SIZE = makesize( SUM_BYTES )
TRANSFER_SIZE = makesize( TRANSFER_BYTES )
PARTIAL_BYTES = TRANSFER_BYTES - SUM_XG_BYTES
if ( PARTIAL_BYTES >= 0 )
PARTIAL_SIZE = makesize( PARTIAL_BYTES )
else
PARTIAL_SIZE = "-" makesize( 0 - PARTIAL_BYTES )
TOTAL = sprintf( "total in files, [%4s] total downloaded, [%4s] partial", TRANSFER_SIZE, PARTIAL_SIZE )
printf( "%3s %3dx [%4s] %s\n", \
"#" PACK, SUM_XG, SUM_SIZE, TOTAL )
}
END {
ausgabe()
ausgabetotal()
if ( SUM_BYTES != ALL_BYTES ) {
print ""
PACK = ALL_PACK
SUM_XG = ALL_XG
SUM_BYTES = ALL_BYTES
SUM_XG_BYTES = ALL_XG_BYTES
TRANSFER_BYTES = ALL_TRANSFER_BYTES
ausgabetotal()
}
}
/Do Not Edit This File/ {
# Do Not Edit This File: 50.08 50.43 15173264677 1638743
if ( LAST_KEY != "" ) {
ausgabe()
if ( LAST_KEY != "-" ) {
ausgabetotal()
SUM_BYTES = 0
SUM_XG = 0
SUM_XG_BYTES = 0
TRANSFER_BYTES = 0
}
XF = ""
print ""
}
TRANSFER_BYTES += $8
ALL_TRANSFER_BYTES += $8
LAST_KEY = $9
PACK = 0
SIZE = 0
if ( DEBUG != "" )
ausgabetotal()
next
}
/^$/ {
if ( XF == "" )
next
ausgabe()
if ( DEBUG != "" )
ausgabetotal()
}
/^xx_file/ {
XF = substr( $0, 9 )
if ( SIZE_CACHE[ XF ] > 0 ) {
BYTES = SIZE_CACHE[ XF ]
} else {
LINE = "eval `stat -s \"" XF "\"` ; echo $st_size > " TMP
system( LINE )
getline < TMP
close( TMP )
BYTES = 0 + $1
}
SUM_BYTES += BYTES
ALL_BYTES += BYTES
SIZE = makesize( BYTES )
next
}
/^xx_desc/ {
XD = substr( $0, 9 )
next
}
/^xx_gets/ {
XG = 0 + substr( $0, 9 )
SUM_XG += XG
ALL_XG += XG
XG_BYTES = XG * BYTES
SUM_XG_BYTES += XG_BYTES
ALL_XG_BYTES += XG_BYTES
}
#