Add system variables for dynamically changing day and month names.

This commit is contained in:
Dianne Skoll
2022-01-25 19:18:59 -05:00
parent f6f201085c
commit dd56b7c385
4 changed files with 88 additions and 20 deletions

View File

@@ -543,9 +543,11 @@ void ProduceCalendar(void)
ColSpaces = (CalWidth - 9) / 7;
CalWidth = 7*ColSpaces + 8;
/* Run the file once to get potentially-overridden day names */
if (CalMonths) {
FromJulian(JulianToday, &y, &m, &d);
JulianToday = Julian(y, m, 1);
FromJulian(JulianToday, &y, &m, &d);
JulianToday = Julian(y, m, 1);
GenerateCalEntries(-1);
DidAMonth = 0;
if (PsCal == PSCAL_LEVEL3) {
printf("[\n");
@@ -562,6 +564,8 @@ void ProduceCalendar(void)
if (MondayFirst) JulianToday -= (JulianToday%7);
else JulianToday -= ((JulianToday+1)%7);
GenerateCalEntries(-1);
if (!DoSimpleCalendar) {
WriteWeekHeaderLine();
WriteCalDays();
@@ -1346,7 +1350,7 @@ static int DoCalRem(ParsePtr p, int col)
Value v;
int r, err;
int jul;
CalEntry *CurCol = CalColumn[col];
CalEntry *CurCol;
CalEntry *e;
char const *s, *s2;
DynamicBuffer buf, obuf, pre_buf, raw_buf;
@@ -1355,6 +1359,11 @@ static int DoCalRem(ParsePtr p, int col)
int is_color, col_r, col_g, col_b;
if (col >= 0) {
CurCol = CalColumn[col];
} else {
CurCol = NULL;
}
is_color = 0;
DBufInit(&buf);
DBufInit(&pre_buf);
@@ -1451,6 +1460,12 @@ static int DoCalRem(ParsePtr p, int col)
}
}
/* If we're not actually generating any calendar entries, we're done */
if (col < 0) {
FreeTrig(&trig);
return OK;
}
/* Don't include timed reminders in calendar if -a option supplied. */
if (DontIssueAts && tim.ttime != NO_TIME) {
FreeTrig(&trig);

View File

@@ -170,8 +170,8 @@ EXTERN char *MonthName[]
EXTERN char *DynamicMonthName[]
#ifdef MK_GLOBALS
= {NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL}
= {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"}
#endif
;
@@ -195,7 +195,8 @@ EXTERN char *DayName[]
EXTERN char *DynamicDayName []
#ifdef MK_GLOBALS
= {NULL, NULL, NULL, NULL, NULL, NULL, NULL}
= {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"}
#endif
;

View File

@@ -740,11 +740,14 @@ typedef struct {
/* All of the system variables sorted alphabetically */
static SysVar SysVarArr[] = {
/* name mod type value min/mal max */
{"CalcUTC", 1, INT_TYPE, &CalculateUTC, 0, 1 },
{"April", 1, STR_TYPE, &DynamicMonthName[3],0, 0 },
{"August", 1, STR_TYPE, &DynamicMonthName[7],0, 0 },
{"CalMode", 0, INT_TYPE, &DoCalendar, 0, 0 },
{"CalcUTC", 1, INT_TYPE, &CalculateUTC, 0, 1 },
{"Daemon", 0, INT_TYPE, &Daemon, 0, 0 },
{"DateSep", 1, SPECIAL_TYPE, date_sep_func, 0, 0 },
{"DateTimeSep", 1, SPECIAL_TYPE, datetime_sep_func, 0, 0 },
{"December", 1, STR_TYPE, &DynamicMonthName[11],0, 0 },
{"DefaultColor", 1, SPECIAL_TYPE, default_color_func, 0, 0 },
{"DefaultPrio", 1, INT_TYPE, &DefaultPrio, 0, 9999},
{"DefaultTDelta", 1, INT_TYPE, &DefaultTDelta, 0, 1440},
@@ -754,14 +757,19 @@ static SysVar SysVarArr[] = {
{"DontTrigAts", 0, INT_TYPE, &DontIssueAts, 0, 0 },
{"EndSent", 1, STR_TYPE, &EndSent, 0, 0 },
{"EndSentIg", 1, STR_TYPE, &EndSentIg, 0, 0 },
{"February", 1, STR_TYPE, &DynamicMonthName[1],0, 0 },
{"FirstIndent", 1, INT_TYPE, &FirstIndent, 0, 132 },
{"FoldYear", 1, INT_TYPE, &FoldYear, 0, 1 },
{"FormWidth", 1, INT_TYPE, &FormWidth, 20, 500 },
{"Friday", 1, STR_TYPE, &DynamicDayName[4], 0, 0 },
{"HushMode", 0, INT_TYPE, &Hush, 0, 0 },
{"IgnoreOnce", 0, INT_TYPE, &IgnoreOnce, 0, 0 },
{"InfDelta", 0, INT_TYPE, &InfiniteDelta, 0, 0 },
{"IntMax", 0, INT_TYPE, &IntMax, 0, 0 },
{"IntMin", 0, INT_TYPE, &IntMin, 0, 0 },
{"January", 1, STR_TYPE, &DynamicMonthName[0],0, 0 },
{"July", 1, STR_TYPE, &DynamicMonthName[6],0, 0 },
{"June", 1, STR_TYPE, &DynamicMonthName[5],0, 0 },
{"LatDeg", 1, SPECIAL_TYPE, latdeg_func, 0, 0 },
{"Latitude", 1, SPECIAL_TYPE, latitude_func, 0, 0 },
{"LatMin", 1, SPECIAL_TYPE, latmin_func, 0, 0 },
@@ -771,24 +779,34 @@ static SysVar SysVarArr[] = {
{"Longitude", 1, SPECIAL_TYPE, longitude_func, 0, 0 },
{"LongMin", 1, SPECIAL_TYPE, longmin_func, 0, 0 },
{"LongSec", 1, SPECIAL_TYPE, longsec_func, 0, 0 },
{"March", 1, STR_TYPE, &DynamicMonthName[2],0, 0 },
{"MaxSatIter", 1, INT_TYPE, &MaxSatIter, 10, ANY },
{"MaxStringLen", 1, INT_TYPE, &MaxStringLen, -1, ANY },
{"May", 1, STR_TYPE, &DynamicMonthName[4],0, 0 },
{"MinsFromUTC", 1, INT_TYPE, &MinsFromUTC, -780, 780 },
{"Monday", 1, STR_TYPE, &DynamicDayName[0], 0, 0 },
{"NextMode", 0, INT_TYPE, &NextMode, 0, 0 },
{"November", 1, STR_TYPE, &DynamicMonthName[10],0, 0 },
{"NumQueued", 0, INT_TYPE, &NumQueued, 0, 0 },
{"NumTrig", 0, INT_TYPE, &NumTriggered, 0, 0 },
{"October", 1, STR_TYPE, &DynamicMonthName[9],0, 0 },
{"PrefixLineNo", 0, INT_TYPE, &DoPrefixLineNo, 0, 0 },
{"PSCal", 0, INT_TYPE, &PsCal, 0, 0 },
{"RunOff", 0, INT_TYPE, &RunDisabled, 0, 0 },
{"Saturday", 1, STR_TYPE, &DynamicDayName[5], 0, 0 },
{"September", 1, STR_TYPE, &DynamicMonthName[8],0, 0 },
{"SimpleCal", 0, INT_TYPE, &DoSimpleCalendar, 0, 0 },
{"SortByDate", 0, INT_TYPE, &SortByDate, 0, 0 },
{"SortByPrio", 0, INT_TYPE, &SortByPrio, 0, 0 },
{"SortByTime", 0, INT_TYPE, &SortByTime, 0, 0 },
{"SubsIndent", 1, INT_TYPE, &SubsIndent, 0, 132 },
{"Sunday", 1, STR_TYPE, &DynamicDayName[6], 0, 0 },
{"T", 0, SPECIAL_TYPE, trig_date_func, 0, 0 },
{"Td", 0, SPECIAL_TYPE, trig_day_func, 0, 0 },
{"Thursday", 1, STR_TYPE, &DynamicDayName[3], 0, 0 },
{"TimeSep", 1, SPECIAL_TYPE, time_sep_func, 0, 0 },
{"Tm", 0, SPECIAL_TYPE, trig_mon_func, 0, 0 },
{"Tuesday", 1, STR_TYPE, &DynamicDayName[1], 0, 0 },
{"Tw", 0, SPECIAL_TYPE, trig_wday_func, 0, 0 },
{"Ty", 0, SPECIAL_TYPE, trig_year_func, 0, 0 },
{"U", 0, SPECIAL_TYPE, today_date_func, 0, 0 },
@@ -796,7 +814,8 @@ static SysVar SysVarArr[] = {
{"Um", 0, SPECIAL_TYPE, today_mon_func, 0, 0 },
{"UntimedFirst", 0, INT_TYPE, &UntimedBeforeTimed, 0, 0 },
{"Uw", 0, SPECIAL_TYPE, today_wday_func, 0, 0 },
{"Uy", 0, SPECIAL_TYPE, today_year_func, 0, 0 }
{"Uy", 0, SPECIAL_TYPE, today_year_func, 0, 0 },
{"Wednesday", 1, STR_TYPE, &DynamicDayName[2], 0, 0 }
};
#define NUMSYSVARS ( sizeof(SysVarArr) / sizeof(SysVar) )
@@ -857,7 +876,11 @@ int GetSysVar(char const *name, Value *val)
SysVarFunc f = (SysVarFunc) v->value;
return f(0, val);
} else if (v->type == STR_TYPE) {
val->v.str = StrDup(*((char **) v->value));
if (! * (char **) v->value) {
val->v.str = StrDup("");
} else {
val->v.str = StrDup(*((char **) v->value));
}
if (!val->v.str) return E_NO_MEM;
} else {
val->v.val = *((int *) v->value);

View File

@@ -2686,11 +2686,14 @@ a125 -1
dump $
Variable Value
$CalcUTC 0 [0, 1]
$April "April"
$August "August"
$CalMode 0
$CalcUTC 0 [0, 1]
$Daemon 0
$DateSep "-"
$DateTimeSep "@"
$December "December"
$DefaultColor "-1 -1 -1"
$DefaultPrio 5000 [0, 9999]
$DefaultTDelta 0 [0, 1440]
@@ -2700,14 +2703,19 @@ Variable Value
$DontTrigAts 0
$EndSent ".?!"
$EndSentIg "" + char(34) + "')]}>"
$February "February"
$FirstIndent 0 [0, 132]
$FoldYear 0 [0, 1]
$FormWidth 72 [20, 500]
$Friday "Friday"
$HushMode 0
$IgnoreOnce 1
$InfDelta 0
$IntMax 2147483647
$IntMin -2147483648
$January "January"
$July "July"
$June "June"
$LatDeg 30
$Latitude "30.500000"
$LatMin 30
@@ -2717,24 +2725,34 @@ Variable Value
$Longitude "24.750000"
$LongMin 15
$LongSec 0
$March "March"
$MaxSatIter 150 [10, Inf)
$MaxStringLen 65535 [-1, Inf)
$May "May"
$MinsFromUTC -300 [-780, 780]
$Monday "Monday"
$NextMode 0
$November "November"
$NumQueued 0
$NumTrig 37
$October "October"
$PrefixLineNo 0
$PSCal 0
$RunOff 0
$Saturday "Saturday"
$September "September"
$SimpleCal 0
$SortByDate 0
$SortByPrio 0
$SortByTime 0
$SubsIndent 0 [0, 132]
$Sunday "Sunday"
$T 1990-01-01
$Td -1
$Thursday "Thursday"
$TimeSep ":"
$Tm -1
$Tuesday "Tuesday"
$Tw -1
$Ty -1
$U 1991-02-16
@@ -2743,6 +2761,7 @@ Variable Value
$UntimedFirst 0
$Uw 6
$Uy 1991
$Wednesday "Wednesday"
dump $aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Variable Value
@@ -4219,6 +4238,13 @@ Reading `../tests/include_dir/subdir/04.rem': Found in cache
Reading `subdir/04.rem': Opening file on disk
../tests/include_dir/02.rem(3): Can't open file: subdir/04.rem
Reading `../tests/include_dir/04cantread.rem': Opening file on disk
Found cached directory listing for `../tests/include_dir'
Reading `../tests/include_dir/01.rem': Found in cache
Reading `../tests/include_dir/02.rem': Found in cache
Reading `../tests/include_dir/subdir/04.rem': Found in cache
Reading `subdir/04.rem': Opening file on disk
../tests/include_dir/02.rem(3): Can't open file: subdir/04.rem
Reading `../tests/include_dir/04cantread.rem': Opening file on disk
# rem2ps begin
August 2007 31 3 0
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
@@ -4236,20 +4262,10 @@ Test 9
Reading `../tests/nonexistent_include_dir': Opening file on disk
Can't open file: ../tests/nonexistent_include_dir
Error reading ../tests/nonexistent_include_dir: Can't open file
# rem2ps begin
August 2007 31 3 0
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
July 31
September 30
Scanning directory `../tests/include_dir_no_rems' for *.rem files
Caching directory `../tests/include_dir_no_rems' listing
../tests/include_dir_no_rems: No files matching *.rem
Error reading ../tests/include_dir_no_rems: No files matching *.rem
# rem2ps begin
August 2007 31 3 0
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
July 31
September 30
Reading `../tests/include_test.rem': Opening file on disk
Caching file `../tests/include_test.rem' in memory
Scanning directory `include_dir' for *.rem files
@@ -4628,6 +4644,18 @@ Found cached directory listing for `include_dir_no_rems'
../tests/include_test.rem(2): include_dir_no_rems: No files matching *.rem
Reading `nonexistent_include_dir': Opening file on disk
../tests/include_test.rem(3): Can't open file: nonexistent_include_dir
Reading `../tests/include_test.rem': Found in cache
Found cached directory listing for `include_dir'
Reading `include_dir/01.rem': Found in cache
Reading `include_dir/02.rem': Found in cache
Reading `include_dir/subdir/04.rem': Found in cache
Reading `subdir/04.rem': Opening file on disk
include_dir/02.rem(3): Can't open file: subdir/04.rem
Reading `include_dir/04cantread.rem': Opening file on disk
Found cached directory listing for `include_dir_no_rems'
../tests/include_test.rem(2): include_dir_no_rems: No files matching *.rem
Reading `nonexistent_include_dir': Opening file on disk
../tests/include_test.rem(3): Can't open file: nonexistent_include_dir
# rem2ps begin
August 2007 31 3 0
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
@@ -7135,6 +7163,7 @@ February 29
-stdin-(7): Number too high
-stdin-(7): Number too high
-stdin-(7): Number too high
-stdin-(7): Number too high
[
{
"monthname":"January","year":2012,"daysinmonth":31,"firstwkday":0,"mondayfirst":0,"daynames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"prevmonthname":"December","daysinprevmonth":31,"prevmonthyear":2011,"nextmonthname":"February","daysinnextmonth":29,"nextmonthyear":2012,"entries":[