~ubuntu-branches/ubuntu/raring/agda-stdlib/raring-proposed

« back to all changes in this revision

Viewing changes to GenerateEverything.hs

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2011-11-29 17:00:35 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20111129170035-00v3pq4mmhoo5ulf
Tags: 0.6~darcs20111129t1640-1
* [ef445ab] Imported Upstream version 0.6~darcs20111129t1640
  + Darcs snapshot required for Agda 2.3.0 compatibility
* [f801f83] Update BDs and deps to require Agda 2.3.0
* [c52be90] Use 3.0 (quilt) for bz2 orig

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
    [] -> return ()
19
19
    _  -> hPutStr stderr usage >> exitFailure
20
20
 
21
 
  header  <- readFile headerFile
 
21
  header  <- readFileUTF8 headerFile
22
22
  modules <- filter isLibraryModule . List.sort <$>
23
23
               find always
24
24
                    (extension ==? ".agda" ||? extension ==? ".lagda")
25
25
                    srcDir
26
26
  headers <- mapM extractHeader modules
27
27
 
28
 
  writeFile outputFile $
 
28
  writeFileUTF8 outputFile $
29
29
    header ++ format (zip modules headers)
30
30
 
31
31
-- | Usage info.
54
54
-- | Reads a module and extracts the header.
55
55
 
56
56
extractHeader :: FilePath -> IO [String]
57
 
extractHeader mod = fmap (extract . lines) $ readFile mod
 
57
extractHeader mod = fmap (extract . lines) $ readFileUTF8 mod
58
58
  where
59
59
  delimiter = all (== '-')
60
60
 
61
 
  extract (d1 : ss)
 
61
  extract (d1 : "-- The Agda standard library" : "--" : ss)
62
62
    | delimiter d1
63
63
    , (info, d2 : rest) <- span ("-- " `List.isPrefixOf`) ss
64
64
    , delimiter d2
84
84
  where
85
85
  slashToDot c | isPathSeparator c = '.'
86
86
               | otherwise         = c
 
87
 
 
88
-- | A variant of 'readFile' which uses the 'utf8' encoding.
 
89
 
 
90
readFileUTF8 :: FilePath -> IO String
 
91
readFileUTF8 f = do
 
92
  h <- openFile f ReadMode
 
93
  hSetEncoding h utf8
 
94
  hGetContents h
 
95
 
 
96
-- | A variant of 'writeFile' which uses the 'utf8' encoding.
 
97
 
 
98
writeFileUTF8 :: FilePath -> String -> IO ()
 
99
writeFileUTF8 f s = withFile f WriteMode $ \h -> do
 
100
  hSetEncoding h utf8
 
101
  hPutStr h s