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

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

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

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

    -- |
    -- defines 'a_version' option

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

    -- |
    -- debug output options

    showOptions     :: [OptDescr SysConfig]
    showOptions :: [OptDescr SysConfig]
    showOptions
        = [ String
    -> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
    forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
    Option String
    ""       [String
    a_show_tree]           (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withShowTree      Bool
    True))          String
    "output tree representation instead of document source"
          , String
    -> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
    forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
    Option String
    ""       [String
    a_show_haskell]        (SysConfig -> ArgDescr SysConfig
    forall a. a -> ArgDescr a
    NoArg  (Bool -> SysConfig
    withShowHaskell   Bool
    True))          String
    "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 :: String
    a_accept_mimetypes              = String
    "accept-mimetypes"
    a_add_default_dtd :: String
    a_add_default_dtd               = String
    "add-default-dtd"
    a_canonicalize :: String
    a_canonicalize                  = String
    "canonicalize"
    a_check_namespaces :: String
    a_check_namespaces              = String
    "check-namespaces"
    a_collect_errors :: String
    a_collect_errors                = String
    "collect-errors"
    a_default_baseuri :: String
    a_default_baseuri               = String
    "default-base-URI"
    a_do_not_canonicalize :: String
    a_do_not_canonicalize           = String
    "do-not-canonicalize"
    a_do_not_check_namespaces :: String
    a_do_not_check_namespaces       = String
    "do-not-check-namespaces"
    a_do_not_issue_errors :: String
    a_do_not_issue_errors           = String
    "do-not-issue-errors"
    a_do_not_issue_warnings :: String
    a_do_not_issue_warnings         = String
    "do-not-issue-warnings"
    a_do_not_preserve_comment :: String
    a_do_not_preserve_comment       = String
    "do-not-preserve-comment"
    a_do_not_remove_whitespace :: String
    a_do_not_remove_whitespace      = String
    "do-not-remove-whitespace"
    a_do_not_subst_dtd_entities :: String
    a_do_not_subst_dtd_entities     = String
    "do-not-subst-dtd-entities"
    a_do_not_subst_html_entities :: String
    a_do_not_subst_html_entities    = String
    "do-not-subst-html-entities"
    a_do_not_validate :: String
    a_do_not_validate               = String
    "do-not-validate"
    a_error :: String
    a_error                         = String
    "error"
    a_error_log :: String
    a_error_log                     = String
    "errorLog"
    a_help :: String
    a_help                          = String
    "help"
    a_if_modified_since :: String
    a_if_modified_since             = String
    "if-modified-since"
    a_if_unmodified_since :: String
    a_if_unmodified_since           = String
    "if-unmodified-since"
    a_ignore_encoding_errors :: String
    a_ignore_encoding_errors        = String
    "ignore-encoding-errors"
    a_ignore_none_xml_contents :: String
    a_ignore_none_xml_contents      = String
    "ignore-none-xml-contents"
    a_indent :: String
    a_indent                        = String
    "indent"
    a_issue_warnings :: String
    a_issue_warnings                = String
    "issue-warnings"
    a_issue_errors :: String
    a_issue_errors                  = String
    "issue-errors"
    a_mime_types :: String
    a_mime_types                    = String
    "mimetypes"
    a_no_empty_elements :: String
    a_no_empty_elements             = String
    "no-empty-elements"
    a_no_empty_elem_for :: String
    a_no_empty_elem_for             = String
    "no-empty-elem-for"
    a_no_redirect :: String
    a_no_redirect                   = String
    "no-redirect"
    a_no_xml_pi :: String
    a_no_xml_pi                     = String
    "no-xml-pi"
    a_output_file :: String
    a_output_file                   = String
    "output-file"
    a_output_html :: String
    a_output_html                   = String
    "output-html"
    a_output_xhtml :: String
    a_output_xhtml                  = String
    "output-xhtml"
    a_output_xml :: String
    a_output_xml                    = String
    "output-xml"
    a_output_plain :: String
    a_output_plain                  = String
    "output-plain"
    a_parse_by_mimetype :: String
    a_parse_by_mimetype             = String
    "parse-by-mimetype"
    a_parse_html :: String
    a_parse_html                    = String
    "parse-html"
    a_parse_xml :: String
    a_parse_xml                     = String
    "parse-xml"
    a_preserve_comment :: String
    a_preserve_comment              = String
    "preserve-comment"
    a_proxy :: String
    a_proxy                         = String
    "proxy"
    a_redirect :: String
    a_redirect                      = String
    "redirect"
    a_remove_whitespace :: String
    a_remove_whitespace             = String
    "remove-whitespace"
    a_show_haskell :: String
    a_show_haskell                  = String
    "show-haskell"
    a_show_tree :: String
    a_show_tree                     = String
    "show-tree"
    a_strict_input :: String
    a_strict_input                  = String
    "strict-input"
    a_subst_dtd_entities :: String
    a_subst_dtd_entities            = String
    "subst-dtd-entities"
    a_subst_html_entities :: String
    a_subst_html_entities           = String
    "subst-html-entities"
    a_text_mode :: String
    a_text_mode                     = String
    "text-mode"
    a_trace :: String
    a_trace                         = String
    "trace"
    a_validate :: String
    a_validate                      = String
    "validate"
    a_verbose :: String
    a_verbose                       = String
    "verbose"

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

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

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

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

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