mirror of
https://github.com/simh/simh.git
synced 2026-02-03 23:23:55 +00:00
SCP: Add DATE_19XX_YY and DATE_19XX_YYYY variable insertion.
These variables can be used in SEND scripts which are setting the date/time on non Y2K compliant operating systems.
This commit is contained in:
21
scp.c
21
scp.c
@@ -3061,10 +3061,31 @@ for (; *ip && (op < oend); ) {
|
||||
sprintf (rbuf, "%d", (tmnow->tm_year + 1900)/100);
|
||||
ap = rbuf;
|
||||
}
|
||||
else if ((!strcmp ("DATE_19XX_YY", gbuf)) || /* Year with same calendar */
|
||||
(!strcmp ("DATE_19XX_YYYY", gbuf))) {
|
||||
int year = tmnow->tm_year + 1900 + 22;
|
||||
int days = year - 2001;
|
||||
int leaps = days/4 - days/100 + days/400;
|
||||
int lyear = ((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0));
|
||||
int selector = ((days + leaps + 7) % 7) + lyear * 7;
|
||||
static int years[] = {90, 91, 97, 98, 99, 94, 89,
|
||||
96, 80, 92, 76, 88, 72, 84};
|
||||
int cal_year = years[selector];
|
||||
|
||||
if (!strcmp ("DATE_19XX_YY", gbuf))
|
||||
sprintf (rbuf, "%d", cal_year); /* 2 digit year */
|
||||
else
|
||||
sprintf (rbuf, "%d", cal_year + 1900); /* 4 digit year */
|
||||
ap = rbuf;
|
||||
}
|
||||
else if (!strcmp ("DATE_MM", gbuf)) {/* Month number (01-12) */
|
||||
strftime (rbuf, sizeof(rbuf), "%m", tmnow);
|
||||
ap = rbuf;
|
||||
}
|
||||
else if (!strcmp ("DATE_MMM", gbuf)) {/* Month number (01-12) */
|
||||
strftime (rbuf, sizeof(rbuf), "%b", tmnow);
|
||||
ap = rbuf;
|
||||
}
|
||||
else if (!strcmp ("DATE_DD", gbuf)) {/* Day of Month (01-31) */
|
||||
strftime (rbuf, sizeof(rbuf), "%d", tmnow);
|
||||
ap = rbuf;
|
||||
|
||||
Reference in New Issue
Block a user