xref: /freebsd/contrib/expat/xmlwf/xmlwf_helpgen.py (revision 627b778d9e6b603a44a010d22d823ca7c392b363)
1#! /usr/bin/env python3
2#                          __  __            _
3#                       ___\ \/ /_ __   __ _| |_
4#                      / _ \\  /| '_ \ / _` | __|
5#                     |  __//  \| |_) | (_| | |_
6#                      \___/_/\_\ .__/ \__,_|\__|
7#                               |_| XML parser
8#
9# Copyright (c) 2019-2025 Sebastian Pipping <sebastian@pipping.org>
10# Copyright (c) 2021      Tim Bray <tbray@textuality.com>
11# Licensed under the MIT license:
12#
13# Permission is  hereby granted,  free of charge,  to any  person obtaining
14# a  copy  of  this  software   and  associated  documentation  files  (the
15# "Software"),  to  deal in  the  Software  without restriction,  including
16# without  limitation the  rights  to use,  copy,  modify, merge,  publish,
17# distribute, sublicense, and/or sell copies of the Software, and to permit
18# persons  to whom  the Software  is  furnished to  do so,  subject to  the
19# following conditions:
20#
21# The above copyright  notice and this permission notice  shall be included
22# in all copies or substantial portions of the Software.
23#
24# THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
25# EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
26# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27# NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28# DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
29# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
30# USE OR OTHER DEALINGS IN THE SOFTWARE.
31
32import argparse
33
34epilog = """
35environment variables:
36  EXPAT_ACCOUNTING_DEBUG=(0|1|2|3)
37                 Control verbosity of accounting debugging (default: 0)
38  EXPAT_ENTITY_DEBUG=(0|1)
39                 Control verbosity of entity debugging (default: 0)
40  EXPAT_ENTROPY_DEBUG=(0|1)
41                 Control verbosity of entropy debugging (default: 0)
42  EXPAT_MALLOC_DEBUG=(0|1|2)
43                 Control verbosity of allocation tracker (default: 0)
44
45exit status:
46  0              the input files are well-formed and the output (if requested) was written successfully
47  1              could not allocate data structures, signals a serious problem with execution environment
48  2              one or more input files were not well-formed
49  3              could not create an output file
50  4              command-line argument error
51
52xmlwf of libexpat is software libre, licensed under the MIT license.
53Please report bugs at https://github.com/libexpat/libexpat/issues -- thank you!
54"""
55
56usage = """
57  %(prog)s [OPTIONS] [FILE ...]
58  %(prog)s -h|--help
59  %(prog)s -v|--version
60"""
61
62parser = argparse.ArgumentParser(prog='xmlwf', add_help=False,
63                                 usage=usage,
64                                 description='xmlwf - Determines if an XML document is well-formed',
65                                 formatter_class=argparse.RawTextHelpFormatter,
66                                 epilog=epilog)
67
68input_related = parser.add_argument_group('input control arguments')
69input_related.add_argument('-s', action='store_true', help='print an error if the document is not [s]tandalone')
70input_related.add_argument('-n', action='store_true', help='enable [n]amespace processing')
71input_related.add_argument('-p', action='store_true', help='enable processing of external DTDs and [p]arameter entities')
72input_related.add_argument('-x', action='store_true', help='enable processing of e[x]ternal entities')
73input_related.add_argument('-e', action='store', metavar='ENCODING', help='override any in-document [e]ncoding declaration')
74input_related.add_argument('-w', action='store_true', help='enable support for [W]indows code pages')
75input_related.add_argument('-r', action='store_true', help='disable memory-mapping and use [r]ead calls instead')
76input_related.add_argument('-g', metavar='BYTES', help='buffer size to request per call pair to XML_[G]etBuffer and read (default: 8 KiB)')
77input_related.add_argument('-k', action='store_true', help='when processing multiple files, [k]eep processing after first file with error')
78
79output_related = parser.add_argument_group('output control arguments')
80output_related.add_argument('-d', action='store', metavar='DIRECTORY', help='output [d]estination directory')
81output_mode = output_related.add_mutually_exclusive_group()
82output_mode.add_argument('-c', action='store_true', help='write a [c]opy of input XML, not canonical XML')
83output_mode.add_argument('-m', action='store_true', help='write [m]eta XML, not canonical XML')
84output_mode.add_argument('-t', action='store_true', help='write no XML output for [t]iming of plain parsing')
85output_related.add_argument('-N', action='store_true', help='enable adding doctype and [n]otation declarations')
86
87billion_laughs = parser.add_argument_group('amplification attack protection (e.g. billion laughs)',
88                                           description='NOTE: '
89                                                       'If you ever need to increase these values '
90                                                       'for non-attack payload, please file a bug report.')
91billion_laughs.add_argument('-a', metavar='FACTOR',
92                            help='set maximum tolerated [a]mplification factor (default: 100.0)')
93billion_laughs.add_argument('-b', metavar='BYTES', help='set number of output [b]ytes needed to activate (default: 8 MiB/64 MiB)')
94
95reparse_deferral = parser.add_argument_group('reparse deferral')
96reparse_deferral.add_argument('-q', action='store_true',
97                            help='disable reparse deferral, and allow [q]uadratic parse runtime with large tokens')
98
99parser.add_argument('files', metavar='FILE', nargs='*', help='file to process (default: STDIN)')
100
101info = parser.add_argument_group('info arguments')
102info = info.add_mutually_exclusive_group()
103info.add_argument('-h', '--help', action='store_true', help='show this [h]elp message and exit')
104info.add_argument('-v', '--version', action='store_true', help='show program\'s [v]ersion number and exit')
105
106
107if __name__ == '__main__':
108    parser.print_help()
109