From ca5e0017badc2099aadc5706e1ce947bfaef15f1 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Sun, 17 Jan 2021 19:07:13 +1300 Subject: [PATCH] Fix freezes & crashes. --- src/Links.hs | 22 ++++++++++++---------- src/main.c | 9 +++++---- useragent.css | 3 +++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Links.hs b/src/Links.hs index c69bad7..aa38638 100644 --- a/src/Links.hs +++ b/src/Links.hs @@ -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, diff --git a/src/main.c b/src/main.c index d632c8f..63f02df 100644 --- a/src/main.c +++ b/src/main.c @@ -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]); diff --git a/useragent.css b/useragent.css index e00c842..eeddae1 100644 --- a/useragent.css +++ b/useragent.css @@ -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 **/ -- 2.30.2