forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.js
More file actions
70 lines (55 loc) · 1.12 KB
/
encode.js
File metadata and controls
70 lines (55 loc) · 1.12 KB
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
if (WScript.arguments.length != 2)
{
WScript.Echo("ERROR: Invalid number of argument");
WScript.Quit(-1);
}
var input = WScript.arguments(0);
var output = WScript.arguments(1);
var fso = WScript.CreateObject("Scripting.FileSystemObject");
try
{
var f = fso.OpenTextFile(input, 1);
}
catch (e)
{
WScript.Echo("ERROR: unable to open input file " + input);
WScript.Quit(-1);
}
var str = f.ReadAll();
f.Close();
if (str.length == 0)
{
WScript.Echo("ERROR: input file is empty");
WScript.Quit(-1);
}
try
{
var out = fso.OpenTextFile(output, 2, true, -1);
}
catch (e)
{
WScript.Echo("ERROR: unable to open output file " + output);
WScript.Quit(-1);
}
function writeChar(c)
{
var line = false;
if (c == "\\") {
c = "\\\\";
} else if (c == "'" || c == "\"") {
c = "\\" + c;
} else if (c == "\r") {
c = "\\r";
} else if (c == "\n") {
c = "\\n";
line = true;
}
out.Write("L'" + c + "'");
out.Write(",");
if (line) out.WriteLine("");
}
for (var i = 0; i < str.length; i++)
{
writeChar(str.charAt(i));
}
out.Close();