From 43479697d9f8d1f7b28d65aa0cb2d77cd590ce9b Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Sun, 5 Apr 2020 12:39:15 +1200 Subject: [PATCH] Output converted webpage. --- src/CExports.hs | 7 ++++--- src/main.c | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/CExports.hs b/src/CExports.hs index e034bfd..768f62a 100644 --- a/src/CExports.hs +++ b/src/CExports.hs @@ -29,6 +29,7 @@ import Data.ByteString (useAsCString) -- For c_extractLinks import Links (Link(..), extractLinks) import qualified Data.Text.Foreign as Txt +import Data.Text (strip) -- Types I can export to C import Foreign.Ptr @@ -120,11 +121,11 @@ foreign export ccall c_extractLinks :: StablePtr Page -> IO (CArray CString) c_extractLinks c_page = do page <- deRefStablePtr c_page ret <- forM (extractLinks $ html page) $ \link -> do - c_label <- text2cstring $ label link - c_title <- text2cstring $ title link + c_label <- text2cstring $ strip $ label link + c_title <- text2cstring $ strip $ title link c_href <- newCString $ uriToString id (href link) "" return [c_label, c_title, c_href] - nil <- newCString "" + nil <- newCString " " newArray0 nil $ concat ret text2cstring txt = Txt.withCStringLen txt $ \s -> (peekCStringLen s >>= newCString) diff --git a/src/main.c b/src/main.c index df81610..0178bd3 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include "HsFFI.h" struct session; @@ -26,7 +26,8 @@ int main(int argc, char **argv) { char *ssml = c_renderDoc(session, page); char **links = c_extractLinks(page); - printf("%i Hello, world!\n", argc); + printf("%s\n", ssml); + for (int i = 0; strcmp(links[i], " ") != 0; i++) fprintf(stderr, "%s\n", links[i]); c_freePage(page); c_freePage(referer); -- 2.30.2