~alcinnz/rhapsode

ca5e0017badc2099aadc5706e1ce947bfaef15f1 — Adrian Cochrane 3 years ago fa07e2d
Fix freezes & crashes.
3 files changed, 20 insertions(+), 14 deletions(-)

M src/Links.hs
M src/main.c
M useragent.css
M src/Links.hs => src/Links.hs +12 -10
@@ 26,6 26,7 @@ import Data.Trie.Text (Trie)
import qualified Data.Trie.Text as Trie
import Data.List (nub, intercalate)
import Control.Concurrent (forkIO)
import qualified System.IO.Strict as Strict

data Link = Link {
    label :: Text,


@@ 51,7 52,7 @@ extractMisc (_:misc) = extractMisc misc
extractMisc [] = []

extractEl path el@(Element (Name "details" _ _) _ childs) =
    [Link (nodesText summary' $ nodesText childs "") "+" nullURI {
   [Link (nodesText summary' $ nodesText childs "") "+" nullURI {
        uriFragment = '#':'.':intercalate "." (map show $ reverse path)
    } | NodeElement summary@(Element (Name "summary" _ _) _ summary') <- childs] ++
    extractNodes (0:path) childs


@@ 63,15 64,16 @@ extractEl _ (Element "{https://specifications.freedesktop.org/metainfo/1.0}url" 
extractEl _ el@(Element _ attrs [])
    | Just "alternate" <- "rel" `M.lookup` attrs', Just typ <- "type" `M.lookup` attrs',
            Just val <- "href" `M.lookup` attrs', Just uri <- parseURIReference $ unpack val =
        let Application name _ title _ = mimeInfo $ unpack typ
        in [Link (pack name) (pack title) uri]
  where attrs' = M.mapKeys nameLocalName attrs
extractEl _ el@(Element (Name "link" _ _) attrs [])
    | Just "stylesheet" <- "rel" `M.lookup` attrs', Nothing <- "title" `M.lookup` attrs',
            Just val <- "href" `M.lookup` attrs', Just uri <- parseURIReference $ unpack val =
        let Application name _ title _ = mimeInfo "text/css"
        in [Link (pack name) (pack title) uri]
--        let Application name _ title _ = mimeInfo $ unpack typ
--        in [Link (pack name) (pack title) uri] -- FIXME `mimeInfo` freezes...
        [Link typ "" uri]
  where attrs' = M.mapKeys nameLocalName attrs
--extractEl _ el@(Element (Name "link" _ _) attrs [])
--    | Just "stylesheet" <- "rel" `M.lookup` attrs', Nothing <- "title" `M.lookup` attrs',
--            Just val <- "href" `M.lookup` attrs', Just uri <- parseURIReference $ unpack val =
--        let Application name _ title _ = mimeInfo "text/css"
--        in [Link (pack name) (pack title) uri]
--  where attrs' = M.mapKeys nameLocalName attrs
extractEl path el@(Element _ _ children) =
    extractElAttr el "href" ++
    extractElAttr el "longdesc" ++


@@ 166,7 168,7 @@ updateSuggestions page = do
    let path = dir </> "suggestions.gmni"
    exists <- doesFileExist path
    suggestions <- if not exists then return [] else do
        file <- Prelude.readFile path
        file <- Strict.readFile path
        return [line' | line <- lines file, line'@(_:uri':_) <- [words line], not (pack uri' `Trie.member` visitedURLs page)]

    let suggestions' = suggestions ++ nub [["=>", uri', domain] | link <- links,

M src/main.c => src/main.c +5 -4
@@ 357,8 357,10 @@ void write_links() {
void read_page(char *uri, int read_input) {
    if (uri == NULL) return; // Leave things as-is...

    for (int i = 0; strcmp(links[i], " ") != 0; i++) free(links[i]);
    free(links);
    if (links != NULL) { // Ensure links is freed...
        for (int i = 0; strcmp(links[i], " ") != 0; i++) free(links[i]);
        free(links);
    }

    if (use_espeak && speak_err == 0) speak_text(uri, espeakRATE, 10);
    #ifdef WITH_SPEECHD


@@ 382,11 384,10 @@ void read_page(char *uri, int read_input) {
    #endif

    c_freePage(page);
    free(uri);
    //free(uri);

    if (read_input) {
        g_io_add_watch(g_io_channel_unix_new(0), G_IO_IN|G_IO_HUP, read_stdin, ssml);
        // if (use_espeak & speak_err == 0) speak_err = speak_finalize(ssml);
    } else {
        free(ssml);
        for (int i = 0; strcmp(links[i], " ") != 0; i++) free(links[i]);

M useragent.css => useragent.css +3 -0
@@ 34,6 34,9 @@ td, th {
    counter-increment: -rhaps-tablecol attr(rowspan); /* TODO parse this syntax */
    counter-increment: -rhaps-tablecol;
}
td::before, th::before {
    content: counter(-rhaps-tablerow) " " counter(-rhaps-tablecol)
}
table caption {voice-volume: soft}

/** Sectioning **/