summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-10-01 16:30:05 -0700
committerAndrea Canciani <ranma42@gmail.com>2012-07-13 17:15:38 +0200
commit4ef59230222be54b3e3051cefc66cf0a8014e24d (patch)
treeaec9423df4a40416b58c6c09970f7caa35926b8f
parentc6642d2b941e52217ec08928d2e06a864b939c11 (diff)
Tools to check the consistency of the implementations
The index.html page accepts an argument which is the target header. The headers in the DIFFTABLE section of that header are compared and the results are shown in the browser.
-rw-r--r--difftable.css18
-rw-r--r--difftable.js161
-rw-r--r--index.html18
3 files changed, 197 insertions, 0 deletions
diff --git a/difftable.css b/difftable.css
new file mode 100644
index 0000000..ebeb72b
--- /dev/null
+++ b/difftable.css
@@ -0,0 +1,18 @@
+table.difftable {
+ border-collapse: collapse;
+}
+
+.diff {
+ background-color: #fcc;
+ margin: 0;
+}
+
+.equal {
+ background-color: #fff;
+ margin: 0;
+}
+
+.empty {
+ background-color: #ccc;
+ margin: 0;
+}
diff --git a/difftable.js b/difftable.js
new file mode 100644
index 0000000..1647d5f
--- /dev/null
+++ b/difftable.js
@@ -0,0 +1,161 @@
+function lcs(a,b){
+ var l = new Array();
+ for(var i = -1; i < a.length; i++)
+ l[i] = new Array();
+
+ for(var i = -1; i < a.length; i++)
+ l[i][-1] = 0;
+ for(var j = -1; j < b.length; j++)
+ l[-1][j] = 0;
+
+ for(var i = 0; i < a.length; i++)
+ for(var j = 0; j < b.length; j++)
+ if (a[i] == b[j])
+ l[i][j] = l[i-1][j-1] + 1;
+ else
+ l[i][j] = Math.max(l[i-1][j], l[i][j-1]);
+
+ var r = [];
+ var i = a.length, j = b.length;
+ while (i > 0 && j > 0) {
+ i--;
+ j--;
+ if (a[i] == b[j])
+ r.unshift(a[i]);
+ else if (l[i][j-1] > l[i-1][j])
+ i++;
+ else
+ j++;
+ }
+
+ return r;
+}
+
+function parseFile(fileName, parser) {
+ var req = new XMLHttpRequest();
+ req.onreadystatechange = function() {
+ if(req.readyState == 4)
+ parser(req.responseText);
+ }
+
+ req.open("GET", fileName);
+ req.send(null);
+}
+
+function getFile(fileName) {
+ var req = new XMLHttpRequest();
+ req.open("GET", fileName, false);
+ req.send(null);
+ return req.responseText;
+}
+
+function parsePublic(target) {
+ var mainLines = getFile(target).split('/* DIFFTABLE */')[1].split('\n');
+
+ var fileNames = new Array();
+
+ var privateFilesRE = new RegExp('#include "simpleops/(.*\.h)"');
+ for(var i = 0; i < mainLines.length; i++)
+ if(privateFilesRE.test(mainLines[i]))
+ fileNames.push(privateFilesRE.exec(mainLines[i])[1]);
+
+ return fileNames;
+}
+
+function addRow(table, row) {
+ var tr = table.insertRow(-1);
+
+ for(var j = 0; j < row.length; j++) {
+ var cell = tr.insertCell(-1);
+ cell.setAttribute("class", row[j].getAttribute("class"));
+ cell.appendChild(row[j]);
+ }
+}
+
+function createPre(x, cls) {
+ var node = document.createElement('pre');
+ node.setAttribute("class", cls);
+ node.appendChild(document.createTextNode(x));
+ return node;
+}
+
+function diffNode(x) {
+ return createPre(x, "diff");
+}
+
+function emptyNode() {
+ return createPre("", "empty");
+}
+
+function equalNode(x) {
+ return createPre(x, "equal");
+}
+
+function multidiff(diffTable, target) {
+ var sourceNames = parsePublic(target);
+
+ var sourceLines = new Array();
+ var idx = new Array();
+ var ref;
+ for(var i = 0; i < sourceNames.length; i++) {
+ var data = getFile(sourceNames[i]);
+ var lines = data.split('\n');
+ sourceLines.push(lines);
+ idx.push(0);
+
+ if(i == 0)
+ ref = lines;
+ else
+ ref = lcs(ref, lines);
+ }
+
+ for(var refidx = 0; refidx < ref.length; refidx++) {
+ while (true) {
+ var matching = true;
+ var line = new Array();
+
+ for(var j = 0; j < sourceLines.length; j++)
+ if (ref[refidx] != sourceLines[j][idx[j]]) {
+ matching = false;
+ line.push(diffNode(sourceLines[j][idx[j]++]));
+ } else {
+ line.push(emptyNode());
+ }
+
+ if (matching)
+ break;
+ else
+ addRow(diffTable, line);
+ }
+
+ var line = new Array();
+ for(var j = 0; j < sourceLines.length; j++)
+ line.push(equalNode(sourceLines[j][idx[j]++]));
+ addRow(diffTable, line);
+ }
+
+ while (true) {
+ var complete = true;
+ var line = new Array();
+
+ for(var j = 0; j < sourceLines.length; j++)
+ if (idx[j] < sourceLines[j].length) {
+ complete = false;
+ line.push(diffNode(sourceLines[j][idx[j]++]));
+ } else {
+ line.push(emptyNode());
+ }
+
+ if (complete)
+ break;
+ else
+ addRow(diffTable, line);
+ }
+
+ var tr = diffTable.createTHead().insertRow(0);
+ for(var j = 0; j < sourceNames.length; j++) {
+ var td = tr.insertCell(j);
+ var text = document.createTextNode(sourceNames[j]);
+ td.appendChild(text);
+ }
+}
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..a0ddf03
--- /dev/null
+++ b/index.html
@@ -0,0 +1,18 @@
+<html><head>
+<title>Simpleops Backend Comparison</title>
+<script language="JavaScript" src="difftable.js"></script>
+<link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" type="text/css" href="difftable.css" media="all" />
+<script langauge="Javascript">
+function initPage() {
+ if (window.location.search[0] != '?')
+ alert("USAGE: ...?target");
+ else
+ multidiff(document.getElementById('diffTable'),
+ window.location.search.slice(1));
+}
+</script>
+</head>
+<body onload="initPage()">
+<table id="diffTable" class="difftable"></table>
+</body>
+</html>