diff options
| -rw-r--r-- | gtk/PlatGTK.cxx | 36 | ||||
| -rw-r--r-- | gtk/ScintillaGTK.cxx | 4 | ||||
| -rw-r--r-- | gtk/deps.mak | 4 | ||||
| -rw-r--r-- | gtk/makefile | 2 | ||||
| -rw-r--r-- | gtk/scintilla.mak | 4 | ||||
| -rw-r--r-- | win32/ExternalLexer.cxx | 312 | ||||
| -rw-r--r-- | win32/ExternalLexer.h | 84 | ||||
| -rw-r--r-- | win32/PlatWin.cxx | 30 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 4 | ||||
| -rw-r--r-- | win32/scintilla.mak | 4 | 
10 files changed, 80 insertions, 404 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index aa0fb3659..d0778c707 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -9,6 +9,7 @@  #include <stddef.h>  #include <glib.h> +#include <gmodule.h>  #include <gdk/gdk.h>  #include <gtk/gtk.h>  #include <gdk/gdkkeysyms.h> @@ -1918,6 +1919,41 @@ ElapsedTime::ElapsedTime() {  	littleBit = curTime.tv_usec;  } +class DynamicLibraryImpl : public DynamicLibrary { +protected: +	GModule* m; +public: +	DynamicLibraryImpl(const char *modulePath) { +		m = g_module_open(modulePath, G_MODULE_BIND_LAZY); +	} + +	virtual ~DynamicLibraryImpl() { +		if (m != NULL) +			g_module_close(m); +	} + +	// Use g_module_symbol to get a pointer to the relevant function. +	virtual Function *FindFunction(const char *name) { +		if (m != NULL) { +			gpointer fn_address = NULL; +			gboolean status = g_module_symbol(m, name, &fn_address); +			if (status) +				return static_cast<Function*>( fn_address ); +			else +				return NULL; +		} else +			return NULL; +	} + +	virtual bool IsValid() { +		return m != NULL; +	} +}; + +DynamicLibrary *DynamicLibrary::Load(const char *modulePath) { +	return static_cast<DynamicLibrary *>( new DynamicLibraryImpl(modulePath) ); +} +  double ElapsedTime::Duration(bool reset) {  	GTimeVal curTime;  	g_get_current_time(&curTime); diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 7029383a9..d3753b5d2 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -49,7 +49,7 @@  #ifdef SCI_LEXER  #include <glib.h>  #include <gmodule.h> -//#include "ExternalLexer.h" +#include "ExternalLexer.h"  #endif  #if GTK_MAJOR_VERSION < 2 @@ -619,7 +619,7 @@ sptr_t ScintillaGTK::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam  #ifdef SCI_LEXER  	case SCI_LOADLEXERLIBRARY: -		//LexerManager::GetInstance()->Load(reinterpret_cast<const char*>( wParam )); +		LexerManager::GetInstance()->Load(reinterpret_cast<const char*>( wParam ));  		break;  #endif diff --git a/gtk/deps.mak b/gtk/deps.mak index 8590dd758..1fe47ca31 100644 --- a/gtk/deps.mak +++ b/gtk/deps.mak @@ -27,6 +27,10 @@ Editor.o: ../src/Editor.cxx ../include/Platform.h ../include/Scintilla.h \    ../src/ContractionState.h ../src/SVector.h ../src/CellBuffer.h \
    ../src/KeyMap.h ../src/Indicator.h ../src/XPM.h ../src/LineMarker.h \
    ../src/Style.h ../src/ViewStyle.h ../src/Document.h ../src/Editor.h
 +ExternalLexer.o: ../src/ExternalLexer.cxx ../include/Platform.h \
 + ../include/Scintilla.h ../include/SciLexer.h ../include/PropSet.h \
 + ../include/Accessor.h ../src/DocumentAccessor.h ../src/Keywords.h \
 + ../src/ExternalLexer.h
  Indicator.o: ../src/Indicator.cxx ../include/Platform.h \
    ../include/Scintilla.h ../src/Indicator.h
  KeyMap.o: ../src/KeyMap.cxx ../include/Platform.h ../include/Scintilla.h \
 diff --git a/gtk/makefile b/gtk/makefile index 2cd2d5262..b8d00556b 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -65,7 +65,7 @@ deps:  	$(CC) -MM `$(CONFIGFLAGS)` $(CXXFLAGS) *.cxx ../src/*.cxx >deps.mak  $(COMPLIB): DocumentAccessor.o WindowAccessor.o KeyWords.o StyleContext.o Document.o CallTip.o \ -	ScintillaBase.o ContractionState.o Editor.o PropSet.o PlatGTK.o \ +	ScintillaBase.o ContractionState.o Editor.o ExternalLexer.o PropSet.o PlatGTK.o \  	KeyMap.o LineMarker.o ScintillaGTK.o CellBuffer.o ViewStyle.o \  	RESearch.o Style.o Indicator.o AutoComplete.o UniConversion.o XPM.o  	$(AR) rc $@ $^ diff --git a/gtk/scintilla.mak b/gtk/scintilla.mak index 33e454c0c..81a01bfd7 100644 --- a/gtk/scintilla.mak +++ b/gtk/scintilla.mak @@ -103,6 +103,7 @@ SOBJS=\  	$(DIR_O)\ContractionState.obj \  	$(DIR_O)\Document.obj \  	$(DIR_O)\Editor.obj \ +	$(DIR_O)\ExternalLexer.obj \  	$(DIR_O)\Indicator.obj \  	$(DIR_O)\KeyMap.obj \  	$(DIR_O)\LineMarker.obj \ @@ -241,6 +242,9 @@ $(DIR_O)\Editor.obj: ..\src\Editor.cxx ..\include\Platform.h ..\include\Scintill   ..\src\CellBuffer.h ..\src\KeyMap.h ..\src\Indicator.h ..\src\LineMarker.h ..\src\Style.h ..\src\ViewStyle.h \   ..\src\Document.h ..\src\Editor.h +$(DIR_O)\ExternalLexer.obj: ..\src\ExternalLexer.cxx ..\include\Platform.h ..\include\Scintilla.h ..\include\SciLexer.h \ + ..\include\PropSet.h ..\include\Accessor.h ..\src\DocumentAccessor.h ..\src\Keywords.h ..\src\ExternalLexer.h +  $(DIR_O)\Indicator.obj: ..\src\Indicator.cxx ..\include\Platform.h ..\include\Scintilla.h ..\src\Indicator.h  $(DIR_O)\KeyMap.obj: ..\src\KeyMap.cxx ..\include\Platform.h ..\include\Scintilla.h ..\src\KeyMap.h diff --git a/win32/ExternalLexer.cxx b/win32/ExternalLexer.cxx deleted file mode 100644 index 41cc812bc..000000000 --- a/win32/ExternalLexer.cxx +++ /dev/null @@ -1,312 +0,0 @@ -// Scintilla source code edit control -/** @file ExternalLexer.cxx - ** Support external lexers in DLLs. - **/ -// Copyright 2001 Simon Steele <ss@pnotepad.org>, portions copyright Neil Hodgson. -// The License.txt file describes the conditions under which this software may be distributed. - -#include <stdlib.h>  -#include <stdio.h>  -#include <ctype.h>  - -#define _WIN32_WINNT  0x0400 -#include <windows.h> - -#include "Platform.h" -#include "SciLexer.h" -#include "PropSet.h" -#include "Accessor.h" -#include "DocumentAccessor.h" -#include "KeyWords.h" -#include "ExternalLexer.h" - -// Initialise the static vars... -int LexerManager::UseCount = 0; -LexerLibrary *LexerManager::first = NULL; -LexerLibrary *LexerManager::last = NULL; -LexerManager *LexerManager::firstlm = NULL; - -//------------------------------------------ -// -// ExternalLexerModule -// -//------------------------------------------ - -char **WordListsToStrings(WordList *val[]) { -	int dim = 0; -	while (val[dim]) -		dim++; -	char **wls = new char * [dim + 1]; -	for (int i = 0;i < dim;i++) { -		SString words; -		words = ""; -		for (int n = 0; n < val[i]->len; n++) { -			words += val[i]->words[n]; -			if (n != val[i]->len - 1) -				words += " "; -		} -		wls[i] = new char[words.length() + 1]; -		strcpy(wls[i], words.c_str()); -	} -	wls[dim] = 0; -	return wls; -} - -void DeleteWLStrings(char *strs[]) { -	int dim = 0; -	while (strs[dim]) { -		delete strs[dim]; -		dim++; -	} -	delete [] strs; -} - -void ExternalLexerModule::Lex(unsigned int startPos, int lengthDoc, int initStyle, -                              WordList *keywordlists[], Accessor &styler) const { -	if (!fneLexer) -		return ; - -	char **kwds = WordListsToStrings(keywordlists); -	char *ps = styler.GetProperties(); -	 -	// The accessor passed in is always a DocumentAccessor so this cast and the subsequent  -	// access will work. Can not use the stricter dynamic_cast as that requires RTTI. -	DocumentAccessor &da = static_cast<DocumentAccessor &>(styler); -	WindowID wID = da.GetWindow(); - -	fneLexer(externalLanguage, startPos, lengthDoc, initStyle, kwds, wID, ps); - -	delete ps; -	DeleteWLStrings(kwds); -} - -void ExternalLexerModule::Fold(unsigned int startPos, int lengthDoc, int initStyle, -                               WordList *keywordlists[], Accessor &styler) const { -	if (!fneFolder) -		return ; - -	char **kwds = WordListsToStrings(keywordlists); -	char *ps = styler.GetProperties(); -	 -	// The accessor passed in is always a DocumentAccessor so this cast and the subsequent  -	// access will work. Can not use the stricter dynamic_cast as that requires RTTI. -	DocumentAccessor &da = static_cast<DocumentAccessor &>(styler); -	WindowID wID = da.GetWindow(); - -	fneFolder(externalLanguage, startPos, lengthDoc, initStyle, kwds, wID, ps); - -	delete ps; -	DeleteWLStrings(kwds); -} - -void ExternalLexerModule::SetExternal(ExtLexerFunction fLexer, ExtFoldFunction fFolder, int index) { -	fneLexer = fLexer; -	fneFolder = fFolder; -	externalLanguage = index; -} - -//------------------------------------------ -// -// LexerLibrary -// -//------------------------------------------ - -LexerLibrary::LexerLibrary(LPCTSTR ModuleName) { -	// Initialise some members... -	first = NULL; -	last = NULL; - -	// Load the DLL -	m_hModule = LoadLibrary(ModuleName); -	if (m_hModule) { -		m_sModuleName = ModuleName; -		GetLexerCountFn GetLexerCount = (GetLexerCountFn)GetProcAddress(m_hModule, "GetLexerCount"); - -		if (GetLexerCount) { -			ExternalLexerModule *lex; -			LexerMinder *lm; - -			// Find functions in the DLL -			GetLexerNameFn GetLexerName = (GetLexerNameFn)GetProcAddress(m_hModule, "GetLexerName"); -			ExtLexerFunction Lexer = (ExtLexerFunction)GetProcAddress(m_hModule, "Lex"); -			ExtFoldFunction Folder = (ExtFoldFunction)GetProcAddress(m_hModule, "Fold"); - -			// Assign a buffer for the lexer name. -			char lexname[100]; -			strcpy(lexname, ""); - -			int nl = GetLexerCount(); - -			for (int i = 0; i < nl; i++) { -				GetLexerName(i, lexname, 100); -				lex = new ExternalLexerModule(SCLEX_AUTOMATIC, NULL, lexname, NULL); - -				// Create a LexerMinder so we don't leak the ExternalLexerModule... -				lm = new LexerMinder; -				lm->self = lex; -				lm->next = NULL; -				if (first != NULL) { -					last->next = lm; -					last = lm; -				} else { -					first = lm; -					last = lm; -				} - -				// The external lexer needs to know how to call into its DLL to -				// do its lexing and folding, we tell it here. Folder may be null. -				lex->SetExternal(Lexer, Folder, i); - -			} -		} -	} -	next = NULL; -} - -LexerLibrary::~LexerLibrary() { -	Release(); -} - -void LexerLibrary::Release() { -	//TODO maintain a list of lexers created, and delete them! -	LexerMinder *lm; -	LexerMinder *next; -	lm = first; -	while (NULL != lm) { -		next = lm->next; -		delete lm->self; -		delete lm; -		lm = next; -	} - -	first = NULL; -	last = NULL; - -	// Release the DLL -	if (NULL != m_hModule) { -		FreeLibrary(m_hModule); -	} -} - -//------------------------------------------ -// -// LexerManager -// -//------------------------------------------ - -int FindLastSlash(char *inp) { -	int ret = -1; -	for (int i = static_cast<int>(strlen(inp)) - 1; i >= 0; i--) { -		if (inp[i] == '\\' || inp[i] == '/') { -			// if you don't like break: -			/* -			if (ret == -1) -			*/ -			ret = i; -			break; -		} -	} -	return ret; -} - -LexerManager::LexerManager() { -	 -	UseCount++; -	if (1 == UseCount) { -		firstlm = this; -		m_bLoaded = false; -	} -} - -void LexerManager::EnumerateLexers() { -	HANDLE hFind; -	WIN32_FIND_DATA FindFileData; - -	char path[MAX_PATH + 1]; - -	GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH); - -	int i = FindLastSlash(path); - -	if (i == -1) -		i = static_cast<int>(strlen(path)); - -	SString sPath(path, 0, i); - -	// Ensure a trailing slash... -	if ( sPath[sPath.size() - 1] != '/' && sPath[sPath.size() - 1] != '\\' ) { -		sPath += '\\'; -	} - -	SString sPattern(sPath); -	sPattern += "*.lexer"; - -	hFind = FindFirstFile(sPattern.c_str(), &FindFileData); -	if (hFind != INVALID_HANDLE_VALUE) { -		//Found the first file... -		BOOL found = TRUE; -		SString to_open; - -		while (found) { -			to_open = sPath; -			to_open += FindFileData.cFileName; -			LexerLibrary *lib = new LexerLibrary(to_open.c_str()); -			if (NULL != first) { -				last->next = lib; -				last = lib; -			} else { -				first = lib; -				last = lib; -			} -			found = FindNextFile(hFind, &FindFileData); -		} - -		FindClose(hFind); - -	} -} - -LexerManager::~LexerManager() { -	// If this is the last LexerManager to be freed then -	// we delete all of our LexerLibrarys. -	UseCount--; -	if (0 == UseCount) { -		if (NULL != first) { -			LexerLibrary *cur = first; -			LexerLibrary *next = first->next; -			while (cur) { -				delete cur; -				cur = next; -			} -			first = NULL; -			last = NULL; -		} -	} -	if (this == firstlm) -		firstlm = NULL; -} - -void LexerManager::Load() -{ -	if(!m_bLoaded) -	{ -		m_bLoaded = true; -		EnumerateLexers(); -	} -} - -// Return a LexerManager, or create one and then return it. -LexerManager *LexerManager::GetInstance() { -	if(!firstlm) -		firstlm = new LexerManager; -	return firstlm; -} - -LMMinder::~LMMinder() -{ -	LexerManager *rem = LexerManager::firstlm; -	if(rem) -		delete rem; -} - -LMMinder minder; diff --git a/win32/ExternalLexer.h b/win32/ExternalLexer.h deleted file mode 100644 index 188ded7a5..000000000 --- a/win32/ExternalLexer.h +++ /dev/null @@ -1,84 +0,0 @@ -// Scintilla source code edit control -/** @file ExternalLexer.h - ** Support external lexers in DLLs. - **/ -// Copyright 2001 Simon Steele <ss@pnotepad.org>, portions copyright Neil Hodgson. -// The License.txt file describes the conditions under which this software may be distributed. - -#ifndef EXTERNALLEXER_H -#define EXTERNALLEXER_H - -// External Lexer function definitions... -typedef void (__stdcall *ExtLexerFunction)(unsigned int lexer, unsigned int startPos, int length, int initStyle, -                  char *words[], WindowID window, char *props); -typedef void (__stdcall *ExtFoldFunction)(unsigned int lexer, unsigned int startPos, int length, int initStyle, -                  char *words[], WindowID window, char *props); -typedef void* (__stdcall *GetLexerFunction)(unsigned int Index); -typedef int (__stdcall *GetLexerCountFn)(); -typedef void (__stdcall *GetLexerNameFn)(unsigned int Index, char *name, int buflength); - -// Sub-class of LexerModule to use an external lexer. -class ExternalLexerModule : protected LexerModule { -protected: -	ExtLexerFunction fneLexer; -	ExtFoldFunction fneFolder; -	int externalLanguage; -	char name[100]; -public: -	ExternalLexerModule(int language_, LexerFunction fnLexer_,  -		const char *languageName_=0, LexerFunction fnFolder_=0) : LexerModule(language_, fnLexer_, 0, fnFolder_){ -		strncpy(name, languageName_, sizeof(name)); -		languageName = name; -	}; -	virtual void Lex(unsigned int startPos, int lengthDoc, int initStyle, -					WordList *keywordlists[], Accessor &styler) const; -	virtual void Fold(unsigned int startPos, int lengthDoc, int initStyle, -					WordList *keywordlists[], Accessor &styler) const; -	virtual void SetExternal(ExtLexerFunction fLexer, ExtFoldFunction fFolder, int index); -}; - -// LexerMinder points to an ExternalLexerModule - so we don't leak them. -class LexerMinder { -public: -	ExternalLexerModule *self; -	LexerMinder *next; -}; - -// LexerLibrary exists for every External Lexer DLL, contains LexerMinders. -class LexerLibrary { -public: -	LexerLibrary(LPCTSTR ModuleName); -	~LexerLibrary(); -	void Release(); -	// Variables -	LexerLibrary	*next; -	SString			m_sModuleName; -private: -	HMODULE m_hModule; -	LexerMinder *first; -	LexerMinder *last; -}; - -// LexerManager manages external lexers, contains LexerLibrarys. -class LexerManager { -	friend class LMMinder; -public: -	LexerManager(); -	~LexerManager(); -	void Load(); -	static LexerManager *GetInstance(); -private: -	bool m_bLoaded; -	void EnumerateLexers(); -	static int UseCount; -	static LexerLibrary *first; -	static LexerLibrary *last; -	static LexerManager *firstlm; -}; - -class LMMinder { -public: -	~LMMinder(); -}; - -#endif diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index bf6112d57..c61a67ca9 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -1288,6 +1288,36 @@ double ElapsedTime::Duration(bool reset) {  	return result;  } +class DynamicLibraryImpl : public DynamicLibrary { +protected: +	HMODULE h; +public: +	DynamicLibraryImpl(const char *modulePath) { +		h = ::LoadLibrary(modulePath); +	} + +	virtual ~DynamicLibraryImpl() { +		if (h != NULL) +			::FreeLibrary(h); +	} + +	// Use GetProcAddress to get a pointer to the relevant function. +	virtual Function *FindFunction(const char *name) { +		if (h != NULL) { +			return reinterpret_cast<Function*>( ::GetProcAddress(h, name) ); +		} else +			return NULL; +	} + +	virtual bool IsValid() { +		return h != NULL; +	} +}; + +DynamicLibrary *DynamicLibrary::Load(const char *modulePath) { +	return static_cast<DynamicLibrary *>( new DynamicLibraryImpl(modulePath) ); +} +  ColourDesired Platform::Chrome() {  	return ::GetSysColor(COLOR_3DFACE);  } diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 724df8359..a49daf61b 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -842,7 +842,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam  #ifdef SCI_LEXER  	case SCI_LOADLEXERLIBRARY: -		//LexerManager::GetInstance()->Load(reinterpret_cast<const char*>(lParam)); +		LexerManager::GetInstance()->Load(reinterpret_cast<const char*>(lParam));  		break;  #endif @@ -2026,8 +2026,6 @@ bool Scintilla_RegisterClasses(void *hInstance) {  	bool result = ScintillaWin::Register(reinterpret_cast<HINSTANCE>(hInstance));  #ifdef SCI_LEXER  	Scintilla_LinkLexers(); -	LexerManager *lexMan = LexerManager::GetInstance(); -	lexMan->Load();  #endif  	return result;  } diff --git a/win32/scintilla.mak b/win32/scintilla.mak index 2865ef725..c60c903b9 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -226,10 +226,10 @@ $(DIR_O)\Editor.obj: ../src/Editor.cxx ../include/Platform.h \   ../src/CellBuffer.h ../src/KeyMap.h ../src/Indicator.h \   ../src/LineMarker.h ../src/Style.h ../src/ViewStyle.h \   ../src/Document.h ../src/Editor.h ../src/XPM.h -$(DIR_O)\ExternalLexer.obj: ExternalLexer.cxx ../include/Platform.h \ +$(DIR_O)\ExternalLexer.obj: ../src/ExternalLexer.cxx ../include/Platform.h \   ../include/SciLexer.h ../include/PropSet.h ../include/SString.h \   ../include/Accessor.h ../src/DocumentAccessor.h ../include/KeyWords.h \ - ExternalLexer.h + ../src/ExternalLexer.h  $(DIR_O)\Indicator.obj: ../src/Indicator.cxx ../include/Platform.h \   ../include/Scintilla.h ../src/Indicator.h  $(DIR_O)\KeyMap.obj: ../src/KeyMap.cxx ../include/Platform.h \  | 
