Browse Source

Add BC_EXPR_EXIT back with setting default

Since it is possible to set defaults now, why *not* add it back? *I*
want it!

Signed-off-by: Gavin Howard <gavin@yzena.com>
line_libs
Gavin Howard 9 months ago
parent
commit
c4e3e23057
Signed by: gavin
GPG Key ID: C08038BDF280D33E
  1. 8
      Makefile.in
  2. 20
      configure.sh
  3. 7
      gen/bc_help.txt
  4. 7
      gen/dc_help.txt
  5. 8
      include/status.h
  6. 6
      include/vm.h
  7. 11
      manuals/bc.1.md.in
  8. 13
      manuals/bc/A.1
  9. 11
      manuals/bc/A.1.md
  10. 13
      manuals/bc/E.1
  11. 11
      manuals/bc/E.1.md
  12. 13
      manuals/bc/EH.1
  13. 11
      manuals/bc/EH.1.md
  14. 13
      manuals/bc/EHN.1
  15. 11
      manuals/bc/EHN.1.md
  16. 13
      manuals/bc/EN.1
  17. 11
      manuals/bc/EN.1.md
  18. 13
      manuals/bc/H.1
  19. 11
      manuals/bc/H.1.md
  20. 13
      manuals/bc/HN.1
  21. 11
      manuals/bc/HN.1.md
  22. 13
      manuals/bc/N.1
  23. 11
      manuals/bc/N.1.md
  24. 11
      manuals/dc.1.md.in
  25. 13
      manuals/dc/A.1
  26. 11
      manuals/dc/A.1.md
  27. 13
      manuals/dc/E.1
  28. 11
      manuals/dc/E.1.md
  29. 13
      manuals/dc/EH.1
  30. 11
      manuals/dc/EH.1.md
  31. 13
      manuals/dc/EHN.1
  32. 11
      manuals/dc/EHN.1.md
  33. 13
      manuals/dc/EN.1
  34. 11
      manuals/dc/EN.1.md
  35. 13
      manuals/dc/H.1
  36. 11
      manuals/dc/H.1.md
  37. 13
      manuals/dc/HN.1
  38. 11
      manuals/dc/HN.1.md
  39. 13
      manuals/dc/N.1
  40. 11
      manuals/dc/N.1.md
  41. 38
      src/vm.c
  42. 8
      vs/bc.vcxproj

8
Makefile.in

@ -146,6 +146,8 @@ BC_DEFAULT_TTY_MODE = %%BC_DEFAULT_TTY_MODE%%
DC_DEFAULT_TTY_MODE = %%DC_DEFAULT_TTY_MODE%%
BC_DEFAULT_PROMPT = %%BC_DEFAULT_PROMPT%%
DC_DEFAULT_PROMPT = %%DC_DEFAULT_PROMPT%%
BC_DEFAULT_EXPR_EXIT = %%BC_DEFAULT_EXPR_EXIT%%
DC_DEFAULT_EXPR_EXIT = %%DC_DEFAULT_EXPR_EXIT%%
RM = rm
MKDIR = mkdir
@ -176,11 +178,13 @@ BC_DEFS0 = -DBC_DEFAULT_BANNER=$(BC_DEFAULT_BANNER)
BC_DEFS1 = -DBC_DEFAULT_SIGINT_RESET=$(BC_DEFAULT_SIGINT_RESET)
BC_DEFS2 = -DBC_DEFAULT_TTY_MODE=$(BC_DEFAULT_TTY_MODE)
BC_DEFS3 = -DBC_DEFAULT_PROMPT=$(BC_DEFAULT_PROMPT)
BC_DEFS = $(BC_DEFS0) $(BC_DEFS1) $(BC_DEFS2) $(BC_DEFS3)
BC_DEFS4 = -DBC_DEFAULT_EXPR_EXIT=$(BC_DEFAULT_EXPR_EXIT)
BC_DEFS = $(BC_DEFS0) $(BC_DEFS1) $(BC_DEFS2) $(BC_DEFS3) $(BC_DEFS4)
DC_DEFS1 = -DDC_DEFAULT_SIGINT_RESET=$(DC_DEFAULT_SIGINT_RESET)
DC_DEFS2 = -DDC_DEFAULT_TTY_MODE=$(DC_DEFAULT_TTY_MODE)
DC_DEFS3 = -DDC_DEFAULT_PROMPT=$(DC_DEFAULT_PROMPT)
DC_DEFS = $(DC_DEFS1) $(DC_DEFS2) $(DC_DEFS3)
DC_DEFS4 = -DDC_DEFAULT_EXPR_EXIT=$(DC_DEFAULT_EXPR_EXIT)
DC_DEFS = $(DC_DEFS1) $(DC_DEFS2) $(DC_DEFS3) $(DC_DEFS4)
CPPFLAGS1 = -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
CPPFLAGS2 = $(CPPFLAGS1) -I./include/ -DBUILD_TYPE=$(BC_BUILD_TYPE) %%LONG_BIT_DEFINE%%

