{-# LANGUAGE RecordWildCards #-}
module Codec.RPM.Types(RPM(..),
Lead(..),
Header(..),
SectionHeader(..))
where
import qualified Data.ByteString as BS
import Data.Word(Word8, Word16, Word32)
import Text.PrettyPrint.HughesPJClass(Pretty(..))
import Text.PrettyPrint(($$), hcat, nest, text, vcat)
import Codec.RPM.Tags
data RPM = RPM {
RPM -> Lead
rpmLead :: Lead,
RPM -> [Header]
rpmSignatures :: [Header],
:: [Header],
RPM -> ByteString
rpmArchive :: BS.ByteString }
deriving(RPM -> RPM -> Bool
(RPM -> RPM -> Bool) -> (RPM -> RPM -> Bool) -> Eq RPM
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RPM -> RPM -> Bool
$c/= :: RPM -> RPM -> Bool
== :: RPM -> RPM -> Bool
$c== :: RPM -> RPM -> Bool
Eq, Int -> RPM -> ShowS
[RPM] -> ShowS
RPM -> String
(Int -> RPM -> ShowS)
-> (RPM -> String) -> ([RPM] -> ShowS) -> Show RPM
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RPM] -> ShowS
$cshowList :: [RPM] -> ShowS
show :: RPM -> String
$cshow :: RPM -> String
showsPrec :: Int -> RPM -> ShowS
$cshowsPrec :: Int -> RPM -> ShowS
Show)
instance Pretty RPM where
pPrint :: RPM -> Doc
pPrint RPM{..} =
[Doc] -> Doc
vcat [ String -> Doc
text "RPM:",
Int -> Doc -> Doc
nest 2 (String -> Doc
text "rpmLead = " Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
nest 2 (Lead -> Doc
forall a. Pretty a => a -> Doc
pPrint Lead
rpmLead)),
Int -> Doc -> Doc
nest 2 (String -> Doc
text "rpmSignatures = " Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
nest 2 ([Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Header -> Doc) -> [Header] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Header -> Doc
forall a. Pretty a => a -> Doc
pPrint [Header]
rpmSignatures)),
Int -> Doc -> Doc
nest 2 (String -> Doc
text "rpmHeaders = " Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
nest 2 ([Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Header -> Doc) -> [Header] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Header -> Doc
forall a. Pretty a => a -> Doc
pPrint [Header]
rpmHeaders)),
Int -> Doc -> Doc
nest 2 (String -> Doc
text "rpmArchive = ...") ]
data Lead = Lead {
Lead -> Word8
rpmMajor :: Word8,
Lead -> Word8
rpmMinor :: Word8,
Lead -> Word16
rpmType :: Word16,
Lead -> Word16
rpmArchNum :: Word16,
Lead -> String
rpmName :: String,
Lead -> Word16
rpmOSNum :: Word16,
Lead -> Word16
rpmSigType :: Word16 }
deriving(Lead -> Lead -> Bool
(Lead -> Lead -> Bool) -> (Lead -> Lead -> Bool) -> Eq Lead
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Lead -> Lead -> Bool
$c/= :: Lead -> Lead -> Bool
== :: Lead -> Lead -> Bool
$c== :: Lead -> Lead -> Bool
Eq, Int -> Lead -> ShowS
[Lead] -> ShowS
Lead -> String
(Int -> Lead -> ShowS)
-> (Lead -> String) -> ([Lead] -> ShowS) -> Show Lead
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Lead] -> ShowS
$cshowList :: [Lead] -> ShowS
show :: Lead -> String
$cshow :: Lead -> String
showsPrec :: Int -> Lead -> ShowS
$cshowsPrec :: Int -> Lead -> ShowS
Show)
instance Pretty Lead where
pPrint :: Lead -> Doc
pPrint Lead{..} =
[Doc] -> Doc
vcat [ String -> Doc
text "Lead:",
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "rpmMajor: ", String -> Doc
text (Word8 -> String
forall a. Show a => a -> String
show Word8
rpmMajor) ],
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "rpmMinor: ", String -> Doc
text (Word8 -> String
forall a. Show a => a -> String
show Word8
rpmMinor) ],
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "rpmType: ", String -> Doc
text (Word16 -> String
forall a. Show a => a -> String
show Word16
rpmType) ],
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "rpmArchNum: ", String -> Doc
text (Word16 -> String
forall a. Show a => a -> String
show Word16
rpmArchNum) ],
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "rpmName: ", String -> Doc
text String
rpmName ],
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "rpmOSNum: ", String -> Doc
text (Word16 -> String
forall a. Show a => a -> String
show Word16
rpmOSNum) ],
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "rpmSigType: ", String -> Doc
text (Word16 -> String
forall a. Show a => a -> String
show Word16
rpmSigType) ] ]
data = {
:: SectionHeader,
:: [Tag],
:: BS.ByteString }
deriving(Header -> Header -> Bool
(Header -> Header -> Bool)
-> (Header -> Header -> Bool) -> Eq Header
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Header -> Header -> Bool
$c/= :: Header -> Header -> Bool
== :: Header -> Header -> Bool
$c== :: Header -> Header -> Bool
Eq, Int -> Header -> ShowS
[Header] -> ShowS
Header -> String
(Int -> Header -> ShowS)
-> (Header -> String) -> ([Header] -> ShowS) -> Show Header
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Header] -> ShowS
$cshowList :: [Header] -> ShowS
show :: Header -> String
$cshow :: Header -> String
showsPrec :: Int -> Header -> ShowS
$cshowsPrec :: Int -> Header -> ShowS
Show)
instance Pretty Header where
pPrint :: Header -> Doc
pPrint Header{..} =
[Doc] -> Doc
vcat [ String -> Doc
text "Header:",
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
text "headerSectionHeader = " Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
nest 2 (SectionHeader -> Doc
forall a. Pretty a => a -> Doc
pPrint SectionHeader
headerSectionHeader),
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
text "headerTags = " Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
nest 2 ([Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Tag -> Doc) -> [Tag] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Tag -> Doc
forall a. Pretty a => a -> Doc
pPrint [Tag]
headerTags),
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
text "headerStore = ..." ]
data = {
SectionHeader -> Word8
sectionVersion :: Word8,
SectionHeader -> Word32
sectionCount :: Word32,
SectionHeader -> Word32
sectionSize :: Word32 }
deriving(SectionHeader -> SectionHeader -> Bool
(SectionHeader -> SectionHeader -> Bool)
-> (SectionHeader -> SectionHeader -> Bool) -> Eq SectionHeader
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SectionHeader -> SectionHeader -> Bool
$c/= :: SectionHeader -> SectionHeader -> Bool
== :: SectionHeader -> SectionHeader -> Bool
$c== :: SectionHeader -> SectionHeader -> Bool
Eq, Int -> SectionHeader -> ShowS
[SectionHeader] -> ShowS
SectionHeader -> String
(Int -> SectionHeader -> ShowS)
-> (SectionHeader -> String)
-> ([SectionHeader] -> ShowS)
-> Show SectionHeader
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SectionHeader] -> ShowS
$cshowList :: [SectionHeader] -> ShowS
show :: SectionHeader -> String
$cshow :: SectionHeader -> String
showsPrec :: Int -> SectionHeader -> ShowS
$cshowsPrec :: Int -> SectionHeader -> ShowS
Show)
instance Pretty SectionHeader where
pPrint :: SectionHeader -> Doc
pPrint SectionHeader{..} =
[Doc] -> Doc
vcat [ String -> Doc
text "SectionHeader:",
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "sectionHeader: ", String -> Doc
text (Word8 -> String
forall a. Show a => a -> String
show Word8
sectionVersion) ],
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "sectionCount: ", String -> Doc
text (Word32 -> String
forall a. Show a => a -> String
show Word32
sectionCount) ],
Int -> Doc -> Doc
nest 2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
hcat [ String -> Doc
text "sectionSize: ", String -> Doc
text (Word32 -> String
forall a. Show a => a -> String
show Word32
sectionSize) ] ]