mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
Add trigbase() built-in function.
This commit is contained in:
@@ -145,7 +145,7 @@
|
||||
"$NumTrig" "$October" "$On" "$OnceFile" "$ParseUntriggered" "$Pm"
|
||||
"$PrefixLineNo" "$PSCal" "$RunOff" "$Saturday" "$September"
|
||||
"$SimpleCal" "$SortByDate" "$SortByPrio" "$SortByTime" "$SubsIndent"
|
||||
"$Sunday" "$SuppressImplicitWarnings" "$SuppressLRM" "$SysInclude" "$T" "$Td"
|
||||
"$Sunday" "$SuppressImplicitWarnings" "$SuppressLRM" "$SysInclude" "$T" "$Tb" "$Td"
|
||||
"$TerminalBackground" "$Thursday" "$TimeSep" "$TimetIs64bit" "$Tm" "$Today"
|
||||
"$Tomorrow" "$Tt" "$Tuesday" "$Tw" "$Ty" "$U" "$Ud" "$Um"
|
||||
"$UntimedFirst" "$Use256Colors" "$UseBGVTColors" "$UseTrueColors"
|
||||
@@ -176,7 +176,7 @@
|
||||
"ostype" "pad" "plural" "psmoon" "psshade" "realcurrent" "realnow"
|
||||
"realtoday" "rows" "sgn" "shell" "shellescape" "slide" "soleq"
|
||||
"stdout" "strlen" "substr" "sunrise" "sunset" "time" "timepart"
|
||||
"timezone" "today" "trig" "trigback" "trigdate" "trigdatetime"
|
||||
"timezone" "today" "trig" "trigback" "trigbase" "trigdate" "trigdatetime"
|
||||
"trigdelta" "trigduration" "trigeventduration" "trigeventstart"
|
||||
"trigfrom" "trigger" "triginfo" "trigpriority" "trigrep"
|
||||
"trigscanfrom" "trigtags" "trigtime" "trigtimedelta" "trigtimerep"
|
||||
|
||||
@@ -3029,6 +3029,9 @@ this installation.
|
||||
.B $T (read-only, DATE type)
|
||||
Exactly equivalent to \fBtrigdate()\fR. (See BUILT-IN FUNCTIONS.)
|
||||
.TP
|
||||
.B $Tb (read-only, DATE type)
|
||||
Exactly equivalent to \fBtrigbase()\fR. (See BUILT-IN FUNCTIONS.)
|
||||
.TP
|
||||
.B $Td (read-only)
|
||||
Equivalent to \fBday(trigdate())\fR.
|
||||
.TP
|
||||
@@ -4388,6 +4391,25 @@ Returns the "back" amount of the last \fBREM\fR or \fBIFTRIG\fR command.
|
||||
Returns a positive integer N if the "back" is of the form -N, or a negative
|
||||
integer if it is of the form --N. If there is no "back", then returns 0.
|
||||
.TP
|
||||
.B trigbase()
|
||||
Returns the "base" date of the last \fBREM\fR or \fBIFTRIG\fR command.
|
||||
If the trigger specification includes \fIall three\fR of day, month
|
||||
and year, then the base date is the date formed from those components.
|
||||
If the trigger specification lacks one of those components, then 0 is
|
||||
returned.
|
||||
.RS
|
||||
.PP
|
||||
Here is an example of how \fBtrigbase()\fR might be used:
|
||||
.PP
|
||||
.nf
|
||||
REM 2025-05-05 *7 UNTIL 2025-05-26 \\
|
||||
MSG Meeting: week #[(trigdate() - trigbase())/7+1]
|
||||
.fi
|
||||
.PP
|
||||
On 2025-05-05, it would print: "Meeting: week #1". On 2025-05-12,
|
||||
it would print: "Meeting: week #2" and so on.
|
||||
.RE
|
||||
.TP
|
||||
.B trigdelta()
|
||||
Returns the "delta" amount of the last \fBREM\fR or \fBIFTRIG\fR command.
|
||||
Returns a positive integer N if the "delta" is of the form +N, or a negative
|
||||
|
||||
@@ -2464,6 +2464,10 @@ void WriteJSONTrigger(Trigger const *t, int include_tags, int today)
|
||||
if (t->rep) {
|
||||
PrintJSONKeyPairInt("rep", t->rep);
|
||||
}
|
||||
if (t->d != NO_DAY && t->m != NO_MON && t->y != NO_YR) {
|
||||
printf("\"trigbase\":\"%04d-%02d-%-2d\",",
|
||||
t->y, t->m+1, t->d);
|
||||
}
|
||||
/* Local omit is an array of days from 0=monday to 6=sunday.
|
||||
We convert to array of strings */
|
||||
if (t->localomit != NO_WD) {
|
||||
|
||||
16
src/funcs.c
16
src/funcs.c
@@ -170,6 +170,7 @@ static int FTimezone (func_info *);
|
||||
static int FToday (func_info *);
|
||||
static int FTrig (func_info *);
|
||||
static int FTrigback (func_info *);
|
||||
static int FTrigbase (func_info *info);
|
||||
static int FTrigdate (func_info *);
|
||||
static int FTrigdatetime (func_info *);
|
||||
static int FTrigdelta (func_info *);
|
||||
@@ -340,6 +341,7 @@ BuiltinFunc Func[] = {
|
||||
{ "today", 0, 0, 0, FToday, NULL },
|
||||
{ "trig", 0, NO_MAX, 0, FTrig, NULL },
|
||||
{ "trigback", 0, 0, 0, FTrigback, NULL },
|
||||
{ "trigbase", 0, 0, 0, FTrigbase, NULL },
|
||||
{ "trigdate", 0, 0, 0, FTrigdate, NULL },
|
||||
{ "trigdatetime", 0, 0, 0, FTrigdatetime, NULL },
|
||||
{ "trigdelta", 0, 0, 0, FTrigdelta, NULL },
|
||||
@@ -1753,6 +1755,20 @@ static int FTrigdate(func_info *info)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int FTrigbase(func_info *info)
|
||||
{
|
||||
if (LastTrigger.d != NO_DAY &&
|
||||
LastTrigger.m != NO_MON &&
|
||||
LastTrigger.y != NO_YR) {
|
||||
RetVal.type = DATE_TYPE;
|
||||
RETVAL = DSE(LastTrigger.y, LastTrigger.m, LastTrigger.d);
|
||||
} else {
|
||||
RetVal.type = INT_TYPE;
|
||||
RETVAL = 0;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int FTrigback(func_info *info)
|
||||
{
|
||||
RetVal.type = INT_TYPE;
|
||||
|
||||
17
src/var.c
17
src/var.c
@@ -254,6 +254,22 @@ static int trig_date_func(int do_set, Value *val)
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int trig_base_func(int do_set, Value *val)
|
||||
{
|
||||
UNUSED(do_set);
|
||||
if (LastTrigger.d != NO_DAY &&
|
||||
LastTrigger.m != NO_MON &&
|
||||
LastTrigger.y != NO_YR) {
|
||||
val->type = DATE_TYPE;
|
||||
val->v.val = DSE(LastTrigger.y, LastTrigger.m, LastTrigger.d);
|
||||
} else {
|
||||
val->type = INT_TYPE;
|
||||
val->v.val = 0;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int trig_day_func(int do_set, Value *val)
|
||||
{
|
||||
int y, m, d;
|
||||
@@ -994,6 +1010,7 @@ static SysVar SysVarArr[] = {
|
||||
{"SuppressLRM", 1, INT_TYPE, &SuppressLRM, 0, 1 },
|
||||
{"SysInclude", 0, STR_TYPE, &SysDir, 0, 0 },
|
||||
{"T", 0, SPECIAL_TYPE, trig_date_func, 0, 0 },
|
||||
{"Tb", 0, SPECIAL_TYPE, trig_base_func, 0, 0 },
|
||||
{"Td", 0, SPECIAL_TYPE, trig_day_func, 0, 0 },
|
||||
{"TerminalBackground", 0, SPECIAL_TYPE, terminal_bg_func, 0, 0 },
|
||||
{"Thursday", 1, TRANS_TYPE, "Thursday", 0, 0 },
|
||||
|
||||
@@ -2818,6 +2818,7 @@ Variable Value
|
||||
$SuppressImplicitWarnings 0 [0, 1]
|
||||
$SuppressLRM 0 [0, 1]
|
||||
$T 0
|
||||
$Tb 0
|
||||
$Td -1
|
||||
$TerminalBackground -1
|
||||
$Thursday "Thursday"
|
||||
@@ -16516,6 +16517,8 @@ DEBUG -x
|
||||
|
||||
DEBUG -e
|
||||
../tests/test.rem(1581): eval(): Too many recursive function calls
|
||||
Base: 1991-02-09
|
||||
Base: 1991-02-09
|
||||
Variable hash table statistics:
|
||||
Entries: 100143; Buckets: 87719; Non-empty Buckets: 66301
|
||||
Maxlen: 5; Minlen: 0; Avglen: 1.142; Stddev: 0.878; Avg nonempty len: 1.510
|
||||
@@ -24539,6 +24542,7 @@ timezone
|
||||
today
|
||||
trig
|
||||
trigback
|
||||
trigbase
|
||||
trigdate
|
||||
trigdatetime
|
||||
trigdelta
|
||||
@@ -24660,6 +24664,7 @@ $SuppressImplicitWarnings
|
||||
$SuppressLRM
|
||||
$SysInclude
|
||||
$T
|
||||
$Tb
|
||||
$Td
|
||||
$TerminalBackground
|
||||
$Thursday
|
||||
|
||||
@@ -1580,6 +1580,10 @@ DEBUG -e
|
||||
set a "eval(a)"
|
||||
set a eval(a)
|
||||
|
||||
# trigbase()
|
||||
REM 9 Feb 1991 *7 MSG Base: [trigbase()]
|
||||
REM 9 Feb 1991 *1 MSG Base: [$Tb]
|
||||
|
||||
# Output expression-node stats
|
||||
DEBUG +h
|
||||
|
||||
|
||||
Reference in New Issue
Block a user