20
configure.sh

@ -290,6 +290,18 @@ usage() {
printf '| | for dc should be on | | |\n'
printf '| | in tty mode. | | |\n'
printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
printf '| bc.expr_exit | Whether to exit bc | 1 | BC_EXPR_EXIT |\n'
printf '| | if an expression or | | |\n'
printf '| | expression file is | | |\n'
printf '| | given with the -e or | | |\n'
printf '| | -f options. | | |\n'
printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
printf '| dc.expr_exit | Whether to exit dc | 1 | DC_EXPR_EXIT |\n'
printf '| | if an expression or | | |\n'
printf '| | expression file is | | |\n'
printf '| | given with the -e or | | |\n'
printf '| | -f options. | | |\n'
printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
printf '\n'
printf 'These settings are not meant to be changed on a whim. They are meant to ensure\n'
printf 'that this bc and dc will conform to the expectations of the user on each\n'
@ -594,6 +606,8 @@ set_default() {
dc.tty_mode) dc_default_tty_mode="$_set_default_on" ;;
bc.prompt) bc_default_prompt="$_set_default_on" ;;
dc.prompt) dc_default_prompt="$_set_default_on" ;;
bc.expr_exit) bc_default_expr_exit="$_set_default_on";;
dc.expr_exit) dc_default_expr_exit="$_set_default_on";;
?) usage "Invalid setting: $_set_default_name" ;;
esac
@ -656,6 +670,8 @@ bc_default_tty_mode=1
dc_default_tty_mode=0
bc_default_prompt=""
dc_default_prompt=""
bc_default_expr_exit=1
dc_default_expr_exit=1
# getopts is a POSIX utility, but it cannot handle long options. Thus, the
# handling of long options is done by hand, and that's the reason that short and
@ -1495,6 +1511,8 @@ printf 'bc.tty_mode=%s\n' "$bc_default_tty_mode"
printf 'dc.tty_mode=%s\n' "$dc_default_tty_mode"
printf 'bc.prompt=%s\n' "$bc_default_prompt"
printf 'dc.prompt=%s\n' "$dc_default_prompt"
printf 'bc.expr_exit=%s\n' "$bc_default_expr_exit"
printf 'dc.expr_exit=%s\n' "$dc_default_expr_exit"
# This is where the real work begins. This is the point at which the Makefile.in
# template is edited and output to the Makefile.
@ -1630,6 +1648,8 @@ contents=$(replace "$contents" "BC_DEFAULT_TTY_MODE" "$bc_default_tty_mode")
contents=$(replace "$contents" "DC_DEFAULT_TTY_MODE" "$dc_default_tty_mode")
contents=$(replace "$contents" "BC_DEFAULT_PROMPT" "$bc_default_prompt")
contents=$(replace "$contents" "DC_DEFAULT_PROMPT" "$dc_default_prompt")
contents=$(replace "$contents" "BC_DEFAULT_EXPR_EXIT" "$bc_default_expr_exit")
contents=$(replace "$contents" "DC_DEFAULT_EXPR_EXIT" "$dc_default_expr_exit")
# Do the first print to the Makefile.
printf '%s\n%s\n\n' "$contents" "$SRC_TARGETS" > "$scriptdir/Makefile"

7
gen/bc_help.txt

@ -183,3 +183,10 @@ Environment variables:
If an integer and non-zero, enable prompt when TTY mode is possible.
Overrides the default, which is prompt %s.
BC_EXPR_EXIT
If an integer and non-zero, exit when expressions or expression files are
given on the command-line, and does not exit when an integer and zero.
Overrides the default, which is %s.

7
gen/dc_help.txt

@ -142,3 +142,10 @@ Environment variables:
If an integer and non-zero, enable prompt when TTY mode is possible.
Overrides the default, which is prompt %s.
DC_EXPR_EXIT
If an integer and non-zero, exit when expressions or expression files are
given on the command-line, and does not exit when an integer and zero.
Overrides the default, which is %s.

8
include/status.h

