home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-07-22 | 30.9 KB | 1,018 lines |
- ***************
- *** 1376,1381 ****
- --- 1390,1426 ----
-
- /***************************************************************/
- /* */
- + /* FFiledir */
- + /* */
- + /* Return directory of current file */
- + /* */
- + /***************************************************************/
- + #ifdef HAVE_PROTOS
- + PRIVATE int FFiledir(void)
- + #else
- + static int FFiledir()
- + #endif
- + {
- + char TmpBuf[LINELEN]; /* Should be _POSIX_PATH_MAX ? */
- + char *s;
- +
- + #ifdef __MSDOS__
- + #define PATHSEP '\\'
- + #else
- + #define PATHSEP '/'
- + #endif
- +
- + strcpy(TmpBuf, FileName);
- + s = TmpBuf + strlen(TmpBuf) - 1;
- + if (s < TmpBuf) return RetStrVal(".");
- + while (s > TmpBuf && *s != PATHSEP) s--;
- + if (*s == PATHSEP) {
- + *s = 0;
- + return RetStrVal(TmpBuf);
- + } else return RetStrVal(".");
- + }
- + /***************************************************************/
- + /* */
- /* FAccess */
- /* */
- /* The UNIX access() system call. */
- ***************
- *** 1571,1576 ****
- --- 1616,1622 ----
- int year, day, mon, jahr;
- int mout, dout;
- int ans, r;
- + int adarbehave;
-
- if (ARG(0).type != INT_TYPE || ARG(1).type != STR_TYPE) return E_BAD_TYPE;
- day = ARG(0).v.val;
- ***************
- *** 1580,1591 ****
- return E_BAD_DATE;
- }
- if (Nargs == 2) {
- ! r = GetNextHebrewDate(JulianToday, mon, day, 0, &ans);
- if (r) return r;
- RetVal.type = DATE_TYPE;
- RetVal.v.val = ans;
- return OK;
- }
- if (Nargs == 4) {
- if (ARG(3).type != INT_TYPE) return E_BAD_TYPE;
- jahr = ARG(3).v.val;
- --- 1626,1644 ----
- return E_BAD_DATE;
- }
- if (Nargs == 2) {
- ! r = GetNextHebrewDate(JulianToday, mon, day, 0, 0, &ans);
- if (r) return r;
- RetVal.type = DATE_TYPE;
- RetVal.v.val = ans;
- return OK;
- }
- + if (Nargs == 5) {
- + if (ARG(4).type != INT_TYPE) return E_BAD_TYPE;
- + adarbehave = ARG(4).v.val;
- + if (adarbehave < 0) return E_2LOW;
- + if (adarbehave > 2) return E_2HIGH;
- + } else adarbehave = 0;
- +
- if (Nargs == 4) {
- if (ARG(3).type != INT_TYPE) return E_BAD_TYPE;
- jahr = ARG(3).v.val;
- ***************
- *** 1599,1605 ****
-
- if (ARG(2).type == INT_TYPE) {
- year = ARG(2).v.val;
- ! r = GetValidHebDate(year, mon, day, &mout, &dout, jahr);
- if (r) return r;
- r = HebToJul(year, mout, dout);
- if (r<0) return E_DATE_OVER;
- --- 1652,1658 ----
-
- if (ARG(2).type == INT_TYPE) {
- year = ARG(2).v.val;
- ! r = GetValidHebDate(year, mon, day, 0, &mout, &dout, jahr);
- if (r) return r;
- r = HebToJul(year, mout, dout);
- if (r<0) return E_DATE_OVER;
- ***************
- *** 1607,1613 ****
- RetVal.type = DATE_TYPE;
- return OK;
- } else if (ARG(2).type == DATE_TYPE) {
- ! r = GetNextHebrewDate(ARG(2).v.val, mon, day, jahr, &ans);
- if (r) return r;
- RetVal.v.val = ans;
- RetVal.type = DATE_TYPE;
- --- 1660,1666 ----
- RetVal.type = DATE_TYPE;
- return OK;
- } else if (ARG(2).type == DATE_TYPE) {
- ! r = GetNextHebrewDate(ARG(2).v.val, mon, day, jahr, adarbehave, &ans);
- if (r) return r;
- RetVal.v.val = ans;
- RetVal.type = DATE_TYPE;
- ***************
- *** 1681,1684 ****
- --- 1734,2008 ----
- RetVal.type = INT_TYPE;
- RetVal.v.val = y;
- return OK;
- + }
- + /****************************************************************/
- + /* */
- + /* FEasterdate - calc. easter Sunday from a year. */
- + /* */
- + /* from The Art of Computer Programming Vol 1. */
- + /* Fundamental Algorithms */
- + /* by Donald Knuth. */
- + /* */
- + /* Donated by Michael Salmon - thanks! */
- + /* */
- + /* I haven't examined this in detail, but I *think* int */
- + /* arithmetic is fine, even on 16-bit machines. */
- + /* */
- + /****************************************************************/
- + #ifdef HAVE_PROTOS
- + PRIVATE int FEasterdate(void)
- + #else
- + static int FEasterdate()
- + #endif
- + {
- + int y, m, d;
- + int g, c, x, z, e, n;
- + if (ARG(0).type == INT_TYPE) {
- + y = ARG(0).v.val;
- + if (y < BASE) return E_2LOW;
- + else if (y > BASE+YR_RANGE) return E_2HIGH;
- + } else if (ARG(0).type == DATE_TYPE) {
- + FromJulian(ARG(0).v.val, &y, &m, &d); /* We just want the year */
- + } else return E_BAD_TYPE;
- +
- + do {
- + g = (y % 19) + 1; /* golden number */
- + c = (y / 100) + 1; /* century */
- + x = (3 * c)/4 - 12; /* correction for non-leap year centuries */
- + z = (8 * c + 5)/25 - 5; /* special constant for moon sync */
- + d = (5 * y)/4 - x - 10; /* find sunday */
- + e = (11 * g + 20 + z - x) % 30; /* calc epact */
- + if ( e < 0 ) e += 30;
- + if ( e == 24 || (e == 25 && g > 11)) e++;
- + n = 44 - e; /* find full moon */
- + if ( n < 21 ) n += 30; /* after 21st */
- + d = n + 7 - (d + n)%7; /* calc sunday after */
- + if (d <= 31) m = 2;
- + else
- + {
- + d = d - 31;
- + m = 3;
- + }
- +
- + RetVal.type = DATE_TYPE;
- + RetVal.v.val = Julian(y, m, d);
- + y++; } while (ARG(0).type == DATE_TYPE && RetVal.v.val < ARG(0).v.val);
- +
- + return OK;
- + }
- + /***************************************************************/
- + /* */
- + /* FIsdst and FMinsfromutc */
- + /* */
- + /* Check whether daylight savings time is in effect, and */
- + /* get minutes from UTC. */
- + /* */
- + /***************************************************************/
- + PRIVATE int FTimeStuff ARGS ((int wantmins));
- + #ifdef HAVE_PROTOS
- + PRIVATE int FIsdst(void)
- + #else
- + static int FIsdst()
- + #endif
- + {
- + return FTimeStuff(0);
- + }
- +
- + #ifdef HAVE_PROTOS
- + PRIVATE int FMinsfromutc(void)
- + #else
- + static int FMinsfromutc()
- + #endif
- + {
- + return FTimeStuff(1);
- + }
- +
- + #ifdef HAVE_PROTOS
- + PRIVATE int FTimeStuff(int wantmins)
- + #else
- + static int FTimeStuff(wantmins)
- + int wantmins;
- + #endif
- + {
- + int jul, tim;
- + int mins, dst;
- +
- + jul = JulianToday;
- + tim = 0;
- +
- + if (Nargs >= 1) {
- + if (ARG(0).type != DATE_TYPE) return E_BAD_TYPE;
- + jul = ARG(0).v.val;
- + if (Nargs >= 2) {
- + if (ARG(1).type != TIM_TYPE) return E_BAD_TYPE;
- + tim = ARG(1).v.val;
- + }
- + }
- +
- + if (CalcMinsFromUTC(jul, tim, &mins, &dst)) return E_MKTIME_PROBLEM;
- + RetVal.type = INT_TYPE;
- + if (wantmins) RetVal.v.val = mins; else RetVal.v.val = dst;
- +
- + return OK;
- + }
- +
- + /***************************************************************/
- + /* */
- + /* Sunrise and sunset functions. */
- + /* */
- + /* Algorithm from "Almanac for computers for the year 1978" */
- + /* by L. E. Doggett, Nautical Almanac Office, USNO. */
- + /* */
- + /* This code also uses some ideas found in programs written */
- + /* by Michael Schwartz and Marc T. Kaufman. */
- + /* */
- + /***************************************************************/
- + #define PI 3.1415926536
- + #define DEGRAD (PI/180.0)
- + #define RADDEG (180.0/PI)
- +
- + #ifdef HAVE_PROTOS
- + PRIVATE int SunStuff(int rise, double cosz, int jul)
- + #else
- + static int SunStuff(rise, cosz, jul)
- + int rise;
- + double cosz;
- + int jul;
- + #endif
- + {
- + int year, mon, day;
- + int jan0;
- + int mins, hours;
- +
- + double M, L, tanA, sinDelta, cosDelta, a, a_hr, cosH, t, H, T;
- + double latitude, longdeg, UT, local;
- +
- + /* Get offset from UTC */
- + if (CalculateUTC) {
- + if (CalcMinsFromUTC(jul, 12*60, &mins, NULL)) {
- + Eprint(ErrMsg[E_MKTIME_PROBLEM]);
- + return NO_TIME;
- + }
- + } else mins = MinsFromUTC;
- +
- + /* Get latitude and longitude */
- + longdeg = (double) LongDeg + (double) LongMin / 60.0
- + + (double) LongSec / 3600.0;
- +
- + latitude = DEGRAD * ((double) LatDeg + (double) LatMin / 60.0
- + + (double) LatSec / 3600.0);
- +
- +
- + FromJulian(jul, &year, &mon, &day);
- + jan0 = jul - Julian(year, 0, 1);
- +
- + /* Following formula on page B6 exactly... */
- + t = (double) jan0;
- + if (rise) t += (6.0 + longdeg/15.0) / 24.0;
- + else t += (18.0 + longdeg/15.0) / 24.0;
- +
- + /* Mean anomaly of sun for 1978 ... how accurate for other years??? */
- + M = 0.985600 * t - 3.251; /* In degrees */
- +
- + /* Sun's true longitude */
- + L = M + 1.916*sin(DEGRAD*M) + 0.02*sin(2*DEGRAD*M) + 282.565;
- + if (L > 360.0) L -= 360.0;
- +
- + /* Tan of sun's right ascension */
- + tanA = 0.91746 * tan(DEGRAD*L);
- + a = RADDEG * atan(tanA);
- +
- + /* Move a into same quadrant as L */
- + if (0.0 <= L && L < 90.0) {
- + if (a < 0.0) a += 180.0;
- + } else if (90.0 <= L && L < 180.0) {
- + a += 180.0;
- + } else if (180.0 <= L && L < 270.0) {
- + a += 180.0;
- + } else {
- + if (a > 0.0) a += 180.0;
- + }
- + /* if (fabs(a - L) > 90.0)
- + a += 180.0; */
- +
- + if (a > 360.0)
- + a -= 360.0;
- + a_hr = a / 15.0;
- +
- + /* Sine of sun's declination */
- + sinDelta = 0.39782 * sin(DEGRAD*L);
- + cosDelta = sqrt(1 - sinDelta*sinDelta);
- +
- + /* Cosine of sun's local hour angle */
- + cosH = (cosz - sinDelta * sin(latitude)) / (cosDelta * cos(latitude));
- +
- + if (cosH > 1.0 || cosH < -1.0) return NO_TIME;
- +
- + H = RADDEG * acos(cosH);
- + if (rise) H = 360.0 - H;
- +
- + T = H / 15.0 + a_hr - 0.065710*t - 6.620;
- + if (T >= 24.0) T -= 24.0;
- + else if (T < 0.0) T+= 24.0;
- +
- + UT = T + longdeg / 15.0;
- +
- +
- + local = UT + (double) mins / 60.0;
- + if (local < 0.0) local += 24.0;
- + else if (local >= 24.0) local -= 24.0;
- +
- + hours = (int) local;
- + mins = (int) ((local - hours) * 60.0);
- +
- + return hours*60 + mins;
- + }
- +
- + /***************************************************************/
- + /* */
- + /* Sunrise and Sunset functions. */
- + /* */
- + /***************************************************************/
- + #ifdef HAVE_PROTOS
- + PRIVATE int FSun(int rise)
- + #else
- + static int FSun(rise)
- + int rise;
- + #endif
- + {
- + int jul = JulianToday;
- + static double cosz = -0.014543897; /* for sunrise and sunset */
- + int r;
- +
- + if (Nargs >= 1) {
- + if (ARG(0).type != DATE_TYPE) return E_BAD_TYPE;
- + jul = ARG(0).v.val;
- + }
- +
- + r = SunStuff(rise, cosz, jul);
- + if (r == NO_TIME) {
- + RetVal.v.val = 0;
- + RetVal.type = INT_TYPE;
- + } else {
- + RetVal.v.val = r;
- + RetVal.type = TIM_TYPE;
- + }
- + return OK;
- + }
- +
- + #ifdef HAVE_PROTOS
- + PRIVATE int FSunrise(void)
- + #else
- + static int FSunrise()
- + #endif
- + {
- + return FSun(1);
- + }
- + #ifdef HAVE_PROTOS
- + PRIVATE int FSunset(void)
- + #else
- + static int FSunset()
- + #endif
- + {
- + return FSun(0);
- }
- *** ../p6/globals.h Thu Apr 22 10:24:07 1993
- --- ./globals.h Mon Jun 28 12:29:31 1993
- ***************
- *** 31,69 ****
- EXTERN int CurMon;
- EXTERN int CurYear;
- EXTERN int LineNo;
- ! EXTERN char FreshLine;
- EXTERN char LineBuffer[LINELEN];
- EXTERN char SubstBuffer[LINELEN];
- EXTERN char TokBuffer[TOKSIZE+1];
- EXTERN INIT( char *MsgCommand, NULL);
- ! EXTERN INIT( char ShowAllErrors, 0);
- EXTERN INIT( int DebugFlag, 0);
- ! EXTERN INIT( char DoCalendar, 0);
- ! EXTERN INIT( char DoSimpleCalendar, 0);
- ! EXTERN INIT( char PsCal, 0);
- EXTERN INIT( int CalWidth, 80);
- EXTERN INIT( int CalWeeks, 0);
- EXTERN INIT( int CalMonths, 0);
- ! EXTERN INIT( char Hush, 0);
- ! EXTERN INIT( char NextMode, 0);
- ! EXTERN INIT( char InfiniteDelta, 0);
- ! EXTERN INIT( char RunDisabled, 0);
- ! EXTERN INIT( char IgnoreOnce, 0);
- EXTERN INIT( char Banner[LINELEN], L_BANNER);
- ! EXTERN INIT( char SortByTime, 0);
- ! EXTERN INIT( char SortByDate, 0);
-
- EXTERN char *InitialFile;
- EXTERN int FileAccessDate;
-
- ! #ifdef HAVE_QUEUED
- ! EXTERN INIT( char DontFork, 0);
- ! EXTERN INIT( char DontQueue, 0);
- EXTERN INIT( int NumQueued, 0);
- ! EXTERN INIT( char DontIssueAts, 0);
- ! EXTERN INIT( char Daemon, 0);
- ! #endif
-
- EXTERN INIT( int ScFormat, SC_AMPM);
- EXTERN INIT( int MaxSatIter, 150);
- EXTERN INIT( char *FileName, NULL);
- --- 31,68 ----
- EXTERN int CurMon;
- EXTERN int CurYear;
- EXTERN int LineNo;
- ! EXTERN int FreshLine;
- EXTERN char LineBuffer[LINELEN];
- EXTERN char SubstBuffer[LINELEN];
- EXTERN char TokBuffer[TOKSIZE+1];
- EXTERN INIT( char *MsgCommand, NULL);
- ! EXTERN INIT( int ShowAllErrors, 0);
- EXTERN INIT( int DebugFlag, 0);
- ! EXTERN INIT( int DoCalendar, 0);
- ! EXTERN INIT( int DoSimpleCalendar, 0);
- ! EXTERN INIT( int PsCal, 0);
- EXTERN INIT( int CalWidth, 80);
- EXTERN INIT( int CalWeeks, 0);
- EXTERN INIT( int CalMonths, 0);
- ! EXTERN INIT( int Hush, 0);
- ! EXTERN INIT( int NextMode, 0);
- ! EXTERN INIT( int InfiniteDelta, 0);
- ! EXTERN INIT( int RunDisabled, 0);
- ! EXTERN INIT( int IgnoreOnce, 0);
- EXTERN INIT( char Banner[LINELEN], L_BANNER);
- ! EXTERN INIT( int SortByTime, 0);
- ! EXTERN INIT( int SortByDate, 0);
-
- EXTERN char *InitialFile;
- EXTERN int FileAccessDate;
-
- ! EXTERN INIT( int DontFork, 0);
- ! EXTERN INIT( int DontQueue, 0);
- EXTERN INIT( int NumQueued, 0);
- ! EXTERN INIT( int DontIssueAts, 0);
- ! EXTERN INIT( int Daemon, 0);
-
- +
- EXTERN INIT( int ScFormat, SC_AMPM);
- EXTERN INIT( int MaxSatIter, 150);
- EXTERN INIT( char *FileName, NULL);
- ***************
- *** 71,79 ****
- EXTERN INIT( int NumIfs, 0);
- EXTERN INIT( unsigned int IfFlags, 0);
- EXTERN INIT( int LastTriggerDate, 0);
- ! EXTERN INIT( char LastTrigValid, 0);
- EXTERN INIT( int LastTriggerTime, 0);
- ! EXTERN INIT( char ShouldCache, 0);
- EXTERN char *CurLine;
- EXTERN INIT( int NumTriggered, 0);
- EXTERN int ArgC;
- --- 70,78 ----
- EXTERN INIT( int NumIfs, 0);
- EXTERN INIT( unsigned int IfFlags, 0);
- EXTERN INIT( int LastTriggerDate, 0);
- ! EXTERN INIT( int LastTrigValid, 0);
- EXTERN INIT( int LastTriggerTime, 0);
- ! EXTERN INIT( int ShouldCache, 0);
- EXTERN char *CurLine;
- EXTERN INIT( int NumTriggered, 0);
- EXTERN int ArgC;
- ***************
- *** 81,86 ****
- --- 80,97 ----
- EXTERN INIT( int CalLines, CAL_LINES);
- EXTERN INIT( int CalPad, 1);
-
- + /* Latitude and longitude */
- + EXTERN INIT( int LatDeg, LAT_DEG);
- + EXTERN INIT( int LatMin, LAT_MIN);
- + EXTERN INIT( int LatSec, LAT_SEC);
- + EXTERN INIT( int LongDeg, LONG_DEG);
- + EXTERN INIT( int LongMin, LONG_MIN);
- + EXTERN INIT( int LongSec, LONG_SEC);
- +
- + /* UTC calculation stuff */
- + EXTERN INIT( int MinsFromUTC, 0);
- + EXTERN INIT( int CalculateUTC, 1);
- + EXTERN INIT( int FoldYear, 0);
- /* List of months */
- EXTERN char *MonthName[]
- #ifdef MK_GLOBALS
- *** ../p6/hbcal.c Mon May 3 11:34:29 1993
- --- ./hbcal.c Mon Jun 28 12:29:49 1993
- ***************
- *** 48,53 ****
- --- 48,57 ----
- #define JAHR_FORWARD 1
- #define JAHR_BACKWARD 2
-
- + #define ADAR2ADARB 0
- + #define ADAR2ADARA 1
- + #define ADAR2BOTH 2
- +
- static char *HebMonthNames[] = {
- "Tishrey", "Heshvan", "Kislev", "Tevet", "Shvat", "Adar A", "Adar B",
- "Nisan", "Iyar", "Sivan", "Tamuz", "Av", "Elul", "Adar"};
- ***************
- *** 324,334 ****
- /* */
- /***************************************************************/
- #ifdef HAVE_PROTOS
- ! PUBLIC int GetValidHebDate(int yin, int min, int din,
- int *mout, int *dout, int jahr)
- #else
- ! int GetValidHebDate(yin, min, din, mout, dout, jahr)
- ! int yin, min, din, *mout, *dout, jahr;
- #endif
- {
- char *monlen;
- --- 328,338 ----
- /* */
- /***************************************************************/
- #ifdef HAVE_PROTOS
- ! PUBLIC int GetValidHebDate(int yin, int min, int din, int adarbehave,
- int *mout, int *dout, int jahr)
- #else
- ! int GetValidHebDate(yin, min, din, adarbehave, mout, dout, jahr)
- ! int yin, min, din, adarbehave, *mout, *dout, jahr;
- #endif
- {
- char *monlen;
- ***************
- *** 344,355 ****
- return E_BAD_DATE;
- }
-
- - /* Convert ADAR to ADAR-B */
- - if (min == ADAR) *mout = min = ADARB;
- -
- ylen = DaysInHebYear(yin);
- monlen = DaysInHebMonths(ylen);
-
- if (din <= monlen[min]) return OK;
-
- switch(jahr) {
- --- 348,371 ----
- return E_BAD_DATE;
- }
-
- ylen = DaysInHebYear(yin);
- monlen = DaysInHebMonths(ylen);
-
- + /* Convert ADAR as necessary */
- + if (min == ADAR) {
- + switch(adarbehave) {
- + case ADAR2ADARA: if (monlen[ADARA]) *mout = min = ADARA;
- + else *mout = min = ADARB;
- + break;
- +
- + case ADAR2ADARB: *mout = min = ADARB; break;
- +
- + default:
- + Eprint("GetValidHebDate: Bad adarbehave value %d", adarbehave);
- + return E_SWERR;
- + }
- + }
- +
- if (din <= monlen[min]) return OK;
-
- switch(jahr) {
- ***************
- *** 418,443 ****
- /* */
- /***************************************************************/
- #ifdef HAVE_PROTOS
- ! PUBLIC int GetNextHebrewDate(int julstart, int hm, int hd, int jahr, int *ans)
- #else
- ! int GetNextHebrewDate(julstart, hm, hd, jahr, ans)
- ! int julstart, hm, hd, jahr, *ans;
- #endif
- {
- int r, yout, mout, dout, jul=1;
-
- /* I initialize jul above to stop gcc from complaining about
- possible use of uninitialized variable. You can take it
- out if the small inefficiency really bothers you. */
-
- JulToHeb(julstart, &yout, &mout, &dout);
-
- r = 1;
- while(r) {
- ! r = GetValidHebDate(yout, hm, hd, &mout, &dout, jahr);
- if (dout == -1) return r;
- if (r) {
- ! yout++;
- continue;
- }
- jul = HebToJul(yout, mout, dout);
- --- 434,471 ----
- /* */
- /***************************************************************/
- #ifdef HAVE_PROTOS
- ! PUBLIC int GetNextHebrewDate(int julstart, int hm, int hd,
- ! int jahr, int adarbehave, int *ans)
- #else
- ! int GetNextHebrewDate(julstart, hm, hd, jahr, adarbehave, ans)
- ! int julstart, hm, hd, jahr, adarbehave, *ans;
- #endif
- {
- int r, yout, mout, dout, jul=1;
- + int adarflag = adarbehave;
-
- /* I initialize jul above to stop gcc from complaining about
- possible use of uninitialized variable. You can take it
- out if the small inefficiency really bothers you. */
-
- + /* If adarbehave == ADAR2BOTH, set adarflag to ADAR2ADARA for now */
- + if (adarbehave == ADAR2BOTH) adarflag = ADAR2ADARA;
- +
- JulToHeb(julstart, &yout, &mout, &dout);
-
- r = 1;
- while(r) {
- ! r = GetValidHebDate(yout, hm, hd, adarflag, &mout, &dout, jahr);
- if (dout == -1) return r;
- if (r) {
- ! if (adarbehave == ADAR2BOTH && hm == ADAR) {
- ! if (adarflag == ADAR2ADARA) {
- ! adarflag = ADAR2ADARB;
- ! } else {
- ! adarflag = ADAR2ADARA;
- ! yout++;
- ! }
- ! } else yout++;
- continue;
- }
- jul = HebToJul(yout, mout, dout);
- ***************
- *** 444,450 ****
- if (jul < 0) return E_DATE_OVER;
- if (jul >= julstart) break;
- else {
- ! yout++;
- r=1; /* Force loop to continue */
- }
- }
- --- 472,485 ----
- if (jul < 0) return E_DATE_OVER;
- if (jul >= julstart) break;
- else {
- ! if (adarbehave == ADAR2BOTH && hm == ADAR) {
- ! if (adarflag == ADAR2ADARA) {
- ! adarflag = ADAR2ADARB;
- ! } else {
- ! adarflag = ADAR2ADARA;
- ! yout++;
- ! }
- ! } else yout++;
- r=1; /* Force loop to continue */
- }
- }
- *** ../p6/init.c Thu Apr 29 15:08:41 1993
- --- ./init.c Mon Jun 28 12:29:50 1993
- ***************
- *** 61,67 ****
- * -z[n] = Daemon mode waking up every n (def 5) minutes.
- * -bn = Time format for cal (0, 1, or 2)
- * -xn = Max. number of iterations for SATISFY
- ! * -uname = Run as user 'name' - only valid when run by root.
- * -kcmd = Run 'cmd' for MSG-type reminders instead of printing to stdout
- * -iVAR=EXPR = Initialize and preserve VAR.
- *
- --- 61,68 ----
- * -z[n] = Daemon mode waking up every n (def 5) minutes.
- * -bn = Time format for cal (0, 1, or 2)
- * -xn = Max. number of iterations for SATISFY
- ! * -uname = Run as user 'name' - only valid when run by root. If run
- ! * by non-root, changes environment but not effective uid.
- * -kcmd = Run 'cmd' for MSG-type reminders instead of printing to stdout
- * -iVAR=EXPR = Initialize and preserve VAR.
- *
- ***************
- *** 116,121 ****
- --- 117,130 ----
- JulianToday = RealToday;
- FromJulian(JulianToday, &CurYear, &CurMon, &CurDay);
-
- + #if !defined(HAVE_QUEUED)
- + DontFork = 1;
- + DontQueue = 1;
- + NumQueued = 0;
- + DontIssueAts = 0;
- + Daemon = 0;
- + #endif
- +
- /* Parse the command-line options */
- i = 1;
- while (i < argc) {
- ***************
- *** 229,236 ****
- case 's':
- case 'S':
- DoSimpleCalendar = 1;
- ! PARSENUM(CalMonths, arg);
- ! if (!CalMonths) CalMonths = 1;
- break;
-
- case 'p':
- --- 238,251 ----
- case 's':
- case 'S':
- DoSimpleCalendar = 1;
- ! if (*arg == '+') {
- ! arg++;
- ! PARSENUM(CalWeeks, arg);
- ! if (!CalWeeks) CalWeeks = 1;
- ! } else {
- ! PARSENUM(CalMonths, arg);
- ! if (!CalMonths) CalMonths = 1;
- ! }
- break;
-
- case 'p':
- ***************
- *** 357,363 ****
- --- 372,383 ----
- CurMon = m;
- CurDay = d;
- if (JulianToday != RealToday) IgnoreOnce = 1;
- +
- }
- + /* Figure out the offset from UTC */
- + if (CalculateUTC)
- + (void) CalcMinsFromUTC(JulianToday, SystemTime()/60,
- + &MinsFromUTC, NULL);
- }
-
- /***************************************************************/
- ***************
- *** 384,390 ****
- fprintf(ErrFp, " -c[n] Produce a calendar for n (default 1) months\n");
- fprintf(ErrFp, " -c+[n] Produce a calendar for n (default 1) weeks\n");
- fprintf(ErrFp, " -w[n[,p[,s]]] Specify width, padding and spacing of calendar\n");
- ! fprintf(ErrFp, " -s[n] Produce 'simple calendar' for n (1) months\n");
- fprintf(ErrFp, " -p[n] Same as -s, but input compatible with rem2ps\n");
- fprintf(ErrFp, " -v Verbose mode\n");
- fprintf(ErrFp, " -o Ignore ONCE directives\n");
- --- 404,410 ----
- fprintf(ErrFp, " -c[n] Produce a calendar for n (default 1) months\n");
- fprintf(ErrFp, " -c+[n] Produce a calendar for n (default 1) weeks\n");
- fprintf(ErrFp, " -w[n[,p[,s]]] Specify width, padding and spacing of calendar\n");
- ! fprintf(ErrFp, " -s[+][n] Produce 'simple calendar' for n (1) months (weeks)\n");
- fprintf(ErrFp, " -p[n] Same as -s, but input compatible with rem2ps\n");
- fprintf(ErrFp, " -v Verbose mode\n");
- fprintf(ErrFp, " -o Ignore ONCE directives\n");
- ***************
- *** 402,408 ****
- fprintf(ErrFp, " -x[n] Iteration limit for SATISFY clause (def=150)\n");
- fprintf(ErrFp, " -kcmd Run 'cmd' for MSG-type reminders\n");
- fprintf(ErrFp, " -g[d[d]] Sort reminders by date and time before issuing\n");
- ! fprintf(ErrFp, "-ivar=val Initialize var to val and preserve var\n");
- exit(1);
- }
-
- --- 422,428 ----
- fprintf(ErrFp, " -x[n] Iteration limit for SATISFY clause (def=150)\n");
- fprintf(ErrFp, " -kcmd Run 'cmd' for MSG-type reminders\n");
- fprintf(ErrFp, " -g[d[d]] Sort reminders by date and time before issuing\n");
- ! fprintf(ErrFp, " -ivar=val Initialize var to val and preserve var\n");
- exit(1);
- }
-
- ***************
- *** 436,445 ****
- static char *home, *shell, *username, *logname;
-
- myuid = getuid();
- - if (myuid) {
- - fprintf(ErrFp, "Remind: Only the super-user can use the '-u' option.\n");
- - exit(1);
- - }
-
- pwent = getpwnam(user);
-
- --- 456,461 ----
- ***************
- *** 448,459 ****
- exit(1);
- }
-
- ! if (setgid(pwent->pw_gid)) {
- fprintf(ErrFp, "Remind: Could not change gid to %d\n", pwent->pw_gid);
- exit(1);
- }
-
- ! if (setuid(pwent->pw_uid)) {
- fprintf(ErrFp, "Remind: Could not change uid to %d\n", pwent->pw_uid);
- exit(1);
- }
- --- 464,475 ----
- exit(1);
- }
-
- ! if (!myuid && setgid(pwent->pw_gid)) {
- fprintf(ErrFp, "Remind: Could not change gid to %d\n", pwent->pw_gid);
- exit(1);
- }
-
- ! if (!myuid && setuid(pwent->pw_uid)) {
- fprintf(ErrFp, "Remind: Could not change uid to %d\n", pwent->pw_uid);
- exit(1);
- }
- ***************
- *** 535,540 ****
- --- 551,566 ----
- r=EvalExpr(&expr, &val);
- if (r) {
- fprintf(ErrFp, Err, ErrMsg[r]);
- + return;
- + }
- +
- + if (*varname == '$') {
- + if (val.type != INT_TYPE) {
- + fprintf(ErrFp, Err, ErrMsg[E_BAD_TYPE]);
- + return;
- + }
- + r=SetSysVar(varname+1, val.v.val);
- + if (r) fprintf(ErrFp, Err, ErrMsg[r]);
- return;
- }
-
- *** ../p6/kall Thu Apr 22 10:24:09 1993
- --- ./kall Mon Jun 28 12:30:15 1993
- ***************
- *** 25,31 ****
-
- # NOTE: You may have to modify the next line, since PS is non-portable.
- # The 'awk' command picks out the process IDs to pass them on to kill.
- ! rprocs=`ps cx | awk '{if(prog == $NF) print $1}' prog=$1 -`
- if [ "$rprocs" != "" ]; then
- msg="1"
- echo -n "${me}: Sending $signal signal to $1 process(es)"
- --- 25,31 ----
-
- # NOTE: You may have to modify the next line, since PS is non-portable.
- # The 'awk' command picks out the process IDs to pass them on to kill.
- ! rprocs=`ps cx | awk '{if(prog == $NF && $1 != mypid) print $1}' prog=$1 mypid=$$ -`
- if [ "$rprocs" != "" ]; then
- msg="1"
- echo -n "${me}: Sending $signal signal to $1 process(es)"
- *** ../p6/main.c Thu Apr 22 10:24:10 1993
- --- ./main.c Mon Jun 28 12:39:37 1993
- ***************
- *** 30,38 ****
-
- #ifdef __MSDOS__
- #include <dos.h>
- ! # ifdef __MSC__
- ! # include <time.h>
- ! # endif
- #endif
-
-
- --- 30,36 ----
-
- #ifdef __MSDOS__
- #include <dos.h>
- ! #include <time.h>
- #endif
-
-
- ***************
- *** 92,98 ****
- /* Not doing a calendar. Do the regular remind loop */
- DoReminders();
-
- ! if (DebugFlag & DB_DUMP_VARS) DumpVarTable();
-
- if (!Hush) {
- if (DestroyOmitContexts())
- --- 90,99 ----
- /* Not doing a calendar. Do the regular remind loop */
- DoReminders();
-
- ! if (DebugFlag & DB_DUMP_VARS) {
- ! DumpVarTable();
- ! DumpSysVarByName(NULL);
- ! }
-
- if (!Hush) {
- if (DestroyOmitContexts())
- ***************
- *** 482,488 ****
- if (err) return err;
- }
- if (!c) return E_EOLN;
- ! if (c != '_' && !isalpha(c)) return E_BAD_ID;
- *out++ = c;
- *out = 0;
- len++;
- --- 483,489 ----
- if (err) return err;
- }
- if (!c) return E_EOLN;
- ! if (c != '$' && c != '_' && !isalpha(c)) return E_BAD_ID;
- *out++ = c;
- *out = 0;
- len++;
- ***************
- *** 1048,1058 ****
- if ( (r=ParseToken(p, TokBuffer)) ) return r;
-
- /* Only allow RUN ON in top-level script */
- ! if (StriEq(TokBuffer, "ON")) {
- if (TopLevel()) RunDisabled &= ~RUN_SCRIPT;
- }
- /* But allow RUN OFF anywhere */
- ! else if (StriEq(TokBuffer, "OFF"))
- RunDisabled |= RUN_SCRIPT;
- else return E_PARSE_ERR;
-
- --- 1049,1059 ----
- if ( (r=ParseToken(p, TokBuffer)) ) return r;
-
- /* Only allow RUN ON in top-level script */
- ! if (! StrCmpi(TokBuffer, "ON")) {
- if (TopLevel()) RunDisabled &= ~RUN_SCRIPT;
- }
- /* But allow RUN OFF anywhere */
- ! else if (! StrCmpi(TokBuffer, "OFF"))
- RunDisabled |= RUN_SCRIPT;
- else return E_PARSE_ERR;
-
- ***************
- *** 1088,1090 ****
- --- 1089,1164 ----
- return OK;
- }
-
- + /***************************************************************/
- + /* */
- + /* CalcMinsFromUTC */
- + /* */
- + /* Attempt to calculate the minutes from UTC for a specific */
- + /* date. */
- + /* */
- + /***************************************************************/
- +
- + /* The array FoldArray[2][7] contains sample years which begin
- + on the specified weekday. For example, FoldArray[0][2] is a
- + non-leapyear beginning on Wednesday, and FoldArray[1][5] is a
- + leapyear beginning on Saturday. Used to fold back dates which
- + are too high for the standard Unix representation.
- + NOTE: This implies that you cannot set BASE > 2001!!!!! */
- + static int FoldArray[2][7] = {
- + {2001, 2002, 2003, 2009, 2010, 2005, 2006},
- + {2024, 2008, 2020, 2004, 2016, 2000, 2012}
- + };
- +
- + #ifdef HAVE_PROTOS
- + PUBLIC int CalcMinsFromUTC(int jul, int tim, int *mins, int *isdst)
- + #else
- + int CalcMinsFromUTC(jul, tim, mins, isdst)
- + int jul, tim, *mins, *isdst;
- + #endif
- + {
- +
- + /* Convert jul and tim to an Unix tm struct */
- + int yr, mon, day;
- + struct tm local, utc, *temp;
- + time_t loc_t, utc_t;
- +
- + FromJulian(jul, &yr, &mon, &day);
- +
- + /* If the year is greater than 2037, some Unix machines have problems.
- + Fold it back to a "similar" year and trust that the UTC calculations
- + are still valid... */
- + if (FoldYear && yr>2037) {
- + jul = Julian(yr, 0, 1);
- + yr = FoldArray[IsLeapYear(yr)][jul%7];
- + }
- + local.tm_sec = 0;
- + local.tm_min = tim % 60;
- + local.tm_hour = tim / 60;
- + local.tm_mday = day;
- + local.tm_mon = mon;
- + local.tm_year = yr-1900;
- + local.tm_isdst = -1; /* We don't know whether or not dst is in effect */
-