    -- ------------------------------------------------------------

    {- |
       Module     : Text.XML.HXT.Arrow.XmlOptions
       Copyright  : Copyright (C) 2010 Uwe Schmidt
       License    : MIT

       Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
       Stability  : stable
       Portability: portable

       system configuration and common options options

    -}

    -- ------------------------------------------------------------

    module Text.XML.HXT.Arrow.XmlOptions
    where

    import Text.XML.HXT.DOM.Interface

    import Text.XML.HXT.Arrow.XmlState.TypeDefs
    import Text.XML.HXT.Arrow.XmlState.SystemConfig

    import Data.Maybe

    import System.Console.GetOpt

    -- ------------------------------------------------------------
    --

    -- |
    -- commonly useful options for XML input
    --
    -- can be used for option definition with haskell getopt
    --
    -- defines options: 'a_trace', 'a_proxy', 'a_use_curl', 'a_do_not_use_curl', 'a_options_curl', 'a_encoding',
    -- 'a_issue_errors', 'a_do_not_issue_errors', 'a_parse_html', 'a_parse_by_mimetype', 'a_issue_warnings', 'a_do_not_issue_warnings',
    -- 'a_parse_xml', 'a_validate', 'a_do_not_validate', 'a_canonicalize', 'a_do_not_canonicalize',
    --- 'a_preserve_comment', 'a_do_not_preserve_comment', 'a_check_namespaces', 'a_do_not_check_namespaces',
    -- 'a_remove_whitespace', 'a_do_not_remove_whitespace'

    inputOptions    :: [OptDescr SysConfig]
    inputOptions :: [OptDescr SysConfig]
    inputOptions
        = [ [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "t"      [[Char]
    a_trace]                       ((Maybe [Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. (Maybe [Char] -> a) -> [Char] -> ArgDescr a
    OptArg Maybe [Char] -> SysConfig
    trc "LEVEL")                    "trace level (0-4), default 1"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "p"      [[Char]
    a_proxy]                       (([Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. ([Char] -> a) -> [Char] -> ArgDescr a
    ReqArg  [Char] -> SysConfig
    withProxy            "PROXY")  "proxy for http access (e.g. \"www-cache:3128\")"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_redirect]                    (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withRedirect           Bool
    True))  "automatically follow redirected URIs"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_no_redirect]                 (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withRedirect          Bool
    False))  "switch off following redirected URIs"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_default_baseuri]             (([Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. ([Char] -> a) -> [Char] -> ArgDescr a
    ReqArg  [Char] -> SysConfig
    withDefaultBaseURI     "URI")  "default base URI, default: \"file:///<cwd>/\""
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "e"      [[Char]
    a_encoding]                    (([Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. ([Char] -> a) -> [Char] -> ArgDescr a
    ReqArg  [Char] -> SysConfig
    withInputEncoding  "CHARSET")  ( "default document encoding (" [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    utf8 [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ", " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    isoLatin1 [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ", " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    usAscii [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ", ...)" )
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_mime_types]                  (([Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. ([Char] -> a) -> [Char] -> ArgDescr a
    ReqArg  [Char] -> SysConfig
    withMimeTypeFile      "FILE")  "set mime type configuration file, e.g. \"/etc/mime.types\""
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_issue_errors]                (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withErrors             Bool
    True))  "issue all error messages on stderr (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_do_not_issue_errors]         (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withErrors            Bool
    False))  "ignore all error messages"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_ignore_encoding_errors]      (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withEncodingErrors    Bool
    False))   "ignore encoding errors"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_ignore_none_xml_contents]    (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withIgnoreNoneXmlContents Bool
    True)) "discards all contents of none XML/HTML documents, only the meta info remains in the doc tree"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_accept_mimetypes]            (([Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. ([Char] -> a) -> [Char] -> ArgDescr a
    ReqArg  [Char] -> SysConfig
    withMT           "MIMETYPES")  "only accept documents matching the given comma separated list of mimetype specs"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "H"      [[Char]
    a_parse_html]                  (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withParseHTML          Bool
    True))  "parse input as HTML, try to interprete everything as HTML, no validation"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "M"      [[Char]
    a_parse_by_mimetype]           (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withParseByMimeType    Bool
    True))  "parse dependent on mime type: text/html as HTML, text/xml and text/xhtml and others as XML, else no parse"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_parse_xml]                   (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withParseHTML         Bool
    False))  "parse input as XML, (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_strict_input]                (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withStrictInput        Bool
    True))  "read input files strictly, this ensures closing the files correctly even if not read completely"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_issue_warnings]              (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withWarnings           Bool
    True))  "issue warnings, when parsing HTML (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "Q"      [[Char]
    a_do_not_issue_warnings]       (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withWarnings          Bool
    False))  "ignore warnings, when parsing HTML"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_validate]                    (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withValidate           Bool
    True))  "document validation when parsing XML (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "w"      [[Char]
    a_do_not_validate]             (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withValidate          Bool
    False))  "only wellformed check, no validation"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_subst_dtd_entities]          (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withSubstDTDEntities   Bool
    True))  "entities defined in DTD are substituted when parsing XML (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_do_not_subst_dtd_entities]   (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withSubstDTDEntities  Bool
    False))  "entities defined in DTD are NOT substituted when parsing XML"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_subst_html_entities]         (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withSubstHTMLEntities   Bool
    True)) "entities defined in XHTML are substituted when parsing XML, only in effect when prev. option is switched off"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_do_not_subst_html_entities]  (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withSubstHTMLEntities  Bool
    False)) "only entities predefined in XML are substituted when parsing XML (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_canonicalize]                (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withCanonicalize       Bool
    True))  "canonicalize document, remove DTD, comment, transform CDATA, CharRef's, ... (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "c"      [[Char]
    a_do_not_canonicalize]         (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withCanonicalize      Bool
    False))  "do not canonicalize document, don't remove DTD, comment, don't transform CDATA, CharRef's, ..."
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "C"      [[Char]
    a_preserve_comment]            (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withPreserveComment    Bool
    True))  "don't remove comments during canonicalisation"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_do_not_preserve_comment]     (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withPreserveComment   Bool
    False))  "remove comments during canonicalisation (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "n"      [[Char]
    a_check_namespaces]            (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withCheckNamespaces    Bool
    True))  "tag tree with namespace information and check namespaces"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_do_not_check_namespaces]     (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withCheckNamespaces   Bool
    False))  "ignore namespaces (default)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "r"      [[Char]
    a_remove_whitespace]           (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withRemoveWS           Bool
    True))  "remove redundant whitespace, simplifies tree and processing"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_do_not_remove_whitespace]    (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withRemoveWS          Bool
    False))  "don't remove redundant whitespace (default)"
          ]
        where
        withMT :: [Char] -> SysConfig
    withMT = [[Char]] -> SysConfig
    withAcceptedMimeTypes ([[Char]] -> SysConfig)
    -> ([Char] -> [[Char]]) -> [Char] -> SysConfig
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> [[Char]]
    words ([Char] -> [[Char]]) -> ([Char] -> [Char]) -> [Char] -> [[Char]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Char) -> [Char] -> [Char]
    forall a b. (a -> b) -> [a] -> [b]
    map (\ x :: Char
    x -> if Char
    x Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == ',' then ' ' else Char
    x)
        trc :: Maybe [Char] -> SysConfig
    trc = Int -> SysConfig
    withTrace (Int -> SysConfig)
    -> (Maybe [Char] -> Int) -> Maybe [Char] -> SysConfig
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> Int -> Int
    forall a. Ord a => a -> a -> a
    max 0 (Int -> Int) -> (Maybe [Char] -> Int) -> Maybe [Char] -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> Int -> Int
    forall a. Ord a => a -> a -> a
    min 9 (Int -> Int) -> (Maybe [Char] -> Int) -> Maybe [Char] -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([Char] -> Int
    forall a. Read a => [Char] -> a
    read :: String -> Int) ([Char] -> Int) -> (Maybe [Char] -> [Char]) -> Maybe [Char] -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ('0'Char -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    :) ([Char] -> [Char])
    -> (Maybe [Char] -> [Char]) -> Maybe [Char] -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> [Char] -> [Char]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Char -> [Char] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` "0123456789") ([Char] -> [Char])
    -> (Maybe [Char] -> [Char]) -> Maybe [Char] -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> Maybe [Char] -> [Char]
    forall a. a -> Maybe a -> a
    fromMaybe [Char]
    v_1

    -- |
    -- commonly useful options for XML output
    --
    -- defines options: 'a_indent', 'a_output_encoding', 'a_output_html' and others

    outputOptions   :: [OptDescr SysConfig]
    outputOptions :: [OptDescr SysConfig]
    outputOptions
        = [ [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "f"      [[Char]
    a_output_file]         (([Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. ([Char] -> a) -> [Char] -> ArgDescr a
    ReqArg ([Char] -> [Char] -> SysConfig
    withSysAttr [Char]
    a_output_file) "FILE")   "output file for resulting document (default: stdout)"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "i"      [[Char]
    a_indent]              (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withIndent               Bool
    True))      "indent XML output for readability"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "o"      [[Char]
    a_output_encoding]     (([Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. ([Char] -> a) -> [Char] -> ArgDescr a
    ReqArg  [Char] -> SysConfig
    withOutputEncoding    "CHARSET")      ( "encoding of output (" [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    utf8 [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ", " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    isoLatin1 [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ", " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    usAscii [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ")" )
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_output_xml]          (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg   SysConfig
    withOutputXML                  )      "output of none ASCII chars as HTMl entity references"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_output_html]         (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg   SysConfig
    withOutputHTML                 )      "output of none ASCII chars as HTMl entity references"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_output_xhtml]        (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg   SysConfig
    withOutputXHTML                )      "output of HTML elements with empty content (script, ...) done in format <elem...></elem> instead of <elem/>"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_output_plain]        (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg   SysConfig
    withOutputPLAIN                )      "output of HTML elements with empty content (script, ...) done in format <elem...></elem> instead of <elem/>"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_no_xml_pi]           (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withXmlPi                Bool
    False))      ("output without <?xml ...?> processing instruction, useful in combination with --" [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char] -> [Char]
    forall a. Show a => a -> [Char]
    show [Char]
    a_output_html)
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_no_empty_elem_for]   (([Char] -> SysConfig) -> [Char] -> ArgDescr SysConfig
    forall a. ([Char] -> a) -> [Char] -> ArgDescr a
    ReqArg ([[Char]] -> SysConfig
    withNoEmptyElemFor ([[Char]] -> SysConfig)
    -> ([Char] -> [[Char]]) -> [Char] -> SysConfig
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> [[Char]]
    words') "NAMES")   "output of empty elements done in format <elem...></elem> only for given list of element names"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_add_default_dtd]     (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withAddDefaultDTD         Bool
    True))      "add the document type declaration given in the input document"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_text_mode]           (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withTextMode              Bool
    True))      "output in text mode"
          ]
        where
        words' :: [Char] -> [[Char]]
    words'
            = [Char] -> [[Char]]
    words
              ([Char] -> [[Char]]) -> ([Char] -> [Char]) -> [Char] -> [[Char]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Char) -> [Char] -> [Char]
    forall a b. (a -> b) -> [a] -> [b]
    map (\ c :: Char
    c -> if Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == ',' then ' ' else Char
    c)

    -- |
    -- commonly useful options
    --
    -- defines options: 'a_verbose', 'a_help'

    generalOptions  :: [OptDescr SysConfig]
    generalOptions :: [OptDescr SysConfig]
    generalOptions
        = [ [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "v"      [[Char]
    a_verbose]             (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  ([Char] -> [Char] -> SysConfig
    withSysAttr [Char]
    a_verbose [Char]
    v_1))               "verbose output"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "h?"     [[Char]
    a_help]                (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  ([Char] -> [Char] -> SysConfig
    withSysAttr [Char]
    a_help    [Char]
    v_1))               "this message"
          ]

    -- |
    -- defines 'a_version' option

    versionOptions  :: [OptDescr SysConfig]
    versionOptions :: [OptDescr SysConfig]
    versionOptions
        = [ [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option "V"      [[Char]
    a_version]             (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  ([Char] -> [Char] -> SysConfig
    withSysAttr [Char]
    a_version [Char]
    v_1))               "show program version"
          ]

    -- |
    -- debug output options

    showOptions     :: [OptDescr SysConfig]
    showOptions :: [OptDescr SysConfig]
    showOptions
        = [ [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_show_tree]           (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withShowTree      Bool
    True))          "output tree representation instead of document source"
          , [Char]
    -> [[Char]] -> ArgDescr SysConfig -> [Char] -> OptDescr SysConfig
    forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
    Option ""       [[Char]
    a_show_haskell]        (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withShowHaskell   Bool
    True))          "output internal Haskell representation instead of document source"
          ]

    -- ------------------------------------------------------------

    a_accept_mimetypes,
     a_add_default_dtd,
     a_canonicalize,
     a_check_namespaces,
     a_collect_errors,
     a_default_baseuri,
     a_do_not_canonicalize,
     a_do_not_check_namespaces,
     a_do_not_issue_errors,
     a_do_not_issue_warnings,
     a_do_not_preserve_comment,
     a_do_not_remove_whitespace,
     a_do_not_subst_dtd_entities,
     a_do_not_subst_html_entities,
     a_do_not_validate,
     a_error,
     a_error_log,
     a_help,
     a_if_modified_since,
     a_if_unmodified_since,
     a_ignore_encoding_errors,
     a_ignore_none_xml_contents,
     a_indent,
     a_issue_errors,
     a_issue_warnings,
     a_mime_types,
     a_no_empty_elements,
     a_no_empty_elem_for,
     a_no_redirect,
     a_no_xml_pi,
     a_output_file,
     a_output_xml,
     a_output_html,
     a_output_xhtml,
     a_output_plain,
     a_parse_by_mimetype,
     a_parse_html,
     a_parse_xml,
     a_preserve_comment,
     a_proxy,
     a_redirect,
     a_remove_whitespace,
     a_show_haskell,
     a_show_tree,
     a_strict_input,
     a_subst_dtd_entities,
     a_subst_html_entities,
     a_text_mode,
     a_trace,
     a_validate,
     a_verbose      :: String

    a_accept_mimetypes :: [Char]
    a_accept_mimetypes              = "accept-mimetypes"
    a_add_default_dtd :: [Char]
    a_add_default_dtd               = "add-default-dtd"
    a_canonicalize :: [Char]
    a_canonicalize                  = "canonicalize"
    a_check_namespaces :: [Char]
    a_check_namespaces              = "check-namespaces"
    a_collect_errors :: [Char]
    a_collect_errors                = "collect-errors"
    a_default_baseuri :: [Char]
    a_default_baseuri               = "default-base-URI"
    a_do_not_canonicalize :: [Char]
    a_do_not_canonicalize           = "do-not-canonicalize"
    a_do_not_check_namespaces :: [Char]
    a_do_not_check_namespaces       = "do-not-check-namespaces"
    a_do_not_issue_errors :: [Char]
    a_do_not_issue_errors           = "do-not-issue-errors"
    a_do_not_issue_warnings :: [Char]
    a_do_not_issue_warnings         = "do-not-issue-warnings"
    a_do_not_preserve_comment :: [Char]
    a_do_not_preserve_comment       = "do-not-preserve-comment"
    a_do_not_remove_whitespace :: [Char]
    a_do_not_remove_whitespace      = "do-not-remove-whitespace"
    a_do_not_subst_dtd_entities :: [Char]
    a_do_not_subst_dtd_entities     = "do-not-subst-dtd-entities"
    a_do_not_subst_html_entities :: [Char]
    a_do_not_subst_html_entities    = "do-not-subst-html-entities"
    a_do_not_validate :: [Char]
    a_do_not_validate               = "do-not-validate"
    a_error :: [Char]
    a_error                         = "error"
    a_error_log :: [Char]
    a_error_log                     = "errorLog"
    a_help :: [Char]
    a_help                          = "help"
    a_if_modified_since :: [Char]
    a_if_modified_since             = "if-modified-since"
    a_if_unmodified_since :: [Char]
    a_if_unmodified_since           = "if-unmodified-since"
    a_ignore_encoding_errors :: [Char]
    a_ignore_encoding_errors        = "ignore-encoding-errors"
    a_ignore_none_xml_contents :: [Char]
    a_ignore_none_xml_contents      = "ignore-none-xml-contents"
    a_indent :: [Char]
    a_indent                        = "indent"
    a_issue_warnings :: [Char]
    a_issue_warnings                = "issue-warnings"
    a_issue_errors :: [Char]
    a_issue_errors                  = "issue-errors"
    a_mime_types :: [Char]
    a_mime_types                    = "mimetypes"
    a_no_empty_elements :: [Char]
    a_no_empty_elements             = "no-empty-elements"
    a_no_empty_elem_for :: [Char]
    a_no_empty_elem_for             = "no-empty-elem-for"
    a_no_redirect :: [Char]
    a_no_redirect                   = "no-redirect"
    a_no_xml_pi :: [Char]
    a_no_xml_pi                     = "no-xml-pi"
    a_output_file :: [Char]
    a_output_file                   = "output-file"
    a_output_html :: [Char]
    a_output_html                   = "output-html"
    a_output_xhtml :: [Char]
    a_output_xhtml                  = "output-xhtml"
    a_output_xml :: [Char]
    a_output_xml                    = "output-xml"
    a_output_plain :: [Char]
    a_output_plain                  = "output-plain"
    a_parse_by_mimetype :: [Char]
    a_parse_by_mimetype             = "parse-by-mimetype"
    a_parse_html :: [Char]
    a_parse_html                    = "parse-html"
    a_parse_xml :: [Char]
    a_parse_xml                     = "parse-xml"
    a_preserve_comment :: [Char]
    a_preserve_comment              = "preserve-comment"
    a_proxy :: [Char]
    a_proxy                         = "proxy"
    a_redirect :: [Char]
    a_redirect                      = "redirect"
    a_remove_whitespace :: [Char]
    a_remove_whitespace             = "remove-whitespace"
    a_show_haskell :: [Char]
    a_show_haskell                  = "show-haskell"
    a_show_tree :: [Char]
    a_show_tree                     = "show-tree"
    a_strict_input :: [Char]
    a_strict_input                  = "strict-input"
    a_subst_dtd_entities :: [Char]
    a_subst_dtd_entities            = "subst-dtd-entities"
    a_subst_html_entities :: [Char]
    a_subst_html_entities           = "subst-html-entities"
    a_text_mode :: [Char]
    a_text_mode                     = "text-mode"
    a_trace :: [Char]
    a_trace                         = "trace"
    a_validate :: [Char]
    a_validate                      = "validate"
    a_verbose :: [Char]
    a_verbose                       = "verbose"

    -- ------------------------------------------------------------

    -- |
    -- select options from a predefined list of option descriptions

    selectOptions   :: [String] -> [OptDescr a] -> [OptDescr a]
    selectOptions :: [[Char]] -> [OptDescr a] -> [OptDescr a]
    selectOptions ol :: [[Char]]
    ol os :: [OptDescr a]
    os
        = [[OptDescr a]] -> [OptDescr a]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat ([[OptDescr a]] -> [OptDescr a])
    -> ([[Char]] -> [[OptDescr a]]) -> [[Char]] -> [OptDescr a]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([Char] -> [OptDescr a]) -> [[Char]] -> [[OptDescr a]]
    forall a b. (a -> b) -> [a] -> [b]
    map (\ on :: [Char]
    on -> (OptDescr a -> Bool) -> [OptDescr a] -> [OptDescr a]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (\ (Option _ ons :: [[Char]]
    ons _ _) -> [Char]
    on [Char] -> [[Char]] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [[Char]]
    ons) [OptDescr a]
    os) ([[Char]] -> [OptDescr a]) -> [[Char]] -> [OptDescr a]
    forall a b. (a -> b) -> a -> b
    $ [[Char]]
    ol

    removeOptions   :: [String] -> [OptDescr a] -> [OptDescr a]
    removeOptions :: [[Char]] -> [OptDescr a] -> [OptDescr a]
    removeOptions ol :: [[Char]]
    ol os :: [OptDescr a]
    os
        = (OptDescr a -> Bool) -> [OptDescr a] -> [OptDescr a]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (\ (Option _ ons :: [[Char]]
    ons _ _) -> Bool -> Bool
    not (Bool -> Bool) -> ([[Char]] -> Bool) -> [[Char]] -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([Char] -> Bool) -> [[Char]] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any ([Char] -> [[Char]] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [[Char]]
    ol) ([[Char]] -> Bool) -> [[Char]] -> Bool
    forall a b. (a -> b) -> a -> b
    $ [[Char]]
    ons ) [OptDescr a]
    os

    -- ------------------------------------------------------------