@ -268,6 +268,10 @@
#define BC_DEFAULT_PROMPT BC_DEFAULT_TTY_MODE
#endif // BC_DEFAULT_PROMPT
#ifndef BC_DEFAULT_EXPR_EXIT
#define BC_DEFAULT_EXPR_EXIT (1)
#endif // BC_DEFAULT_EXPR_EXIT
// All of these set defaults for settings.
#ifndef DC_DEFAULT_SIGINT_RESET
#define DC_DEFAULT_SIGINT_RESET (1)
@ -285,6 +289,10 @@
#define DC_DEFAULT_PROMPT DC_DEFAULT_TTY_MODE
#endif // DC_DEFAULT_PROMPT
#ifndef DC_DEFAULT_EXPR_EXIT
#define DC_DEFAULT_EXPR_EXIT (1)
#endif // DC_DEFAULT_EXPR_EXIT
/// Statuses, which mark either which category of error happened, or some other
/// status that matters.
typedef enum BcStatus {

6
include/vm.h

@ -176,6 +176,9 @@
/// The flag for reset on SIGINT.
#define BC_FLAG_SIGINT (UINTMAX_C(1)<<12)
/// The flag for exiting with expressions.
#define BC_FLAG_EXPR_EXIT (UINTMAX_C(1)<<13)
/// A convenience macro for getting the TTYIN flag.
#define BC_TTYIN (vm.flags & BC_FLAG_TTYIN)
@ -220,6 +223,9 @@
/// A convenience macro for getting the leading zero flag.
#define BC_Z (vm.flags & BC_FLAG_Z)
/// A convenience macro for getting the expression exit flag.
#define BC_EXPR_EXIT (vm.flags & BC_FLAG_EXPR_EXIT)
#if BC_ENABLED
/// A convenience macro for checking if bc is in POSIX mode.

11
manuals/bc.1.md.in

@ -2223,6 +2223,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

13
manuals/bc/A.1

@ -2552,6 +2552,19 @@ This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]BC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
expressions and expression files, and a non-zero value makes bc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
bc(1) returns the following exit statuses:

11
manuals/bc/A.1.md

@ -2129,6 +2129,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

13
manuals/bc/E.1

@ -1400,6 +1400,19 @@ This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]BC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
expressions and expression files, and a non-zero value makes bc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
bc(1) returns the following exit statuses:

11
manuals/bc/E.1.md

@ -1149,6 +1149,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

13
manuals/bc/EH.1

@ -1400,6 +1400,19 @@ This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]BC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
expressions and expression files, and a non-zero value makes bc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
bc(1) returns the following exit statuses:

11
manuals/bc/EH.1.md

@ -1149,6 +1149,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

13
manuals/bc/EHN.1

@ -1400,6 +1400,19 @@ This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]BC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
expressions and expression files, and a non-zero value makes bc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
bc(1) returns the following exit statuses:

11
manuals/bc/EHN.1.md

@ -1149,6 +1149,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

13
manuals/bc/EN.1

@ -1400,6 +1400,19 @@ This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]BC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
expressions and expression files, and a non-zero value makes bc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
bc(1) returns the following exit statuses:

11
manuals/bc/EN.1.md

@ -1149,6 +1149,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

13
manuals/bc/H.1

@ -2552,6 +2552,19 @@ This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]BC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
expressions and expression files, and a non-zero value makes bc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
bc(1) returns the following exit statuses:

11
manuals/bc/H.1.md

@ -2129,6 +2129,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

13
manuals/bc/HN.1

@ -2552,6 +2552,19 @@ This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]BC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
expressions and expression files, and a non-zero value makes bc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
bc(1) returns the following exit statuses:

11
manuals/bc/HN.1.md

@ -2129,6 +2129,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

13
manuals/bc/N.1

@ -2552,6 +2552,19 @@ This environment variable and the \f[B]BC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]BC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes bc(1) exit after executing the
expressions and expression files, and a non-zero value makes bc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
bc(1) returns the following exit statuses:

11
manuals/bc/N.1.md

@ -2129,6 +2129,17 @@ bc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**BC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes bc(1) exit
after executing the expressions and expression files, and a non-zero value
makes bc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
bc(1) returns the following exit statuses:

11
manuals/dc.1.md.in

@ -1225,6 +1225,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

13
manuals/dc/A.1

@ -1340,6 +1340,19 @@ This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]DC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
expressions and expression files, and a non-zero value makes dc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
dc(1) returns the following exit statuses:

11
manuals/dc/A.1.md

@ -1190,6 +1190,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

13
manuals/dc/E.1

@ -1135,6 +1135,19 @@ This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]DC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
expressions and expression files, and a non-zero value makes dc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
dc(1) returns the following exit statuses:

