forked from cappuccino/cappuccino
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cplutil.js
103 lines (72 loc) · 2.45 KB
/
cplutil.js
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
importPackage(java.lang);
importClass(java.io.File);
importClass(java.io.BufferedReader);
importClass(java.io.FileReader);
importClass(java.io.BufferedWriter);
importClass(java.io.FileWriter);
function printUsage()
{
print("this is where you say the usage");
}
function main()
{
if (arguments.length < 1)
return printUsage();
var allFiles = NO,
format = nil,
filePaths = [],
outPath = nil,
outExtension = nil;
index = 0,
count = arguments.length;
for (; index < count; ++index)
{
var argument = arguments[index];
if (argument.charAt(0) === '-' && !allFiles)
{
if (filePaths.length > 0)
return printUsage();
else if (argument === "-convert")
format = arguments[++index];
else if (argument === "-o")
outPath = arguments[++index];
else if (argument === "-e")
outExtension = arguments[++index];
else if (argument === "--")
allFiles = YES;
else if (argument === "-help")
return printUsage();
}
else
filePaths.push(arguments[index]);
}
index = 0;
count = filePaths.length;
for (; index < count; ++index)
{
// Read the plist file
var file = new File(filePaths[index]),
reader = new BufferedReader(new FileReader(file)),
fileContents = "";
// Get contents of the file
while (reader.ready())
fileContents += reader.readLine() + '\n';
reader.close();
var data = new objj_data();
data.string = fileContents;
var plistObject = new CPPropertyListCreateFromData(data);
if (format === "280north1")
data = CPPropertyListCreate280NorthData(plistObject);
else if (format === "xml1")
data = CPPropertyListCreateXMLData(plistObject);
var outFile = file;
if (outPath)
outFile = new File(outPath);
// else if (outExtension)
// Write out file
var writer = new BufferedWriter(new FileWriter(outFile));
writer.write(data.string);
writer.close();
}
}
main.apply(main, arguments);