xref: /freebsd/contrib/bc/gen/dc_help.txt (revision a970610a3af63b3f4df5b69d91c6b4093a00ed8f)
1252884aeSStefan Eßer/*
2252884aeSStefan Eßer * *****************************************************************************
3252884aeSStefan Eßer *
43aa99676SStefan Eßer * SPDX-License-Identifier: BSD-2-Clause
5252884aeSStefan Eßer *
6*a970610aSStefan Eßer * Copyright (c) 2018-2024 Gavin D. Howard and contributors.
7252884aeSStefan Eßer *
8252884aeSStefan Eßer * Redistribution and use in source and binary forms, with or without
9252884aeSStefan Eßer * modification, are permitted provided that the following conditions are met:
10252884aeSStefan Eßer *
11252884aeSStefan Eßer * * Redistributions of source code must retain the above copyright notice, this
12252884aeSStefan Eßer *   list of conditions and the following disclaimer.
13252884aeSStefan Eßer *
14252884aeSStefan Eßer * * Redistributions in binary form must reproduce the above copyright notice,
15252884aeSStefan Eßer *   this list of conditions and the following disclaimer in the documentation
16252884aeSStefan Eßer *   and/or other materials provided with the distribution.
17252884aeSStefan Eßer *
18252884aeSStefan Eßer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19252884aeSStefan Eßer * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20252884aeSStefan Eßer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21252884aeSStefan Eßer * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22252884aeSStefan Eßer * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23252884aeSStefan Eßer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24252884aeSStefan Eßer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25252884aeSStefan Eßer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26252884aeSStefan Eßer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27252884aeSStefan Eßer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28252884aeSStefan Eßer * POSSIBILITY OF SUCH DAMAGE.
29252884aeSStefan Eßer *
30252884aeSStefan Eßer * *****************************************************************************
31252884aeSStefan Eßer *
32252884aeSStefan Eßer * The dc help text.
33252884aeSStefan Eßer *
34252884aeSStefan Eßer */
35252884aeSStefan Eßer
36252884aeSStefan Eßerusage: %s [options] [file...]
37252884aeSStefan Eßer
38252884aeSStefan Eßerdc is a reverse-polish notation command-line calculator which supports unlimited
397e5c51e5SStefan Eßerprecision arithmetic. For details, use `man %s` or see the online documentation
404fca8e0fSStefan Eßerat https://git.gavinhoward.com/gavin/bc/src/tag/%s/manuals/bc/%s.1.md.
41252884aeSStefan Eßer
427e5c51e5SStefan EßerThis dc is (mostly) compatible with the OpenBSD dc and the GNU dc. See the
437e5c51e5SStefan EßerOpenBSD man page (http://man.openbsd.org/OpenBSD-current/man1/dc.1) and the GNU
447e5c51e5SStefan Eßerdc manual (https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html)
457e5c51e5SStefan Eßerfor details.
46252884aeSStefan Eßer
47252884aeSStefan EßerThis dc has a few differences from the two above:
48252884aeSStefan Eßer
49252884aeSStefan Eßer  1) When printing a byte stream (command "P"), this bc follows what the FreeBSD
50252884aeSStefan Eßer     dc does.
51252884aeSStefan Eßer  2) This dc implements the GNU extensions for divmod ("~") and modular
52252884aeSStefan Eßer     exponentiation ("|").
53252884aeSStefan Eßer  3) This dc implements all FreeBSD extensions, except for "J" and "M".
54252884aeSStefan Eßer  4) This dc does not implement the run command ("!"), for security reasons.
55252884aeSStefan Eßer  5) Like the FreeBSD dc, this dc supports extended registers. However, they are
56252884aeSStefan Eßer     implemented differently. When it encounters whitespace where a register
57252884aeSStefan Eßer     should be, it skips the whitespace. If the character following is not
58252884aeSStefan Eßer     a lowercase letter, an error is issued. Otherwise, the register name is
59252884aeSStefan Eßer     parsed by the following regex:
60252884aeSStefan Eßer
61252884aeSStefan Eßer       [a-z][a-z0-9_]*
62252884aeSStefan Eßer
63252884aeSStefan Eßer     This generally means that register names will be surrounded by whitespace.
64252884aeSStefan Eßer
65252884aeSStefan Eßer     Examples:
66252884aeSStefan Eßer
67252884aeSStefan Eßer       l idx s temp L index S temp2 < do_thing
68252884aeSStefan Eßer
69252884aeSStefan Eßer     Also note that, unlike the FreeBSD dc, extended registers are not even
70252884aeSStefan Eßer     parsed unless the "-x" option is given. Instead, the space after a command
71252884aeSStefan Eßer     that requires a register name is taken as the register name.
72252884aeSStefan Eßer
73252884aeSStefan EßerOptions:
74d101cdd6SStefan Eßer
75d101cdd6SStefan Eßer  -C  --no-digit-clamp
76d101cdd6SStefan Eßer
77d101cdd6SStefan Eßer      Disables clamping of digits that are larger than or equal to the current
78d101cdd6SStefan Eßer      ibase when parsing numbers.
79d101cdd6SStefan Eßer
80d101cdd6SStefan Eßer      This means that the value added to a number from a digit is always that
81d101cdd6SStefan Eßer      digit's value multiplied by the value of ibase raised to the power of the
82d101cdd6SStefan Eßer      digit's position, which starts from 0 at the least significant digit.
83d101cdd6SStefan Eßer
84d101cdd6SStefan Eßer      If multiple of this option and the -c option are given, the last is used.
85d101cdd6SStefan Eßer
86d101cdd6SStefan Eßer  -c  --digit-clamp
87d101cdd6SStefan Eßer
88d101cdd6SStefan Eßer      Enables clamping of digits that are larger than or equal to the current
89d101cdd6SStefan Eßer      ibase when parsing numbers.
90d101cdd6SStefan Eßer
91d101cdd6SStefan Eßer      This means that digits that the value added to a number from a digit that
92d101cdd6SStefan Eßer      is greater than or equal to the ibase is the value of ibase minus 1 all
93d101cdd6SStefan Eßer      multiplied by the value of ibase raised to the power of the digit's
94d101cdd6SStefan Eßer      position, which starts from 0 at the least significant digit.
95d101cdd6SStefan Eßer
96d101cdd6SStefan Eßer      If multiple of this option and the -C option are given, the last is used.
9778bc019dSStefan Eßer{{ A H N HN }}
9878bc019dSStefan Eßer
9978bc019dSStefan Eßer  -E  seed  --seed=seed
10078bc019dSStefan Eßer
10178bc019dSStefan Eßer      Sets the builtin variable seed to the given value assuming that the given
10278bc019dSStefan Eßer      value is in base 10. It is a fatal error if the given value is not a valid
10378bc019dSStefan Eßer      number.
10478bc019dSStefan Eßer{{ end }}
105252884aeSStefan Eßer
106252884aeSStefan Eßer  -e  expr  --expression=expr
107252884aeSStefan Eßer
108252884aeSStefan Eßer      Run "expr" and quit. If multiple expressions or files (see below) are
109252884aeSStefan Eßer      given, they are all run. After running, dc will exit.
110252884aeSStefan Eßer
111252884aeSStefan Eßer  -f  file  --file=file
112252884aeSStefan Eßer
113252884aeSStefan Eßer      Run the dc code in "file" and exit. See above.
114252884aeSStefan Eßer
115252884aeSStefan Eßer  -h  --help
116252884aeSStefan Eßer
117252884aeSStefan Eßer      Print this usage message and exit.
118252884aeSStefan Eßer
11978bc019dSStefan Eßer  -I  ibase  --ibase=ibase
12078bc019dSStefan Eßer
12178bc019dSStefan Eßer      Sets the builtin variable ibase to the given value assuming that the given
12278bc019dSStefan Eßer      value is in base 10. It is a fatal error if the given value is not a valid
12378bc019dSStefan Eßer      number.
12478bc019dSStefan Eßer
125252884aeSStefan Eßer  -i  --interactive
126252884aeSStefan Eßer
127252884aeSStefan Eßer      Put dc into interactive mode. See the man page for more details.
128252884aeSStefan Eßer
129d43fa8efSStefan Eßer  -L  --no-line-length
130d43fa8efSStefan Eßer
131d43fa8efSStefan Eßer      Disable line length checking.
132d43fa8efSStefan Eßer
13378bc019dSStefan Eßer  -O  obase  --obase=obase
13478bc019dSStefan Eßer
13578bc019dSStefan Eßer      Sets the builtin variable obase to the given value assuming that the given
13678bc019dSStefan Eßer      value is in base 10. It is a fatal error if the given value is not a valid
13778bc019dSStefan Eßer      number.
13878bc019dSStefan Eßer
139252884aeSStefan Eßer  -P  --no-prompt
140252884aeSStefan Eßer
1417e5c51e5SStefan Eßer      Disable the prompts in interactive mode.
1427e5c51e5SStefan Eßer
1437e5c51e5SStefan Eßer  -R  --no-read-prompt
1447e5c51e5SStefan Eßer
1457e5c51e5SStefan Eßer      Disable the read prompt in interactive mode.
146252884aeSStefan Eßer
14778bc019dSStefan Eßer  -S  scale  --scale=scale
14878bc019dSStefan Eßer
14978bc019dSStefan Eßer      Sets the builtin variable scale to the given value assuming that the given
15078bc019dSStefan Eßer      value is in base 10. It is a fatal error if the given value is not a valid
15178bc019dSStefan Eßer      number.
15278bc019dSStefan Eßer
153252884aeSStefan Eßer  -V  --version
154252884aeSStefan Eßer
155252884aeSStefan Eßer      Print version and copyright and exit.
156252884aeSStefan Eßer
157252884aeSStefan Eßer  -x  --extended-register
158252884aeSStefan Eßer
159252884aeSStefan Eßer      Enable extended register mode.
16044d4804dSStefan Eßer
161d43fa8efSStefan Eßer  -z  --leading-zeroes
162d43fa8efSStefan Eßer
163d43fa8efSStefan Eßer      Enable leading zeroes on numbers greater than -1 and less than 1.
164d43fa8efSStefan Eßer
16544d4804dSStefan EßerEnvironment variables:
16644d4804dSStefan Eßer
16744d4804dSStefan Eßer  DC_ENV_ARGS
16844d4804dSStefan Eßer
16944d4804dSStefan Eßer      Command-line arguments to use on every run.
17044d4804dSStefan Eßer
17144d4804dSStefan Eßer  DC_LINE_LENGTH
17244d4804dSStefan Eßer
17344d4804dSStefan Eßer      If an integer, the number of characters to print on a line before
174d43fa8efSStefan Eßer      wrapping. Using 0 will disable line length checking.
17544d4804dSStefan Eßer
17644d4804dSStefan Eßer  DC_SIGINT_RESET
17744d4804dSStefan Eßer
17844d4804dSStefan Eßer      If an integer and non-zero, reset on SIGINT, rather than exit, when in
17944d4804dSStefan Eßer      interactive mode.
18044d4804dSStefan Eßer
181d101cdd6SStefan Eßer      If zero, do not reset on SIGINT in all cases, but exit instead.
182d101cdd6SStefan Eßer
18344d4804dSStefan Eßer      Overrides the default, which is %s.
18444d4804dSStefan Eßer
18544d4804dSStefan Eßer  DC_TTY_MODE
18644d4804dSStefan Eßer
18744d4804dSStefan Eßer      If an integer and non-zero, enable TTY mode when it is available.
18844d4804dSStefan Eßer
189d101cdd6SStefan Eßer      If zero, disable TTY mode in all cases.
190d101cdd6SStefan Eßer
19144d4804dSStefan Eßer      Overrides the default, which is TTY mode %s.
19244d4804dSStefan Eßer
19344d4804dSStefan Eßer  DC_PROMPT
19444d4804dSStefan Eßer
19544d4804dSStefan Eßer      If an integer and non-zero, enable prompt when TTY mode is possible.
19644d4804dSStefan Eßer
197d101cdd6SStefan Eßer      If zero, disable prompt in all cases.
198d101cdd6SStefan Eßer
19944d4804dSStefan Eßer      Overrides the default, which is prompt %s.
20010041e99SStefan Eßer
20110041e99SStefan Eßer  DC_EXPR_EXIT
20210041e99SStefan Eßer
20310041e99SStefan Eßer      If an integer and non-zero, exit when expressions or expression files are
20410041e99SStefan Eßer      given on the command-line, and does not exit when an integer and zero.
20510041e99SStefan Eßer
20610041e99SStefan Eßer      Overrides the default, which is %s.
207d101cdd6SStefan Eßer
208d101cdd6SStefan Eßer  DC_DIGIT_CLAMP
209d101cdd6SStefan Eßer
210d101cdd6SStefan Eßer      If an integer and non-zero, clamp digits larger than or equal to the
211d101cdd6SStefan Eßer      current ibase when parsing numbers.
212d101cdd6SStefan Eßer
213d101cdd6SStefan Eßer      Overrides the default, which is %s.
214