Compare commits

..
Author SHA1 Message Date
60f4cc8216 fix FFI
Signed-off-by: hashirama <hashirama@noreply.localhost>
2026-01-20 03:27:06 +00:00
5b67ca2164 use the target function
the processDictionary function is the one we need to use for lookups, because it inserts all resources and gives just the full html at the end, ready to be displayed

Signed-off-by: hashirama <hashirama@noreply.localhost>
2026-01-20 03:24:16 +00:00
7b64430472 Merge pull request 'separate pure and IO' (#3) from castelia/mdict-hs:main into main
Reviewed-on: hashirama/mdict-hs#3
2026-01-20 02:11:15 +00:00
2 changed files with 16 additions and 11 deletions

View file

@ -75,8 +75,8 @@ isMDDFile path = map toLower (takeExtension path) == ".mdd"
-- FFI imports
foreign import ccall "mdict_init" c_mdict_init :: CString -> IO (Ptr ())
foreign import ccall "mdict_destory" c_mdict_destroy :: Ptr () -> IO CInt
foreign import ccall "&mdict_destory" raw_mdict_destroy_finalizer :: FunPtr (Ptr () -> IO CInt)
foreign import ccall "mdict_destroy" c_mdict_destroy :: Ptr () -> IO CInt
foreign import ccall "&mdict_destroy" raw_mdict_destroy_finalizer :: FunPtr (Ptr () -> IO CInt)
foreign import ccall "mdict_lookup" c_mdict_lookup :: Ptr () -> CString -> Ptr (Ptr CChar) -> IO ()
foreign import ccall "mdict_atomic_lookup" c_mdict_atomic_lookup :: CString -> CString -> IO CString
foreign import ccall "mdict_locate" c_mdict_locate :: Ptr () -> CString -> Ptr (Ptr CChar) -> CInt -> IO ()

View file

@ -3,17 +3,22 @@
import System.Environment (getArgs)
import System.Exit (exitFailure)
import Control.Monad (when)
import MDict (lookupInCollection)
import MDict
main :: IO ()
main = do
args <- getArgs
when (length args < 2) $ do
putStrLn "Usage: Main <dictionary_dir> <query_key>"
exitFailure
args <- getArgs
when (length args < 2) $ do
putStrLn "Usage: Main <dictionary_dir> <query_key>"
exitFailure
let dictDir = args !! 0
queryKey = args !! 1
let dict = args !! 0
queryKey = args !! 1
-- Process all files
lookupInCollection dictDir queryKey
res <- processDictionary dict queryKey
html <- case res of
Left err -> error err
Right h -> return h
putStrLn (html)