KeyDebug.hs revision b87efd3db0d2dc41615ea28669faf80fc1b48d56
module OMDoc.KeyDebug where
import qualified Data.Map as Map
import Debug.Trace (trace)
import Data.Char (toLower)
import Data.List (find, isPrefixOf, isInfixOf, intercalate)
import Common.Utils (getEnvDef, splitOn, trim)
import qualified System.IO.Unsafe as SysUnsafe
keysWithPolicy::DbgKeyPolicy->[DbgKey]->Map.Map DbgKeyPolicy [DbgKey]
keysWithPolicy _ [] = Map.empty
keysWithPolicy p keys = Map.singleton p keys
(enkeys, diskeys) = foldl (\(e,d) i -> if head i == '!' then (e,d++[drop 1 i]) else (e++[i],d)) ([],[]) pkeys
) Map.empty) [ekwp, dkwp]
dbgKeys::Map.Map DbgKeyPolicy [DbgKey]
, dbgDisKeys :: Map.Map DbgKeyPolicy [DbgKey]
mkDebug keys diskeys = emptyDbgInf { dbgKeys = keysWithPolicy KPExact keys, dbgDisKeys = keysWithPolicy KPExact diskeys }
addDbgKey dbginf key = dbginf { dbgKeys = Map.insertWith (++) KPExact [key] (dbgKeys dbginf) }
addDbgDisKey dbginf key = dbginf { dbgDisKeys = Map.insertWith (++) KPExact [key] (dbgDisKeys dbginf) }
dbgKeys = Map.unionWith (++) (dbgKeys di1) (dbgKeys di2)
,dbgDisKeys = Map.unionWith (++) (dbgDisKeys di1) (dbgDisKeys di2)
any (\p -> policyElem p (Map.findWithDefault [] p (dbgDisKeys dbginf)) key) (Map.keys (dbgDisKeys dbginf))
(elem "all" (Map.findWithDefault [] KPExact (dbgKeys dbginf)))
|| any (\p -> policyElem p (Map.findWithDefault [] p (dbgKeys dbginf)) key) (Map.keys (dbgKeys dbginf))
envDbgInf = SysUnsafe.unsafePerformIO envDebug
Debug.Trace.trace (dbgkey ++ ": " ++ msg) x