.\"
.\" Copyright (C) 1999-2007,2014,2018	Landon Curt Noll
.\"
.\" Calc is open software; you can redistribute it and/or modify it under
.\" the terms of the version 2 of the GNU General Public License
.\" as published by the Free Software Foundation.
.\"
.\" Calc is distributed in the hope that it will be useful, but WITHOUT
.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
.\" or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
.\" Public License for more details.
.\"
.\" A copy of version 2 of the GNU General Public License is
.\" distributed with calc under the filename COPYING-GPL.  You should have
.\" received a copy with calc; if not, write to Free Software Foundation, Inc.
.\" 51 Franklin Street, Fifth Floor, Boston, MA	 02110-1301, USA.
.\"
.\" Under source code control:	    1991/07/23 05:48:26
.\" File existed as early as:	    1991
.\"
.\" chongo <was here> /\oo/\	http://www.isthe.com/chongo/
.\" Share and enjoy!  :-)	http://www.isthe.com/chongo/tech/comp/calc/
.\"
.\" calculator by David I. Bell
.\" man page by Landon Noll
.\"
.TH calc 1 "^..^" "2007-02-06"
.SH NAME
calc \- arbitrary precision calculator
.SH SYNOPSIS
\fIcalc\fP
.RB [ \-c ]
.RB [ \-C ]
.RB [ \-d ]
.br
.in +5n
.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ]
.br
.RB [ \-e ]
.RB [ \-h ]
.RB [ \-i ]
.RB [ \-m\ \&mode ]
.RB [ \-O ]
.br
.RB [ \-p ]
.RB [ \-q ]
.RB [ \-s ]
.RB [ \-u ]
.RB [ \-v ]
.RB [ [\-\-]\ calc_cmd\ \&.\|.\|. ]
.in -5n
.sp
\fI#!/usr/bin/calc\fP\ [other_flags\ \&...] \fB\-f\fP
.SH DESCRIPTION
\&
.br
CALC OPTIONS
.PP

.TP
.B \-c
Continue reading command lines even after a scan/parse
error has caused the abandonment of a line.
Note that this option only deals with scanning and
parsing of the calc language.
It does not deal with execution or run-time errors.
.sp 1
For example:
.sp 1
.in +5n
.nf
calc read many_errors.cal
.fi
.in -5n
.sp 1
will cause
.B calc
to abort on the first syntax error, whereas:
.sp 1
.in +5n
.nf
calc -c read many_errors.cal
.fi
.in -5n
.sp 1
will
cause
.B calc
to try to process each line being read
despite the scan/parse errors that it encounters.
.sp 1
By default, calc startup resource files are silently
ignored if not found.
This flag will report missing
startup resource files unless
.B \-d
is also given.

.TP
.B \-C
Permit the execution of custom builtin functions.
Without
this flag, calling the custom() builtin function will
simply generate an error.
.sp 1
Use of this flag may cause
.B calc
to execute functions
that are non-standard and that are not portable.  Custom builtin
functions are disabled by default for this reason.

.TP
.B \-d
Disable the printing of the opening title.  The printing
of resource file debug and informational messages is also disabled
as if \fBconfig("resource_debug", 0)\fP had been executed.
.sp 1
For example:
.sp 1
.in +5n
calc "read qtime; qtime(2)"
.in -5n
.sp 1
will output something like:
.sp 1
.in +5n
.nf
qtime(utc_hr_offset) defined
It's nearly ten past six.
.fi
.in -5n
.sp 1
whereas:
.sp 1
.in +5n
.nf
calc -d "read qtime; qtime(2)"
.fi
.in -5n
.sp 1
will just print:
.sp 1
.in +5n
.nf
It's nearly ten past six.
.fi
.in -5n
.sp 1
This flag disables the reporting of missing calc
startup resource files.
.sp 1

This flag also disables the printing the leading tilde. For example:
.sp 1
.in +5n
.nf
calc 2/3
.fi
.in -5n
.sp 1
will print:
.sp 1
.in +5n
.nf
~0.66666666666666666667
.fi
.in -5n
.sp 1
.sp 1
whereas:
.sp 1
.in +5n
.nf
calc -d 2/3
.fi
.in -5n
.sp 1
will just print:
.sp 1
.in +5n
.nf
0.66666666666666666667
.fi
.in -5n
.sp 1

.TP
.BR -D " calc_debug[:resource_debug[:user_debug]]"
Force the initial value of config("calc_debug"),
config("resource_debug") and config("user_debug").
.sp 1
The : separated strings are interpreted as signed 32 bit integers.
After an optional leading sign a leading zero indicates octal
conversion, and a leading ``0x'' or ``0X'' hexadecimal
conversion.  Otherwise, decimal conversion is assumed.
.sp 1
By default,
.I calc_debug
is 0,
.I resource_debug
is 3 and
.I user_debug
is 0.
.sp 1
For more information use the following
.B calc
command:
.sp 1
.in +5n
.nf
help config
.fi
.in -5n

