File: jush-help.wsf

package info (click to toggle)
libjs-jush 2.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 992 kB
  • sloc: javascript: 6,929; php: 12; makefile: 7
file content (71 lines) | stat: -rw-r--r-- 2,406 bytes parent folder | download
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
<job>
<!-- SciTE: (file must be saved)
file.patterns.jush=*.htm;*.html;*.php;*.sql;*.js;*.css;php.ini;*.conf;.htaccess;my.ini
command.1.$(file.patterns.jush)=WScript jush-help.wsf "$(FilePath)" $(SelectionStartLine) $(SelectionStartColumn) $(tabsize) "$(CurrentWord)"
command.name.1.$(file.patterns.jush)=JUSH help
command.subsystem.1.$(file.patterns.jush)=2
command.save.before.1.$(file.patterns.jush)=1
-->
<script language="JScript" src="jush.js"></script>
<script language="JScript">
function readFile(filename) {
	var fso = new ActiveXObject('Scripting.FileSystemObject');
	var file = fso.OpenTextFile(filename, 1);
	return file.ReadAll();
}

function openUrl(url) {
	var shell = new ActiveXObject('WScript.Shell');
	var command = shell.RegRead('HKCR\\http\\shell\\open\\command\\'); // `start` is not available
	shell.Exec(command.replace(/%1/g, url));
}

if (WScript.Arguments.length < 3) {
	WScript.Echo('Usage: WScript jush-help.wsf filename line column [tabsize] [word]\nPurpose: Open URL with help on specified position in file');
	WScript.Quit(1);
}
var filename = WScript.Arguments(0);
var line = WScript.Arguments(1);
var column = WScript.Arguments(2);
var lang = 'htm';
var match = /\.(js|sql|xml|css)$/.exec(filename);
if (match) {
	lang = match[1];
} else if (/php\.ini$/.test(filename)) {
	lang = 'phpini';
} else if (/my\.ini$/.test(filename)) {
	lang = 'sqlset';
} else if (/(\.conf|\\\.htaccess)$/.test(filename)) {
	lang = 'cnf';
}
var file = (new RegExp('^(.*\n){' + (line - 1) + '}.*', '')).exec(readFile(filename).replace(/\r/g, ''))[0]; // highlight only first lines of file (performance)
var s = /(.*)$/.exec(jush.highlight(lang, file))[1]; // get last line of output
if (WScript.Arguments.length >= 3) {
	var tab = '';
	for (var i = WScript.Arguments(3); i--; ) {
		tab += ' ';
	}
	s = s.replace(/\t/g, tab);
}
s = s.replace(/&[^;]+;/g, '&');
var href = '';
var pos = 1;
var re = /<a href="([^"]+)" class="jush-help">|(<\/a>)|<[^>]+>|([^<]+)/g;
while (match = re.exec(s)) {
	if (match[1]) {
		href = match[1];
	} else if (match[2]) {
		if (pos == column) { // last character of link
			break;
		}
		href = '';
	} else if (match[3]) {
		pos += match[3].length;
		if (pos > column) {
			break;
		}
	}
}
openUrl(href ? href : 'https://www.google.com/search?q=' + encodeURIComponent(WScript.Arguments.length >= 4 ? WScript.Arguments(4) : (match ? match[3] : '')));
</script>
</job>