Path: itexjct!mintaka.lcs.mit.edu!olivea!uunet!iWarp.intel.com|inews!pinkas From: pinkas@caraway.intel.com (Israel Pinkas) Newsgroups: soc.culture.jewish Subject: Re: Calendar Utility Wanted Message-ID: Date: 12 May 92 23:11:01 GMT References: Sender: news@inews.intel.com Reply-To: pinkas@stps18.intel.com Organization: Software Technologies, INTeL Corporation, Santa Clara, CA Lines: 475 In-reply-to: ubiquity@cs.utexas.edu's message of 11 May 92 04:11:48 GMT This was posted to s.c.j a number of years ago. It fits the bill to a T. This works under Unix. I only have SVR4, but I believe that it should work under SVR3.x and BSD unmodified. It does work on a NeXT (Mach). I have another program (hcal/hdate) which I have ported to DOS. If there is enough interest, I can post hcal/hdate as well. -Israel ---------------------------------------------------------------------- #include #include /* 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 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 && jarg13 || 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] [ ]\n", program); (void) printf(" (default is 1)\n"); (void) printf(" years to first observation\n"); (void) printf(" (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; } -- Disclaimer: The above are my personal opinions, and in no way represent the opinions of Intel Corporation. In no way should the above be taken to be a statement of Intel.