+ protected void ParseArgs() {
+ Options = new Dictionary<string,string>();
+ Queue<string> q = new Queue<string>();
+ foreach (string s in System.Environment.GetCommandLineArgs()) {
+ q.Enqueue(s);
+ }
+ q.Dequeue(); // Remove self argument
+
+ Regex SimpleOpt = new Regex(@"^-([a-zA-Z0-9]+)$");
+ Regex LongOpt = new Regex(@"^--([\w-]+)$");
+ string OptLast = null;
+ List<string> args = new List<string>();
+
+ while (q.Count > 0) {
+ string opt = q.Dequeue();
+ Match m;
+
+ m = SimpleOpt.Match(opt);
+ if (m.Success) {
+ string s = m.Groups[1].Value;
+ if (s.Length > 1) {
+ foreach (char c in s) {
+ Options[c.ToString()] = "";
+ }
+ OptLast = null;
+ } else {
+ Options[s] = "";
+ OptLast = s;
+ }
+ continue;
+ }
+
+ m = LongOpt.Match(opt);
+ if (m.Success) {
+ string s = m.Groups[1].Value;
+ Options[s] = "";
+ OptLast = s;
+ continue;
+ }
+
+ // else
+
+ if (OptLast != null) {
+ Options[OptLast] = opt;
+ OptLast = null;
+ } else {
+ args.Add(opt);
+ }
+ }
+ Arguments = args.ToArray();
+
+ /*
+ Console.WriteLine("Options:");
+ foreach (string key in Options.Keys)
+ Console.WriteLine(" {0}\t{1}", key, Options[key]);
+
+ Console.WriteLine("Arguments: {0}", String.Join(" ", Arguments));
+ */
+ }
+