| 47 | //------------------------------------------ |
| 48 | |
| 49 | LexerLibrary::LexerLibrary(const char *ModuleName) { |
| 50 | // Initialise some members... |
| 51 | first = NULL; |
| 52 | last = NULL; |
| 53 | |
| 54 | // Load the DLL |
| 55 | lib = DynamicLibrary::Load(ModuleName); |
| 56 | if (lib->IsValid()) { |
| 57 | m_sModuleName = ModuleName; |
| 58 | //Cannot use reinterpret_cast because: ANSI C++ forbids casting between pointers to functions and objects |
| 59 | GetLexerCountFn GetLexerCount = (GetLexerCountFn)(sptr_t)lib->FindFunction("GetLexerCount"); |
| 60 | |
| 61 | if (GetLexerCount) { |
| 62 | ExternalLexerModule *lex; |
| 63 | LexerMinder *lm; |
| 64 | |
| 65 | // Find functions in the DLL |
| 66 | GetLexerNameFn GetLexerName = (GetLexerNameFn)(sptr_t)lib->FindFunction("GetLexerName"); |
| 67 | GetLexerFactoryFunction fnFactory = (GetLexerFactoryFunction)(sptr_t)lib->FindFunction("GetLexerFactory"); |
| 68 | |
| 69 | // Assign a buffer for the lexer name. |
| 70 | char lexname[100]; |
| 71 | strcpy(lexname, ""); |
| 72 | |
| 73 | int nl = GetLexerCount(); |
| 74 | |
| 75 | for (int i = 0; i < nl; i++) { |
| 76 | GetLexerName(i, lexname, 100); |
| 77 | lex = new ExternalLexerModule(SCLEX_AUTOMATIC, NULL, lexname, NULL); |
| 78 | Catalogue::AddLexerModule(lex); |
| 79 | |
| 80 | // Create a LexerMinder so we don't leak the ExternalLexerModule... |
| 81 | lm = new LexerMinder; |
| 82 | lm->self = lex; |
| 83 | lm->next = NULL; |
| 84 | if (first != NULL) { |
| 85 | last->next = lm; |
| 86 | last = lm; |
| 87 | } else { |
| 88 | first = lm; |
| 89 | last = lm; |
| 90 | } |
| 91 | |
| 92 | // The external lexer needs to know how to call into its DLL to |
| 93 | // do its lexing and folding, we tell it here. |
| 94 | lex->SetExternal(fnFactory, i); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | next = NULL; |
| 99 | } |
| 100 | |
| 101 | LexerLibrary::~LexerLibrary() { |
| 102 | Release(); |
nothing calls this directly
no test coverage detected