xref: /freebsd/contrib/bc/gen/bc_help.txt (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1/*
2 * *****************************************************************************
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 *
6 * Copyright (c) 2018-2023 Gavin D. Howard and contributors.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright notice, this
12 *   list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright notice,
15 *   this list of conditions and the following disclaimer in the documentation
16 *   and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * *****************************************************************************
31 *
32 * The bc help text.
33 *
34 */
35
36usage: %s [options] [file...]
37
38bc is a command-line, arbitrary-precision calculator with a Turing-complete
39language. For details, use `man %s` or see the online documentation at
40https://git.gavinhoward.com/gavin/bc/src/tag/%s/manuals/bc/%s.1.md.
41
42This bc is compatible with both the GNU bc and the POSIX bc spec. See the GNU bc
43manual (https://www.gnu.org/software/bc/manual/bc.html) and bc spec
44(http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html)
45for details.
46
47This bc has three differences to the GNU bc:
48
49  1) Arrays can be passed to the builtin "length" function to get the number of
50     elements currently in the array. The following example prints "1":
51
52       a[0] = 0
53       length(a[])
54
55  2) The precedence of the boolean "not" operator (!) is equal to that of the
56     unary minus (-), or negation, operator. This still allows POSIX-compliant
57     scripts to work while somewhat preserving expected behavior (versus C) and
58     making parsing easier.
59  3) This bc has many more extensions than the GNU bc does. For details, see the
60     man page or online documentation.
61
62This bc also implements the dot (.) extension of the BSD bc.
63
64Options:
65
66  -C  --no-digit-clamp
67
68      Disables clamping of digits that are larger than or equal to the current
69      ibase when parsing numbers.
70
71      This means that the value added to a number from a digit is always that
72      digit's value multiplied by the value of ibase raised to the power of the
73      digit's position, which starts from 0 at the least significant digit.
74
75      If multiple of this option and the -c option are given, the last is used.
76
77  -c  --digit-clamp
78
79      Enables clamping of digits that are larger than or equal to the current
80      ibase when parsing numbers.
81
82      This means that digits that the value added to a number from a digit that
83      is greater than or equal to the ibase is the value of ibase minus 1 all
84      multiplied by the value of ibase raised to the power of the digit's
85      position, which starts from 0 at the least significant digit.
86
87      If multiple of this option and the -C option are given, the last is used.
88{{ A H N HN }}
89
90  -E  seed  --seed=seed
91
92      Sets the builtin variable seed to the given value assuming that the given
93      value is in base 10. It is a fatal error if the given value is not a valid
94      number.
95{{ end }}
96
97  -e  expr  --expression=expr
98
99      Run "expr" and quit. If multiple expressions or files (see below) are
100      given, they are all run before executing from stdin.
101
102  -f  file  --file=file
103
104      Run the bc code in "file" and exit. See above as well.
105
106  -g  --global-stacks
107
108      Turn scale, ibase, and obase into stacks. This makes the value of each be
109      be restored on returning from functions. See the man page or online
110      documentation for more details.
111
112  -h  --help
113
114      Print this usage message and exit.
115
116  -I  ibase  --ibase=ibase
117
118      Sets the builtin variable ibase to the given value assuming that the given
119      value is in base 10. It is a fatal error if the given value is not a valid
120      number.
121
122  -i  --interactive
123
124      Force interactive mode.
125
126  -L  --no-line-length
127
128      Disable line length checking.
129
130  -l  --mathlib
131
132      Use predefined math routines:
133
134          s(expr)  =  sine of expr in radians
135          c(expr)  =  cosine of expr in radians
136          a(expr)  =  arctangent of expr, returning radians
137          l(expr)  =  natural log of expr
138          e(expr)  =  raises e to the power of expr
139          j(n, x)  =  Bessel function of integer order n of x
140
141      This bc may load more functions with these options. See the manpage or
142      online documentation for details.
143
144  -O  obase  --obase=obase
145
146      Sets the builtin variable obase to the given value assuming that the given
147      value is in base 10. It is a fatal error if the given value is not a valid
148      number.
149
150  -P  --no-prompt
151
152      Disable the prompts in interactive mode.
153
154  -R  --no-read-prompt
155
156      Disable the read prompt in interactive mode.
157
158  -r  keyword  --redefine=keyword
159
160      Redefines "keyword" and allows it to be used as a function, variable, and
161      array name. This is useful when this bc gives parse errors on scripts
162      meant for other bc implementations.
163
164      Only keywords that are not in the POSIX bc spec may be redefined.
165
166      It is a fatal error to attempt to redefine a keyword that cannot be
167      redefined or does not exist.
168
169  -q  --quiet
170
171      Don't print version and copyright.
172
173  -S  scale  --scale=scale
174
175      Sets the builtin variable scale to the given value assuming that the given
176      value is in base 10. It is a fatal error if the given value is not a valid
177      number.
178
179  -s  --standard
180
181      Error if any non-POSIX extensions are used.
182
183  -w  --warn
184
185      Warn if any non-POSIX extensions are used.
186
187  -v  --version
188
189      Print version information and copyright and exit.
190
191  -z  --leading-zeroes
192
193      Enable leading zeroes on numbers greater than -1 and less than 1.
194
195Environment variables:
196
197  POSIXLY_CORRECT
198
199      Error if any non-POSIX extensions are used.
200
201  BC_ENV_ARGS
202
203      Command-line arguments to use on every run.
204
205  BC_LINE_LENGTH
206
207      If an integer, the number of characters to print on a line before
208      wrapping. Using 0 will disable line length checking.
209
210  BC_BANNER
211
212      If an integer and non-zero, display the copyright banner in interactive
213      mode.
214
215      If zero, disable the banner.
216
217      Overrides the default, which is %s print the banner.
218
219  BC_SIGINT_RESET
220
221      If an integer and non-zero, reset on SIGINT, rather than exit, when in
222      interactive mode.
223
224      If zero, do not reset on SIGINT in all cases, but exit instead.
225
226      Overrides the default, which is %s.
227
228  BC_TTY_MODE
229
230      If an integer and non-zero, enable TTY mode when it is available.
231
232      If zero, disable TTY mode in all cases.
233
234      Overrides the default, which is TTY mode %s.
235
236  BC_PROMPT
237
238      If an integer and non-zero, enable prompt when TTY mode is possible.
239
240      If zero, disable prompt in all cases.
241
242      Overrides the default, which is prompt %s.
243
244  BC_EXPR_EXIT
245
246      If an integer and non-zero, exit when expressions or expression files are
247      given on the command-line, and does not exit when an integer and zero.
248
249      Overrides the default, which is %s.
250
251  BC_DIGIT_CLAMP
252
253      If an integer and non-zero, clamp digits larger than or equal to the
254      current ibase when parsing numbers.
255
256      Overrides the default, which is %s.
257