-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbyteCalc.wsf
90 lines (86 loc) · 2.15 KB
/
byteCalc.wsf
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
<!--
byteCalc - Calculator for file sizes
Copyright (C) 2015 David Lichti <[email protected]>
This prgram is distributed under the BSD 3-Clause license
-->
<job id="byteCalc">
<script language="JScript" src="FSize.js"/><!-- Library doing the actual computation -->
<script language="JScript" src="conf.js"/><!-- Configuration -->
<script language="JScript" src="strings.js"/><!-- Strings for output -->
<script language="JScript">
// If the script doesn't run in cscript, then launch it in cscript
if ((env = WScript.FullName.match(/(\w+)(?:\.\w*)?$/)[1].toLowerCase()) != 'cscript') {
var sh = WScript.CreateObject('WScript.Shell');
WScript.Quit(sh.Run('cscript ' + WScript.ScriptFullName));
}
var res = 0;
var inp = '';
WScript.Echo(msg.header);
// User interface
WScript.StdOut.Write(msg.res);
do {
inp = WScript.StdIn.ReadLine();
switch (inp.charAt(0)) {
case '+':
if ((s = parseFSize(inp.substr(1))) !== false) {
res += s;
} else {
WScript.Echo(msg.error);
}
break;
case '-':
if ((s = parseFSize(inp.substr(1))) !== false) {
res -= s;
} else {
WScript.Echo(msg.error);
}
break;
case '*':
if (isNaN(inp.substr(1))) {
WScript.Echo(msg.error);
} else {
res *= inp.substr(1);
}
break;
case '/':
if (isNaN(inp.substr(1))) {
WScript.Echo(msg.error);
} else {
res /= inp.substr(1);
}
break;
case '=':
WScript.Echo(msg.res + group(res) + ' B');
WScript.StdOut.Write(msg.reb);
continue;
break;
case 'c':
WScript.Echo(msg.res + printFSize(parseFSize(inp.substr(1))));
break;
case 'q':
WScript.Echo(msg.res + printFSize(res));
WScript.Quit(0);
break;
case 'l':
WScript.Echo(msg.license);
break;
case 'h':
case '?':
WScript.Echo(msg.help);
break;
case ' ':
default:
if ((init = parseFSize(inp)) !== false) {
res = init;
WScript.StdOut.Write(msg.reb);
continue;
} else {
WScript.Echo(msg.error);
break;
}
}
WScript.Echo(msg.res + printFSize(res));
WScript.StdOut.Write(msg.reb);
} while (inp.charAt(0) != 'q');
</script>
</job>