MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / Style_SetLexerFromFile

Function Style_SetLexerFromFile

src/Styles.c:2155–2231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2153extern FILEVARS fvCurFile;
2154
2155void Style_SetLexerFromFile ( HWND hwnd, LPCWSTR lpszFile )
2156{
2157 LPWSTR lpszExt;
2158 BOOL bFound = FALSE;
2159 PEDITLEXER pLexNew = pLexArray[iDefaultLexer];
2160 PEDITLEXER pLexSniffed;
2161 if ( ( fvCurFile.mask & FV_MODE ) && fvCurFile.tchMode[0] ) {
2162 WCHAR wchMode[32];
2163 PEDITLEXER pLexMode;
2164 UINT cp = ( UINT ) SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 );
2165 MultiByteToWideChar ( cp, 0, fvCurFile.tchMode, -1, wchMode, COUNTOF ( wchMode ) );
2166 if ( !fNoCGIGuess && ( lstrcmpi ( wchMode, L"cgi" ) == 0 || lstrcmpi ( wchMode, L"fcgi" ) == 0 ) ) {
2167 char tchText[256];
2168 SendMessage ( hwnd, SCI_GETTEXT, ( WPARAM ) COUNTOF ( tchText ) - 1, ( LPARAM ) tchText );
2169 StrTrimA ( tchText, " \t\n\r" );
2170 if ( pLexSniffed = Style_SniffShebang ( tchText ) ) {
2171 pLexNew = pLexSniffed;
2172 bFound = TRUE;
2173 }
2174 }
2175 if ( !bFound ) {
2176 if ( pLexMode = Style_MatchLexer ( wchMode, FALSE ) ) {
2177 pLexNew = pLexMode;
2178 bFound = TRUE;
2179 } else if ( pLexMode = Style_MatchLexer ( wchMode, TRUE ) ) {
2180 pLexNew = pLexMode;
2181 bFound = TRUE;
2182 }
2183 }
2184 }
2185 lpszExt = PathFindExtension ( lpszFile );
2186 if ( !bFound && bAutoSelect && /* bAutoSelect == FALSE skips lexer search */
2187 ( lpszFile && lstrlen ( lpszFile ) > 0 && *lpszExt ) ) {
2188 if ( *lpszExt == L'.' ) {
2189 lpszExt++;
2190 }
2191 if ( !fNoCGIGuess && ( lstrcmpi ( lpszExt, L"cgi" ) == 0 || lstrcmpi ( lpszExt, L"fcgi" ) == 0 ) ) {
2192 char tchText[256];
2193 SendMessage ( hwnd, SCI_GETTEXT, ( WPARAM ) COUNTOF ( tchText ) - 1, ( LPARAM ) tchText );
2194 StrTrimA ( tchText, " \t\n\r" );
2195 if ( pLexSniffed = Style_SniffShebang ( tchText ) ) {
2196 pLexNew = pLexSniffed;
2197 bFound = TRUE;
2198 }
2199 }
2200 // check associated extensions
2201 if ( !bFound ) {
2202 if ( pLexSniffed = Style_MatchLexer ( lpszExt, FALSE ) ) {
2203 pLexNew = pLexSniffed;
2204 bFound = TRUE;
2205 }
2206 }
2207 }
2208 if ( !bFound && bAutoSelect &&
2209 lstrcmpi ( PathFindFileName ( lpszFile ), L"makefile" ) == 0 ) {
2210 pLexNew = &lexMAK;
2211 bFound = TRUE;
2212 }

Callers 3

Style_SetLexerFromNameFunction · 0.85
_FileLoadFunction · 0.85
FileSaveFunction · 0.85

Calls 3

Style_SniffShebangFunction · 0.85
Style_MatchLexerFunction · 0.85
Style_SetLexerFunction · 0.85

Tested by

no test coverage detected