status_t MediaReader::FillFileBuffer( BBuffer * buffer) { CALLED(); if (GetCurrentFile() == 0) { PRINT("\t<- B_NO_INIT\n"); return B_NO_INIT; } PRINT("\t%ld buffer bytes used, %ld buffer bytes available\n", buffer->SizeUsed(), buffer->SizeAvailable()); off_t position = GetCurrentFile()->Position(); ssize_t bytesRead = GetCurrentFile()->Read(buffer->Data(),buffer->SizeAvailable()); if (bytesRead < 0) { PRINT("\t<- B_FILE_ERROR\n"); return B_FILE_ERROR; // some sort of file related error } PRINT("\t%ld file bytes read at position %ld.\n", bytesRead, position); buffer->SetSizeUsed(bytesRead); media_header * header = buffer->Header(); header->type = B_MEDIA_MULTISTREAM; header->size_used = bytesRead; header->file_pos = position; header->orig_size = bytesRead; header->time_source = TimeSource()->ID(); header->start_time = TimeSource()->Now(); // nothing more to say? return B_OK; }
void Internal (const char* Format, ...) /* Print a message about an internal compiler error and die. */ { va_list ap; const char* FileName; unsigned LineNum; if (CurTok.LI) { FileName = GetInputName (CurTok.LI); LineNum = GetInputLine (CurTok.LI); } else { FileName = GetCurrentFile (); LineNum = GetCurrentLine (); } fprintf (stderr, "%s(%u): Internal compiler error:\n", FileName, LineNum); va_start (ap, Format); vfprintf (stderr, Format, ap); va_end (ap); fprintf (stderr, "\n"); if (Line) { fprintf (stderr, "\nInput: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line)); } /* Use abort to create a core dump */ abort (); }
void Fatal (const char* Format, ...) /* Print a message about a fatal error and die */ { va_list ap; const char* FileName; unsigned LineNum; if (CurTok.LI) { FileName = GetInputName (CurTok.LI); LineNum = GetInputLine (CurTok.LI); } else { FileName = GetCurrentFile (); LineNum = GetCurrentLine (); } fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum); va_start (ap, Format); vfprintf (stderr, Format, ap); va_end (ap); fprintf (stderr, "\n"); if (Line) { Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line)); } exit (EXIT_FAILURE); }
std::string ProjectManager::DoEditor(SpritePtr pNextAppButton) { GSGUI_BUTTON file_r = PlaceFileMenu(); if (file_r.text == _S_NEW_PROJ) { SaveAs(); } if (file_r.text == _S_LOAD_PROJ) { Open(); } SetFileNameToTitle(m_provider->GetVideo(), _ETH_PROJECT_MANAGER_WINDOW_TITLE); if (GetCurrentProject() == "") { ShadowPrint(Vector2(64,128), GS_L("-Start a new project or load an existing one.\n") \ GS_L("-If you start a new project, all necessary files and paths will be copied to the target folder.\n") \ GS_L("-Media files (sprites, sounds, normals) should be manually placed into their correct directories.\n") \ GS_L("-Create .ENT entity files before building your scenes.\n")); } else { str_type::string currentProjectFilename = utf8::c(Platform::GetFileName(GetCurrentFile(false))).wc_str(); str_type::string sText = GS_L("Project loaded: ") + currentProjectFilename + GS_L("\n") + GS_L("We're ready to go. Press TAB or click the arrow to go to the Editors"); ShadowPrint(Vector2(64,128), sText.c_str()); } ProccessFileOpenRequests(); return GetCurrentProject(); }
static Boolean ResidentBrowseFormFieldChanged(AppContext* appContext, FormType* form, EventType* event) { char * word; UInt32 newSelectedWord=0; FieldType * field; ListType * list; UInt16 index=FrmGetObjectIndex(form, fieldWord); Assert(index!=frmInvalidObjectId); field=(FieldType*)FrmGetObjectPtr(form, index); Assert(field); index=FrmGetObjectIndex(form, listMatching); Assert(index!=frmInvalidObjectId); list=(ListType*)FrmGetObjectPtr(form, index); Assert(list); word=FldGetTextPtr(field); // TODO: get length of the word via FldGetTextLength() if (word && *word) newSelectedWord = dictGetFirstMatching(GetCurrentFile(appContext), word); if (appContext->selectedWord != newSelectedWord) { appContext->selectedWord = newSelectedWord; Assert(appContext->selectedWord < appContext->wordsCount); LstSetSelectionMakeVisibleEx(appContext, list, appContext->selectedWord); } return true; }
void PPError (const char* Format, ...) /* Print an error message. For use within the preprocessor. */ { va_list ap; va_start (ap, Format); IntError (GetCurrentFile(), GetCurrentLine(), Format, ap); va_end (ap); }
void PPWarning (const char* Format, ...) /* Print warning message. For use within the preprocessor. */ { va_list ap; va_start (ap, Format); IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap); va_end (ap); }
void MediaReader::LateNoticeReceived( const media_source & what, bigtime_t how_much, bigtime_t performance_time) { CALLED(); if (what == output.source) { switch (RunMode()) { case B_OFFLINE: // nothing to do break; case B_RECORDING: // nothing to do break; case B_INCREASE_LATENCY: fInternalLatency += how_much; SetEventLatency(fDownstreamLatency + fInternalLatency); break; case B_DECREASE_PRECISION: // XXX : shorten our buffer period // We could opt to just not wait but we should // probably gradually shorten the period so we // don't starve others. Also, we need to make // sure we are catching up! We may have some sort // of time goal for how long it takes us to // catch up, as well. break; case B_DROP_DATA: // Okay you asked for it, we'll skip ahead in the file! // We'll drop 1 buffer's worth if (GetCurrentFile() == 0) { PRINT("MediaReader::LateNoticeReceived called without" "an GetCurrentFile() (!)\n"); } else { GetCurrentFile()->Seek(output.format.u.multistream.max_chunk_size,SEEK_CUR); } break; default: // huh?? there aren't any more run modes. PRINT("MediaReader::LateNoticeReceived with unexpected run mode.\n"); break; } } }
void EditorBase::SetFileNameToTitle(VideoPtr video, const wchar_t *wszTitle) { wstring newTitle, file; file = utf8::c(GetCurrentFile(false)).wc_str(); newTitle = wszTitle; newTitle += L" - "; newTitle += file; video->SetWindowTitle(newTitle); }
void DictCurrentFree(AppContext* appContext) { AbstractFile* file=GetCurrentFile(appContext); if ( NULL != file ) { dictDelete(file); FsFileClose( file ); SetCurrentFile(appContext, NULL); } }
void ParticleEditor::Save() { TiXmlDocument doc; TiXmlDeclaration *pDecl = new TiXmlDeclaration(GS_L("1.0"), GS_L(""), GS_L("")); doc.LinkEndChild(pDecl); TiXmlElement *pElement = new TiXmlElement(GS_L("Ethanon")); doc.LinkEndChild(pElement); m_system.WriteToXMLFile(doc.RootElement()); const str_type::string filePath = GetCurrentFile(true); doc.SaveFile(filePath); m_untitled = false; }
void ParticleEditor::Save() { TiXmlDocument doc; TiXmlDeclaration *pDecl = new TiXmlDeclaration(GS_L("1.0"), GS_L(""), GS_L("")); doc.LinkEndChild(pDecl); TiXmlElement *pElement = new TiXmlElement(GS_L("Ethanon")); doc.LinkEndChild(pElement); m_system.WriteToXMLFile(doc.RootElement()); const str_type::string filePath = utf8::c(GetCurrentFile(true)).wstr(); doc.SaveFile(filePath); #ifdef GS2D_STR_TYPE_ANSI m_provider->GetFileManager()->ConvertAnsiFileToUTF16LE(filePath); #endif m_untitled = false; }
static Boolean ResidentBrowseFormWinEnter(AppContext* appContext, FormType* form, EventType* event) { struct _WinEnterEventType* winEnter=(struct _WinEnterEventType*)&event->data; if (winEnter->enterWindow==(void*)form) // this means we're entering this window for the first time and we have to do initial list drawing { FieldType* field=NULL; ListType* list=NULL; UInt16 index=FrmGetObjectIndex(form, fieldWord); Assert(index!=frmInvalidObjectId); field=(FieldType*)FrmGetObjectPtr(form, index); index=FrmGetObjectIndex(form, listMatching); Assert(index!=frmInvalidObjectId); list=(ListType*)FrmGetObjectPtr(form, index); appContext->prevSelectedWord = 0xffffffff; LstSetListChoicesEx(list, NULL, dictGetWordsCount(GetCurrentFile(appContext))); LstSetDrawFunction(list, ListDrawFunc); appContext->prevTopItem = 0; Assert(appContext->selectedWord < appContext->wordsCount); if (*appContext->lastWord) { appContext->selectedWord = 0; FldInsert(field, appContext->lastWord, StrLen(appContext->lastWord)); FldSendChangeNotification(field); } else { if (-1==appContext->currentWord) appContext->selectedWord=0; else appContext->selectedWord=appContext->currentWord; LstSetSelectionEx(appContext, list, appContext->selectedWord); } index=FrmGetObjectIndex(form, fieldWord); Assert(index!=frmInvalidObjectId); FrmSetFocus(form, index); FrmUpdateForm(formResidentBrowse, frmRedrawUpdateCode); } return false; }
void CMainWnd::OnPlayPrev() { BOOL fPlay = MAP_GetStatus(m_hMap) != MAP_STATUS_STOP; // ファイル再生の時に再生時間が2秒以上なら先頭に // 2秒未満の場合は前の曲 FILEINFO* pInfo = GetInfo(GetCurrentFile()); if (pInfo && !IsURL(pInfo->szPath)) { long lCurrent = MAP_GetCurrent(m_hMap); if (fPlay && lCurrent > 2000) { MAP_Seek(m_hMap, 0); return; } } int nPrev = GetPrevIndex(); if (nPrev == OPEN_NONE) return; Open(nPrev); if (fPlay) Play(); }
Boolean BookmarksFormHandleEvent(EventType * event) { Boolean handled = false; FormType * frm; ListType * bkmList, * sortTypeList; char * listTxt; UInt16 bookmarksCount; AppContext* appContext = GetAppContext(); frm = FrmGetActiveForm(); switch (event->eType) { case frmOpenEvent: OpenBookmarksDB(appContext, appContext->prefs.bookmarksSortType); bkmList = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listBookmarks)); bookmarksCount = BookmarksWordCount(appContext); Assert( 0 != bookmarksCount ); LstSetDrawFunction(bkmList, BookmarksListDrawFunc); LstSetListChoices(bkmList, NULL, bookmarksCount); sortTypeList = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listSortBy)); // list position matches enums for simplicity LstSetSelection(sortTypeList, (Int16)appContext->prefs.bookmarksSortType); listTxt = LstGetSelectionText(sortTypeList, appContext->prefs.bookmarksSortType); CtlSetLabel((ControlType *)FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,popupSortBy)), listTxt); FrmDrawForm(frm); handled = true; break; case winDisplayChangedEvent: handled= BookmarksFormDisplayChanged(appContext, frm); break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case buttonCancel: CloseBookmarksDB(appContext); FrmReturnToForm(0); handled = true; break; case popupSortBy: // do nothing break; default: Assert(false); break; } break; case popSelectEvent: switch (event->data.popSelect.listID) { case listSortBy: Assert( appContext->currBookmarkDbType == appContext->prefs.bookmarksSortType ); if ((BookmarkSortType) event->data.popSelect.selection != appContext->prefs.bookmarksSortType) { // we changed sorting type sortTypeList = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listSortBy)); listTxt = LstGetSelectionText(sortTypeList, event->data.popSelect.selection); CtlSetLabel((ControlType *)FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,popupSortBy)), listTxt); // list position matches enums for simplicity OpenBookmarksDB(appContext, (BookmarkSortType) event->data.popSelect.selection); appContext->prefs.bookmarksSortType = (BookmarkSortType) event->data.popSelect.selection; #ifdef DEBUG // word count shouldn't change bookmarksCount = BookmarksWordCount(appContext); bkmList = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listBookmarks)); Assert( LstGetNumberOfItems(bkmList) == bookmarksCount ); #endif FrmDrawForm(frm); } handled = true; break; default: Assert(false); break; } break; case lstSelectEvent: { MemHandle recHandle; char * word; recHandle = DmQueryRecord(appContext->bookmarksDb, event->data.lstSelect.selection); Assert( recHandle ); // no reason it shouldn't work if (recHandle) { word = (char*)MemHandleLock(recHandle); Assert(word); #ifndef I_NOAH appContext->currentWord = dictGetFirstMatching(GetCurrentFile(appContext), word); MemHandleUnlock(recHandle); SendEvtWithType(evtNewWordSelected); #else FrmReturnToForm(0); StartWordLookup(appContext, word); MemHandleUnlock(recHandle); #endif } CloseBookmarksDB(appContext); #ifndef I_NOAH FrmReturnToForm(0); #endif handled = true; } default: break; } return handled; }
void Preprocess (void) /* Preprocess a line */ { int Skip; ident Directive; /* Create the output buffer if we don't already have one */ if (MLine == 0) { MLine = NewStrBuf (); } /* Skip white space at the beginning of the line */ SkipWhitespace (0); /* Check for stuff to skip */ Skip = 0; while (CurC == '\0' || CurC == '#' || Skip) { /* Check for preprocessor lines lines */ if (CurC == '#') { NextChar (); SkipWhitespace (0); if (CurC == '\0') { /* Ignore the empty preprocessor directive */ continue; } if (!IsSym (Directive)) { PPError ("Preprocessor directive expected"); ClearLine (); } else { switch (FindPPToken (Directive)) { case PP_DEFINE: if (!Skip) { DefineMacro (); } break; case PP_ELIF: if (IfIndex >= 0) { if ((IfStack[IfIndex] & IFCOND_ELSE) == 0) { /* Handle as #else/#if combination */ if ((IfStack[IfIndex] & IFCOND_SKIP) == 0) { Skip = !Skip; } IfStack[IfIndex] |= IFCOND_ELSE; Skip = DoIf (Skip); /* #elif doesn't need a terminator */ IfStack[IfIndex] &= ~IFCOND_NEEDTERM; } else { PPError ("Duplicate #else/#elif"); } } else { PPError ("Unexpected #elif"); } break; case PP_ELSE: if (IfIndex >= 0) { if ((IfStack[IfIndex] & IFCOND_ELSE) == 0) { if ((IfStack[IfIndex] & IFCOND_SKIP) == 0) { Skip = !Skip; } IfStack[IfIndex] |= IFCOND_ELSE; } else { PPError ("Duplicate #else"); } } else { PPError ("Unexpected `#else'"); } break; case PP_ENDIF: if (IfIndex >= 0) { /* Remove any clauses on top of stack that do not * need a terminating #endif. */ while (IfIndex >= 0 && (IfStack[IfIndex] & IFCOND_NEEDTERM) == 0) { --IfIndex; } /* Stack may not be empty here or something is wrong */ CHECK (IfIndex >= 0); /* Remove the clause that needs a terminator */ Skip = (IfStack[IfIndex--] & IFCOND_SKIP) != 0; } else { PPError ("Unexpected `#endif'"); } break; case PP_ERROR: if (!Skip) { DoError (); } break; case PP_IF: Skip = DoIf (Skip); break; case PP_IFDEF: Skip = DoIfDef (Skip, 1); break; case PP_IFNDEF: Skip = DoIfDef (Skip, 0); break; case PP_INCLUDE: if (!Skip) { DoInclude (); } break; case PP_LINE: /* Should do something in C99 at least, but we ignore it */ if (!Skip) { ClearLine (); } break; case PP_PRAGMA: if (!Skip) { DoPragma (); goto Done; } break; case PP_UNDEF: if (!Skip) { DoUndef (); } break; case PP_WARNING: /* #warning is a non standard extension */ if (IS_Get (&Standard) > STD_C99) { if (!Skip) { DoWarning (); } } else { if (!Skip) { PPError ("Preprocessor directive expected"); } ClearLine (); } break; default: if (!Skip) { PPError ("Preprocessor directive expected"); } ClearLine (); } } } if (NextLine () == 0) { if (IfIndex >= 0) { PPError ("`#endif' expected"); } return; } SkipWhitespace (0); } PreprocessLine (); Done: if (Verbosity > 1 && SB_NotEmpty (Line)) { printf ("%s(%u): %.*s\n", GetCurrentFile (), GetCurrentLine (), (int) SB_GetLen (Line), SB_GetConstBuf (Line)); } }
void NextToken (void) /* Get next token from input stream */ { ident token; /* We have to skip white space here before shifting tokens, since the ** tokens and the current line info is invalid at startup and will get ** initialized by reading the first time from the file. Remember if ** we were at end of input and handle that later. */ int GotEOF = (SkipWhite() == 0); /* Current token is the lookahead token */ if (CurTok.LI) { ReleaseLineInfo (CurTok.LI); } CurTok = NextTok; /* When reading the first time from the file, the line info in NextTok, ** which was copied to CurTok is invalid. Since the information from ** the token is used for error messages, we must make it valid. */ if (CurTok.LI == 0) { CurTok.LI = UseLineInfo (GetCurLineInfo ()); } /* Remember the starting position of the next token */ NextTok.LI = UseLineInfo (GetCurLineInfo ()); /* Now handle end of input. */ if (GotEOF) { /* End of file reached */ NextTok.Tok = TOK_CEOF; return; } /* Determine the next token from the lookahead */ if (IsDigit (CurC) || (CurC == '.' && IsDigit (NextC))) { /* A number */ NumericConst (); return; } /* Check for wide character literals */ if (CurC == 'L' && NextC == '\"') { StringConst (); return; } /* Check for keywords and identifiers */ if (IsSym (token)) { /* Check for a keyword */ if ((NextTok.Tok = FindKey (token)) != TOK_IDENT) { /* Reserved word found */ return; } /* No reserved word, check for special symbols */ if (token[0] == '_' && token[1] == '_') { /* Special symbols */ if (strcmp (token+2, "FILE__") == 0) { NextTok.SVal = AddLiteral (GetCurrentFile()); NextTok.Tok = TOK_SCONST; return; } else if (strcmp (token+2, "LINE__") == 0) { NextTok.Tok = TOK_ICONST; NextTok.IVal = GetCurrentLine(); NextTok.Type = type_int; return; } else if (strcmp (token+2, "func__") == 0) { /* __func__ is only defined in functions */ if (CurrentFunc) { NextTok.SVal = AddLiteral (F_GetFuncName (CurrentFunc)); NextTok.Tok = TOK_SCONST; return; } } } /* No reserved word but identifier */ strcpy (NextTok.Ident, token); NextTok.Tok = TOK_IDENT; return; } /* Monstrous switch statement ahead... */ switch (CurC) { case '!': NextChar (); if (CurC == '=') { SetTok (TOK_NE); } else { NextTok.Tok = TOK_BOOL_NOT; } break; case '\"': StringConst (); break; case '%': NextChar (); if (CurC == '=') { SetTok (TOK_MOD_ASSIGN); } else { NextTok.Tok = TOK_MOD; } break; case '&': NextChar (); switch (CurC) { case '&': SetTok (TOK_BOOL_AND); break; case '=': SetTok (TOK_AND_ASSIGN); break; default: NextTok.Tok = TOK_AND; } break; case '\'': CharConst (); break; case '(': SetTok (TOK_LPAREN); break; case ')': SetTok (TOK_RPAREN); break; case '*': NextChar (); if (CurC == '=') { SetTok (TOK_MUL_ASSIGN); } else { NextTok.Tok = TOK_STAR; } break; case '+': NextChar (); switch (CurC) { case '+': SetTok (TOK_INC); break; case '=': SetTok (TOK_PLUS_ASSIGN); break; default: NextTok.Tok = TOK_PLUS; } break; case ',': SetTok (TOK_COMMA); break; case '-': NextChar (); switch (CurC) { case '-': SetTok (TOK_DEC); break; case '=': SetTok (TOK_MINUS_ASSIGN); break; case '>': SetTok (TOK_PTR_REF); break; default: NextTok.Tok = TOK_MINUS; } break; case '.': NextChar (); if (CurC == '.') { NextChar (); if (CurC == '.') { SetTok (TOK_ELLIPSIS); } else { UnknownChar (CurC); } } else { NextTok.Tok = TOK_DOT; } break; case '/': NextChar (); if (CurC == '=') { SetTok (TOK_DIV_ASSIGN); } else { NextTok.Tok = TOK_DIV; } break; case ':': SetTok (TOK_COLON); break; case ';': SetTok (TOK_SEMI); break; case '<': NextChar (); switch (CurC) { case '=': SetTok (TOK_LE); break; case '<': NextChar (); if (CurC == '=') { SetTok (TOK_SHL_ASSIGN); } else { NextTok.Tok = TOK_SHL; } break; default: NextTok.Tok = TOK_LT; } break; case '=': NextChar (); if (CurC == '=') { SetTok (TOK_EQ); } else { NextTok.Tok = TOK_ASSIGN; } break; case '>': NextChar (); switch (CurC) { case '=': SetTok (TOK_GE); break; case '>': NextChar (); if (CurC == '=') { SetTok (TOK_SHR_ASSIGN); } else { NextTok.Tok = TOK_SHR; } break; default: NextTok.Tok = TOK_GT; } break; case '?': SetTok (TOK_QUEST); break; case '[': SetTok (TOK_LBRACK); break; case ']': SetTok (TOK_RBRACK); break; case '^': NextChar (); if (CurC == '=') { SetTok (TOK_XOR_ASSIGN); } else { NextTok.Tok = TOK_XOR; } break; case '{': SetTok (TOK_LCURLY); break; case '|': NextChar (); switch (CurC) { case '|': SetTok (TOK_BOOL_OR); break; case '=': SetTok (TOK_OR_ASSIGN); break; default: NextTok.Tok = TOK_OR; } break; case '}': SetTok (TOK_RCURLY); break; case '~': SetTok (TOK_COMP); break; default: UnknownChar (CurC); } }
void MediaReader::Connect( status_t error, const media_source & source, const media_destination & destination, const media_format & format, char * io_name) { CALLED(); if (error != B_OK) { PRINT("\t<- error already\n"); output.destination = media_destination::null; GetFormat(&output.format); return; } if (output.source != source) { PRINT("\t<- B_MEDIA_BAD_SOURCE\n"); output.destination = media_destination::null; GetFormat(&output.format); return; } // record the agreed upon values output.destination = destination; output.format = format; strncpy(io_name,output.name,B_MEDIA_NAME_LENGTH-1); io_name[B_MEDIA_NAME_LENGTH-1] = '\0'; // determine our downstream latency media_node_id id; FindLatencyFor(output.destination, &fDownstreamLatency, &id); // compute the buffer period (must be done before setbuffergroup) fBufferPeriod = bigtime_t(1000 * 8000000 / 1024 * output.format.u.multistream.max_chunk_size / output.format.u.multistream.max_bit_rate); PRINT("\tmax chunk size = %ld, max bit rate = %f, buffer period = %lld\n", output.format.u.multistream.max_chunk_size, output.format.u.multistream.max_bit_rate,fBufferPeriod); // setup the buffers if they aren't setup yet if (fBufferGroup == 0) { status_t status = SetBufferGroup(output.source,0); if (status != B_OK) { PRINT("\t<- SetBufferGroup failed\n"); output.destination = media_destination::null; GetFormat(&output.format); return; } } SetBufferDuration(fBufferPeriod); if (GetCurrentFile() != 0) { bigtime_t start, end; // buffer group buffer size uint8 * data = new uint8[output.format.u.multistream.max_chunk_size]; BBuffer * buffer = 0; ssize_t bytesRead = 0; { // timed section start = TimeSource()->RealTime(); // first we try to use a real BBuffer buffer = fBufferGroup->RequestBuffer( output.format.u.multistream.max_chunk_size,fBufferPeriod); if (buffer != 0) { FillFileBuffer(buffer); } else { // didn't get a real BBuffer, try simulation by just a read from the disk bytesRead = GetCurrentFile()->Read( data, output.format.u.multistream.max_chunk_size); } end = TimeSource()->RealTime(); } bytesRead = buffer->SizeUsed(); delete data; if (buffer != 0) { buffer->Recycle(); } GetCurrentFile()->Seek(-bytesRead,SEEK_CUR); // put it back where we found it fInternalLatency = end - start; PRINT("\tinternal latency from disk read = %lld\n", fInternalLatency); } else { fInternalLatency = 100; // just guess PRINT("\tinternal latency guessed = %lld\n", fInternalLatency); } SetEventLatency(fDownstreamLatency + fInternalLatency); // XXX: do anything else? }
// // Read and unfold one semantic line from the source file, stripping off any coments. // int Parser::ReadLine() { #define RETRY() do { \ state = STAT_0; \ goto retry; \ } while(0) #define ENTER_COMMENT() do { prev_state = state; state = STAT_SLASH; } while(0) #define EXIT_COMMENT() do { state = prev_state; prev_state = STAT_INVALID; } while(0) CC_STRING& line = pline.parsed; pline.from.clear(); pline.parsed.clear(); pline.to.clear(); pline.pp_id = SSID_INVALID; pline.content = -1; enum { STAT_INVALID = -1, STAT_INIT = 0, STAT_SPACE1, STAT_SHARP, STAT_SPACE2, STAT_WORD, STAT_0, STAT_SLASH, STAT_LC, STAT_BC, STAT_ASTERISK, STAT_FOLD, STAT_SQ, STAT_DQ, STAT_SQ_ESC, STAT_DQ_ESC, } state, prev_state = STAT_INVALID; int c; int foldcnt = 0; File *file = GetCurrentFile().ifile; CC_STRING directive; bool eof = false; state = STAT_INIT; while(!eof) { c = file->ReadChar(); if(c == EOF) { if(line.isnull()) return 0; c = '\n'; eof = true; } else pline.from += c; if( c == '\r' ) /* Ignore carriage characters */ continue; if(c == '\n') file->line++; retry: switch(state) { case STAT_INIT: switch(c) { case ' ': case '\t': state = STAT_SPACE1; line = c; continue; case '#': state = STAT_SHARP; line = c; continue; } state = STAT_0; case STAT_0: switch(c) { case '/': ENTER_COMMENT(); break; case '\\': state = STAT_FOLD; break; case '"': state = STAT_DQ; break; case '\'': state = STAT_SQ; break; default: if(rtc && c == rtc->as_lc_char && pline.pp_id == SSID_INVALID) state = STAT_LC; break; } break; case STAT_SLASH: switch(c) { case '/': state = STAT_LC; mark_comment_start(); line.remove_last(); break; case '*': state = STAT_BC; mark_comment_start(); line.remove_last(); break; case '"': state = STAT_DQ; break; case '\'': state = STAT_SQ; break; default: EXIT_COMMENT(); } break; case STAT_LC: /* line comment */ if(c == '\n') state = STAT_0; break; case STAT_BC: /* block comments */ if(c == '*') state = STAT_ASTERISK; if(c == '\n') foldcnt++; break; case STAT_ASTERISK: /* asterisk */ if(c == '/') { EXIT_COMMENT(); continue; } else if(c != '*') state = STAT_BC; break; case STAT_FOLD: /* folding the line */ if(c == '\t' || c == ' ') ; else { if(c == '\n') foldcnt++; state = STAT_0; continue; } break; case STAT_DQ: switch(c) { case '\\': state = STAT_DQ_ESC; break; case '"': state = STAT_0; break; } break; case STAT_SQ: switch(c) { case '\\': state = STAT_SQ_ESC; break; case '\'': state = STAT_0; break; } break; case STAT_DQ_ESC: state = STAT_DQ; break; case STAT_SQ_ESC: state = STAT_SQ; break; case STAT_SPACE1: switch(c) { case '#': state = STAT_SHARP; break; case ' ': case '\t': break; case '/': ENTER_COMMENT(); break; default: RETRY(); } break; case STAT_SHARP: if(isblank(c)) { state = STAT_SPACE2; break; } /* fall through */ case STAT_SPACE2: if(isalpha(c) || isdigit(c) || c == '_') { state = STAT_WORD; directive = '#'; directive += c; } else if(c == '/') ENTER_COMMENT(); else if(!isblank(c)) RETRY(); break; case STAT_WORD: if(isalpha(c) || isdigit(c) || c == '_') directive += c; else { for(size_t i = 0; i < num_preprocessors; i++) if(preprocessors[i] == directive) { pline.pp_id = intab->syLut.Put(preprocessors[i]); pline.content = line.size(); state = STAT_0; break; } RETRY(); } break; case STAT_INVALID: errmsg = "Invalid state"; return -1; } if(state != STAT_LC && state != STAT_BC && state != STAT_FOLD && state != STAT_ASTERISK) line += c; if ((state == STAT_INIT || state == STAT_0) && c == '\n') break; } if(state != STAT_INIT && state != STAT_0) { errmsg = "Syntax error"; return -1; } file->offset = -foldcnt; return 1; }