ostern.c revision 15714
1137587Snik/* 2137587Snik * Copyright (c) 1995 Wolfram Schneider. Public domain. 3137587Snik * 4137587Snik * $Id: ostern.c,v 1.1 1996/02/02 06:02:40 wosch Exp $ 5137587Snik*/ 6137587Snik 7137587Snik#include <string.h> 8137587Snik#include <stdlib.h> 9137587Snik 10137587Snik/* return year day for Easter */ 11 12int easter (year) 13 int year; /* 0 ... abcd, NOT since 1900 */ 14{ 15 16 int e_a, e_b, e_c, e_d, e_e,e_f, e_g, e_h, e_i, e_k, 17 e_l, e_m, e_n, e_p, e_q; 18 19 /* silly, but it works */ 20 e_a = year % 19; 21 e_b = year / 100; 22 e_c = year % 100; 23 24 e_d = e_b / 4; 25 e_e = e_b % 4; 26 e_f = (e_b + 8) / 25; 27 e_g = (e_b + 1 - e_f) / 3; 28 e_h = ((19 * e_a) + 15 + e_b - (e_d + e_g)) % 30; 29 e_i = e_c / 4; 30 e_k = e_c % 4; 31 e_l = (32 + 2 * e_e + 2 * e_i - (e_h + e_k)) % 7; 32 e_m = (e_a + 11 * e_h + 22 * e_l) / 451; 33 e_n = (e_h + e_l + 114 - (7 * e_m)) / 31; 34 e_p = (e_h + e_l + 114 - (7 * e_m)) % 31; 35 e_p = e_p + 1; 36 37 e_q = 31 + 28; 38 39 if (e_k == 0 && e_c != 0) 40 e_q += 1; 41 42 if (e_n == 4) 43 e_q += 31; 44 45 e_q += e_p; 46 47#if DEBUG 48 printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", e_a , e_b , e_c , e_d , e_e , e_f , e_g , e_h , e_i , e_k , e_l , e_m , e_n , e_p , e_q); 49#endif 50 51 return (e_q); 52} 53 54/* return year day for Easter or easter depending days 55 * Match: Easter([+-][0-9]+)? 56 * e.g: Easter-2 is Good Friday (2 days before Easter) 57 */ 58 59int 60geteaster(s, year) 61 char *s; 62 int year; 63{ 64 register int offset = 0; 65 66#define EASTER "easter" 67#define EASTERNAMELEN (sizeof(EASTER) - 1) 68 69 /* no easter */ 70 if (strncasecmp(s, EASTER, EASTERNAMELEN)) 71 return(0); 72 73#if DEBUG 74 printf("%s %d %d\n", s, year, EASTERNAMELEN); 75#endif 76 77 /* Easter+1 or Easter-2 78 * ^ ^ */ 79 80 switch(*(s + EASTERNAMELEN)) { 81 82 case '-': 83 offset = -(atoi(s + EASTERNAMELEN + 1)); 84 break; 85 86 case '+': 87 offset = atoi(s + EASTERNAMELEN + 1); 88 break; 89 90 default: 91 offset = 0; 92 } 93 94 return (easter(year) + offset); 95} 96