paskha.c revision 200420
11539Srgrimes/* 21539Srgrimes * Copyright (C) 1993-1996 by Andrey A. Chernov, Moscow, Russia. 31539Srgrimes * All rights reserved. 41539Srgrimes * 51539Srgrimes * Redistribution and use in source and binary forms, with or without 61539Srgrimes * modification, are permitted provided that the following conditions 71539Srgrimes * are met: 81539Srgrimes * 1. Redistributions of source code must retain the above copyright 91539Srgrimes * notice, this list of conditions and the following disclaimer. 101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111539Srgrimes * notice, this list of conditions and the following disclaimer in the 121539Srgrimes * documentation and/or other materials provided with the distribution. 131539Srgrimes * 141539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 151539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 161539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 171539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 181539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 191539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 201539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 211539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 221539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 231539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 241539Srgrimes * SUCH DAMAGE. 251539Srgrimes */ 261539Srgrimes 271539Srgrimes#include <sys/cdefs.h> 281539Srgrimes__FBSDID("$FreeBSD: head/usr.bin/calendar/paskha.c 200420 2009-12-11 23:35:38Z delphij $"); 291539Srgrimes 301539Srgrimes#include <stdio.h> 311539Srgrimes#include <stdlib.h> 321539Srgrimes#include <string.h> 3323650Speter 3478169Sru#include "calendar.h" 351539Srgrimes 361539Srgrimes#define PASKHA "paskha" 371539Srgrimes#define PASKHALEN (sizeof(PASKHA) - 1) 381539Srgrimes 391539Srgrimesstatic int paskha(int); 401539Srgrimes 411539Srgrimes/* return year day for Orthodox Easter using Gauss formula */ 421539Srgrimes/* (old style result) */ 431539Srgrimes 441539Srgrimesstatic int 451539Srgrimespaskha(int R) /*year*/ 461539Srgrimes{ 471539Srgrimes int a, b, c, d, e; 481539Srgrimes static int x = 15; 4978169Sru static int y = 6; 5078169Sru 511539Srgrimes a = R % 19; 521539Srgrimes b = R % 4; 531539Srgrimes c = R % 7; 541539Srgrimes d = (19 * a + x) % 30; 551539Srgrimes e = (2 * b + 4 * c + 6 * d + y) % 7; 561539Srgrimes return (((cumdays[3] + 1) + 22) + (d + e)); 571539Srgrimes} 581539Srgrimes 5923650Speter/* return year day for Orthodox Easter depending days */ 6023650Speter 611539Srgrimesint 6223650Spetergetpaskha(char *s, int year) 6323650Speter{ 641539Srgrimes int offset; 651539Srgrimes 661539Srgrimes if (strncasecmp(s, PASKHA, PASKHALEN) == 0) 671539Srgrimes s += PASKHALEN; 681539Srgrimes else if (npaskha.name != NULL 691539Srgrimes && strncasecmp(s, npaskha.name, npaskha.len) == 0) 701539Srgrimes s += npaskha.len; 711539Srgrimes else 721539Srgrimes return 0; 731539Srgrimes 741539Srgrimes /* Paskha+1 or Paskha-2 751539Srgrimes * ^ ^ */ 761539Srgrimes 771539Srgrimes switch (*s) { 781539Srgrimes 791539Srgrimes case '-': 801539Srgrimes case '+': 811539Srgrimes offset = atoi(s); 821539Srgrimes break; 831539Srgrimes 841539Srgrimes default: 851539Srgrimes offset = 0; 861539Srgrimes break; 871539Srgrimes } 881539Srgrimes 891539Srgrimes return (paskha(year) + offset + 13 /* new style */); 901539Srgrimes} 911539Srgrimes