11
manuals/dc/E.1.md

@ -1025,6 +1025,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

13
manuals/dc/EH.1

@ -1135,6 +1135,19 @@ This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]DC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
expressions and expression files, and a non-zero value makes dc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
dc(1) returns the following exit statuses:

11
manuals/dc/EH.1.md

@ -1025,6 +1025,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

13
manuals/dc/EHN.1

@ -1135,6 +1135,19 @@ This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]DC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
expressions and expression files, and a non-zero value makes dc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
dc(1) returns the following exit statuses:

11
manuals/dc/EHN.1.md

@ -1025,6 +1025,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

13
manuals/dc/EN.1

@ -1135,6 +1135,19 @@ This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]DC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
expressions and expression files, and a non-zero value makes dc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
dc(1) returns the following exit statuses:

11
manuals/dc/EN.1.md

@ -1025,6 +1025,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

13
manuals/dc/H.1

@ -1340,6 +1340,19 @@ This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]DC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
expressions and expression files, and a non-zero value makes dc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
dc(1) returns the following exit statuses:

11
manuals/dc/H.1.md

@ -1190,6 +1190,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

13
manuals/dc/HN.1

@ -1340,6 +1340,19 @@ This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]DC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
expressions and expression files, and a non-zero value makes dc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
dc(1) returns the following exit statuses:

11
manuals/dc/HN.1.md

@ -1190,6 +1190,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

13
manuals/dc/N.1

@ -1340,6 +1340,19 @@ This environment variable and the \f[B]DC_TTY_MODE\f[R] environment
variable override the default, which can be queried with the
\f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.TP
\f[B]DC_EXPR_EXIT\f[R]
If any expressions or expression files are given on the command-line
with \f[B]-e\f[R], \f[B]--expression\f[R], \f[B]-f\f[R], or
\f[B]--file\f[R], then if this environment variable exists and contains
an integer, a non-zero value makes dc(1) exit after executing the
expressions and expression files, and a non-zero value makes dc(1) not
exit.
.RS
.PP
This environment variable overrides the default, which can be queried
with the \f[B]-h\f[R] or \f[B]--help\f[R] options.
.RE
.SH EXIT STATUS
.PP
dc(1) returns the following exit statuses:

11
manuals/dc/N.1.md

@ -1190,6 +1190,17 @@ dc(1) recognizes the following environment variables:
override the default, which can be queried with the **-h** or **-\-help**
options.
**DC_EXPR_EXIT**
: If any expressions or expression files are given on the command-line with
**-e**, **-\-expression**, **-f**, or **-\-file**, then if this environment
variable exists and contains an integer, a non-zero value makes dc(1) exit
after executing the expressions and expression files, and a non-zero value
makes dc(1) not exit.
This environment variable overrides the default, which can be queried with
the **-h** or **-\-help** options.
# EXIT STATUS
dc(1) returns the following exit statuses:

38
src/vm.c