.TP
.B \-e
Ignore any environment variables on startup.
The getenv() builtin will still return values, however.

.TP
.B \-f
This flag is required when using calc in
.BR "shell script mode" .
It must be at the end of the initial
.B #!
line of the script.
.sp 1
This flag is normally only at the end of a calc shell script.
If the first line of an executable file begins
.B #!
followed by the absolute pathname of the
.B calc
program and the flag
.B \-f
as in:
.sp 1
.in +5n
.nf
\fI#!/usr/bin/calc\fP\ [other_flags\ \&...] \fB\-f\fP
.fi
.in -5n
.sp 1
the rest of the file will be processed in
.BR "shell script mode" .
See
.B "SHELL SCRIPT MODE"
section of this man page
below for details.
.sp 1
The actual form of this flag is:
.sp 1
.in +5n
.B \-f
filename
.in -5n
.sp 1
On systems that treat an executable that begins with
.B #!
as a script, the path of the executable is appended by the kernel
as the final argument to the exec() system call.
This is why the
.B \-f
flag at the very end of the
.B #!
line.
.sp 1
It is possible use
.B \-f\ filename
on the command line:
.sp 1
.in +5n
.nf
\fIcalc\fP\ [other_flags\ \&...] \fB\-f\fP filename
.fi
.in -5n
.sp 1
This will cause calc to process lines in
.B filename
in
.BR "shell script mode" .
.sp 1
Use of
.B \-f
implies
.BR \-s .
In addition,
.B \-d
and
.B \-p
are implied if
.B \-i
is not given.

.TP
.B \-h
Print a help message.  This option implies
.BR \-q .
This
is equivalent to the
.B calc
command help help.
The help facility is disabled unless the mode is 5 or 7.
See
.BR \-m .

.TP
.B \-i
Become interactive if possible.
This flag will cause
.B calc
to drop into interactive mode after the
.I calc_cmd
arguments on the command line are evaluated.
Without this flag,
.B calc
will exit after they are evaluated.
.sp 1
For example:
.sp 1
.in +5n
.nf
calc 2+5
.fi
.in -5n
.sp 1
will print the value 7 and exit whereas:
.sp 1
.in +5n
.nf
calc -i 2+5
.fi
.in -5n
.sp 1
will print the value 7 and prompt the user for more
.B calc
commands.

.TP
.BR \-m " mode"
This flag sets the permission mode of
.BR calc .
It controls the ability for
.B calc
to open files and execute programs.
.I Mode
may be a number from 0 to 7.
.sp 1
The mode value is interpreted in a way similar to that
of the
.BR chmod (1)
octal mode:
.sp 1
.in +5n
.nf
0  do not open any file, do not execute progs
1  do not open any file
2  do not open files for reading, do not execute progs
3  do not open files for reading
4  do not open files for writing, do not execute progs
5  do not open files for writing
6  do not execute any program
7  allow everything (default mode)
.fi
.in -5n
.sp 1
If one wished to run
.B calc
from a privileged user, one might want to use
.BR \-m " 0"
in an effort to make
.B calc
somewhat more secure.
.sp 1
Mode bits for reading and writing apply only on an
open.
Files already open are not effected.
Thus if one wanted to use the
.BR \-m " 0"
in an effort to make
.B calc
somewhat more secure, but still wanted to read and write a specific
file, one might want to do in
.BR sh (1),
.BR ksh (1),
.BR bash (1)-like
shells:
.sp 1
.in +5n
.nf
calc -m 0 3<a.file
.fi
.in -5n
.sp 1
Files presented to
.B calc
in this way are opened in an
unknown mode.
.B Calc
will attempt to read or write them if directed.
.sp 1
If the mode disables opening of files for reading, then
the startup resource files are disabled as if
.B \-q
was given.
The reading of key bindings is also disabled
when the mode disables opening of files for reading.

.TP
.B \-O
Use the old classic defaults instead of the
default configuration.
This flag as the same effect
as executing \fBconfig("all", "oldcfg")\fP at startup time.
.sp 1
NOTE: Older versions of calc used
.B \-n
to setup a modified form of the default calc configuration.
The
.B \-n
flag currently does nothing.
Use of the
.B \-n
flag is now deprecated and may be used for
something else in the future.

.TP
.B \-p
Pipe processing is enabled by use of
.BR \-p .
For example:
.sp 1
.in +5n
.nf
calc -p "2^21701-1" | fizzbin
.fi
.in -5n
.sp 1
In pipe mode,
