[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference taveng::bagels

Title:BAGELS and other things of Jewish interest
Notice:1.0 policy, 280.0 directory, 32.0 registration
Moderator:SMURF::FENSTER
Created:Mon Feb 03 1986
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1524
Total number of notes:18709

260.0. "Jewish Software" by GRAMPS::LISS (ESD&P Shrewsbury) Tue Jan 20 1987 16:53

    Here is a collection of programs that I've come across during the
    last couple of years that I would like to share with the group.
    Some of them are very useful and others are just fun. They all
    came from the USENET so I know nothing about their copyrights. 
    
    I'm setting this note nowrite because I would like to have only
    listings and no discussion. If you have a listing you would like
    to post write up a note and I'll post it for you. 
    
    Some programs that I will be posting when I get the time are
    
    	YERTZ.C  Yertzite calander
    	LCAL.C	 Jewish calander
    	HCAL.C	 A variation of LCAL.C
    
    
T.RTitleUserPersonal
Name
DateLines
260.1YERTZ.CGRAMPS::LISSESD&P ShrewsburyFri Feb 20 1987 15:20496
    The programs I entered here a while back seem to have "gone away".
    I'll post them one more time. 
    
    YERTZ.C is a program for generating an 80 year yertzite calendar.
    it is also useful for future birthdays, anniversaries, and
    holidays. Here is a quick cookbook method to get this program to
    run. 
    
    Use the following commands to compile and link the program.
    
	$ cc yertz
	$ link yertz,sys$library:vaxcrtl/lib

    Add the following symbol to your login.com. Don't forget the $
    before the disk name. 
    
    	YERTZ :== $yourdisk:[yourdirectory]yertz
    
    Run your login.com file.
    
    Run the program by typing...
    
    yertz mm dd yyyy
    
    mm is the month
    dd is the day
    yyyy is the year
    
    For example enter   yertz 02 15 1987  for Feb 15, 1987. If
    you do not enter a date the default will be todays date. There
    is additional information in the program listing. Have fun.
    
    
    -----------------------< cut here >-----------------------
#include <stdio.h>
#include <time.h>
/*
This program writes a 80-year 'Yahrzeit' table (to stdout) according to the
Jewish Calendar.  If no argument is specified, it calls a "ctime"
function to use today's date.  Otherwise, it may be invoked
with 3 arguments -- month, day, year (4-digit negative for BC(E)).
*/
/*
The rules for the case that the event occurs on the 30th of Chshvn or Kislev
were obtained from 'A Guide to Jewish Practice' by Rabbi Isaac Klein and
from a conversation with Rabbi Eliahv Soloveichik of the Chicago, IL, area.
*/
 
static char *copyright = {
"(C) 1986 Randolph J. Herber  Usage is unrestricted with retention of notice."
};
 
#define TRUE     1
#define FALSE    0
 
extern void exit();
 
static char *program;
 
static char msg1[] = "%s: Internal error (%d)\n";
static char msg2[] = "%s: Can not setup %s year (%d)\n";
static char Jewish[] = "Jewish";
static char Common[] = "Common";
 
static char *dname[] = {
	"Sunday",
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday"
};
 
static int cyear, cstyle, cleap;
 
static int cmln[] = {
	0,31,28,31,30,31,30,31,31,30,31,30,31
};
 
static char *cmname[] = {
	"",
	"January",
	"February",
	"March",
	"April",
	"May",
	"June",
	"July",
	"August",
	"September",
	"October",
	"November",
	"December"
};
 
static int jyear, jtype, jleap, jrhdow, jpdow;
 
static int jmln[] = {
	0,30,29,30,29,30,30,29,30,29,30,29,30,29
};
 
static char *jmname[] = {
	"",
	"Tishri",
	"Chshvn",
	"Kislev",
	"Tebet",
	"Shebat",
	"Adar",
	"VeAdar",
	"Nisan",
	"Iyar",
	"Sivan",
	"Tammuz",
	"Ab",
	"Elul"
};
 
static short mdays[] = {
	0,   354,   708,  1092,
	1446,  1801,  2185,  2539,
	2923,  3277,  3632,  4016,
	4370,  4724,  5108,  5463,
	5817,  6201,  6555
};
 
static short mparts[] = {
	0,  9516, 19032, 16381,
	25897,  9493,  6842, 16358,
	13703, 23223,  6819,  4168,
	13684, 23200, 20549,  4145,
	13661, 11010, 20526
};
 
static short mtype[] = {
	2,     1,     0,     2,
	1,     0,     3,     0,
	2,     1,     0,     2,
	1,     0,     2,     1,
	0,     3,     0
};
 
static long table1[4][9] = {
	{0,15611,38880,64800, 83855,116640,145211,168480,181440},
	{0, 3444,38880,55284,107124,116640,133044,168480,181440},
	{0, 3444,36229,55284,107124,116640,123528,168480,181440},
	{0, 3444,36229,55284,107124,116640,133044,168480,181440}
};
 
 
 
static short table2[2][9] = {
	{1,3,2,2,3,1,3,1,0},
	{1,3,2,1,3,1,3,1,0}
};
 
 
 
static short table3[] = {
	1,1,2,4,4,6,6,1,0
};
 
static char *jtx1[] = {
	"", "defective", "normal", "complete"
};
 
static char *jtx2[] = {
	"", " leap"
};
 
int unit(f1,f2)
	int f1, f2;
{
	int rmdr;
	rmdr = f1 % f2;
	if (rmdr < 0) rmdr += f2;
	return (f1 - rmdr) / f2;
}
 
 
long lunit(f1,f2)
	long f1, f2;
{
	long rmdr;
	rmdr = f1 % f2;
	if (rmdr < 0) rmdr += f2;
	return (f1 - rmdr) / f2;
}
 
 
int rmdr(f1,f2)
	int f1, f2;
{
	int rmdrx;
	rmdrx = f1 % f2;
	if (rmdrx < 0) rmdrx += f2;
	return rmdrx;
}
 
 
long lrmdr(f1,f2)
	long f1, f2;
{
	long rmdrx;
	rmdrx = f1 % f2;
	if (rmdrx < 0) rmdrx += f2;
	return rmdrx;
}
 
static int ca(year,month,day,jdcommon)
int year, month, day;
long *jdcommon;
{
	int yr, yrm1, n;
	*jdcommon = 0;
	if (year != 0 && year >= -3761 && year < 10000) {
		yr = year > 0 ? year : year + 1;
		cstyle = year > 1582;
		cleap = cstyle
		    ? (((yr % 4) == 0) && ((yr % 100) != 0)) ||
			((yr % 400) == 0)
		    : ((yr % 4) == 0);
		cmln[2] = cleap ? 29 : 28;
		if (month>=1 && month<=12 && day>=1 && day<=cmln[month] &&
		    !(year==1582 && month==10 && day>=5 && day<=14)) {
			if (year == 1582 && month == 10) {
				cmln[10] = 21;
				if (day >= 15) day -= 10;
			} else {
				cmln[10] = 31;
			}
			yrm1 = yr - 1;
			*jdcommon = 1721423l+yrm1*365+unit(yrm1,4)+day;
			for (n=1;n<month;++n) {
				*jdcommon += cmln[n];
			}
			if (cstyle) {
				*jdcommon -= 10 +
					(yrm1-1500)/100 - (yrm1-1200)/400;
			}
			cyear = year;
			return 0;
		} else
			return 1;
	} else
		return 2;
}
 
static int ja(year,month,day,jdjewish)
int year, month, day;
long *jdjewish;
{
	long jparts, days, jarg, jwork;
	int jyr;
	int jcycle, n;
	*jdjewish = 0;
	jtype = 0;
	jleap = 0;
	jrhdow = 0;
	jpdow = 0;
	if (year < 1 || (year==1 && (month<13 || (month==13 && day<25))))
		return 2;
	if (year > 13760)
		return 2;
	jyr = year - 1;
	jcycle = unit(jyr,19);
	year = rmdr(jyr,19);
	jtype = mtype[year];
	jleap = jtype == 0;
	jparts = 17875l*jcycle+mparts[year]+25044l;
	days = lunit(jparts,25920l);
	jparts -= days * 25920l;
	days += 6939l*jcycle+mdays[year]+347998l;
	jarg = lrmdr(days,7l)*25920l+jparts;
	for(n=0;n<=7;++n) {
		if (table1[jtype][n]<=jarg &&
		    jarg<table1[jtype][n+1]) break;
	}
	jtype = table2[jleap][n];
	jwork = days+lrmdr(2l+table3[n]-days,7l)-3l;
	switch (jtype) {
		case 1: jmln[2] = 29; jmln[3] = 29; break;
		case 2: jmln[2] = 29; jmln[3] = 30; break;
		case 3: jmln[2] = 30; jmln[3] = 30; break;
		default:
			(void) printf(msg1, program, 1);
			(void) exit(3);
			break;
	}
	if (jleap) {
		jmln[6] = 30;
		jmln[7] = 29;
	} else {
		jmln[6] = 29;
		jmln[7] = 0;
	}
	if (month==7 && !jleap)
		month = 6;
	if (month<1 || month>13 || day<1 || day>jmln[month])
		return 1;
	jrhdow = lrmdr(jwork+1l,7l);
	jpdow = lrmdr(jwork+
		jmln[1]+jmln[2]+jmln[3]+jmln[4]+jmln[5]+jmln[6]+jmln[7]+15l,7l);
	for(n=1; n<month; ++n)
		jwork += jmln[n];
	*jdjewish = jwork+day-1;
	jyear = year;
	return 0;
}
 
main(argc,argv)
int argc;
char **argv;
{
 
	long secs, time();
	struct tm *tbuf, *localtime();
	int yr, mo, da, jyr, jmo, jda, wjmo, wjda;
	long jdcommon, jdjewish, junk;
	int n, delay = 1;
	char text[80];
	char up = FALSE;
 
	program = *argv;
 
	if (!((argc == 1) ||
	      (argc == 2 && argv[1][0] == '-') ||
	      (argc == 4 && argv[1][0] != '-') ||
	      (argc == 5 && argv[1][0] == '-'))) {
		(void) printf("Usage: %s [-<n>] [<mo> <da> <yr>]\n", program);
		(void) printf("          <n> (default is 1)\n");
		(void) printf("              years to first observation\n");
		(void) printf("          <mo> <da> <yr> (default is today)\n");
		(void) printf("              common date of initial event\n");
		(void) exit(1);
	}
	if (argc == 2 || argc == 5) {
		delay = atoi(argv[1]+1);
		if (delay < 0)
			delay = 0;
		--argc;
		++argv;
	}
	if (argc == 1) {
		secs = time((long *)0);
		tbuf = localtime(&secs);
		mo = tbuf->tm_mon + 1;
		da = tbuf->tm_mday;
		yr = tbuf->tm_year + 1900;
	}
	else {
		mo = atoi(argv[1]);
		da = atoi(argv[2]);
		yr = atoi(argv[3]);
	}
 
	if (!ca(yr,mo,da,&jdcommon)) {
		if (jdcommon < 348348) {
			(void) printf("%s: Date of range!\n",program);
			(void) exit(2);
		}
		jyr = yr + 3762;
		do {
			--jyr;
			if(ja(jyr,1,1,&jdjewish)) {
				(void) printf(msg2, program, Jewish, 1);
				(void) exit(4);
			}
		} while (jdjewish > jdcommon);
		jda = (jdcommon-jdjewish)+1;
		for(jmo=1; jmo<=13 && jda>jmln[jmo]; ++jmo)
			jda -= jmln[jmo]; 
		if(jmo>13) {
			(void) printf(msg1, program, 2);
			(void) exit(3);
		}
		if(ja(jyr,jmo,jda,&jdjewish)) {
			(void) printf(msg2, program, Jewish, 2);
			(void) exit(4);
		}
		(void) sprintf(text,"%s, %d %s %d %.2s %s%s %.2s",
			dname[lrmdr(jdjewish+1l,7l)],
			jda,jmname[jmo],jyr,
			dname[jrhdow],
			jtx1[jtype],jtx2[jleap],
			dname[jpdow]);
		yr = jyr - 3759;
		do {
			--yr;
			if(ca(yr,1,1,&jdcommon)) {
				(void) printf(msg2, program, Common, 1);
				(void) exit(4);
			}
		} while (jdcommon > jdjewish);
		da = (jdjewish-jdcommon)+1;
		for(mo=1; mo<=12 && da>cmln[mo]; ++mo)
			da -= cmln[mo]; 
		if(mo>12) {
			(void) printf(msg1, program, 3);
			(void) exit(3);
		}
		(void) printf("Event:\t%-47.47s %s %d, %d %s\n\n",
			text,cmname[mo],da,yr,jtx2[cleap]);
		if (jda == 30 && (jmo == 2 || jmo == 3 || jmo == 6)) {
			if (delay) {
				switch(ja(jyr+delay,jmo,jda,&junk)) {
				case 0:
					up = TRUE;
					break;
				case 1:
					jda = 29;
					break;
				case 2:
					(void) printf(msg2, program, Jewish, 3);
					(void) exit(4);
					break;
				default:
					(void) printf(msg1, program, 4);
					(void) exit(3);
					break;
				}
			} else {
				up = TRUE;
			}
		}
		for(n=delay?delay:1, jyr += n; n<=80; ++n, ++jyr) {
			wjmo = jmo;
			wjda = jda;
			if(ja(jyr,jmo,jda,&jdjewish)) {
				if (up && jda == 30)
					if(jmo == 2 || jmo == 3) {
						wjmo += 1;
						wjda = 1;
						if(ja(jyr,wjmo,wjda,
							&jdjewish)) {
							(void) printf(msg2,
								program,
								Jewish, 4);
							(void) exit(4);
						}
					} else if (jmo = 6) {
						wjmo += 2;
						wjda = 1;
						if(ja(jyr,wjmo,wjda,
							&jdjewish)) {
							(void) printf(msg2,
								program,
								Jewish, 5);
							(void) exit(4);
						}
					} else {
						(void) printf(msg2,
							program, Jewish, 6);
						(void) exit(4);
					}
				else {
					(void) printf(msg2, program, Jewish, 7);
					(void) exit(4);
				}
			}
			if(!jleap&&wjmo==7)
				--wjmo;
			(void) sprintf(text,
					"%s, %d %s %d %.2s %s%s %.2s",
				dname[lrmdr(jdjewish+1l,7l)],
				wjda,jmname[wjmo],jyr,
				dname[jrhdow],
				jtx1[jtype],jtx2[jleap],
				dname[jpdow]);
			yr = jyr - 3759;
			do {
				--yr;
				if(ca(yr,1,1,&jdcommon)) {
					(void) printf(msg2, program, Common, 2);
					(void) exit(4);
				}
			} while (jdcommon > jdjewish);
			da = (jdjewish-jdcommon)+1;
			for(mo=1; mo<=12 && da>cmln[mo]; ++mo)
				da -= cmln[mo]; 
			if(mo>12) {
				(void) printf(msg1, program, 5);
				(void) exit(3);
			}
			(void) printf("+%d\t%-47.47s %s %d, %d %s\n",
				n,text,cmname[mo],da,yr,jtx2[cleap]);
		}
		(void) exit(0);
	} else {
		(void) printf("%s: Invalid date!\n",program);
		(void) exit(2);
	}
	return 0;
}

260.2HCAL.CGRAMPS::LISSESD&amp;P ShrewsburyFri Feb 20 1987 15:22292
    HCAL is a calandar program for giving a Hebrew date for the
    corresponding date. Here is a quick cookbook method to get
    this program to run.
    
    Use the following commands to compile and link the program.
    
	$ cc hcal
	$ link hcal,sys$library:vaxcrtl/lib

    Add the following symbol to your login.com. Don't forget the $
    before the disk name. 
    
    	HCAL :== $yourdisk:[yourdirectory]hcal
    
    Run your login.com file.
    
    Run the program by typing...
    
    hcal mm dd yyyy
    
    mm is the month
    dd is the day
    yyyy is the year
    
    For example enter   hcal 02 15 1987  for Feb 15, 1987.
    
    If you do not enter a date the default will be the current
    date. 
    
    Some of the terms that asre printed with the date are explained
    in note #197.18.
    
    ---------------------------< cut here >-------------------------
#endif

#include <stdio.h>
#include <time.h>
#ifdef	vms
#include		errno
#include		ssdef
#include		stsdef
#define	IO_SUCCESS	(SS$_NORMAL | STS$M_INHIB_MSG)
#define	IO_ERROR	(SS$_ABORT)
#endif

#ifndef	IO_SUCCESS
#define	IO_SUCCESS	0			/* Normal exit		*/
#define	IO_ERROR	1			/* Error exit		*/
#endif

/*
This program writes a date (to stdout) according to the Jewish
Calendar.  If no argument is specified, it calls a "ctime"
function to use today's date.  Otherwise, it may be invoked
with 3 arguments -- month, day, year (4-digit negative for BC(E)).
*/

static char *copyright = {
"(C) 1985 Randolph J. Herber  Usage is unrestricted with retention of notice."
};

#define TRUE     1
#define FALSE    0

static int mlen[] = {
	0,31,28,31,30,31,30,31,31,30,31,30,31
};

static int jmlen[] = {
	0,30,29,30,29,30,30,29,30,29,30,29,30,29
};

static char *mname[] = {
	"",
	"Tishri",
	"Chshvn",
	"Kislev",
	"Tebet",
	"Shebat",
	"Adar",
	"VeAdar",
	"Nisan",
	"Iyar",
	"Sivan",
	"Tammuz",
	"Ab",
	"Elul"
};

static short mdays[] = {
	0,   354,   708,  1092,
	1446,  1801,  2185,  2539,
	2923,  3277,  3632,  4016,
	4370,  4724,  5108,  5463,
	5817,  6201,  6555
};

static short mparts[] = {
	0,  9516, 19032, 16381,
	25897,  9493,  6842, 16358,
	13703, 23223,  6819,  4168,
	13684, 23200, 20549,  4145,
	13661, 11010, 20526
};

static short mtype[] = {
	2,     1,     0,     2,
	1,     0,     3,     0,
	2,     1,     0,     2,
	1,     0,     2,     1,
	0,     3,     0
};

static long table1[4][9] = {
	{0,15611,38880,64800, 83855,116640,145211,168480,181440},
	{0, 3444,38880,55284,107124,116640,133044,168480,181440},
	{0, 3444,36229,55284,107124,116640,123528,168480,181440},
	{0, 3444,36229,55284,107124,116640,133044,168480,181440}
};



static short table2[2][9] = {
	{1,3,2,2,3,1,3,1,0},
	{1,3,2,1,3,1,3,1,0}
};



static short table3[] = {
	1,1,2,4,4,6,6,1,0
};

static char *jkind1[] = {
	"", "defective", "normal", "complete"
};

static char *jkind2[] = {
	"", " leap"
};

main(argc,argv)
int argc;
char **argv;
{

	long secs, time();
	struct tm *tbuf, *localtime();
	void exit();
	int year, yr, mo, da, unit(), jyr, jcycle;
	long jdate, jpart, jday, jarg, jstart;
	short yrm1, n, jyear;
	char style, leap, jtype, jleap;

	if (argc > 1 && argc != 4) {
		(void) printf("Usage:  No arguments for today's date,");
		(void) printf(" or '%s <mo> <da> <yr>'.\n", *argv);
		(void) exit(IO_ERROR);
	}
	else if (argc == 1) {
		secs = time((long *)0);
		tbuf = localtime(&secs);
		mo = tbuf->tm_mon + 1;
		da = tbuf->tm_mday;
		year = tbuf->tm_year + 1900;
	}
	else {
		mo = atoi(argv[1]);
		da = atoi(argv[2]);
		year = atoi(argv[3]);
	}

	if (year != 0 && year >= -3761 && year < 10000) {
		yr = year > 0 ? year : year + 1;
		style = year > 1582;
		leap = style
		    ? (((yr % 4) == 0) && ((yr % 100) != 0)) ||
			((yr % 400) == 0)
		    : ((yr % 4) == 0);
		mlen[2] = leap ? 29 : 28;
		if (mo >=1 && mo <= 12 && da >= 1 && da <= mlen[mo] &&
		    !(year == 1582 && (mo == 1 || mo == 2 ||
		    (mo == 10 && da >= 5 && da <= 14)))) {
			if (year == 1582 && mo == 10) {
				mlen[10] = 21;
				if (da >= 15) da -= 10;
			} else {
				mlen[10] = 31;
			}
			yrm1 = yr - 1;
			jdate = 1721423l+yrm1*365+unit(yrm1,4)+da;
			for (n=1;n<mo;++n) {
				jdate += mlen[n];
			}
			if (style) {
				jdate -= 10 + (yrm1-1500)/100 - (yrm1-1200)/400;
			}
			if (jdate < 347998) {
				(void) printf("%s: Date of range!\n",*argv);
				(void) exit(IO_ERROR);
			}
			jyr = yr + 3761;
			do {
				jyr -= 1;
				jcycle = unit(jyr,19);
				jyear = rmdr(jyr,19);
				jtype = mtype[jyear];
				jleap = jtype == 0;
				jpart = 17875l*jcycle+mparts[jyear]+25044l;
				jday = lunit(jpart,25920l);
				jpart -= jday * 25920l;
				jday += 6939l*jcycle+mdays[jyear]+347998l;
				jarg = lrmdr(jday,7l)*25920l+jpart;
				for(n=0;n<=7;++n) {
					if (table1[jtype][n]<=jarg &&
					    jarg<table1[jtype][n+1]) break;
				}
				jtype = table2[jleap][n];
				jstart = jday+lrmdr(2l+table3[n]-jday,7l)-3l;
			} while (jdate < jstart);
			jyr += 1;
			jday = (jdate - jstart) + 1;
			switch (jtype) {
				case 1: jmlen[3] = 29; break;
				case 2: break;
				case 3: jmlen[2] = 30; break;
				default:
					printf("%s: Internal error 1\n",*argv);
					exit(IO_ERROR);
					break;
			}
			if (!jleap) {
				mname[7] = mname[6];
				mname[6] = mname[0];
				jmlen[6] = 0;
			}
			for(n=1;n<=13;++n) {
				if(jday<=jmlen[n]) break;
				jday -= jmlen[n];
			}
			(void) printf("%s %d, %d %s%s\n",
				mname[n],jday,jyr,
				jkind1[jtype],jkind2[jleap]);
			(void) exit(IO_SUCCESS);
		} else {
			(void) printf("%s: Invalid date!\n",*argv);
			(void) exit(IO_ERROR);
		}
	}
	(void) printf("%s: Date out of range!\n",*argv);
	(void) exit(IO_ERROR);
}

int unit(f1,f2)
	int f1, f2;
{
	int rmdr;
	rmdr = f1 % f2;
	if (rmdr < 0) rmdr += f2;
	return (f1 - rmdr) / f2;
}


long lunit(f1,f2)
	long f1, f2;
{
	long rmdr;
	rmdr = f1 % f2;
	if (rmdr < 0) rmdr += f2;
	return (f1 - rmdr) / f2;
}


int rmdr(f1,f2)
	int f1, f2;
{
	int rmdrx;
	rmdrx = f1 % f2;
	if (rmdrx < 0) rmdrx += f2;
	return rmdrx;
}


long lrmdr(f1,f2)
	long f1, f2;
{
	long rmdrx;
	rmdrx = f1 % f2;
	if (rmdrx < 0) rmdrx += f2;
	return rmdrx;
}

260.3LUNCAL.CGRAMPS::LISSESD&amp;P ShrewsburyFri Feb 20 1987 15:23187
    LUNCAL is a calandar program for giving a Hebrew date for the
    corresponding date. Here is a quick cookbook method to get
    this program to run.
    
    Use the following commands to compile and link the program.
    
	$ cc luncal
	$ link luncal,sys$library:vaxcrtl/lib

    Add the following symbol to your login.com. Don't forget the $
    before the disk name. 
    
    	LCAL :== $yourdisk:[yourdirectory]luncal
    
    Run your login.com file.
    
    Run the program by typing...
    
    lcal yyyy mm dd
    
    yyyy is the year
    mm is the month
    dd is the day
    
    For example enter   lcal 1987 02 15   for Feb 15, 1987.
    
    There is no default. You must enter a date.
    
    -----------------------< cut here >-----------------------
#ifdef comment
>From floyd!trb Wed Oct 20 17:31:27 1982
To: rabbit!smb
Subject: REAL hebcal.c

>From harpo!alice!adw Tue Aug 17 10:45:55 1982
Date: Tue Aug 17 10:44:39 1982
Status: R
#endif

/* This program accepts a Gregorian date (yr mon date) and produces the*/
/*equivilant Hebrew date, input from command line*/


#include <stdio.h>
main(c,v)
int c;
char *v[];

{int y,m,d;
	if(c != 4){
		fprintf(stderr,"usage: %s yyyy mm dd\n",v[0]);
		exit(1);
	}
	sscanf(v[1],"%d",&y);
	sscanf(v[2],"%d",&m);
	sscanf(v[3],"%d",&d);
	greg_heb(y,m,d);
}

int daysinh[6][14] ={
		{0,30,29,29,29,30,29,30,29,30,29,30,29},
		{0,30,29,30,29,30,29,30,29,30,29,30,29},
		{0,30,30,30,29,30,29,30,29,30,29,30,29},
		{0,30,29,29,29,30,30,29,30,29,30,29,30,29},
		{0,30,29,30,29,30,30,29,30,29,30,29,30,29},
		{0,30,30,30,29,30,30,29,30,29,30,29,30,29}
};

int daysing[2][12] ={
		{30,31,30,31,31,28,31,30,31,30,31,31},
		{30,31,30,31,31,29,31,30,31,30,31,31}
};

char *nameh[2][14] = {
	{"Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "Adar", "Nisan",
	 "Iyyar", "Sivan", "Tammuz", "Av", "Elul","Elul"},
	{"Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "Adar I", "Adar II",
	 "Nisan", "Iyyar", "Sivan", "Tammuz", "Av", "Elul", "Elul"}
};


greg_heb(gyr, gmo, gdate)
int gyr,gmo,gdate;

{int rhgr0, rhgr1, rh(), t1, t, type, gdayno, useleap, flag;
 int hyr,hmo, hdate, septdate,septmon;

hyr = (gmo < 9)? gyr -1 :gyr;		/*Greg. yr of RH*/

type = 0;
rhgr0 = rh(hyr);			/*Sept x of RH*/
if(gmo == 9 && gdate < rhgr0) {		/*check if date is before RH*/
	flag = 1;
	hyr = gyr +3760;
	hmo = 13;		/*Elul is also 14th month */
	hdate = 30 - (rhgr0 -gdate);
	}
else if(gmo == 10 && gdate +30 < rhgr0){
	flag = 1;
	hyr = gyr +3760;
	hmo = 13;
	hdate = 30 - (rhgr0 -gdate -30);
	}
else {
	useleap = 0;
	if(((hyr+1)%400==0)||(((hyr+1)%4 ==0)&& ((hyr+1)%100 !=0))) useleap = 1;


	septdate = gdate;			/*no. of days from Sept 0*/
	septmon = (gmo > 8) ? (gmo -9): gmo +3; /*ie Sept is mon0 */
	while( septmon > 0)
		septdate = daysing[useleap][--septmon] + septdate;

	rhgr1 = rh(hyr +1);		/*Sept x of next RH*/
	t= rhgr1 - rhgr0 + useleap;
	
	if(t == -12) type = 0;
	if(t == -11) type = 1;
	if(t == -10) type = 2;		/*Type of year: 12 months is 0-2*/
	if(t == 18)  type = 3;			/*13 months is 3-5*/
	if(t == 19)  type = 4;
	if(t == 20)  type = 5;

	hyr = hyr + 3761;
	hmo = 1;
	hdate = septdate - rhgr0 + 1;
	while(hdate > daysinh[type][hmo]) 
		hdate = hdate - daysinh[type][hmo++];
	}
t1 = (type <3) ? 0 : 1;
printf("%d %s %d\n", hyr, nameh[t1][hmo-1], hdate);
}


rh(y)
int y;
{int day,x,n2,g;
 float fraction,n1;

	g = (y%19) +1;		/*g = "golden number"*/
	n1 = y/100.0 -y/400.0 -2.0 +(765433.0/492480.0)*((12*g)%19) +(y%4)/4.0
		-(313.0*y + 89091.0)/98496.0;
	n2 = n1;	/*this is 'N' in Conway's formula */
	day = dayofwk(y-2000,7,n2);
	fraction = n1 -n2;
	x = (12 * g)%19;
	if(day == 1 || day == 4 || day == 6) 
		{n2 = n1 +1;
		 day = day +1;
		}
	else {
	     if(day == 3 && (fraction >=(1367.0/2160.0)) && x >6)
		{day = 5; n2 = n2 +2; }
	     if(day == 2 && (fraction >= (23269.0/25920.0)) && x >11)
		{day = 3; n2 = n2 +1; }
	     }
	return(n2);
}



/*This subroutine computes the day of week of the unadjusted RH     */
/*The month is reduced by 2- ie September is the 7th month          */

int daysin[]  = {
	0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29
};


dayofwk(yr, mon, date)
int yr, mon, date;
{
	int  dayofyr, offset, x, y;

	if(mon <= 0) mon = mon +12;
	if(mon==12 || mon == 11) yr = yr -1;

	dayofyr = date;
	while(mon >1)
		dayofyr = daysin[--mon] + dayofyr;
	x = (yr < 0) ? 1 : 0 ;     /*adjust for 2000 a leap year*/
	y = (dayofyr + yr -x +(yr+x)/4 - (yr+x)/100 + (yr+x)/400 +3)%7;
	offset = (y >= 0) ? y : y + 7; /*get remainder into [0,6]*/
	return(offset);
}


260.4Update on HCAL & Comments on MSC 5.1 & MSDOSRETORT::UMINAThu Sep 01 1988 15:42343
    /*
    The program HCAL.C has a couple of minor problems with it, however
    these can be easily fixed - by minor problems, I mean with regard
    to getting a successful compilation - not with regard to the historical
    accuracy or theolical accuracy, which I have no way of checking.
    
    All three of these programs (including HCAL.C when fixed as shown
    below) will compile using Microsoft C V5.1, and will therefore run
    quite nicely under MSDOS.
    
    The following are the errors which were fixed to compile HCAL.C
    using MSC 5.1 (note that YERTZ.C and LCAL.C were OK as is):
    
    1. remove the endif statement just after the line --< cut here >--
    
    2. move the functions from the end of the program, which are
       unit, lunit, rmdr, and lrmdr so that they are placed just
       before the function main() which calls them.  Otherwise you
       get function redefinition errors with MSC.
    
    For those who may be somewhat unfamiliar with this process, I will
    post the new version of HCAL.C here.  If anyone wishes the MSDOS
    executable files (ie you don't have MSC) send me some mail and I
    will put them up so you can copy and download them.
    
    PS thanks for putting these programs in here.  The Jewish calander
    has been something I have been trying to understand for a long time,
    and though I don't think I'm any closer to understanding it, these
    programs point out why (the complexity) and give me some basis upon
    which I can base further study.
    
    /Len
    */
    
    /*

    ================================================================================
    Note 260.2                       Jewish Software               
              2 of 3
    GRAMPS::LISS "ESD&P Shrewsbury"                     292 lines
    20-FEB-1987 12:22
                                      -< HCAL.C >-

    --------------------------------------------------------------------------------
    
        HCAL is a calandar program for giving a Hebrew date for the
        corresponding date. Here is a quick cookbook method to get
        this program to run.
        
        Use the following commands to compile and link the program.
        
    	$ cc hcal
    	$ link hcal,sys$library:vaxcrtl/lib
    
        Add the following symbol to your login.com. Don't forget the
    $
        before the disk name. 
        
        	HCAL :== $yourdisk:[yourdirectory]hcal
        
        Run your login.com file.
        
        Run the program by typing...
        
        hcal mm dd yyyy
        
        mm is the month
        dd is the day
        yyyy is the year
        
        For example enter   hcal 02 15 1987  for Feb 15, 1987.
        
        If you do not enter a date the default will be the current
        date. 
        
        Some of the terms that asre printed with the date are explained
        in note #197.18.
        
        ---------------------------< cut here >-------------------------
    */
    #include <stdio.h>
    #include <time.h>
    #ifdef	vms
    #include		errno
    #include		ssdef
    #include		stsdef
    #define	IO_SUCCESS	(SS$_NORMAL | STS$M_INHIB_MSG)
    #define	IO_ERROR	(SS$_ABORT)
    #endif
    
    #ifndef	IO_SUCCESS
    #define	IO_SUCCESS	0			/* Normal exit
    */#define	IO_ERROR	1			/* Error exit
    */#endif
    
    /*
    This program writes a date (to stdout) according to the Jewish
    Calendar.  If no argument is specified, it calls a "ctime"
    function to use today's date.  Otherwise, it may be invoked
    with 3 arguments -- month, day, year (4-digit negative for BC(E)).
    */
    
    static char *copyright = {
    "(C) 1985 Randolph J. Herber  Usage is unrestricted with retention
    of notice."
    };
    
    #define TRUE     1
    #define FALSE    0
    
    static int mlen[] = {
    	0,31,28,31,30,31,30,31,31,30,31,30,31
    };
    
    static int jmlen[] = {
    	0,30,29,30,29,30,30,29,30,29,30,29,30,29
    };
    
    static char *mname[] = {
    	"",
    	"Tishri",
    	"Chshvn",
    	"Kislev",
    	"Tebet",
    	"Shebat",
    	"Adar",
    	"VeAdar",
    	"Nisan",
    	"Iyar",
    	"Sivan",
    	"Tammuz",
    	"Ab",
    	"Elul"
    };
    
    static short mdays[] = {
    	0,   354,   708,  1092,
    	1446,  1801,  2185,  2539,
    	2923,  3277,  3632,  4016,
    	4370,  4724,  5108,  5463,
    	5817,  6201,  6555
    };
    
    static short mparts[] = {
    	0,  9516, 19032, 16381,
    	25897,  9493,  6842, 16358,
    	13703, 23223,  6819,  4168,
    	13684, 23200, 20549,  4145,
    	13661, 11010, 20526
    };
    
    static short mtype[] = {
    	2,     1,     0,     2,
    	1,     0,     3,     0,
    	2,     1,     0,     2,
    	1,     0,     2,     1,
    	0,     3,     0
    };
    
    static long table1[4][9] = {
    	{0,15611,38880,64800, 83855,116640,145211,168480,181440},
    	{0, 3444,38880,55284,107124,116640,133044,168480,181440},
    	{0, 3444,36229,55284,107124,116640,123528,168480,181440},
    	{0, 3444,36229,55284,107124,116640,133044,168480,181440}
    };
    
    
    
    static short table2[2][9] = {
    	{1,3,2,2,3,1,3,1,0},
    	{1,3,2,1,3,1,3,1,0}
    };
    
    
    
    static short table3[] = {
    	1,1,2,4,4,6,6,1,0
    };
    
    static char *jkind1[] = {
    	"", "defective", "normal", "complete"
    };
    
    static char *jkind2[] = {
    	"", " leap"
    };
    
    int unit(f1,f2)
    	int f1, f2;
    {
    	int rmdr;
    	rmdr = f1 % f2;
    	if (rmdr < 0) rmdr += f2;
    	return (f1 - rmdr) / f2;
    }
    
    
    long hlunit(f1,f2)
    	long f1, f2;
    {
    	long rmdr;
    	rmdr = f1 % f2;
    	if (rmdr < 0) rmdr += f2;
    	return (f1 - rmdr) / f2;
    }
    
    
    int rmdr(f1,f2)
    	int f1, f2;
    {
    	int rmdrx;
    	rmdrx = f1 % f2;
    	if (rmdrx < 0) rmdrx += f2;
    	return rmdrx;
    }
    
    
    long hlrmdr(f1,f2)
    	long f1, f2;
    {
    	long rmdrx;
    	rmdrx = f1 % f2;
    	if (rmdrx < 0) rmdrx += f2;
    	return rmdrx;
    }
    
    
    main(argc,argv)
    int argc;
    char **argv;
    {
    
    	long secs, time();
    	struct tm *tbuf, *localtime();
    	void exit();
    	int year, yr, mo, da, unit(), jyr, jcycle;
    	long jdate, jpart, jday, jarg, jstart;
    	short yrm1, n, jyear;
    	char style, leap, jtype, jleap;
    
    	if (argc > 1 && argc != 4) {
    		(void) printf("Usage:  No arguments for today's date,");
    		(void) printf(" or '%s <mo> <da> <yr>'.\n", *argv);
    		(void) exit(IO_ERROR);
    	}
    	else if (argc == 1) {
    		secs = time((long *)0);
    		tbuf = localtime(&secs);
    		mo = tbuf->tm_mon + 1;
    		da = tbuf->tm_mday;
    		year = tbuf->tm_year + 1900;
    	}
    	else {
    		mo = atoi(argv[1]);
    		da = atoi(argv[2]);
    		year = atoi(argv[3]);
    	}
    
    	if (year != 0 && year >= -3761 && year < 10000) {
    		yr = year > 0 ? year : year + 1;
    		style = year > 1582;
    		leap = style
    		    ? (((yr % 4) == 0) && ((yr % 100) != 0)) ||
    			((yr % 400) == 0)
    		    : ((yr % 4) == 0);
    		mlen[2] = leap ? 29 : 28;
    		if (mo >=1 && mo <= 12 && da >= 1 && da <= mlen[mo]
    &&
    		    !(year == 1582 && (mo == 1 || mo == 2 ||
    		    (mo == 10 && da >= 5 && da <= 14)))) {
    			if (year == 1582 && mo == 10) {
    				mlen[10] = 21;
    				if (da >= 15) da -= 10;
    			} else {
    				mlen[10] = 31;
    			}
    			yrm1 = yr - 1;
    			jdate = 1721423l+yrm1*365+unit(yrm1,4)+da;
    			for (n=1;n<mo;++n) {
    				jdate += mlen[n];
    			}
    			if (style) {
    				jdate -= 10 + (yrm1-1500)/100 -
    (yrm1-1200)/400;			}
    			if (jdate < 347998) {
    				(void) printf("%s: Date of
    range!\n",*argv);				(void) exit(IO_ERROR);
    			}
    			jyr = yr + 3761;
    			do {
    				jyr -= 1;
    				jcycle = unit(jyr,19);
    				jyear = rmdr(jyr,19);
    				jtype = mtype[jyear];
    				jleap = jtype == 0;
    				jpart = 17875l*jcycle+mparts[jyear]+25044l;
    				jday = hlunit(jpart,25920l);
    				jpart -= jday * 25920l;
    				jday += 6939l*jcycle+mdays[jyear]+347998l;
    				jarg = hlrmdr(jday,7l)*25920l+jpart;
    				for(n=0;n<=7;++n) {
    					if (table1[jtype][n]<=jarg &&
    					    jarg<table1[jtype][n+1])
    break;
    				}
    				jtype = table2[jleap][n];
    				jstart =
    jday+hlrmdr(2l+table3[n]-jday,7l)-3l;			} while
    (jdate < jstart);
    			jyr += 1;
    			jday = (jdate - jstart) + 1;
    			switch (jtype) {
    				case 1: jmlen[3] = 29; break;
    				case 2: break;
    				case 3: jmlen[2] = 30; break;
    				default:
    					printf("%s: Internal error
    1\n",*argv);					exit(IO_ERROR);
    					break;
    			}
    			if (!jleap) {
    				mname[7] = mname[6];
    				mname[6] = mname[0];
    				jmlen[6] = 0;
    			}
    			for(n=1;n<=13;++n) {
    				if(jday<=jmlen[n]) break;
    				jday -= jmlen[n];
    			}
    			(void) printf("%s %d, %d %s%s\n",
    				mname[n],jday,jyr,
    				jkind1[jtype],jkind2[jleap]);
    			(void) exit(IO_SUCCESS);
    		} else {
    			(void) printf("%s: Invalid date!\n",*argv);
    			(void) exit(IO_ERROR);
    		}
    	}
    	(void) printf("%s: Date out of range!\n",*argv);
    	(void) exit(IO_ERROR);
    }
    
    
260.5Beware of HCAL.C, some bugs still there!RETORT::UMINAThu Sep 01 1988 16:048
    After getting HCAL.C to compile, I find that there are some errors
    in the program which apparently have to do with pointers being
    incorrectly set or not initialized properly.  If anyone cares to
    fix the program, please do.  If I get to debugging it I will upload
    it here.  YERTZ.C and LCAL.C appear to work fine.
    
    /Len
    
260.6One for a PCHPSTEK::SIMONCuriosier and curiosier...Thu Sep 01 1988 21:078
    I have an MSDOS program that converts Jewish dates to "regualar"
    and back, calculates anniversary dates, shows all holidays over
    a yesar, etc.  It runs on any IBM-PC compatible.  If there is an
    interest, I'll transfer it from my PC to the VAX for anybody to
    copy.
    
    Regards,
    Leo
260.7Re:.6 - Please put program on the VAX.TAVIS::JUANFri Sep 02 1988 14:402
    
    
260.8More Hebrew Calendar ConversionsBOLT::MINOWFortran for PrecedentFri Sep 02 1988 18:1816
You might (also) wish to copy any or all of the following:

	bolt::user1:[minow.personal.source.calendar]jewishcalendar.*
	bolt::user1:[minow.personal.source.hdate]*.*

The first is -- I believe -- my copy of the calendar program under
discussion.  The second is a different implementation of the algorithm,
including a program to translate dates between Hebrew and civil form,
and a program to print a calendar with the Hebrew dates and their
civil equivalent.

Both programs compile and run under VMS and should be readily portable
to other computers that support C.  There is some discussion of the
algorithm in ...hdate]explain.txt.

Martin.
260.9It is hereHPSTEK::SIMONCuriosier and curiosier...Mon Sep 05 1988 05:0511
    Re: My promise in .6
    
    I placed the program in 
    
    BARNUM::POWER:[SIMON.MSDOS]JCAL40.ARC
    
    Transfer it to your PC, de-ARC with the latest PKXARC and run.
    
    Regards,
    Leo
    
260.10Just in time for the new yearBOLT::MINOWFortran for PrecedentFri Sep 09 1988 14:165
For what it's worth, I just submitted the hdate and hcal programs to the
software toolshed.  When they're installed, you can get them by the
procedure described in the notesfile catalog METOO::SW_TOOLS_CATALOG.

Martin.