public static void LoadErrors(string filename) { if (!File.Exists(filename)) { return; } Dictionary <string, string> dict = GetDictionary(Constants.ENGLISH, s_errors); string[] lines = Utils.GetFileLines(filename); foreach (string line in lines) { string[] tokens = line.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Length < 1 || tokens[0].StartsWith("#")) { continue; } if (tokens.Length == 1) { dict = GetDictionary(tokens[0], s_errors); continue; } dict[tokens[0].Trim()] = tokens[1].Trim(); } }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, m_name, true); string filename = args[0].AsString(); string[] lines = Utils.GetFileLines(filename); string includeFile = string.Join(Environment.NewLine, lines); Dictionary <int, int> char2Line; string includeScript = Utils.ConvertToScript(includeFile, out char2Line); ParsingScript tempScript = new ParsingScript(includeScript, 0, char2Line); tempScript.Filename = filename; tempScript.OriginalScript = string.Join(Constants.END_LINE.ToString(), lines); while (tempScript.Pointer < includeScript.Length) { tempScript.ExecuteTo(); tempScript.GoToNextStatement(); } return(Variable.EmptyInstance); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, m_name, true); string filename = args[0].AsString(); string[] lines = Utils.GetFileLines(filename); string includeFile = string.Join(Environment.NewLine, lines); Dictionary <int, int> char2Line; string includeScript = Utils.ConvertToScript(includeFile, out char2Line); ParsingScript tempScript = new ParsingScript(includeScript, 0, char2Line); tempScript.Filename = filename; tempScript.OriginalScript = string.Join(Constants.END_LINE.ToString(), lines); tempScript.ParentScript = script; tempScript.InTryBlock = script.InTryBlock; Variable result = null; if (script.Debugger != null) { result = script.Debugger.StepInIncludeIfNeeded(tempScript); } while (tempScript.Pointer < includeScript.Length) { result = tempScript.ExecuteTo(); tempScript.GoToNextStatement(); } return(result == null ? Variable.EmptyInstance : result); }
protected override Variable Evaluate(ParsingScript script) { string filename = Utils.GetItem(script).AsString(); string[] lines = Utils.GetFileLines(filename); List <Variable> results = Utils.ConvertToResults(lines); return(new Variable(results)); }
private static string GetFileContents(string filename) { try { string[] readText = Utils.GetFileLines(filename); return(string.Join("\n", readText)); } catch (ArgumentException exc) { Console.WriteLine(exc.Message); Environment.Exit(1); return(""); } }
protected override Variable Evaluate(ParsingScript script) { string filename = Utils.GetStringOrVarValue(script); string[] lines = Utils.GetFileLines(filename); List <Variable> results = Utils.ConvertToResults(lines); Interpreter.Instance.AppendOutput("Read " + lines.Length + " line(s).", true); return(new Variable(results)); }
public static string GetFileContents(string filename) { try { string[] readText = Utils.GetFileLines(filename); return(string.Join("\n", readText)); } catch (Exception exc) { Console.WriteLine(exc.Message); return(""); } }
public ParsingScript GetIncludeFileScript(string filename) { string pathname = GetFilePath(filename); string[] lines = Utils.GetFileLines(pathname); string includeFile = string.Join(Environment.NewLine, lines); Dictionary <int, int> char2Line; var includeScript = Utils.ConvertToScript(includeFile, out char2Line, pathname); ParsingScript tempScript = new ParsingScript(includeScript, 0, char2Line); tempScript.Filename = pathname; tempScript.OriginalScript = string.Join(Constants.END_LINE.ToString(), lines); tempScript.ParentScript = this; tempScript.InTryBlock = InTryBlock; return(tempScript); }
protected override Variable Evaluate(ParsingScript script) { string filename = Utils.GetStringOrVarValue(script); int size = Constants.DEFAULT_FILE_LINES; bool sizeAvailable = Utils.SeparatorExists(script); if (sizeAvailable) { Variable length = Utils.GetItem(script); Utils.CheckPosInt(length); size = (int)length.Value; } string[] lines = Utils.GetFileLines(filename, -1, size); List <Variable> results = Utils.ConvertToResults(lines); return(new Variable(results)); }
protected override Variable Evaluate(string data, ref int from) { string filename = Utils.GetItem(data, ref from).AsString(); string[] lines = Utils.GetFileLines(filename); string includeFile = string.Join(Environment.NewLine, lines); string includeScript = Utils.ConvertToScript(includeFile); int filePtr = 0; while (filePtr < includeScript.Length) { Parser.LoadAndCalculate(includeScript, ref filePtr, Constants.END_LINE_ARRAY); Utils.GoToNextStatement(includeScript, ref filePtr); } return(Variable.EmptyInstance); }
public static void LoadDictionary(string filename, string fromLang, string toLang) { Dictionary <string, string> dict1 = TranslationDictionary(fromLang, toLang); Dictionary <string, string> dict2 = TranslationDictionary(toLang, fromLang); string[] lines = Utils.GetFileLines(filename); foreach (string line in lines) { string[] tokens = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Length < 2 || tokens[0].StartsWith("#")) { continue; } string word1 = tokens[0].Trim(); string word2 = tokens[1].Trim(); dict1[word1] = word2; dict2[word2] = word1; } }