void ScrollViewUp( LPCLASSDATA lpcd ) { int nLines = ArrayGetSize( lpcd->lpLines ) - 1; /* * Are we there already? */ if (( lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1 ) < nLines ) { /* * Go down one. */ lpcd->ptViewPos.y++; VScroll( lpcd, -1 ); /* * Setup the scroller. */ SetupVScroller( lpcd ); /* * Caret OK? */ if ( lpcd->ptCaretPos.y < lpcd->ptViewPos.y ) { /* * Make it visible. */ lpcd->ptCaretPos.y = lpcd->ptViewPos.y; lpcd->ptCaretPos.x = lpcd->nLastColumnPos = 0; UpdateCaret( lpcd ); } } }
tCacheItem * Cache_GetDependency (/*in*/ req * r, /*in*/ tCacheItem * pItem, /*in*/ int n) { if (!pItem -> pDependsOn || ArrayGetSize (r -> pApp, pItem -> pDependsOn) < n || n < 0) return NULL ; return pItem -> pDependsOn[n] ; }
static void MoveEnd( LPCLASSDATA lpcd ) { /* * Are we there yet? */ if ( lpcd->ptCaretPos.y == ArrayGetSize( lpcd->lpLines ) - 1 && lpcd->ptCaretPos.x == GETLINE( lpcd )->nLength ) /* * Yes. */ return; /* * Put us on the last line. */ lpcd->ptCaretPos.y = ArrayGetSize( lpcd->lpLines ) - 1; /* * Move us to the end. */ //lpcd->ptCaretPos.x = GETLINE( lpcd )->nLength; // Modified by Stephan (2005-06-08): Don't jump to the end of the line lpcd->ptCaretPos.x = 0; /* * Save this position. */ lpcd->nLastColumnPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x ); /* * Make sure the care is in the view. */ MakeCaretVisible( lpcd ); /* * Update caret position. */ UpdateCaret( lpcd ); }
int Cache_CleanupRequest (req * r) { if (pCachesToRelease) { int n = ArrayGetSize (r -> pApp, pCachesToRelease) ; int i ; /* lprintf (r -> pApp, "XXXXX Cache_CleanupRequest [%d/%d] pProviders=%x pCacheItems=%x pCachesToRelease=%x", _getpid(), GetCurrentThreadId(), pProviders, pCacheItems, pCachesToRelease) ; */ for (i = 0; i < n; i++) Cache_FreeContent (r, pCachesToRelease[i]) ; ArraySetSize(r -> pApp, &pCachesToRelease, 0) ; } return ok ; }
int Cache_ReleaseContent (/*in*/ req * r, /*in*/ tCacheItem *pItem) { /* locking not yet implemented */ tCacheItem * pSubItem ; int i ; int numItems = pItem -> pDependsOn?ArrayGetSize (r -> pApp, pItem -> pDependsOn):0 ; if (!pItem -> bCache) Cache_FreeContent (r, pItem) ; for (i = 0; i < numItems; i++) { pSubItem = pItem -> pDependsOn[i] ; Cache_ReleaseContent (r, pSubItem) ; } return ok ; }
static void MoveRight( LPCLASSDATA lpcd ) { /* * Caret at the end of the line? */ if ( lpcd->ptCaretPos.x == GETLINE( lpcd )->nLength ) { /* * Yes. Are we at the last line? */ if ( lpcd->ptCaretPos.y < ArrayGetSize( lpcd->lpLines ) - 1 ) { /* * Go down one. */ lpcd->ptCaretPos.y++; lpcd->ptCaretPos.x = 0; } } else /* * One right. */ lpcd->ptCaretPos.x++; /* * Save off this position. */ lpcd->nLastColumnPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x ); /* * Make sure the caret is in the view. */ MakeCaretVisible( lpcd ); /* * Update caret position. */ UpdateCaret( lpcd ); }
static void MoveViewDown( LPCLASSDATA lpcd ) { int nLines = ArrayGetSize( lpcd->lpLines ) - 1; /* * Are we already at the end? */ if ( lpcd->ptCaretPos.y < nLines ) { /* * Hide the caret. */ DisplayCaret( lpcd, FALSE ); /* * Are we on the bottom of the view? */ if ( lpcd->ptCaretPos.y == ( lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1 )) /* * Move down a page. */ lpcd->ptCaretPos.y = min( lpcd->ptCaretPos.y + lpcd->szViewSize.cy - 1, nLines ); else /* * Move to the bottom of the page. */ lpcd->ptCaretPos.y = min( lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1, nLines ); /* * Make sure the caret is visible. */ MakeCaretVisible( lpcd ); /* * Show the caret. */ DisplayCaret( lpcd, TRUE ); } }
/* * Any text in the buffer? */ BOOL AnyText( LPCLASSDATA lpcd ) { if ( ArrayGetSize( lpcd->lpLines ) == 1 && (( LPLINE )ArrayGetAt( lpcd->lpLines, 0 ))->nLength == 0 ) return FALSE; return TRUE; }
static void SetSizeControls( HWND hDlg ) { LPCLASSDATA lpcd = ( LPCLASSDATA )GetWindowLong( hDlg, DWL_USER ); TCHAR szBuffer[ 256 ]; SHFILEINFO psfi; int nLines = ArrayGetSize( lpcd->lpLines ), i, nFileMode; unsigned int nBytes = 0, nLineTerm = 1; /* * Get system file type. */ SHGetFileInfo( lpcd->szFileName, 0, &psfi, sizeof( SHFILEINFO ), SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME ); SetDlgItemText( hDlg, IDC_PROP_SYSTYPE, psfi.szTypeName[ 0 ] ? psfi.szTypeName : GetString( IDS_NO_TYPENAME )); /* * Setup language name. */ SetDlgItemText( hDlg, IDC_PROP_LANGUAGE, Parser->pszTitle ); /* * Setup tab-size. */ SetDlgItemInt( hDlg, IDC_PROP_TABSIZE, Parser->nTabSize, FALSE ); /* * Setup icon. */ SendDlgItemMessage( hDlg, IDC_PROP_ICON, STM_SETICON, ( WPARAM )lpcd->hIconLarge, 0 ); /* * Setup file mode. */ SendDlgItemMessage( hDlg, IDC_PROP_TYPE, CB_SETCURSEL, Parser->nFileMode, 0 ); /* * Get file mode. */ nFileMode = SendDlgItemMessage( hDlg, IDC_PROP_TYPE, CB_GETCURSEL, 0, 0 ); /* * Compute size of the * line terminator. */ if ( nFileMode == FMODE_MSDOS || nFileMode == FMODE_UNIX ) nLineTerm = 2; /* * Compute the file size * in bytes. */ for ( i = 0; i < nLines; i++ ) { /* * Add line length. */ nBytes += (( LPLINE )ArrayGetAt( lpcd->lpLines, i ))->nLength; /* * Add line terminator bytes * if this is not the last line. */ if ( i < nLines - 1 ) nBytes += nLineTerm; } /* * Format and set size string. */ _stprintf_s( szBuffer, 256, GetString( IDS_FILE_SIZE ), nBytes, nLines ); SetDlgItemText( hDlg, IDC_PROP_SIZE, szBuffer ); }
BOOL Delete( LPCLASSDATA lpcd ) { /* * Read only? */ if ( ISREADONLY ) return TRUE; /* * Do we have a mark and * is it valid? */ if ( HasMark( lpcd )) { /* * Remove the text. */ DeleteText( lpcd, &lpcd->ptSelStart, &lpcd->ptSelEnd, TRUE ); /* * We _must_ have atleast one * empty line. */ if ( ArrayGetSize( lpcd->lpLines ) == 0 ) { if ( InsertLine( lpcd, NULL, 0, -1, TRUE ) == FALSE ) return FALSE; } /* * Hide the caret. */ DisplayCaret( lpcd, FALSE ); /* * Move to the start position. */ lpcd->ptCaretPos = lpcd->ptSelStart; /* * Update column position. */ lpcd->nLastColumnPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x ); /* * Invalidate marks. */ lpcd->ptSelStart.x = lpcd->ptSelStart.y = -1; lpcd->ptSelEnd.x = lpcd->ptSelEnd.y = -1; /* * Is the caret inside * the view? */ if ( CaretInView( lpcd ) == FALSE ) /* * No. Move the view to * make it visible. */ MakeCaretVisibleNoRedraw( lpcd ); /* * Re-render. */ InvalidateRect( lpcd->hWnd, NULL, FALSE ); /* * Setup scrollers. */ SetupHScroller( lpcd ); SetupVScroller( lpcd ); /* * We are modified. */ SetModified( lpcd, TRUE ); /* * Send status message. */ SendStatusMessage( lpcd ); /* * Show the caret. */ DisplayCaret( lpcd, TRUE ); } return TRUE; }
/* * Pre-parse until we reach the passed line. */ void PreParseTo( LPCLASSDATA lpcd, int nTo ) { register LPLINE lpLine; register int i, nBlock = -1, nLines = ArrayGetSize( lpcd->lpLines ); int nDummy; /* * Did the previous line end with an open block * marker? */ if ( lpcd->dwParsedUpTo == 0 ) nBlock = -1; else nBlock = (( LPLINE )ArrayGetAt( lpcd->lpLines, lpcd->dwParsedUpTo ))->nBlock; /* * Make sure we do not go past the end * of the file. */ nTo = min( nTo, nLines - 1 ); /* * Iterate the lines. */ for ( i = lpcd->dwParsedUpTo; i <= nTo; i++ ) { /* * Get line pointer. */ lpLine = ArrayGetAt( lpcd->lpLines, i ); /* * Pre-parse the line. This is done so that * the blocks found in the text are parsed * before the file is displayed the first * time. */ lpLine->nBlock = nBlock = ParseLine( lpcd, nBlock, lpLine->pcText, lpLine->nLength, NULL, &nDummy, 0, i ); } /* * Are all lines parsed? */ if ( nTo >= nLines - 1 ) { /* * Kill the timer. */ if ( lpcd->nParseTimerID ) { KillTimer( lpcd->hWnd, lpcd->nParseTimerID ); lpcd->nParseTimerID = 0; } /* * Set the counter to the maximum. */ lpcd->dwParsedUpTo = 0xFFFFFFFF; } else { /* * Is the parsing timer up? */ if ( lpcd->nParseTimerID == 0 ) lpcd->nParseTimerID = SetTimer( lpcd->hWnd, IDT_PARSETIMER, 100, NULL ); /* * Update the counter. */ lpcd->dwParsedUpTo = nTo; } }
static void MoveNextWord( LPCLASSDATA lpcd ) { /* * Obtain current caret column and a * pointer to the line. */ int nPos = lpcd->ptCaretPos.x; LPLINE lpLine = GETLINE( lpcd ); /* * Are we at the end of the line? */ if ( nPos == lpLine->nLength ) { /* * Yes go down one line and to the * first word on that line. */ if ( lpcd->ptCaretPos.y < ArrayGetSize( lpcd->lpLines ) - 1 ) { /* * Start at 0 */ nPos = 0; /* * Go down. */ lpcd->ptCaretPos.y++; /* * Skip spaces. */ lpLine = GETLINE( lpcd ); if ( lpLine->pcText ) { while ( _istspace( lpLine->pcText[ nPos ] ) && nPos < GETLINE( lpcd )->nLength ) nPos++; } /* * Store new column position. */ lpcd->ptCaretPos.x = nPos; } } else { BOOL bBreakOnNonSpace = FALSE; /* * Are we on a white space? */ if ( _istspace( lpLine->pcText[ nPos ] )) { /* * Skip spaces... */ while ( _istspace( lpLine->pcText[ nPos ] ) && nPos < lpLine->nLength ) nPos++; } else if ( IsDelimiter( lpcd, lpLine->pcText [ nPos ] )) /* A delimiter? */ { /* * Skip all delimiters and white spaces. */ while (( IsDelimiter( lpcd, lpLine->pcText[ nPos ] ) || _istspace( lpLine->pcText[ nPos ] )) && nPos < lpLine->nLength ) { /* * White space? */ if ( _istspace( lpLine->pcText[ nPos ] )) /* * Yes. Break on the next non-white space. */ bBreakOnNonSpace = TRUE; else if ( bBreakOnNonSpace ) /* * Stop at this non-white space. */ break; nPos++; } } else { /* * Skip all non delimiters and white spaces. */ while (( IsDelimiter( lpcd, lpLine->pcText[ nPos ] ) == FALSE || _istspace( lpLine->pcText[ nPos ] )) && nPos < lpLine->nLength ) { /* * White space? */ if ( _istspace( lpLine->pcText[ nPos ] )) /* * Yes. Break on the next non-white space. */ bBreakOnNonSpace = TRUE; else if ( bBreakOnNonSpace ) /* * Stop at this non-white space. */ break; nPos++; } } /* * Store position. */ lpcd->ptCaretPos.x = nPos; } /* * Save this position. */ lpcd->nLastColumnPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x ); /* * Make sure the caret is in the view. */ MakeCaretVisible( lpcd ); /* * Update caret position. */ UpdateCaret( lpcd ); }
static void MoveDown( LPCLASSDATA lpcd ) { /* * Caret at the last line? */ if ( lpcd->ptCaretPos.y < ArrayGetSize( lpcd->lpLines ) - 1 ) { /* * Fast scrolling? */ if ( Parser->bFastScroll && lpcd->bRepeatMode ) { /* * Are we at the top of the view? */ if ( lpcd->ptCaretPos.y == ( lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1 )) /* * Setup new position. */ lpcd->ptCaretPos.y = min( lpcd->ptCaretPos.y + 2, ArrayGetSize( lpcd->lpLines ) - 1 ); else /* * One line up. */ lpcd->ptCaretPos.y++; } else /* * Go one down. */ lpcd->ptCaretPos.y++; /* * Try to locate the cursor as close to the * last column position as possible since * the user changed the column. */ lpcd->ptCaretPos.x = GetTextOffset( lpcd, lpcd->nLastColumnPos ); /* * Are we passed the end? */ if ( lpcd->ptCaretPos.x > GETLINE( lpcd )->nLength ) /* * Set us at the end. */ lpcd->ptCaretPos.x = GETLINE( lpcd )->nLength; } else { /* * Caret at the end of the line? */ // Modified by Stephan (2005-06-08): Don't jump to end of line //if ( lpcd->ptCaretPos.x < GETLINE( lpcd )->nLength ) //lpcd->ptCaretPos.x = GETLINE( lpcd )->nLength; } /* * Make sure the care is in the view. */ MakeCaretVisible( lpcd ); /* * Update caret position. */ UpdateCaret( lpcd ); }
int Cache_IsExpired (/*in*/ req * r, /*in*/ tCacheItem * pItem, /*in*/ int nLastUpdated) { epTHX_ int rc ; tCacheItem * pSubItem ; int i ; int numItems = pItem -> pDependsOn?ArrayGetSize (r -> pApp, pItem -> pDependsOn):0 ; if (nLastUpdated < pItem -> nLastUpdated) return TRUE ; if (pItem -> pProvider -> pProviderClass -> fExpires) { if ((*pItem -> pProvider -> pProviderClass -> fExpires)(r, pItem -> pProvider)) { if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s expired because provider C sub returned TRUE\n", r -> pThread -> nPid, pItem -> sKey) ; Cache_FreeContent (r, pItem) ; return pItem -> bExpired = TRUE ; } } if (pItem -> bExpired || pItem -> nLastChecked == r -> nRequestCount) return pItem -> bExpired ; /* we already have checked this or know that is it expired */ pItem -> nLastChecked = r -> nRequestCount ; /* first check dependency */ for (i = 0; i < numItems; i++) { pSubItem = pItem -> pDependsOn[i] ; if (Cache_IsExpired (r, pSubItem, pItem -> nLastUpdated)) { if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s expired because dependencies is expired or newer\n", r -> pThread -> nPid, pItem -> sKey) ; Cache_FreeContent (r, pItem) ; return pItem -> bExpired = TRUE ; } } if (pItem -> nExpiresInTime && pItem -> nLastModified + pItem -> nExpiresInTime < r -> nRequestTime) { if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s expired because of timeout (%d sec)\n", r -> pThread -> nPid, pItem -> sKey, pItem -> nExpiresInTime) ; Cache_FreeContent (r, pItem) ; return pItem -> bExpired = TRUE ; } if (pItem -> sExpiresFilename) { #ifdef WIN32 if (_stat (pItem -> sExpiresFilename, &pItem -> FileStat)) #else if (stat (pItem -> sExpiresFilename, &pItem -> FileStat)) #endif { if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s expired because cannot stat file %s\n", r -> pThread -> nPid, pItem -> sKey, pItem -> sExpiresFilename) ; Cache_FreeContent (r, pItem) ; return pItem -> bExpired = TRUE ; } if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s stat file %s mtime=%d size=%d\n", r -> pThread -> nPid, pItem -> sKey, pItem -> sExpiresFilename, pItem -> FileStat.st_mtime, pItem -> FileStat.st_size) ; if (pItem -> nFileModified != pItem -> FileStat.st_mtime) { if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s expired because file %s changed\n", r -> pThread -> nPid, pItem -> sKey, pItem -> sExpiresFilename) ; pItem -> nFileModified = pItem -> FileStat.st_mtime ; Cache_FreeContent (r, pItem) ; return pItem -> bExpired = TRUE ; } } if (pItem -> pExpiresCV) { SV * pRet ; if ((rc = CallCV (r, "Expired?", pItem -> pExpiresCV, 0, &pRet)) != ok) { LogError (r, rc) ; Cache_FreeContent (r, pItem) ; return pItem -> bExpired = TRUE ; } if (pRet && SvTRUE(pRet)) { /* Expire the entry */ if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s expired because expirey Perl sub returned TRUE\n", r -> pThread -> nPid, pItem -> sKey) ; Cache_FreeContent (r, pItem) ; return pItem -> bExpired = TRUE ; } } if (pItem -> fExpires) { if ((*pItem -> fExpires)(pItem)) { if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s expired because expirey C sub returned TRUE\n", r -> pThread -> nPid, pItem -> sKey) ; Cache_FreeContent (r, pItem) ; return pItem -> bExpired = TRUE ; } } if (r -> Component.Config.bDebug & dbgCache) lprintf (r -> pApp, "[%d]CACHE: %s NOT expired\n", r -> pThread -> nPid, pItem -> sKey) ; return FALSE ; }