Make setthetime() static per the prototype.
[dragonfly.git] / contrib / traceroute / median.awk
1 /^ *[0-9]/      {
2         # print out the median time to each hop along a route.
3         tottime = 0; n = 0;
4         for (f = 5; f <= NF; ++f) {
5                 if ($f == "ms") {
6                         ++n
7                         time[n] = $(f - 1)
8                 }
9         }
10         if (n > 0) {
11                 # insertion sort the times to find the median
12                 for (i = 2; i <= n; ++i) {
13                         v = time[i]; j = i - 1;
14                         while (time[j] > v) {
15                                 time[j+1] = time[j];
16                                 j = j - 1;
17                                 if (j < 0)
18                                         break;
19                         }
20                         time[j+1] = v;
21                 }
22                 if (n > 1 && (n % 2) == 0)
23                         median = (time[n/2] + time[(n/2) + 1]) / 2
24                 else
25                         median = time[(n+1)/2]
26
27                 print $1, median
28         }
29 }