public void AddRule(string target, Program.RuleForFunction rule) { /* Identify wildcards as those containing unescaped % characters */ bool wc = false; for (int i = 0; i < target.Length; i++) { if (target[i] == '%') { if (i == 0 || target[i - 1] != '\\') { wc = true; break; } } } if (wc) { wildcards.Add(target); Wildcards.Add(new Wildcard { mr = rule, target = target }); } else { target = new Uri(new Uri(Environment.CurrentDirectory + "/"), target).AbsolutePath; rules[target] = rule; } rule.export = true; if (rule.export) { TyMakeState cur_s = parent as TyMakeState; while (cur_s != null) { if (wc) { cur_s.wildcards.Add(target); cur_s.Wildcards.Add(new Wildcard { mr = rule, target = target }); } else { cur_s.rules[target] = rule; } cur_s = cur_s.parent as TyMakeState; } } }
public override Expression.EvalResult Run(MakeState s, List <Expression.EvalResult> passed_args) { TyMakeState tms = s as TyMakeState; string wc_pat; if (tms.GetRule(passed_args[0].strval, out wc_pat) == null) { return(new Expression.EvalResult(0)); } else { return(new Expression.EvalResult(1)); } }
public override MakeState Clone() { TyMakeState other = new TyMakeState(); other.wildcards = new List <string>(wildcards); other.Wildcards = new List <Wildcard>(Wildcards); other.rules = new Dictionary <string, Program.RuleForFunction>(); foreach (var kvp in rules) { other.rules[kvp.Key] = kvp.Value; } CloneTo(other); return(other); }
static void Main(string[] args) { var s = new TyMakeState(); TymakeLib.InitMakeState(s, Console.In, Console.Out, Console.Out); new TyProject().Execute(s); new TyProjectLibDirFunction().Execute(s); new TyProjectSetCscFunction().Execute(s); new RuleForFunction().Execute(s); new BuildCommandStatement().Execute(s); new AutoDirStatement().Execute(s); new ShellCommandFunction().Execute(s); /* Add in current environment variables */ System.Collections.IDictionary env_vars = Environment.GetEnvironmentVariables(); foreach (System.Collections.DictionaryEntry env_var in env_vars) { s.SetDefine(env_var.Key.ToString().ToUpper(), new Expression.EvalResult(env_var.Value.ToString())); } if (System.Environment.OSVersion.Platform == PlatformID.Unix) { s.SetDefine("EXEC_EXTENSIONS", new Expression.EvalResult(new Expression.EvalResult[] { new Expression.EvalResult("") })); s.SetDefine("PATH_SPLIT", new Expression.EvalResult(":")); s.SetDefine("DIR_SPLIT", new Expression.EvalResult("/")); s.SetDefine("PLATFORM", new Expression.EvalResult("unix")); } else { s.SetDefine("EXEC_EXTENSIONS", new Expression.EvalResult(new Expression.EvalResult[] { new Expression.EvalResult(".exe") })); s.SetDefine("PATH_SPLIT", new Expression.EvalResult(";")); s.SetDefine("DIR_SPLIT", new Expression.EvalResult("\\")); s.SetDefine("PLATFORM", new Expression.EvalResult("win")); } /* Include the standard library */ System.IO.FileInfo exec_fi = new System.IO.FileInfo(typeof(Program).Module.FullyQualifiedName); System.IO.FileInfo[] stdlib_fis = exec_fi.Directory.GetFiles("*.tmh"); foreach (System.IO.FileInfo stdlib_fi in stdlib_fis) { TymakeLib.ExecuteFile(stdlib_fi.FullName, s); } /* Determine what to run - either interpret the arguments as files or as commands */ bool immediate = false; foreach (string arg in args) { if (arg == "-") { immediate = true; } else if (Statement.FileDirExists(arg)) { var ret = TymakeLib.ExecuteFile(arg, s); if (ret.AsInt != 0) { System.Diagnostics.Debugger.Break(); } } else { var ret = TymakeLib.ExecuteString(arg, s); if (ret.AsInt != 0) { System.Diagnostics.Debugger.Break(); } } } if (immediate) { while (true) { Console.Write("> "); try { TymakeLib.ExecuteString(Console.ReadLine(), s); } catch (ParseException e) { Console.WriteLine(); Console.WriteLine(e.Message); } catch (Statement.SyntaxException e) { Console.WriteLine(); Console.WriteLine(e.Message); } } } }