1 -- partain: the failure (crashing) was w/ -prof-auto compilation
5 xreff :: Int -> [String] -> Table -> Int -> String -> String
6 xreff cc exs stab lineno [] = display (foldl delete stab exs)
7 xreff cc exs stab lineno ('\n':cs) = xreff cc exs stab (lineno+1) cs
8 xreff cc exs stab lineno (c:cs)
9 = if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') then
10 case getRestWord cs of
11 (word, rest) -> if (cc :: Int) == 0
15 (enter lineno stab (c:word)) lineno rest
16 else error "Force failed?!"
18 (enter lineno stab (c:word)) lineno rest
19 else xreff cc exs stab lineno cs
21 xref exceptions source = xreff 1000 exceptions ALeaf 1 source
23 getRestWord [] = ([], [])
24 getRestWord xs@(x:xs')
25 | (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || (x >= '0' && x <= '9')
26 = case getRestWord xs' of
27 (ys,zs) -> if (x >= 'A' && x <= 'Z')
28 then (toEnum (fromEnum x + (32::Int)):ys, zs)
33 data Table = ALeaf | ABranch Table String [Int] Table deriving (Eq)
35 enter n ALeaf w = ABranch ALeaf w [n] ALeaf
36 enter n (ABranch l k ns r) w
37 = if w < k then ABranch (enter n l w) k ns r else
38 if w > k then ABranch l k ns (enter n r w) else
41 delete ALeaf w = ALeaf
42 delete (ABranch l k ns r) w
43 = if w < k then ABranch (delete l w) k ns r else
44 if w > k then ABranch l k ns (delete r w) else
47 display :: Table -> String
48 display t = display_a t ""
50 display_a :: Table -> String -> String
51 display_a ALeaf acc = acc
52 display_a (ABranch l k ns r) acc
53 = display_a l (dispLine k ns ++ display_a r acc)
56 dispLine k ns = k ++ ":" ++ dispNos ns ++ "\n"
58 dispNos :: [Int] -> String
60 dispNos (n:ns) = ' ':(show n ++ dispNos ns)
64 exceptions <- catch (readFile "exceptions") (\ e -> return "")
65 putStr (xref (lines exceptions) input)
68 main = readChan stdin abort (\input ->
70 (\errors -> output (xref [] input))
71 (\exceptions -> output (xref (lines exceptions) input)))
72 where output s = appendChan stdout s abort done