diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-13 16:35:52 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-13 16:35:52 +0100 |
commit | 89e785af98acb71ae495c76e1f1cf4944431a3db (patch) | |
tree | 8200728aacfc4c5cb45d6455248847f0ff5fc5a8 | |
parent | 9811ad02bdbd9dbec9f1e929808d305d4ebb0f14 (diff) | |
download | busybox-w32-89e785af98acb71ae495c76e1f1cf4944431a3db.tar.gz busybox-w32-89e785af98acb71ae495c76e1f1cf4944431a3db.tar.bz2 busybox-w32-89e785af98acb71ae495c76e1f1cf4944431a3db.zip |
bc: trim config help text, add a few comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 88 |
1 files changed, 38 insertions, 50 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index c7e0e39e0..47acd7fc3 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -10,49 +10,34 @@ | |||
10 | //config: bc is a command-line, arbitrary-precision calculator with a | 10 | //config: bc is a command-line, arbitrary-precision calculator with a |
11 | //config: Turing-complete language. See the GNU bc manual | 11 | //config: Turing-complete language. See the GNU bc manual |
12 | //config: (https://www.gnu.org/software/bc/manual/bc.html) and bc spec | 12 | //config: (https://www.gnu.org/software/bc/manual/bc.html) and bc spec |
13 | //config: (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) | 13 | //config: (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html). |
14 | //config: for details. | ||
15 | //config: | 14 | //config: |
16 | //config: This bc has four differences to the GNU bc: | 15 | //config: This bc has five differences to the GNU bc: |
17 | //config: | 16 | //config: 1) The period (.) is a shortcut for "last", as in the BSD bc. |
18 | //config: 1) The period (.) can also be used as a shortcut for "last", as in | ||
19 | //config: the BSD bc. | ||
20 | //config: 2) Arrays are copied before being passed as arguments to | 17 | //config: 2) Arrays are copied before being passed as arguments to |
21 | //config: functions. This behavior is required by the bc spec. | 18 | //config: functions. This behavior is required by the bc spec. |
22 | //config: 3) Arrays can be passed to the builtin "length" function to get | 19 | //config: 3) Arrays can be passed to the builtin "length" function to get |
23 | //config: the number of elements currently in the array. The following | 20 | //config: the number of elements in the array. This prints "1": |
24 | //config: example prints "1": | 21 | //config: a[0] = 0; length(a[]) |
25 | //config: | ||
26 | //config: a[0] = 0 | ||
27 | //config: length(a[]) | ||
28 | //config: | ||
29 | //config: 4) The precedence of the boolean "not" operator (!) is equal to | 22 | //config: 4) The precedence of the boolean "not" operator (!) is equal to |
30 | //config: that of the unary minus (-), or negation, operator. This still | 23 | //config: that of the unary minus (-) negation operator. This still |
31 | //config: allows POSIX-compliant scripts to work while somewhat | 24 | //config: allows POSIX-compliant scripts to work while somewhat |
32 | //config: preserving expected behavior (versus C) and making parsing | 25 | //config: preserving expected behavior (versus C) and making parsing |
33 | //config: easier. | 26 | //config: easier. |
27 | //config: 5) "read()" accepts expressions, not only numeric literals. | ||
34 | //config: | 28 | //config: |
35 | //config: Options: | 29 | //config: Options: |
36 | //config: | ||
37 | //config: -i --interactive force interactive mode | 30 | //config: -i --interactive force interactive mode |
31 | //config: -q --quiet don't print version and copyright | ||
32 | //config: -s --standard error if any non-POSIX extensions are used | ||
33 | //config: -w --warn warn if any non-POSIX extensions are used | ||
38 | //config: -l --mathlib use predefined math routines: | 34 | //config: -l --mathlib use predefined math routines: |
39 | //config: | 35 | //config: s(expr) sine in radians |
40 | //config: s(expr) = sine of expr in radians | 36 | //config: c(expr) cosine in radians |
41 | //config: c(expr) = cosine of expr in radians | 37 | //config: a(expr) arctangent, returning radians |
42 | //config: a(expr) = arctangent of expr, returning | 38 | //config: l(expr) natural log |
43 | //config: radians | 39 | //config: e(expr) raises e to the power of expr |
44 | //config: l(expr) = natural log of expr | 40 | //config: j(n, x) Bessel function of integer order n of x |
45 | //config: e(expr) = raises e to the power of expr | ||
46 | //config: j(n, x) = Bessel function of integer order | ||
47 | //config: n of x | ||
48 | //config: | ||
49 | //config: -q --quiet don't print version and copyright. | ||
50 | //config: -s --standard error if any non-POSIX extensions are used. | ||
51 | //config: -w --warn warn if any non-POSIX extensions are used. | ||
52 | //config: -v --version print version and copyright and exit. | ||
53 | //config: | ||
54 | //config: Long options are only available if FEATURE_BC_LONG_OPTIONS is | ||
55 | //config: enabled. | ||
56 | //config: | 41 | //config: |
57 | //config:config DC | 42 | //config:config DC |
58 | //config: bool "dc (38 kb; 49 kb when combined with bc)" | 43 | //config: bool "dc (38 kb; 49 kb when combined with bc)" |
@@ -61,33 +46,24 @@ | |||
61 | //config: dc is a reverse-polish notation command-line calculator which | 46 | //config: dc is a reverse-polish notation command-line calculator which |
62 | //config: supports unlimited precision arithmetic. See the FreeBSD man page | 47 | //config: supports unlimited precision arithmetic. See the FreeBSD man page |
63 | //config: (https://www.unix.com/man-page/FreeBSD/1/dc/) and GNU dc manual | 48 | //config: (https://www.unix.com/man-page/FreeBSD/1/dc/) and GNU dc manual |
64 | //config: (https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html) | 49 | //config: (https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html). |
65 | //config: for details. | ||
66 | //config: | 50 | //config: |
67 | //config: This dc has a few differences from the two above: | 51 | //config: This dc has a few differences from the two above: |
68 | //config: | 52 | //config: 1) When printing a byte stream (command "P"), this dc follows what |
69 | //config: 1) When printing a byte stream (command "P"), this bc follows what | ||
70 | //config: the FreeBSD dc does. | 53 | //config: the FreeBSD dc does. |
71 | //config: 2) This dc implements the GNU extensions for divmod ("~") and | 54 | //config: 2) Implements the GNU extensions for divmod ("~") and |
72 | //config: modular exponentiation ("|"). | 55 | //config: modular exponentiation ("|"). |
73 | //config: 3) This dc implements all FreeBSD extensions, except for "J" and | 56 | //config: 3) Implements all FreeBSD extensions, except for "J" and "M". |
74 | //config: "M". | ||
75 | //config: 4) Like the FreeBSD dc, this dc supports extended registers. | 57 | //config: 4) Like the FreeBSD dc, this dc supports extended registers. |
76 | //config: However, they are implemented differently. When it encounters | 58 | //config: However, they are implemented differently. When it encounters |
77 | //config: whitespace where a register should be, it skips the whitespace. | 59 | //config: whitespace where a register should be, it skips the whitespace. |
78 | //config: If the character following is not a lowercase letter, an error | 60 | //config: If the character following is not a lowercase letter, an error |
79 | //config: is issued. Otherwise, the register name is parsed by the | 61 | //config: is issued. Otherwise, the register name is parsed by the |
80 | //config: following regex: | 62 | //config: following regex: |
81 | //config: | 63 | //config: [a-z][a-z0-9_]* |
82 | //config: [a-z][a-z0-9_]* | ||
83 | //config: | ||
84 | //config: This generally means that register names will be surrounded by | 64 | //config: This generally means that register names will be surrounded by |
85 | //config: whitespace. | 65 | //config: whitespace. Examples: |
86 | //config: | 66 | //config: l idx s temp L index S temp2 < do_thing |
87 | //config: Examples: | ||
88 | //config: | ||
89 | //config: l idx s temp L index S temp2 < do_thing | ||
90 | //config: | ||
91 | //config: Also note that, like the FreeBSD dc, extended registers are not | 67 | //config: Also note that, like the FreeBSD dc, extended registers are not |
92 | //config: allowed unless the "-x" option is given. | 68 | //config: allowed unless the "-x" option is given. |
93 | //config: | 69 | //config: |
@@ -105,11 +81,19 @@ | |||
105 | //config: NOTE: This will require libm to be present for linking. | 81 | //config: NOTE: This will require libm to be present for linking. |
106 | //config: | 82 | //config: |
107 | //config:config FEATURE_BC_SIGNALS | 83 | //config:config FEATURE_BC_SIGNALS |
108 | //config: bool "Enable bc/dc signal handling" | 84 | //config: bool "Interactive mode (+4kb)" |
109 | //config: default y | 85 | //config: default y |
110 | //config: depends on (BC || DC) && !FEATURE_DC_SMALL | 86 | //config: depends on (BC || DC) && !FEATURE_DC_SMALL |
111 | //config: help | 87 | //config: help |
112 | //config: Enable signal handling for bc and dc. | 88 | //config: Enable interactive mode: when started on a tty, |
89 | //config: ^C interrupts execution and returns to command line, | ||
90 | //config: errors also return to command line instead of exiting, | ||
91 | //config: line editing with history is available. | ||
92 | //config: | ||
93 | //config: With this option off, input can still be taken from tty, | ||
94 | //config: but all errors are fatal, ^C is fatal, | ||
95 | //config: tty is treated exactly the same as any other | ||
96 | //config: standard input (IOW: no line editing). | ||
113 | //config: | 97 | //config: |
114 | //config:config FEATURE_BC_LONG_OPTIONS | 98 | //config:config FEATURE_BC_LONG_OPTIONS |
115 | //config: bool "Enable bc/dc long options" | 99 | //config: bool "Enable bc/dc long options" |
@@ -7468,6 +7452,8 @@ static int bc_vm_init(const char *env_len) | |||
7468 | bc_program_init(); | 7452 | bc_program_init(); |
7469 | bc_parse_create(&G.prs, BC_PROG_MAIN); | 7453 | bc_parse_create(&G.prs, BC_PROG_MAIN); |
7470 | 7454 | ||
7455 | //TODO: in GNU bc, the check is (isatty(0) && isatty(1)), | ||
7456 | //-i option unconditionally enables this regardless of isatty(): | ||
7471 | if (isatty(0)) { | 7457 | if (isatty(0)) { |
7472 | #if ENABLE_FEATURE_BC_SIGNALS | 7458 | #if ENABLE_FEATURE_BC_SIGNALS |
7473 | G_ttyin = 1; | 7459 | G_ttyin = 1; |
@@ -7476,10 +7462,12 @@ static int bc_vm_init(const char *env_len) | |||
7476 | // In particular, this means ^C won't cause | 7462 | // In particular, this means ^C won't cause |
7477 | // stdout to get into "error state" if SIGINT hits | 7463 | // stdout to get into "error state" if SIGINT hits |
7478 | // within write() syscall. | 7464 | // within write() syscall. |
7479 | // The downside is that ^C while line input is taken | 7465 | // |
7466 | // The downside is that ^C while tty input is taken | ||
7480 | // will only be handled after [Enter] since read() | 7467 | // will only be handled after [Enter] since read() |
7481 | // from stdin is not interrupted by ^C either, | 7468 | // from stdin is not interrupted by ^C either, |
7482 | // it restarts, thus fgetc() does not return on ^C. | 7469 | // it restarts, thus fgetc() does not return on ^C. |
7470 | // (This problem manifests only if line editing is disabled) | ||
7483 | signal_SA_RESTART_empty_mask(SIGINT, record_signo); | 7471 | signal_SA_RESTART_empty_mask(SIGINT, record_signo); |
7484 | 7472 | ||
7485 | // Without SA_RESTART, this exhibits a bug: | 7473 | // Without SA_RESTART, this exhibits a bug: |