Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
116 lines (104 loc) · 3.79 KB
/
Copy pathProgram.cs
File metadata and controls
116 lines (104 loc) · 3.79 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
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
/*
Copyright 2017 YANG Huan ([email protected]).
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpLua {
class Program {
private const string kHelpCmdString = @"Usage: CSharp.lua [-s srcfolder] [-d dstfolder]
Arguments
-s : source directory, all *.cs files whill be compiled
-d : destination directory, will put the out lua files
Options
-h : show the help message and exit
-l : libraries referenced, use ';' to separate
-m : meta files, like System.xml, use ';' to separate
-csc : csc.exe command argumnets, use ' ' or '\t' to separate
-c : support classic lua version(5.1), default support 5.3
-i : indent number, default is 2
-a : attributes need to export, use ';' to separate, if ""-a"" only, all attributes whill be exported
";
public static void Main(string[] args) {
if (args.Length > 0) {
try {
var cmds = Utility.GetCommondLines(args);
if (cmds.ContainsKey("-h")) {
ShowHelpInfo();
return;
}
Console.WriteLine($"start {DateTime.Now}");
string folder = cmds.GetArgument("-s");
string output = cmds.GetArgument("-d");
string lib = cmds.GetArgument("-l", true);
string meta = cmds.GetArgument("-m", true);
bool isClassic = cmds.ContainsKey("-c");
string indent = cmds.GetArgument("-i", true);
string atts = cmds.GetArgument("-a", true);
if (atts == null && cmds.ContainsKey("-a")) {
atts = string.Empty;
}
string csc = GetCSCArgument(cmds);
Compiler w = new Compiler(folder, output, lib, meta, csc, isClassic, indent, atts);
w.Do();
Console.WriteLine("all operator success");
Console.WriteLine($"end {DateTime.Now}");
} catch (CmdArgumentException e) {
Console.Error.WriteLine(e.Message);
ShowHelpInfo();
Environment.ExitCode = -1;
} catch (CompilationErrorException e) {
Console.Error.WriteLine(e.Message);
Environment.ExitCode = -1;
} catch (Exception e) {
Console.Error.WriteLine(e.ToString());
Environment.ExitCode = -1;
}
} else {
ShowHelpInfo();
Environment.ExitCode = -1;
}
}
private static void ShowHelpInfo() {
Console.Error.WriteLine(kHelpCmdString);
}
private static bool IsArgumentKey(string key) {
switch (key) {
case "-s":
case "-d":
case "-l":
case "-m":
case "-c":
case "-i":
case "-a":
return true;
}
return false;
}
private static string GetCSCArgument(Dictionary<string, string[]> cmds) {
if (cmds.ContainsKey("-csc")) {
int index = cmds.Keys.IndexOf(i => i == "-csc");
Contract.Assert(index != -1);
var remains = cmds.Keys.Skip(index + 1);
int end = remains.IndexOf(IsArgumentKey);
if (end != -1) {
remains = remains.Take(end);
}
return string.Join(" ", remains);
}
return null;
}
}
}