3 -- Copyright : (c) 2008 Bertram Felgenhauer
6 -- Maintainer : Bertram Felgenhauer <int-e@gmx.de>
7 -- Stability : experimental
8 -- Portability : portable
10 -- This module is part of Haskell PGMS.
12 -- Miscellaneous utility functions
22 import System
.Directory
27 -- this uses Paths_mine.getDataFileName, but also looks
28 -- in a few other places for convenient in-place running.
29 findFile
:: FilePath -> IO FilePath
31 let scan
:: [IO FilePath] -> IO FilePath
32 scan
[] = error $ "Couldn't find file '" ++ name
++ "'"
36 if b
then return f
else scan cs
37 scan
[getDataFileName name
,
38 return $ "data/" ++ name
,
39 return $ "../data/" ++ name
,
42 -- format a text string to fit nicely into 78 columns of text.
43 formatString
:: String -> String
44 formatString
= unlines . concatMap (block
. (++" ")) . intersperse "" . lines
48 (chunk
, rest
) = splitAt 78 text
49 (end
', start
') = span
(not . isSpace) (reverse chunk
)
51 if null start
' then chunk
: block
(dropWhile isSpace rest
)
52 else reverse (dropWhile isSpace start
')
53 : block
(reverse end
' ++ rest
)