[BACK]Return to ostern.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / calendar

Annotation of src/usr.bin/calendar/ostern.c, Revision 1.1

1.1     ! millert     1: /*     $OpenBSD: $     */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
        !             5:  * All rights reserved.
        !             6:  *
        !             7:  * Redistribution and use in source and binary forms, with or without
        !             8:  * modification, are permitted provided that the following conditions
        !             9:  * are met:
        !            10:  * 1. Redistributions of source code must retain the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer.
        !            12:  * 2. Redistributions in binary form must reproduce the above copyright
        !            13:  *    notice, this list of conditions and the following disclaimer in the
        !            14:  *    documentation and/or other materials provided with the distribution.
        !            15:  *
        !            16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
        !            17:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            18:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            19:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
        !            20:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            21:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            22:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            23:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            24:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            25:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            26:  * SUCH DAMAGE.
        !            27:  *
        !            28:  *     $Id: ostern.c,v 1.5 1996/08/27 20:04:15 wosch Exp $
        !            29:  */
        !            30:
        !            31: #ifndef lint
        !            32: static char rcsid[] = "$OpenBSD: $";
        !            33: #endif /* not lint */
        !            34:
        !            35: #include <stdio.h>
        !            36: #include <stdlib.h>
        !            37: #include <string.h>
        !            38: #include <time.h>
        !            39:
        !            40: #include "calendar.h"
        !            41:
        !            42: /* return year day for Easter */
        !            43:
        !            44: int easter (year)
        !            45:     int year;            /* 0 ... abcd, NOT since 1900 */
        !            46: {
        !            47:
        !            48:     int e_a, e_b, e_c, e_d, e_e,e_f, e_g, e_h, e_i, e_k,
        !            49:         e_l, e_m, e_n, e_p, e_q;
        !            50:
        !            51:     /* silly, but it works */
        !            52:     e_a = year % 19;
        !            53:     e_b = year / 100;
        !            54:     e_c = year % 100;
        !            55:
        !            56:     e_d = e_b / 4;
        !            57:     e_e = e_b % 4;
        !            58:     e_f = (e_b + 8) / 25;
        !            59:     e_g = (e_b + 1 - e_f) / 3;
        !            60:     e_h = ((19 * e_a) + 15 + e_b - (e_d + e_g)) % 30;
        !            61:     e_i = e_c / 4;
        !            62:     e_k = e_c % 4;
        !            63:     e_l = (32 + 2 * e_e + 2 * e_i - (e_h + e_k)) % 7;
        !            64:     e_m = (e_a + 11 * e_h + 22 * e_l) / 451;
        !            65:     e_n = (e_h + e_l + 114 - (7 * e_m)) / 31;
        !            66:     e_p = (e_h + e_l + 114 - (7 * e_m)) % 31;
        !            67:     e_p = e_p + 1;
        !            68:
        !            69:     e_q = 31 + 28;
        !            70:
        !            71:     if (e_k == 0 && e_c != 0)
        !            72:        e_q += 1;
        !            73:
        !            74:     if (e_n == 4)
        !            75:        e_q += 31;
        !            76:
        !            77:     e_q += e_p;
        !            78:
        !            79: #if DEBUG
        !            80:     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);
        !            81: #endif
        !            82:
        !            83:     return (e_q);
        !            84: }
        !            85:
        !            86: /* return year day for  Easter or easter depending days
        !            87:  * Match: Easter([+-][0-9]+)?
        !            88:  * e.g: Easter-2 is  Good Friday (2 days before Easter)
        !            89:  */
        !            90:
        !            91: int
        !            92: geteaster(s, year)
        !            93:        char *s;
        !            94:         int year;
        !            95: {
        !            96:        register int offset = 0;
        !            97:        extern struct fixs neaster;
        !            98:
        !            99: #define EASTER "easter"
        !           100: #define EASTERNAMELEN (sizeof(EASTER) - 1)
        !           101:
        !           102:        if (strncasecmp(s, EASTER, EASTERNAMELEN) == 0)
        !           103:            s += EASTERNAMELEN;
        !           104:        else if (   neaster.name != NULL
        !           105:                 && strncasecmp(s, neaster.name, neaster.len) == 0
        !           106:                )
        !           107:            s += neaster.len;
        !           108:        else
        !           109:            return(0);
        !           110:
        !           111: #if DEBUG
        !           112:        printf("%s %d %d\n", s, year, EASTERNAMELEN);
        !           113: #endif
        !           114:
        !           115:        /* Easter+1  or Easter-2
        !           116:         *       ^            ^   */
        !           117:
        !           118:        switch(*s) {
        !           119:
        !           120:        case '-':
        !           121:        case '+':
        !           122:            offset = atoi(s);
        !           123:            break;
        !           124:
        !           125:        default:
        !           126:            offset = 0;
        !           127:        }
        !           128:
        !           129:        return (easter(year) + offset);
        !           130: }