private void loadDataTo(string csvPath, int targetIndex, Int64[] targetI, bool disp) { if (!File.Exists(csvPath)) return; string[] target = names[targetIndex]; List<int> defined = new List<int>(); EraStreamReader eReader = new EraStreamReader(); if (!eReader.Open(csvPath)) { output.PrintError(eReader.Filename + "のオープンに失敗しました"); return; } ScriptPosition position = null; if (disp || Program.AnalysisMode) output.PrintLine(eReader.Filename + "読み込み中・・・"); try { StringStream st = null; while ((st = eReader.ReadEnabledLine()) != null) { position = new ScriptPosition(eReader.Filename, eReader.LineNo, st.RowString); string[] tokens = st.Substring().Split(','); if (tokens.Length < 2) { ParserMediator.Warn("\",\"が必要です", position, 1); continue; } int index = 0; if (!Int32.TryParse(tokens[0], out index)) { ParserMediator.Warn("一つ目の値を整数値に変換できません", position, 1); continue; } if ((index < 0) || (target.Length <= index)) { ParserMediator.Warn(index.ToString() + "は配列の範囲外です", position, 1); continue; } if (defined.Contains(index)) ParserMediator.Warn(index.ToString() + "番目の要素はすでに定義されています(新しい値で上書きされます)", position, 1); else defined.Add(index); target[index] = tokens[1]; if ((targetI != null) && (tokens.Length >= 3)) { Int64 price; if (!Int64.TryParse(tokens[2].TrimEnd(), out price)) { ParserMediator.Warn("金額が読み取れません", position, 1); continue; } targetI[index] = price; } } } catch { System.Media.SystemSounds.Hand.Play(); if (position != null) ParserMediator.Warn("予期しないエラーが発生しました", position, 3); else output.PrintError("予期しないエラーが発生しました"); return; } finally { eReader.Close(); } }
private void loadVariableSizeData(string csvPath, bool disp) { if (!File.Exists(csvPath)) return; EraStreamReader eReader = new EraStreamReader(); if (!eReader.Open(csvPath)) { output.PrintError(eReader.Filename + "のオープンに失敗しました"); return; } ScriptPosition position = null; if (disp) output.PrintLine(eReader.Filename + "読み込み中・・・"); try { StringStream st = null; while ((st = eReader.ReadEnabledLine()) != null) { position = new ScriptPosition(eReader.Filename, eReader.LineNo, st.RowString); changeVariableSizeData(st.Substring(), position); } position = new ScriptPosition(eReader.Filename, -1, null); } catch { System.Media.SystemSounds.Hand.Play(); if (position != null) ParserMediator.Warn("予期しないエラーが発生しました", position, 3); else output.PrintError("予期しないエラーが発生しました"); return; } finally { eReader.Close(); } decideActualArraySize(position); }
//1756 Process.Load.csより移動 public static void LoadEraExRenameFile(string filepath) { if (RenameDic != null) RenameDic.Clear(); //とにかく辞書を作る。辞書がnullのときは UseRenameFileがNOの時のみ RenameDic = new Dictionary<string, string>(); EraStreamReader eReader = new EraStreamReader(); if ((!File.Exists(filepath)) || (!eReader.Open(filepath))) { return; } string line = null; ScriptPosition pos = null; Regex reg = new Regex(@"\\,", RegexOptions.Compiled); try { while ((line = eReader.ReadLine()) != null) { if (line.Length == 0) continue; if (line.StartsWith(";")) continue; string[] baseTokens = reg.Split(line); if (!baseTokens[baseTokens.Length - 1].Contains(",")) continue; string[] last = baseTokens[baseTokens.Length - 1].Split(','); baseTokens[baseTokens.Length - 1] = last[0]; string[] tokens = new string[2]; tokens[0] = string.Join(",", baseTokens); tokens[1] = last[1]; pos = new ScriptPosition(eReader.Filename, eReader.LineNo, line); //右がERB中の表記、左が変換先になる。 string value = tokens[0].Trim(); string key = string.Format("[[{0}]]", tokens[1].Trim()); RenameDic[key] = value; pos = null; } } catch (Exception e) { if (pos != null) throw new CodeEE(e.Message, pos); else throw new CodeEE(e.Message); } finally { eReader.Close(); } }
private bool loadHeaderFile(string filepath, string filename) { StringStream st = null; ScriptPosition position = null; EraStreamReader eReader = new EraStreamReader(); if (!eReader.Open(filepath, filename)) { throw new CodeEE(eReader.Filename + "のオープンに失敗しました"); //return false; } try { while ((st = eReader.ReadEnabledLine()) != null) { if (!noError) return false; position = new ScriptPosition(filename, eReader.LineNo, st.RowString); LexicalAnalyzer.SkipWhiteSpace(st); if (st.Current != '#') throw new CodeEE("ヘッダーの中に#で始まらない行があります", position); st.ShiftNext(); string sharpID = LexicalAnalyzer.ReadSingleIdentifier(st); if (sharpID == null) { ParserMediator.Warn("解釈できない#行です", position, 1); return false; } if (Config.ICFunction) sharpID = sharpID.ToUpper(); LexicalAnalyzer.SkipWhiteSpace(st); switch (sharpID) { case "DEFINE": analyzeSharpDefine(st, position); break; case "DIM": case "DIMS": analyzeSharpDim(st, position, sharpID == "DIMS"); break; default: throw new CodeEE("#" + sharpID + "は解釈できないプリプロセッサです", position); } } } catch (CodeEE e) { if (e.Position != null) position = e.Position; ParserMediator.Warn(e.Message, position, 2); return false; } finally { eReader.Close(); } return true; }
/// <summary> /// ファイル一つを読む /// </summary> /// <param name="filepath"></param> private void loadErb(string filepath, string filename, List<string> isOnlyEvent) { //読み込んだファイルのパスを記録 //一部ファイルの再読み込み時の処理用 labelDic.AddFilename(filename); EraStreamReader eReader = new EraStreamReader(); if (!eReader.Open(filepath, filename)) { output.PrintError(eReader.Filename + "のオープンに失敗しました"); return; } try { PPState ppstate = new PPState(); LogicalLine nextLine = new NullLine(); LogicalLine lastLine = new NullLine(); FunctionLabelLine lastLabelLine = null; StringStream st = null; string rowLine = null; ScriptPosition position = null; int funcCount = 0; if (Program.AnalysisMode) output.Print(" "); while ((st = eReader.ReadEnabledLine()) != null) { rowLine = st.RowString; position = new ScriptPosition(eReader.Filename, eReader.LineNo, rowLine); //1808alpha006 eramakerExの仕様通りにrenameを無制限に適用する if (Config.UseRenameFile && ParserMediator.RenameDic != null &&(rowLine.IndexOf("[[") >= 0) && (rowLine.IndexOf("]]") >= 0)) { foreach (KeyValuePair<string, string> pair in ParserMediator.RenameDic) rowLine = rowLine.Replace(pair.Key, pair.Value); st = new StringStream(rowLine); } //命令文の一部を[[]]置換できるのはよろしくないので、処理位置変更に対応 //全置換は弾く if (st.Current == '[' && st.Next != '[') { st.ShiftNext(); string token = LexicalAnalyzer.ReadSingleIdentifier(st); LexicalAnalyzer.SkipWhiteSpace(st); string token2 = LexicalAnalyzer.ReadSingleIdentifier(st); if ((string.IsNullOrEmpty(token)) || (st.Current != ']')) ParserMediator.Warn("[]の使い方が不正です", position, 1); ppstate.AddKeyWord(token, token2, position); st.ShiftNext(); if (!st.EOS) ParserMediator.Warn("[" + token + "]の後ろは無視されます。", position, 1); continue; } //if ((skip) || (Program.DebugMode && ifndebug) || (!Program.DebugMode && ifdebug)) // continue; if (ppstate.Disabled) continue; //ここまでプリプロセッサ if (st.Current == '#') { if ((lastLine == null) || !(lastLine is FunctionLabelLine)) { ParserMediator.Warn("関数宣言の直後以外で#行が使われています", position, 1); continue; } if (!LogicalLineParser.ParseSharpLine((FunctionLabelLine)lastLine, st, position, isOnlyEvent)) noError = false; continue; } if ((st.Current == '$') || (st.Current == '@')) { bool isFunction = (st.Current == '@'); nextLine = LogicalLineParser.ParseLabelLine(st, position, output); if (isFunction) { FunctionLabelLine label = (FunctionLabelLine)nextLine; lastLabelLine = label; if (label is InvalidLabelLine) { noError = false; ParserMediator.Warn(nextLine.ErrMes, position, 2); labelDic.AddInvalidLabel(label); } else// if (label is FunctionLabelLine) { labelDic.AddLabel(label); if (!label.IsEvent && (Config.WarnNormalFunctionOverloading || Program.AnalysisMode)) { FunctionLabelLine seniorLabel = labelDic.GetSameNameLabel(label); if (seniorLabel != null) { //output.NewLine(); ParserMediator.Warn("関数@" + label.LabelName + "は既に定義(" + seniorLabel.Position.Filename + "の" + seniorLabel.Position.LineNo.ToString() + "行目)されています", position, 1); funcCount = -1; } } funcCount++; if (Program.AnalysisMode && (Config.PrintCPerLine > 0 && (funcCount % Config.PrintCPerLine) == 0)) { output.NewLine(); output.Print(" "); } } } else { if (nextLine is GotoLabelLine) { GotoLabelLine gotoLabel = (GotoLabelLine)nextLine; gotoLabel.ParentLabelLine = lastLabelLine; if (lastLabelLine != null && !labelDic.AddLabelDollar(gotoLabel)) { ScriptPosition pos = labelDic.GetLabelDollar(gotoLabel.LabelName, lastLabelLine).Position; ParserMediator.Warn("ラベル名$" + gotoLabel.LabelName + "は既に同じ関数内(" + pos.Filename + "の" + pos.LineNo.ToString() + "行目)で使用されています", position, 2); } } } if (nextLine is InvalidLine) { noError = false; ParserMediator.Warn(nextLine.ErrMes, position, 2); } } else { //1808alpha006 処理位置変更 ////全置換はここで対応 ////1756beta1+++ 最初に全置換してしまうと関数定義を_Renameでとか論外なことができてしまうので永久封印した //if (ParserMediator.RenameDic != null && st.CurrentEqualTo("[[") && (rowLine.TrimEnd().IndexOf("]]") == rowLine.TrimEnd().Length - 2)) //{ // string replacedLine = st.Substring(); // foreach (KeyValuePair<string, string> pair in ParserMediator.RenameDic) // replacedLine = replacedLine.Replace(pair.Key, pair.Value); // st = new StringStream(replacedLine); //} nextLine = LogicalLineParser.ParseLine(st, position, output); if (nextLine == null) continue; if (nextLine is InvalidLine) { noError = false; ParserMediator.Warn(nextLine.ErrMes, position, 2); } } if (lastLabelLine == null) ParserMediator.Warn("関数が定義されるより前に行があります", position, 1); nextLine.ParentLabelLine = lastLabelLine; lastLine = addLine(nextLine, lastLine); } addLine(new NullLine(), lastLine); position = new ScriptPosition(eReader.Filename, -1, null); ppstate.FileEnd(position); } finally { eReader.Close(); } return; }
public void LoadGameBaseCsv(string basePath) { if (!File.Exists(basePath)) return; ScriptPosition pos = null; EraStreamReader eReader = new EraStreamReader(); if (!eReader.Open(basePath)) { //output.PrintLine(eReader.Filename + "のオープンに失敗しました"); return; } try { StringStream st = null; while ((st = eReader.ReadEnabledLine()) != null) { string[] tokens = st.Substring().Split(','); if (tokens.Length < 2) continue; string param = tokens[1].Trim(); pos = new ScriptPosition(eReader.Filename, eReader.LineNo, st.RowString); switch (tokens[0]) { case "コード": if (tryatoi(tokens[1], out ScriptUniqueCode)) { if (ScriptUniqueCode == 0L) ParserMediator.Warn("コード:0のセーブデータはいかなるコードのスクリプトからも読めるデータとして扱われます", pos, 0); } break; case "バージョン": ScriptVersionDefined = tryatoi(tokens[1], out ScriptVersion); break; case "バージョン違い認める": tryatoi(tokens[1], out ScriptCompatibleMinVersion); break; case "最初からいるキャラ": tryatoi(tokens[1], out DefaultCharacter); break; case "アイテムなし": tryatoi(tokens[1], out DefaultNoItem); break; case "タイトル": ScriptTitle = tokens[1]; break; case "作者": ScriptAutherName = tokens[1]; break; case "製作年": ScriptYear = tokens[1]; break; case "追加情報": ScriptDetail = tokens[1]; break; case "ウィンドウタイトル": ScriptWindowTitle = tokens[1]; break; } } } catch { return; } finally { eReader.Close(); } if (ScriptWindowTitle == null) { if (string.IsNullOrEmpty(ScriptTitle)) ScriptWindowTitle = "Emuera"; else ScriptWindowTitle = ScriptTitle + " " + ScriptVersionText; } return; }