From 06c650577abf949f212fd66562d65332f285cdfc Mon Sep 17 00:00:00 2001 From: ketmar Date: Mon, 28 May 2012 03:50:35 +0300 Subject: [PATCH] script parser changed a little --- src/felib/femath.cpp | 2 +- src/felib/fesave.cpp | 236 +++++++++++++++++++++++++++++--------------------- src/felib/fesave.h | 18 ++-- src/game/database.cpp | 34 ++++---- src/game/game.cpp | 48 +++++----- src/game/script.cpp | 56 ++++++------ 6 files changed, 217 insertions(+), 177 deletions(-) diff --git a/src/felib/femath.cpp b/src/felib/femath.cpp index af445d8..78b87d6 100644 --- a/src/felib/femath.cpp +++ b/src/felib/femath.cpp @@ -216,7 +216,7 @@ void ReadData(interval &I, inputfile &SaveFile) { SaveFile.ReadWord(Word); if (Word == ";" || Word == ",") I.Max = I.Min; else if (Word == ":") I.Max = Max(SaveFile.ReadNumber(), I.Min); - else ABORT("Odd interval terminator %s detected, file %s line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + else ABORT("Odd interval terminator %s detected, file %s line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } diff --git a/src/felib/fesave.cpp b/src/felib/fesave.cpp index c3253fe..0ad378c 100644 --- a/src/felib/fesave.cpp +++ b/src/felib/fesave.cpp @@ -142,6 +142,7 @@ festring inputfile::GetMyDir (void) { } +//////////////////////////////////////////////////////////////////////////////// inputfile::inputfile (cfestring &FileName, const valuemap *ValueMap, truth AbortOnErr) : #ifdef USE_ZLIB Buffer(gzopen(FileName.CStr(), "rb")), @@ -150,10 +151,13 @@ inputfile::inputfile (cfestring &FileName, const valuemap *ValueMap, truth Abort #endif FileName(FileName), ValueMap(ValueMap), - lastWordWasString(false) + lastWordWasString(false), #ifdef USE_ZLIB - , mFileSize(-1) + mFileSize(-1), #endif + mCharBufPos(0), + mCurrentLine(1), + mTokenLine(1) { if (AbortOnErr && !IsOpen()) ABORT("File %s not found!", FileName.CStr()); } @@ -177,12 +181,30 @@ void inputfile::Close () { int inputfile::Get () { - return Xgetc(Buffer); + if (mCharBufPos > 0) { + return mCharBuf[--mCharBufPos]; + } else if (Buffer) { + int ch = Xgetc(Buffer); + // + if (ch == '\n') ++mCurrentLine; + return (ch < 0 ? EOF : ch); + } else { + return EOF; + } +} + + +void inputfile::Unget (int ch) { + if (ch >= 0) { + if (mCharBufPos > 4) die("too many unread chars"); + mCharBuf[mCharBufPos++] = ch; + } } -int inputfile::Unget (int ch) { - return Xungc(ch, Buffer); +truth inputfile::Eof () { + if (Buffer) return (mCharBufPos == 0 && Xfeof(Buffer)); + return true; } @@ -195,11 +217,6 @@ void inputfile::Read (char *Offset, sLong Size) { } -truth inputfile::Eof () { - return Xfeof(Buffer); -} - - void inputfile::SeekPosBegin (sLong Offset) { if (Xseek(Buffer, Offset, SEEK_SET) < 0) ABORT("File '%s': seek error!", FileName.CStr()); } @@ -304,7 +321,7 @@ truth inputfile::delVar (cfestring &name) { void inputfile::die (cfestring &msg) { - ABORT("ERROR in file %s, line %d: %s", GetFileName().CStr(), TellLine(), msg.CStr()); + ABORT("ERROR in file %s, line %d: %s", GetFileName().CStr(), mTokenLine, msg.CStr()); } @@ -324,6 +341,7 @@ static const char *opers[5][7] = { festring inputfile::readCondition (festring &token, int prio, truth skipIt) { festring res, op1, opc; + // //fprintf(stderr, "IN: prio: %d; skip: %s; [%s]\n", prio, skipIt?"t":"o", token.CStr()); switch (prio) { case 0: // term @@ -432,6 +450,7 @@ done: // 666: in '{}', processing void inputfile::ReadWord (festring &str, truth AbortOnEOF, truth skipIt) { int prc; + // for (;;) { if (!mIfStack.empty()) prc = mIfStack.top(); else prc = 0; readWordIntr(str, AbortOnEOF); @@ -497,40 +516,43 @@ void inputfile::ReadWord (festring &str, truth AbortOnEOF, truth skipIt) { festring inputfile::ReadWord (truth AbortOnEOF) { festring ToReturn; + // ReadWord(ToReturn, AbortOnEOF); return ToReturn; } void inputfile::SkipSpaces () { - while (!Xfeof(Buffer)) { - int ch = Xgetc(Buffer); + while (!Eof()) { + int ch = Get(); if (ch == EOF) break; if ((unsigned char)ch > ' ') { - Xungc(ch, Buffer); + Unget(ch); break; } } } -#define MODE_WORD 1 -#define MODE_NUMBER 2 +#define MODE_WORD (1) +#define MODE_NUMBER (2) + +#define PUNCT_RETURN (0) +#define PUNCT_CONTINUE (1) -#define PUNCT_RETURN 0 -#define PUNCT_CONTINUE 1 int inputfile::HandlePunct (festring &String, int Char, int Mode) { + mTokenLine = mCurrentLine; if (Char == '/') { // comment? (can be nested) - if (!Xfeof(Buffer)) { - Char = Xgetc(Buffer); + if (!Eof()) { + Char = Get(); if (Char == '*') { - sLong StartPos = TellPos(); int OldChar = 0, CommentLevel = 1; + // for (;;) { - if (Xfeof(Buffer)) ABORT("Unterminated comment in file %s, beginning at line %d!", FileName.CStr(), TellLineOfPos(StartPos)); - Char = Xgetc(Buffer); + if (Eof()) ABORT("Unterminated comment in file %s, beginning at line %d!", FileName.CStr(), mTokenLine); + Char = Get(); if (OldChar != '*' || Char != '/') { if (OldChar != '/' || Char != '*') OldChar = Char; else { @@ -546,41 +568,40 @@ int inputfile::HandlePunct (festring &String, int Char, int Mode) { } if (Char == '/') { // comment (to eol) - while (!Xfeof(Buffer)) { - int ch = Xgetc(Buffer); + while (!Eof()) { + int ch = Get(); if (ch == '\n') break; } return PUNCT_CONTINUE; } - Xungc(Char, Buffer); - Xclre(Buffer); + Unget(Char); + ClearFlags(); } - if (Mode) Xungc('/', Buffer); else String << '/'; + if (Mode) Unget('/'); else String << '/'; return PUNCT_RETURN; } // if (Mode) { - Xungc(Char, Buffer); + Unget(Char); return PUNCT_RETURN; } // if (Char == '"') { // string lastWordWasString = true; - sLong StartPos = TellPos(); for (;;) { - if (Xfeof(Buffer)) ABORT("Unterminated string in file %s, beginning at line %d!", FileName.CStr(), TellLineOfPos(StartPos)); - Char = Xgetc(Buffer); + if (Eof()) ABORT("Unterminated string in file %s, beginning at line %d!", FileName.CStr(), mTokenLine); + Char = Get(); if (Char == '\\') { - Char = Xgetc(Buffer); - if (Char == EOF) ABORT("Unterminated string in file %s, beginning at line %d!", FileName.CStr(), TellLineOfPos(StartPos)); + Char = Get(); + if (Char == EOF) ABORT("Unterminated string in file %s, beginning at line %d!", FileName.CStr(), mTokenLine); switch (Char) { case 't': String << '\t'; break; case 'n': String << '\n'; break; case 'r': String << '\r'; break; case '"': String << '"'; break; default: - ABORT("Invalid escape in string in file %s at line %d!", FileName.CStr(), TellLine()); + ABORT("Invalid escape in string in file %s at line %d!", FileName.CStr(), mTokenLine); } } else if (Char == '"') { return PUNCT_RETURN; @@ -599,16 +620,16 @@ int inputfile::HandlePunct (festring &String, int Char, int Mode) { } } String << char(Char); - if (!Xfeof(Buffer)) { + if (!Eof()) { if (Char == '=' || Char == '<' || Char == '>' || Char == '!') { - Char = Xgetc(Buffer); - if (Char == '=') String << char(Char); else Xungc(Char, Buffer); + Char = Get(); + if (Char == '=') String << char(Char); else Unget(Char); } else if (Char == '&' || Char == '|') { - int ch = Xgetc(Buffer); - if (Char == ch) String << char(ch); else Xungc(ch, Buffer); + int ch = Get(); + if (Char == ch) String << char(ch); else Unget(ch); } else if (Char == ':') { - Char = Xgetc(Buffer); - if (Char == '=') String << char(Char); else Xungc(Char, Buffer); + Char = Get(); + if (Char == '=') String << char(Char); else Unget(Char); } } return PUNCT_RETURN; @@ -617,22 +638,28 @@ int inputfile::HandlePunct (festring &String, int Char, int Mode) { void inputfile::readWordIntr (festring &String, truth AbortOnEOF) { int Mode = 0; + // String.Empty(); lastWordWasString = false; - for (int Char = Xgetc(Buffer); !Xfeof(Buffer); Char = Xgetc(Buffer)) { + mTokenLine = mCurrentLine; + for (int Char = Get(); !Eof(); Char = Get()) { if (isalpha(Char) || Char == '_') { - if (!Mode) Mode = MODE_WORD; - else if (Mode == MODE_NUMBER) { - Xungc(Char, Buffer); + if (!Mode) { + mTokenLine = mCurrentLine; + Mode = MODE_WORD; + } else if (Mode == MODE_NUMBER) { + Unget(Char); return; } String << char(Char); continue; } if (isdigit(Char)) { - if (!Mode) Mode = MODE_NUMBER; - else if (Mode == MODE_WORD) { - Xungc(Char, Buffer); + if (!Mode) { + mTokenLine = mCurrentLine; + Mode = MODE_NUMBER; + } else if (Mode == MODE_WORD) { + Unget(Char); return; } String << char(Char); @@ -642,23 +669,24 @@ void inputfile::readWordIntr (festring &String, truth AbortOnEOF) { if (ispunct(Char) && HandlePunct(String, Char, Mode) == PUNCT_RETURN) return; } if (AbortOnEOF) ABORT("Unexpected end of file %s!", FileName.CStr()); - if (Mode) Xclre(Buffer); + if (Mode) ClearFlags(); } char inputfile::ReadLetter (truth AbortOnEOF) { - for (int Char = Xgetc(Buffer); !Xfeof(Buffer); Char = Xgetc(Buffer)) { + mTokenLine = mCurrentLine; + for (int Char = Get(); !Eof(); mTokenLine = mCurrentLine, Char = Get()) { if (isalpha(Char) || isdigit(Char)) return Char; if (ispunct(Char)) { if (Char == '/') { - if (!Xfeof(Buffer)) { - Char = Xgetc(Buffer); + if (!Eof()) { + Char = Get(); if (Char == '*') { - sLong StartPos = TellPos(); int OldChar = 0, CommentLevel = 1; + // for (;;) { - if (Xfeof(Buffer)) ABORT("Unterminated comment in file %s, beginning at line %d!", FileName.CStr(), TellLineOfPos(StartPos)); - Char = Xgetc(Buffer); + if (Eof()) ABORT("Unterminated comment in file %s, beginning at line %d!", FileName.CStr(), mTokenLine); + Char = Get(); if (OldChar != '*' || Char != '/') { if (OldChar != '/' || Char != '*') OldChar = Char; else { @@ -672,7 +700,7 @@ char inputfile::ReadLetter (truth AbortOnEOF) { } continue; } else { - Xungc(Char, Buffer); + Unget(Char); } } return '/'; @@ -690,13 +718,14 @@ char inputfile::ReadLetter (truth AbortOnEOF) { //sLong inputfile::ReadNumber (int CallLevel, truth PreserveTerminator) { festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, truth allowStr, truth PreserveTerminator, truth *wasCloseBrc) { sLong Value = 0; - festring Word; + festring Word, res; truth NumberCorrect = false; truth firstWord = true; + // *isString = false; *num = 0; if (wasCloseBrc) *wasCloseBrc = false; - festring res; + mTokenLine = mCurrentLine; for (;;) { ReadWord(Word); if (Word == "@") { @@ -718,7 +747,7 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, *isString = true; return Word; } else { - ABORT("Number expected in file %s, line %d!", FileName.CStr(), TellLine()); + ABORT("Number expected in file %s, line %d!", FileName.CStr(), mTokenLine); } } if (firstWord) { @@ -727,11 +756,11 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, ReadWord(res); if (res.GetSize() == 1) { if (res[0] != ';' && res[0] != ',' && res[0] != ':') { - ABORT("Invalid terminator in file %s, line %d!", FileName.CStr(), TellLine()); + ABORT("Invalid terminator in file %s, line %d!", FileName.CStr(), mTokenLine); } - if (PreserveTerminator) Xungc(res[0], Buffer); + if (PreserveTerminator) Unget(res[0]); } else { - ABORT("Terminator expected in file %s, line %d!", FileName.CStr(), TellLine()); + ABORT("Terminator expected in file %s, line %d!", FileName.CStr(), mTokenLine); } return Word; } @@ -746,12 +775,12 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, if (Word.GetSize() == 1) { if (First == ';' || First == ',' || First == ':' || (wasCloseBrc && First == '}')) { if (First == '}' && wasCloseBrc) *wasCloseBrc = true; - if (CallLevel != HIGHEST || PreserveTerminator) Xungc(First, Buffer); + if (CallLevel != HIGHEST || PreserveTerminator) Unget(First); *num = Value; return res; } if (First == ')') { - if ((CallLevel != HIGHEST && CallLevel != 4) || PreserveTerminator) Xungc(')', Buffer); + if ((CallLevel != HIGHEST && CallLevel != 4) || PreserveTerminator) Unget(')'); *num = Value; return res; } @@ -768,7 +797,7 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, NumberCorrect = true;\ continue;\ } else {\ - Xungc(#op[0], Buffer);\ + Unget(#op[0]);\ *num = Value;\ return res;\ } \ @@ -784,12 +813,12 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, NumberCorrect = true; continue; } else { - Xungc('<', Buffer); - Xungc('<', Buffer); + Unget('<'); + Unget('<'); *num = Value; return res; } else { - Xungc(Next, Buffer); + Unget(Next); } } if (First == '>') { @@ -800,17 +829,17 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, NumberCorrect = true; continue; } else { - Xungc('>', Buffer); - Xungc('>', Buffer); + Unget('>'); + Unget('>'); *num = Value; return res; } else { - Xungc(Next, Buffer); + Unget(Next); } } if (First == '(') { if (NumberCorrect) { - Xungc('(', Buffer); + Unget('('); *num = Value; return res; } else { @@ -822,14 +851,14 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, if (First == '=' && CallLevel == HIGHEST) continue; if (First == '#') { // for #defines - Xungc('#', Buffer); + Unget('#'); *num = Value; return res; } } /* if (Word == "enum" || Word == "bitenum") { - if (CallLevel != HIGHEST || PreserveTerminator) Xungc(';', Buffer); + if (CallLevel != HIGHEST || PreserveTerminator) Unget(';'); *num = Value; return res; } @@ -847,7 +876,7 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, int Blue = ReadNumber(); Value = MakeRGB24(Red, Green, Blue); } else { - ABORT("Illegal RGB bit size %d in file %s, line %d!", Bits, FileName.CStr(), TellLine()); + ABORT("Illegal RGB bit size %d in file %s, line %d!", Bits, FileName.CStr(), mTokenLine); } NumberCorrect = true; continue; @@ -870,8 +899,7 @@ festring inputfile::ReadNumberIntr (int CallLevel, sLong *num, truth *isString, continue; } } - ABORT("Odd numeric value \"%s\" encountered in file %s, line %d!", - Word.CStr(), FileName.CStr(), TellLine()); + ABORT("Odd numeric value \"%s\" encountered in file %s, line %d!", Word.CStr(), FileName.CStr(), mTokenLine); } } @@ -881,15 +909,16 @@ festring inputfile::ReadCode (truth AbortOnEOF) { char inString = 0; festring res; // - for (char Char = Xgetc(Buffer); !Xfeof(Buffer); Char = Xgetc(Buffer)) { + mTokenLine = mCurrentLine; + for (int Char = Get(); !Eof(); Char = Get()) { //fprintf(stderr, "char: [%c]; inString: %d; sqLevel: %d\n", (Char < 32 || Char > 126 ? '?' : Char), inString, sqLevel); if (inString) { res << Char; if (Char == inString) { inString = 0; } else if (Char == '\\') { - if (Xfeof(Buffer)) break; - Char = Xgetc(Buffer); + if (Eof()) break; + Char = Get(); res << Char; } } else { @@ -900,16 +929,16 @@ festring inputfile::ReadCode (truth AbortOnEOF) { if (--sqLevel == 0) break; res << Char; } else if (Char == '/') { - if (Xfeof(Buffer)) { res << Char; break; } - switch ((Char = Xgetc(Buffer))) { + if (Eof()) { res << Char; break; } + switch ((Char = Get())) { case '/': // eol comment - while (!Xfeof(Buffer)) if (Xgetc(Buffer) == '\n') break; + while (!Eof()) if (Get() == '\n') break; break; case '*': // c-like comment - while (!Xfeof(Buffer)) { - if (Xgetc(Buffer) == '*') { - if (Xfeof(Buffer)) break; - if (Xgetc(Buffer) == '/') break; + while (!Eof()) { + if (Get() == '*') { + if (Eof()) break; + if (Get() == '/') break; } } break; @@ -926,7 +955,7 @@ festring inputfile::ReadCode (truth AbortOnEOF) { } } } - if (AbortOnEOF && Xfeof(Buffer)) ABORT("Unexpected end of file %s!", FileName.CStr()); + if (AbortOnEOF && Eof()) ABORT("Unexpected end of file %s!", FileName.CStr()); return res; } @@ -934,6 +963,7 @@ festring inputfile::ReadCode (truth AbortOnEOF) { sLong inputfile::ReadNumber (int CallLevel, truth PreserveTerminator, truth *wasCloseBrc) { sLong num = 0; truth isString = false; + // ReadNumberIntr(CallLevel, &num, &isString, false, PreserveTerminator, wasCloseBrc); return num; } @@ -946,6 +976,7 @@ festring inputfile::ReadStringOrNumber (sLong *num, truth *isString, truth Prese v2 inputfile::ReadVector2d () { v2 Vector; + // Vector.X = ReadNumber(); Vector.Y = ReadNumber(); return Vector; @@ -954,6 +985,7 @@ v2 inputfile::ReadVector2d () { rect inputfile::ReadRect () { rect Rect; + // Rect.X1 = ReadNumber(); Rect.Y1 = ReadNumber(); Rect.X2 = ReadNumber(); @@ -1024,7 +1056,7 @@ void ReadData (fearray &Array, inputfile &SaveFile) { Array.Data[0] = SaveFile.ReadNumber(); } else if (Word == ":=") { SaveFile.ReadWord(Word); - if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); // std::vector v; // @@ -1038,13 +1070,13 @@ void ReadData (fearray &Array, inputfile &SaveFile) { for (unsigned int f = 0; f < v.size(); ++f) Array.Data[f] = v[f]; } else if (Word == "=") { SaveFile.ReadWord(Word); - if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); fearray::sizetype Size = SaveFile.ReadNumber(); Array.Allocate(Size); for (fearray::sizetype c = 0; c < Size; ++c) Array.Data[c] = SaveFile.ReadNumber(); - if (SaveFile.ReadWord() != "}") ABORT("Illegal array terminator \"%s\" encountered in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (SaveFile.ReadWord() != "}") ABORT("Illegal array terminator \"%s\" encountered in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } else { - ABORT("Array syntax error: '=', '==' or ':=' expected in file %s, line %d!", SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + ABORT("Array syntax error: '=', '==' or ':=' expected in file %s, line %d!", SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } } @@ -1056,10 +1088,10 @@ void ReadData (fearray &Array, inputfile &SaveFile) { if (Word == "==") { Array.Allocate(1); SaveFile.ReadWord(Array.Data[0]); - if (SaveFile.ReadWord() != ";") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (SaveFile.ReadWord() != ";") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } else if (Word == ":=") { SaveFile.ReadWord(Word); - if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); // std::vector v; // @@ -1069,35 +1101,37 @@ void ReadData (fearray &Array, inputfile &SaveFile) { v.push_back(Word); SaveFile.ReadWord(Word); if (Word == "}") break; - if (Word != "," && Word != ";") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != "," && Word != ";") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } Array.Allocate(v.size()); for (unsigned int f = 0; f < v.size(); ++f) Array.Data[f] = v[f]; } else if (Word == "=") { SaveFile.ReadWord(Word); - if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); fearray::sizetype Size = SaveFile.ReadNumber(); Array.Allocate(Size); for (fearray::sizetype c = 0; c < Size; ++c) { SaveFile.ReadWord(Array.Data[c]); SaveFile.ReadWord(Word); - if (Word != "," && Word != ";") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != "," && Word != ";") ABORT("Array syntax error \"%s\" found in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } - if (SaveFile.ReadWord() != "}") ABORT("Illegal array terminator \"%s\" encountered in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (SaveFile.ReadWord() != "}") ABORT("Illegal array terminator \"%s\" encountered in file %s, line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } else { - ABORT("Array syntax error: '=', '==' or ':=' expected in file %s, line %d!", SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + ABORT("Array syntax error: '=', '==' or ':=' expected in file %s, line %d!", SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } } +/* feuLong inputfile::TellLineOfPos (sLong Pos) { feuLong Line = 1; sLong BackupPos = TellPos(); SeekPosBegin(0); - while (TellPos() != Pos) { if (Xgetc(Buffer) == '\n') ++Line; } + while (TellPos() != Pos) { if (Get() == '\n') ++Line; } if (TellPos() != BackupPos) SeekPosBegin(BackupPos); return Line; } +*/ //////////////////////////////////////////////////////////////////////////////// diff --git a/src/felib/fesave.h b/src/felib/fesave.h index 5c35063..ff77381 100644 --- a/src/felib/fesave.h +++ b/src/felib/fesave.h @@ -89,7 +89,7 @@ public: v2 ReadVector2d (); rect ReadRect (); int Get (); - int Unget (int ch); + void Unget (int ch); void Read (char *Offset, sLong Size); truth IsOpen () { return (Buffer != 0); } truth Eof (); @@ -98,8 +98,8 @@ public: void SeekPosCurrent (sLong Offset); void SeekPosEnd (sLong Offset); sLong TellPos (); - feuLong TellLine () { return TellLineOfPos(TellPos()); } - feuLong TellLineOfPos (sLong); + //feuLong TellLine () { return TellLineOfPos(TellPos()); } + //feuLong TellLineOfPos (sLong); cfestring &GetFileName () const { return FileName; } void Close (); @@ -114,6 +114,8 @@ public: void die (cfestring &msg); + inline int TokenLine () const { return mTokenLine; } + protected: festring ReadNumberIntr (int CallLevel, sLong *num, truth *isString, truth allowStr, truth PreserveTerminator, truth *wasCloseBrc); int HandlePunct (festring &String, int Char, int Mode); @@ -139,6 +141,10 @@ protected: #ifdef USE_ZLIB int mFileSize; #endif + int mCharBuf[4]; + int mCharBufPos; + int mCurrentLine; + int mTokenLine; }; @@ -188,14 +194,14 @@ template inline void ReadData (fearray &Array, inputfile &Sav ReadData(Array.Data[0], SaveFile); return; } - if (Word != "=") ABORT("Array syntax error: '=' or '==' expected in file %s, line %u!", SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != "=") ABORT("Array syntax error: '=' or '==' expected in file %s, line %u!", SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); SaveFile.ReadWord(Word); - if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %u!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != "{") ABORT("Array syntax error \"%s\" found in file %s, line %u!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); typedef typename fearray::sizetype sizetype; sizetype Size = SaveFile.ReadNumber(); Array.Allocate(Size); for (sizetype c = 0; c < Size; ++c) ReadData(Array.Data[c], SaveFile); - if (SaveFile.ReadWord() != "}") ABORT("Illegal array terminator \"%s\" encountered in file %s, line %u!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (SaveFile.ReadWord() != "}") ABORT("Illegal array terminator \"%s\" encountered in file %s, line %u!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } diff --git a/src/game/database.cpp b/src/game/database.cpp index e4e8e62..93f1db9 100644 --- a/src/game/database.cpp +++ b/src/game/database.cpp @@ -46,13 +46,13 @@ static void collectHandler (festring &dest, std::stack &infStack, i inputfile *inFile = *iff; festring Word = inFile->ReadWord(true); dest << "on " << Word << "\n{\n"; - if (inFile->ReadWord() != "{") ABORT("'{' missing in datafile %s line %d!", inFile->GetFileName().CStr(), inFile->TellLine()); + if (inFile->ReadWord() != "{") ABORT("'{' missing in datafile %s line %d!", inFile->GetFileName().CStr(), inFile->TokenLine()); int cnt = 1; truth inStr = false; for (;;) { int ch = inFile->Get(); if (ch == EOF) { - if (infStack.empty()) ABORT("'}' missing in datafile %s line %d!", inFile->GetFileName().CStr(), inFile->TellLine()); + if (infStack.empty()) ABORT("'}' missing in datafile %s line %d!", inFile->GetFileName().CStr(), inFile->TokenLine()); delete inFile; *iff = inFile = infStack.top(); infStack.pop(); @@ -125,7 +125,7 @@ template void databasecreator::ReadFrom (const festring &base for (inFile->ReadWord(Word, false); !inFile->Eof(); inFile->ReadWord(Word, false)) { if (Word == "Include") { Word = inFile->ReadWord(); - if (inFile->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", inFile->GetFileName().CStr(), inFile->TellLine()); + if (inFile->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", inFile->GetFileName().CStr(), inFile->TokenLine()); //fprintf(stderr, "loading: %s\n", Word.CStr()); inputfile *incf = new inputfile(game::GetGameDir()+"Script/"+Word, &game::GetGlobalValueMap()); infStack.push(inFile); @@ -135,7 +135,7 @@ template void databasecreator::ReadFrom (const festring &base } if (Word == "Message") { Word = inFile->ReadWord(); - if (inFile->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", inFile->GetFileName().CStr(), inFile->TellLine()); + if (inFile->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", inFile->GetFileName().CStr(), inFile->TokenLine()); fprintf(stderr, "MESSAGE: %s\n", Word.CStr()); continue; } @@ -151,19 +151,19 @@ template void databasecreator::ReadFrom (const festring &base //////// defName = Word; int Type = protocontainer::SearchCodeName(Word); - if (!Type) ABORT("Odd term <%s> encountered in %s datafile %s line %d!", Word.CStr(), protocontainer::GetMainClassID(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (!Type) ABORT("Odd term <%s> encountered in %s datafile %s line %d!", Word.CStr(), protocontainer::GetMainClassID(), inFile->GetFileName().CStr(), inFile->TokenLine()); prototype *Proto = protocontainer::GetProtoData()[Type]; - if (!Proto) ABORT("Something weird with <%s> in file %s at line %d!", defName.CStr(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (!Proto) ABORT("Something weird with <%s> in file %s at line %d!", defName.CStr(), inFile->GetFileName().CStr(), inFile->TokenLine()); database *DataBase; int Configs; if (doOverride) { - if (!Proto->ConfigData) ABORT("Can't override undefined <%s> in file %s at line %d!", defName.CStr(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (!Proto->ConfigData) ABORT("Can't override undefined <%s> in file %s at line %d!", defName.CStr(), inFile->GetFileName().CStr(), inFile->TokenLine()); delete [] Proto->ConfigData; Proto->ConfigData = NULL; Proto->ConfigSize = 0; } if (doExtend) { - if (!Proto->ConfigData) ABORT("Can't extend undefined <%s> in file %s at line %d!", defName.CStr(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (!Proto->ConfigData) ABORT("Can't extend undefined <%s> in file %s at line %d!", defName.CStr(), inFile->GetFileName().CStr(), inFile->TokenLine()); DataBase = Proto->ConfigData[0]; Configs = Proto->ConfigSize; for (int f = 0; f < Configs; f++) TempConfig[f] = Proto->ConfigData[f]; @@ -171,19 +171,19 @@ template void databasecreator::ReadFrom (const festring &base Proto->ConfigData = NULL; Proto->ConfigSize = 0; } else { - if (Proto->ConfigData) ABORT("Can't redefine <%s> in file %s at line %d!", defName.CStr(), inFile->GetFileName().CStr(), inFile->TellLine()); - if (Proto->Base && !Proto->Base->ConfigData) ABORT("Database has no description of base prototype <%s> in file %s at line %d!", Proto->Base->GetClassID(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (Proto->ConfigData) ABORT("Can't redefine <%s> in file %s at line %d!", defName.CStr(), inFile->GetFileName().CStr(), inFile->TokenLine()); + if (Proto->Base && !Proto->Base->ConfigData) ABORT("Database has no description of base prototype <%s> in file %s at line %d!", Proto->Base->GetClassID(), inFile->GetFileName().CStr(), inFile->TokenLine()); DataBase = Proto->Base ? new database(**Proto->Base->ConfigData) : new database; DataBase->InitDefaults(Proto, 0); TempConfig[0] = DataBase; Configs = 1; } - if (inFile->ReadWord() != "{") ABORT("'{' missing in %s datafile %s line %d!", protocontainer::GetMainClassID(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (inFile->ReadWord() != "{") ABORT("'{' missing in %s datafile %s line %d!", protocontainer::GetMainClassID(), inFile->GetFileName().CStr(), inFile->TokenLine()); //for (inFile->ReadWord(Word); Word != "}"; inFile->ReadWord(Word)) for (;;) { inFile->ReadWord(Word, false); if (Word == "" && inFile->Eof()) { - if (infStack.empty()) ABORT("'}' missing in %s datafile %s line %d!", protocontainer::GetMainClassID(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (infStack.empty()) ABORT("'}' missing in %s datafile %s line %d!", protocontainer::GetMainClassID(), inFile->GetFileName().CStr(), inFile->TokenLine()); delete inFile; inFile = infStack.top(); infStack.pop(); @@ -194,7 +194,7 @@ template void databasecreator::ReadFrom (const festring &base // if (Word == "Include") { Word = inFile->ReadWord(); - if (inFile->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", inFile->GetFileName().CStr(), inFile->TellLine()); + if (inFile->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", inFile->GetFileName().CStr(), inFile->TokenLine()); //fprintf(stderr, "loading: %s\n", Word.CStr()); inputfile *incf = new inputfile(game::GetGameDir()+"Script/"+Word, &game::GetGlobalValueMap()); infStack.push(inFile); @@ -204,7 +204,7 @@ template void databasecreator::ReadFrom (const festring &base } if (Word == "Message") { Word = inFile->ReadWord(); - if (inFile->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", inFile->GetFileName().CStr(), inFile->TellLine()); + if (inFile->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", inFile->GetFileName().CStr(), inFile->TokenLine()); fprintf(stderr, "MESSAGE: %s\n", Word.CStr()); continue; } @@ -224,13 +224,13 @@ template void databasecreator::ReadFrom (const festring &base database *ConfigDataBase = new database(*Proto->ChooseBaseForConfig(TempConfig, Configs, ConfigNumber)); ConfigDataBase->InitDefaults(Proto, ConfigNumber); TempConfig[Configs++] = ConfigDataBase; - if (inFile->ReadWord() != "{") ABORT("'{' missing in %s datafile %s line %d!", protocontainer::GetMainClassID(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (inFile->ReadWord() != "{") ABORT("'{' missing in %s datafile %s line %d!", protocontainer::GetMainClassID(), inFile->GetFileName().CStr(), inFile->TokenLine()); for (inFile->ReadWord(Word); Word != "}"; inFile->ReadWord(Word)) { if (Word == "on") { collectHandler(Proto->mOnEvents, infStack, &inFile); continue; } - if (!AnalyzeData(*inFile, Word, *ConfigDataBase)) ABORT("Illegal datavalue %s found while building up %s config #%d, file %s, line %d!", Word.CStr(), Proto->GetClassID(), ConfigNumber, inFile->GetFileName().CStr(), inFile->TellLine()); + if (!AnalyzeData(*inFile, Word, *ConfigDataBase)) ABORT("Illegal datavalue %s found while building up %s config #%d, file %s, line %d!", Word.CStr(), Proto->GetClassID(), ConfigNumber, inFile->GetFileName().CStr(), inFile->TokenLine()); } ConfigDataBase->PostProcess(); } @@ -240,7 +240,7 @@ template void databasecreator::ReadFrom (const festring &base collectHandler(Proto->mOnEvents, infStack, &inFile); continue; } - if (!AnalyzeData(*inFile, Word, *DataBase)) ABORT("Illegal datavalue %s found while building up %s, file %s, line %d!", Word.CStr(), Proto->GetClassID(), inFile->GetFileName().CStr(), inFile->TellLine()); + if (!AnalyzeData(*inFile, Word, *DataBase)) ABORT("Illegal datavalue %s found while building up %s, file %s, line %d!", Word.CStr(), Proto->GetClassID(), inFile->GetFileName().CStr(), inFile->TokenLine()); } DataBase->PostProcess(); //Configs = Proto->CreateSpecialConfigurations(TempConfig, Configs); diff --git a/src/game/game.cpp b/src/game/game.cpp index 7c8b858..ef337e4 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1370,7 +1370,7 @@ void game::LoadGlobalValueMap (inputfile &fl) { for (fl.ReadWord(word, false); !fl.Eof(); fl.ReadWord(word, false)) { if (word == "Include") { word = fl.ReadWord(); - if (fl.ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", fl.GetFileName().CStr(), fl.TellLine()); + if (fl.ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", fl.GetFileName().CStr(), fl.TokenLine()); //fprintf(stderr, "loading: %s\n", word.CStr()); inputfile incf(game::GetGameDir()+"Script/"+word, &game::GetGlobalValueMap()); LoadGlobalValueMap(incf); @@ -1378,16 +1378,16 @@ void game::LoadGlobalValueMap (inputfile &fl) { } if (word == "Message") { word = fl.ReadWord(); - if (fl.ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", fl.GetFileName().CStr(), fl.TellLine()); + if (fl.ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", fl.GetFileName().CStr(), fl.TokenLine()); fprintf(stderr, "MESSAGE: %s\n", word.CStr()); continue; } - if (word != "#") ABORT("Illegal datafile define in file %s on line %d!", fl.GetFileName().CStr(), fl.TellLine()); + if (word != "#") ABORT("Illegal datafile define in file %s on line %d!", fl.GetFileName().CStr(), fl.TokenLine()); fl.ReadWord(word, true); if (word == "enum" || word == "bitenum") { truth isBit = word == "bitenum"; sLong idx = 0; - if (fl.ReadWord() != "{") ABORT("'{' expected in file %s at line %d!", fl.GetFileName().CStr(), fl.TellLine()); + if (fl.ReadWord() != "{") ABORT("'{' expected in file %s at line %d!", fl.GetFileName().CStr(), fl.TokenLine()); festring idName; truth done = false; while (!done) { @@ -1403,7 +1403,7 @@ void game::LoadGlobalValueMap (inputfile &fl) { // set current index idx = fl.ReadNumber(); } else { - if (word != "," && word != ";" && word != "}") ABORT("',' expected in file %s at line %d!", fl.GetFileName().CStr(), fl.TellLine()); + if (word != "," && word != ";" && word != "}") ABORT("',' expected in file %s at line %d!", fl.GetFileName().CStr(), fl.TokenLine()); if (word == "}") done = true; } if (idName.GetSize() > 0) { @@ -1416,7 +1416,7 @@ void game::LoadGlobalValueMap (inputfile &fl) { fl.SkipSpaces(); int ch = fl.Get(); if (ch != EOF && ch != ';') fl.Unget(ch); - //if (fl.ReadWord() != ";") ABORT("';' expected in file %s at line %d!", fl.GetFileName().CStr(), fl.TellLine()); + //if (fl.ReadWord() != ";") ABORT("';' expected in file %s at line %d!", fl.GetFileName().CStr(), fl.TokenLine()); continue; } if (word == "define") { @@ -1425,7 +1425,7 @@ void game::LoadGlobalValueMap (inputfile &fl) { GlobalValueMap.insert(std::make_pair(word, v)); continue; } - ABORT("Illegal datafile define in file %s on line %d!", fl.GetFileName().CStr(), fl.TellLine()); + ABORT("Illegal datafile define in file %s on line %d!", fl.GetFileName().CStr(), fl.TokenLine()); } } @@ -3135,7 +3135,7 @@ int game::ParseFuncArgs (cfestring &types, std::vector &args, inputfile if (isStr) args.push_back(FuncArg(s)); else args.push_back(FuncArg(n)); fl->ReadWord(s, true); if (s == ";") return args.size(); - if (s != ",") ABORT("',' expected in file %s line %d!", fl->GetFileName().CStr(), fl->TellLine()); + if (s != ",") ABORT("',' expected in file %s line %d!", fl->GetFileName().CStr(), fl->TokenLine()); } // never reached case 's': @@ -3147,11 +3147,11 @@ int game::ParseFuncArgs (cfestring &types, std::vector &args, inputfile if (f == types.GetSize()-1) { if (noterm) break; fl->ReadWord(s, true); - if (s != ";") ABORT("';' expected in file %s line %d!", fl->GetFileName().CStr(), fl->TellLine()); + if (s != ";") ABORT("';' expected in file %s line %d!", fl->GetFileName().CStr(), fl->TokenLine()); break; } else { fl->ReadWord(s, true); - if (s != ",") ABORT("',' expected in file %s line %d!", fl->GetFileName().CStr(), fl->TellLine()); + if (s != ",") ABORT("',' expected in file %s line %d!", fl->GetFileName().CStr(), fl->TokenLine()); } } return args.size(); @@ -3170,7 +3170,7 @@ truth game::GetWord (festring &w) { } if (w == "Include") { fl->ReadWord(w, true); - if (fl->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", fl->GetFileName().CStr(), fl->TellLine()); + if (fl->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", fl->GetFileName().CStr(), fl->TokenLine()); w = game::GetGameDir()+"Script/"+w; inputfile *fl = new inputfile(w, &game::GetGlobalValueMap(), true); fl->setGetVarCB(game::ldrGetVar); @@ -3179,7 +3179,7 @@ truth game::GetWord (festring &w) { } if (w == "Message") { fl->ReadWord(w, true); - if (fl->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", fl->GetFileName().CStr(), fl->TellLine()); + if (fl->ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", fl->GetFileName().CStr(), fl->TokenLine()); fprintf(stderr, "MESSAGE: %s\n", w.CStr()); continue; } @@ -3192,7 +3192,7 @@ void game::SkipBlock (truth brcEaten) { festring w; if (!brcEaten) { mFEStack.top()->ReadWord(w, true); - if (w != "{") ABORT("'{' expected in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + if (w != "{") ABORT("'{' expected in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); } int cnt = 1; for (;;) { @@ -3211,7 +3211,7 @@ truth game::DoOnEvent (truth brcEaten, truth AllowScript) { festring w; if (!brcEaten) { mFEStack.top()->ReadWord(w, true); - if (w != "{") ABORT("'{' expected in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + if (w != "{") ABORT("'{' expected in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); } for (;;) { if (!GetWord(w)) { @@ -3220,13 +3220,13 @@ truth game::DoOnEvent (truth brcEaten, truth AllowScript) { } //fprintf(stderr, " :[%s]\n", w.CStr()); if (w == "}") { - if (AllowScript) ABORT("Unexpected '}' in AllowScript file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + if (AllowScript) ABORT("Unexpected '}' in AllowScript file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); break; } if (w == ";") continue; if (w == "@") { mFEStack.top()->ReadWord(w, true); - if (mFEStack.top()->ReadWord(true) != "=") ABORT("'=' expected in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + if (mFEStack.top()->ReadWord(true) != "=") ABORT("'=' expected in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); //fprintf(stderr, "setvar: %s\n", w.CStr()); if (w == "money") { sLong n = mFEStack.top()->ReadNumber(true); @@ -3238,7 +3238,7 @@ truth game::DoOnEvent (truth brcEaten, truth AllowScript) { mResult = mFEStack.top()->ReadNumber(true); continue; } - ABORT("Unknown var [%s] in file %s at line %d!", w.CStr(), mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + ABORT("Unknown var [%s] in file %s at line %d!", w.CStr(), mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); } else { //mFEStack.top()->ReadWord(w, true); std::vector args; @@ -3267,19 +3267,19 @@ truth game::DoOnEvent (truth brcEaten, truth AllowScript) { continue; } if (w == "EatThisEvent") { - if (AllowScript) ABORT("'EatThisEvent' forbidden in AllowScripts in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + if (AllowScript) ABORT("'EatThisEvent' forbidden in AllowScripts in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); eaten = true; continue; } if (w == "Disallow") { - if (!AllowScript) ABORT("'Disallow' forbidden in not-AllowScripts in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + if (!AllowScript) ABORT("'Disallow' forbidden in not-AllowScripts in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); eaten = false; continue; } - ABORT("Unknown function [%s] in file %s at line %d!", w.CStr(), mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); - //if (mFEStack.top()->ReadWord() != ";") ABORT("';' expected in file %s line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + ABORT("Unknown function [%s] in file %s at line %d!", w.CStr(), mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); + //if (mFEStack.top()->ReadWord() != ";") ABORT("';' expected in file %s line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); } - //ABORT("Invalid term in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + //ABORT("Invalid term in file %s at line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); } //fprintf(stderr, "------------\n"); return eaten; @@ -3330,7 +3330,7 @@ truth game::RunOnEvent (cfestring &ename) { // festring w; while (GetWord(w)) { - if (w != "on") ABORT("'on' expected in file %s line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + if (w != "on") ABORT("'on' expected in file %s line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); mFEStack.top()->ReadWord(w, true); truth doIt = (w==ename); if (doIt && !res) { @@ -3357,7 +3357,7 @@ truth game::RunOnEventStr (cfestring &ename, cfestring &str) { //fprintf(stderr, "event: [%s]\n", ename.CStr()); //fprintf(stderr, "---\n%s---\n", str.CStr()); while (GetWord(w)) { - if (w != "on") ABORT("'on' expected in file %s line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TellLine()); + if (w != "on") ABORT("'on' expected in file %s line %d!", mFEStack.top()->GetFileName().CStr(), mFEStack.top()->TokenLine()); mFEStack.top()->ReadWord(w, true); //fprintf(stderr, "on: [%s]\n", w.CStr()); truth doIt = (w==ename); diff --git a/src/game/script.cpp b/src/game/script.cpp index 63562d6..9cf5e2f 100644 --- a/src/game/script.cpp +++ b/src/game/script.cpp @@ -225,12 +225,12 @@ void materialscript::ReadFrom (inputfile &SaveFile) { valuemap::const_iterator i = game::GetGlobalValueMap().find(Word); // if (i != game::GetGlobalValueMap().end()) Config = i->second; - else ABORT("Unconfigured material script detected at line %d!", SaveFile.TellLine()); + else ABORT("Unconfigured material script detected at line %d!", SaveFile.TokenLine()); } if (SaveFile.ReadWord() != "{") return; for (SaveFile.ReadWord(Word); Word != "}"; SaveFile.ReadWord(Word)) { if (!ReadMember(SaveFile, Word)) { - ABORT("Odd script term %s encountered in material script line %d!", Word.CStr(), SaveFile.TellLine()); + ABORT("Odd script term %s encountered in material script line %d!", Word.CStr(), SaveFile.TokenLine()); } } } @@ -299,7 +299,7 @@ void basecontentscript::ReadFrom (inputfile &SaveFile) { Random = false; ContentType = SearchCodeName(Word); if (ContentType || Word == "0") SaveFile.ReadWord(Word); - else ABORT("Odd script term %s encountered in %s content script, file %s line %d!", Word.CStr(), GetClassID(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + else ABORT("Odd script term %s encountered in %s content script, file %s line %d!", Word.CStr(), GetClassID(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } if (Word == "(") { Config = SaveFile.ReadNumber(); @@ -309,14 +309,14 @@ void basecontentscript::ReadFrom (inputfile &SaveFile) { } if (Word == "{") { for (SaveFile.ReadWord(Word); Word != "}"; SaveFile.ReadWord(Word)) { - if (!ReadMember(SaveFile, Word)) ABORT("Odd script term %s encountered in %s content script, file %s line %d!", Word.CStr(), GetClassID(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (!ReadMember(SaveFile, Word)) ABORT("Odd script term %s encountered in %s content script, file %s line %d!", Word.CStr(), GetClassID(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } } else { if (Word == "[") { mCode = SaveFile.ReadCode(); SaveFile.ReadWord(Word); } - if (Word != ";" && Word != ",") ABORT("Odd terminator %s encountered in %s content script, file %s line %d!", Word.CStr(), GetClassID(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (Word != ";" && Word != ",") ABORT("Odd terminator %s encountered in %s content script, file %s line %d!", Word.CStr(), GetClassID(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } } @@ -578,9 +578,9 @@ void squarescript::ReadFrom (inputfile &SaveFile) { SaveFile.ReadWord(Word); if (Word != "=") { PositionHolder.ReadFrom(SaveFile); - if (SaveFile.ReadWord() != "{") ABORT("Bracket missing in square script line %d!", SaveFile.TellLine()); + if (SaveFile.ReadWord() != "{") ABORT("Bracket missing in square script line %d!", SaveFile.TokenLine()); for (SaveFile.ReadWord(Word); Word != "}"; SaveFile.ReadWord(Word)) { - if (!ReadMember(SaveFile, Word)) ABORT("Odd script term %s encountered in square script line %d!", Word.CStr(), SaveFile.TellLine()); + if (!ReadMember(SaveFile, Word)) ABORT("Odd script term %s encountered in square script line %d!", Word.CStr(), SaveFile.TokenLine()); } } else { GTerrainHolder.ReadFrom(SaveFile); @@ -607,10 +607,10 @@ template void contentmap::Rea typedef typename maptype::iterator mapiterator; if(ContentMap) - ABORT("Illegal %s content map redefinition on line %d!", protocontainer::GetMainClassID(), SaveFile.TellLine()); + ABORT("Illegal %s content map redefinition on line %d!", protocontainer::GetMainClassID(), SaveFile.TokenLine()); if(SaveFile.ReadWord() != "{") - ABORT("Bracket missing in %s content map script line %d!", protocontainer::GetMainClassID(), SaveFile.TellLine()); + ABORT("Bracket missing in %s content map script line %d!", protocontainer::GetMainClassID(), SaveFile.TokenLine()); SymbolMap.insert(std::pair('.', contenttype())); static festring Word1, Word2; @@ -620,7 +620,7 @@ template void contentmap::Rea if(Word1 == "Types") { if(SaveFile.ReadWord() != "{") - ABORT("Missing bracket in %s content map script line %d!", protocontainer::GetMainClassID(), SaveFile.TellLine()); + ABORT("Missing bracket in %s content map script line %d!", protocontainer::GetMainClassID(), SaveFile.TokenLine()); for(SaveFile.ReadWord(Word2); Word2 != "}"; Word2 = SaveFile.ReadWord()) { @@ -629,21 +629,21 @@ template void contentmap::Rea if(Return.second) ReadData(Return.first->second, SaveFile); else - ABORT("Symbol %c defined again in %s content map script line %d!", Word2[0], protocontainer::GetMainClassID(), SaveFile.TellLine()); + ABORT("Symbol %c defined again in %s content map script line %d!", Word2[0], protocontainer::GetMainClassID(), SaveFile.TokenLine()); } continue; } if(!ReadMember(SaveFile, Word1)) - ABORT("Odd script term %s encountered in %s content script line %d!", Word1.CStr(), protocontainer::GetMainClassID(), SaveFile.TellLine()); + ABORT("Odd script term %s encountered in %s content script line %d!", Word1.CStr(), protocontainer::GetMainClassID(), SaveFile.TokenLine()); } v2 Size = *GetSize(); Alloc2D(ContentMap, Size.X, Size.Y); if(SaveFile.ReadWord() != "{") - ABORT("Missing bracket in %s content map script line %d!", protocontainer::GetMainClassID(), SaveFile.TellLine()); + ABORT("Missing bracket in %s content map script line %d!", protocontainer::GetMainClassID(), SaveFile.TokenLine()); for(int y = 0; y < Size.Y; ++y) for(int x = 0; x < Size.X; ++x) @@ -654,11 +654,11 @@ template void contentmap::Rea if(i != SymbolMap.end()) ContentMap[x][y] = std::make_pair(Char, &i->second); else - ABORT("Illegal content %c in %s content map line %d!", Char, protocontainer::GetMainClassID(), SaveFile.TellLine()); + ABORT("Illegal content %c in %s content map line %d!", Char, protocontainer::GetMainClassID(), SaveFile.TokenLine()); } if(SaveFile.ReadWord() != "}") - ABORT("Missing bracket in %s content map script line %d!", protocontainer::GetMainClassID(), SaveFile.TellLine()); + ABORT("Missing bracket in %s content map script line %d!", protocontainer::GetMainClassID(), SaveFile.TokenLine()); } template void contentmap::Save(outputfile& SaveFile) const @@ -721,7 +721,7 @@ void roomscript::InitDataMap() void roomscript::ReadFrom(inputfile& SaveFile) { if(SaveFile.ReadWord() != "{") - ABORT("Bracket missing in room script line %d!", SaveFile.TellLine()); + ABORT("Bracket missing in room script line %d!", SaveFile.TokenLine()); static festring Word; @@ -735,7 +735,7 @@ void roomscript::ReadFrom(inputfile& SaveFile) } if(!ReadMember(SaveFile, Word)) - ABORT("Odd script term %s encountered in room script line %d!", Word.CStr(), SaveFile.TellLine()); + ABORT("Odd script term %s encountered in room script line %d!", Word.CStr(), SaveFile.TokenLine()); } } @@ -794,7 +794,7 @@ void levelscript::InitDataMap() void levelscript::ReadFrom(inputfile& SaveFile) { if(SaveFile.ReadWord() != "{") - ABORT("Bracket missing in level script line %d!", SaveFile.TellLine()); + ABORT("Bracket missing in level script line %d!", SaveFile.TokenLine()); if(Base) { @@ -831,7 +831,7 @@ void levelscript::ReadFrom(inputfile& SaveFile) } if(!ReadMember(SaveFile, Word)) - ABORT("Odd script term %s encountered in level script line %d!", Word.CStr(), SaveFile.TellLine()); + ABORT("Odd script term %s encountered in level script line %d!", Word.CStr(), SaveFile.TokenLine()); if(Word == "Size") { @@ -920,7 +920,7 @@ void dungeonscript::InitDataMap() void dungeonscript::ReadFrom(inputfile& SaveFile) { if(SaveFile.ReadWord() != "{") - ABORT("Bracket missing in dungeon script line %d!", SaveFile.TellLine()); + ABORT("Bracket missing in dungeon script line %d!", SaveFile.TokenLine()); static festring Word; @@ -942,7 +942,7 @@ void dungeonscript::ReadFrom(inputfile& SaveFile) LS.ReadFrom(SaveFile); } else - ABORT("Level #%d defined again in dungeon script line %d!", Index, SaveFile.TellLine()); + ABORT("Level #%d defined again in dungeon script line %d!", Index, SaveFile.TokenLine()); continue; } @@ -962,7 +962,7 @@ void dungeonscript::ReadFrom(inputfile& SaveFile) } if(!ReadMember(SaveFile, Word)) - ABORT("Odd script term %s encountered in dungeon script line %d!", Word.CStr(), SaveFile.TellLine()); + ABORT("Odd script term %s encountered in dungeon script line %d!", Word.CStr(), SaveFile.TokenLine()); } } @@ -1009,7 +1009,7 @@ void teamscript::InitDataMap() void teamscript::ReadFrom(inputfile& SaveFile) { if(SaveFile.ReadWord() != "{") - ABORT("Bracket missing in team script line %d!", SaveFile.TellLine()); + ABORT("Bracket missing in team script line %d!", SaveFile.TokenLine()); static festring Word; @@ -1025,7 +1025,7 @@ void teamscript::ReadFrom(inputfile& SaveFile) } if(!ReadMember(SaveFile, Word)) - ABORT("Odd script term %s encountered in team script line %d!", Word.CStr(), SaveFile.TellLine()); + ABORT("Odd script term %s encountered in team script line %d!", Word.CStr(), SaveFile.TokenLine()); } } @@ -1059,7 +1059,7 @@ void gamescript::ReadFrom (inputfile &SaveFile) { int Index = SaveFile.ReadNumber(); std::pair::iterator, bool> Return = Dungeon.insert(std::make_pair(Index, dungeonscript())); if (Return.second) Return.first->second.ReadFrom(SaveFile); - else ABORT("Dungeon #%d defined again in game script file %s line %d!", Index, SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + else ABORT("Dungeon #%d defined again in game script file %s line %d!", Index, SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); continue; } if (Word == "Team") { @@ -1070,7 +1070,7 @@ void gamescript::ReadFrom (inputfile &SaveFile) { } if (Word == "Include") { Word = SaveFile.ReadWord(); - if (SaveFile.ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (SaveFile.ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); //fprintf(stderr, "loading: %s\n", Word.CStr()); inputfile incf(game::GetGameDir()+"Script/"+Word, &game::GetGlobalValueMap()); ReadFrom(incf); @@ -1078,11 +1078,11 @@ void gamescript::ReadFrom (inputfile &SaveFile) { } if (Word == "Message") { Word = SaveFile.ReadWord(); - if (SaveFile.ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (SaveFile.ReadWord() != ";") ABORT("Invalid terminator in file %s at line %d!", SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); fprintf(stderr, "MESSAGE: %s\n", Word.CStr()); continue; } - if (!ReadMember(SaveFile, Word)) ABORT("Odd script term %s encountered in game script file %s line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TellLine()); + if (!ReadMember(SaveFile, Word)) ABORT("Odd script term %s encountered in game script file %s line %d!", Word.CStr(), SaveFile.GetFileName().CStr(), SaveFile.TokenLine()); } } -- 2.11.4.GIT