-
Notifications
You must be signed in to change notification settings - Fork 33
/
PatienceDiff.html
71 lines (57 loc) · 2.26 KB
/
PatienceDiff.html
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
<html>
<head>
<script src="PatienceDiff.js"></script>
<style>
div {
font-family: Courier;
font-size: 12;
}
textarea {
font-family: Courier;
font-size: 12;
}
</style>
</head>
<body onload="init()">
<script type="text/javascript">
var aLines = `/\/ Opening comment\n#include <stdio.h>\n\n/\/ Frobs foo heartily\nint frobnitz(int foo)\n{\n int i;\n for(i = 0; i < 10; i++)\n {\n printf("Your answer is: ");\n printf("%d\\n", foo);\n }\n}\n\nint fact(int n)\n{\n if(n > 1)\n {\n return fact(n-1) * n;\n }\n return 1;\n}\n\nint main(int argc, char **argv)\n{\n frobnitz(fact(10));\n}`;
var bLines = `#include <stdio.h>\n\nint fib(int n)\n{\n if(n > 2)\n {\n return fib(n-1) + fib(n-2);\n }\n return 1;\n}\n\n/\/ Frobs foo heartily\nint frobnitz(int foo)\n{\n int i;\n for(i = 0; i < 10; i++)\n {\n printf("%d\\n", foo);\n }\n}\n\nint main(int argc, char **argv)\n{\n frobnitz(fib(10));\n}\n/\/ Closing comment`;
function init() {
document.getElementById("aLines").value = aLines;
document.getElementById("bLines").value = bLines;
}
function calcDiff(diffVsPlus) {
var a = document.getElementById("aLines").value.split("\n");
var b = document.getElementById("bLines").value.split("\n");
if (diffVsPlus) {
var diff = patienceDiff(a , b);
} else {
var diff = patienceDiffPlus(a , b);
}
var diffLines = "";
diff.lines.forEach((o) => {
if (o.bIndex < 0 && o.moved) {
diffLines += "-m ";
} else if (o.moved) {
diffLines += "+m ";
} else if (o.aIndex < 0) {
diffLines += "+ ";
} else if (o.bIndex < 0) {
diffLines += "- ";
} else {
diffLines += " ";
}
diffLines += o.line + "\n";
});
document.getElementById("diff").value = diffLines;
}
</script>
<div>
<textarea id="aLines" style="width:25%; height:100%"></textarea>
<textarea id="bLines" style="width:25%; height:100%"></textarea>
<button type="button" onclick="calcDiff(true)" style="position:absolute; top:25%; left:55%">=> Diff =></button>
<button type="button" onclick="calcDiff(false)" style="position:absolute; top:35%; left:55%">=> DiffPlus =></button>
<textarea id="diff" style="float:right; width:33%; height:100%;"></textarea>
</div>
</body>
</html>