mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-17 14:59:20 +02:00
Compare commits
93 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e33bf4e80a | ||
|
|
b3af44d212 | ||
|
|
1e753d5209 | ||
|
|
4bf31005ea | ||
|
|
7c86bc910a | ||
|
|
4f146a99a9 | ||
|
|
a6a638e0e6 | ||
|
|
325814f5e1 | ||
|
|
5c4ea7d09e | ||
|
|
2bf73987ac | ||
|
|
3e9eeea8dc | ||
|
|
d164d72c1c | ||
|
|
632cee62d9 | ||
|
|
7a40260f0d | ||
|
|
09f043b3de | ||
|
|
c0341c8ba3 | ||
|
|
850c717803 | ||
|
|
f13f9e18bd | ||
|
|
8bdca0d684 | ||
|
|
129bf5612e | ||
|
|
829962fae1 | ||
|
|
c5f9ed8541 | ||
|
|
4a7cef4644 | ||
|
|
0e010b56ec | ||
|
|
ee179ee2f5 | ||
|
|
e28712cef3 | ||
|
|
8f0a2a7e79 | ||
|
|
ef23bba77f | ||
|
|
602086ae2d | ||
|
|
f5a170acbd | ||
|
|
8125b96f0b | ||
|
|
0bb7d89bb9 | ||
|
|
eb109bbbc0 | ||
|
|
1a0809fd31 | ||
|
|
09625b9d68 | ||
|
|
4e164c4268 | ||
|
|
691185f22c | ||
|
|
a8bfb41a9e | ||
|
|
fafb30db05 | ||
|
|
243e816523 | ||
|
|
b49c0f52bd | ||
|
|
07fca94a7f | ||
|
|
73917ee537 | ||
|
|
76f9edecf6 | ||
|
|
d77d9854d2 | ||
|
|
c2b53f95a4 | ||
|
|
caef8b80d6 | ||
|
|
5e016768af | ||
|
|
ee08ce98d7 | ||
|
|
581bd95838 | ||
|
|
bb92dab1ab | ||
|
|
83b5c52c76 | ||
|
|
93eca25141 | ||
|
|
34421cb10e | ||
|
|
29b87898aa | ||
|
|
e9e4db94bd | ||
|
|
c95ad0261a | ||
|
|
7fef456483 | ||
|
|
386131e74d | ||
|
|
824d3c88f1 | ||
|
|
18a206abd2 | ||
|
|
8dbae776c9 | ||
|
|
b78702cc53 | ||
|
|
d2b43605ad | ||
|
|
7728e09337 | ||
|
|
2666353ce6 | ||
|
|
0b8a306483 | ||
|
|
b51a0b2d08 | ||
|
|
959355b19c | ||
|
|
9c3f0f1994 | ||
|
|
dac337a65b | ||
|
|
98739dfdbc | ||
|
|
17b7a1ea84 | ||
|
|
4d45925758 | ||
|
|
8cadb23f48 | ||
|
|
63211b65c2 | ||
|
|
1be84525b1 | ||
|
|
67ae95a464 | ||
|
|
c03a95ad94 | ||
|
|
51aa7aecb9 | ||
|
|
592cfe5a20 | ||
|
|
b4cf15e73e | ||
|
|
862e143372 | ||
|
|
1f10ca49ad | ||
|
|
4a0c4ffdca | ||
|
|
27c8737f3a | ||
|
|
ecf45fc453 | ||
|
|
0a1178cfd7 | ||
|
|
20a35dc627 | ||
|
|
79887c06f0 | ||
|
|
f7ff424904 | ||
|
|
6678721fe3 | ||
|
|
496302097b |
@@ -1,3 +1,8 @@
|
|||||||
|
workflow:
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH =~ /wip/
|
||||||
|
when: never
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
image: 'debian:stable-slim'
|
image: 'debian:stable-slim'
|
||||||
before_script:
|
before_script:
|
||||||
|
|||||||
28
build.tk
28
build.tk
@@ -15,6 +15,8 @@
|
|||||||
# the next line restarts using wish \
|
# the next line restarts using wish \
|
||||||
exec wish "$0" "$@"
|
exec wish "$0" "$@"
|
||||||
|
|
||||||
|
global RemindExecutable
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
# %PROCEDURE: SetConfigDefaults
|
# %PROCEDURE: SetConfigDefaults
|
||||||
# %ARGUMENTS:
|
# %ARGUMENTS:
|
||||||
@@ -40,7 +42,7 @@ proc SetConfigDefaults {} {
|
|||||||
set Config(WESTERN_HEMISPHERE) 1
|
set Config(WESTERN_HEMISPHERE) 1
|
||||||
set Config(LANGUAGE) "English"
|
set Config(LANGUAGE) "English"
|
||||||
set Config(INST_DIR) "/usr/local/bin"
|
set Config(INST_DIR) "/usr/local/bin"
|
||||||
set Config(MAN_DIR) "/usr/local/man"
|
set Config(MAN_DIR) "/usr/local/share/man"
|
||||||
}
|
}
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
@@ -124,7 +126,7 @@ proc CreateMainDialog {} {
|
|||||||
# Creates the "installation directories" dialog.
|
# Creates the "installation directories" dialog.
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
proc CreateInstallDirDialog { w } {
|
proc CreateInstallDirDialog { w } {
|
||||||
global Config
|
global Config RemindExecutable
|
||||||
label $w.binlabel -text "Location for programs: "
|
label $w.binlabel -text "Location for programs: "
|
||||||
entry $w.bin -width 30
|
entry $w.bin -width 30
|
||||||
$w.bin insert end $Config(INST_DIR)
|
$w.bin insert end $Config(INST_DIR)
|
||||||
@@ -133,16 +135,19 @@ proc CreateInstallDirDialog { w } {
|
|||||||
entry $w.man -width 30
|
entry $w.man -width 30
|
||||||
$w.man insert end $Config(MAN_DIR)
|
$w.man insert end $Config(MAN_DIR)
|
||||||
|
|
||||||
text $w.blurb -width 1 -height 5 -wrap word -relief flat -takefocus 0
|
text $w.blurb -width 1 -height 20 -wrap word -relief flat -takefocus 0
|
||||||
$w.blurb insert end "\n(Tabbed-notebook Tcl code taken from \"Effective Tcl/Tk Programming\" by Mark Harrison and Michael McLennan, Addison-Wesley Professional Computing Series.)"
|
if { "$RemindExecutable" != "" } {
|
||||||
$w.blurb configure -state disabled
|
$w.blurb insert end "Note: Default settings were obtained by querying the existing installed version of Remind found at: $RemindExecutable\n"
|
||||||
# Disable all text-window behaviour
|
}
|
||||||
bindtags $w.blurb {NoSuchTag}
|
$w.blurb insert end "\n(Tabbed-notebook Tcl code taken from \"Effective Tcl/Tk Programming\" by Mark Harrison and Michael McLennan, Addison-Wesley Professional Computing Series.)\n"
|
||||||
grid $w.binlabel -row 0 -column 0 -sticky e
|
grid $w.binlabel -row 0 -column 0 -sticky e
|
||||||
grid $w.bin -row 0 -column 1 -sticky nsew
|
grid $w.bin -row 0 -column 1 -sticky nsew
|
||||||
grid $w.manlabel -row 1 -column 0 -sticky e
|
grid $w.manlabel -row 1 -column 0 -sticky e
|
||||||
grid $w.man -row 1 -column 1 -sticky nsew
|
grid $w.man -row 1 -column 1 -sticky nsew
|
||||||
grid $w.blurb - -sticky nsew
|
grid $w.blurb - -sticky nsew
|
||||||
|
# Disable all text-window behaviour
|
||||||
|
bindtags $w.blurb {NoSuchTag}
|
||||||
|
$w.blurb configure -state disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
@@ -727,7 +732,7 @@ proc notebook_fix_size {win} {
|
|||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
proc FindRemind {} {
|
proc FindRemind {} {
|
||||||
global env
|
global env
|
||||||
set path [concat [split $env(PATH) ":"] "/bin" "/usr/bin" "/usr/local/bin"]
|
set path [concat [split $env(PATH) ":"] "/usr/local/bin" "/bin" "/usr/bin" ]
|
||||||
foreach thing $path {
|
foreach thing $path {
|
||||||
if [file executable [file join $thing "remind"]] {
|
if [file executable [file join $thing "remind"]] {
|
||||||
return [file join $thing "remind"]
|
return [file join $thing "remind"]
|
||||||
@@ -745,16 +750,17 @@ proc FindRemind {} {
|
|||||||
# sensible defaults.
|
# sensible defaults.
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
proc SetConfigFromRemind {} {
|
proc SetConfigFromRemind {} {
|
||||||
global Config
|
global Config RemindExecutable
|
||||||
SetConfigDefaults
|
SetConfigDefaults
|
||||||
set rem [FindRemind]
|
set rem [FindRemind]
|
||||||
|
set RemindExecutable $rem
|
||||||
if {"$rem" == ""} {
|
if {"$rem" == ""} {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
set dir [file dirname $rem]
|
set dir [file dirname $rem]
|
||||||
set Config(INST_DIR) $dir
|
set Config(INST_DIR) $dir
|
||||||
if {"$dir" == "/usr/local/bin"} {
|
if {"$dir" == "/usr/local/bin"} {
|
||||||
set Config(MAN_DIR) "/usr/local/man"
|
set Config(MAN_DIR) "/usr/local/share/man"
|
||||||
} elseif {$dir == "/usr/bin"} {
|
} elseif {$dir == "/usr/bin"} {
|
||||||
set Config(MAN_DIR) "/usr/share/man"
|
set Config(MAN_DIR) "/usr/share/man"
|
||||||
}
|
}
|
||||||
@@ -764,6 +770,8 @@ proc SetConfigFromRemind {} {
|
|||||||
set Config(MAN_DIR) "/usr/share/man"
|
set Config(MAN_DIR) "/usr/share/man"
|
||||||
} elseif {[file readable "/usr/man/man1/remind.1"]} {
|
} elseif {[file readable "/usr/man/man1/remind.1"]} {
|
||||||
set Config(MAN_DIR) "/usr/man"
|
set Config(MAN_DIR) "/usr/man"
|
||||||
|
} elseif {[file readable "/usr/local/share/man/man1/remind.1"]} {
|
||||||
|
set Config(MAN_DIR) "/usr/local/share/man"
|
||||||
} elseif {[file readable "/usr/local/man/man1/remind.1"]} {
|
} elseif {[file readable "/usr/local/man/man1/remind.1"]} {
|
||||||
set Config(MAN_DIR) "/usr/local/man"
|
set Config(MAN_DIR) "/usr/local/man"
|
||||||
}
|
}
|
||||||
|
|||||||
115
configure
vendored
115
configure
vendored
@@ -1,6 +1,6 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated by GNU Autoconf 2.71.
|
# Generated by GNU Autoconf 2.71 for remind 05.00.00.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation,
|
# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation,
|
||||||
@@ -606,12 +606,12 @@ MFLAGS=
|
|||||||
MAKEFLAGS=
|
MAKEFLAGS=
|
||||||
|
|
||||||
# Identity of this package.
|
# Identity of this package.
|
||||||
PACKAGE_NAME=''
|
PACKAGE_NAME='remind'
|
||||||
PACKAGE_TARNAME=''
|
PACKAGE_TARNAME='remind'
|
||||||
PACKAGE_VERSION=''
|
PACKAGE_VERSION='05.00.00'
|
||||||
PACKAGE_STRING=''
|
PACKAGE_STRING='remind 05.00.00'
|
||||||
PACKAGE_BUGREPORT=''
|
PACKAGE_BUGREPORT=''
|
||||||
PACKAGE_URL=''
|
PACKAGE_URL='https://dianne.skoll.ca/projects/remind/'
|
||||||
|
|
||||||
ac_unique_file="src/queue.c"
|
ac_unique_file="src/queue.c"
|
||||||
# Factoring default headers for most tests.
|
# Factoring default headers for most tests.
|
||||||
@@ -757,7 +757,7 @@ localstatedir='${prefix}/var'
|
|||||||
runstatedir='${localstatedir}/run'
|
runstatedir='${localstatedir}/run'
|
||||||
includedir='${prefix}/include'
|
includedir='${prefix}/include'
|
||||||
oldincludedir='/usr/include'
|
oldincludedir='/usr/include'
|
||||||
docdir='${datarootdir}/doc/${PACKAGE}'
|
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
|
||||||
infodir='${datarootdir}/info'
|
infodir='${datarootdir}/info'
|
||||||
htmldir='${docdir}'
|
htmldir='${docdir}'
|
||||||
dvidir='${docdir}'
|
dvidir='${docdir}'
|
||||||
@@ -1264,7 +1264,7 @@ if test "$ac_init_help" = "long"; then
|
|||||||
# Omit some internal or obsolete options to make the list less imposing.
|
# Omit some internal or obsolete options to make the list less imposing.
|
||||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||||
cat <<_ACEOF
|
cat <<_ACEOF
|
||||||
\`configure' configures this package to adapt to many kinds of systems.
|
\`configure' configures remind 05.00.00 to adapt to many kinds of systems.
|
||||||
|
|
||||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||||
|
|
||||||
@@ -1313,7 +1313,7 @@ Fine tuning of the installation directories:
|
|||||||
--infodir=DIR info documentation [DATAROOTDIR/info]
|
--infodir=DIR info documentation [DATAROOTDIR/info]
|
||||||
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
|
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
|
||||||
--mandir=DIR man documentation [DATAROOTDIR/man]
|
--mandir=DIR man documentation [DATAROOTDIR/man]
|
||||||
--docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE]
|
--docdir=DIR documentation root [DATAROOTDIR/doc/remind]
|
||||||
--htmldir=DIR html documentation [DOCDIR]
|
--htmldir=DIR html documentation [DOCDIR]
|
||||||
--dvidir=DIR dvi documentation [DOCDIR]
|
--dvidir=DIR dvi documentation [DOCDIR]
|
||||||
--pdfdir=DIR pdf documentation [DOCDIR]
|
--pdfdir=DIR pdf documentation [DOCDIR]
|
||||||
@@ -1325,7 +1325,9 @@ _ACEOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if test -n "$ac_init_help"; then
|
if test -n "$ac_init_help"; then
|
||||||
|
case $ac_init_help in
|
||||||
|
short | recursive ) echo "Configuration of remind 05.00.00:";;
|
||||||
|
esac
|
||||||
cat <<\_ACEOF
|
cat <<\_ACEOF
|
||||||
|
|
||||||
Optional Features:
|
Optional Features:
|
||||||
@@ -1348,6 +1350,7 @@ Use these variables to override the choices made by `configure' or to help
|
|||||||
it to find libraries and programs with nonstandard names/locations.
|
it to find libraries and programs with nonstandard names/locations.
|
||||||
|
|
||||||
Report bugs to the package provider.
|
Report bugs to the package provider.
|
||||||
|
remind home page: <https://dianne.skoll.ca/projects/remind/>.
|
||||||
_ACEOF
|
_ACEOF
|
||||||
ac_status=$?
|
ac_status=$?
|
||||||
fi
|
fi
|
||||||
@@ -1411,7 +1414,7 @@ fi
|
|||||||
test -n "$ac_init_help" && exit $ac_status
|
test -n "$ac_init_help" && exit $ac_status
|
||||||
if $ac_init_version; then
|
if $ac_init_version; then
|
||||||
cat <<\_ACEOF
|
cat <<\_ACEOF
|
||||||
configure
|
remind configure 05.00.00
|
||||||
generated by GNU Autoconf 2.71
|
generated by GNU Autoconf 2.71
|
||||||
|
|
||||||
Copyright (C) 2021 Free Software Foundation, Inc.
|
Copyright (C) 2021 Free Software Foundation, Inc.
|
||||||
@@ -1861,7 +1864,7 @@ cat >config.log <<_ACEOF
|
|||||||
This file contains any messages produced by compilers while
|
This file contains any messages produced by compilers while
|
||||||
running configure, to aid debugging if configure makes a mistake.
|
running configure, to aid debugging if configure makes a mistake.
|
||||||
|
|
||||||
It was created by $as_me, which was
|
It was created by remind $as_me 05.00.00, which was
|
||||||
generated by GNU Autoconf 2.71. Invocation command line was
|
generated by GNU Autoconf 2.71. Invocation command line was
|
||||||
|
|
||||||
$ $0$ac_configure_args_raw
|
$ $0$ac_configure_args_raw
|
||||||
@@ -2450,7 +2453,6 @@ as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H"
|
|||||||
as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H"
|
as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H"
|
||||||
as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H"
|
as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H"
|
||||||
as_fn_append ac_header_c_list " sys/time.h sys_time_h HAVE_SYS_TIME_H"
|
as_fn_append ac_header_c_list " sys/time.h sys_time_h HAVE_SYS_TIME_H"
|
||||||
as_fn_append ac_header_c_list " utime.h utime_h HAVE_UTIME_H"
|
|
||||||
|
|
||||||
# Auxiliary files required by this configure script.
|
# Auxiliary files required by this configure script.
|
||||||
ac_aux_files="install-sh"
|
ac_aux_files="install-sh"
|
||||||
@@ -4004,6 +4006,12 @@ printf "%s\n" "#define SIZEOF_TIME_T $ac_cv_sizeof_time_t" >>confdefs.h
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ac_fn_c_check_header_compile "$LINENO" "strings.h" "ac_cv_header_strings_h" "$ac_includes_default"
|
||||||
|
if test "x$ac_cv_header_strings_h" = xyes
|
||||||
|
then :
|
||||||
|
printf "%s\n" "#define HAVE_STRINGS_H 1" >>confdefs.h
|
||||||
|
|
||||||
|
fi
|
||||||
ac_fn_c_check_header_compile "$LINENO" "sys/types.h" "ac_cv_header_sys_types_h" "$ac_includes_default"
|
ac_fn_c_check_header_compile "$LINENO" "sys/types.h" "ac_cv_header_sys_types_h" "$ac_includes_default"
|
||||||
if test "x$ac_cv_header_sys_types_h" = xyes
|
if test "x$ac_cv_header_sys_types_h" = xyes
|
||||||
then :
|
then :
|
||||||
@@ -4080,60 +4088,6 @@ printf "%s\n" "#define TM_IN_SYS_TIME 1" >>confdefs.h
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether utime accepts a null argument" >&5
|
|
||||||
printf %s "checking whether utime accepts a null argument... " >&6; }
|
|
||||||
if test ${ac_cv_func_utime_null+y}
|
|
||||||
then :
|
|
||||||
printf %s "(cached) " >&6
|
|
||||||
else $as_nop
|
|
||||||
rm -f conftest.data; >conftest.data
|
|
||||||
# Sequent interprets utime(file, 0) to mean use start of epoch. Wrong.
|
|
||||||
if test "$cross_compiling" = yes
|
|
||||||
then :
|
|
||||||
ac_cv_func_utime_null='guessing yes'
|
|
||||||
else $as_nop
|
|
||||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
|
||||||
/* end confdefs.h. */
|
|
||||||
$ac_includes_default
|
|
||||||
#ifdef HAVE_UTIME_H
|
|
||||||
# include <utime.h>
|
|
||||||
#endif
|
|
||||||
int
|
|
||||||
main (void)
|
|
||||||
{
|
|
||||||
struct stat s, t;
|
|
||||||
return ! (stat ("conftest.data", &s) == 0
|
|
||||||
&& utime ("conftest.data", 0) == 0
|
|
||||||
&& stat ("conftest.data", &t) == 0
|
|
||||||
&& t.st_mtime >= s.st_mtime
|
|
||||||
&& t.st_mtime - s.st_mtime < 120);
|
|
||||||
;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
_ACEOF
|
|
||||||
if ac_fn_c_try_run "$LINENO"
|
|
||||||
then :
|
|
||||||
ac_cv_func_utime_null=yes
|
|
||||||
else $as_nop
|
|
||||||
ac_cv_func_utime_null=no
|
|
||||||
fi
|
|
||||||
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
|
|
||||||
conftest.$ac_objext conftest.beam conftest.$ac_ext
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_utime_null" >&5
|
|
||||||
printf "%s\n" "$ac_cv_func_utime_null" >&6; }
|
|
||||||
if test "x$ac_cv_func_utime_null" != xno; then
|
|
||||||
ac_cv_func_utime_null=yes
|
|
||||||
|
|
||||||
printf "%s\n" "#define HAVE_UTIME_NULL 1" >>confdefs.h
|
|
||||||
|
|
||||||
fi
|
|
||||||
rm -f conftest.data
|
|
||||||
|
|
||||||
if test "$GCC" = yes; then
|
if test "$GCC" = yes; then
|
||||||
CFLAGS="$CFLAGS -Wall -Wextra -Wstrict-prototypes"
|
CFLAGS="$CFLAGS -Wall -Wextra -Wstrict-prototypes"
|
||||||
# Check for link-time optimization support
|
# Check for link-time optimization support
|
||||||
@@ -4181,6 +4135,24 @@ if test "$?" != 0 ; then
|
|||||||
echo "*** COULD NOT DETERMINE RELEASE DATE: docs/WHATSNEW is incorrect!"
|
echo "*** COULD NOT DETERMINE RELEASE DATE: docs/WHATSNEW is incorrect!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup"
|
||||||
|
if test "x$ac_cv_func_strdup" = xyes
|
||||||
|
then :
|
||||||
|
printf "%s\n" "#define HAVE_STRDUP 1" >>confdefs.h
|
||||||
|
|
||||||
|
fi
|
||||||
|
ac_fn_c_check_func "$LINENO" "strcasecmp" "ac_cv_func_strcasecmp"
|
||||||
|
if test "x$ac_cv_func_strcasecmp" = xyes
|
||||||
|
then :
|
||||||
|
printf "%s\n" "#define HAVE_STRCASECMP 1" >>confdefs.h
|
||||||
|
|
||||||
|
fi
|
||||||
|
ac_fn_c_check_func "$LINENO" "strncasecmp" "ac_cv_func_strncasecmp"
|
||||||
|
if test "x$ac_cv_func_strncasecmp" = xyes
|
||||||
|
then :
|
||||||
|
printf "%s\n" "#define HAVE_STRNCASECMP 1" >>confdefs.h
|
||||||
|
|
||||||
|
fi
|
||||||
ac_fn_c_check_func "$LINENO" "setenv" "ac_cv_func_setenv"
|
ac_fn_c_check_func "$LINENO" "setenv" "ac_cv_func_setenv"
|
||||||
if test "x$ac_cv_func_setenv" = xyes
|
if test "x$ac_cv_func_setenv" = xyes
|
||||||
then :
|
then :
|
||||||
@@ -4225,7 +4197,7 @@ then :
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
VERSION=04.03.06
|
VERSION=$PACKAGE_VERSION
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -4731,7 +4703,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
|||||||
# report actual input values of CONFIG_FILES etc. instead of their
|
# report actual input values of CONFIG_FILES etc. instead of their
|
||||||
# values after options handling.
|
# values after options handling.
|
||||||
ac_log="
|
ac_log="
|
||||||
This file was extended by $as_me, which was
|
This file was extended by remind $as_me 05.00.00, which was
|
||||||
generated by GNU Autoconf 2.71. Invocation command line was
|
generated by GNU Autoconf 2.71. Invocation command line was
|
||||||
|
|
||||||
CONFIG_FILES = $CONFIG_FILES
|
CONFIG_FILES = $CONFIG_FILES
|
||||||
@@ -4787,7 +4759,8 @@ $config_files
|
|||||||
Configuration headers:
|
Configuration headers:
|
||||||
$config_headers
|
$config_headers
|
||||||
|
|
||||||
Report bugs to the package provider."
|
Report bugs to the package provider.
|
||||||
|
remind home page: <https://dianne.skoll.ca/projects/remind/>."
|
||||||
|
|
||||||
_ACEOF
|
_ACEOF
|
||||||
ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"`
|
ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"`
|
||||||
@@ -4795,7 +4768,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
|
|||||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||||
ac_cs_config='$ac_cs_config_escaped'
|
ac_cs_config='$ac_cs_config_escaped'
|
||||||
ac_cs_version="\\
|
ac_cs_version="\\
|
||||||
config.status
|
remind config.status 05.00.00
|
||||||
configured by $0, generated by GNU Autoconf 2.71,
|
configured by $0, generated by GNU Autoconf 2.71,
|
||||||
with options \\"\$ac_cs_config\\"
|
with options \\"\$ac_cs_config\\"
|
||||||
|
|
||||||
|
|||||||
12
configure.in
12
configure.in
@@ -1,6 +1,6 @@
|
|||||||
dnl Process this file with autoconf to produce a configure script.
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
AC_INIT
|
AC_INIT(remind, 05.00.00, , , https://dianne.skoll.ca/projects/remind/)
|
||||||
AC_CONFIG_SRCDIR([src/queue.c])
|
AC_CONFIG_SRCDIR([src/queue.c])
|
||||||
|
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@ -30,7 +30,7 @@ AC_PATH_PROG([PERL], [perl])
|
|||||||
|
|
||||||
dnl Checks for libraries.
|
dnl Checks for libraries.
|
||||||
AC_CHECK_LIB(m, sqrt)
|
AC_CHECK_LIB(m, sqrt)
|
||||||
AC_CHECK_HEADERS_ONCE([sys/time.h])
|
AC_CHECK_HEADERS_ONCE([sys/time.h stdint.h])
|
||||||
|
|
||||||
dnl Integer sizes
|
dnl Integer sizes
|
||||||
AC_CHECK_SIZEOF(unsigned int)
|
AC_CHECK_SIZEOF(unsigned int)
|
||||||
@@ -38,13 +38,11 @@ AC_CHECK_SIZEOF(unsigned long)
|
|||||||
AC_CHECK_SIZEOF(time_t)
|
AC_CHECK_SIZEOF(time_t)
|
||||||
|
|
||||||
dnl Checks for header files.
|
dnl Checks for header files.
|
||||||
AC_CHECK_HEADERS(sys/types.h glob.h wctype.h locale.h langinfo.h sys/inotify.h)
|
AC_CHECK_HEADERS(strings.h sys/types.h glob.h wctype.h locale.h langinfo.h sys/inotify.h)
|
||||||
|
|
||||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||||
AC_STRUCT_TM
|
AC_STRUCT_TM
|
||||||
|
|
||||||
dnl Checks for library functions.
|
|
||||||
AC_FUNC_UTIME_NULL
|
|
||||||
if test "$GCC" = yes; then
|
if test "$GCC" = yes; then
|
||||||
CFLAGS="$CFLAGS -Wall -Wextra -Wstrict-prototypes"
|
CFLAGS="$CFLAGS -Wall -Wextra -Wstrict-prototypes"
|
||||||
# Check for link-time optimization support
|
# Check for link-time optimization support
|
||||||
@@ -86,9 +84,9 @@ if test "$?" != 0 ; then
|
|||||||
echo "*** COULD NOT DETERMINE RELEASE DATE: docs/WHATSNEW is incorrect!"
|
echo "*** COULD NOT DETERMINE RELEASE DATE: docs/WHATSNEW is incorrect!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
AC_CHECK_FUNCS(setenv unsetenv glob mbstowcs setlocale initgroups inotify_init1)
|
AC_CHECK_FUNCS(strdup strcasecmp strncasecmp setenv unsetenv glob mbstowcs setlocale initgroups inotify_init1)
|
||||||
|
|
||||||
VERSION=04.03.06
|
VERSION=$PACKAGE_VERSION
|
||||||
AC_SUBST(VERSION)
|
AC_SUBST(VERSION)
|
||||||
AC_SUBST(PERL)
|
AC_SUBST(PERL)
|
||||||
AC_SUBST(PERLARTIFACTS)
|
AC_SUBST(PERLARTIFACTS)
|
||||||
|
|||||||
@@ -1,7 +1,105 @@
|
|||||||
CHANGES TO REMIND
|
CHANGES TO REMIND
|
||||||
|
|
||||||
|
* VERSION 5.0 Patch 0 - 2024-06-06
|
||||||
|
|
||||||
|
* MAJOR CHANGE: The expression evaluation engine has been completely replaced
|
||||||
|
with a new one that splits parsing and evaluating into two separate steps.
|
||||||
|
It also features short-circuit evaluation of &&, ||, iif() and choose().
|
||||||
|
This should speed up expression-heavy reminder files.
|
||||||
|
|
||||||
|
NOTE INCOMPATIBILITY: In expressions with side-effects, the short-circuit
|
||||||
|
evaluation might change the result you get. For example, consider
|
||||||
|
running the following file through: remind file.rem 2024-06-04
|
||||||
|
|
||||||
|
SET a trig("Mon +7") || trig("Thu +7")
|
||||||
|
MSG trig = [trig()]
|
||||||
|
|
||||||
|
Older Remind versions will output:
|
||||||
|
|
||||||
|
trig = 2024-06-06
|
||||||
|
|
||||||
|
whereas this version outputs:
|
||||||
|
|
||||||
|
trig = 2024-06-10
|
||||||
|
|
||||||
|
because the second part of the "||" expression is not evaluated. The vast
|
||||||
|
majority of Remind expressions do not have side-effects and should yield
|
||||||
|
the same results as before.
|
||||||
|
|
||||||
|
The newer expression engine also permits recursive functions, but
|
||||||
|
these are not recommended. Still, if you want to, you can do:
|
||||||
|
|
||||||
|
fset factorial(n) iif(n <= 1, 1, n*factorial(n-1))
|
||||||
|
|
||||||
|
and it will work for values of n that don't cause integer overflow.
|
||||||
|
|
||||||
|
* IMPROVEMENT: If there's an unmatched PUSH-OMIT-CONTEXT, print the
|
||||||
|
filename and line number containing it.
|
||||||
|
|
||||||
|
* IMPROVEMENT: If there's an IF with a missing ENDIF, print the filename
|
||||||
|
and line number of the IF statement.
|
||||||
|
|
||||||
|
* NEW FEATURE: Add EXPR OFF command to completely disable expression
|
||||||
|
evaluation. Useful if you INCLUDE files that you don't expect to
|
||||||
|
contain expressions and may come from slightly untrustworthy sources.
|
||||||
|
|
||||||
|
* NEW FEATURE: Add $ExpressionTimeLimit system variable to enforce a
|
||||||
|
maximum limit on how long evaluating an expression is allowed to take.
|
||||||
|
|
||||||
|
* NEW FEATURE: Add --max-execution-time=n command-line option to terminate
|
||||||
|
Remind if it runs for more than n seconds.
|
||||||
|
|
||||||
|
* CHANGE: Make the command-line option "-ifoo" equivalent to "-ifoo=0"
|
||||||
|
|
||||||
|
* CHANGE: Permit a literal [ in a reminder by using the sequence [[
|
||||||
|
The old ["["] still works.
|
||||||
|
|
||||||
|
* BUG FIX: In "purge" mode, Remind would sometimes purge reminders with
|
||||||
|
a relative "SCANFROM" which haven't actually expired. This has been fixed.
|
||||||
|
|
||||||
|
* BUG FIX: Disallow something like: FSET func(x, x) expr
|
||||||
|
which shouldn't have been allowed in the first place.
|
||||||
|
|
||||||
|
* BUG FIX: Replace leading spaces with tabs in Makefiles (per Emanuele Torre
|
||||||
|
and Tim Chase)
|
||||||
|
|
||||||
|
* VERSION 4.3 Patch 7 - 2024-04-29
|
||||||
|
|
||||||
|
* IMPROVEMENT: build.tk: Add a note if build.tk obtains default settings
|
||||||
|
from an existing Remind installation.
|
||||||
|
|
||||||
|
* IMPROVEMENT: configure: Pass all args to AC_INIT including the Remind
|
||||||
|
home page. Remove some unused autoconf cruft.
|
||||||
|
|
||||||
|
* IMPROVEMENT: Use standard C library versions of strdup, strcasecmp and
|
||||||
|
strncasecmp where available, rather than using our own versions.
|
||||||
|
|
||||||
|
* MINOR FEATURE: remind: Make $Tt a synonym for trigtime().
|
||||||
|
|
||||||
|
* BUG FIX: remind: Make sure shellescape() doesn't mangle UTF-8 characters
|
||||||
|
with high-bits set.
|
||||||
|
|
||||||
|
* BUG FIX: remind: Don't rely on undefined behavior of "%" operator in
|
||||||
|
the ord() built-in function.
|
||||||
|
|
||||||
|
* BUG FIX: remind: Do not clear out trigtime() unnecessarily. Before,
|
||||||
|
you could not write things like the following; now you can:
|
||||||
|
|
||||||
|
REM Tue AT 11:30 DURATION 0:30 MSG Thing 1
|
||||||
|
REM Tue AT [trigtime()+trigduration()] DURATION 1:00 MSG Thing 2
|
||||||
|
REM Tue AT [trigtime()+trigduration()] DURATION 0:45 MSG Thing 3
|
||||||
|
|
||||||
|
for successive reminders that should be moved as a block if the time of
|
||||||
|
the first one changes.
|
||||||
|
|
||||||
|
* BUG FIX: Don't update trigdate() or trigtime() while parsing a REM
|
||||||
|
statement... only when actually computing the trigger.
|
||||||
|
|
||||||
* VERSION 4.3 Patch 6 - 2024-04-02
|
* VERSION 4.3 Patch 6 - 2024-04-02
|
||||||
|
|
||||||
|
* NEW FILE: Add [$SysInclude]/holidays/pt.rem - Portuguese holidays, courtesy
|
||||||
|
of Joop Kiefte.
|
||||||
|
|
||||||
* BUG FIX: remind: Fix compile error on systems that don't support inotify(7).
|
* BUG FIX: remind: Fix compile error on systems that don't support inotify(7).
|
||||||
|
|
||||||
* BUG FIX: remind: Fix test failures on FreeBSD. On FreeBSD, you have to copy
|
* BUG FIX: remind: Fix test failures on FreeBSD. On FreeBSD, you have to copy
|
||||||
|
|||||||
@@ -106,7 +106,3 @@ IF !Reform
|
|||||||
[_PastSat(17, "Tamuz")] ++4 MSG %"Tzom Tammuz%" is %b.
|
[_PastSat(17, "Tamuz")] ++4 MSG %"Tzom Tammuz%" is %b.
|
||||||
[_PastSat(9, "Av")] ++4 MSG %"Tish'a B'Av%" is %b.
|
[_PastSat(9, "Av")] ++4 MSG %"Tish'a B'Av%" is %b.
|
||||||
ENDIF
|
ENDIF
|
||||||
|
|
||||||
# Clean up
|
|
||||||
FUNSET _h _h2 _PastSat _BackTwoFri _BackTwoSat _chan
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0-only
|
# SPDX-License-Identifier: GPL-2.0-only
|
||||||
SET autolang getenv("REMIND_LANG")
|
if !defined("__autolang__")
|
||||||
|
SET __autolang__ 1
|
||||||
|
PRESERVE __autolang__
|
||||||
|
SET autolang getenv("REMIND_LANG")
|
||||||
|
|
||||||
IF autolang == ""
|
IF autolang == ""
|
||||||
SET autolang getenv("LC_ALL")
|
SET autolang getenv("LC_ALL")
|
||||||
ENDIF
|
ENDIF
|
||||||
IF autolang == ""
|
IF autolang == ""
|
||||||
SET autolang getenv("LANGUAGE")
|
SET autolang getenv("LANGUAGE")
|
||||||
ENDIF
|
ENDIF
|
||||||
IF autolang == ""
|
IF autolang == ""
|
||||||
SET autolang getenv("LANG")
|
SET autolang getenv("LANG")
|
||||||
ENDIF
|
ENDIF
|
||||||
|
|
||||||
IF autolang != ""
|
IF autolang != ""
|
||||||
IF access($SysInclude + "/lang/" + lower(substr(autolang, 1, 5)) + ".rem", "r") == 0
|
IF access($SysInclude + "/lang/" + lower(substr(autolang, 1, 5)) + ".rem", "r") == 0
|
||||||
INCLUDE [$SysInclude]/lang/[lower(substr(autolang, 1, 5))].rem
|
INCLUDE [$SysInclude]/lang/[lower(substr(autolang, 1, 5))].rem
|
||||||
ELSE
|
ELSE
|
||||||
IF access($SysInclude + "/lang/" + lower(substr(autolang, 1, 2)) + ".rem", "r") == 0
|
IF access($SysInclude + "/lang/" + lower(substr(autolang, 1, 2)) + ".rem", "r") == 0
|
||||||
INCLUDE [$SysInclude]/lang/[lower(substr(autolang, 1, 2))].rem
|
INCLUDE [$SysInclude]/lang/[lower(substr(autolang, 1, 2))].rem
|
||||||
|
ENDIF
|
||||||
ENDIF
|
ENDIF
|
||||||
ENDIF
|
ENDIF
|
||||||
|
UNSET autolang
|
||||||
ENDIF
|
ENDIF
|
||||||
|
|
||||||
UNSET autolang
|
|
||||||
|
|||||||
@@ -87,3 +87,5 @@ SET daylightST_starts_str "Beginn Sommerzeit"
|
|||||||
|
|
||||||
# Daylight saving time ends
|
# Daylight saving time ends
|
||||||
SET daylightST_ends_str "Ende Sommerzeit"
|
SET daylightST_ends_str "Ende Sommerzeit"
|
||||||
|
|
||||||
|
PRESERVE earthseasons_Perihelion_str earthseasons_EquinoxMar_str earthseasons_SolsticeJun_str earthseasons_Aphelion_str earthseasons_EquinoxSep_str earthseasons_SolsticeDec_str daylightST_starts_str daylightST_ends_str
|
||||||
@@ -81,3 +81,5 @@ SET daylightST_starts_str "Έναρξη θέρους"
|
|||||||
|
|
||||||
# Daylight saving time ends
|
# Daylight saving time ends
|
||||||
SET daylightST_ends_str "Τέλος θέρους"
|
SET daylightST_ends_str "Τέλος θέρους"
|
||||||
|
|
||||||
|
PRESERVE earthseasons_Perihelion_str earthseasons_EquinoxMar_str earthseasons_SolsticeJun_str earthseasons_Aphelion_str earthseasons_EquinoxSep_str earthseasons_SolsticeDec_str daylightST_starts_str daylightST_ends_str
|
||||||
|
|||||||
200
man/remind.1.in
200
man/remind.1.in
@@ -28,10 +28,6 @@ Anything after the __EOF__ marker is completely ignored.
|
|||||||
\fBRemind\fR has a slew of options. If you're new to the program,
|
\fBRemind\fR has a slew of options. If you're new to the program,
|
||||||
ignore them for now and skip to the section "REMINDER FILES".
|
ignore them for now and skip to the section "REMINDER FILES".
|
||||||
.TP
|
.TP
|
||||||
.B \-\-version
|
|
||||||
The \fB\-\-version\fR option causes \fBRemind\fR to print its version number
|
|
||||||
to standard output and then exit.
|
|
||||||
.TP
|
|
||||||
.B \-n
|
.B \-n
|
||||||
The \fB\-n\fR option causes \fBRemind\fR to print the \fBnext\fR occurrence
|
The \fB\-n\fR option causes \fBRemind\fR to print the \fBnext\fR occurrence
|
||||||
of each reminder in a simple calendar format. You can sort this by
|
of each reminder in a simple calendar format. You can sort this by
|
||||||
@@ -302,9 +298,9 @@ Echo lines when displaying error messages
|
|||||||
Trace the reading of reminder files
|
Trace the reading of reminder files
|
||||||
.TP
|
.TP
|
||||||
.B s
|
.B s
|
||||||
Upon exit, print the high-water mark of the operator and value stacks
|
Trace expression parsing and display the internal expression node
|
||||||
used for expression-parsing. This is unlikely to be useful unless
|
tree. This is unlikely to be useful unless you are working on
|
||||||
you're intimately familiar with Remind's source code.
|
\fBRemind\fR's expression evaluation engine.
|
||||||
.RE
|
.RE
|
||||||
.TP
|
.TP
|
||||||
\fB\-g\fR[\fBa|d\fR[\fBa|d\fR[\fBa|d\fR[\fBa|d\fR]]]]
|
\fB\-g\fR[\fBa|d\fR[\fBa|d\fR[\fBa|d\fR[\fBa|d\fR]]]]
|
||||||
@@ -420,7 +416,9 @@ TAG clause.
|
|||||||
\fB\-i\fR\fIvar\fR\fB=\fR\fIexpr\fR
|
\fB\-i\fR\fIvar\fR\fB=\fR\fIexpr\fR
|
||||||
Sets the value of the specified \fIvar\fR to \fIexpr\fR, and \fBpreserves\fR
|
Sets the value of the specified \fIvar\fR to \fIexpr\fR, and \fBpreserves\fR
|
||||||
\fIvar\fR. \fIExpr\fR can be any valid \fBRemind\fR expression. See the
|
\fIvar\fR. \fIExpr\fR can be any valid \fBRemind\fR expression. See the
|
||||||
section "INITIALIZING VARIABLES ON THE COMMAND LINE" for more details.
|
section "INITIALIZING VARIABLES ON THE COMMAND LINE" for more details. If
|
||||||
|
you omit the \fB=\fR\fIexpr\fR part, then \fIvar\fR is initialized to 0.
|
||||||
|
In other words, \fB\-i\fIvar\fR is exactly the same as \fB\-i\fIvar\fR\fB=\fR0.
|
||||||
.TP
|
.TP
|
||||||
\fB\-i\fR\fIfunc\fR(\fIargs\fR)=\fIdefinition\fR
|
\fB\-i\fR\fIfunc\fR(\fIargs\fR)=\fIdefinition\fR
|
||||||
Allows you to define a function on the command line.
|
Allows you to define a function on the command line.
|
||||||
@@ -451,6 +449,30 @@ with the date incrementing on each iteration. You may have to enclose
|
|||||||
the parameter in quotes to avoid shell expansion. See the subsection
|
the parameter in quotes to avoid shell expansion. See the subsection
|
||||||
"Repeated Execution" in the section "CALENDAR MODE" for more
|
"Repeated Execution" in the section "CALENDAR MODE" for more
|
||||||
information.
|
information.
|
||||||
|
|
||||||
|
.SH LONG OPTIONS
|
||||||
|
|
||||||
|
\fBRemind\fR supports the following long options, which \fIare\fR
|
||||||
|
case-sensitive:
|
||||||
|
|
||||||
|
.RP
|
||||||
|
.B \-\-version
|
||||||
|
The \fB\-\-version\fR option causes \fBRemind\fR to print its version number
|
||||||
|
to standard output and then exit.
|
||||||
|
.TP
|
||||||
|
.B \-\-max-execution-time\fR=\fIn\fR
|
||||||
|
Limit the total execution time (as measured by the wall clock) to
|
||||||
|
\fIn\fR seconds. This is useful if \fBRemind\fR is invoked on
|
||||||
|
potentially-untrustworthy files that could attempt to use a lot of
|
||||||
|
resources. Note that the limit \fIn\fR is approximate and
|
||||||
|
\fBRemind\fR might execute for one or two more seconds before it is
|
||||||
|
killed. If \fIn\fR is specified as zero, then no limit is applied, just
|
||||||
|
as if the option had not been used at all.
|
||||||
|
.PP
|
||||||
|
If a limit is applied, it applies only to the foreground run of \fBRemind\fR.
|
||||||
|
If \fBRemind\fR finishes processing the script and then starts handling
|
||||||
|
queued reminders, the time limit is reset to no limit.
|
||||||
|
.PP
|
||||||
.SH REMINDER FILES
|
.SH REMINDER FILES
|
||||||
.PP
|
.PP
|
||||||
\fBRemind\fR uses scripts to control its operation. You can use any
|
\fBRemind\fR uses scripts to control its operation. You can use any
|
||||||
@@ -1880,24 +1902,6 @@ If you run \fBRemind\fR with the \fB\-r\fR command-line option,
|
|||||||
regardless of any \fBRUN\fR commands in the reminder script. However,
|
regardless of any \fBRUN\fR commands in the reminder script. However,
|
||||||
any command supplied with the \fB\-k\fR option will still be executed.
|
any command supplied with the \fB\-k\fR option will still be executed.
|
||||||
.PP
|
.PP
|
||||||
One use of the \fBRUN\fR command is to provide a secure interface
|
|
||||||
between \fBRemind\fR and the \fBElm\fR mail system. The \fBElm\fR
|
|
||||||
system can automatically scan incoming mail for reminder or calendar
|
|
||||||
entries, and place them in your calendar file. To use this feature,
|
|
||||||
you should set the calendar filename option under \fBElm\fR to be something
|
|
||||||
like "~/.reminders.in", \fInot\fR your main reminder file! This is
|
|
||||||
so that any \fBRUN ON\fR commands mailed to you can never be activated.
|
|
||||||
.PP
|
|
||||||
Then, you can use the \fBElm\fR \fIscan message for calendar entries\fR
|
|
||||||
command to place reminders prefaced by "->" into .reminders.in. In
|
|
||||||
your main .reminders file, include the following lines:
|
|
||||||
.PP
|
|
||||||
.nf
|
|
||||||
RUN OFF # Disable RUN
|
|
||||||
INCLUDE .reminders.in
|
|
||||||
RUN ON # Re-enable RUN
|
|
||||||
.fi
|
|
||||||
.PP
|
|
||||||
In addition, \fBRemind\fR contains a few other security
|
In addition, \fBRemind\fR contains a few other security
|
||||||
features. It will not read a file that is group- or world-writable.
|
features. It will not read a file that is group- or world-writable.
|
||||||
It will not run set-uid. If it reads a file you don't own, it will
|
It will not run set-uid. If it reads a file you don't own, it will
|
||||||
@@ -1909,6 +1913,30 @@ attempt to check the ownership of standard input, even if it is
|
|||||||
coming from a file, and hence does \fInot\fR disable RUN and shell()
|
coming from a file, and hence does \fInot\fR disable RUN and shell()
|
||||||
in this situation.
|
in this situation.
|
||||||
|
|
||||||
|
.PP
|
||||||
|
.SH THE EXPR COMMAND
|
||||||
|
.PP
|
||||||
|
\fBRemind\fR lets you completely disable expression evaluation. This
|
||||||
|
could be useful if you are running Remind on a somewhat-untrustworthy
|
||||||
|
file that is not expected to contain expressions. To disable
|
||||||
|
expression evaluation, use:
|
||||||
|
.PP
|
||||||
|
.nf
|
||||||
|
EXPR OFF
|
||||||
|
.fi
|
||||||
|
.PP
|
||||||
|
If \fBRemind\fR encounters an expression while EXPR OFF is in effect, it
|
||||||
|
returns an error
|
||||||
|
.PP
|
||||||
|
To re-enable expression evaluation, use:
|
||||||
|
.PP
|
||||||
|
.nf
|
||||||
|
EXPR ON
|
||||||
|
.fi
|
||||||
|
.PP
|
||||||
|
As with \fBRUN ON\fB, \fBEXPR ON\fR can be used only in the top-level
|
||||||
|
script, not in an included file.
|
||||||
|
.PP
|
||||||
.SH THE INCLUDECMD COMMAND
|
.SH THE INCLUDECMD COMMAND
|
||||||
.PP
|
.PP
|
||||||
\fBRemind\fR allows you to execute a shell command and evaluate the
|
\fBRemind\fR allows you to execute a shell command and evaluate the
|
||||||
@@ -2161,13 +2189,13 @@ than those on higher lines. The operators approximately correspond to
|
|||||||
C operators.
|
C operators.
|
||||||
.PP
|
.PP
|
||||||
.nf
|
.nf
|
||||||
! - (unary logical negation and arithmetic negation)
|
! - (unary logical negation and arithmetic negation)
|
||||||
* / %
|
* / % (multiplication, division, modulus)
|
||||||
+ -
|
+ - (addition/concatenation, subtraction)
|
||||||
< <= > >=
|
< <= > >= (comparisons)
|
||||||
== !=
|
== != (equality and inequality tests)
|
||||||
&&
|
&& (logical AND)
|
||||||
||
|
|| (logical OR)
|
||||||
.fi
|
.fi
|
||||||
.PP
|
.PP
|
||||||
.B DESCRIPTION OF OPERATORS
|
.B DESCRIPTION OF OPERATORS
|
||||||
@@ -2279,16 +2307,15 @@ If the operands are not of the same type, == returns 0 and != returns
|
|||||||
.RE
|
.RE
|
||||||
.TP
|
.TP
|
||||||
.B &&
|
.B &&
|
||||||
This is the logical AND operator. Both of its operands must be of the
|
This is the logical AND operator. Neither of its operands can be
|
||||||
same type and must not be \fBSTRING\fR type. Returns the second
|
\fBSTRING\fR type. Returns the second operand if both operands are
|
||||||
operand if both operands are non-zero. Otherwise, returns a zero
|
non-zero. Otherwise, returns whichever operand is zero.
|
||||||
of the same type as the operands.
|
|
||||||
.TP
|
.TP
|
||||||
.B ||
|
.B ||
|
||||||
This is the logical OR operator. Both of its operands must be of
|
This is the logical OR operator. Neither of its operands can be
|
||||||
the same type and must not be of \fBSTRING\fR type. It returns
|
\fBSTRING\fR type. It returns the first operand that is non-zero; if
|
||||||
the first operand that is non-zero; if both operands are zero, then
|
both operands are zero, then returns the second operand.
|
||||||
returns a zero of the same type as the operands.
|
|
||||||
.PP
|
.PP
|
||||||
.B NOTES
|
.B NOTES
|
||||||
.PP
|
.PP
|
||||||
@@ -2309,15 +2336,10 @@ For example:
|
|||||||
12:59 + (1 + "test") yields "12:591test"
|
12:59 + (1 + "test") yields "12:591test"
|
||||||
.fi
|
.fi
|
||||||
.PP
|
.PP
|
||||||
The logical operators are \fInot\fR so-called short-circuit operators, as
|
The logical operators are so-called short-circuit operators, as
|
||||||
they are in C. Both operands are always evaluated. Thus, an expression
|
they are in C. This means that if the first operand of || is true,
|
||||||
such as:
|
then the second operand is \fInot\fR evaluated. Similarly, if the first
|
||||||
.PP
|
operand of && is false, then the second operand is \fInot\fR evaluated.
|
||||||
.nf
|
|
||||||
(f!=0) && (100/f <= 3)
|
|
||||||
.fi
|
|
||||||
.PP
|
|
||||||
will cause an error if f is zero.
|
|
||||||
.PP
|
.PP
|
||||||
.B VARIABLES
|
.B VARIABLES
|
||||||
.PP
|
.PP
|
||||||
@@ -2474,6 +2496,14 @@ because the final parenthesis and quote are ignored (for the purposes
|
|||||||
of spacing) when they follow a period.
|
of spacing) when they follow a period.
|
||||||
.RE
|
.RE
|
||||||
.TP
|
.TP
|
||||||
|
.B $ExpressionTimeLimit
|
||||||
|
If set to a non-zero value \fIn\fR, than any expression that takes longer than
|
||||||
|
\fIn\fR seconds to evaluate will be aborted and an error returned. This is
|
||||||
|
to prevent maliciously-crafted expressions for creating a denial-of-service.
|
||||||
|
In an included file, $ExpressionTimeLimit can only be lowered from its
|
||||||
|
current value. In the top-level file, it can be set to any value, including
|
||||||
|
zero to disable the time limit.
|
||||||
|
.TP
|
||||||
.B $FirstIndent
|
.B $FirstIndent
|
||||||
The number of spaces by which to indent the first line of a \fBMSF\fR-type
|
The number of spaces by which to indent the first line of a \fBMSF\fR-type
|
||||||
reminder. The default is 0.
|
reminder. The default is 0.
|
||||||
@@ -2747,6 +2777,9 @@ Equivalent to \fBwkdaynum(trigdate())\fR.
|
|||||||
.B $Ty (read-only)
|
.B $Ty (read-only)
|
||||||
Equivalent to \fByear(trigdate())\fR.
|
Equivalent to \fByear(trigdate())\fR.
|
||||||
.TP
|
.TP
|
||||||
|
.B $Tt (read-only, TIME type)
|
||||||
|
Equivalent to \fBtrigtime()\fR.
|
||||||
|
.TP
|
||||||
.B $TimeSep
|
.B $TimeSep
|
||||||
This variable can be set only to ":" or ".". It holds the character
|
This variable can be set only to ":" or ".". It holds the character
|
||||||
used to separate portions of a time when \fBRemind\fR prints a TIME or
|
used to separate portions of a time when \fBRemind\fR prints a TIME or
|
||||||
@@ -3835,7 +3868,7 @@ function for advance warning to work properly. This is because
|
|||||||
\fBtrig\fR returns a date constant (the trigger date) and the
|
\fBtrig\fR returns a date constant (the trigger date) and the
|
||||||
REM command does not know the details of \fBtrig\fR's arguments.
|
REM command does not know the details of \fBtrig\fR's arguments.
|
||||||
.PP
|
.PP
|
||||||
Note that because \fBRemind\fR does not have short-circuit logical
|
Note that because \fBRemind\fR has short-circuit logical
|
||||||
operators, something like:
|
operators, something like:
|
||||||
.PP
|
.PP
|
||||||
.nf
|
.nf
|
||||||
@@ -3843,58 +3876,9 @@ operators, something like:
|
|||||||
.fi
|
.fi
|
||||||
|
|
||||||
would set the value of trig() to the date of the following
|
would set the value of trig() to the date of the following
|
||||||
Thursday. Even though trig("Mon +7") always returns true,
|
Monday. Because trig("Mon +7") always returns true,
|
||||||
the logical-OR operator still evaluates trig("Fri +7") which
|
the logical-OR operator does not bother evaluating trig("Fri +7") which
|
||||||
\fIalso\fR returns true and sets \fBtrig()\fR.
|
therefore does not set \fBtrig()\fR.
|
||||||
.PP
|
|
||||||
You can work around the lack of a short-circuit logical-OR as follows:
|
|
||||||
If \fBtrig\fR returns a true value, the specific value it returns
|
|
||||||
can be coerced to a DATE which is the trigger date. So the following code:
|
|
||||||
.PP
|
|
||||||
.nf
|
|
||||||
SET a trig("Mon +4") || trig("Fri +4")
|
|
||||||
IF a
|
|
||||||
REM [a] +4 MSG [wkday($T)] %b.
|
|
||||||
ENDIF
|
|
||||||
.fi
|
|
||||||
.PP
|
|
||||||
would operate as follows:
|
|
||||||
.PP
|
|
||||||
.nf
|
|
||||||
On Monday: Monday today.
|
|
||||||
On Tuesday: Friday in 3 days' time.
|
|
||||||
On Wednesday: Friday in 2 days' time.
|
|
||||||
On Thursday: Monday in 4 days' time.
|
|
||||||
On Friday: Monday in 3 days' time.
|
|
||||||
On Saturday: Monday in 2 days' time.
|
|
||||||
On Sunday: Monday tomorrow.
|
|
||||||
.fi
|
|
||||||
.PP
|
|
||||||
Compare with the following:
|
|
||||||
.PP
|
|
||||||
.nf
|
|
||||||
SET a trig("Mon +4") || trig("Fri +4")
|
|
||||||
IF a
|
|
||||||
REM [trig()] +4 MSG [wkday($T)] %b.
|
|
||||||
ENDIF
|
|
||||||
.fi
|
|
||||||
.PP
|
|
||||||
which yields:
|
|
||||||
.PP
|
|
||||||
.nf
|
|
||||||
On Monday: Friday in 4 days' time.
|
|
||||||
On Tuesday: Friday in 3 days' time.
|
|
||||||
On Wednesday: Friday in 2 days' time.
|
|
||||||
On Thursday: Friday tomorrow.
|
|
||||||
On Friday: Friday today.
|
|
||||||
On Saturday: Monday in 2 days' time.
|
|
||||||
On Sunday: Monday tomorrow.
|
|
||||||
.fi
|
|
||||||
.PP
|
|
||||||
That is because \fBtrig()\fR returns the trigger date of
|
|
||||||
the \fIlast\fR trig function that returns true,
|
|
||||||
whereas the value of \fBa\fR is the trigger date of the \fIfirst\fR
|
|
||||||
trig function that returns true.
|
|
||||||
.PP
|
.PP
|
||||||
\fBImportant Note\fR: Because \fBtrig()\fR always returns an absolute
|
\fBImportant Note\fR: Because \fBtrig()\fR always returns an absolute
|
||||||
date, it will \fBnot\fR work properly with a \fBSATISFY\fR clause.
|
date, it will \fBnot\fR work properly with a \fBSATISFY\fR clause.
|
||||||
@@ -4234,6 +4218,14 @@ with square brackets. For example:
|
|||||||
This evaluates the expression "mydate", where "mydate" is
|
This evaluates the expression "mydate", where "mydate" is
|
||||||
presumably some pre-computed variable, and then "pastes" the result
|
presumably some pre-computed variable, and then "pastes" the result
|
||||||
into the command-line for the parser to process.
|
into the command-line for the parser to process.
|
||||||
|
.PP
|
||||||
|
If you want a literal "[" character for some reason, simply use "[[". For
|
||||||
|
example:
|
||||||
|
.PP
|
||||||
|
.nf
|
||||||
|
REM MSG Here are [[square] brackets!
|
||||||
|
.fi
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
A formal description of this is: When \fBRemind\fR encounters a
|
A formal description of this is: When \fBRemind\fR encounters a
|
||||||
"pasted-in" expression, it evaluates the expression, and coerces the
|
"pasted-in" expression, it evaluates the expression, and coerces the
|
||||||
@@ -4781,7 +4773,7 @@ under program control. The format is:
|
|||||||
.PP
|
.PP
|
||||||
\fBDEBUG\fR [+\fIflagson\fR] [\-\fIflagsoff\fR]
|
\fBDEBUG\fR [+\fIflagson\fR] [\-\fIflagsoff\fR]
|
||||||
.PP
|
.PP
|
||||||
\fIFlagson\fR and \fIflagsoff\fR consist of strings of the characters "extvlf"
|
\fIFlagson\fR and \fIflagsoff\fR consist of strings of the characters "extvlfs"
|
||||||
that correspond to the debugging options discussed in the command-line
|
that correspond to the debugging options discussed in the command-line
|
||||||
options section. If preceded with a "+", the corresponding group of
|
options section. If preceded with a "+", the corresponding group of
|
||||||
debugging options is switched on. Otherwise, they are switched off.
|
debugging options is switched on. Otherwise, they are switched off.
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ install:
|
|||||||
@if test "$(PERL)" = "" ; then \
|
@if test "$(PERL)" = "" ; then \
|
||||||
echo "Not installing rem2html; Perl is required"; exit 0; fi; \
|
echo "Not installing rem2html; Perl is required"; exit 0; fi; \
|
||||||
for m in $(PERLMODS_NEEDED) ; \
|
for m in $(PERLMODS_NEEDED) ; \
|
||||||
do \
|
do \
|
||||||
$(PERL) -M$$m -e 1 > /dev/null 2>&1; \
|
$(PERL) -M$$m -e 1 > /dev/null 2>&1; \
|
||||||
if test $$? != 0 ; then echo "Not installing rem2html; missing $$m"; exit 0; fi; \
|
if test $$? != 0 ; then echo "Not installing rem2html; missing $$m"; exit 0; fi; \
|
||||||
done; \
|
done; \
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ REMINDSRCS= calendar.c dynbuf.c dorem.c dosubst.c expr.c files.c funcs.c \
|
|||||||
globals.c hbcal.c init.c main.c md5.c moon.c omit.c queue.c \
|
globals.c hbcal.c init.c main.c md5.c moon.c omit.c queue.c \
|
||||||
sort.c token.c trigger.c userfns.c utils.c var.c
|
sort.c token.c trigger.c userfns.c utils.c var.c
|
||||||
|
|
||||||
REMINDHDRS=config.h custom.h dynbuf.h err.h expr.h globals.h lang.h \
|
REMINDHDRS=config.h custom.h dynbuf.h err.h globals.h lang.h \
|
||||||
md5.h protos.h rem2ps.h types.h version.h
|
md5.h protos.h rem2ps.h types.h version.h
|
||||||
REMINDOBJS= $(REMINDSRCS:.c=.o)
|
REMINDOBJS= $(REMINDSRCS:.c=.o)
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ install: all
|
|||||||
update-desktop-database < /dev/null > /dev/null 2>&1 ; \
|
update-desktop-database < /dev/null > /dev/null 2>&1 ; \
|
||||||
xdg-icon-resource install --novendor --size 64 $(DESTDIR)$(prefix)/share/pixmaps/tkremind.png < /dev/null > /dev/null 2>&1 || true; \
|
xdg-icon-resource install --novendor --size 64 $(DESTDIR)$(prefix)/share/pixmaps/tkremind.png < /dev/null > /dev/null 2>&1 || true; \
|
||||||
xdg-desktop-menu install --novendor $(DESTDIR)$(prefix)/share/applications/tkremind.desktop < /dev/null > /dev/null 2>&1 || true; \
|
xdg-desktop-menu install --novendor $(DESTDIR)$(prefix)/share/applications/tkremind.desktop < /dev/null > /dev/null 2>&1 || true; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install-stripped: install
|
install-stripped: install
|
||||||
strip $(DESTDIR)$(bindir)/remind || true
|
strip $(DESTDIR)$(bindir)/remind || true
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "expr.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
@@ -1670,6 +1669,7 @@ static void GenerateCalEntries(int col)
|
|||||||
case T_Pop: r=PopOmitContext(&p); break;
|
case T_Pop: r=PopOmitContext(&p); break;
|
||||||
case T_Push: r=PushOmitContext(&p); break;
|
case T_Push: r=PushOmitContext(&p); break;
|
||||||
case T_Preserve: r=DoPreserve(&p); break;
|
case T_Preserve: r=DoPreserve(&p); break;
|
||||||
|
case T_Expr: r = DoExpr(&p); break;
|
||||||
case T_RemType: if (tok.val == RUN_TYPE) {
|
case T_RemType: if (tok.val == RUN_TYPE) {
|
||||||
r=DoRun(&p);
|
r=DoRun(&p);
|
||||||
break;
|
break;
|
||||||
@@ -1770,7 +1770,7 @@ static int DoCalRem(ParsePtr p, int col)
|
|||||||
DBufInit(&raw_buf);
|
DBufInit(&raw_buf);
|
||||||
|
|
||||||
/* Parse the trigger date and time */
|
/* Parse the trigger date and time */
|
||||||
if ( (r=ParseRem(p, &trig, &tim, 1)) ) {
|
if ( (r=ParseRem(p, &trig, &tim)) ) {
|
||||||
FreeTrig(&trig);
|
FreeTrig(&trig);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/* Define if utime(file, NULL) sets file's timestamp to the present. */
|
|
||||||
#undef HAVE_UTIME_NULL
|
|
||||||
|
|
||||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
|
||||||
#undef TIME_WITH_SYS_TIME
|
|
||||||
|
|
||||||
/* Define if your <sys/time.h> declares struct tm. */
|
/* Define if your <sys/time.h> declares struct tm. */
|
||||||
#undef TM_IN_SYS_TIME
|
#undef TM_IN_SYS_TIME
|
||||||
|
|
||||||
@@ -16,6 +10,15 @@
|
|||||||
/* Define if you have the <glob.h> header file */
|
/* Define if you have the <glob.h> header file */
|
||||||
#undef HAVE_GLOB_H
|
#undef HAVE_GLOB_H
|
||||||
|
|
||||||
|
/* Define if you have <stdint.h> */
|
||||||
|
#undef HAVE_STDINT_H
|
||||||
|
|
||||||
|
#undef HAVE_STRINGS_H
|
||||||
|
|
||||||
|
#undef HAVE_STRDUP
|
||||||
|
#undef HAVE_STRCASECMP
|
||||||
|
#undef HAVE_STRNCASECMP
|
||||||
|
|
||||||
#undef HAVE_WCTYPE_H
|
#undef HAVE_WCTYPE_H
|
||||||
|
|
||||||
#undef HAVE_LOCALE_H
|
#undef HAVE_LOCALE_H
|
||||||
@@ -42,4 +45,8 @@
|
|||||||
/* The number of bytes in a unsigned long. */
|
/* The number of bytes in a unsigned long. */
|
||||||
#undef SIZEOF_UNSIGNED_LONG
|
#undef SIZEOF_UNSIGNED_LONG
|
||||||
|
|
||||||
|
#define PACKAGE_NAME "@PACKAGE_NAME@"
|
||||||
|
#define PACKAGE_URL "@PACKAGE_URL@"
|
||||||
|
|
||||||
#include "custom.h"
|
#include "custom.h"
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,10 @@
|
|||||||
|
|
||||||
#define PASSTHRU_LEN 32
|
#define PASSTHRU_LEN 32
|
||||||
|
|
||||||
|
#define MAX_RECURSION_LEVEL 1000
|
||||||
|
|
||||||
|
#define MAX_FUNC_ARGS 64
|
||||||
|
|
||||||
#define PSBEGIN "# rem2ps begin"
|
#define PSBEGIN "# rem2ps begin"
|
||||||
#define PSEND "# rem2ps end"
|
#define PSEND "# rem2ps end"
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,10 @@
|
|||||||
|
|
||||||
#define PASSTHRU_LEN 32
|
#define PASSTHRU_LEN 32
|
||||||
|
|
||||||
|
#define MAX_RECURSION_LEVEL 1000
|
||||||
|
|
||||||
|
#define MAX_FUNC_ARGS 64
|
||||||
|
|
||||||
#define PSBEGIN "# rem2ps begin"
|
#define PSBEGIN "# rem2ps begin"
|
||||||
#define PSEND "# rem2ps end"
|
#define PSEND "# rem2ps end"
|
||||||
|
|
||||||
|
|||||||
74
src/dorem.c
74
src/dorem.c
@@ -23,9 +23,8 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "expr.h"
|
|
||||||
|
|
||||||
static int ParseTimeTrig (ParsePtr s, TimeTrig *tim, int save_in_globals);
|
static int ParseTimeTrig (ParsePtr s, TimeTrig *tim);
|
||||||
static int ParseLocalOmit (ParsePtr s, Trigger *t);
|
static int ParseLocalOmit (ParsePtr s, Trigger *t);
|
||||||
static int ParseScanFrom (ParsePtr s, Trigger *t, int type);
|
static int ParseScanFrom (ParsePtr s, Trigger *t, int type);
|
||||||
static int ParsePriority (ParsePtr s, Trigger *t);
|
static int ParsePriority (ParsePtr s, Trigger *t);
|
||||||
@@ -63,7 +62,7 @@ int DoRem(ParsePtr p)
|
|||||||
DBufInit(&buf);
|
DBufInit(&buf);
|
||||||
|
|
||||||
/* Parse the trigger date and time */
|
/* Parse the trigger date and time */
|
||||||
if ( (r=ParseRem(p, &trig, &tim, 1)) ) {
|
if ( (r=ParseRem(p, &trig, &tim)) ) {
|
||||||
FreeTrig(&trig);
|
FreeTrig(&trig);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -163,6 +162,7 @@ int DoRem(ParsePtr p)
|
|||||||
if (p->expr_happened) {
|
if (p->expr_happened) {
|
||||||
if (p->nonconst_expr) {
|
if (p->nonconst_expr) {
|
||||||
PurgeEchoLine("%s\n", "#!P: Next line may have expired, but contains non-constant expression");
|
PurgeEchoLine("%s\n", "#!P: Next line may have expired, but contains non-constant expression");
|
||||||
|
PurgeEchoLine("%s\n", "#!P: or a relative SCANFROM clause");
|
||||||
PurgeEchoLine("%s\n", CurLine);
|
PurgeEchoLine("%s\n", CurLine);
|
||||||
} else {
|
} else {
|
||||||
PurgeEchoLine("%s\n", "#!P: Next line has expired, but contains expression... please verify");
|
PurgeEchoLine("%s\n", "#!P: Next line has expired, but contains expression... please verify");
|
||||||
@@ -220,7 +220,7 @@ int DoRem(ParsePtr p)
|
|||||||
/* trigger structure. */
|
/* trigger structure. */
|
||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim)
|
||||||
{
|
{
|
||||||
register int r;
|
register int r;
|
||||||
DynamicBuffer buf;
|
DynamicBuffer buf;
|
||||||
@@ -262,10 +262,6 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
|||||||
trig->need_wkday = 0;
|
trig->need_wkday = 0;
|
||||||
trig->adj_for_last = 0;
|
trig->adj_for_last = 0;
|
||||||
|
|
||||||
if (save_in_globals) {
|
|
||||||
LastTriggerTime = NO_TIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
int parsing = 1;
|
int parsing = 1;
|
||||||
while(parsing) {
|
while(parsing) {
|
||||||
/* Read space-delimited string */
|
/* Read space-delimited string */
|
||||||
@@ -315,10 +311,6 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
|||||||
trig->m = m;
|
trig->m = m;
|
||||||
trig->d = d;
|
trig->d = d;
|
||||||
tim->ttime = (tok.val % MINUTES_PER_DAY);
|
tim->ttime = (tok.val % MINUTES_PER_DAY);
|
||||||
if (save_in_globals) {
|
|
||||||
LastTriggerTime = tim->ttime;
|
|
||||||
SaveLastTimeTrig(tim);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_WkDay:
|
case T_WkDay:
|
||||||
@@ -355,14 +347,14 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
|||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
if (tim->ttime != NO_TIME) return E_TIME_TWICE;
|
if (tim->ttime != NO_TIME) return E_TIME_TWICE;
|
||||||
tim->ttime = tok.val;
|
tim->ttime = tok.val;
|
||||||
r = ParseTimeTrig(s, tim, save_in_globals);
|
r = ParseTimeTrig(s, tim);
|
||||||
if (r) return r;
|
if (r) return r;
|
||||||
trig->duration_days = ComputeTrigDuration(tim);
|
trig->duration_days = ComputeTrigDuration(tim);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_At:
|
case T_At:
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
r=ParseTimeTrig(s, tim, save_in_globals);
|
r=ParseTimeTrig(s, tim);
|
||||||
if (r) return r;
|
if (r) return r;
|
||||||
trig->duration_days = ComputeTrigDuration(tim);
|
trig->duration_days = ComputeTrigDuration(tim);
|
||||||
break;
|
break;
|
||||||
@@ -481,10 +473,10 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
|||||||
r=ParseToken(s, &buf);
|
r=ParseToken(s, &buf);
|
||||||
if (r) return r;
|
if (r) return r;
|
||||||
StrnCpy(trig->omitfunc, DBufValue(&buf), VAR_NAME_LEN);
|
StrnCpy(trig->omitfunc, DBufValue(&buf), VAR_NAME_LEN);
|
||||||
|
strtolower(trig->omitfunc);
|
||||||
/* An OMITFUNC counts as a nonconst_expr! */
|
/* An OMITFUNC counts as a nonconst_expr! */
|
||||||
s->expr_happened = 1;
|
s->expr_happened = 1;
|
||||||
s->nonconst_expr = 1;
|
s->nonconst_expr = 1;
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -492,6 +484,7 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
|||||||
r=ParseToken(s, &buf);
|
r=ParseToken(s, &buf);
|
||||||
if(r) return r;
|
if(r) return r;
|
||||||
StrnCpy(trig->warn, DBufValue(&buf), VAR_NAME_LEN);
|
StrnCpy(trig->warn, DBufValue(&buf), VAR_NAME_LEN);
|
||||||
|
strtolower(trig->warn);
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -522,9 +515,6 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
|||||||
} else {
|
} else {
|
||||||
tim->duration = NO_TIME;
|
tim->duration = NO_TIME;
|
||||||
}
|
}
|
||||||
if (save_in_globals) {
|
|
||||||
SaveLastTimeTrig(tim);
|
|
||||||
}
|
|
||||||
trig->duration_days = ComputeTrigDuration(tim);
|
trig->duration_days = ComputeTrigDuration(tim);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -536,6 +526,7 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
|||||||
r=ParseToken(s, &buf);
|
r=ParseToken(s, &buf);
|
||||||
if(r) return r;
|
if(r) return r;
|
||||||
StrnCpy(trig->sched, DBufValue(&buf), VAR_NAME_LEN);
|
StrnCpy(trig->sched, DBufValue(&buf), VAR_NAME_LEN);
|
||||||
|
strtolower(trig->sched);
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -608,7 +599,7 @@ int ParseRem(ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals)
|
|||||||
/* ParseTimeTrig - parse the AT part of a timed reminder */
|
/* ParseTimeTrig - parse the AT part of a timed reminder */
|
||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
static int ParseTimeTrig(ParsePtr s, TimeTrig *tim, int save_in_globals)
|
static int ParseTimeTrig(ParsePtr s, TimeTrig *tim)
|
||||||
{
|
{
|
||||||
Token tok;
|
Token tok;
|
||||||
int r;
|
int r;
|
||||||
@@ -643,11 +634,6 @@ static int ParseTimeTrig(ParsePtr s, TimeTrig *tim, int save_in_globals)
|
|||||||
default:
|
default:
|
||||||
if (tim->ttime == NO_TIME) return E_EXPECT_TIME;
|
if (tim->ttime == NO_TIME) return E_EXPECT_TIME;
|
||||||
|
|
||||||
/* Save trigger time in global variable */
|
|
||||||
if (save_in_globals) {
|
|
||||||
LastTriggerTime = tim->ttime;
|
|
||||||
SaveLastTimeTrig(tim);
|
|
||||||
}
|
|
||||||
PushToken(DBufValue(&buf), s);
|
PushToken(DBufValue(&buf), s);
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
return OK;
|
return OK;
|
||||||
@@ -876,6 +862,9 @@ static int ParseScanFrom(ParsePtr s, Trigger *t, int type)
|
|||||||
tok.val = -tok.val;
|
tok.val = -tok.val;
|
||||||
}
|
}
|
||||||
FromDSE(DSEToday - tok.val, &y, &m, &d);
|
FromDSE(DSEToday - tok.val, &y, &m, &d);
|
||||||
|
/* Don't purge reminders with a relative scanfrom */
|
||||||
|
s->expr_happened = 1;
|
||||||
|
s->nonconst_expr = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1284,20 +1273,28 @@ int DoSatRemind(Trigger *trig, TimeTrig *tt, ParsePtr p)
|
|||||||
{
|
{
|
||||||
int iter, dse, r, start;
|
int iter, dse, r, start;
|
||||||
Value v;
|
Value v;
|
||||||
char const *s;
|
expr_node *sat_node;
|
||||||
char const *t;
|
int nonconst = 0;
|
||||||
|
|
||||||
t = p->pos;
|
sat_node = ParseExpr(p, &r);
|
||||||
|
if (r != OK) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (!sat_node) {
|
||||||
|
return E_SWERR;
|
||||||
|
}
|
||||||
iter = 0;
|
iter = 0;
|
||||||
start = trig->scanfrom;
|
start = trig->scanfrom;
|
||||||
while (iter++ < MaxSatIter) {
|
while (iter++ < MaxSatIter) {
|
||||||
dse = ComputeTriggerNoAdjustDuration(start, trig, tt, &r, 1, 0);
|
dse = ComputeTriggerNoAdjustDuration(start, trig, tt, &r, 1, 0);
|
||||||
if (r) {
|
if (r) {
|
||||||
|
free_expr_tree(sat_node);
|
||||||
if (r == E_CANT_TRIG) return OK; else return r;
|
if (r == E_CANT_TRIG) return OK; else return r;
|
||||||
}
|
}
|
||||||
if (dse != start && trig->duration_days) {
|
if (dse != start && trig->duration_days) {
|
||||||
dse = ComputeTriggerNoAdjustDuration(start, trig, tt, &r, 1, trig->duration_days);
|
dse = ComputeTriggerNoAdjustDuration(start, trig, tt, &r, 1, trig->duration_days);
|
||||||
if (r) {
|
if (r) {
|
||||||
|
free_expr_tree(sat_node);
|
||||||
if (r == E_CANT_TRIG) return OK; else return r;
|
if (r == E_CANT_TRIG) return OK; else return r;
|
||||||
}
|
}
|
||||||
} else if (dse == start) {
|
} else if (dse == start) {
|
||||||
@@ -1310,13 +1307,18 @@ int DoSatRemind(Trigger *trig, TimeTrig *tt, ParsePtr p)
|
|||||||
SaveAllTriggerInfo(trig, tt, dse, tt->ttime, 1);
|
SaveAllTriggerInfo(trig, tt, dse, tt->ttime, 1);
|
||||||
}
|
}
|
||||||
if (dse == -1) {
|
if (dse == -1) {
|
||||||
|
free_expr_tree(sat_node);
|
||||||
return E_EXPIRED;
|
return E_EXPIRED;
|
||||||
}
|
}
|
||||||
s = p->pos;
|
r = evaluate_expression(sat_node, NULL, &v, &nonconst);
|
||||||
r = EvaluateExpr(p, &v);
|
if (r) {
|
||||||
t = p->pos;
|
free_expr_tree(sat_node);
|
||||||
if (r) return r;
|
return r;
|
||||||
if (v.type != INT_TYPE && v.type != STR_TYPE) return E_BAD_TYPE;
|
}
|
||||||
|
if (v.type != INT_TYPE && v.type != STR_TYPE) {
|
||||||
|
free_expr_tree(sat_node);
|
||||||
|
return E_BAD_TYPE;
|
||||||
|
}
|
||||||
if ((v.type == INT_TYPE && v.v.val) ||
|
if ((v.type == INT_TYPE && v.v.val) ||
|
||||||
(v.type == STR_TYPE && *v.v.str)) {
|
(v.type == STR_TYPE && *v.v.str)) {
|
||||||
AdjustTriggerForDuration(trig->scanfrom, dse, trig, tt, 1);
|
AdjustTriggerForDuration(trig->scanfrom, dse, trig, tt, 1);
|
||||||
@@ -1341,17 +1343,17 @@ int DoSatRemind(Trigger *trig, TimeTrig *tt, ParsePtr p)
|
|||||||
}
|
}
|
||||||
fprintf(ErrFp, "\n");
|
fprintf(ErrFp, "\n");
|
||||||
}
|
}
|
||||||
|
free_expr_tree(sat_node);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
p->pos = s;
|
|
||||||
if (dse+trig->duration_days < start) {
|
if (dse+trig->duration_days < start) {
|
||||||
start++;
|
start++;
|
||||||
} else {
|
} else {
|
||||||
start = dse+trig->duration_days+1;
|
start = dse+trig->duration_days+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p->pos = t;
|
|
||||||
LastTrigValid = 0;
|
LastTrigValid = 0;
|
||||||
|
free_expr_tree(sat_node);
|
||||||
return E_CANT_TRIG;
|
return E_CANT_TRIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "expr.h"
|
#include "types.h"
|
||||||
#define L_IN_DOSUBST
|
#define L_IN_DOSUBST
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
@@ -242,7 +241,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i < 64) {
|
if (i < 64) {
|
||||||
*ss++ = c;
|
*ss++ = tolower(c);
|
||||||
*ss = 0;
|
*ss = 0;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -269,10 +268,10 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
done = 0;
|
done = 0;
|
||||||
snprintf(uf, sizeof(uf), "subst_%c", c);
|
snprintf(uf, sizeof(uf), "subst_%c", tolower(c));
|
||||||
if (UserFuncExists(uf) == 3) {
|
if (UserFuncExists(uf) == 3) {
|
||||||
snprintf(s, sizeof(s), "subst_%c(%d,'%04d-%02d-%02d',%02d:%02d)",
|
snprintf(s, sizeof(s), "subst_%c(%d,'%04d-%02d-%02d',%02d:%02d)",
|
||||||
c, altmode ? 1 : 0, y, m+1, d, h, min);
|
tolower(c), altmode ? 1 : 0, y, m+1, d, h, min);
|
||||||
expr = (char const *) s;
|
expr = (char const *) s;
|
||||||
r = EvalExpr(&expr, &v, NULL);
|
r = EvalExpr(&expr, &v, NULL);
|
||||||
if (r == OK) {
|
if (r == OK) {
|
||||||
@@ -344,10 +343,10 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
|
|||||||
|
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
snprintf(uf, sizeof(uf), "subst_%cx", c);
|
snprintf(uf, sizeof(uf), "subst_%cx", tolower(c));
|
||||||
if (UserFuncExists(uf) == 3) {
|
if (UserFuncExists(uf) == 3) {
|
||||||
snprintf(s, sizeof(s), "subst_%cx(%d,'%04d-%02d-%02d',%02d:%02d)",
|
snprintf(s, sizeof(s), "subst_%cx(%d,'%04d-%02d-%02d',%02d:%02d)",
|
||||||
c, altmode ? 1 : 0, y, m+1, d, h, min);
|
tolower(c), altmode ? 1 : 0, y, m+1, d, h, min);
|
||||||
expr = (char const *) s;
|
expr = (char const *) s;
|
||||||
r = EvalExpr(&expr, &v, NULL);
|
r = EvalExpr(&expr, &v, NULL);
|
||||||
if (r == OK) {
|
if (r == OK) {
|
||||||
|
|||||||
@@ -124,7 +124,9 @@ int DBufPuts(DynamicBuffer *dbuf, char const *str)
|
|||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
void DBufFree(DynamicBuffer *dbuf)
|
void DBufFree(DynamicBuffer *dbuf)
|
||||||
{
|
{
|
||||||
if (dbuf->buffer != dbuf->staticBuf) free(dbuf->buffer);
|
if (dbuf->buffer != NULL && dbuf->buffer != dbuf->staticBuf) {
|
||||||
|
free(dbuf->buffer);
|
||||||
|
}
|
||||||
DBufInit(dbuf);
|
DBufInit(dbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
216
src/err.h
216
src/err.h
@@ -122,6 +122,9 @@
|
|||||||
#define E_TIME_TWICE 102
|
#define E_TIME_TWICE 102
|
||||||
#define E_DURATION_NO_AT 103
|
#define E_DURATION_NO_AT 103
|
||||||
#define E_EXPECTING_WEEKDAY 104
|
#define E_EXPECTING_WEEKDAY 104
|
||||||
|
#define E_REPEATED_ARG 105
|
||||||
|
#define E_EXPR_DISABLED 106
|
||||||
|
#define E_TIME_EXCEEDED 107
|
||||||
|
|
||||||
#ifdef MK_GLOBALS
|
#ifdef MK_GLOBALS
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
@@ -140,111 +143,114 @@ EXTERN char *ErrMsg[]
|
|||||||
|
|
||||||
#ifdef MK_GLOBALS
|
#ifdef MK_GLOBALS
|
||||||
= {
|
= {
|
||||||
"Ok",
|
/* OK */ "Ok",
|
||||||
"Missing ']'",
|
/* E_MISS_END */ "Missing ']'",
|
||||||
"Missing quote",
|
/* E_MISS_QUOTE */ "Missing quote",
|
||||||
"Expression too complex - too many operators",
|
/* E_OP_STK_OVER */ "Expression too complex",
|
||||||
"Expression too complex - too many operands",
|
/* E_VA_STK_OVER */ "Expression too complex - too many operands",
|
||||||
"Missing ')'",
|
/* E_MISS_RIGHT_PAREN */ "Missing ')'",
|
||||||
"Undefined function",
|
/* E_UNDEF_FUNC */ "Undefined function",
|
||||||
"Illegal character",
|
/* E_ILLEGAL_CHAR */ "Illegal character",
|
||||||
"Expecting binary operator",
|
/* E_EXPECTING_BINOP */ "Expecting binary operator",
|
||||||
"Out of memory",
|
/* E_NO_MEM */ "Out of memory",
|
||||||
"Ill-formed number",
|
/* E_BAD_NUMBER */ "Ill-formed number",
|
||||||
"Op stack underflow - internal error",
|
/* E_OP_STK_UNDER */ "Op stack underflow - internal error",
|
||||||
"Va stack underflow - internal error",
|
/* E_VA_STK_UNDER */ "Va stack underflow - internal error",
|
||||||
"Can't coerce",
|
/* E_CANT_COERCE */ "Can't coerce",
|
||||||
"Type mismatch",
|
/* E_BAD_TYPE */ "Type mismatch",
|
||||||
"Date overflow",
|
/* E_DATE_OVER */ "Date overflow",
|
||||||
"Stack error - internal error",
|
/* E_STACK_ERR */ "Stack error - internal error",
|
||||||
"Division by zero",
|
/* E_DIV_ZERO */ "Division by zero",
|
||||||
"Undefined variable",
|
/* E_NOSUCH_VAR */ "Undefined variable",
|
||||||
"Unexpected end of line",
|
/* E_EOLN */ "Unexpected end of line",
|
||||||
"Unexpected end of file",
|
/* E_EOF */ "Unexpected end of file",
|
||||||
"I/O error",
|
/* E_IO_ERR */ "I/O error",
|
||||||
"Line too long",
|
/* E_LINE_2_LONG */ "Line too long",
|
||||||
"Internal error",
|
/* E_SWERR */ "Internal error",
|
||||||
"Bad date specification",
|
/* E_BAD_DATE */ "Bad date specification",
|
||||||
"Not enough arguments",
|
/* E_2FEW_ARGS */ "Not enough arguments",
|
||||||
"Too many arguments",
|
/* E_2MANY_ARGS */ "Too many arguments",
|
||||||
"Ill-formed time",
|
/* E_BAD_TIME */ "Ill-formed time",
|
||||||
"Number too high",
|
/* E_2HIGH */ "Number too high",
|
||||||
"Number too low",
|
/* E_2LOW */ "Number too low",
|
||||||
"Can't open file",
|
/* E_CANT_OPEN */ "Can't open file",
|
||||||
"INCLUDE nested too deeply (max. " STR(INCLUDE_NEST) ")",
|
/* E_NESTED_INCLUDE */ "INCLUDE nested too deeply (max. " STR(INCLUDE_NEST) ")",
|
||||||
"Parse error",
|
/* E_PARSE_ERR */ "Parse error",
|
||||||
"Can't compute trigger",
|
/* E_CANT_TRIG */ "Can't compute trigger",
|
||||||
"Too many nested IFs",
|
/* E_NESTED_IF */ "Too many nested IFs",
|
||||||
"ELSE with no matching IF",
|
/* E_ELSE_NO_IF */ "ELSE with no matching IF",
|
||||||
"ENDIF with no matching IF",
|
/* E_ENDIF_NO_IF */ "ENDIF with no matching IF",
|
||||||
"Can't OMIT every weekday",
|
/* E_2MANY_LOCALOMIT */ "Can't OMIT every weekday",
|
||||||
"Extraneous token(s) on line",
|
/* E_EXTRANEOUS_TOKEN */ "Extraneous token(s) on line",
|
||||||
"POP-OMIT-CONTEXT without matching PUSH-OMIT-CONTEXT",
|
/* E_POP_NO_PUSH */ "POP-OMIT-CONTEXT without matching PUSH-OMIT-CONTEXT",
|
||||||
"RUN disabled",
|
/* E_RUN_DISABLED */ "RUN disabled",
|
||||||
"Domain error",
|
/* E_DOMAIN_ERR */ "Domain error",
|
||||||
"Invalid identifier",
|
/* E_BAD_ID */ "Invalid identifier",
|
||||||
"Recursive function call detected",
|
/* E_RECURSIVE */ "Too many recursive function calls",
|
||||||
"",
|
/* E_PARSE_AS_REM */ "",
|
||||||
"Cannot modify system variable",
|
/* E_CANT_MODIFY */ "Cannot modify system variable",
|
||||||
"C library function can't represent date/time",
|
/* E_MKTIME_PROBLEM */ "C library function can't represent date/time",
|
||||||
"Attempt to redefine built-in function",
|
/* E_REDEF_FUNC */ "Attempt to redefine built-in function",
|
||||||
"Can't nest function definition in expression",
|
/* E_CANTNEST_FDEF */ "Can't nest function definition in expression",
|
||||||
"Must fully specify date to use repeat factor",
|
/* E_REP_FULSPEC */ "Must fully specify date to use repeat factor",
|
||||||
"Year specified twice",
|
/* E_YR_TWICE */ "Year specified twice",
|
||||||
"Month specified twice",
|
/* E_MON_TWICE */ "Month specified twice",
|
||||||
"Day specified twice",
|
/* E_DAY_TWICE */ "Day specified twice",
|
||||||
"Unknown token",
|
/* E_UNKNOWN_TOKEN */ "Unknown token",
|
||||||
"Must specify month in OMIT command",
|
/* E_SPEC_MON */ "Must specify month in OMIT command",
|
||||||
"Too many partial OMITs (max. " STR(MAX_PARTIAL_OMITS) ")",
|
/* E_2MANY_PART */ "Too many partial OMITs (max. " STR(MAX_PARTIAL_OMITS) ")",
|
||||||
"Too many full OMITs (max. " STR(MAX_FULL_OMITS) ")",
|
/* E_2MANY_FULL */ "Too many full OMITs (max. " STR(MAX_FULL_OMITS) ")",
|
||||||
"Warning: PUSH-OMIT-CONTEXT without matching POP-OMIT-CONTEXT",
|
/* E_PUSH_NOPOP */ "Warning: PUSH-OMIT-CONTEXT without matching POP-OMIT-CONTEXT",
|
||||||
"Error reading",
|
/* E_ERR_READING */ "Error reading",
|
||||||
"Expecting end-of-line",
|
/* E_EXPECTING_EOL */ "Expecting end-of-line",
|
||||||
"Invalid Hebrew date",
|
/* E_BAD_HEBDATE */ "Invalid Hebrew date",
|
||||||
"IIF needs odd number of arguments",
|
/* E_IIF_ODD */ "IIF needs odd number of arguments",
|
||||||
"Warning: Missing ENDIF",
|
/* E_MISS_ENDIF */ "Warning: Missing ENDIF",
|
||||||
"Expecting comma",
|
/* E_EXPECT_COMMA */ "Expecting comma",
|
||||||
"Weekday specified twice",
|
/* E_WD_TWICE */ "Weekday specified twice",
|
||||||
"Only use one of BEFORE, AFTER or SKIP",
|
/* E_SKIP_ERR */ "Only use one of BEFORE, AFTER or SKIP",
|
||||||
"Can't nest MSG, MSF, RUN, etc. in expression",
|
/* E_CANT_NEST_RTYPE */ "Can't nest MSG, MSF, RUN, etc. in expression",
|
||||||
"Repeat value specified twice",
|
/* E_REP_TWICE */ "Repeat value specified twice",
|
||||||
"Delta value specified twice",
|
/* E_DELTA_TWICE */ "Delta value specified twice",
|
||||||
"Back value specified twice",
|
/* E_BACK_TWICE */ "Back value specified twice",
|
||||||
"ONCE keyword used twice. (Hah.)",
|
/* E_ONCE_TWICE */ "ONCE keyword used twice. (Hah.)",
|
||||||
"Expecting time after AT",
|
/* E_EXPECT_TIME */ "Expecting time after AT",
|
||||||
"THROUGH/UNTIL keyword used twice",
|
/* E_UNTIL_TWICE */ "THROUGH/UNTIL keyword used twice",
|
||||||
"Incomplete date specification",
|
/* E_INCOMPLETE */ "Incomplete date specification",
|
||||||
"FROM/SCANFROM keyword used twice",
|
/* E_SCAN_TWICE */ "FROM/SCANFROM keyword used twice",
|
||||||
"Variable",
|
/* E_VAR */ "Variable",
|
||||||
"Value",
|
/* E_VAL */ "Value",
|
||||||
"*UNDEFINED*",
|
/* E_UNDEF */ "*UNDEFINED*",
|
||||||
"Entering UserFN",
|
/* E_ENTER_FUN */ "Entering UserFN",
|
||||||
"Leaving UserFN",
|
/* E_LEAVE_FUN */ "Leaving UserFN",
|
||||||
"Expired",
|
/* E_EXPIRED */ "Expired",
|
||||||
"fork() failed - can't do queued reminders",
|
/* E_CANTFORK */ "fork() failed - can't do queued reminders",
|
||||||
"Can't access file",
|
/* E_CANTACCESS */ "Can't access file",
|
||||||
"Illegal system date: Year is less than %d\n",
|
/* M_BAD_SYS_DATE */ "Illegal system date: Year is less than %d\n",
|
||||||
"Unknown debug flag '%c'\n",
|
/* M_BAD_DB_FLAG */ "Unknown debug flag '%c'\n",
|
||||||
"Unknown option '%c'\n",
|
/* M_BAD_OPTION */ "Unknown option '%c'\n",
|
||||||
"Unknown user '%s'\n",
|
/* M_BAD_USER */ "Unknown user '%s'\n",
|
||||||
"Could not change gid to %d\n",
|
/* M_NO_CHG_GID */ "Could not change gid to %d\n",
|
||||||
"Could not change uid to %d\n",
|
/* M_NO_CHG_UID */ "Could not change uid to %d\n",
|
||||||
"Out of memory for environment\n",
|
/* M_NOMEM_ENV */ "Out of memory for environment\n",
|
||||||
"Missing '=' sign",
|
/* E_MISS_EQ */ "Missing '=' sign",
|
||||||
"Missing variable name",
|
/* E_MISS_VAR */ "Missing variable name",
|
||||||
"Missing expression",
|
/* E_MISS_EXPR */ "Missing expression",
|
||||||
"Can't reset access date of %s\n",
|
/* M_CANTSET_ACCESS */ "Can't reset access date of %s\n",
|
||||||
"Remind: '-i' option: %s\n",
|
/* M_I_OPTION */ "Remind: '-i' option: %s\n",
|
||||||
"No reminders.",
|
/* E_NOREMINDERS */ "No reminders.",
|
||||||
"%d reminder(s) queued for later today.\n",
|
/* M_QUEUED */ "%d reminder(s) queued for later today.\n",
|
||||||
"Expecting number",
|
/* E_EXPECTING_NUMBER */ "Expecting number",
|
||||||
"Bad function in WARN clause",
|
/* M_BAD_WARN_FUNC */ "Bad function in WARN clause",
|
||||||
"Can't convert between time zones",
|
/* E_CANT_CONVERT_TZ */ "Can't convert between time zones",
|
||||||
"No files matching *.rem",
|
/* E_NO_MATCHING_REMS */ "No files matching *.rem",
|
||||||
"String too long",
|
/* E_STRING_TOO_LONG */ "String too long",
|
||||||
"Time specified twice",
|
/* E_TIME_TWICE */ "Time specified twice",
|
||||||
"Cannot specify DURATION without specifying AT",
|
/* E_DURATION_NO_AT */ "Cannot specify DURATION without specifying AT",
|
||||||
"Expecting weekday name"
|
/* E_EXPECTING_WEEKDAY */ "Expecting weekday name",
|
||||||
|
/* E_REPEATED_ARG */ "Duplicate argument name",
|
||||||
|
/* E_EXPR_DISABLED */ "Expression evaluation is disabled",
|
||||||
|
/* E_TIME_EXCEEDED */ "Time limit for expression evaluation exceeded",
|
||||||
}
|
}
|
||||||
#endif /* MK_GLOBALS */
|
#endif /* MK_GLOBALS */
|
||||||
;
|
;
|
||||||
|
|||||||
3679
src/expr.c
3679
src/expr.c
File diff suppressed because it is too large
Load Diff
67
src/expr.h
67
src/expr.h
@@ -1,67 +0,0 @@
|
|||||||
/***************************************************************/
|
|
||||||
/* */
|
|
||||||
/* EXPR.H */
|
|
||||||
/* */
|
|
||||||
/* Contains a few definitions used by expression evaluator. */
|
|
||||||
/* */
|
|
||||||
/* This file is part of REMIND. */
|
|
||||||
/* Copyright (C) 1992-2024 by Dianne Skoll */
|
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
|
||||||
|
|
||||||
/* Define the types of values */
|
|
||||||
#define ERR_TYPE 0
|
|
||||||
#define INT_TYPE 1
|
|
||||||
#define TIME_TYPE 2
|
|
||||||
#define DATE_TYPE 3
|
|
||||||
#define STR_TYPE 4
|
|
||||||
#define DATETIME_TYPE 5
|
|
||||||
#define SPECIAL_TYPE 6 /* Only for system variables */
|
|
||||||
#define CONST_INT_TYPE 7 /* Only for system variables */
|
|
||||||
|
|
||||||
/* Define stuff for parsing expressions */
|
|
||||||
#define BEG_OF_EXPR '['
|
|
||||||
#define END_OF_EXPR ']'
|
|
||||||
#define COMMA ','
|
|
||||||
|
|
||||||
#define UN_OP 0 /* Unary operator */
|
|
||||||
#define BIN_OP 1 /* Binary Operator */
|
|
||||||
#define FUNC 2 /* Function */
|
|
||||||
|
|
||||||
/* Make the pushing and popping of values and operators in-line code
|
|
||||||
for speed. BEWARE: These macros invoke return if an error happens ! */
|
|
||||||
|
|
||||||
#define PushOpStack(op) \
|
|
||||||
do { if (OpStackPtr >= OP_STACK_SIZE) return E_OP_STK_OVER; \
|
|
||||||
else { OpStack[OpStackPtr++] = (op); if (OpStackPtr > OpStackHiWater) OpStackHiWater = OpStackPtr; } } while(0)
|
|
||||||
|
|
||||||
#define PopOpStack(op) \
|
|
||||||
if (OpStackPtr <= 0) \
|
|
||||||
return E_OP_STK_UNDER; \
|
|
||||||
else \
|
|
||||||
(op) = OpStack[--OpStackPtr]
|
|
||||||
|
|
||||||
#define PushValStack(val) \
|
|
||||||
do { if (ValStackPtr >= VAL_STACK_SIZE) { \
|
|
||||||
DestroyValue(val); \
|
|
||||||
return E_VA_STK_OVER; \
|
|
||||||
} else { \
|
|
||||||
ValStack[ValStackPtr++] = (val); \
|
|
||||||
if (ValStackPtr > ValStackHiWater) ValStackHiWater = ValStackPtr; \
|
|
||||||
} } while (0);
|
|
||||||
|
|
||||||
#define PopValStack(val) \
|
|
||||||
if (ValStackPtr <= 0) \
|
|
||||||
return E_VA_STK_UNDER; \
|
|
||||||
else \
|
|
||||||
(val) = ValStack[--ValStackPtr]
|
|
||||||
|
|
||||||
/* These functions are in utils.c and are used to detect overflow
|
|
||||||
in various arithmetic operators. They have to be in separate
|
|
||||||
functions with extern linkage to defeat compiler optimizations
|
|
||||||
that would otherwise break the overflow checks. */
|
|
||||||
extern int _private_mul_overflow(int a, int b);
|
|
||||||
extern int _private_add_overflow(int a, int b);
|
|
||||||
extern int _private_sub_overflow(int a, int b);
|
|
||||||
|
|
||||||
12
src/files.c
12
src/files.c
@@ -79,6 +79,7 @@ typedef struct {
|
|||||||
int LineNo;
|
int LineNo;
|
||||||
unsigned int IfFlags;
|
unsigned int IfFlags;
|
||||||
int NumIfs;
|
int NumIfs;
|
||||||
|
int IfLinenos[IF_NEST];
|
||||||
long offset;
|
long offset;
|
||||||
CachedLine *CLine;
|
CachedLine *CLine;
|
||||||
int ownedByMe;
|
int ownedByMe;
|
||||||
@@ -526,8 +527,14 @@ static int NextChainedFile(IncludeStruct *i)
|
|||||||
static int PopFile(void)
|
static int PopFile(void)
|
||||||
{
|
{
|
||||||
IncludeStruct *i;
|
IncludeStruct *i;
|
||||||
|
int j;
|
||||||
|
|
||||||
if (!Hush && NumIfs) Eprint("%s", ErrMsg[E_MISS_ENDIF]);
|
if (!Hush && NumIfs) {
|
||||||
|
Eprint("%s", ErrMsg[E_MISS_ENDIF]);
|
||||||
|
for (j=NumIfs-1; j >=0; j--) {
|
||||||
|
fprintf(ErrFp, "%s(%d): IF without ENDIF\n", FileName, IfLinenos[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!IStackPtr) return E_EOF;
|
if (!IStackPtr) return E_EOF;
|
||||||
i = &IStack[IStackPtr-1];
|
i = &IStack[IStackPtr-1];
|
||||||
|
|
||||||
@@ -547,6 +554,7 @@ static int PopFile(void)
|
|||||||
|
|
||||||
LineNo = i->LineNo;
|
LineNo = i->LineNo;
|
||||||
IfFlags = i->IfFlags;
|
IfFlags = i->IfFlags;
|
||||||
|
memcpy(IfLinenos, i->IfLinenos, IF_NEST);
|
||||||
NumIfs = i->NumIfs;
|
NumIfs = i->NumIfs;
|
||||||
CLine = i->CLine;
|
CLine = i->CLine;
|
||||||
fp = NULL;
|
fp = NULL;
|
||||||
@@ -871,6 +879,7 @@ static int IncludeCmd(char const *cmd)
|
|||||||
i->LineNo = LineNo;
|
i->LineNo = LineNo;
|
||||||
i->NumIfs = NumIfs;
|
i->NumIfs = NumIfs;
|
||||||
i->IfFlags = IfFlags;
|
i->IfFlags = IfFlags;
|
||||||
|
memcpy(i->IfLinenos, IfLinenos, IF_NEST);
|
||||||
i->CLine = CLine;
|
i->CLine = CLine;
|
||||||
i->offset = -1L;
|
i->offset = -1L;
|
||||||
i->chain = NULL;
|
i->chain = NULL;
|
||||||
@@ -973,6 +982,7 @@ int IncludeFile(char const *fname)
|
|||||||
i->LineNo = LineNo;
|
i->LineNo = LineNo;
|
||||||
i->NumIfs = NumIfs;
|
i->NumIfs = NumIfs;
|
||||||
i->IfFlags = IfFlags;
|
i->IfFlags = IfFlags;
|
||||||
|
memcpy(i->IfLinenos, IfLinenos, IF_NEST);
|
||||||
i->CLine = CLine;
|
i->CLine = CLine;
|
||||||
i->offset = -1L;
|
i->offset = -1L;
|
||||||
i->chain = NULL;
|
i->chain = NULL;
|
||||||
|
|||||||
579
src/funcs.c
579
src/funcs.c
@@ -23,6 +23,11 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
#include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@@ -49,12 +54,13 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "expr.h"
|
|
||||||
|
|
||||||
/* Defines that used to be static variables */
|
/* Defines that used to be static variables */
|
||||||
#define Nargs (info->nargs)
|
#define Nargs (info->nargs)
|
||||||
#define RetVal (info->retval)
|
#define RetVal (info->retval)
|
||||||
|
|
||||||
|
#define DBG(x) do { if (DebugFlag & DB_PRTEXPR) { x; } } while(0)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
solstice_equinox_for_year(int y, int which);
|
solstice_equinox_for_year(int y, int which);
|
||||||
|
|
||||||
@@ -69,7 +75,7 @@ static int FArgs (func_info *);
|
|||||||
static int FAsc (func_info *);
|
static int FAsc (func_info *);
|
||||||
static int FBaseyr (func_info *);
|
static int FBaseyr (func_info *);
|
||||||
static int FChar (func_info *);
|
static int FChar (func_info *);
|
||||||
static int FChoose (func_info *);
|
static int FChoose (expr_node *, Value *, Value *, int *);
|
||||||
static int FCoerce (func_info *);
|
static int FCoerce (func_info *);
|
||||||
static int FColumns (func_info *);
|
static int FColumns (func_info *);
|
||||||
static int FCurrent (func_info *);
|
static int FCurrent (func_info *);
|
||||||
@@ -96,7 +102,7 @@ static int FHebyear (func_info *);
|
|||||||
static int FHour (func_info *);
|
static int FHour (func_info *);
|
||||||
static int FHtmlEscape (func_info *);
|
static int FHtmlEscape (func_info *);
|
||||||
static int FHtmlStriptags (func_info *);
|
static int FHtmlStriptags (func_info *);
|
||||||
static int FIif (func_info *);
|
static int FIif (expr_node *, Value *, Value *, int *);
|
||||||
static int FIndex (func_info *);
|
static int FIndex (func_info *);
|
||||||
static int FIsAny (func_info *);
|
static int FIsAny (func_info *);
|
||||||
static int FIsdst (func_info *);
|
static int FIsdst (func_info *);
|
||||||
@@ -175,14 +181,9 @@ static int FWkday (func_info *);
|
|||||||
static int FWkdaynum (func_info *);
|
static int FWkdaynum (func_info *);
|
||||||
static int FYear (func_info *);
|
static int FYear (func_info *);
|
||||||
|
|
||||||
static int CleanUpAfterFunc (func_info *);
|
|
||||||
static int CheckArgs (BuiltinFunc *f, int nargs);
|
|
||||||
static int SunStuff (int rise, double cosz, int dse);
|
static int SunStuff (int rise, double cosz, int dse);
|
||||||
static int tz_set_tz (char const *tz);
|
static int tz_set_tz (char const *tz);
|
||||||
|
|
||||||
/* "Overload" the struct Operator definition */
|
|
||||||
#define NO_MAX 127
|
|
||||||
|
|
||||||
/* Caches for extracting months, days, years from dates - may
|
/* Caches for extracting months, days, years from dates - may
|
||||||
improve performance slightly. */
|
improve performance slightly. */
|
||||||
static int CacheDse = -1;
|
static int CacheDse = -1;
|
||||||
@@ -191,14 +192,9 @@ static int CacheYear, CacheMon, CacheDay;
|
|||||||
static int CacheHebDse = -1;
|
static int CacheHebDse = -1;
|
||||||
static int CacheHebYear, CacheHebMon, CacheHebDay;
|
static int CacheHebYear, CacheHebMon, CacheHebDay;
|
||||||
|
|
||||||
/* We need access to the value stack */
|
|
||||||
extern Value ValStack[];
|
|
||||||
extern int ValStackPtr;
|
|
||||||
extern int ValStackHiWater;
|
|
||||||
|
|
||||||
/* Macro for accessing arguments from the value stack - args are numbered
|
/* Macro for accessing arguments from the value stack - args are numbered
|
||||||
from 0 to (Nargs - 1) */
|
from 0 to (Nargs - 1) */
|
||||||
#define ARG(x) (ValStack[ValStackPtr - Nargs + (x)])
|
#define ARG(x) (info->args[x])
|
||||||
|
|
||||||
#define ARGV(x) ARG(x).v.val
|
#define ARGV(x) ARG(x).v.val
|
||||||
#define ARGSTR(x) ARG(x).v.str
|
#define ARGSTR(x) ARG(x).v.str
|
||||||
@@ -226,215 +222,127 @@ extern int ValStackHiWater;
|
|||||||
|
|
||||||
/* The array holding the built-in functions. */
|
/* The array holding the built-in functions. */
|
||||||
BuiltinFunc Func[] = {
|
BuiltinFunc Func[] = {
|
||||||
/* Name minargs maxargs is_constant func */
|
/* Name minargs maxargs is_constant func newfunc*/
|
||||||
|
|
||||||
{ "abs", 1, 1, 1, FAbs },
|
{ "abs", 1, 1, 1, FAbs, NULL },
|
||||||
{ "access", 2, 2, 0, FAccess },
|
{ "access", 2, 2, 0, FAccess, NULL },
|
||||||
{ "adawn", 0, 1, 0, FADawn},
|
{ "adawn", 0, 1, 0, FADawn, NULL},
|
||||||
{ "adusk", 0, 1, 0, FADusk},
|
{ "adusk", 0, 1, 0, FADusk, NULL},
|
||||||
{ "ampm", 1, 3, 1, FAmpm },
|
{ "ampm", 1, 3, 1, FAmpm, NULL },
|
||||||
{ "ansicolor", 1, 5, 1, FAnsicolor },
|
{ "ansicolor", 1, 5, 1, FAnsicolor, NULL },
|
||||||
{ "args", 1, 1, 0, FArgs },
|
{ "args", 1, 1, 0, FArgs, NULL },
|
||||||
{ "asc", 1, 1, 1, FAsc },
|
{ "asc", 1, 1, 1, FAsc, NULL },
|
||||||
{ "baseyr", 0, 0, 1, FBaseyr },
|
{ "baseyr", 0, 0, 1, FBaseyr, NULL },
|
||||||
{ "char", 1, NO_MAX, 1, FChar },
|
{ "char", 1, NO_MAX, 1, FChar, NULL },
|
||||||
{ "choose", 2, NO_MAX, 1, FChoose },
|
{ "choose", 2, NO_MAX, 1, NULL, FChoose }, /*NEW-STYLE*/
|
||||||
{ "coerce", 2, 2, 1, FCoerce },
|
{ "coerce", 2, 2, 1, FCoerce, NULL },
|
||||||
{ "columns", 0, 1, 0, FColumns },
|
{ "columns", 0, 1, 0, FColumns, NULL },
|
||||||
{ "current", 0, 0, 0, FCurrent },
|
{ "current", 0, 0, 0, FCurrent, NULL },
|
||||||
{ "date", 3, 3, 1, FDate },
|
{ "date", 3, 3, 1, FDate, NULL },
|
||||||
{ "datepart", 1, 1, 1, FDatepart },
|
{ "datepart", 1, 1, 1, FDatepart, NULL },
|
||||||
{ "datetime", 2, 5, 1, FDateTime },
|
{ "datetime", 2, 5, 1, FDateTime, NULL },
|
||||||
{ "dawn", 0, 1, 0, FDawn},
|
{ "dawn", 0, 1, 0, FDawn, NULL },
|
||||||
{ "day", 1, 1, 1, FDay },
|
{ "day", 1, 1, 1, FDay, NULL },
|
||||||
{ "daysinmon", 2, 2, 1, FDaysinmon },
|
{ "daysinmon", 2, 2, 1, FDaysinmon, NULL },
|
||||||
{ "defined", 1, 1, 0, FDefined },
|
{ "defined", 1, 1, 0, FDefined, NULL },
|
||||||
{ "dosubst", 1, 3, 0, FDosubst },
|
{ "dosubst", 1, 3, 0, FDosubst, NULL },
|
||||||
{ "dusk", 0, 1, 0, FDusk },
|
{ "dusk", 0, 1, 0, FDusk, NULL },
|
||||||
{ "easterdate", 0, 1, 0, FEasterdate },
|
{ "easterdate", 0, 1, 0, FEasterdate, NULL },
|
||||||
{ "evaltrig", 1, 2, 0, FEvalTrig },
|
{ "evaltrig", 1, 2, 0, FEvalTrig, NULL },
|
||||||
{ "filedate", 1, 1, 0, FFiledate },
|
{ "filedate", 1, 1, 0, FFiledate, NULL },
|
||||||
{ "filedatetime", 1, 1, 0, FFiledatetime },
|
{ "filedatetime", 1, 1, 0, FFiledatetime, NULL },
|
||||||
{ "filedir", 0, 0, 0, FFiledir },
|
{ "filedir", 0, 0, 0, FFiledir, NULL },
|
||||||
{ "filename", 0, 0, 0, FFilename },
|
{ "filename", 0, 0, 0, FFilename, NULL },
|
||||||
{ "getenv", 1, 1, 0, FGetenv },
|
{ "getenv", 1, 1, 0, FGetenv, NULL },
|
||||||
{ "hebdate", 2, 5, 0, FHebdate },
|
{ "hebdate", 2, 5, 0, FHebdate, NULL },
|
||||||
{ "hebday", 1, 1, 0, FHebday },
|
{ "hebday", 1, 1, 0, FHebday, NULL },
|
||||||
{ "hebmon", 1, 1, 0, FHebmon },
|
{ "hebmon", 1, 1, 0, FHebmon, NULL },
|
||||||
{ "hebyear", 1, 1, 0, FHebyear },
|
{ "hebyear", 1, 1, 0, FHebyear, NULL },
|
||||||
{ "hour", 1, 1, 1, FHour },
|
{ "hour", 1, 1, 1, FHour, NULL },
|
||||||
{ "htmlescape", 1, 1, 1, FHtmlEscape },
|
{ "htmlescape", 1, 1, 1, FHtmlEscape, NULL },
|
||||||
{ "htmlstriptags",1, 1, 1, FHtmlStriptags },
|
{ "htmlstriptags",1, 1, 1, FHtmlStriptags, NULL },
|
||||||
{ "iif", 1, NO_MAX, 1, FIif },
|
{ "iif", 1, NO_MAX, 1, NULL, FIif }, /*NEW-STYLE*/
|
||||||
{ "index", 2, 3, 1, FIndex },
|
{ "index", 2, 3, 1, FIndex, NULL },
|
||||||
{ "isany", 1, NO_MAX, 1, FIsAny },
|
{ "isany", 1, NO_MAX, 1, FIsAny, NULL },
|
||||||
{ "isdst", 0, 2, 0, FIsdst },
|
{ "isdst", 0, 2, 0, FIsdst, NULL },
|
||||||
{ "isleap", 1, 1, 1, FIsleap },
|
{ "isleap", 1, 1, 1, FIsleap, NULL },
|
||||||
{ "isomitted", 1, 1, 0, FIsomitted },
|
{ "isomitted", 1, 1, 0, FIsomitted, NULL },
|
||||||
{ "language", 0, 0, 1, FLanguage },
|
{ "language", 0, 0, 1, FLanguage, NULL },
|
||||||
{ "localtoutc", 1, 1, 1, FLocalToUTC },
|
{ "localtoutc", 1, 1, 1, FLocalToUTC, NULL },
|
||||||
{ "lower", 1, 1, 1, FLower },
|
{ "lower", 1, 1, 1, FLower, NULL },
|
||||||
{ "max", 1, NO_MAX, 1, FMax },
|
{ "max", 1, NO_MAX, 1, FMax, NULL },
|
||||||
{ "min", 1, NO_MAX, 1, FMin },
|
{ "min", 1, NO_MAX, 1, FMin, NULL },
|
||||||
{ "minsfromutc", 0, 2, 0, FMinsfromutc },
|
{ "minsfromutc", 0, 2, 0, FMinsfromutc, NULL },
|
||||||
{ "minute", 1, 1, 1, FMinute },
|
{ "minute", 1, 1, 1, FMinute, NULL },
|
||||||
{ "mon", 1, 1, 1, FMon },
|
{ "mon", 1, 1, 1, FMon, NULL },
|
||||||
{ "monnum", 1, 1, 1, FMonnum },
|
{ "monnum", 1, 1, 1, FMonnum, NULL },
|
||||||
{ "moondate", 1, 3, 0, FMoondate },
|
{ "moondate", 1, 3, 0, FMoondate, NULL },
|
||||||
{ "moondatetime", 1, 3, 0, FMoondatetime },
|
{ "moondatetime", 1, 3, 0, FMoondatetime, NULL },
|
||||||
{ "moonphase", 0, 2, 0, FMoonphase },
|
{ "moonphase", 0, 2, 0, FMoonphase, NULL },
|
||||||
{ "moontime", 1, 3, 0, FMoontime },
|
{ "moontime", 1, 3, 0, FMoontime, NULL },
|
||||||
{ "multitrig", 1, NO_MAX, 0, FMultiTrig },
|
{ "multitrig", 1, NO_MAX, 0, FMultiTrig, NULL },
|
||||||
{ "ndawn", 0, 1, 0, FNDawn},
|
{ "ndawn", 0, 1, 0, FNDawn, NULL },
|
||||||
{ "ndusk", 0, 1, 0, FNDusk},
|
{ "ndusk", 0, 1, 0, FNDusk, NULL },
|
||||||
{ "nonomitted", 2, NO_MAX, 0, FNonomitted },
|
{ "nonomitted", 2, NO_MAX, 0, FNonomitted, NULL },
|
||||||
{ "now", 0, 0, 0, FNow },
|
{ "now", 0, 0, 0, FNow, NULL },
|
||||||
{ "ord", 1, 1, 1, FOrd },
|
{ "ord", 1, 1, 1, FOrd, NULL },
|
||||||
{ "orthodoxeaster",0, 1, 0, FOrthodoxeaster },
|
{ "orthodoxeaster",0, 1, 0, FOrthodoxeaster, NULL },
|
||||||
{ "ostype", 0, 0, 1, FOstype },
|
{ "ostype", 0, 0, 1, FOstype, NULL },
|
||||||
{ "pad", 3, 4, 1, FPad },
|
{ "pad", 3, 4, 1, FPad, NULL },
|
||||||
{ "plural", 1, 3, 1, FPlural },
|
{ "plural", 1, 3, 1, FPlural, NULL },
|
||||||
{ "psmoon", 1, 4, 1, FPsmoon},
|
{ "psmoon", 1, 4, 1, FPsmoon, NULL },
|
||||||
{ "psshade", 1, 3, 1, FPsshade},
|
{ "psshade", 1, 3, 1, FPsshade, NULL },
|
||||||
{ "realcurrent", 0, 0, 0, FRealCurrent},
|
{ "realcurrent", 0, 0, 0, FRealCurrent, NULL },
|
||||||
{ "realnow", 0, 0, 0, FRealnow},
|
{ "realnow", 0, 0, 0, FRealnow, NULL },
|
||||||
{ "realtoday", 0, 0, 0, FRealtoday },
|
{ "realtoday", 0, 0, 0, FRealtoday, NULL },
|
||||||
{ "rows", 0, 0, 0, FRows },
|
{ "rows", 0, 0, 0, FRows, NULL },
|
||||||
{ "sgn", 1, 1, 1, FSgn },
|
{ "sgn", 1, 1, 1, FSgn, NULL },
|
||||||
{ "shell", 1, 2, 0, FShell },
|
{ "shell", 1, 2, 0, FShell, NULL },
|
||||||
{ "shellescape", 1, 1, 1, FShellescape },
|
{ "shellescape", 1, 1, 1, FShellescape, NULL },
|
||||||
{ "slide", 2, NO_MAX, 0, FSlide },
|
{ "slide", 2, NO_MAX, 0, FSlide, NULL },
|
||||||
{ "soleq", 1, 2, 0, FSoleq },
|
{ "soleq", 1, 2, 0, FSoleq, NULL },
|
||||||
{ "stdout", 0, 0, 1, FStdout },
|
{ "stdout", 0, 0, 1, FStdout, NULL },
|
||||||
{ "strlen", 1, 1, 1, FStrlen },
|
{ "strlen", 1, 1, 1, FStrlen, NULL },
|
||||||
{ "substr", 2, 3, 1, FSubstr },
|
{ "substr", 2, 3, 1, FSubstr, NULL },
|
||||||
{ "sunrise", 0, 1, 0, FSunrise},
|
{ "sunrise", 0, 1, 0, FSunrise, NULL },
|
||||||
{ "sunset", 0, 1, 0, FSunset },
|
{ "sunset", 0, 1, 0, FSunset, NULL },
|
||||||
{ "time", 2, 2, 1, FTime },
|
{ "time", 2, 2, 1, FTime, NULL },
|
||||||
{ "timepart", 1, 1, 1, FTimepart },
|
{ "timepart", 1, 1, 1, FTimepart, NULL },
|
||||||
{ "timezone", 0, 1, 1, FTimezone },
|
{ "timezone", 0, 1, 1, FTimezone, NULL },
|
||||||
{ "today", 0, 0, 0, FToday },
|
{ "today", 0, 0, 0, FToday, NULL },
|
||||||
{ "trig", 0, NO_MAX, 0, FTrig },
|
{ "trig", 0, NO_MAX, 0, FTrig, NULL },
|
||||||
{ "trigback", 0, 0, 0, FTrigback },
|
{ "trigback", 0, 0, 0, FTrigback, NULL },
|
||||||
{ "trigdate", 0, 0, 0, FTrigdate },
|
{ "trigdate", 0, 0, 0, FTrigdate, NULL },
|
||||||
{ "trigdatetime", 0, 0, 0, FTrigdatetime },
|
{ "trigdatetime", 0, 0, 0, FTrigdatetime, NULL },
|
||||||
{ "trigdelta", 0, 0, 0, FTrigdelta },
|
{ "trigdelta", 0, 0, 0, FTrigdelta, NULL },
|
||||||
{ "trigduration", 0, 0, 0, FTrigduration },
|
{ "trigduration", 0, 0, 0, FTrigduration, NULL },
|
||||||
{ "trigeventduration", 0, 0, 0, FTrigeventduration },
|
{ "trigeventduration", 0, 0, 0, FTrigeventduration, NULL },
|
||||||
{ "trigeventstart", 0, 0, 0, FTrigeventstart },
|
{ "trigeventstart", 0, 0, 0, FTrigeventstart, NULL },
|
||||||
{ "trigfrom", 0, 0, 0, FTrigfrom },
|
{ "trigfrom", 0, 0, 0, FTrigfrom, NULL },
|
||||||
{ "trigger", 1, 3, 0, FTrigger },
|
{ "trigger", 1, 3, 0, FTrigger, NULL },
|
||||||
{ "trigpriority", 0, 0, 0, FTrigpriority },
|
{ "trigpriority", 0, 0, 0, FTrigpriority, NULL },
|
||||||
{ "trigrep", 0, 0, 0, FTrigrep },
|
{ "trigrep", 0, 0, 0, FTrigrep, NULL },
|
||||||
{ "trigscanfrom", 0, 0, 0, FTrigscanfrom },
|
{ "trigscanfrom", 0, 0, 0, FTrigscanfrom, NULL },
|
||||||
{ "trigtags", 0, 0, 0, FTrigtags },
|
{ "trigtags", 0, 0, 0, FTrigtags, NULL },
|
||||||
{ "trigtime", 0, 0, 0, FTrigtime },
|
{ "trigtime", 0, 0, 0, FTrigtime, NULL },
|
||||||
{ "trigtimedelta",0, 0, 0, FTrigtimedelta },
|
{ "trigtimedelta",0, 0, 0, FTrigtimedelta, NULL },
|
||||||
{ "trigtimerep", 0, 0, 0, FTrigtimerep },
|
{ "trigtimerep", 0, 0, 0, FTrigtimerep, NULL },
|
||||||
{ "triguntil", 0, 0, 0, FTriguntil },
|
{ "triguntil", 0, 0, 0, FTriguntil, NULL },
|
||||||
{ "trigvalid", 0, 0, 0, FTrigvalid },
|
{ "trigvalid", 0, 0, 0, FTrigvalid, NULL },
|
||||||
{ "typeof", 1, 1, 1, FTypeof },
|
{ "typeof", 1, 1, 1, FTypeof, NULL },
|
||||||
{ "tzconvert", 2, 3, 0, FTzconvert },
|
{ "tzconvert", 2, 3, 0, FTzconvert, NULL },
|
||||||
{ "upper", 1, 1, 1, FUpper },
|
{ "upper", 1, 1, 1, FUpper, NULL },
|
||||||
{ "utctolocal", 1, 1, 1, FUTCToLocal },
|
{ "utctolocal", 1, 1, 1, FUTCToLocal, NULL },
|
||||||
{ "value", 1, 2, 0, FValue },
|
{ "value", 1, 2, 0, FValue, NULL },
|
||||||
{ "version", 0, 0, 1, FVersion },
|
{ "version", 0, 0, 1, FVersion, NULL },
|
||||||
{ "weekno", 0, 3, 1, FWeekno },
|
{ "weekno", 0, 3, 1, FWeekno, NULL },
|
||||||
{ "wkday", 1, 1, 1, FWkday },
|
{ "wkday", 1, 1, 1, FWkday, NULL },
|
||||||
{ "wkdaynum", 1, 1, 1, FWkdaynum },
|
{ "wkdaynum", 1, 1, 1, FWkdaynum, NULL },
|
||||||
{ "year", 1, 1, 1, FYear }
|
{ "year", 1, 1, 1, FYear, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Need a variable here - Func[] array not really visible to outside. */
|
/* Need a variable here - Func[] array not really visible to outside. */
|
||||||
int NumFuncs = sizeof(Func) / sizeof(Operator) ;
|
int NumFuncs = sizeof(Func) / sizeof(BuiltinFunc) ;
|
||||||
|
|
||||||
/***************************************************************/
|
|
||||||
/* */
|
|
||||||
/* CallFunc */
|
|
||||||
/* */
|
|
||||||
/* Call a function given a pointer to it, and the number */
|
|
||||||
/* of arguments supplied. */
|
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
|
||||||
int CallFunc(BuiltinFunc *f, int nargs)
|
|
||||||
{
|
|
||||||
register int r = CheckArgs(f, nargs);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
func_info info_obj;
|
|
||||||
func_info *info = &info_obj;
|
|
||||||
|
|
||||||
Nargs = nargs;
|
|
||||||
RetVal.type = ERR_TYPE;
|
|
||||||
|
|
||||||
if (DebugFlag & DB_PRTEXPR) {
|
|
||||||
fprintf(ErrFp, "%s(", f->name);
|
|
||||||
for (i=0; i<nargs; i++) {
|
|
||||||
PrintValue(&ARG(i), ErrFp);
|
|
||||||
if (i<nargs-1) fprintf(ErrFp, ", ");
|
|
||||||
}
|
|
||||||
fprintf(ErrFp, ") => ");
|
|
||||||
if (r) {
|
|
||||||
fprintf(ErrFp, "%s\n", ErrMsg[r]);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (r) {
|
|
||||||
Eprint("%s(): %s", f->name, ErrMsg[r]);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = (*(f->func))(info);
|
|
||||||
if (r) {
|
|
||||||
DestroyValue(RetVal);
|
|
||||||
if (DebugFlag & DB_PRTEXPR)
|
|
||||||
fprintf(ErrFp, "%s\n", ErrMsg[r]);
|
|
||||||
else
|
|
||||||
Eprint("%s(): %s", f->name, ErrMsg[r]);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
if (DebugFlag & DB_PRTEXPR) {
|
|
||||||
PrintValue(&RetVal, ErrFp);
|
|
||||||
fprintf(ErrFp, "\n");
|
|
||||||
}
|
|
||||||
r = CleanUpAfterFunc(info);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************************/
|
|
||||||
/* */
|
|
||||||
/* CheckArgs */
|
|
||||||
/* */
|
|
||||||
/* Check that the right number of args have been supplied */
|
|
||||||
/* for a function. */
|
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
|
||||||
static int CheckArgs(BuiltinFunc *f, int nargs)
|
|
||||||
{
|
|
||||||
if (nargs < f->minargs) return E_2FEW_ARGS;
|
|
||||||
if (nargs > f->maxargs && f->maxargs != NO_MAX) return E_2MANY_ARGS;
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
/***************************************************************/
|
|
||||||
/* */
|
|
||||||
/* CleanUpAfterFunc */
|
|
||||||
/* */
|
|
||||||
/* Clean up the stack after a function call - remove */
|
|
||||||
/* args and push the new value. */
|
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
|
||||||
static int CleanUpAfterFunc(func_info *info)
|
|
||||||
{
|
|
||||||
Value v;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0; i<Nargs; i++) {
|
|
||||||
PopValStack(v);
|
|
||||||
DestroyValue(v);
|
|
||||||
}
|
|
||||||
PushValStack(RetVal);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
@@ -1108,8 +1016,11 @@ static int FOrd(func_info *info)
|
|||||||
ASSERT_TYPE(0, INT_TYPE);
|
ASSERT_TYPE(0, INT_TYPE);
|
||||||
|
|
||||||
v = ARGV(0);
|
v = ARGV(0);
|
||||||
t = v % 100;
|
if (v < 0) {
|
||||||
if (t < 0) t = -t;
|
t = (-v) % 100;
|
||||||
|
} else {
|
||||||
|
t = v % 100;
|
||||||
|
}
|
||||||
u = t % 10;
|
u = t % 10;
|
||||||
s = "th";
|
s = "th";
|
||||||
if (u == 1 && t != 11) s = "st";
|
if (u == 1 && t != 11) s = "st";
|
||||||
@@ -1271,6 +1182,9 @@ static int FIsAny(func_info *info)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Debugging helpers for "choose()" and "iif() */
|
||||||
|
#define PUT(x) DBufPuts(&DebugBuf, x)
|
||||||
|
#define OUT() do { fprintf(ErrFp, "%s\n", DBufValue(&DebugBuf)); DBufFree(&DebugBuf); } while(0)
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* FChoose */
|
/* FChoose */
|
||||||
@@ -1279,15 +1193,63 @@ static int FIsAny(func_info *info)
|
|||||||
/* from 1. */
|
/* from 1. */
|
||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
static int FChoose(func_info *info)
|
static int FChoose(expr_node *node, Value *locals, Value *ans, int *nonconst)
|
||||||
{
|
{
|
||||||
int v;
|
DynamicBuffer DebugBuf;
|
||||||
|
expr_node *cur;
|
||||||
|
int r;
|
||||||
|
int n;
|
||||||
|
int nargs = node->num_kids;
|
||||||
|
Value(v);
|
||||||
|
DBG(DBufInit(&DebugBuf));
|
||||||
|
DBG(PUT("choose("));
|
||||||
|
|
||||||
ASSERT_TYPE(0, INT_TYPE);
|
cur = node->child;
|
||||||
v = ARGV(0);
|
r = evaluate_expr_node(cur, locals, &v, nonconst);
|
||||||
if (v < 1) v = 1;
|
if (r != OK) {
|
||||||
if (v > Nargs-1) v = Nargs-1;
|
DBG(DBufFree(&DebugBuf));
|
||||||
DCOPYVAL(RetVal, ARG(v));
|
return r;
|
||||||
|
}
|
||||||
|
DBG(PUT(PrintValue(&v, NULL)));
|
||||||
|
if (v.type != INT_TYPE) {
|
||||||
|
if (DebugFlag & DB_PRTEXPR) {
|
||||||
|
cur = cur->sibling;
|
||||||
|
while(cur) {
|
||||||
|
PUT(", ?");
|
||||||
|
cur = cur->sibling;
|
||||||
|
}
|
||||||
|
PUT(") => ");
|
||||||
|
PUT(ErrMsg[E_BAD_TYPE]);
|
||||||
|
OUT();
|
||||||
|
}
|
||||||
|
return E_BAD_TYPE;
|
||||||
|
}
|
||||||
|
n = v.v.val;
|
||||||
|
if (n < 1) n = 1;
|
||||||
|
if (n > nargs-1) n = nargs-1;
|
||||||
|
|
||||||
|
while(n--) {
|
||||||
|
cur = cur->sibling;
|
||||||
|
DBG(if (n) { PUT(", ?"); });
|
||||||
|
if (!cur) return E_SWERR; /* Should not happen! */
|
||||||
|
}
|
||||||
|
r = evaluate_expr_node(cur, locals, ans, nonconst);
|
||||||
|
if (r != OK) {
|
||||||
|
DBG(DBufFree(&DebugBuf));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (DebugFlag & DB_PRTEXPR) {
|
||||||
|
PUT(", ");
|
||||||
|
PUT(PrintValue(ans, NULL));
|
||||||
|
cur = cur->sibling;
|
||||||
|
while(cur) {
|
||||||
|
PUT(", ?");
|
||||||
|
cur = cur->sibling;
|
||||||
|
}
|
||||||
|
PUT(") => ");
|
||||||
|
PUT(PrintValue(ans, NULL));
|
||||||
|
OUT();
|
||||||
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1473,7 +1435,7 @@ static int FValue(func_info *info)
|
|||||||
ASSERT_TYPE(0, STR_TYPE);
|
ASSERT_TYPE(0, STR_TYPE);
|
||||||
switch(Nargs) {
|
switch(Nargs) {
|
||||||
case 1:
|
case 1:
|
||||||
return GetVarValue(ARGSTR(0), &RetVal, NULL, NULL);
|
return GetVarValue(ARGSTR(0), &RetVal);
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
v = FindVar(ARGSTR(0), 0);
|
v = FindVar(ARGSTR(0), 0);
|
||||||
@@ -1945,33 +1907,101 @@ static int FIndex(func_info *info)
|
|||||||
/* */
|
/* */
|
||||||
/* FIif */
|
/* FIif */
|
||||||
/* */
|
/* */
|
||||||
/* The IIF function. */
|
/* The IIF function. Uses new-style evaluation */
|
||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
static int FIif(func_info *info)
|
static int FIif(expr_node *node, Value *locals, Value *ans, int *nonconst)
|
||||||
{
|
{
|
||||||
int istrue;
|
int istrue;
|
||||||
int arg;
|
int r;
|
||||||
|
int done;
|
||||||
|
Value v;
|
||||||
|
expr_node *cur;
|
||||||
|
DynamicBuffer DebugBuf;
|
||||||
|
|
||||||
if (!(Nargs % 2)) return E_IIF_ODD;
|
DBG(DBufInit(&DebugBuf));
|
||||||
|
DBG(PUT("iif("));
|
||||||
|
cur = node->child;
|
||||||
|
|
||||||
for (arg=0; arg<Nargs-1; arg += 2) {
|
if (!(node->num_kids % 2)) {
|
||||||
if (ARG(arg).type != STR_TYPE && ARG(arg).type != INT_TYPE)
|
if (DebugFlag & DB_PRTEXPR) {
|
||||||
return E_BAD_TYPE;
|
r = 0;
|
||||||
|
while(cur) {
|
||||||
if (ARG(arg).type == INT_TYPE)
|
if (r) PUT(", ");
|
||||||
istrue = ARG(arg).v.val;
|
r=1;
|
||||||
else
|
PUT("?");
|
||||||
istrue = *(ARG(arg).v.str);
|
cur = cur->sibling;
|
||||||
|
}
|
||||||
if (istrue) {
|
PUT(") => ");
|
||||||
DCOPYVAL(RetVal, ARG(arg+1));
|
PUT(ErrMsg[E_IIF_ODD]);
|
||||||
return OK;
|
OUT();
|
||||||
}
|
}
|
||||||
|
return E_IIF_ODD;
|
||||||
}
|
}
|
||||||
|
|
||||||
DCOPYVAL(RetVal, ARG(Nargs-1));
|
|
||||||
return OK;
|
done = 0;
|
||||||
|
while(cur->sibling) {
|
||||||
|
r = evaluate_expr_node(cur, locals, &v, nonconst);
|
||||||
|
if (r != OK) {
|
||||||
|
DBG(DBufFree(&DebugBuf));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (DebugFlag & DB_PRTEXPR) {
|
||||||
|
if (done) PUT(", ");
|
||||||
|
done = 1;
|
||||||
|
PUT(PrintValue(&v, NULL));
|
||||||
|
}
|
||||||
|
if (v.type != STR_TYPE && v.type != INT_TYPE) {
|
||||||
|
if (DebugFlag & DB_PRTEXPR) {
|
||||||
|
cur = cur->sibling;
|
||||||
|
while(cur) {
|
||||||
|
PUT(", ?");
|
||||||
|
cur = cur->sibling;
|
||||||
|
}
|
||||||
|
PUT(") => ");
|
||||||
|
PUT(ErrMsg[E_BAD_TYPE]);
|
||||||
|
OUT();
|
||||||
|
}
|
||||||
|
return E_BAD_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v.type == INT_TYPE) {
|
||||||
|
istrue = v.v.val;
|
||||||
|
} else {
|
||||||
|
istrue = *(v.v.str);
|
||||||
|
}
|
||||||
|
if (istrue) {
|
||||||
|
r = evaluate_expr_node(cur->sibling, locals, ans, nonconst);
|
||||||
|
if (r == OK && (DebugFlag & DB_PRTEXPR)) {
|
||||||
|
PUT(", ");
|
||||||
|
PUT(PrintValue(ans, NULL));
|
||||||
|
cur = cur->sibling->sibling;
|
||||||
|
while(cur) {
|
||||||
|
PUT(", ?");
|
||||||
|
cur = cur->sibling;
|
||||||
|
}
|
||||||
|
PUT(") => ");
|
||||||
|
PUT(PrintValue(ans, NULL));
|
||||||
|
OUT();
|
||||||
|
}
|
||||||
|
DBG(DBufFree(&DebugBuf));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
DBG(PUT(", ?"));
|
||||||
|
cur = cur->sibling->sibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the last arg */
|
||||||
|
r = evaluate_expr_node(cur, locals, ans, nonconst);
|
||||||
|
if (DebugFlag & DB_PRTEXPR) {
|
||||||
|
if (done) PUT(", ");
|
||||||
|
PUT(PrintValue(ans, NULL));
|
||||||
|
PUT(") => ");
|
||||||
|
PUT(PrintValue(ans, NULL));
|
||||||
|
OUT();
|
||||||
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
@@ -2093,6 +2123,7 @@ static int FArgs(func_info *info)
|
|||||||
{
|
{
|
||||||
ASSERT_TYPE(0, STR_TYPE);
|
ASSERT_TYPE(0, STR_TYPE);
|
||||||
RetVal.type = INT_TYPE;
|
RetVal.type = INT_TYPE;
|
||||||
|
strtolower(ARGSTR(0));
|
||||||
RETVAL = UserFuncExists(ARGSTR(0));
|
RETVAL = UserFuncExists(ARGSTR(0));
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -2365,14 +2396,18 @@ static int FEasterdate(func_info *info)
|
|||||||
{
|
{
|
||||||
int y, m, d;
|
int y, m, d;
|
||||||
int g, c, x, z, e, n;
|
int g, c, x, z, e, n;
|
||||||
|
int base;
|
||||||
if (Nargs == 0) {
|
if (Nargs == 0) {
|
||||||
|
base = DSEToday;
|
||||||
FromDSE(DSEToday, &y, &m, &d);
|
FromDSE(DSEToday, &y, &m, &d);
|
||||||
} else {
|
} else {
|
||||||
if (ARG(0).type == INT_TYPE) {
|
if (ARG(0).type == INT_TYPE) {
|
||||||
|
base = -1;
|
||||||
y = ARGV(0);
|
y = ARGV(0);
|
||||||
if (y < BASE) return E_2LOW;
|
if (y < BASE) return E_2LOW;
|
||||||
else if (y > BASE+YR_RANGE) return E_2HIGH;
|
else if (y > BASE+YR_RANGE) return E_2HIGH;
|
||||||
} else if (HASDATE(ARG(0))) {
|
} else if (HASDATE(ARG(0))) {
|
||||||
|
base = DATEPART(ARG(0));
|
||||||
FromDSE(DATEPART(ARG(0)), &y, &m, &d); /* We just want the year */
|
FromDSE(DATEPART(ARG(0)), &y, &m, &d); /* We just want the year */
|
||||||
} else return E_BAD_TYPE;
|
} else return E_BAD_TYPE;
|
||||||
}
|
}
|
||||||
@@ -2398,7 +2433,7 @@ static int FEasterdate(func_info *info)
|
|||||||
|
|
||||||
RetVal.type = DATE_TYPE;
|
RetVal.type = DATE_TYPE;
|
||||||
RETVAL = DSE(y, m, d);
|
RETVAL = DSE(y, m, d);
|
||||||
y++; } while (HASDATE(ARG(0)) && RETVAL < DATEPART(ARG(0)));
|
y++; } while (base > -1 && RETVAL < base);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -2414,7 +2449,9 @@ static int FOrthodoxeaster(func_info *info)
|
|||||||
{
|
{
|
||||||
int y, m, d;
|
int y, m, d;
|
||||||
int a, b, c, dd, e, f, dse;
|
int a, b, c, dd, e, f, dse;
|
||||||
|
int base = -1;
|
||||||
if (Nargs == 0) {
|
if (Nargs == 0) {
|
||||||
|
base = DSEToday;
|
||||||
FromDSE(DSEToday, &y, &m, &d);
|
FromDSE(DSEToday, &y, &m, &d);
|
||||||
} else {
|
} else {
|
||||||
if (ARG(0).type == INT_TYPE) {
|
if (ARG(0).type == INT_TYPE) {
|
||||||
@@ -2422,6 +2459,7 @@ static int FOrthodoxeaster(func_info *info)
|
|||||||
if (y < BASE) return E_2LOW;
|
if (y < BASE) return E_2LOW;
|
||||||
else if (y > BASE+YR_RANGE) return E_2HIGH;
|
else if (y > BASE+YR_RANGE) return E_2HIGH;
|
||||||
} else if (HASDATE(ARG(0))) {
|
} else if (HASDATE(ARG(0))) {
|
||||||
|
base = DATEPART(ARG(0));
|
||||||
FromDSE(DATEPART(ARG(0)), &y, &m, &d); /* We just want the year */
|
FromDSE(DATEPART(ARG(0)), &y, &m, &d); /* We just want the year */
|
||||||
} else return E_BAD_TYPE;
|
} else return E_BAD_TYPE;
|
||||||
}
|
}
|
||||||
@@ -2441,7 +2479,7 @@ static int FOrthodoxeaster(func_info *info)
|
|||||||
RetVal.type = DATE_TYPE;
|
RetVal.type = DATE_TYPE;
|
||||||
RETVAL = dse;
|
RETVAL = dse;
|
||||||
y++;
|
y++;
|
||||||
} while (HASDATE(ARG(0)) && RETVAL < DATEPART(ARG(0)));
|
} while (base > -1 && RETVAL < base);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -3498,7 +3536,7 @@ FEvalTrig(func_info *info)
|
|||||||
|
|
||||||
CreateParser(ARGSTR(0), &p);
|
CreateParser(ARGSTR(0), &p);
|
||||||
p.allownested = 0;
|
p.allownested = 0;
|
||||||
r = ParseRem(&p, &trig, &tim, 0);
|
r = ParseRem(&p, &trig, &tim);
|
||||||
if (r) {
|
if (r) {
|
||||||
DestroyParser(&p);
|
DestroyParser(&p);
|
||||||
return r;
|
return r;
|
||||||
@@ -3557,7 +3595,7 @@ FMultiTrig(func_info *info)
|
|||||||
for (i=0; i<Nargs; i++) {
|
for (i=0; i<Nargs; i++) {
|
||||||
CreateParser(ARGSTR(i), &p);
|
CreateParser(ARGSTR(i), &p);
|
||||||
p.allownested = 0;
|
p.allownested = 0;
|
||||||
r = ParseRem(&p, &trig, &tim, 0);
|
r = ParseRem(&p, &trig, &tim);
|
||||||
if (r) {
|
if (r) {
|
||||||
DestroyParser(&p);
|
DestroyParser(&p);
|
||||||
return r;
|
return r;
|
||||||
@@ -3614,7 +3652,7 @@ FTrig(func_info *info)
|
|||||||
for (i=0; i<Nargs; i++) {
|
for (i=0; i<Nargs; i++) {
|
||||||
CreateParser(ARGSTR(i), &p);
|
CreateParser(ARGSTR(i), &p);
|
||||||
p.allownested = 0;
|
p.allownested = 0;
|
||||||
r = ParseRem(&p, &trig, &tim, 0);
|
r = ParseRem(&p, &trig, &tim);
|
||||||
if (r) {
|
if (r) {
|
||||||
DestroyParser(&p);
|
DestroyParser(&p);
|
||||||
return r;
|
return r;
|
||||||
@@ -3888,3 +3926,38 @@ FSoleq(func_info *info)
|
|||||||
RETVAL = ret;
|
RETVAL = ret;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Compare two strings case-insensitively, where we KNOW
|
||||||
|
that the second string is definitely lower-case */
|
||||||
|
static int strcmp_lcfirst(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
while (*s1 && *s2) {
|
||||||
|
r = tolower(*s1) - *s2;
|
||||||
|
if (r) return r;
|
||||||
|
s1++;
|
||||||
|
s2++;
|
||||||
|
}
|
||||||
|
return tolower(*s1) - *s2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FindBuiltinFunc */
|
||||||
|
/* */
|
||||||
|
/* Find a built-in function. */
|
||||||
|
/* */
|
||||||
|
/***************************************************************/
|
||||||
|
BuiltinFunc *FindBuiltinFunc(char const *name)
|
||||||
|
{
|
||||||
|
int top=NumFuncs-1, bot=0;
|
||||||
|
int mid, r;
|
||||||
|
while (top >= bot) {
|
||||||
|
mid = (top + bot) / 2;
|
||||||
|
r = strcmp_lcfirst(name, Func[mid].name);
|
||||||
|
if (!r) return &Func[mid];
|
||||||
|
else if (r > 0) bot = mid+1;
|
||||||
|
else top = mid-1;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#define INIT(var, val) var
|
#define INIT(var, val) var
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -73,6 +74,9 @@ EXTERN INIT( int InfiniteDelta, 0);
|
|||||||
EXTERN INIT( int DefaultTDelta, 0);
|
EXTERN INIT( int DefaultTDelta, 0);
|
||||||
EXTERN INIT( int DeltaOverride, 0);
|
EXTERN INIT( int DeltaOverride, 0);
|
||||||
EXTERN INIT( int RunDisabled, 0);
|
EXTERN INIT( int RunDisabled, 0);
|
||||||
|
EXTERN INIT( int ExpressionEvaluationDisabled, 0);
|
||||||
|
EXTERN INIT( int ExpressionEvaluationTimeLimit, 0);
|
||||||
|
EXTERN INIT( volatile sig_atomic_t ExpressionTimeLimitExceeded, 0);
|
||||||
EXTERN INIT( int IgnoreOnce, 0);
|
EXTERN INIT( int IgnoreOnce, 0);
|
||||||
EXTERN INIT( int SortByTime, 0);
|
EXTERN INIT( int SortByTime, 0);
|
||||||
EXTERN INIT( int SortByDate, 0);
|
EXTERN INIT( int SortByDate, 0);
|
||||||
@@ -110,11 +114,12 @@ EXTERN INIT( int PurgeIncludeDepth, 0);
|
|||||||
EXTERN INIT( FILE *PurgeFP, NULL);
|
EXTERN INIT( FILE *PurgeFP, NULL);
|
||||||
EXTERN INIT( int NumIfs, 0);
|
EXTERN INIT( int NumIfs, 0);
|
||||||
EXTERN INIT( unsigned int IfFlags, 0);
|
EXTERN INIT( unsigned int IfFlags, 0);
|
||||||
|
EXTERN INIT( int IfLinenos[IF_NEST], {0});
|
||||||
EXTERN INIT( int LastTrigValid, 0);
|
EXTERN INIT( int LastTrigValid, 0);
|
||||||
EXTERN Trigger LastTrigger;
|
EXTERN Trigger LastTrigger;
|
||||||
EXTERN TimeTrig LastTimeTrig;
|
EXTERN TimeTrig LastTimeTrig;
|
||||||
EXTERN INIT( int LastTriggerDate, 0);
|
EXTERN INIT( int LastTriggerDate, 0);
|
||||||
EXTERN INIT( int LastTriggerTime, 0);
|
EXTERN INIT( int LastTriggerTime, NO_TIME);
|
||||||
EXTERN INIT( int ShouldCache, 0);
|
EXTERN INIT( int ShouldCache, 0);
|
||||||
EXTERN char const *CurLine;
|
EXTERN char const *CurLine;
|
||||||
EXTERN INIT( int NumTriggered, 0);
|
EXTERN INIT( int NumTriggered, 0);
|
||||||
@@ -159,6 +164,9 @@ EXTERN DynamicBuffer Banner;
|
|||||||
EXTERN DynamicBuffer LineBuffer;
|
EXTERN DynamicBuffer LineBuffer;
|
||||||
EXTERN DynamicBuffer ExprBuf;
|
EXTERN DynamicBuffer ExprBuf;
|
||||||
|
|
||||||
|
/* User-func recursion level */
|
||||||
|
EXTERN INIT( unsigned int FuncRecursionLevel, 0);
|
||||||
|
|
||||||
extern int NumFullOmits, NumPartialOmits;
|
extern int NumFullOmits, NumPartialOmits;
|
||||||
|
|
||||||
/* List of months */
|
/* List of months */
|
||||||
|
|||||||
@@ -20,6 +20,12 @@
|
|||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
#include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define HOUR 1080L
|
#define HOUR 1080L
|
||||||
#define DAY (24L*HOUR)
|
#define DAY (24L*HOUR)
|
||||||
#define WEEK (7L*DAY)
|
#define WEEK (7L*DAY)
|
||||||
|
|||||||
87
src/init.c
87
src/init.c
@@ -19,7 +19,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -38,7 +38,6 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "expr.h"
|
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
|
||||||
static int should_guess_terminal_background = 1;
|
static int should_guess_terminal_background = 1;
|
||||||
@@ -605,7 +604,7 @@ void InitRemind(int argc, char const *argv[])
|
|||||||
case 'D':
|
case 'D':
|
||||||
while (*arg) {
|
while (*arg) {
|
||||||
switch(*arg++) {
|
switch(*arg++) {
|
||||||
case 's': case 'S': DebugFlag |= DB_EXPR_STACKS; break;
|
case 's': case 'S': DebugFlag |= DB_PARSE_EXPR; break;
|
||||||
case 'e': case 'E': DebugFlag |= DB_ECHO_LINE; break;
|
case 'e': case 'E': DebugFlag |= DB_ECHO_LINE; break;
|
||||||
case 'x': case 'X': DebugFlag |= DB_PRTEXPR; break;
|
case 'x': case 'X': DebugFlag |= DB_PRTEXPR; break;
|
||||||
case 't': case 'T': DebugFlag |= DB_PRTTRIG; break;
|
case 't': case 'T': DebugFlag |= DB_PRTTRIG; break;
|
||||||
@@ -806,6 +805,7 @@ void Usage(void)
|
|||||||
fprintf(ErrFp, " -m Start calendar with Monday rather than Sunday\n");
|
fprintf(ErrFp, " -m Start calendar with Monday rather than Sunday\n");
|
||||||
fprintf(ErrFp, " -y Synthesize tags for tagless reminders\n");
|
fprintf(ErrFp, " -y Synthesize tags for tagless reminders\n");
|
||||||
fprintf(ErrFp, " -j[n] Run in 'purge' mode. [n = INCLUDE depth]\n");
|
fprintf(ErrFp, " -j[n] Run in 'purge' mode. [n = INCLUDE depth]\n");
|
||||||
|
fprintf(ErrFp, "\nRemind home page: %s\n", PACKAGE_URL);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
#endif /* L_USAGE_OVERRIDE */
|
#endif /* L_USAGE_OVERRIDE */
|
||||||
@@ -925,7 +925,12 @@ static void InitializeVar(char const *str)
|
|||||||
r = 0;
|
r = 0;
|
||||||
while (*str && *str != '=') {
|
while (*str && *str != '=') {
|
||||||
if (r < VAR_NAME_LEN) {
|
if (r < VAR_NAME_LEN) {
|
||||||
varname[r++] = *str;
|
if (isalpha(*str) || *str == '_' || (r > 0 && *str == '(') || (r == 0 && *str == '$') || (r > 0 && isdigit(*str))) {
|
||||||
|
varname[r++] = *str;
|
||||||
|
} else {
|
||||||
|
fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_ILLEGAL_CHAR]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (*str == '(') {
|
if (*str == '(') {
|
||||||
/* Do a function definition if we see a paren */
|
/* Do a function definition if we see a paren */
|
||||||
@@ -935,10 +940,28 @@ static void InitializeVar(char const *str)
|
|||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
varname[r] = 0;
|
varname[r] = 0;
|
||||||
if (!*str) {
|
if (!*varname) {
|
||||||
fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_EQ]);
|
fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_VAR]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!*str) {
|
||||||
|
/* Setting a system var does require =expr on the commandline */
|
||||||
|
if (*varname == '$') {
|
||||||
|
fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_EQ]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
val.type = INT_TYPE;
|
||||||
|
val.v.val = 0;
|
||||||
|
r = SetVar(varname, &val);
|
||||||
|
if (!r) {
|
||||||
|
r = PreserveVar(varname);
|
||||||
|
}
|
||||||
|
if (r) {
|
||||||
|
fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[r]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!*varname) {
|
if (!*varname) {
|
||||||
fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_VAR]);
|
fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_VAR]);
|
||||||
return;
|
return;
|
||||||
@@ -991,13 +1014,65 @@ AddTrustedUser(char const *username)
|
|||||||
NumTrustedUsers++;
|
NumTrustedUsers++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pid_t LimiterPid = (pid_t) -1;
|
||||||
|
|
||||||
|
void unlimit_execution_time(void)
|
||||||
|
{
|
||||||
|
if (LimiterPid != (pid_t) -1) {
|
||||||
|
kill(LimiterPid, SIGTERM);
|
||||||
|
LimiterPid = (pid_t) -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void limit_execution_time(int t)
|
||||||
|
{
|
||||||
|
pid_t parent = getpid();
|
||||||
|
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
perror("fork");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid > 0) {
|
||||||
|
LimiterPid = pid;
|
||||||
|
/* In the parent */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* In the child */
|
||||||
|
time_t start = time(NULL);
|
||||||
|
while(1) {
|
||||||
|
sleep(1);
|
||||||
|
if (kill(parent, 0) < 0) {
|
||||||
|
/* Parent has probably exited */
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (time(NULL) - start > t) {
|
||||||
|
kill(parent, SIGXCPU);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ProcessLongOption(char const *arg)
|
ProcessLongOption(char const *arg)
|
||||||
{
|
{
|
||||||
|
int t;
|
||||||
if (!strcmp(arg, "version")) {
|
if (!strcmp(arg, "version")) {
|
||||||
printf("%s\n", VERSION);
|
printf("%s\n", VERSION);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
if (sscanf(arg, "max-execution-time=%d", &t) == 1) {
|
||||||
|
if (t < 0) {
|
||||||
|
fprintf(ErrFp, "%s: --max-execution-time must be non-negative\n", ArgV[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (t > 0) {
|
||||||
|
limit_execution_time(t);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
fprintf(ErrFp, "%s: Unknown long option --%s\n", ArgV[0], arg);
|
fprintf(ErrFp, "%s: Unknown long option --%s\n", ArgV[0], arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ EXTERN char *ErrMsg[] =
|
|||||||
"Ok",
|
"Ok",
|
||||||
"Puuttuva ']'",
|
"Puuttuva ']'",
|
||||||
"Puuttuva lainausmerkki",
|
"Puuttuva lainausmerkki",
|
||||||
"Liian monimutkainen lauseke - liikaa operaattoreita",
|
"Liian monimutkainen lauseke",
|
||||||
"Liian monimutkainen lauseke - liikaa operandeja",
|
"Liian monimutkainen lauseke - liikaa operandeja",
|
||||||
"Puuttuva ')'",
|
"Puuttuva ')'",
|
||||||
"Määrittelemätön funktio",
|
"Määrittelemätön funktio",
|
||||||
@@ -246,7 +246,10 @@ EXTERN char *ErrMsg[] =
|
|||||||
"String too long",
|
"String too long",
|
||||||
"Time specified twice",
|
"Time specified twice",
|
||||||
"Cannot specify DURATION without specifying AT",
|
"Cannot specify DURATION without specifying AT",
|
||||||
"Odotettu viikonpäivän nimi"
|
"Odotettu viikonpäivän nimi",
|
||||||
|
"Päällekkäinen argumentin nimi",
|
||||||
|
"Lausekkeiden arviointi on poistettu käytöstä",
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif /* MK_GLOBALS */
|
#endif /* MK_GLOBALS */
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ EXTERN char *ErrMsg[] =
|
|||||||
"Ok",
|
"Ok",
|
||||||
"']' manquant",
|
"']' manquant",
|
||||||
"Apostrophe manquant",
|
"Apostrophe manquant",
|
||||||
"Expression trop complexe - trop d'opérateurs",
|
"Expression trop complexe",
|
||||||
"Expression trop complexe - trop d'opérandes",
|
"Expression trop complexe - trop d'opérandes",
|
||||||
"')' manquante",
|
"')' manquante",
|
||||||
"Fonction non-définie",
|
"Fonction non-définie",
|
||||||
@@ -221,6 +221,9 @@ EXTERN char *ErrMsg[] =
|
|||||||
"Time specified twice",
|
"Time specified twice",
|
||||||
"Cannot specify DURATION without specifying AT",
|
"Cannot specify DURATION without specifying AT",
|
||||||
"Nom du jour de la semaine attendu",
|
"Nom du jour de la semaine attendu",
|
||||||
|
"Nom de l'argument en double",
|
||||||
|
"L'évaluation de l'expression est désactivée",
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif /* MK_GLOBALS */
|
#endif /* MK_GLOBALS */
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ EXTERN char *ErrMsg[] =
|
|||||||
"OK",
|
"OK",
|
||||||
"Brakujący ']'",
|
"Brakujący ']'",
|
||||||
"Brakujący nawias",
|
"Brakujący nawias",
|
||||||
"Zbyt skomplikowane wyrażenie - za dużo operatorów",
|
"Zbyt skomplikowane wyrażenie",
|
||||||
"Zbyt skomplikowane wyrażenie - za dużo argumentów",
|
"Zbyt skomplikowane wyrażenie - za dużo argumentów",
|
||||||
"Brakujący ')'",
|
"Brakujący ')'",
|
||||||
"Nie zdefiniowana funkcja",
|
"Nie zdefiniowana funkcja",
|
||||||
@@ -236,7 +236,9 @@ EXTERN char *ErrMsg[] =
|
|||||||
"String too long",
|
"String too long",
|
||||||
"Time specified twice",
|
"Time specified twice",
|
||||||
"Cannot specify DURATION without specifying AT",
|
"Cannot specify DURATION without specifying AT",
|
||||||
"Oczekiwana nazwa dnia tygodnia"
|
"Oczekiwana nazwa dnia tygodnia",
|
||||||
|
"Zduplikowana nazwa argumentu",
|
||||||
|
"Ocena wyrażeń jest wyłączona",
|
||||||
};
|
};
|
||||||
#endif /* MK_GLOBALS */
|
#endif /* MK_GLOBALS */
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ EXTERN char *ErrMsg[] =
|
|||||||
"Ok",
|
"Ok",
|
||||||
"Falta um ']'",
|
"Falta um ']'",
|
||||||
"Falta uma aspa",
|
"Falta uma aspa",
|
||||||
"Expressao muito complexa - muitos operadores",
|
"Expressao muito complexa",
|
||||||
"Expressao muito complexa - muitos operandos",
|
"Expressao muito complexa - muitos operandos",
|
||||||
"Falta um ')'",
|
"Falta um ')'",
|
||||||
"Funcao nao definida",
|
"Funcao nao definida",
|
||||||
@@ -246,6 +246,8 @@ EXTERN char *ErrMsg[] =
|
|||||||
"Time specified twice",
|
"Time specified twice",
|
||||||
"Cannot specify DURATION without specifying AT",
|
"Cannot specify DURATION without specifying AT",
|
||||||
"Esperando nome do dia da semana",
|
"Esperando nome do dia da semana",
|
||||||
|
"Nome de argumento duplicado",
|
||||||
|
"A avaliação da expressão está desabilitada",
|
||||||
};
|
};
|
||||||
#endif /* MK_GLOBALS */
|
#endif /* MK_GLOBALS */
|
||||||
|
|
||||||
|
|||||||
241
src/main.c
241
src/main.c
@@ -22,6 +22,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
#include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#ifdef HAVE_LOCALE_H
|
#ifdef HAVE_LOCALE_H
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
@@ -41,7 +46,6 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "expr.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
|
||||||
@@ -50,6 +54,33 @@ static void DoReminders(void);
|
|||||||
/* Macro for simplifying common block so as not to litter code */
|
/* Macro for simplifying common block so as not to litter code */
|
||||||
#define OUTPUT(c) do { if (output) { DBufPutc(output, c); } else { putchar(c); } } while(0)
|
#define OUTPUT(c) do { if (output) { DBufPutc(output, c); } else { putchar(c); } } while(0)
|
||||||
|
|
||||||
|
void
|
||||||
|
exitfunc(void)
|
||||||
|
{
|
||||||
|
/* Kill any execution-time-limiter process */
|
||||||
|
unlimit_execution_time();
|
||||||
|
|
||||||
|
if (DebugFlag & DB_PARSE_EXPR) {
|
||||||
|
fflush(stdout);
|
||||||
|
fflush(stderr);
|
||||||
|
UnsetAllUserFuncs();
|
||||||
|
print_expr_nodes_stats();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sigalrm(int)
|
||||||
|
{
|
||||||
|
if (ExpressionEvaluationTimeLimit) {
|
||||||
|
ExpressionTimeLimitExceeded = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sigxcpu(int)
|
||||||
|
{
|
||||||
|
write(STDERR_FILENO, "\n\nmax-execution-time exceeded.\n\n", 32);
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/** **/
|
/** **/
|
||||||
@@ -61,6 +92,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
|
struct sigaction act;
|
||||||
|
|
||||||
#ifdef HAVE_SETLOCALE
|
#ifdef HAVE_SETLOCALE
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
#endif
|
#endif
|
||||||
@@ -73,10 +106,29 @@ int main(int argc, char *argv[])
|
|||||||
ArgV = (char const **) argv;
|
ArgV = (char const **) argv;
|
||||||
|
|
||||||
InitRemind(argc, (char const **) argv);
|
InitRemind(argc, (char const **) argv);
|
||||||
|
|
||||||
|
act.sa_handler = sigalrm;
|
||||||
|
sigemptyset(&act.sa_mask);
|
||||||
|
act.sa_flags = SA_RESTART;
|
||||||
|
if (sigaction(SIGALRM, &act, NULL) < 0) {
|
||||||
|
fprintf(stderr, "%s: sigaction() failed: %s\n",
|
||||||
|
argv[0], strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
act.sa_handler = sigxcpu;
|
||||||
|
act.sa_flags = SA_RESTART;
|
||||||
|
sigemptyset(&act.sa_mask);
|
||||||
|
if (sigaction(SIGXCPU, &act, NULL) < 0) {
|
||||||
|
fprintf(stderr, "%s: sigaction() failed: %s\n",
|
||||||
|
argv[0], strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
DBufInit(&(LastTrigger.tags));
|
DBufInit(&(LastTrigger.tags));
|
||||||
ClearLastTriggers();
|
ClearLastTriggers();
|
||||||
|
|
||||||
atexit(DebugExitFunc);
|
atexit(exitfunc);
|
||||||
|
|
||||||
if (DoCalendar || (DoSimpleCalendar && (!NextMode || PsCal))) {
|
if (DoCalendar || (DoSimpleCalendar && (!NextMode || PsCal))) {
|
||||||
ProduceCalendar();
|
ProduceCalendar();
|
||||||
@@ -101,7 +153,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Hush) {
|
if (!Hush) {
|
||||||
if (DestroyOmitContexts())
|
if (DestroyOmitContexts(1))
|
||||||
Eprint("%s", ErrMsg[E_PUSH_NOPOP]);
|
Eprint("%s", ErrMsg[E_PUSH_NOPOP]);
|
||||||
if (!Daemon && !NextMode && !NumTriggered && !NumQueued) {
|
if (!Daemon && !NextMode && !NumTriggered && !NumQueued) {
|
||||||
printf("%s\n", ErrMsg[E_NOREMINDERS]);
|
printf("%s\n", ErrMsg[E_NOREMINDERS]);
|
||||||
@@ -154,7 +206,7 @@ void
|
|||||||
PerIterationInit(void)
|
PerIterationInit(void)
|
||||||
{
|
{
|
||||||
ClearGlobalOmits();
|
ClearGlobalOmits();
|
||||||
DestroyOmitContexts();
|
DestroyOmitContexts(1);
|
||||||
DestroyVars(0);
|
DestroyVars(0);
|
||||||
DefaultColorR = -1;
|
DefaultColorR = -1;
|
||||||
DefaultColorG = -1;
|
DefaultColorG = -1;
|
||||||
@@ -281,9 +333,11 @@ static void DoReminders(void)
|
|||||||
case T_Pop: r=PopOmitContext(&p); break;
|
case T_Pop: r=PopOmitContext(&p); break;
|
||||||
case T_Preserve: r=DoPreserve(&p); break;
|
case T_Preserve: r=DoPreserve(&p); break;
|
||||||
case T_Push: r=PushOmitContext(&p); break;
|
case T_Push: r=PushOmitContext(&p); break;
|
||||||
|
case T_Expr: r = DoExpr(&p); break;
|
||||||
case T_RemType: if (tok.val == RUN_TYPE) {
|
case T_RemType: if (tok.val == RUN_TYPE) {
|
||||||
r=DoRun(&p);
|
r=DoRun(&p);
|
||||||
} else {
|
} else {
|
||||||
|
DestroyParser(&p);
|
||||||
CreateParser(CurLine, &p);
|
CreateParser(CurLine, &p);
|
||||||
r=DoRem(&p);
|
r=DoRem(&p);
|
||||||
purge_handled = 1;
|
purge_handled = 1;
|
||||||
@@ -292,10 +346,8 @@ static void DoReminders(void)
|
|||||||
|
|
||||||
|
|
||||||
/* If we don't recognize the command, do a REM by default */
|
/* If we don't recognize the command, do a REM by default */
|
||||||
/* Note: Since the parser hasn't been used yet, we don't */
|
|
||||||
/* need to destroy it here. */
|
|
||||||
|
|
||||||
default: CreateParser(CurLine, &p); purge_handled = 1; r=DoRem(&p); break;
|
default: DestroyParser(&p); CreateParser(CurLine, &p); purge_handled = 1; r=DoRem(&p); break;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (r && (!Hush || r != E_RUN_DISABLED)) {
|
if (r && (!Hush || r != E_RUN_DISABLED)) {
|
||||||
@@ -453,6 +505,16 @@ int ParseChar(ParsePtr p, int *err, int peek)
|
|||||||
return *(p->pos++);
|
return *(p->pos++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert [[ to just a literal [ */
|
||||||
|
if (*p->pos == BEG_OF_EXPR && *(p->pos+1) == BEG_OF_EXPR) {
|
||||||
|
if (peek) {
|
||||||
|
return *(p->pos+1);
|
||||||
|
} else {
|
||||||
|
p->pos++;
|
||||||
|
return *(p->pos++);
|
||||||
|
}
|
||||||
|
}
|
||||||
p->expr_happened = 1;
|
p->expr_happened = 1;
|
||||||
p->pos++;
|
p->pos++;
|
||||||
r = EvalExpr(&(p->pos), &val, p);
|
r = EvalExpr(&(p->pos), &val, p);
|
||||||
@@ -461,8 +523,15 @@ int ParseChar(ParsePtr p, int *err, int peek)
|
|||||||
DestroyParser(p);
|
DestroyParser(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
while(*p->pos && (isempty(*p->pos))) {
|
||||||
|
p->pos++;
|
||||||
|
}
|
||||||
if (*p->pos != END_OF_EXPR) {
|
if (*p->pos != END_OF_EXPR) {
|
||||||
*err = E_MISS_END;
|
if (*p->pos) {
|
||||||
|
*err = E_PARSE_ERR;
|
||||||
|
} else {
|
||||||
|
*err = E_MISS_END;
|
||||||
|
}
|
||||||
DestroyParser(p);
|
DestroyParser(p);
|
||||||
DestroyValue(val);
|
DestroyValue(val);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -577,6 +646,57 @@ int ParseIdentifier(ParsePtr p, DynamicBuffer *dbuf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/* */
|
||||||
|
/* ParseExpr */
|
||||||
|
/* */
|
||||||
|
/* We are expecting an expression here. Parse it and return */
|
||||||
|
/* the value node tree. */
|
||||||
|
/* */
|
||||||
|
/***************************************************************/
|
||||||
|
expr_node * ParseExpr(ParsePtr p, int *r)
|
||||||
|
{
|
||||||
|
|
||||||
|
int bracketed = 0;
|
||||||
|
expr_node *node;
|
||||||
|
|
||||||
|
if (p->isnested) {
|
||||||
|
*r = E_PARSE_ERR; /* Can't nest expressions */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!p->pos) {
|
||||||
|
*r = E_PARSE_ERR; /* Missing expression */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (isempty(*p->pos)) (p->pos)++;
|
||||||
|
if (!*(p->pos)) {
|
||||||
|
*r = E_EOLN;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (*p->pos == BEG_OF_EXPR) {
|
||||||
|
(p->pos)++;
|
||||||
|
bracketed = 1;
|
||||||
|
}
|
||||||
|
node = parse_expression(&(p->pos), r, NULL);
|
||||||
|
if (*r) {
|
||||||
|
return free_expr_tree(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bracketed) {
|
||||||
|
if (*p->pos != END_OF_EXPR) {
|
||||||
|
if (*p->pos) {
|
||||||
|
*r = E_PARSE_ERR;
|
||||||
|
} else {
|
||||||
|
*r = E_MISS_END;
|
||||||
|
}
|
||||||
|
return free_expr_tree(node);
|
||||||
|
}
|
||||||
|
(p->pos)++;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* EvaluateExpr */
|
/* EvaluateExpr */
|
||||||
@@ -588,21 +708,22 @@ int ParseIdentifier(ParsePtr p, DynamicBuffer *dbuf)
|
|||||||
int EvaluateExpr(ParsePtr p, Value *v)
|
int EvaluateExpr(ParsePtr p, Value *v)
|
||||||
{
|
{
|
||||||
|
|
||||||
int bracketed = 0;
|
|
||||||
int r;
|
int r;
|
||||||
|
int nonconst = 0;
|
||||||
|
expr_node *node = ParseExpr(p, &r);
|
||||||
|
|
||||||
if (p->isnested) return E_PARSE_ERR; /* Can't nest expressions */
|
if (r != OK) {
|
||||||
if (!p->pos) return E_PARSE_ERR; /* Missing expression */
|
return r;
|
||||||
while (isempty(*p->pos)) (p->pos)++;
|
|
||||||
if (*p->pos == BEG_OF_EXPR) {
|
|
||||||
(p->pos)++;
|
|
||||||
bracketed = 1;
|
|
||||||
}
|
}
|
||||||
r = EvalExpr(&(p->pos), v, p);
|
if (!node) {
|
||||||
|
return E_SWERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = evaluate_expression(node, NULL, v, &nonconst);
|
||||||
|
free_expr_tree(node);
|
||||||
if (r) return r;
|
if (r) return r;
|
||||||
if (bracketed) {
|
if (nonconst) {
|
||||||
if (*p->pos != END_OF_EXPR) return E_MISS_END;
|
p->nonconst_expr = 1;
|
||||||
(p->pos)++;
|
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -638,36 +759,36 @@ void Wprint(char const *fmt, ...)
|
|||||||
void Eprint(char const *fmt, ...)
|
void Eprint(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list argptr;
|
va_list argptr;
|
||||||
|
char const *fname;
|
||||||
|
|
||||||
/* Check if more than one error msg. from this line */
|
/* Check if more than one error msg. from this line */
|
||||||
if (!FreshLine && !ShowAllErrors) return;
|
if (!FreshLine && !ShowAllErrors) return;
|
||||||
|
|
||||||
if (FreshLine && FileName) {
|
if (!FileName) {
|
||||||
FreshLine = 0;
|
return;
|
||||||
if (strcmp(FileName, "-")) {
|
|
||||||
(void) fprintf(ErrFp, "%s(%d): ", FileName, LineNo);
|
|
||||||
if (print_callstack(ErrFp)) {
|
|
||||||
(void) fprintf(ErrFp, ": ");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
(void) fprintf(ErrFp, "-stdin-(%d): ", LineNo);
|
|
||||||
if (print_callstack(ErrFp)) {
|
|
||||||
(void) fprintf(ErrFp, ": ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (DebugFlag & DB_PRTLINE) OutputLine(ErrFp);
|
|
||||||
} else if (FileName) {
|
|
||||||
fprintf(ErrFp, " ");
|
|
||||||
if (print_callstack(ErrFp)) {
|
|
||||||
(void) fprintf(ErrFp, ": ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(FileName, "-")) {
|
||||||
|
fname = FileName;
|
||||||
|
} else {
|
||||||
|
fname = "-stdin-";
|
||||||
|
}
|
||||||
|
if (FreshLine) {
|
||||||
|
(void) fprintf(ErrFp, "%s(%d): ", fname, LineNo);
|
||||||
|
} else {
|
||||||
|
fprintf(ErrFp, " ");
|
||||||
|
}
|
||||||
va_start(argptr, fmt);
|
va_start(argptr, fmt);
|
||||||
(void) vfprintf(ErrFp, fmt, argptr);
|
(void) vfprintf(ErrFp, fmt, argptr);
|
||||||
(void) fputc('\n', ErrFp);
|
(void) fputc('\n', ErrFp);
|
||||||
va_end(argptr);
|
va_end(argptr);
|
||||||
return;
|
if (print_callstack(ErrFp)) {
|
||||||
|
(void) fprintf(ErrFp, "\n");
|
||||||
|
}
|
||||||
|
if (FreshLine) {
|
||||||
|
if (DebugFlag & DB_PRTLINE) OutputLine(ErrFp);
|
||||||
|
}
|
||||||
|
FreshLine = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
@@ -836,6 +957,7 @@ int DoIf(ParsePtr p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IfLinenos[NumIfs] = LineNo;
|
||||||
NumIfs++;
|
NumIfs++;
|
||||||
IfFlags &= ~(IF_MASK << (2*NumIfs - 2));
|
IfFlags &= ~(IF_MASK << (2*NumIfs - 2));
|
||||||
IfFlags |= syndrome << (2 * NumIfs - 2);
|
IfFlags |= syndrome << (2 * NumIfs - 2);
|
||||||
@@ -900,7 +1022,7 @@ int DoIfTrig(ParsePtr p)
|
|||||||
if ((size_t) NumIfs >= IF_NEST) return E_NESTED_IF;
|
if ((size_t) NumIfs >= IF_NEST) return E_NESTED_IF;
|
||||||
if (ShouldIgnoreLine()) syndrome = IF_TRUE | BEFORE_ELSE;
|
if (ShouldIgnoreLine()) syndrome = IF_TRUE | BEFORE_ELSE;
|
||||||
else {
|
else {
|
||||||
if ( (r=ParseRem(p, &trig, &tim, 1)) ) return r;
|
if ( (r=ParseRem(p, &trig, &tim)) ) return r;
|
||||||
if (trig.typ != NO_TYPE) return E_PARSE_ERR;
|
if (trig.typ != NO_TYPE) return E_PARSE_ERR;
|
||||||
dse = ComputeTrigger(trig.scanfrom, &trig, &tim, &r, 1);
|
dse = ComputeTrigger(trig.scanfrom, &trig, &tim, &r, 1);
|
||||||
if (r) {
|
if (r) {
|
||||||
@@ -1020,8 +1142,8 @@ int DoDebug(ParsePtr p)
|
|||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
case 'S':
|
case 'S':
|
||||||
if (val) DebugFlag |= DB_EXPR_STACKS;
|
if (val) DebugFlag |= DB_PARSE_EXPR;
|
||||||
else DebugFlag &= ~DB_EXPR_STACKS;
|
else DebugFlag &= ~DB_PARSE_EXPR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
@@ -1089,7 +1211,7 @@ int DoBanner(ParsePtr p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBufFree(&Banner);
|
DBufFree(&Banner);
|
||||||
|
|
||||||
err = DBufPuts(&Banner, DBufValue(&buf));
|
err = DBufPuts(&Banner, DBufValue(&buf));
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
return err;
|
return err;
|
||||||
@@ -1101,7 +1223,6 @@ int DoBanner(ParsePtr p)
|
|||||||
/* */
|
/* */
|
||||||
/* Enable or disable the RUN command under program control */
|
/* Enable or disable the RUN command under program control */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
int DoRun(ParsePtr p)
|
int DoRun(ParsePtr p)
|
||||||
{
|
{
|
||||||
@@ -1128,6 +1249,38 @@ int DoRun(ParsePtr p)
|
|||||||
return VerifyEoln(p);
|
return VerifyEoln(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/* */
|
||||||
|
/* DoExpr */
|
||||||
|
/* */
|
||||||
|
/* Enable or disable expression evaluation */
|
||||||
|
/* */
|
||||||
|
/***************************************************************/
|
||||||
|
int DoExpr(ParsePtr p)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
DynamicBuffer buf;
|
||||||
|
DBufInit(&buf);
|
||||||
|
|
||||||
|
if ( (r=ParseToken(p, &buf)) ) return r;
|
||||||
|
|
||||||
|
/* Only allow EXPR ON in top-level script */
|
||||||
|
if (! StrCmpi(DBufValue(&buf), "ON")) {
|
||||||
|
if (TopLevel()) ExpressionEvaluationDisabled = 0;
|
||||||
|
}
|
||||||
|
/* But allow EXPR OFF anywhere */
|
||||||
|
else if (! StrCmpi(DBufValue(&buf), "OFF"))
|
||||||
|
ExpressionEvaluationDisabled = 1;
|
||||||
|
else {
|
||||||
|
DBufFree(&buf);
|
||||||
|
return E_PARSE_ERR;
|
||||||
|
}
|
||||||
|
DBufFree(&buf);
|
||||||
|
|
||||||
|
return VerifyEoln(p);
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* DoFlush */
|
/* DoFlush */
|
||||||
|
|||||||
10
src/md5.h
10
src/md5.h
@@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_STDINT_H
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef uint32_t uint32;
|
||||||
|
#else
|
||||||
#if SIZEOF_UNSIGNED_INT == 4
|
#if SIZEOF_UNSIGNED_INT == 4
|
||||||
typedef unsigned int uint32;
|
typedef unsigned int uint32;
|
||||||
#elif SIZEOF_UNSIGNED_LONG == 4
|
#elif SIZEOF_UNSIGNED_LONG == 4
|
||||||
@@ -13,6 +17,7 @@ typedef unsigned long uint32;
|
|||||||
#else
|
#else
|
||||||
# error Could not find a 32-bit integer type
|
# error Could not find a 32-bit integer type
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
struct MD5Context {
|
struct MD5Context {
|
||||||
uint32 buf[4];
|
uint32 buf[4];
|
||||||
@@ -26,9 +31,4 @@ void MD5Update(struct MD5Context *context, unsigned char const *buf,
|
|||||||
void MD5Final(unsigned char digest[16], struct MD5Context *context);
|
void MD5Final(unsigned char digest[16], struct MD5Context *context);
|
||||||
void MD5Transform(uint32 buf[4], uint32 const in[16]);
|
void MD5Transform(uint32 buf[4], uint32 const in[16]);
|
||||||
|
|
||||||
/*
|
|
||||||
* This is needed to make RSAREF happy on some MS-DOS compilers.
|
|
||||||
*/
|
|
||||||
typedef struct MD5Context MD5_CTX;
|
|
||||||
|
|
||||||
#endif /* !MD5_H */
|
#endif /* !MD5_H */
|
||||||
|
|||||||
@@ -66,7 +66,6 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "expr.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
|
||||||
|
|||||||
28
src/omit.c
28
src/omit.c
@@ -14,13 +14,12 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "expr.h"
|
|
||||||
|
|
||||||
static int BexistsIntArray (int const array[], int num, int key);
|
static int BexistsIntArray (int const array[], int num, int key);
|
||||||
static void InsertIntoSortedArray (int *array, int num, int key);
|
static void InsertIntoSortedArray (int *array, int num, int key);
|
||||||
@@ -37,6 +36,8 @@ int NumFullOmits, NumPartialOmits;
|
|||||||
/* The structure for saving and restoring OMIT contexts */
|
/* The structure for saving and restoring OMIT contexts */
|
||||||
typedef struct omitcontext {
|
typedef struct omitcontext {
|
||||||
struct omitcontext *next;
|
struct omitcontext *next;
|
||||||
|
char *filename;
|
||||||
|
int lineno;
|
||||||
int numfull, numpart;
|
int numfull, numpart;
|
||||||
int *fullsave;
|
int *fullsave;
|
||||||
int *partsave;
|
int *partsave;
|
||||||
@@ -79,19 +80,25 @@ int DoClear(ParsePtr p)
|
|||||||
/* */
|
/* */
|
||||||
/* Free all the memory used by saved OMIT contexts. */
|
/* Free all the memory used by saved OMIT contexts. */
|
||||||
/* As a side effect, return the number of OMIT contexts */
|
/* As a side effect, return the number of OMIT contexts */
|
||||||
/* destroyed. */
|
/* destroyed. If print_unmatched is true, print an error for */
|
||||||
|
/* each undestroyed OMIT contect */
|
||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
int DestroyOmitContexts(void)
|
int DestroyOmitContexts(int print_unmatched)
|
||||||
{
|
{
|
||||||
OmitContext *c = SavedOmitContexts;
|
OmitContext *c = SavedOmitContexts;
|
||||||
OmitContext *d;
|
OmitContext *d;
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
|
||||||
while (c) {
|
while (c) {
|
||||||
|
if (print_unmatched) {
|
||||||
|
Wprint("Unmatched PUSH-OMIT-CONTEXT at %s(%d)",
|
||||||
|
c->filename, c->lineno);
|
||||||
|
}
|
||||||
num++;
|
num++;
|
||||||
if (c->fullsave) free(c->fullsave);
|
if (c->fullsave) free(c->fullsave);
|
||||||
if (c->partsave) free(c->partsave);
|
if (c->partsave) free(c->partsave);
|
||||||
|
if (c->filename) free(c->filename);
|
||||||
d = c->next;
|
d = c->next;
|
||||||
free(c);
|
free(c);
|
||||||
c = d;
|
c = d;
|
||||||
@@ -116,16 +123,28 @@ int PushOmitContext(ParsePtr p)
|
|||||||
context = NEW(OmitContext);
|
context = NEW(OmitContext);
|
||||||
if (!context) return E_NO_MEM;
|
if (!context) return E_NO_MEM;
|
||||||
|
|
||||||
|
if (FileName) {
|
||||||
|
context->filename = StrDup(FileName);
|
||||||
|
} else {
|
||||||
|
context->filename = StrDup("");
|
||||||
|
}
|
||||||
|
if (!context->filename) {
|
||||||
|
free(context);
|
||||||
|
return E_NO_MEM;
|
||||||
|
}
|
||||||
|
context->lineno = LineNo;
|
||||||
context->numfull = NumFullOmits;
|
context->numfull = NumFullOmits;
|
||||||
context->numpart = NumPartialOmits;
|
context->numpart = NumPartialOmits;
|
||||||
context->weekdaysave = WeekdayOmits;
|
context->weekdaysave = WeekdayOmits;
|
||||||
context->fullsave = malloc(NumFullOmits * sizeof(int));
|
context->fullsave = malloc(NumFullOmits * sizeof(int));
|
||||||
if (NumFullOmits && !context->fullsave) {
|
if (NumFullOmits && !context->fullsave) {
|
||||||
|
free(context->filename);
|
||||||
free(context);
|
free(context);
|
||||||
return E_NO_MEM;
|
return E_NO_MEM;
|
||||||
}
|
}
|
||||||
context->partsave = malloc(NumPartialOmits * sizeof(int));
|
context->partsave = malloc(NumPartialOmits * sizeof(int));
|
||||||
if (NumPartialOmits && !context->partsave) {
|
if (NumPartialOmits && !context->partsave) {
|
||||||
|
free(context->filename);
|
||||||
free(context->fullsave);
|
free(context->fullsave);
|
||||||
free(context);
|
free(context);
|
||||||
return E_NO_MEM;
|
return E_NO_MEM;
|
||||||
@@ -175,6 +194,7 @@ int PopOmitContext(ParsePtr p)
|
|||||||
/* Free memory used by the saved context */
|
/* Free memory used by the saved context */
|
||||||
if (c->partsave) free(c->partsave);
|
if (c->partsave) free(c->partsave);
|
||||||
if (c->fullsave) free(c->fullsave);
|
if (c->fullsave) free(c->fullsave);
|
||||||
|
if (c->filename) free(c->filename);
|
||||||
free(c);
|
free(c);
|
||||||
|
|
||||||
return VerifyEoln(p);
|
return VerifyEoln(p);
|
||||||
|
|||||||
58
src/protos.h
58
src/protos.h
@@ -13,6 +13,18 @@
|
|||||||
/* Suppress unused variable warnings */
|
/* Suppress unused variable warnings */
|
||||||
#define UNUSED(x) (void) x
|
#define UNUSED(x) (void) x
|
||||||
|
|
||||||
|
#ifdef HAVE_STRDUP
|
||||||
|
#define StrDup strdup
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STRNCASECMP
|
||||||
|
#define StrinCmp strncasecmp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STRCASECMP
|
||||||
|
#define StrCmpi strcasecmp
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define a string assignment macro - be careful!!! */
|
/* Define a string assignment macro - be careful!!! */
|
||||||
#define STRSET(x, str) { if (x) free(x); (x) = StrDup(str); }
|
#define STRSET(x, str) { if (x) free(x); (x) = StrDup(str); }
|
||||||
|
|
||||||
@@ -31,22 +43,30 @@
|
|||||||
int CallUserFunc (char const *name, int nargs, ParsePtr p);
|
int CallUserFunc (char const *name, int nargs, ParsePtr p);
|
||||||
int DoFset (ParsePtr p);
|
int DoFset (ParsePtr p);
|
||||||
int DoFunset (ParsePtr p);
|
int DoFunset (ParsePtr p);
|
||||||
|
void UnsetAllUserFuncs(void);
|
||||||
void ProduceCalendar (void);
|
void ProduceCalendar (void);
|
||||||
char const *SimpleTime (int tim);
|
char const *SimpleTime (int tim);
|
||||||
char const *CalendarTime (int tim, int duration);
|
char const *CalendarTime (int tim, int duration);
|
||||||
int DoRem (ParsePtr p);
|
int DoRem (ParsePtr p);
|
||||||
int DoFlush (ParsePtr p);
|
int DoFlush (ParsePtr p);
|
||||||
void DoExit (ParsePtr p);
|
void DoExit (ParsePtr p);
|
||||||
int ParseRem (ParsePtr s, Trigger *trig, TimeTrig *tim, int save_in_globals);
|
int ParseRem (ParsePtr s, Trigger *trig, TimeTrig *tim);
|
||||||
int TriggerReminder (ParsePtr p, Trigger *t, TimeTrig *tim, int dse, int is_queued, DynamicBuffer *output);
|
int TriggerReminder (ParsePtr p, Trigger *t, TimeTrig *tim, int dse, int is_queued, DynamicBuffer *output);
|
||||||
int ShouldTriggerReminder (Trigger *t, TimeTrig *tim, int dse, int *err);
|
int ShouldTriggerReminder (Trigger *t, TimeTrig *tim, int dse, int *err);
|
||||||
int DoSubst (ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, int mode);
|
int DoSubst (ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse, int mode);
|
||||||
int DoSubstFromString (char const *source, DynamicBuffer *dbuf, int dse, int tim);
|
int DoSubstFromString (char const *source, DynamicBuffer *dbuf, int dse, int tim);
|
||||||
int ParseLiteralDate (char const **s, int *dse, int *tim);
|
int ParseLiteralDate (char const **s, int *dse, int *tim);
|
||||||
int ParseLiteralTime (char const **s, int *tim);
|
int ParseLiteralTime (char const **s, int *tim);
|
||||||
|
expr_node *parse_expression(char const **e, int *r, Var *locals);
|
||||||
|
|
||||||
|
int evaluate_expression(expr_node *node, Value *locals, Value *ans, int *nonconst);
|
||||||
|
int evaluate_expr_node(expr_node *node, Value *locals, Value *ans, int *nonconst);
|
||||||
|
void print_expr_tree(expr_node *node, FILE *fp);
|
||||||
|
void unlimit_execution_time(void);
|
||||||
|
expr_node *free_expr_tree(expr_node *node);
|
||||||
int EvalExpr (char const **e, Value *v, ParsePtr p);
|
int EvalExpr (char const **e, Value *v, ParsePtr p);
|
||||||
int DoCoerce (char type, Value *v);
|
int DoCoerce (char type, Value *v);
|
||||||
void PrintValue (Value *v, FILE *fp);
|
char const *PrintValue (Value *v, FILE *fp);
|
||||||
int CopyValue (Value *dest, const Value *src);
|
int CopyValue (Value *dest, const Value *src);
|
||||||
int ReadLine (void);
|
int ReadLine (void);
|
||||||
int OpenFile (char const *fname);
|
int OpenFile (char const *fname);
|
||||||
@@ -65,8 +85,9 @@ int JulianToGregorianOffset(int y, int m);
|
|||||||
int ParseChar (ParsePtr p, int *err, int peek);
|
int ParseChar (ParsePtr p, int *err, int peek);
|
||||||
int ParseToken (ParsePtr p, DynamicBuffer *dbuf);
|
int ParseToken (ParsePtr p, DynamicBuffer *dbuf);
|
||||||
int ParseIdentifier (ParsePtr p, DynamicBuffer *dbuf);
|
int ParseIdentifier (ParsePtr p, DynamicBuffer *dbuf);
|
||||||
|
expr_node * ParseExpr(ParsePtr p, int *r);
|
||||||
|
void print_expr_nodes_stats(void);
|
||||||
int EvaluateExpr (ParsePtr p, Value *v);
|
int EvaluateExpr (ParsePtr p, Value *v);
|
||||||
int Evaluate (char const **s, Var *locals, ParsePtr p);
|
|
||||||
int FnPopValStack (Value *val);
|
int FnPopValStack (Value *val);
|
||||||
void Eprint (char const *fmt, ...);
|
void Eprint (char const *fmt, ...);
|
||||||
void Wprint (char const *fmt, ...);
|
void Wprint (char const *fmt, ...);
|
||||||
@@ -86,10 +107,11 @@ int VerifyEoln (ParsePtr p);
|
|||||||
int DoDebug (ParsePtr p);
|
int DoDebug (ParsePtr p);
|
||||||
int DoBanner (ParsePtr p);
|
int DoBanner (ParsePtr p);
|
||||||
int DoRun (ParsePtr p);
|
int DoRun (ParsePtr p);
|
||||||
|
int DoExpr (ParsePtr p);
|
||||||
int DoErrMsg (ParsePtr p);
|
int DoErrMsg (ParsePtr p);
|
||||||
int ClearGlobalOmits (void);
|
int ClearGlobalOmits (void);
|
||||||
int DoClear (ParsePtr p);
|
int DoClear (ParsePtr p);
|
||||||
int DestroyOmitContexts (void);
|
int DestroyOmitContexts (int print_unmatched);
|
||||||
int PushOmitContext (ParsePtr p);
|
int PushOmitContext (ParsePtr p);
|
||||||
int PopOmitContext (ParsePtr p);
|
int PopOmitContext (ParsePtr p);
|
||||||
int IsOmitted (int dse, int localomit, char const *omitfunc, int *omit);
|
int IsOmitted (int dse, int localomit, char const *omitfunc, int *omit);
|
||||||
@@ -103,13 +125,26 @@ int ComputeTrigger (int today, Trigger *trig, TimeTrig *tim, int *err, int save_
|
|||||||
int ComputeTriggerNoAdjustDuration (int today, Trigger *trig, TimeTrig *tim, int *err, int save_in_globals, int duration_days);
|
int ComputeTriggerNoAdjustDuration (int today, Trigger *trig, TimeTrig *tim, int *err, int save_in_globals, int duration_days);
|
||||||
int AdjustTriggerForDuration(int today, int r, Trigger *trig, TimeTrig *tim, int save_in_globals);
|
int AdjustTriggerForDuration(int today, int r, Trigger *trig, TimeTrig *tim, int save_in_globals);
|
||||||
char *StrnCpy (char *dest, char const *source, int n);
|
char *StrnCpy (char *dest, char const *source, int n);
|
||||||
|
|
||||||
|
#ifndef HAVE_STRNCASECMP
|
||||||
int StrinCmp (char const *s1, char const *s2, int n);
|
int StrinCmp (char const *s1, char const *s2, int n);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRDUP
|
||||||
char *StrDup (char const *s);
|
char *StrDup (char const *s);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRCASECMP
|
||||||
int StrCmpi (char const *s1, char const *s2);
|
int StrCmpi (char const *s1, char const *s2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void strtolower(char *s);
|
||||||
|
|
||||||
Var *FindVar (char const *str, int create);
|
Var *FindVar (char const *str, int create);
|
||||||
|
SysVar *FindSysVar (char const *name);
|
||||||
int DeleteVar (char const *str);
|
int DeleteVar (char const *str);
|
||||||
int SetVar (char const *str, Value const *val);
|
int SetVar (char const *str, Value const *val);
|
||||||
int GetVarValue (char const *str, Value *val, Var *locals, ParsePtr p);
|
int GetVarValue (char const *str, Value *val);
|
||||||
int DoSet (Parser *p);
|
int DoSet (Parser *p);
|
||||||
int DoUnset (Parser *p);
|
int DoUnset (Parser *p);
|
||||||
int DoDump (ParsePtr p);
|
int DoDump (ParsePtr p);
|
||||||
@@ -122,10 +157,10 @@ int DoMsgCommand (char const *cmd, char const *msg, int is_queued);
|
|||||||
int ParseNonSpaceChar (ParsePtr p, int *err, int peek);
|
int ParseNonSpaceChar (ParsePtr p, int *err, int peek);
|
||||||
unsigned int HashVal (char const *str);
|
unsigned int HashVal (char const *str);
|
||||||
int DateOK (int y, int m, int d);
|
int DateOK (int y, int m, int d);
|
||||||
Operator *FindOperator (char const *name, Operator where[], int num);
|
BuiltinFunc *FindBuiltinFunc (char const *name);
|
||||||
BuiltinFunc *FindFunc (char const *name, BuiltinFunc where[], int num);
|
|
||||||
int InsertIntoSortBuffer (int dse, int tim, char const *body, int typ, int prio);
|
int InsertIntoSortBuffer (int dse, int tim, char const *body, int typ, int prio);
|
||||||
void IssueSortedReminders (void);
|
void IssueSortedReminders (void);
|
||||||
|
UserFunc *FindUserFunc(char const *name);
|
||||||
int UserFuncExists (char const *fn);
|
int UserFuncExists (char const *fn);
|
||||||
void DSEToHeb (int dse, int *hy, int *hm, int *hd);
|
void DSEToHeb (int dse, int *hy, int *hm, int *hd);
|
||||||
int HebNameToNum (char const *mname);
|
int HebNameToNum (char const *mname);
|
||||||
@@ -185,6 +220,7 @@ void set_cloexec(FILE *fp);
|
|||||||
int push_call(char const *filename, char const *func, int lineno);
|
int push_call(char const *filename, char const *func, int lineno);
|
||||||
void clear_callstack(void);
|
void clear_callstack(void);
|
||||||
int print_callstack(FILE *fp);
|
int print_callstack(FILE *fp);
|
||||||
|
int have_callstack(void);
|
||||||
void pop_call(void);
|
void pop_call(void);
|
||||||
void FixSpecialType(Trigger *trig);
|
void FixSpecialType(Trigger *trig);
|
||||||
void WriteJSONTrigger(Trigger const *t, int include_tags, int today);
|
void WriteJSONTrigger(Trigger const *t, int include_tags, int today);
|
||||||
@@ -195,3 +231,11 @@ void WriteJSONTimeTrigger(TimeTrig const *tt);
|
|||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
void PutWideChar(wchar_t const wc, DynamicBuffer *output);
|
void PutWideChar(wchar_t const wc, DynamicBuffer *output);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* These functions are in utils.c and are used to detect overflow
|
||||||
|
in various arithmetic operators. They have to be in separate
|
||||||
|
functions with extern linkage to defeat compiler optimizations
|
||||||
|
that would otherwise break the overflow checks. */
|
||||||
|
extern int _private_mul_overflow(int a, int b);
|
||||||
|
extern int _private_add_overflow(int a, int b);
|
||||||
|
extern int _private_sub_overflow(int a, int b);
|
||||||
|
|||||||
10
src/queue.c
10
src/queue.c
@@ -34,7 +34,6 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "expr.h"
|
|
||||||
|
|
||||||
#undef USE_INOTIFY
|
#undef USE_INOTIFY
|
||||||
#if defined(HAVE_SYS_INOTIFY_H) && defined(HAVE_INOTIFY_INIT1)
|
#if defined(HAVE_SYS_INOTIFY_H) && defined(HAVE_INOTIFY_INIT1)
|
||||||
@@ -311,6 +310,12 @@ void HandleQueuedReminders(void)
|
|||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
char qid[64];
|
char qid[64];
|
||||||
|
|
||||||
|
/* Disable any potential pending SIGALRMs */
|
||||||
|
alarm(0);
|
||||||
|
|
||||||
|
/* Un-limit execution time */
|
||||||
|
unlimit_execution_time();
|
||||||
|
|
||||||
/* Turn off sorting -- otherwise, TriggerReminder has no effect! */
|
/* Turn off sorting -- otherwise, TriggerReminder has no effect! */
|
||||||
SortByDate = 0;
|
SortByDate = 0;
|
||||||
|
|
||||||
@@ -354,7 +359,8 @@ void HandleQueuedReminders(void)
|
|||||||
|
|
||||||
if (ShouldFork || Daemon) {
|
if (ShouldFork || Daemon) {
|
||||||
sa.sa_handler = SigIntHandler;
|
sa.sa_handler = SigIntHandler;
|
||||||
sa.sa_flags = 0;
|
sa.sa_flags = SA_RESTART;
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
(void) sigaction(SIGINT, &sa, NULL);
|
(void) sigaction(SIGINT, &sa, NULL);
|
||||||
sa.sa_handler = SigContHandler;
|
sa.sa_handler = SigContHandler;
|
||||||
(void) sigaction(SIGCONT, &sa, NULL);
|
(void) sigaction(SIGCONT, &sa, NULL);
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "expr.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ Token TokArray[] = {
|
|||||||
{ "endif", 5, T_EndIf, 0 },
|
{ "endif", 5, T_EndIf, 0 },
|
||||||
{ "errmsg", 6, T_ErrMsg, 0 },
|
{ "errmsg", 6, T_ErrMsg, 0 },
|
||||||
{ "exit", 4, T_Exit, 0 },
|
{ "exit", 4, T_Exit, 0 },
|
||||||
|
{ "expr", 4, T_Expr, 0 },
|
||||||
{ "february", 3, T_Month, 1 },
|
{ "february", 3, T_Month, 1 },
|
||||||
{ "first", 5, T_Ordinal, 0 },
|
{ "first", 5, T_Ordinal, 0 },
|
||||||
{ "flush", 5, T_Flush, 0 },
|
{ "flush", 5, T_Flush, 0 },
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "expr.h"
|
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
|||||||
92
src/types.h
92
src/types.h
@@ -13,6 +13,22 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "dynbuf.h"
|
#include "dynbuf.h"
|
||||||
|
|
||||||
|
typedef struct udf_struct UserFunc;
|
||||||
|
|
||||||
|
/* Define the types of values */
|
||||||
|
#define ERR_TYPE 0
|
||||||
|
#define INT_TYPE 1
|
||||||
|
#define TIME_TYPE 2
|
||||||
|
#define DATE_TYPE 3
|
||||||
|
#define STR_TYPE 4
|
||||||
|
#define DATETIME_TYPE 5
|
||||||
|
#define SPECIAL_TYPE 6 /* Only for system variables */
|
||||||
|
#define CONST_INT_TYPE 7 /* Only for system variables */
|
||||||
|
|
||||||
|
#define BEG_OF_EXPR '['
|
||||||
|
#define END_OF_EXPR ']'
|
||||||
|
#define COMMA ','
|
||||||
|
|
||||||
/* Values */
|
/* Values */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char type;
|
char type;
|
||||||
@@ -22,29 +38,61 @@ typedef struct {
|
|||||||
} v;
|
} v;
|
||||||
} Value;
|
} Value;
|
||||||
|
|
||||||
/* Define the type of operators */
|
/* New-style expr_node structure and constants */
|
||||||
typedef struct {
|
enum expr_node_type
|
||||||
char const *name;
|
{
|
||||||
char prec;
|
N_FREE,
|
||||||
char type;
|
N_ERROR,
|
||||||
int (*func)(void);
|
N_CONSTANT,
|
||||||
} Operator;
|
N_LOCAL_VAR,
|
||||||
|
N_SHORT_VAR,
|
||||||
|
N_VARIABLE,
|
||||||
|
N_SHORT_SYSVAR,
|
||||||
|
N_SYSVAR,
|
||||||
|
N_BUILTIN_FUNC,
|
||||||
|
N_SHORT_USER_FUNC,
|
||||||
|
N_USER_FUNC,
|
||||||
|
N_OPERATOR,
|
||||||
|
};
|
||||||
|
|
||||||
/* Structure for passing in Nargs and out RetVal from functions */
|
/* Structure for passing in Nargs and out RetVal from functions */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int nargs;
|
int nargs;
|
||||||
|
Value *args;
|
||||||
Value retval;
|
Value retval;
|
||||||
} func_info;
|
} func_info;
|
||||||
|
|
||||||
|
/* Forward reference */
|
||||||
|
typedef struct expr_node_struct expr_node;
|
||||||
|
|
||||||
/* Define the type of user-functions */
|
/* Define the type of user-functions */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char const *name;
|
char const *name;
|
||||||
char minargs;
|
char minargs;
|
||||||
char maxargs;
|
char maxargs;
|
||||||
char is_constant;
|
char is_constant;
|
||||||
|
/* Old-style function calling convention */
|
||||||
int (*func)(func_info *);
|
int (*func)(func_info *);
|
||||||
|
|
||||||
|
/* New-style function calling convention */
|
||||||
|
int (*newfunc)(expr_node *node, Value *locals, Value *ans, int *nonconst);
|
||||||
} BuiltinFunc;
|
} BuiltinFunc;
|
||||||
|
|
||||||
|
#define SHORT_NAME_BUF 16
|
||||||
|
typedef struct expr_node_struct {
|
||||||
|
struct expr_node_struct *child;
|
||||||
|
struct expr_node_struct *sibling;
|
||||||
|
enum expr_node_type type;
|
||||||
|
int num_kids;
|
||||||
|
union {
|
||||||
|
Value value;
|
||||||
|
int arg;
|
||||||
|
BuiltinFunc *builtin_func;
|
||||||
|
char name[SHORT_NAME_BUF];
|
||||||
|
int (*operator_func) (struct expr_node_struct *node, Value *locals, Value *ans, int *nonconst);
|
||||||
|
} u;
|
||||||
|
} expr_node;
|
||||||
|
|
||||||
/* Define the structure of a variable */
|
/* Define the structure of a variable */
|
||||||
typedef struct var {
|
typedef struct var {
|
||||||
struct var *next;
|
struct var *next;
|
||||||
@@ -142,6 +190,8 @@ typedef Parser *ParsePtr; /* Pointer to parser structure */
|
|||||||
#define MSF_TYPE 7
|
#define MSF_TYPE 7
|
||||||
#define PASSTHRU_TYPE 8
|
#define PASSTHRU_TYPE 8
|
||||||
|
|
||||||
|
/* For function arguments */
|
||||||
|
#define NO_MAX 127
|
||||||
|
|
||||||
/* DEFINES for debugging flags */
|
/* DEFINES for debugging flags */
|
||||||
#define DB_PRTLINE 1
|
#define DB_PRTLINE 1
|
||||||
@@ -150,7 +200,7 @@ typedef Parser *ParsePtr; /* Pointer to parser structure */
|
|||||||
#define DB_DUMP_VARS 8
|
#define DB_DUMP_VARS 8
|
||||||
#define DB_ECHO_LINE 16
|
#define DB_ECHO_LINE 16
|
||||||
#define DB_TRACE_FILES 32
|
#define DB_TRACE_FILES 32
|
||||||
#define DB_EXPR_STACKS 64
|
#define DB_PARSE_EXPR 64
|
||||||
|
|
||||||
/* Enumeration of the tokens */
|
/* Enumeration of the tokens */
|
||||||
enum TokTypes
|
enum TokTypes
|
||||||
@@ -184,7 +234,8 @@ enum TokTypes
|
|||||||
T_MaybeUncomputable,
|
T_MaybeUncomputable,
|
||||||
T_Ordinal,
|
T_Ordinal,
|
||||||
T_In,
|
T_In,
|
||||||
T_LastBack
|
T_LastBack,
|
||||||
|
T_Expr
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The structure of a token */
|
/* The structure of a token */
|
||||||
@@ -244,3 +295,26 @@ typedef struct {
|
|||||||
#define TERMINAL_BACKGROUND_UNKNOWN -1
|
#define TERMINAL_BACKGROUND_UNKNOWN -1
|
||||||
#define TERMINAL_BACKGROUND_DARK 0
|
#define TERMINAL_BACKGROUND_DARK 0
|
||||||
#define TERMINAL_BACKGROUND_LIGHT 1
|
#define TERMINAL_BACKGROUND_LIGHT 1
|
||||||
|
|
||||||
|
typedef int (*SysVarFunc)(int, Value *);
|
||||||
|
/* The structure of a system variable */
|
||||||
|
typedef struct {
|
||||||
|
char const *name;
|
||||||
|
char modifiable;
|
||||||
|
int type;
|
||||||
|
void *value;
|
||||||
|
int min; /* Or const-value */
|
||||||
|
int max;
|
||||||
|
} SysVar;
|
||||||
|
|
||||||
|
/* Define the data structure used to hold a user-defined function */
|
||||||
|
typedef struct udf_struct {
|
||||||
|
struct udf_struct *next;
|
||||||
|
char name[VAR_NAME_LEN+1];
|
||||||
|
expr_node *node;
|
||||||
|
char **args;
|
||||||
|
int nargs;
|
||||||
|
char const *filename;
|
||||||
|
int lineno;
|
||||||
|
} UserFunc;
|
||||||
|
|
||||||
|
|||||||
331
src/userfns.c
331
src/userfns.c
@@ -16,43 +16,46 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
#include <strings.h>
|
||||||
|
#endif
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "expr.h"
|
|
||||||
|
|
||||||
#define FUNC_HASH_SIZE 32 /* Size of User-defined function hash table */
|
#define FUNC_HASH_SIZE 32 /* Size of User-defined function hash table */
|
||||||
|
|
||||||
/* Define the data structure used to hold a user-defined function */
|
|
||||||
typedef struct udf_struct {
|
|
||||||
struct udf_struct *next;
|
|
||||||
char name[VAR_NAME_LEN+1];
|
|
||||||
char const *text;
|
|
||||||
Var *locals;
|
|
||||||
char IsActive;
|
|
||||||
int nargs;
|
|
||||||
char const *filename;
|
|
||||||
int lineno;
|
|
||||||
} UserFunc;
|
|
||||||
|
|
||||||
/* The hash table */
|
/* The hash table */
|
||||||
static UserFunc *FuncHash[FUNC_HASH_SIZE];
|
static UserFunc *FuncHash[FUNC_HASH_SIZE];
|
||||||
|
|
||||||
/* Access to built-in functions */
|
|
||||||
extern int NumFuncs;
|
|
||||||
extern BuiltinFunc Func[];
|
|
||||||
|
|
||||||
/* We need access to the expression evaluation stack */
|
|
||||||
extern Value ValStack[];
|
|
||||||
extern int ValStackPtr;
|
|
||||||
|
|
||||||
static void DestroyUserFunc (UserFunc *f);
|
static void DestroyUserFunc (UserFunc *f);
|
||||||
static void FUnset (char const *name);
|
static void FUnset (char const *name);
|
||||||
static void FSet (UserFunc *f);
|
static void FSet (UserFunc *f);
|
||||||
static int SetUpLocalVars (UserFunc *f);
|
|
||||||
static void DestroyLocalVals (UserFunc *f);
|
/***************************************************************/
|
||||||
|
/* */
|
||||||
|
/* HashVal */
|
||||||
|
/* Given a string, compute the hash value. */
|
||||||
|
/* */
|
||||||
|
/***************************************************************/
|
||||||
|
unsigned int HashVal_nocase(char const *str)
|
||||||
|
{
|
||||||
|
register unsigned int i=0;
|
||||||
|
register unsigned int j=1;
|
||||||
|
register unsigned int len=0;
|
||||||
|
|
||||||
|
while(*str && len < VAR_NAME_LEN) {
|
||||||
|
i += j * (*str);
|
||||||
|
str++;
|
||||||
|
len++;
|
||||||
|
j = 3-j;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
@@ -75,6 +78,7 @@ int DoFunset(ParsePtr p)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
seen_one = 1;
|
seen_one = 1;
|
||||||
|
strtolower(DBufValue(&buf));
|
||||||
FUnset(DBufValue(&buf));
|
FUnset(DBufValue(&buf));
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
}
|
}
|
||||||
@@ -93,8 +97,11 @@ int DoFset(ParsePtr p)
|
|||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
int c;
|
int c;
|
||||||
|
int i;
|
||||||
UserFunc *func;
|
UserFunc *func;
|
||||||
Var *v;
|
UserFunc *existing;
|
||||||
|
Var *locals = NULL;
|
||||||
|
Var local_array[MAX_FUNC_ARGS];
|
||||||
int orig_namelen;
|
int orig_namelen;
|
||||||
|
|
||||||
DynamicBuffer buf;
|
DynamicBuffer buf;
|
||||||
@@ -119,6 +126,21 @@ int DoFset(ParsePtr p)
|
|||||||
return E_PARSE_ERR;
|
return E_PARSE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert to lower-case */
|
||||||
|
strtolower(DBufValue(&buf));
|
||||||
|
|
||||||
|
/* If the function exists and was defined at the same line of the same
|
||||||
|
file, do nothing */
|
||||||
|
existing = FindUserFunc(DBufValue(&buf));
|
||||||
|
if (existing) {
|
||||||
|
if (!strcmp(existing->filename, FileName) &&
|
||||||
|
strcmp(existing->filename, "[cmdline]") &&
|
||||||
|
existing->lineno == LineNo) {
|
||||||
|
DBufFree(&buf);
|
||||||
|
/* We already have it! Our work here is done. */
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
func = NEW(UserFunc);
|
func = NEW(UserFunc);
|
||||||
if (!func) {
|
if (!func) {
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
@@ -137,25 +159,22 @@ int DoFset(ParsePtr p)
|
|||||||
StrnCpy(func->name, DBufValue(&buf), VAR_NAME_LEN);
|
StrnCpy(func->name, DBufValue(&buf), VAR_NAME_LEN);
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
if (!Hush) {
|
if (!Hush) {
|
||||||
if (FindFunc(func->name, Func, NumFuncs)) {
|
if (FindBuiltinFunc(func->name)) {
|
||||||
Eprint("%s: `%s'", ErrMsg[E_REDEF_FUNC], func->name);
|
Eprint("%s: `%s'", ErrMsg[E_REDEF_FUNC], func->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func->locals = NULL;
|
func->node = NULL;
|
||||||
func->text = NULL;
|
|
||||||
func->IsActive = 0;
|
|
||||||
func->nargs = 0;
|
func->nargs = 0;
|
||||||
|
func->args = NULL;
|
||||||
|
|
||||||
/* Get the local variables - we insert the local variables in REVERSE
|
/* Get the local variables */
|
||||||
order, but that's OK, because we pop them off the stack in reverse
|
|
||||||
order, too, so everything works out just fine. */
|
|
||||||
|
|
||||||
c=ParseNonSpaceChar(p, &r, 1);
|
c=ParseNonSpaceChar(p, &r, 1);
|
||||||
if (r) return r;
|
if (r) return r;
|
||||||
if (c == ')') {
|
if (c == ')') {
|
||||||
(void) ParseNonSpaceChar(p, &r, 0);
|
(void) ParseNonSpaceChar(p, &r, 0);
|
||||||
}
|
} else {
|
||||||
else {
|
locals = local_array;
|
||||||
while(1) {
|
while(1) {
|
||||||
if ( (r=ParseIdentifier(p, &buf)) ) return r;
|
if ( (r=ParseIdentifier(p, &buf)) ) return r;
|
||||||
if (*DBufValue(&buf) == '$') {
|
if (*DBufValue(&buf) == '$') {
|
||||||
@@ -163,18 +182,25 @@ int DoFset(ParsePtr p)
|
|||||||
DestroyUserFunc(func);
|
DestroyUserFunc(func);
|
||||||
return E_BAD_ID;
|
return E_BAD_ID;
|
||||||
}
|
}
|
||||||
v = NEW(Var);
|
/* If we've already seen this local variable, error */
|
||||||
if (!v) {
|
for (i=0; i<func->nargs; i++) {
|
||||||
DBufFree(&buf);
|
if (!StrinCmp(DBufValue(&buf), local_array[i].name, VAR_NAME_LEN)) {
|
||||||
DestroyUserFunc(func);
|
DBufFree(&buf);
|
||||||
return E_NO_MEM;
|
DestroyUserFunc(func);
|
||||||
}
|
return E_REPEATED_ARG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i = func->nargs;
|
||||||
|
if (i >= MAX_FUNC_ARGS-1) {
|
||||||
|
DBufFree(&buf);
|
||||||
|
DestroyUserFunc(func);
|
||||||
|
return E_2MANY_ARGS;
|
||||||
|
}
|
||||||
|
local_array[i].v.type = ERR_TYPE;
|
||||||
|
StrnCpy(local_array[i].name, DBufValue(&buf), VAR_NAME_LEN);
|
||||||
|
local_array[i].next = &(local_array[i+1]);
|
||||||
|
local_array[i+1].next = NULL;
|
||||||
func->nargs++;
|
func->nargs++;
|
||||||
v->v.type = ERR_TYPE;
|
|
||||||
StrnCpy(v->name, DBufValue(&buf), VAR_NAME_LEN);
|
|
||||||
DBufFree(&buf);
|
|
||||||
v->next = func->locals;
|
|
||||||
func->locals = v;
|
|
||||||
c = ParseNonSpaceChar(p, &r, 0);
|
c = ParseNonSpaceChar(p, &r, 0);
|
||||||
if (c == ')') break;
|
if (c == ')') break;
|
||||||
else if (c != ',') {
|
else if (c != ',') {
|
||||||
@@ -189,17 +215,42 @@ int DoFset(ParsePtr p)
|
|||||||
if (c == '=') {
|
if (c == '=') {
|
||||||
(void) ParseNonSpaceChar(p, &r, 0);
|
(void) ParseNonSpaceChar(p, &r, 0);
|
||||||
}
|
}
|
||||||
/* Copy the text over */
|
|
||||||
if (p->isnested) {
|
if (p->isnested) {
|
||||||
Eprint("%s", ErrMsg[E_CANTNEST_FDEF]);
|
Eprint("%s", ErrMsg[E_CANTNEST_FDEF]);
|
||||||
DestroyUserFunc(func);
|
DestroyUserFunc(func);
|
||||||
return E_PARSE_ERR;
|
return E_PARSE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
func->text = StrDup(p->pos);
|
while(*(p->pos) && isspace(*(p->pos))) {
|
||||||
if (!func->text) {
|
p->pos++;
|
||||||
DestroyUserFunc(func);
|
}
|
||||||
return E_NO_MEM;
|
if (!*(p->pos)) {
|
||||||
|
DestroyUserFunc(func);
|
||||||
|
return E_EOLN;
|
||||||
|
}
|
||||||
|
/* Parse the expression */
|
||||||
|
func->node = parse_expression(&(p->pos), &r, locals);
|
||||||
|
if (!func->node) {
|
||||||
|
DestroyUserFunc(func);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = ParseNonSpaceChar(p, &r, 1);
|
||||||
|
if (c != 0) {
|
||||||
|
DestroyUserFunc(func);
|
||||||
|
return E_EXPECTING_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save the argument names */
|
||||||
|
if (func->nargs) {
|
||||||
|
func->args = calloc(sizeof(char *), func->nargs);
|
||||||
|
for (i=0; i<func->nargs; i++) {
|
||||||
|
func->args[i] = StrDup(local_array[i].name);
|
||||||
|
if (!func->args[i]) {
|
||||||
|
DestroyUserFunc(func);
|
||||||
|
return E_NO_MEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If an old definition of this function exists, destroy it */
|
/* If an old definition of this function exists, destroy it */
|
||||||
@@ -223,23 +274,22 @@ int DoFset(ParsePtr p)
|
|||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
static void DestroyUserFunc(UserFunc *f)
|
static void DestroyUserFunc(UserFunc *f)
|
||||||
{
|
{
|
||||||
Var *v, *prev;
|
int i;
|
||||||
|
|
||||||
/* Free the local variables first */
|
|
||||||
v = f->locals;
|
|
||||||
while(v) {
|
|
||||||
DestroyValue(v->v);
|
|
||||||
prev = v;
|
|
||||||
v = v->next;
|
|
||||||
free(prev);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free the function definition */
|
/* Free the function definition */
|
||||||
if (f->text) free( (char *) f->text);
|
if (f->node) free_expr_tree(f->node);
|
||||||
|
|
||||||
/* Free the filename */
|
/* Free the filename */
|
||||||
if (f->filename) free( (char *) f->filename);
|
if (f->filename) free( (char *) f->filename);
|
||||||
|
|
||||||
|
/* Free arg names */
|
||||||
|
if (f->args) {
|
||||||
|
for (i=0; i<f->nargs; i++) {
|
||||||
|
if (f->args[i]) free(f->args[i]);
|
||||||
|
}
|
||||||
|
free(f->args);
|
||||||
|
}
|
||||||
|
|
||||||
/* Free the data structure itself */
|
/* Free the data structure itself */
|
||||||
free(f);
|
free(f);
|
||||||
}
|
}
|
||||||
@@ -257,12 +307,12 @@ static void FUnset(char const *name)
|
|||||||
UserFunc *cur, *prev;
|
UserFunc *cur, *prev;
|
||||||
int h;
|
int h;
|
||||||
|
|
||||||
h = HashVal(name) % FUNC_HASH_SIZE;
|
h = HashVal_nocase(name) % FUNC_HASH_SIZE;
|
||||||
|
|
||||||
cur = FuncHash[h];
|
cur = FuncHash[h];
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
while(cur) {
|
while(cur) {
|
||||||
if (! StrinCmp(name, cur->name, VAR_NAME_LEN)) break;
|
if (! strncmp(name, cur->name, VAR_NAME_LEN)) break;
|
||||||
prev = cur;
|
prev = cur;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
@@ -280,134 +330,22 @@ static void FUnset(char const *name)
|
|||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
static void FSet(UserFunc *f)
|
static void FSet(UserFunc *f)
|
||||||
{
|
{
|
||||||
int h = HashVal(f->name) % FUNC_HASH_SIZE;
|
int h = HashVal_nocase(f->name) % FUNC_HASH_SIZE;
|
||||||
f->next = FuncHash[h];
|
f->next = FuncHash[h];
|
||||||
FuncHash[h] = f;
|
FuncHash[h] = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
UserFunc *FindUserFunc(char const *name)
|
||||||
/* */
|
|
||||||
/* CallUserFunc */
|
|
||||||
/* */
|
|
||||||
/* Call a user-defined function. */
|
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
|
||||||
int CallUserFunc(char const *name, int nargs, ParsePtr p)
|
|
||||||
{
|
{
|
||||||
UserFunc *f;
|
UserFunc *f;
|
||||||
int h = HashVal(name) % FUNC_HASH_SIZE;
|
int h = HashVal_nocase(name) % FUNC_HASH_SIZE;
|
||||||
int i;
|
|
||||||
char const *s;
|
|
||||||
|
|
||||||
/* Search for the function */
|
/* Search for the function */
|
||||||
f = FuncHash[h];
|
f = FuncHash[h];
|
||||||
while (f && StrinCmp(name, f->name, VAR_NAME_LEN)) f = f->next;
|
while (f && strncmp(name, f->name, VAR_NAME_LEN)) f = f->next;
|
||||||
if (!f) {
|
return f;
|
||||||
Eprint("%s: `%s'", ErrMsg[E_UNDEF_FUNC], name);
|
|
||||||
return E_UNDEF_FUNC;
|
|
||||||
}
|
|
||||||
/* Debugging stuff */
|
|
||||||
if (DebugFlag & DB_PRTEXPR) {
|
|
||||||
fprintf(ErrFp, "%s %s(", ErrMsg[E_ENTER_FUN], f->name);
|
|
||||||
for (i=0; i<nargs; i++) {
|
|
||||||
PrintValue(&ValStack[ValStackPtr - nargs + i], ErrFp);
|
|
||||||
if (i<nargs-1) fprintf(ErrFp, ", ");
|
|
||||||
}
|
|
||||||
fprintf(ErrFp, ")\n");
|
|
||||||
}
|
|
||||||
/* Detect illegal recursive call */
|
|
||||||
if (f->IsActive) {
|
|
||||||
if (DebugFlag &DB_PRTEXPR) {
|
|
||||||
fprintf(ErrFp, "%s %s() => ", ErrMsg[E_LEAVE_FUN], name);
|
|
||||||
fprintf(ErrFp, "%s\n", ErrMsg[E_RECURSIVE]);
|
|
||||||
}
|
|
||||||
return E_RECURSIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check number of args */
|
|
||||||
if (nargs != f->nargs) {
|
|
||||||
if (DebugFlag &DB_PRTEXPR) {
|
|
||||||
fprintf(ErrFp, "%s %s() => ", ErrMsg[E_LEAVE_FUN], name);
|
|
||||||
fprintf(ErrFp, "%s\n",
|
|
||||||
ErrMsg[(nargs < f->nargs) ? E_2FEW_ARGS : E_2MANY_ARGS]);
|
|
||||||
}
|
|
||||||
return (nargs < f->nargs) ? E_2FEW_ARGS : E_2MANY_ARGS;
|
|
||||||
}
|
|
||||||
/* Found the function - set up a local variable frame */
|
|
||||||
h = SetUpLocalVars(f);
|
|
||||||
if (h) {
|
|
||||||
if (DebugFlag &DB_PRTEXPR) {
|
|
||||||
fprintf(ErrFp, "%s %s() => ", ErrMsg[E_LEAVE_FUN], name);
|
|
||||||
fprintf(ErrFp, "%s\n", ErrMsg[h]);
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Evaluate the expression */
|
|
||||||
f->IsActive = 1;
|
|
||||||
s = f->text;
|
|
||||||
|
|
||||||
/* Skip the opening bracket, if there's one */
|
|
||||||
while (isempty(*s)) s++;
|
|
||||||
if (*s == BEG_OF_EXPR) {
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
push_call(f->filename, f->name, f->lineno);
|
|
||||||
h = Evaluate(&s, f->locals, p);
|
|
||||||
if (h == OK) {
|
|
||||||
pop_call();
|
|
||||||
}
|
|
||||||
f->IsActive = 0;
|
|
||||||
DestroyLocalVals(f);
|
|
||||||
if (DebugFlag &DB_PRTEXPR) {
|
|
||||||
fprintf(ErrFp, "%s %s() => ", ErrMsg[E_LEAVE_FUN], name);
|
|
||||||
if (h) fprintf(ErrFp, "%s\n", ErrMsg[h]);
|
|
||||||
else {
|
|
||||||
PrintValue(&ValStack[ValStackPtr-1], ErrFp);
|
|
||||||
fprintf(ErrFp, "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
|
||||||
/* */
|
|
||||||
/* SetUpLocalVars */
|
|
||||||
/* */
|
|
||||||
/* Set up the local variables from the stack frame. */
|
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
|
||||||
static int SetUpLocalVars(UserFunc *f)
|
|
||||||
{
|
|
||||||
int i, r;
|
|
||||||
Var *var;
|
|
||||||
|
|
||||||
for (i=0, var=f->locals; var && i<f->nargs; var=var->next, i++) {
|
|
||||||
if ( (r=FnPopValStack(&(var->v))) ) {
|
|
||||||
DestroyLocalVals(f);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************************/
|
|
||||||
/* */
|
|
||||||
/* DestroyLocalVals */
|
|
||||||
/* */
|
|
||||||
/* Destroy the values of all local variables after evaluating */
|
|
||||||
/* the function. */
|
|
||||||
/* */
|
|
||||||
/***************************************************************/
|
|
||||||
static void DestroyLocalVals(UserFunc *f)
|
|
||||||
{
|
|
||||||
Var *v = f->locals;
|
|
||||||
|
|
||||||
while(v) {
|
|
||||||
DestroyValue(v->v);
|
|
||||||
v = v->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* UserFuncExists */
|
/* UserFuncExists */
|
||||||
@@ -418,12 +356,33 @@ static void DestroyLocalVals(UserFunc *f)
|
|||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
int UserFuncExists(char const *fn)
|
int UserFuncExists(char const *fn)
|
||||||
{
|
{
|
||||||
UserFunc *f;
|
UserFunc *f = FindUserFunc(fn);
|
||||||
int h = HashVal(fn) % FUNC_HASH_SIZE;
|
|
||||||
|
|
||||||
f = FuncHash[h];
|
|
||||||
while (f && StrinCmp(fn, f->name, VAR_NAME_LEN)) f = f->next;
|
|
||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
else return f->nargs;
|
else return f->nargs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/* */
|
||||||
|
/* UnsetAllUserFuncs */
|
||||||
|
/* */
|
||||||
|
/* Call FUNSET on all user funcs. Used with -ds flag to */
|
||||||
|
/* ensure no expr_node memory leaks. */
|
||||||
|
/* */
|
||||||
|
/***************************************************************/
|
||||||
|
void
|
||||||
|
UnsetAllUserFuncs(void)
|
||||||
|
{
|
||||||
|
UserFunc *f;
|
||||||
|
UserFunc *next;
|
||||||
|
int i;
|
||||||
|
for (i=0; i<FUNC_HASH_SIZE; i++) {
|
||||||
|
f = FuncHash[i];
|
||||||
|
while(f) {
|
||||||
|
next = f->next;
|
||||||
|
DestroyUserFunc(f);
|
||||||
|
f = next;
|
||||||
|
}
|
||||||
|
FuncHash[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
92
src/utils.c
92
src/utils.c
@@ -17,6 +17,11 @@ static char const DontEscapeMe[] =
|
|||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
#include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
@@ -46,6 +51,7 @@ char *StrnCpy(char *dest, char const *source, int n)
|
|||||||
return odest;
|
return odest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_STRNCASECMP
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* StrinCmp - compare strings, case-insensitive */
|
/* StrinCmp - compare strings, case-insensitive */
|
||||||
@@ -64,6 +70,9 @@ int StrinCmp(char const *s1, char const *s2, int n)
|
|||||||
if (n) return (toupper(*s1) - toupper(*s2)); else return 0;
|
if (n) return (toupper(*s1) - toupper(*s2)); else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRDUP
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* StrDup */
|
/* StrDup */
|
||||||
@@ -79,6 +88,9 @@ char *StrDup(char const *s)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRCASECMP
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* StrCmpi */
|
/* StrCmpi */
|
||||||
@@ -98,6 +110,8 @@ int StrCmpi(char const *s1, char const *s2)
|
|||||||
return toupper(*s1) - toupper(*s2);
|
return toupper(*s1) - toupper(*s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* DateOK */
|
/* DateOK */
|
||||||
@@ -116,6 +130,14 @@ int DateOK(int y, int m, int d)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void strtolower(char *s)
|
||||||
|
{
|
||||||
|
while (*s) {
|
||||||
|
*s = tolower(*s);
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Functions designed to defeat gcc optimizer */
|
/* Functions designed to defeat gcc optimizer */
|
||||||
|
|
||||||
int _private_mul_overflow(int a, int b)
|
int _private_mul_overflow(int a, int b)
|
||||||
@@ -151,11 +173,15 @@ int _private_sub_overflow(int a, int b)
|
|||||||
int
|
int
|
||||||
ShellEscape(char const *in, DynamicBuffer *out)
|
ShellEscape(char const *in, DynamicBuffer *out)
|
||||||
{
|
{
|
||||||
while(*in) {
|
unsigned char const *i = (unsigned char const *) in;
|
||||||
if (!strchr(DontEscapeMe, *in)) {
|
while(*i) {
|
||||||
if (DBufPutc(out, '\\') != OK) return E_NO_MEM;
|
/* Don't escape chars with high bit set. That will mangle UTF-8 */
|
||||||
|
if (! (*i & 0x80) ) {
|
||||||
|
if (!strchr(DontEscapeMe, *i)) {
|
||||||
|
if (DBufPutc(out, '\\') != OK) return E_NO_MEM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (DBufPutc(out, *in++) != OK) return E_NO_MEM;
|
if (DBufPutc(out, *i++) != OK) return E_NO_MEM;
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -169,31 +195,33 @@ typedef struct cs_s {
|
|||||||
} cs;
|
} cs;
|
||||||
|
|
||||||
static cs *callstack = NULL;
|
static cs *callstack = NULL;
|
||||||
|
static cs *freecs = NULL;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_cs(cs *entry)
|
destroy_cs(cs *entry)
|
||||||
{
|
{
|
||||||
if (entry->filename) free( (void *) entry->filename);
|
entry->next = freecs;
|
||||||
if (entry->func) free( (void *) entry->func);
|
freecs = entry;
|
||||||
free( (void *) entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
push_call(char const *filename, char const *func, int lineno)
|
push_call(char const *filename, char const *func, int lineno)
|
||||||
{
|
{
|
||||||
cs *entry = NEW(cs);
|
cs *entry;
|
||||||
if (!entry) {
|
if (freecs) {
|
||||||
return E_NO_MEM;
|
entry = freecs;
|
||||||
|
freecs = freecs->next;
|
||||||
|
} else {
|
||||||
|
entry = NEW(cs);
|
||||||
|
if (!entry) {
|
||||||
|
return E_NO_MEM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
entry->next = NULL;
|
entry->next = NULL;
|
||||||
entry->filename = StrDup(filename);
|
entry->filename = filename;
|
||||||
entry->func = StrDup(func);
|
entry->func = func;
|
||||||
entry->lineno = lineno;
|
entry->lineno = lineno;
|
||||||
if (!entry->filename || !entry->func) {
|
|
||||||
destroy_cs(entry);
|
|
||||||
return E_NO_MEM;
|
|
||||||
}
|
|
||||||
entry->next = callstack;
|
entry->next = callstack;
|
||||||
callstack = entry;
|
callstack = entry;
|
||||||
return OK;
|
return OK;
|
||||||
@@ -215,11 +243,35 @@ clear_callstack(void)
|
|||||||
static void
|
static void
|
||||||
print_callstack_aux(FILE *fp, cs *entry)
|
print_callstack_aux(FILE *fp, cs *entry)
|
||||||
{
|
{
|
||||||
if (entry) {
|
int i = 0;
|
||||||
print_callstack_aux(fp, entry->next);
|
char const *in = "In";
|
||||||
fprintf(fp, "\n");
|
cs *prev = NULL;
|
||||||
(void) fprintf(fp, "%s(%d): In function `%s'", entry->filename, entry->lineno, entry->func);
|
while(entry) {
|
||||||
|
if (prev) {
|
||||||
|
in = "Called from";
|
||||||
|
}
|
||||||
|
if (!prev || strcmp(prev->func, entry->func) || strcmp(prev->filename, entry->filename) || prev->lineno != entry->lineno) {
|
||||||
|
if (prev) {
|
||||||
|
fprintf(fp, "\n");
|
||||||
|
}
|
||||||
|
(void) fprintf(fp, " %s(%d): [#%d] %s function `%s'", entry->filename, entry->lineno, i, in, entry->func);
|
||||||
|
}
|
||||||
|
prev = entry;
|
||||||
|
entry = entry->next;
|
||||||
|
i++;
|
||||||
|
if (i > 10) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (entry) {
|
||||||
|
(void) fprintf(fp, "\n [remaining call frames omitted]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
have_callstack(void)
|
||||||
|
{
|
||||||
|
return (callstack != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
73
src/var.c
73
src/var.c
@@ -22,7 +22,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "expr.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "protos.h"
|
#include "protos.h"
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
@@ -39,8 +38,6 @@ static int IntMax = INT_MAX;
|
|||||||
|
|
||||||
static Var *VHashTbl[VAR_HASH_SIZE];
|
static Var *VHashTbl[VAR_HASH_SIZE];
|
||||||
|
|
||||||
typedef int (*SysVarFunc)(int, Value *);
|
|
||||||
|
|
||||||
static double
|
static double
|
||||||
strtod_in_c_locale(char const *str, char **endptr)
|
strtod_in_c_locale(char const *str, char **endptr)
|
||||||
{
|
{
|
||||||
@@ -175,6 +172,19 @@ static int terminal_bg_func(int do_set, Value *val)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int trig_time_func(int do_set, Value *val)
|
||||||
|
{
|
||||||
|
UNUSED(do_set);
|
||||||
|
if (LastTriggerTime != NO_TIME) {
|
||||||
|
val->type = TIME_TYPE;
|
||||||
|
val->v.val = LastTriggerTime;
|
||||||
|
} else {
|
||||||
|
val->type = INT_TYPE;
|
||||||
|
val->v.val = 0;
|
||||||
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
static int trig_date_func(int do_set, Value *val)
|
static int trig_date_func(int do_set, Value *val)
|
||||||
{
|
{
|
||||||
UNUSED(do_set);
|
UNUSED(do_set);
|
||||||
@@ -309,6 +319,29 @@ static int datetime_sep_func(int do_set, Value *val)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int expr_time_limit_func(int do_set, Value *val)
|
||||||
|
{
|
||||||
|
if (!do_set) {
|
||||||
|
val->type = INT_TYPE;
|
||||||
|
val->v.val = ExpressionEvaluationTimeLimit;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
if (val->type != INT_TYPE) return E_BAD_TYPE;
|
||||||
|
if (val->v.val < 0) return E_2LOW;
|
||||||
|
|
||||||
|
if (!TopLevel()) {
|
||||||
|
/* Ignore attempts to set from non-toplevel unless it's
|
||||||
|
lower than current value */
|
||||||
|
if (val->v.val == 0 ||
|
||||||
|
val->v.val >= ExpressionEvaluationTimeLimit) {
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpressionEvaluationTimeLimit = val->v.val;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
static int default_color_func(int do_set, Value *val)
|
static int default_color_func(int do_set, Value *val)
|
||||||
{
|
{
|
||||||
int col_r, col_g, col_b;
|
int col_r, col_g, col_b;
|
||||||
@@ -477,7 +510,7 @@ int DeleteVar(char const *str)
|
|||||||
/* */
|
/* */
|
||||||
/* SetVar */
|
/* SetVar */
|
||||||
/* */
|
/* */
|
||||||
/* Set the indicate variable to the specified value. */
|
/* Set the indicated variable to the specified value. */
|
||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
int SetVar(char const *str, Value const *val)
|
int SetVar(char const *str, Value const *val)
|
||||||
@@ -498,20 +531,10 @@ int SetVar(char const *str, Value const *val)
|
|||||||
/* Get a copy of the value of the variable. */
|
/* Get a copy of the value of the variable. */
|
||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
int GetVarValue(char const *str, Value *val, Var *locals, ParsePtr p)
|
int GetVarValue(char const *str, Value *val)
|
||||||
{
|
{
|
||||||
Var *v;
|
Var *v;
|
||||||
|
|
||||||
/* Try searching local variables first */
|
|
||||||
v = locals;
|
|
||||||
while (v) {
|
|
||||||
if (! StrinCmp(str, v->name, VAR_NAME_LEN))
|
|
||||||
return CopyValue(val, &v->v);
|
|
||||||
v = v->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Global variable... mark expression as non-constant */
|
|
||||||
if (p) p->nonconst_expr = 1;
|
|
||||||
v=FindVar(str, 0);
|
v=FindVar(str, 0);
|
||||||
|
|
||||||
if (!v) {
|
if (!v) {
|
||||||
@@ -544,6 +567,11 @@ int DoSet (Parser *p)
|
|||||||
ParseNonSpaceChar(p, &r, 0);
|
ParseNonSpaceChar(p, &r, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p->isnested) {
|
||||||
|
Eprint("%s", "Do not use [] around expression in SET command");
|
||||||
|
return E_CANTNEST_FDEF;
|
||||||
|
}
|
||||||
|
|
||||||
r = EvaluateExpr(p, &v);
|
r = EvaluateExpr(p, &v);
|
||||||
if (r) {
|
if (r) {
|
||||||
DBufFree(&buf);
|
DBufFree(&buf);
|
||||||
@@ -772,16 +800,6 @@ int DoPreserve (Parser *p)
|
|||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
/* The structure of a system variable */
|
|
||||||
typedef struct {
|
|
||||||
char const *name;
|
|
||||||
char modifiable;
|
|
||||||
int type;
|
|
||||||
void *value;
|
|
||||||
int min; /* Or const-value */
|
|
||||||
int max;
|
|
||||||
} SysVar;
|
|
||||||
|
|
||||||
/* Macro to access "min" but as a constval. Just to make source more
|
/* Macro to access "min" but as a constval. Just to make source more
|
||||||
readable */
|
readable */
|
||||||
#define constval min
|
#define constval min
|
||||||
@@ -818,6 +836,7 @@ static SysVar SysVarArr[] = {
|
|||||||
{"DontTrigAts", 0, INT_TYPE, &DontIssueAts, 0, 0 },
|
{"DontTrigAts", 0, INT_TYPE, &DontIssueAts, 0, 0 },
|
||||||
{"EndSent", 1, STR_TYPE, &EndSent, 0, 0 },
|
{"EndSent", 1, STR_TYPE, &EndSent, 0, 0 },
|
||||||
{"EndSentIg", 1, STR_TYPE, &EndSentIg, 0, 0 },
|
{"EndSentIg", 1, STR_TYPE, &EndSentIg, 0, 0 },
|
||||||
|
{"ExpressionTimeLimit", 1, SPECIAL_TYPE, expr_time_limit_func, 0, 0 },
|
||||||
{"February", 1, STR_TYPE, &DynamicMonthName[1], 0, 0 },
|
{"February", 1, STR_TYPE, &DynamicMonthName[1], 0, 0 },
|
||||||
{"FirstIndent", 1, INT_TYPE, &FirstIndent, 0, 132 },
|
{"FirstIndent", 1, INT_TYPE, &FirstIndent, 0, 132 },
|
||||||
{"FoldYear", 1, INT_TYPE, &FoldYear, 0, 1 },
|
{"FoldYear", 1, INT_TYPE, &FoldYear, 0, 1 },
|
||||||
@@ -887,6 +906,7 @@ static SysVar SysVarArr[] = {
|
|||||||
{"Tm", 0, SPECIAL_TYPE, trig_mon_func, 0, 0 },
|
{"Tm", 0, SPECIAL_TYPE, trig_mon_func, 0, 0 },
|
||||||
{"Today", 1, STR_TYPE, &DynamicToday, 0, 0 },
|
{"Today", 1, STR_TYPE, &DynamicToday, 0, 0 },
|
||||||
{"Tomorrow", 1, STR_TYPE, &DynamicTomorrow, 0, 0 },
|
{"Tomorrow", 1, STR_TYPE, &DynamicTomorrow, 0, 0 },
|
||||||
|
{"Tt", 0, SPECIAL_TYPE, trig_time_func, 0, 0 },
|
||||||
{"Tuesday", 1, STR_TYPE, &DynamicDayName[1], 0, 0 },
|
{"Tuesday", 1, STR_TYPE, &DynamicDayName[1], 0, 0 },
|
||||||
{"Tw", 0, SPECIAL_TYPE, trig_wday_func, 0, 0 },
|
{"Tw", 0, SPECIAL_TYPE, trig_wday_func, 0, 0 },
|
||||||
{"Ty", 0, SPECIAL_TYPE, trig_year_func, 0, 0 },
|
{"Ty", 0, SPECIAL_TYPE, trig_year_func, 0, 0 },
|
||||||
@@ -905,7 +925,6 @@ static SysVar SysVarArr[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define NUMSYSVARS ( sizeof(SysVarArr) / sizeof(SysVar) )
|
#define NUMSYSVARS ( sizeof(SysVarArr) / sizeof(SysVar) )
|
||||||
static SysVar *FindSysVar (char const *name);
|
|
||||||
static void DumpSysVar (char const *name, const SysVar *v);
|
static void DumpSysVar (char const *name, const SysVar *v);
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/* */
|
/* */
|
||||||
@@ -1002,7 +1021,7 @@ int GetSysVar(char const *name, Value *val)
|
|||||||
/* Find a system var with specified name. */
|
/* Find a system var with specified name. */
|
||||||
/* */
|
/* */
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
static SysVar *FindSysVar(char const *name)
|
SysVar *FindSysVar(char const *name)
|
||||||
{
|
{
|
||||||
int top=NUMSYSVARS-1, bottom=0;
|
int top=NUMSYSVARS-1, bottom=0;
|
||||||
int mid=(top + bottom) / 2;
|
int mid=(top + bottom) / 2;
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ set a ansicolor(-1, 0, 0)
|
|||||||
set a ansicolor(42, 42, 256)
|
set a ansicolor(42, 42, 256)
|
||||||
set a ansicolor("foo")
|
set a ansicolor("foo")
|
||||||
set a ansicolor("1 1")
|
set a ansicolor("1 1")
|
||||||
set a ansicolor("-1 -1 0");
|
set a ansicolor("-1 -1 0")
|
||||||
set a ansicolor("256 1 1");
|
set a ansicolor("256 1 1")
|
||||||
set a ansicolor(128, 128, 128, 2)
|
set a ansicolor(128, 128, 128, 2)
|
||||||
set a ansicolor(128, 128, 128, -1)
|
set a ansicolor(128, 128, 128, -1)
|
||||||
set a ansicolor(128, 128, 128, 0, 2)
|
set a ansicolor(128, 128, 128, 0, 2)
|
||||||
|
|||||||
51
tests/expr.rem
Normal file
51
tests/expr.rem
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
debug +sx
|
||||||
|
|
||||||
|
set a 1
|
||||||
|
|
||||||
|
set a 0&&0
|
||||||
|
set a 0&&1
|
||||||
|
set a 1&&0
|
||||||
|
set a 1&&1
|
||||||
|
|
||||||
|
set a 0||0
|
||||||
|
set a 0||1
|
||||||
|
set a 1||0
|
||||||
|
set a 1||1
|
||||||
|
|
||||||
|
set a 2, 3
|
||||||
|
|
||||||
|
set a iif(0, "foo", 0, "bar", 1, "blech", 0, "quux", 1, "borhy", "wacka")
|
||||||
|
|
||||||
|
set a max(2*3, 4+5, min(6*7+8, 7+6*8))
|
||||||
|
|
||||||
|
set a max(1,,1)
|
||||||
|
|
||||||
|
set a 5%0
|
||||||
|
|
||||||
|
set a 5/0
|
||||||
|
|
||||||
|
set a -$IntMin
|
||||||
|
|
||||||
|
set a $IntMin / -1
|
||||||
|
set a $IntMin % -1
|
||||||
|
|
||||||
|
set a (7+5)*(8+2)/(9-4)
|
||||||
|
|
||||||
|
set a "foo" * 5
|
||||||
|
set a "foo" / 5
|
||||||
|
set a "foo" * "five"
|
||||||
|
set a "foo" + "bar"
|
||||||
|
set a '2024-01-02' + 3
|
||||||
|
set a 3 + '2024-01-02'
|
||||||
|
set a 11:33 + 75
|
||||||
|
set a 75 + 11:33
|
||||||
|
set a '2024-01-01@11:33' + 1500
|
||||||
|
set a 1500 + '2024-01-01@11:33'
|
||||||
|
|
||||||
|
set a '2024-03-02' - '2024-01-01'
|
||||||
|
set a 15:00 - 14:44
|
||||||
|
|
||||||
|
|
||||||
|
set a (1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+1))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||||
|
|
||||||
|
set a (1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+1)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||||
4
tests/if1.rem
Normal file
4
tests/if1.rem
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
BANNER %
|
||||||
|
set $AddBlankLines 0
|
||||||
|
IF 1
|
||||||
|
INCLUDE [filedir()]/if2.rem
|
||||||
5
tests/if2.rem
Normal file
5
tests/if2.rem
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Another unmatched IF
|
||||||
|
IF 0
|
||||||
|
ELSE
|
||||||
|
IF 1
|
||||||
|
|
||||||
@@ -65,8 +65,6 @@ echo "Test 1" > ../tests/test.out
|
|||||||
echo "" >> ../tests/test.out
|
echo "" >> ../tests/test.out
|
||||||
../src/remind -e -dxte ../tests/test.rem 16 feb 1991 12:13 >> ../tests/test.out 2>&1
|
../src/remind -e -dxte ../tests/test.rem 16 feb 1991 12:13 >> ../tests/test.out 2>&1
|
||||||
echo "" >> ../tests/test.out
|
echo "" >> ../tests/test.out
|
||||||
echo 'set a 1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+2*3))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))' | ../src/remind -ds - 16 feb 1991 12:13 >> ../tests/test.out 2>&1
|
|
||||||
echo "" >> ../tests/test.out
|
|
||||||
echo "Test 2" >> ../tests/test.out
|
echo "Test 2" >> ../tests/test.out
|
||||||
echo "" >> ../tests/test.out
|
echo "" >> ../tests/test.out
|
||||||
../src/remind -p -l ../tests/test2.rem 1 aug 2007 >> ../tests/test.out 2>&1
|
../src/remind -p -l ../tests/test2.rem 1 aug 2007 >> ../tests/test.out 2>&1
|
||||||
@@ -178,7 +176,7 @@ REM 1 Jan 2012 AT 10:00 MSG 10am: Should show up
|
|||||||
MSG [$DontTrigAts]
|
MSG [$DontTrigAts]
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# An OMITFUNC should indicate nonconst_expr
|
# OMITFUNC should indicate nonconst_expr
|
||||||
../src/remind -pp - 1 jan 2012 9:00 <<'EOF' >> ../tests/test.out 2>&1
|
../src/remind -pp - 1 jan 2012 9:00 <<'EOF' >> ../tests/test.out 2>&1
|
||||||
REM Mon OMITFUNC foo MSG bar
|
REM Mon OMITFUNC foo MSG bar
|
||||||
EOF
|
EOF
|
||||||
@@ -541,6 +539,36 @@ EOF
|
|||||||
|
|
||||||
(echo 'BANNER %'; echo 'REM 29 MSG No bug') | ../src/remind -dt - 29 Feb 2024 >> ../tests/test.out 2>&1
|
(echo 'BANNER %'; echo 'REM 29 MSG No bug') | ../src/remind -dt - 29 Feb 2024 >> ../tests/test.out 2>&1
|
||||||
|
|
||||||
|
../src/remind -ifoo - <<'EOF' >> ../tests/test.out 2>&1
|
||||||
|
BANNER %
|
||||||
|
DUMP
|
||||||
|
EOF
|
||||||
|
|
||||||
|
../src/remind '-i$AddBlankLines' - <<'EOF' >> ../tests/test.out 2>&1
|
||||||
|
BANNER %
|
||||||
|
DUMP
|
||||||
|
EOF
|
||||||
|
|
||||||
|
../src/remind ../tests/expr.rem >> ../tests/test.out 2>&1
|
||||||
|
|
||||||
|
../src/remind - <<'EOF' >> ../tests/test.out 2>&1
|
||||||
|
PUSH
|
||||||
|
POP
|
||||||
|
PUSH
|
||||||
|
PUSH
|
||||||
|
POP
|
||||||
|
POP
|
||||||
|
PUSH
|
||||||
|
PUSH
|
||||||
|
POP
|
||||||
|
PUSH
|
||||||
|
POP
|
||||||
|
PUSH
|
||||||
|
POP
|
||||||
|
EOF
|
||||||
|
|
||||||
|
../src/remind ../tests/if1.rem 2020-03-03 >> ../tests/test.out 2>&1
|
||||||
|
|
||||||
# Remove references to SysInclude, which is build-specific
|
# Remove references to SysInclude, which is build-specific
|
||||||
grep -F -v '$SysInclude' < ../tests/test.out > ../tests/test.out.1 && mv -f ../tests/test.out.1 ../tests/test.out
|
grep -F -v '$SysInclude' < ../tests/test.out > ../tests/test.out.1 && mv -f ../tests/test.out.1 ../tests/test.out
|
||||||
cmp -s ../tests/test.out ../tests/test.cmp
|
cmp -s ../tests/test.out ../tests/test.cmp
|
||||||
|
|||||||
1958
tests/test.cmp
1958
tests/test.cmp
File diff suppressed because one or more lines are too long
@@ -329,6 +329,7 @@ set a052 time(1+2, 3+4)
|
|||||||
rem 10 jan 1992 AT 11:22 CAL
|
rem 10 jan 1992 AT 11:22 CAL
|
||||||
set a053 trigdate()
|
set a053 trigdate()
|
||||||
set a054 trigtime()
|
set a054 trigtime()
|
||||||
|
set a054b $Tt
|
||||||
set a055 trigvalid()
|
set a055 trigvalid()
|
||||||
set a056 upper("sdfjhsdf ksjdfh kjsdfh ksjdfh")
|
set a056 upper("sdfjhsdf ksjdfh kjsdfh ksjdfh")
|
||||||
set a057 value("a05"+"6")
|
set a057 value("a05"+"6")
|
||||||
@@ -457,6 +458,7 @@ set a129 23:30 + '2019-02-02@16:44'
|
|||||||
REM 13 AT 16:00 DURATION 72:00 MSG 72-hour event
|
REM 13 AT 16:00 DURATION 72:00 MSG 72-hour event
|
||||||
set a130 trigdate()
|
set a130 trigdate()
|
||||||
set a131 trigtime()
|
set a131 trigtime()
|
||||||
|
set a131b $Tt
|
||||||
set a132 trigdatetime()
|
set a132 trigdatetime()
|
||||||
set a133 trigduration()
|
set a133 trigduration()
|
||||||
set a134 trigeventstart()
|
set a134 trigeventstart()
|
||||||
@@ -775,12 +777,15 @@ ENDIF
|
|||||||
# Trig with a good warnfunc
|
# Trig with a good warnfunc
|
||||||
FSET w(x) choose(x, 5, 3, 1, 0)
|
FSET w(x) choose(x, 5, 3, 1, 0)
|
||||||
|
|
||||||
# Ugh. This is where short-circuit logical operators
|
Short-circuit operators
|
||||||
# would really come in handy.
|
|
||||||
IF trig("sun warn w") || trig("thu warn w")
|
IF trig("sun warn w") || trig("thu warn w")
|
||||||
REM [trig()] +5 MSG Foo %b
|
REM [trig()] +5 MSG Foo %b
|
||||||
ENDIF
|
ENDIF
|
||||||
|
|
||||||
|
IF trig("thu warn w") || trig("sun warn w")
|
||||||
|
REM [trig()] +5 MSG Foo %b
|
||||||
|
ENDIF
|
||||||
|
|
||||||
REM [trig("Mon", "Tue", "Wed", "Sat")] MSG foo
|
REM [trig("Mon", "Tue", "Wed", "Sat")] MSG foo
|
||||||
REM [trig("Mon", "Tue", "Wed")] MSG bar
|
REM [trig("Mon", "Tue", "Wed")] MSG bar
|
||||||
|
|
||||||
@@ -925,6 +930,21 @@ REM Tue OMIT 2024-01-01 MSG Wookie
|
|||||||
# No error
|
# No error
|
||||||
REM Tue OMIT Wed 2024-01-01 MSG Blort
|
REM Tue OMIT Wed 2024-01-01 MSG Blort
|
||||||
|
|
||||||
|
# Make sure trigtime() is not reset between invocations
|
||||||
|
REM Tue AT 16:00 DURATION 30 MSG Thing One
|
||||||
|
REM [$T] AT [trigtime()+trigduration()] DURATION 15 MSG Thing Two
|
||||||
|
REM [$T] AT [$Tt+trigduration()] DURATION 30 MSG Thing Three
|
||||||
|
REM [$T] AT [trigtime()+trigduration()] DURATION 10 MSG Last Thing
|
||||||
|
|
||||||
|
# Make sure trigtime is not reset during parsing
|
||||||
|
REM Tue AT 16:00 MSG blort
|
||||||
|
REM Tue AT 10:00 DURATION [$Tt] MSG blort
|
||||||
|
REM Tue AT 16:00 MSG blort
|
||||||
|
REM Tue AT 10:00 DURATION [trigtime()] MSG blort
|
||||||
|
|
||||||
|
# Make sure shellescape does not mangle UTF-8 characters
|
||||||
|
msg [shellescape("😆")]
|
||||||
|
|
||||||
# Don't want Remind to queue reminders
|
# Don't want Remind to queue reminders
|
||||||
EXIT
|
EXIT
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ install:
|
|||||||
chmod 755 $(DESTDIR)$(SCRIPTDIR)/calpdf $(DESTDIR)$(SCRIPTDIR)/calps $(DESTDIR)$(SCRIPTDIR)/hebdate \
|
chmod 755 $(DESTDIR)$(SCRIPTDIR)/calpdf $(DESTDIR)$(SCRIPTDIR)/calps $(DESTDIR)$(SCRIPTDIR)/hebdate \
|
||||||
$(DESTDIR)$(SCRIPTDIR)/hebps $(DESTDIR)$(SCRIPTDIR)/hebpdf $(DESTDIR)$(SCRIPTDIR)/moon \
|
$(DESTDIR)$(SCRIPTDIR)/hebps $(DESTDIR)$(SCRIPTDIR)/hebpdf $(DESTDIR)$(SCRIPTDIR)/moon \
|
||||||
$(DESTDIR)$(SCRIPTDIR)/sunrise $(DESTDIR)$(SCRIPTDIR)/sunset \
|
$(DESTDIR)$(SCRIPTDIR)/sunrise $(DESTDIR)$(SCRIPTDIR)/sunset \
|
||||||
$(DESTDIR)$(SCRIPTDIR)/hebhtml \
|
$(DESTDIR)$(SCRIPTDIR)/hebhtml \
|
||||||
|
|
||||||
-mkdir -p $(DESTDIR)$(IMAGEDIR)
|
-mkdir -p $(DESTDIR)$(IMAGEDIR)
|
||||||
cp calendar.css rem-default.css *.png $(DESTDIR)$(IMAGEDIR)
|
cp calendar.css rem-default.css *.png $(DESTDIR)$(IMAGEDIR)
|
||||||
|
|||||||
Reference in New Issue
Block a user