File: Control.hs

package info (click to toggle)
haskell-debian 3.64-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 364 kB
  • sloc: haskell: 3,226; ansic: 8; makefile: 3
file content (55 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- |A module for working with Debian control files <http://www.debian.org/doc/debian-policy/ch-controlfields.html>
module Debian.Control 
    ( -- * Types
      Control'(..)
    , Paragraph'(..)
    , Field'(..)
    , Control
    , Paragraph
    , Field
    , ControlParser
    , ControlFunctions(..)
    -- * Control File Parser
    , pControl
    -- * Helper Functions
    , mergeControls
    , fieldValue
    , removeField
    , prependFields
    , appendFields
    , renameField
    , modifyField
    , raiseFields
    , packParagraph
    , packField
    , formatControl
    , formatParagraph
    , formatField
    ) where

--import Control.Monad
--import Data.List
--import Text.ParserCombinators.Parsec
--import System.IO
import Debian.Control.String
import Data.List
import qualified Debian.Control.ByteString as B
import qualified Debian.Control.String as S
import qualified Data.ByteString.Char8 as B

packParagraph :: S.Paragraph -> B.Paragraph
packParagraph (S.Paragraph s) = B.Paragraph (map packField s)

packField :: Field' String -> Field' B.ByteString
packField (S.Field (name, value)) = B.Field (B.pack name, B.pack value)
packField (S.Comment s) = B.Comment (B.pack s)

formatControl :: Control' B.ByteString -> [B.ByteString]
formatControl (B.Control paragraphs) = intersperse (B.pack "\n") . map formatParagraph $ paragraphs

formatParagraph :: Paragraph' B.ByteString -> B.ByteString
formatParagraph (B.Paragraph fields) = B.concat . map formatField $ fields

formatField :: Field' B.ByteString -> B.ByteString
formatField (B.Field (name, value)) = B.concat [name, B.pack ":", value, B.pack "\n"]
formatField (B.Comment s) = s