public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Usage: scriptconversion <scripts|file> ..."); return; } string mode = args[0]; if (mode == "scripts") { ConvertScripts(args.Skip(1).ToArray()); return; } else if (mode == "folder") { Tig.FS = TroikaVfs.CreateFromInstallationDir(args[1]); Directory.CreateDirectory("temp"); var conversion = new ScriptConversion("temp"); foreach (var pythonFile in Directory.EnumerateFiles(args[2], "*.py")) { conversion.ConvertSingleFile(pythonFile, ScriptType.TemplePlusCondition); } } else { Console.WriteLine("Unknown mode: " + mode); } }
private static void ConvertScripts(string[] args) { var outputDir = "scripts"; if (args.Length != 1 && args.Length != 2) { Console.WriteLine("Usage: scriptconversion <toee-dir> [<script-out-dir>]"); return; } var installationDir = args[0]; if (args.Length > 1) { outputDir = args[1]; } Directory.CreateDirectory(outputDir); Tig.FS = TroikaVfs.CreateFromInstallationDir(installationDir); var conversion = new ScriptConversion(outputDir); conversion.LoadTyping(outputDir); conversion.ConvertScripts(); conversion.ConvertDialog(); }
private static double dbl(object expression) { return(ScriptConversion.ToDouble(expression)); }
private static float sng(object expression) { return(ScriptConversion.ToSingle(expression)); }
//////////////////////////////////////////////////////////// //// //// Shortens the ScriptConversion methods to shorter names. //// //////////////////////////////////////////////////////////// private static int @int(object expression) { return(ScriptConversion.ToInteger(expression)); }
/// <summary> /// Evaluates a script comparison between two expressions. /// </summary> /// <param name="inputString">The string containing the expression to compare.</param> /// <param name="caseSensitive">If the case of the strings should be evaluated.</param> public static bool EvaluateScriptComparison(string inputString, bool caseSensitive) { string comparer = "="; int level = 0; string setComparer = ""; string lastComparer = ""; int comparerIndex = inputString.IndexOf("="); int lastComparerIndex = 0; int i = 0; int countStarts = 0; foreach (char c in inputString) { switch (c) { case '<': countStarts += 1; break; case '>': countStarts -= 1; break; } } if (countStarts < 0) { setComparer = ">"; } else if (countStarts > 0) { setComparer = "<"; } else { setComparer = "="; } if (setComparer == ">") { foreach (char c in inputString) { switch (c) { case '<': level += 1; break; case '>': level -= 1; if (level == -1) { comparerIndex = i; break; // TODO: might not be correct. Was : Exit For } break; } i += 1; } } else if (setComparer == "<") { List <int> started = new List <int>(); foreach (char c in inputString) { switch (c) { case '<': started.Add(i); break; case '>': started.RemoveAt(started.Count - 1); break; } i += 1; } comparerIndex = started[0]; } if (!string.IsNullOrEmpty(setComparer)) { comparer = setComparer; } else { comparerIndex = inputString.IndexOf("="); } object compareValue = inputString.Substring(comparerIndex + 1); string classValue = inputString.Substring(0, comparerIndex); object resultValue = EvaluateConstruct(classValue); compareValue = EvaluateConstruct(compareValue); bool comparisonResult = false; switch (comparer) { case "=": if (caseSensitive == true | resultValue as string == null | compareValue as string == null) { if (resultValue.Equals(compareValue)) { comparisonResult = true; } } else { if (ScriptConversion.IsBoolean(Convert.ToString(resultValue)) == true & ScriptConversion.IsBoolean(Convert.ToString(compareValue)) == true) { if (ScriptConversion.ToBoolean(resultValue) == ScriptConversion.ToBoolean(compareValue)) { comparisonResult = true; } } else { if (Convert.ToString(resultValue).ToLower() == Convert.ToString(compareValue).ToLower()) { comparisonResult = true; } } } break; case ">": if (Information.IsNumeric(resultValue) == true & Information.IsNumeric(compareValue) == true) { if (dbl(resultValue) > dbl(compareValue)) { comparisonResult = true; } } break; case "<": if (Information.IsNumeric(resultValue) == true & Information.IsNumeric(compareValue) == true) { if (dbl(resultValue) < dbl(compareValue)) { comparisonResult = true; } } break; } return(comparisonResult); }
private static double dbl(object expression) => ScriptConversion.ToDouble(expression);
private static double sng(object expression) => ScriptConversion.ToSingle(expression);
//////////////////////////////////////////////////////////// //// //// Shortens the ScriptConversion methods to shorter names. //// //////////////////////////////////////////////////////////// private static int @int(object expression) => ScriptConversion.ToInteger(expression);