@ -186,9 +186,11 @@ void bc_vm_info(const char* const help) {
"disabled";
const char* const prompt = BC_DEFAULT_PROMPT ? "enabled" :
"disabled";
const char* const expr = BC_DEFAULT_EXPR_EXIT ? "to exit" :
"to not exit";
bc_file_printf(&vm.fout, help, vm.name, vm.name, BC_VERSION,
BC_BUILD_TYPE, banner, sigint, tty, prompt);
BC_BUILD_TYPE, banner, sigint, tty, prompt, expr);
}
#endif // BC_ENABLED
@ -201,9 +203,11 @@ void bc_vm_info(const char* const help) {
"disabled";
const char* const prompt = DC_DEFAULT_PROMPT ? "enabled" :
"disabled";
const char* const expr = DC_DEFAULT_EXPR_EXIT ? "to exit" :
"to not exit";
bc_file_printf(&vm.fout, help, vm.name, vm.name, BC_VERSION,
BC_BUILD_TYPE, sigint, tty, prompt);
BC_BUILD_TYPE, sigint, tty, prompt, expr);
}
#endif // DC_ENABLED
}
@ -1172,7 +1176,7 @@ static void bc_vm_exec(void) {
BC_SIG_UNLOCK;
// Sometimes, executing expressions means we need to quit.
if (!vm.no_exprs && vm.exit_exprs) return;
if (!vm.no_exprs && vm.exit_exprs && BC_EXPR_EXIT) return;
}
// Process files.
@ -1194,9 +1198,7 @@ static void bc_vm_exec(void) {
// We need to keep tty if history is enabled, and we need to keep rpath for
// the times when we read from /dev/urandom.
if (BC_TTY && !vm.history.badTerm) {
bc_pledge(bc_pledge_end_history, NULL);
}
if (BC_TTY && !vm.history.badTerm) bc_pledge(bc_pledge_end_history, NULL);
else
#endif // BC_ENABLE_HISTORY
{
@ -1233,6 +1235,8 @@ void bc_vm_boot(int argc, char *argv[]) {
bool tty;
const char* const env_len = BC_IS_BC ? "BC_LINE_LENGTH" : "DC_LINE_LENGTH";
const char* const env_args = BC_IS_BC ? "BC_ENV_ARGS" : "DC_ENV_ARGS";
const char* const env_exit = BC_IS_BC ? "BC_EXPR_EXIT" : "DC_EXPR_EXIT";
int env_exit_def = BC_IS_BC ? BC_DEFAULT_EXPR_EXIT : DC_DEFAULT_EXPR_EXIT;
// We need to know which of stdin, stdout, and stderr are tty's.
ttyin = isatty(STDIN_FILENO);
@ -1269,6 +1273,8 @@ void bc_vm_boot(int argc, char *argv[]) {
// Set the line length by environment variable.
vm.line_len = (uint16_t) bc_vm_envLen(env_len);
bc_vm_setenvFlag(env_exit, env_exit_def, BC_FLAG_EXPR_EXIT);
// Clear the files and expressions vectors, just in case. This marks them as
// *not* allocated.
bc_vec_clear(&vm.files);
@ -1289,26 +1295,22 @@ void bc_vm_boot(int argc, char *argv[]) {
bc_program_init(&vm.prog);
bc_parse_init(&vm.prs, &vm.prog, BC_PROG_MAIN);
// Set defaults.
vm.flags |= BC_TTY ? BC_FLAG_P | BC_FLAG_R : 0;
vm.flags |= BC_I ? BC_FLAG_Q : 0;
#if BC_ENABLED
// bc checks this environment variable to see if it should run in standard
// mode.
if (BC_IS_BC) {
// bc checks this environment variable to see if it should run in
// standard mode.
char* var = bc_vm_getenv("POSIXLY_CORRECT");
vm.flags |= BC_FLAG_S * (var != NULL);
bc_vm_getenvFree(var);
}
#endif // BC_ENABLED
// Set defaults.
vm.flags |= BC_TTY ? BC_FLAG_P | BC_FLAG_R : 0;
vm.flags |= BC_I ? BC_FLAG_Q : 0;
#if BC_ENABLED
if (BC_IS_BC && BC_I) {
// Set whether we print the banner or not.
bc_vm_setenvFlag("BC_BANNER", BC_DEFAULT_BANNER, BC_FLAG_Q);
if (BC_I) bc_vm_setenvFlag("BC_BANNER", BC_DEFAULT_BANNER, BC_FLAG_Q);
}
#endif // BC_ENABLED
@ -1349,9 +1351,7 @@ void bc_vm_boot(int argc, char *argv[]) {
#if BC_ENABLED
// Disable global stacks in POSIX mode.
if (BC_IS_POSIX) vm.flags &= ~(BC_FLAG_G);
#endif // BC_ENABLED
#if BC_ENABLED
// Print the banner if allowed. We have to be in bc, in interactive mode,
// and not be quieted by command-line option or environment variable.
if (BC_IS_BC && BC_I && (vm.flags & BC_FLAG_Q)) {

8
vs/bc.vcxproj

@ -102,7 +102,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BUILD_TYPE=HN;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BUILD_TYPE=HN;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ConformanceMode>true</ConformanceMode>
@ -123,7 +123,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BUILD_TYPE=HN;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BUILD_TYPE=HN;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ConformanceMode>true</ConformanceMode>
@ -144,7 +144,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BUILD_TYPE=HN;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BUILD_TYPE=HN;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ConformanceMode>true</ConformanceMode>
@ -164,7 +164,7 @@
<WarningLevel>Level3</WarningLevel>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BUILD_TYPE=HN;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;BUILD_TYPE=HN;BC_DEFAULT_BANNER=1;BC_DEFAULT_SIGINT_RESET=0;DC_DEFAULT_SIGINT_RESET=0;BC_DEFAULT_TTY_MODE=1;DC_DEFAULT_TTY_MODE=1;BC_DEFAULT_PROMPT=1;DC_DEFAULT_PROMPT=1;BC_DEFAULT_EXPR_EXIT=1;DC_DEFAULT_EXPR_EXIT=1;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>

Loading…
Cancel
Save