mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-30 08:59:56 +02:00
add math function calls to fltexpr; HISTFILESIZE documentation updates; help text updates for exxport, history; update translations
This commit is contained in:
+22
-1
@@ -1,4 +1,4 @@
|
||||
|
||||
\
|
||||
12/6/2020
|
||||
---------
|
||||
|
||||
@@ -11103,3 +11103,24 @@ lib/sh/gettimeofday.c
|
||||
- updated from version in gnulib
|
||||
|
||||
[bash-5.3-rc1 frozen]
|
||||
|
||||
4/4
|
||||
---
|
||||
examples/loadables/fltexpr.c
|
||||
- add support for function calls; support almost all math function
|
||||
calls in math.h
|
||||
- add support for pi, gamma, e mathematical constants
|
||||
|
||||
4/7
|
||||
---
|
||||
doc/bash.1,doc/bashref.texi
|
||||
- HISTFILESIZE: note that the history file will contain complete
|
||||
history entries whose lines may total slightly more than
|
||||
$HISTFILESIZE if the entries contain multiple lines
|
||||
From a report from Jens Schmidt <farblos@vodafonemail.de>
|
||||
- export: note that you can use -f with -p to display exported functions
|
||||
From a report from Duncan Roe <duncan_roe@optusnet.com.au>
|
||||
|
||||
builtins/history.def
|
||||
- add history -d start-end to the long doc
|
||||
From a report from Duncan Roe <duncan_roe@optusnet.com.au>
|
||||
|
||||
Vendored
+22
@@ -2240,3 +2240,25 @@ else
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([FNMATCH_EQUIV_FALLBACK], [$bash_cv_fnmatch_equiv_value], [Whether fnmatch can be used for bracket equivalence classes])
|
||||
])
|
||||
|
||||
AC_DEFUN([BASH_FUNC_STRCHRNUL],
|
||||
[
|
||||
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
|
||||
AC_CACHE_CHECK([whether strchrnul works],
|
||||
[bash_cv_func_strchrnul_works],
|
||||
[AC_RUN_IFELSE([AC_LANG_PROGRAM(
|
||||
[[
|
||||
#include <string.h>
|
||||
]],
|
||||
[[const char *buf = "abc";
|
||||
return strchrnul (buf, 'd') != buf + 3;
|
||||
]]
|
||||
)],
|
||||
[bash_cv_func_strchrnul_works=yes], [bash_cv_func_strchrnul_works=no],
|
||||
[bash_cv_func_strchrnul_works=no]
|
||||
)])
|
||||
|
||||
if test "$bash_cv_func_strchrnul_works" = "no"; then
|
||||
AC_LIBOBJ([strchrnul])
|
||||
fi
|
||||
])
|
||||
|
||||
@@ -33,6 +33,8 @@ Options:
|
||||
-c clear the history list by deleting all of the entries
|
||||
-d offset delete the history entry at position OFFSET. Negative
|
||||
offsets count back from the end of the history list
|
||||
-d start-end delete the history entries beginning at position START
|
||||
through position END.
|
||||
|
||||
-a append history lines from this session to the history file
|
||||
-n read all history lines not already read from the history file
|
||||
|
||||
@@ -50,7 +50,7 @@ extern sh_builtin_func_t *this_shell_builtin;
|
||||
|
||||
$BUILTIN export
|
||||
$FUNCTION export_builtin
|
||||
$SHORT_DOC export [-fn] [name[=value] ...] or export -p
|
||||
$SHORT_DOC export [-fn] [name[=value] ...] or export -p [-f]
|
||||
Set export attribute for shell variables.
|
||||
|
||||
Marks each NAME for automatic export to the environment of subsequently
|
||||
@@ -59,7 +59,7 @@ executed commands. If VALUE is supplied, assign VALUE before exporting.
|
||||
Options:
|
||||
-f refer to shell functions
|
||||
-n remove the export property from each NAME
|
||||
-p display a list of all exported variables and functions
|
||||
-p display a list of all exported variables or functions
|
||||
|
||||
An argument of `--' disables further option processing.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /bin/sh
|
||||
# From configure.ac for Bash 5.3, version 5.076.
|
||||
# From configure.ac for Bash 5.3, version 5.077.
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.72 for bash 5.3-rc1.
|
||||
#
|
||||
@@ -16174,21 +16174,6 @@ esac
|
||||
esac
|
||||
fi
|
||||
|
||||
ac_fn_c_check_func "$LINENO" "strchrnul" "ac_cv_func_strchrnul"
|
||||
if test "x$ac_cv_func_strchrnul" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_STRCHRNUL 1" >>confdefs.h
|
||||
|
||||
else case e in #(
|
||||
e) case " $LIBOBJS " in
|
||||
*" strchrnul.$ac_objext "* ) ;;
|
||||
*) LIBOBJS="$LIBOBJS strchrnul.$ac_objext"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup"
|
||||
if test "x$ac_cv_func_strdup" = xyes
|
||||
then :
|
||||
@@ -18997,6 +18982,62 @@ fi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether strchrnul works" >&5
|
||||
printf %s "checking whether strchrnul works... " >&6; }
|
||||
if test ${bash_cv_func_strchrnul_works+y}
|
||||
then :
|
||||
printf %s "(cached) " >&6
|
||||
else case e in #(
|
||||
e) if test "$cross_compiling" = yes
|
||||
then :
|
||||
bash_cv_func_strchrnul_works=no
|
||||
|
||||
else case e in #(
|
||||
e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
const char *buf = "abc";
|
||||
return strchrnul (buf, 'd') != buf + 3;
|
||||
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_run "$LINENO"
|
||||
then :
|
||||
bash_cv_func_strchrnul_works=yes
|
||||
else case e in #(
|
||||
e) bash_cv_func_strchrnul_works=no ;;
|
||||
esac
|
||||
fi
|
||||
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
|
||||
conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $bash_cv_func_strchrnul_works" >&5
|
||||
printf "%s\n" "$bash_cv_func_strchrnul_works" >&6; }
|
||||
|
||||
if test "$bash_cv_func_strchrnul_works" = "no"; then
|
||||
case " $LIBOBJS " in
|
||||
*" strchrnul.$ac_objext "* ) ;;
|
||||
*) LIBOBJS="$LIBOBJS strchrnul.$ac_objext"
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if dup2 fails to clear the close-on-exec flag" >&5
|
||||
printf %s "checking if dup2 fails to clear the close-on-exec flag... " >&6; }
|
||||
if test ${bash_cv_dup2_broken+y}
|
||||
|
||||
+3
-2
@@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure script.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
AC_REVISION([for Bash 5.3, version 5.076])dnl
|
||||
AC_REVISION([for Bash 5.3, version 5.077])dnl
|
||||
|
||||
define(bashvers, 5.3)
|
||||
define(relstatus, rc1)
|
||||
@@ -898,7 +898,6 @@ AC_REPLACE_FUNCS(getcwd memset)
|
||||
AC_REPLACE_FUNCS(strcasecmp strcasestr strerror strftime strnlen strpbrk strstr)
|
||||
AC_REPLACE_FUNCS(strtod strtol strtoul strtoll strtoull strtoumax)
|
||||
AC_REPLACE_FUNCS(dprintf)
|
||||
AC_REPLACE_FUNCS(strchrnul)
|
||||
AC_REPLACE_FUNCS(strdup)
|
||||
AC_REPLACE_FUNCS(strlcpy)
|
||||
AC_REPLACE_FUNCS(reallocarray)
|
||||
@@ -1049,6 +1048,8 @@ if test "$ac_cv_func_lstat" = "no"; then
|
||||
BASH_FUNC_LSTAT
|
||||
fi
|
||||
|
||||
BASH_FUNC_STRCHRNUL
|
||||
|
||||
dnl behavior of system calls and library functions
|
||||
BASH_FUNC_DUP2_CLOEXEC_CHECK
|
||||
BASH_SYS_PGRP_SYNC
|
||||
|
||||
+14
-6
@@ -5,7 +5,7 @@
|
||||
.\" Case Western Reserve University
|
||||
.\" chet.ramey@case.edu
|
||||
.\"
|
||||
.\" Last Change: Mon Feb 24 16:09:49 EST 2025
|
||||
.\" Last Change: Mon Apr 7 16:59:13 EDT 2025
|
||||
.\"
|
||||
.\" For bash_builtins, strip all but "SHELL BUILTIN COMMANDS" section
|
||||
.\" For rbash, strip all but "RESTRICTED SHELL" section
|
||||
@@ -21,7 +21,7 @@
|
||||
.ds zY \" empty
|
||||
.if \n(zZ=1 .ig zZ
|
||||
.if \n(zY=1 .ig zY
|
||||
.TH BASH 1 "2025 February 24" "GNU Bash 5.3"
|
||||
.TH BASH 1 "2025 April 7" "GNU Bash 5.3"
|
||||
.\"
|
||||
.ie \n(.g \{\
|
||||
.ds ' \(aq
|
||||
@@ -2617,8 +2617,13 @@ the shell does not save the command history when it exits.
|
||||
.B HISTFILESIZE
|
||||
The maximum number of lines contained in the history file.
|
||||
When this variable is assigned a value, the history file is truncated,
|
||||
if necessary, to contain no more than that number of lines
|
||||
if necessary, to contain no more than
|
||||
the number of history entries
|
||||
that total no more than that number of lines
|
||||
by removing the oldest entries.
|
||||
If the history list contains multi-line entries,
|
||||
the history file may contain more lines than this maximum
|
||||
to avoid leaving partial history entries.
|
||||
The history file is also truncated to this size after
|
||||
writing it when a shell exits or by the
|
||||
.B \%history
|
||||
@@ -10174,7 +10179,7 @@ is executed before the shell terminates.
|
||||
\fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIvalue\fP]] .\|.\|.
|
||||
.PD 0
|
||||
.TP
|
||||
.B export \-p
|
||||
.B export \-p [\fB\-f\fP\^]
|
||||
.PD
|
||||
The supplied
|
||||
.I names
|
||||
@@ -10191,10 +10196,13 @@ The
|
||||
option unexports, or removes the export attribute, from each \fIname\fP.
|
||||
If no
|
||||
.I names
|
||||
are given, or if the
|
||||
are given, or if only the
|
||||
.B \-p
|
||||
option is supplied, \fBexport\fP prints a list of names of all exported
|
||||
option is supplied,
|
||||
\fBexport\fP displays a list of names of all exported
|
||||
variables on the standard output.
|
||||
Using \fB\-p\fP and \fB\-f\fP together displays exported functions.
|
||||
The \fB\-p\fP option displays output in a form that may be reused as input.
|
||||
.IP
|
||||
\fBexport\fP allows the value of a variable to be set when it is exported
|
||||
or unexported by following the variable name with =\fIvalue\fP.
|
||||
|
||||
+11
-4
@@ -4370,9 +4370,11 @@ refer to shell functions; otherwise the names refer to shell variables.
|
||||
|
||||
The @option{-n} option means to unexport each name: no longer mark
|
||||
it for export.
|
||||
If no @var{name}s are supplied, or if the @option{-p} option is given,
|
||||
@code{export} displays a list of names of all exported variables on the
|
||||
standard output.
|
||||
If no @var{name}s are supplied, or if only
|
||||
the @option{-p} option is given,
|
||||
@code{export} displays a list of names of all exported
|
||||
variables on the standard output.
|
||||
Using @option{-p} and @option{-f} together displays exported functions.
|
||||
The @option{-p} option displays output in a form that may be reused as input.
|
||||
|
||||
@code{export} allows the value of a variable to be set at the same time
|
||||
@@ -7301,8 +7303,13 @@ the shell does not save the command history when it exits.
|
||||
@item HISTFILESIZE
|
||||
The maximum number of lines contained in the history file.
|
||||
When this variable is assigned a value, the history file is truncated,
|
||||
if necessary, to contain no more than that number of lines
|
||||
if necessary, to contain no more than
|
||||
the number of history entries
|
||||
that total no more than that number of lines
|
||||
by removing the oldest entries.
|
||||
If the history list contains multi-line entries,
|
||||
the history file may contain more lines than this maximum
|
||||
to avoid leaving partial history entries.
|
||||
The history file is also truncated to this size after
|
||||
writing it when a shell exits or by the @code{history} builtin.
|
||||
If the value is 0, the history file is truncated to zero size.
|
||||
|
||||
+3
-3
@@ -2,10 +2,10 @@
|
||||
Copyright (C) 1988-2025 Free Software Foundation, Inc.
|
||||
@end ignore
|
||||
|
||||
@set LASTCHANGE Mon Feb 24 16:09:32 EST 2025
|
||||
@set LASTCHANGE Mon Apr 7 16:58:51 EDT 2025
|
||||
|
||||
@set EDITION 5.3
|
||||
@set VERSION 5.3
|
||||
|
||||
@set UPDATED 24 February 2025
|
||||
@set UPDATED-MONTH February 2025
|
||||
@set UPDATED 7 April 2025
|
||||
@set UPDATED-MONTH April 2025
|
||||
|
||||
@@ -103,8 +103,8 @@ INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins -I${srcdir} \
|
||||
ALLPROG = print truefalse sleep finfo logname basename dirname fdflags \
|
||||
tty pathchk tee head mkdir rmdir mkfifo mktemp printenv id whoami \
|
||||
uname sync push ln unlink realpath strftime mypid setpgid seq rm \
|
||||
accept csv dsv cut stat getconf kv strptime chmod
|
||||
OTHERPROG = necho hello cat pushd asort fltexpr
|
||||
accept csv dsv cut stat getconf kv strptime chmod fltexpr
|
||||
OTHERPROG = necho hello cat pushd asort
|
||||
|
||||
SUBDIRS = perl
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ typedef double sh_float_t;
|
||||
#define PREDEC 15 /* --var */
|
||||
#define POSTINC 16 /* var++ */
|
||||
#define POSTDEC 17 /* var-- */
|
||||
#define FUNC 18 /* function call */
|
||||
#define EQ '='
|
||||
#define GT '>'
|
||||
#define LT '<'
|
||||
@@ -148,6 +149,10 @@ typedef double sh_float_t;
|
||||
#define SHFLOAT_LENGTH_MODIFIER 'l';
|
||||
#define SHFLOAT_STRTOD strtod
|
||||
|
||||
#ifndef M_EGAMMA
|
||||
#define M_EGAMMA 0.57721566490153286060651209008240243
|
||||
#endif
|
||||
|
||||
struct lvalue
|
||||
{
|
||||
char *tokstr; /* possibly-rewritten lvalue if not NULL */
|
||||
@@ -184,6 +189,133 @@ static int already_expanded;
|
||||
static struct lvalue curlval = {0, 0, 0, -1};
|
||||
static struct lvalue lastlval = {0, 0, 0, -1};
|
||||
|
||||
/* Function equivalents for POSIX math.h macros. */
|
||||
static int xfpclassify(sh_float_t d) { return fpclassify(d); }
|
||||
static int xisinf(sh_float_t d) { return isinf(d); }
|
||||
static int xisnan(sh_float_t d) { return isnan(d); }
|
||||
static int xisnormal(sh_float_t d) { return isnormal(d); }
|
||||
static int xisfinite(sh_float_t d) { return isfinite(d); }
|
||||
static int xsignbit(sh_float_t d) { return signbit(d); }
|
||||
|
||||
static int xisgreater(sh_float_t d1, sh_float_t d2) { return isgreater(d1, d2); }
|
||||
static int xisgreaterequal(sh_float_t d1, sh_float_t d2) { return isgreaterequal(d1, d2); }
|
||||
static int xisless(sh_float_t d1, sh_float_t d2) { return isless(d1, d2); }
|
||||
static int xislessequal(sh_float_t d1, sh_float_t d2) { return islessequal(d1, d2); }
|
||||
static int xislessgreater(sh_float_t d1, sh_float_t d2) { return islessgreater(d1, d2); }
|
||||
static int xisunordered(sh_float_t d1, sh_float_t d2) { return isunordered(d1, d2); }
|
||||
|
||||
static int xisinfinite(sh_float_t d) { return (fpclassify(d) == FP_INFINITE); }
|
||||
static int xissubnormal(sh_float_t d) { return (fpclassify(d) == FP_SUBNORMAL); }
|
||||
static int xiszero(sh_float_t d) { return (fpclassify(d) == FP_ZERO); }
|
||||
|
||||
/* Function replacements for some math functions that don't conform to the
|
||||
supported prototypes. */
|
||||
static sh_float_t xscalbn(sh_float_t d1, sh_float_t d2) { int x = d2; return (scalbn (d1, x)); }
|
||||
static sh_float_t xjn(sh_float_t d1, sh_float_t d2) { int x = d1; return (jn (x, d2)); }
|
||||
static sh_float_t xyn(sh_float_t d1, sh_float_t d2) { int x = d1; return (yn (x, d2)); }
|
||||
static sh_float_t xldexp(sh_float_t d1, sh_float_t d2) { int x = d2; return (ldexp (d1, x)); }
|
||||
|
||||
typedef int imathfunc1(sh_float_t);
|
||||
typedef int imathfunc2(sh_float_t, sh_float_t);
|
||||
typedef sh_float_t mathfunc1(sh_float_t);
|
||||
typedef sh_float_t mathfunc2(sh_float_t, sh_float_t);
|
||||
typedef sh_float_t mathfunc3(sh_float_t, sh_float_t, sh_float_t);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
int nargs; /* > 0, function returns double; < 0, function returns int */
|
||||
union
|
||||
{
|
||||
mathfunc1 *func1;
|
||||
mathfunc2 *func2;
|
||||
mathfunc3 *func3;
|
||||
imathfunc1 *ifunc1;
|
||||
imathfunc2 *ifunc2;
|
||||
} f;
|
||||
} FLTEXPR_MATHFUN;
|
||||
|
||||
/* Not implemented yet: functions that don't fit one of the supported
|
||||
calling prototypes, with a couple of exceptions */
|
||||
FLTEXPR_MATHFUN mathfuncs[] =
|
||||
{
|
||||
{ "abs", 1, { .func1 = fabs } },
|
||||
{ "acos", 1, { .func1 = acos } },
|
||||
{ "acosh", 1, { .func1 = acosh } },
|
||||
{ "asin", 1, { .func1 = asin } },
|
||||
{ "asinh", 1, { .func1 = asinh } },
|
||||
{ "atan", 1, { .func1 = atan } },
|
||||
{ "atanh", 1, { .func1 = atanh } },
|
||||
{ "cbrt", 1, { .func1 = cbrt } },
|
||||
{ "ceil", 1, { .func1 = ceil } },
|
||||
{ "cos", 1, { .func1 = cos } },
|
||||
{ "cosh", 1, { .func1 = cosh } },
|
||||
{ "erf", 1, { .func1 = erf } },
|
||||
{ "erfc", 1, { .func1 = erfc } },
|
||||
{ "exp", 1, { .func1 = exp } },
|
||||
{ "exp2", 1, { .func1 = exp2 } },
|
||||
{ "expm1", 1, { .func1 = expm1 } },
|
||||
{ "fabs", 1, { .func1 = fabs } },
|
||||
{ "floor", 1, { .func1 = floor } },
|
||||
{ "j0", 1, { .func1 = j0 } },
|
||||
{ "j1", 1, { .func1 = j1 } },
|
||||
{ "lgamma", 1, { .func1 = lgamma } },
|
||||
{ "log", 1, { .func1 = log } },
|
||||
{ "log10", 1, { .func1 = log10 } },
|
||||
{ "log1p", 1, { .func1 = log1p } },
|
||||
{ "log2", 1, { .func1 = log2 } },
|
||||
{ "logb", 1, { .func1 = logb } },
|
||||
{ "nearbyint",1, { .func1 = nearbyint } },
|
||||
{ "rint", 1, { .func1 = rint } },
|
||||
{ "round", 1, { .func1 = round } },
|
||||
{ "sin", 1, { .func1 = sin } },
|
||||
{ "sinh", 1, { .func1 = sinh } },
|
||||
{ "sqrt", 1, { .func1 = sqrt } },
|
||||
{ "tan", 1, { .func1 = tan } },
|
||||
{ "tanh", 1, { .func1 = tanh } },
|
||||
{ "tgamma", 1, { .func1 = tgamma } },
|
||||
{ "trunc", 1, { .func1 = trunc } },
|
||||
{ "y0", 1, { .func1 = y0 } },
|
||||
{ "y1", 1, { .func1 = y1 } },
|
||||
|
||||
{ "atan2", 2, { .func2 = atan2 } },
|
||||
{ "copysign", 2, { .func2 = copysign } },
|
||||
{ "fdim", 2, { .func2 = fdim } },
|
||||
{ "fmax", 2, { .func2 = fmax } },
|
||||
{ "fmin", 2, { .func2 = fmin } },
|
||||
{ "fmod", 2, { .func2 = fmod } },
|
||||
{ "hypot", 2, { .func2 = hypot } },
|
||||
{ "nextafter",2, { .func2 = nextafter } },
|
||||
{ "pow", 2, { .func2 = pow } },
|
||||
{ "remainder",2, { .func2 = remainder } },
|
||||
{ "ldexp", 2, { .func2 = xldexp } },
|
||||
{ "jn", 2, { .func2 = xjn } },
|
||||
{ "scalbn", 2, { .func2 = xscalbn } },
|
||||
{ "yn", 2, { .func2 = xyn } },
|
||||
|
||||
{ "fma", 3, { .func3 = fma } },
|
||||
|
||||
{ "fpclassify",-1, { .ifunc1 = xfpclassify } },
|
||||
{ "isfinite", -1, { .ifunc1 = xisfinite } },
|
||||
{ "isinf", -1, { .ifunc1 = xisinf } },
|
||||
{ "isinfinite",-1, { .ifunc1 = xisinfinite } },
|
||||
{ "isnan", -1, { .ifunc1 = xisnan } },
|
||||
{ "isnormal", -1, { .ifunc1 = xisnormal } },
|
||||
{ "issubnormal",-1, { .ifunc1 = xissubnormal } },
|
||||
{ "iszero", -1, { .ifunc1 = xiszero } },
|
||||
{ "ilogb", -1, { .ifunc1 = ilogb } },
|
||||
{ "signbit", -1, { .ifunc1 = xsignbit } },
|
||||
|
||||
{ "isgreater",-2, { .ifunc2 = xisgreater } },
|
||||
{ "isgreaterequal",-2,{ .ifunc2 = xisgreaterequal } },
|
||||
{ "isless", -2, { .ifunc2 = xisless } },
|
||||
{ "islessequal", -2, { .ifunc2 = xislessequal } },
|
||||
{ "islessgreater",-2, { .ifunc2 = xislessgreater } },
|
||||
{ "isunordered",-2, { .ifunc2 = xisunordered } },
|
||||
|
||||
{ NULL, 0, NULL }
|
||||
};
|
||||
|
||||
static sh_float_t nanval, infval;
|
||||
|
||||
static int is_arithop (int);
|
||||
@@ -194,10 +326,15 @@ static void init_lvalue (struct lvalue *);
|
||||
static struct lvalue *alloc_lvalue (void);
|
||||
static void free_lvalue (struct lvalue *);
|
||||
|
||||
static sh_float_t fltexpr_streval (char *, int, struct lvalue *);
|
||||
static sh_float_t fltexpr_streval (char *, int, struct lvalue *);
|
||||
|
||||
static int fltexpr_findfunc (char *);
|
||||
static sh_float_t fltexpr_funeval (char *, struct lvalue *);
|
||||
static sh_float_t expfunc (int);
|
||||
|
||||
static void evalerror (const char *);
|
||||
|
||||
static sh_float_t fltexpr_strtod (const char *, char **);
|
||||
static sh_float_t fltexpr_strtod (const char *, char **);
|
||||
static char *fltexpr_format (sh_float_t);
|
||||
|
||||
#if defined (ARRAYS)
|
||||
@@ -368,7 +505,7 @@ fltexpr_format (sh_float_t val)
|
||||
*p++ = '.';
|
||||
*p++ = '*';
|
||||
*p++ = SHFLOAT_LENGTH_MODIFIER;
|
||||
*p++ = 'g'; /* XXX */
|
||||
*p++ = 'g';
|
||||
*p = '\0';
|
||||
|
||||
retsize = sizeof (ret);
|
||||
@@ -1019,12 +1156,74 @@ exp0 (void)
|
||||
|
||||
readtok ();
|
||||
}
|
||||
else if (curtok == FUNC)
|
||||
{
|
||||
val = expfunc (tokval);
|
||||
lasttok = FUNC;
|
||||
curtok = NUM;
|
||||
|
||||
readtok (); /* skip over closing right paren, expfunc checks syntax */
|
||||
}
|
||||
else
|
||||
evalerror (_("arithmetic syntax error: operand expected"));
|
||||
|
||||
return (val);
|
||||
}
|
||||
|
||||
/* Evaluate a math function call with some minimal error checking. */
|
||||
static sh_float_t
|
||||
expfunc (int ind)
|
||||
{
|
||||
FLTEXPR_MATHFUN func;
|
||||
sh_float_t arg1, arg2, arg3, val;
|
||||
int nargs, ival;
|
||||
|
||||
func = mathfuncs[ind];
|
||||
/* If func.nargs > 0, the function returns double and takes func.nargs arguments;
|
||||
if func.nargs < 0, the function returns int and takes -func.nargs arguments. */
|
||||
nargs = (func.nargs > 0) ? func.nargs : -func.nargs;
|
||||
|
||||
readtok();
|
||||
if (curtok != LPAR)
|
||||
evalerror (_("function call: expected left paren"));
|
||||
|
||||
readtok ();
|
||||
arg1 = expassign ();
|
||||
if (nargs > 1)
|
||||
{
|
||||
if (curtok != COMMA)
|
||||
evalerror (_("function call: expected comma"));
|
||||
readtok (); /* consume the comma */
|
||||
arg2 = expassign ();
|
||||
}
|
||||
if (nargs > 2)
|
||||
{
|
||||
if (curtok != COMMA)
|
||||
evalerror (_("function call: expected comma"));
|
||||
readtok (); /* consume the comma */
|
||||
arg3 = expassign ();
|
||||
}
|
||||
|
||||
if (curtok != RPAR)
|
||||
evalerror (_("function call: expected right paren"));
|
||||
|
||||
switch (func.nargs)
|
||||
{
|
||||
case 1:
|
||||
val = (*func.f.func1) (arg1); break;
|
||||
case 2:
|
||||
val = (*func.f.func2) (arg1, arg2); break;
|
||||
case 3:
|
||||
val = (*func.f.func3) (arg1, arg2, arg3); break;
|
||||
case -1:
|
||||
ival = (*func.f.ifunc1) (arg1); val = ival; break;
|
||||
case -2:
|
||||
ival = (*func.f.ifunc2) (arg1, arg2); val = ival; break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void
|
||||
init_lvalue (struct lvalue *lv)
|
||||
{
|
||||
@@ -1050,6 +1249,17 @@ free_lvalue (struct lvalue *lv)
|
||||
free (lv); /* should be inlined */
|
||||
}
|
||||
|
||||
static int
|
||||
fltexpr_findfunc (char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; mathfuncs[i].name; i++)
|
||||
if (STREQ (name, mathfuncs[i].name))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static sh_float_t
|
||||
fltexpr_streval (char *tok, int e, struct lvalue *lvalue)
|
||||
{
|
||||
@@ -1263,12 +1473,33 @@ readtok (void)
|
||||
lasttok = curtok;
|
||||
curtok = NUM;
|
||||
}
|
||||
else if (strncasecmp (tp, "PI", 2) == 0 && (isalnum (tp[2]) == 0))
|
||||
{
|
||||
cp = tp + 2;
|
||||
tokval = M_PI;
|
||||
lasttok = curtok;
|
||||
curtok = NUM;
|
||||
}
|
||||
else if (strncasecmp (tp, "GAMMA", 2) == 0 && (isalnum (tp[5]) == 0))
|
||||
{
|
||||
cp = tp + 5;
|
||||
tokval = M_EGAMMA;
|
||||
lasttok = curtok;
|
||||
curtok = NUM;
|
||||
}
|
||||
else if ((tp[0] == 'E' || tp[0] == 'e') && (isalnum (tp[1]) == 0))
|
||||
{
|
||||
cp = tp + 1;
|
||||
tokval = M_E;
|
||||
lasttok = curtok;
|
||||
curtok = NUM;
|
||||
}
|
||||
else if (legal_variable_starter (c))
|
||||
{
|
||||
/* variable names not preceded with a dollar sign are shell variables. */
|
||||
char *savecp;
|
||||
FLTEXPR_CONTEXT ec;
|
||||
int peektok;
|
||||
int peektok, ind;
|
||||
|
||||
while (legal_variable_char (c))
|
||||
c = *cp++;
|
||||
@@ -1312,6 +1543,18 @@ readtok (void)
|
||||
RESTORETOK (&ec);
|
||||
cp = savecp;
|
||||
|
||||
ind = -1;
|
||||
if ((ind = fltexpr_findfunc (tokstr)) != -1 && peektok == LPAR)
|
||||
{
|
||||
lasttok = curtok;
|
||||
curtok = FUNC;
|
||||
tokval = ind; /* overload this here for expfunc */
|
||||
tp = cp;
|
||||
return; /* XXX */
|
||||
}
|
||||
else if (ind == -1 && peektok == LPAR)
|
||||
evalerror (_("unrecognized function name"));
|
||||
|
||||
/* The tests for PREINC and PREDEC aren't strictly correct, but they
|
||||
preserve old behavior if a construct like --x=9 is given. */
|
||||
if (lasttok == PREINC || lasttok == PREDEC || peektok != EQ)
|
||||
|
||||
+252
-244
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+307
-342
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+304
-341
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+840
-1486
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+306
-514
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+242
-231
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user