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