Thanks Chris!
I tweaked the include a bit to work on 32bit Linux, should be easy to do for osx as well, only the function names seem to differ slightly.
Download link for recent Linux library and example :
http://goo.gl/94bH4Tweaked include:
Code:
#hunspellDLLx86 = "Hunspellx86.dll"
#hunspellDLLx64 = "Hunspellx64.dll"
#hunspellSOx86linux = "./libhunspell-1.3.so"
Global *hunspellLib ; stores handle to hunspell lib
Global *hunspell ; stores handle to initialised hunspell object
Global hunspell_dicpath.s ; stores path to current dictionary file
Global hunspellReturnString$ ; used in PureBasic Userlib to return string
; hunspell prototypes
PrototypeC.i HSInit_PT(aff_file.p-utf8, dic_file.p-utf8) : Global HSInit.HSInit_PT
PrototypeC.i HSFree_PT(*hunspell) : Global HSFree.HSFree_PT
PrototypeC.i HSSpell_PT(*hunspell, word.p-utf8) : Global HSSpell.HSSpell_PT
PrototypeC.i HSSuggest_PT(*hunspell, *elements, word.p-utf8) : Global HSSuggest.HSSuggest_PT
PrototypeC.i HSAdd_PT(*hunspell, word.p-utf8) : Global HSAdd.HSAdd_PT
; ******************************* public commands here ********************************************************
Procedure SpellCheck_Dictionary(dicPath.s) ; Sets the current dictionary, returns nonzero if successful
If *hunspellLib = 0
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
hunspell$ = #hunspellSOx86linux
CompilerEndIf
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
hunspell$ = #hunspellDLLx86
CompilerElse
hunspell$ = #hunspellDLLx64
CompilerEndIf
CompilerEndIf
*hunspellLib = OpenLibrary(#PB_Any, hunspell$)
If *hunspellLib
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
HSInit = GetFunction(*hunspellLib, "hunspell_initialize")
HSFree = GetFunction(*hunspellLib, "hunspell_uninitialize")
HSSpell = GetFunction(*hunspellLib, "hunspell_spell")
HSSuggest = GetFunction(*hunspellLib,"Hunspell_suggest")
HSAdd = GetFunction(*hunspellLib,"Hunspell_add")
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
HSInit = GetFunction(*hunspellLib, "Hunspell_create")
HSFree = GetFunction(*hunspellLib, "Hunspell_free")
HSSpell = GetFunction(*hunspellLib, "Hunspell_spell")
HSSuggest = GetFunction(*hunspellLib,"Hunspell_suggest")
HSAdd = GetFunction(*hunspellLib,"Hunspell_add")
CompilerEndIf
Else
MessageRequester("Error!","Can't open library "+hunspell$+"!")
EndIf
EndIf
If *hunspellLib <> 0
If *hunspell
HSFree(*hunspell)
EndIf
*hunspell = HSInit(StringField(dicPath, 1, ".")+".aff", dicPath)
hunspell_dicpath = dicPath
datFile = ReadFile(#PB_Any, StringField(hunspell_dicpath, 1, ".")+".dat")
If datFile
While Eof(datFile) = 0
HSAdd(*hunspell, ReadString(datFile, #PB_UTF8))
Wend
CloseFile(datFile)
EndIf
EndIf
ProcedureReturn *hunspell
EndProcedure
Procedure SpellCheck(word.s) ; Checks spelling of specified word, returns true if correct spelling, false otherwise
If *hunspell
ProcedureReturn HSSpell(*hunspell, word)
EndIf
EndProcedure
Procedure.s SpellCheck_Suggest(word.s) ; Offers suggestions for a word, returns string containing comma separated list
If *hunspell
hunspellReturnString$ = ""
*elements = AllocateMemory(1024)
If *elements
suggestions = HSSuggest(*hunspell, *elements, word)
If suggestions > 0
For i = 0 To Suggestions-1
hunspellReturnString$ + PeekS(PeekI(PeekI(*elements)+(i*SizeOf(*elements))), -1, #PB_UTF8)
If i < Suggestions-1
hunspellReturnString$ + ","
EndIf
Next
EndIf
FreeMemory(*elements)
EndIf
EndIf
ProcedureReturn hunspellReturnString$
EndProcedure
Procedure SpellCheck_Ignore(word.s) ; Adds a new temporary word to the current spellcheck session, having the effect of ignoring the specified word
If *hunspell
HSAdd(*hunspell, word)
ProcedureReturn #True
EndIf
EndProcedure
Procedure SpellCheck_Add(word.s) ; Adds a new word to the custom user dictionary of the currently opened dictionary
; word not already learnt
If *hunspell And SpellCheck(word) = 0
datFile = OpenFile(#PB_Any, StringField(hunspell_dicpath, 1, ".")+".dat")
If datFile
FileSeek(datFile, Lof(datFile))
WriteStringN(datFile, word, #PB_UTF8)
CloseFile(datFile)
HSAdd(*hunspell, word)
ProcedureReturn #True
EndIf
EndIf
EndProcedure
Procedure SpellCheck_End() ; Free the hunspell library
If *hunspell
HSFree(*hunspell)
CloseLibrary(*hunspellLib)
*hunspell = #False
*hunspellLib = #False
EndIf
EndProcedure