Improved argument parsing code.

This commit is contained in:
the_fiddler 2010-12-06 15:19:45 +00:00
parent 1db9c38ed8
commit b4839fd78b

View file

@ -13,6 +13,7 @@ using System.Security;
using Bind.CL; using Bind.CL;
using Bind.ES; using Bind.ES;
using Bind.GL2; using Bind.GL2;
using System.Text.RegularExpressions;
namespace Bind namespace Bind
{ {
@ -56,12 +57,16 @@ namespace Bind
try try
{ {
foreach (string a in arguments) var split = new Regex(@"-\w+", RegexOptions.Compiled);
foreach (var argument in arguments)
{ {
if (a.StartsWith("--") || a.StartsWith("-") || a.StartsWith("/")) string a = argument.Replace("--", "-").Trim();
var match = split.Match(a);
if (match.Success)
{ {
string[] b = a.Split(new char[] { '-', ':', '=' }, StringSplitOptions.RemoveEmptyEntries); string opt = match.Value.Substring(1).Trim();
switch (b[0]) string val = a.Substring(match.Value.Length + 1).Trim();
switch (opt)
{ {
case "?": case "?":
case "help": case "help":
@ -69,17 +74,17 @@ namespace Bind
return; return;
case "in": case "in":
case "input": case "input":
Settings.InputPath = string.Join(Path.DirectorySeparatorChar.ToString(), b.Skip(1).ToArray()); Settings.InputPath = val;
break; break;
case "out": case "out":
case "output": case "output":
Settings.OutputPath = string.Join(Path.DirectorySeparatorChar.ToString(), b.Skip(1).ToArray()); Settings.OutputPath = val;
break; break;
case "l": case "l":
case "lang": case "lang":
case "language": case "language":
{ {
string arg = b[1].ToLower(); string arg = val.ToLower();
if (arg == "cpp" || arg == "c++" || arg == "c") if (arg == "cpp" || arg == "c++" || arg == "c")
{ {
Settings.Language = GeneratorLanguage.Cpp; Settings.Language = GeneratorLanguage.Cpp;
@ -92,33 +97,32 @@ namespace Bind
} }
case "mode": case "mode":
{ {
string arg = b[1].ToLower(); string arg = val.ToLower();
SetGeneratorMode(dirName, arg); SetGeneratorMode(dirName, arg);
if (b.Length > 2) dirName = val;
dirName = b[2];
break; break;
} }
case "namespace": case "namespace":
case "ns": case "ns":
Settings.OutputNamespace = b[1]; Settings.OutputNamespace = val;
break; break;
case "class": case "class":
Settings.OutputClass = b[1]; Settings.OutputClass = val;
break; break;
case "gl": case "gl":
Settings.GLClass = b[1]; Settings.GLClass = val;
break; break;
case "legacy": case "legacy":
case "o": case "o":
case "option": case "option":
Settings.Compatibility |= b[1].ToLower() == "tao" ? Settings.Legacy.Tao : Settings.Legacy.None; Settings.Compatibility |= val.ToLower() == "tao" ? Settings.Legacy.Tao : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "simple_enums" ? Settings.Legacy.NoAdvancedEnumProcessing : Settings.Legacy.None; Settings.Compatibility |= val.ToLower() == "simple_enums" ? Settings.Legacy.NoAdvancedEnumProcessing : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "safe" ? Settings.Legacy.NoPublicUnsafeFunctions : Settings.Legacy.None; Settings.Compatibility |= val.ToLower() == "safe" ? Settings.Legacy.NoPublicUnsafeFunctions : Settings.Legacy.None;
//Settings.Compatibility |= b[1].ToLower().Contains("novoid") ? Settings.Legacy.TurnVoidPointersToIntPtr : Settings.Legacy.None; //Settings.Compatibility |= b[1].ToLower().Contains("novoid") ? Settings.Legacy.TurnVoidPointersToIntPtr : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "permutations" ? Settings.Legacy.GenerateAllPermutations : Settings.Legacy.None; Settings.Compatibility |= val.ToLower() == "permutations" ? Settings.Legacy.GenerateAllPermutations : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "enums_in_class" ? Settings.Legacy.NestedEnums : Settings.Legacy.None; Settings.Compatibility |= val.ToLower() == "enums_in_class" ? Settings.Legacy.NestedEnums : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "nodocs" ? Settings.Legacy.NoDocumentation : Settings.Legacy.None; Settings.Compatibility |= val.ToLower() == "nodocs" ? Settings.Legacy.NoDocumentation : Settings.Legacy.None;
Settings.Compatibility |= b[1].ToLower() == "keep_untyped_enums" ? Settings.Legacy.KeepUntypedEnums : Settings.Legacy.None; Settings.Compatibility |= val.ToLower() == "keep_untyped_enums" ? Settings.Legacy.KeepUntypedEnums : Settings.Legacy.None;
break; break;
default: default:
throw new ArgumentException( throw new ArgumentException(