/usr/share/devhelp/assistant/assistant.js is in devhelp-common 3.8.2-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | function strStrip(str)
{
return str.replace(/^\s*(.*?)\s*$/, "$1");
}
function strCompactWhitespace(str)
{
var length;
var i;
var ret;
var whitespace_count = 0;
str = str.replace(/\t/, " ");
ret = "";
length = str.length;
i = 0;
while (i < length) {
if (str[i] == " ") {
whitespace_count++;
} else {
if (whitespace_count > 0) {
ret += " ";
whitespace_count = 0;
}
ret += str[i];
}
i++;
}
return ret;
}
function getIndexOfParen(str)
{
var length = str.length;
for (var i = 0; i < length; i++) {
if (str[i] == "(")
return i;
}
return 0;
}
function getIndexOfLastWord(str)
{
for (var i = str.length; i >= 0; i--) {
if (str[i] == " ")
return i + 1;
}
return -1;
}
function getIndexOfLastWordIgnoreAsterisk(str)
{
for (var i = str.length; i >= 0; i--) {
if (str[i] == " " || str[i] == "*")
return i + 1;
}
return -1;
}
function buildPadding(length)
{
var str = "";
while (length > 0) {
str += " ";
length--;
}
return str;
}
function reformatSignature()
{
var elements = document.getElementsByClassName('programlisting');
listing = elements[0];
/* Fixup oddly formatted HTML, e.g libxml has <br> inside the pre
* element.
*/
tmp = listing.innerHTML;
tmp = tmp.replace("<br>", "\n").replace("\t", " ");
listing.innerHTML = tmp;
var input = listing.textContent;
var lines = input.split("\n");
var line;
var i;
i = 0;
while (line = lines[i]) {
lines[i] = strCompactWhitespace(strStrip(line));
i++;
}
var indexOfParen = getIndexOfParen(lines[1]);
var lastWordIndices = Array(lines.length);
var maxIndexOfLastWord = 0;
var maxDiff = 0;
i = 1;
while (line = lines[i]) {
lastWordIndices[i] = getIndexOfLastWordIgnoreAsterisk(line);
tmp = getIndexOfLastWord(line);
if (i > 1) {
lastWordIndices[i] += indexOfParen + 1;
tmp += indexOfParen + 1;
}
if (tmp > maxIndexOfLastWord)
maxIndexOfLastWord = tmp;
if (lastWordIndices[i] - tmp > maxDiff)
maxDiff = lastWordIndices[i] - tmp;
i++;
}
maxIndexOfLastWord += maxDiff;
// Now get the formatted text.
var formattedLines = listing.innerHTML.split("\n");
i = 0;
while (line = formattedLines[i]) {
formattedLines[i] = strCompactWhitespace(strStrip(line));
i++;
}
var formattedLastWordIndices = Array(formattedLines.length);
i = 1;
while (line = formattedLines[i]) {
formattedLastWordIndices[i] = getIndexOfLastWord(line);
if (i > 1)
formattedLastWordIndices[i] += indexOfParen + 1;
i++;
}
padding = buildPadding(indexOfParen + 1);
i = 2;
while (line = formattedLines[i]) {
formattedLines[i] = padding + line;
i++;
}
i = 1;
while (line = formattedLines[i]) {
padding = buildPadding(maxIndexOfLastWord - lastWordIndices[i]);
formattedLines[i] = line.substr(0, formattedLastWordIndices[i]) +
padding + line.substr(formattedLastWordIndices[i]);
i++;
}
var output = "";
i = 0;
while (line = formattedLines[i]) {
output = output + line + "\n";
i++;
}
listing.innerHTML = output;
}
function cleanupSignature()
{
var elements = document.getElementsByClassName('programlisting');
listing = elements[0];
var input = listing.innerHTML;
var lines = input.split("\n");
var line;
var i = 0;
while (line = lines[i]) {
lines[i] = strCompactWhitespace(strStrip(line));
i++;
}
var output = "";
i = 0;
while (line = lines[i]) {
output = output + line + "\n";
i++;
}
listing.innerHTML = output;
}
|