paskha.c revision 15720
115714Sache/*
215714Sache * Copyright (C) 1993-1996 by Andrey A. Chernov, Moscow, Russia.
315714Sache * All rights reserved.
415714Sache *
515714Sache * Redistribution and use in source and binary forms, with or without
615714Sache * modification, are permitted provided that the following conditions
715714Sache * are met:
815714Sache * 1. Redistributions of source code must retain the above copyright
915714Sache *    notice, this list of conditions and the following disclaimer.
1015714Sache * 2. Redistributions in binary form must reproduce the above copyright
1115714Sache *    notice, this list of conditions and the following disclaimer in the
1215714Sache *    documentation and/or other materials provided with the distribution.
1315714Sache *
1415714Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
1515714Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1615714Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1715714Sache * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1815714Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1915714Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2015714Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2115714Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2215714Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2315714Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2415714Sache * SUCH DAMAGE.
2515714Sache */
2615714Sache
2715714Sache#include <stdlib.h>
2815714Sache#include <string.h>
2915720Sache#include <stdio.h>
3015714Sache
3115720Sache#include "calendar.h"
3215720Sache
3315714Sache#define PASKHA "paskha"
3415714Sache#define PASKHALEN (sizeof(PASKHA) - 1)
3515714Sache
3615714Sache/* return year day for Orthodox Easter using Gauss formula */
3715714Sache/* (old style result) */
3815714Sache
3915714Sachestatic int
4015714Sachepaskha (R)
4115714Sacheint R;  /*year*/
4215714Sache{
4315714Sache	int a, b, c, d, e;
4415714Sache	static int x = 15;
4515714Sache	static int y = 6;
4615720Sache	extern int *cumdays;
4715714Sache
4815714Sache	a = R % 19;
4915714Sache	b = R % 4;
5015714Sache	c = R % 7;
5115714Sache	d = (19*a + x) % 30;
5215714Sache	e = (2*b + 4*c + 6*d + y) % 7;
5315714Sache	return ((cumdays[2/*feb*/] + 22/*mar*/) + (d + e));
5415714Sache}
5515714Sache
5615714Sache/* return year day for Orthodox Easter depending days */
5715714Sache
5815714Sacheint
5915714Sachegetpaskha(s, year)
6015714Sache	char *s;
6115714Sache        int year;
6215714Sache{
6315714Sache	int offset;
6415720Sache	extern struct fixs npaskha;
6515714Sache
6615714Sache	if (strncasecmp(s, PASKHA, PASKHALEN) == 0)
6715714Sache	    s += PASKHALEN;
6815720Sache	else if (   npaskha.name != NULL
6915720Sache		 && strncasecmp(s, npaskha.name, npaskha.len) == 0
7015720Sache		)
7115720Sache	    s += npaskha.len;
7215714Sache	else
7315714Sache	    return 0;
7415714Sache
7515714Sache
7615714Sache	/* Paskha+1  or Paskha-2
7715714Sache	 *       ^            ^   */
7815714Sache
7915714Sache	switch(*s) {
8015714Sache
8115714Sache	case '-':
8215714Sache	case '+':
8315714Sache	    offset = atoi(s);
8415714Sache	    break;
8515714Sache
8615714Sache	default:
8715714Sache	    offset = 0;
8815714Sache	    break;
8915714Sache	}
9015714Sache
9115714Sache	return (paskha(year) + offset + 13/* new style */);
9215714Sache}
93