• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2018 syzkaller project authors. All rights reserved.
2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3
4function sortTable(item, colName, conv) {
5	table = item.parentNode.parentNode.parentNode;
6	rows = table.getElementsByTagName("tr");
7	col = findColumnByName(rows[0].getElementsByTagName("th"), colName);
8	values = new Array;
9	for (i = 1; i < rows.length; i++)
10		values[i] = conv(rows[i].getElementsByTagName("td")[col].textContent);
11	desc = isSorted(values);
12	do {
13		changed = false;
14		for (i = 1; i < values.length - 1; i++) {
15			v0 = values[i];
16			v1 = values[i + 1];
17			if (desc && v0 >= v1 || !desc && v0 <= v1)
18				continue;
19			changed = true;
20			values[i] = v1;
21			values[i + 1] = v0;
22			rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
23		}
24	} while (changed);
25	return false;
26}
27
28function findColumnByName(headers, colName) {
29	for (i = 0; i < headers.length; i++) {
30		if (headers[i].textContent == colName)
31			return i;
32	}
33	return 0;
34}
35
36function isSorted(values) {
37	for (i = 1; i < rows.length - 1; i++) {
38		if (values[i] > values[i + 1])
39			return false;
40	}
41	return true;
42}
43
44function textSort(v) { return v.toLowerCase(); }
45function numSort(v) { return -parseInt(v); }
46function reproSort(v) { return v == "C" ? 0 : v == "syz" ? 1 : 2; }
47function patchedSort(v) { return v == "" ? -1 : parseInt(v); }
48
49function timeSort(v) {
50	if (v == "now")
51		return 0;
52	m = v.indexOf('m');
53	h = v.indexOf('h');
54	d = v.indexOf('d');
55	if (m > 0 && h < 0)
56		return parseInt(v);
57	if (h > 0 && m > 0)
58		return parseInt(v) * 60 + parseInt(v.substring(h + 1));
59	if (d > 0 && h > 0)
60		return parseInt(v) * 60 * 24 + parseInt(v.substring(d + 1)) * 60;
61	if (d > 0)
62		return parseInt(v) * 60 * 24;
63	return 1000000000;
64}
65