diff --git a/contrib/c-bindings/PGFFFI.hs b/contrib/c-bindings/PGFFFI.hs index a957e3e35..5506e2b58 100644 --- a/contrib/c-bindings/PGFFFI.hs +++ b/contrib/c-bindings/PGFFFI.hs @@ -1,5 +1,5 @@ -- GF C Bindings --- Copyright (C) 2008-2009 Kevin Kofler +-- Copyright (C) 2008-2010 Kevin Kofler -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Lesser General Public @@ -24,7 +24,7 @@ import Foreign.C.Types import Control.Exception import IO import Data.Maybe -import GF.Text.Lexing +-- import GF.Text.Lexing -- Utility functions used in the implementation (not exported): @@ -217,13 +217,13 @@ gf_parse pgf lang cat input = do -- GF.Text.Lexing: -foreign export ccall gf_stringOp :: CString -> CString -> IO CString -gf_stringOp op str = do - o <- (peekCString op) - s <- (peekCString str) - case (stringOp o) of - Just fn -> (newCString (fn s)) - Nothing -> (return nullPtr) +-- foreign export ccall gf_stringOp :: CString -> CString -> IO CString +-- gf_stringOp op str = do +-- o <- (peekCString op) +-- s <- (peekCString str) +-- case (stringOp o) of +-- Just fn -> (newCString (fn s)) +-- Nothing -> (return nullPtr) -- Unused (exception handling): diff --git a/contrib/c-bindings/build-gfctest.sh b/contrib/c-bindings/build-gfctest.sh index c0929d517..e8cbdfea4 100644 --- a/contrib/c-bindings/build-gfctest.sh +++ b/contrib/c-bindings/build-gfctest.sh @@ -1,7 +1,7 @@ #!/bin/sh # GF C Bindings -# Copyright (C) 2008-2009 Kevin Kofler +# Copyright (C) 2008-2010 Kevin Kofler # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -17,4 +17,4 @@ # License along with this library; if not, see . ghc --make -fglasgow-exts -O2 -no-hs-main $* -c PGFFFI.hs && -ghc --make -fglasgow-exts -O2 -no-hs-main $* gfctest.c PGFFFI.hs -o gfctest +ghc --make -fglasgow-exts -O2 -no-hs-main $* gfctest.c gf_lexing.c PGFFFI.hs -o gfctest diff --git a/contrib/c-bindings/gfctest.c b/contrib/c-bindings/gfctest.c index f11b103db..1b5dd97c1 100644 --- a/contrib/c-bindings/gfctest.c +++ b/contrib/c-bindings/gfctest.c @@ -18,6 +18,7 @@ #include #include #include "pgf.h" +#include "gf_lexing.h" int main(int argc, char *argv[]) { @@ -26,7 +27,7 @@ int main(int argc, char *argv[]) GF_PGF pgf = gf_readPGF("../examples/tutorial/embedded/Query.pgf"); GF_Language lang = gf_readLanguage("QueryEng"); GF_Type cat = gf_startCat(pgf); - char *lexed = gf_stringOp("lextext", "Is 2 prime"); + char *lexed = gf_stringOp("lextext")("Is 2 prime"); GF_Tree *result = gf_parse(pgf, lang, cat, lexed); free(lexed); GF_Tree *p = result; diff --git a/contrib/c-bindings/readme-ffi.txt b/contrib/c-bindings/readme-ffi.txt index c0728b567..bc9abb294 100644 --- a/contrib/c-bindings/readme-ffi.txt +++ b/contrib/c-bindings/readme-ffi.txt @@ -1,5 +1,5 @@ GF C Bindings -Copyright (C) 2008-2009 Kevin Kofler +Copyright (C) 2008-2010 Kevin Kofler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -109,10 +109,12 @@ void gf_freeTrees(GF_Tree *p); -In addition, the following function from GF.Text.Lexing: +In addition, a C equivalent to the following function from GF.Text.Lexing: stringOp :: String -> Maybe (String -> String) -is wrapped as: -char *gf_stringOp(char *op, char *str) -which returns NULL if op is not a valid operation name, otherwise applies the -function corresponding to op to the string str. The resulting string must be -freed with free if non-NULL. +is provided as: +typedef char *(*GF_StringOp)(const char *str); +GF_StringOp gf_stringOp(const char *op); /* may return NULL */ +which returns NULL if op is not a valid operation name, otherwise a pointer to a +function which applies the function corresponding to op to the string str. The +resulting string must be freed with free. The function pointer MUST NOT be +freed.