inputfile::inputfile(const festring& FileName, const valuemap* ValueMap, truth AbortOnErr) : Buffer(fopen(FileName.CStr(), "rb")), FileName(FileName), ValueMap(ValueMap) { if(AbortOnErr && !IsOpen()) ABORT("File %s not found!", FileName.CStr()); }
void logentry::WriteLog(const festring& FileName) { FILE* LogFile = fopen(FileName.CStr(), "a"); if(!LogFile) return; festring Sep = CONST_S(":"); festring Subst = CONST_S("_"); festring::SearchAndReplace(Name, Sep, Subst); festring::SearchAndReplace(Ktyp, Sep, Subst); festring::SearchAndReplace(Kaux, Sep, Subst); festring::SearchAndReplace(Killer, Sep, Subst); festring::SearchAndReplace(Msg, Sep, Subst); festring::SearchAndReplace(Place, Sep, Subst); // XXX duplicating game::GetTime() int Hour = 12 + Tick / 2000; int Day = Hour/24 + 1; Hour %= 24; int Min = Tick % 2000 * 60 / 2000; fprintf(LogFile, "name=%s:start=%ld:end=%ld:hp=%d:mhp=%d:ktyp=%s:kaux=%s" ":killer=%s:msg=%s:place=%s:sc=%d" ":turn=%d:dur=%ld:time=Day %d, %d_%02d\n", Name.CStr(), (long)Start, (long)End, Hp, Mhp, Ktyp.CStr(), Kaux.CStr(), Killer.CStr(), Msg.CStr(), Place.CStr(), Score, Turn, (long)Dur, Day, Hour, Min ); if(fclose(LogFile)) { // error: cannot write to log } }
long inputfile::ReadNumber(int CallLevel, truth PreserveTerminator) { long Value = 0; static festring Word; truth NumberCorrect = false; for(;;) { ReadWord(Word); char First = Word[0]; if(isdigit(First)) { Value = atoi(Word.CStr()); NumberCorrect = true; continue; } if(Word.GetSize() == 1) { if(First == ';' || First == ',' || First == ':') { if(CallLevel != HIGHEST || PreserveTerminator) ungetc(First, Buffer); return Value; } if(First == ')') { if((CallLevel != HIGHEST && CallLevel != 4) || PreserveTerminator) ungetc(')', Buffer); return Value; } if(First == '~') { Value = ~ReadNumber(4); NumberCorrect = true; continue; } /* Convert this into an inline function! */ #define CHECK_OP(op, cl)\ if(First == #op[0])\ if(cl < CallLevel)\ {\ Value op##= ReadNumber(cl);\ NumberCorrect = true;\ continue;\ }\ else\ {\ ungetc(#op[0], Buffer);\ return Value;\ } CHECK_OP(&, 1); CHECK_OP(|, 1); CHECK_OP(^, 1); CHECK_OP(*, 2); CHECK_OP(/, 2); CHECK_OP(%, 2); CHECK_OP(+, 3); CHECK_OP(-, 3); if(First == '<') { char Next = Get(); if(Next == '<') if(1 < CallLevel) { Value <<= ReadNumber(1); NumberCorrect = true; continue; } else { ungetc('<', Buffer); ungetc('<', Buffer); return Value; } else ungetc(Next, Buffer); } if(First == '>') { char Next = Get(); if(Next == '>') if(1 < CallLevel) { Value >>= ReadNumber(1); NumberCorrect = true; continue; } else { ungetc('>', Buffer); ungetc('>', Buffer); return Value; } else
outputfile::outputfile(const festring& FileName, truth AbortOnErr) : Buffer(fopen(FileName.CStr(), "wb")), FileName(FileName) { if(AbortOnErr && !IsOpen()) ABORT("Can't open %s for output!", FileName.CStr()); }